| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 599 人关注过本帖
标题:[求助]把.NET转ASP?
只看楼主 加入收藏
威风八面
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2006-6-12
收藏
 问题点数:0 回复次数:1 
[求助]把.NET转ASP?
把.NET转ASP?

做不好就要失业了。请高手帮帮忙!

我所在的学校每个学生都有一个学号。是在入学时候按输入的学生ID=入学年份+学部+学号+性别;

下面是student表的结构。

id(int 4) sName(nvarchar 50) sNum(char 10) sDep(char 2) grade(char 2) sClass(char 1) sSex(char 10) InPutTime(datetime 8)
824 某某某 2001020580 02 09 2 2006-2-22

主要是要生成sNum(char 10)这个学生ID。原来已有了.NET的程序生成。现在希望能转为ASP的方式生成。


.Net的生成代码如下:
//生成学生ID号
protected string sId()
{
string sId;//学生ID号
string sIn;//入学日期
string sDeps;//学部
string sSexs;//学生性别
string sNum;//学生学号
int yearin;//临时存放入学日期
DateTime thisDate = DateTime.Now;
int year = (int)thisDate.Year;
int month = (int)thisDate.Month;
switch(sDep.SelectedValue)
{
case "01" :
yearin = year-Int32.Parse(sGrade.SelectedValue);
break;
default :
yearin = year-Int32.Parse(sGrade.SelectedValue)+4;
break;
}
//学生性别
switch(sSex.SelectedValue)
{
case "男" :
sSexs = "1";
break;
default :
sSexs = "0";
break;
}
month = month/9; //学校的学年是从九月份开始
yearin = yearin + month; //入学日期,如果当前时间是九月到十二月则加一
sIn = yearin.ToString();
sDeps = sDep.SelectedValue;//学部
sNum = sNum_Get();//返回函数得到学生学号
sId = sIn+sDeps+sNum+sSexs;//学生ID=入学年份+学部+学号+性别;
return sId;
}

//生成学生学号
protected string sNum_Get()
{
int sNumInt=0;//临时存放学号,再转换成string
string sNum;

string sql = "select substring(sNum,7,3) as [学号] from student where sDep='"+sDep.SelectedValue.ToString().Trim()+"' and grade='"+sGrade.SelectedValue.ToString().Trim()+"' order by [学号]";
DataSet studentDs = new DataSet();
studentDs = sqlLink.myDataSet(ref studentDs,sql);
int numCount = studentDs.Tables[0].Rows.Count;

//如果numCount为零则学号为1,否则开始计算学号
if(numCount!=0)
{

//后一数据与前一数据相差大于等于2的话可以插入一新的数据
for(int i=0;i<numCount-1;i++)
{
if(Convert.ToInt32(studentDs.Tables[0].Rows[i+1][0])-Convert.ToInt32(studentDs.Tables[0].Rows[i][0])>=2)
{
sNumInt = Convert.ToInt32(studentDs.Tables[0].Rows[i][0])+1;
break;
}
}

//当遍历之后找不到后一数据与前一数据相差大于等于2的数据,则sNumInt为最后一数据加1
if(sNumInt == 0)
{
sNumInt = Convert.ToInt32(studentDs.Tables[0].Rows[numCount-1][0])+1;
}
}
else
{
sNumInt = 1;
}
string sNumPre=null;//到目前为止生成的sNumInt的前面的"0"
sNum = sNumInt.ToString();
switch(sNum.Length)
{
case 1 :
sNumPre = "00";
break;
case 2 :
sNumPre = "0";
break;
default :
sNumPre = "";
break;
}

sNum = sNumPre+sNum;//最终生成的学号

return sNum;
}
}
}


请高手帮忙转成ASP的,不知道行不行。谢谢了。

[此贴子已经被作者于2006-6-12 11:15:13编辑过]

搜索更多相关主题的帖子: NET ASP 失业 char 学号 
2006-06-12 11:14
威风八面
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2006-6-12
收藏
得分:0 

全部代码如下:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace cas
{
/// <summary>
/// student 的摘要说明。
/// </summary>
public class student : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.Label Label4;
protected System.Web.UI.HtmlControls.HtmlForm Form1;
protected System.Web.UI.WebControls.TextBox sName;
protected System.Web.UI.WebControls.DropDownList sGrade;
protected System.Web.UI.WebControls.TextBox sClass;
protected System.Web.UI.WebControls.DropDownList sDep;
protected System.Web.UI.WebControls.TextBox sBorn;
protected System.Web.UI.WebControls.DropDownList sSex;
protected System.Web.UI.WebControls.HyperLink HyperLink1;
protected System.Web.UI.WebControls.Button Button1;

private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(Session["username"]==null)
{
Response.Redirect("login.aspx");
}
}

#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void Button1_Click(object sender, System.EventArgs e)
{
Button1.Enabled = false;
string insertSql = "insert into student(sName,sNum,sDep,grade,sClass,sSex,sBorn) values('"+sName.Text.ToString()+"','"+sId();
insertSql += "','"+sDep.SelectedItem.Value.ToString()+"','"+sGrade.SelectedItem.Value.ToString()+"','"+sClass.Text.ToString()+"','"+sSex.Selec-tedValue+"','"+sBorn.Text.ToString()+"')";
//Response.Write(insertSql);
sqlLink.cmdExcuteQuery(insertSql);
sqlLink.odcClose();
Response.Write("<script>alert('添加成功!');location.href('student.aspx')</script>");
//Response.Write(sNum_Get());
}

//生成学生ID号
protected string sId()
{
string sId;//学生ID号
string sIn;//入学日期
string sDeps;//学部
string sSexs;//学生性别
string sNum;//学生学号
int yearin;//临时存放入学日期
DateTime thisDate = DateTime.Now;
int year = (int)thisDate.Year;
int month = (int)thisDate.Month;
switch(sDep.SelectedValue)
{
case "01" :
yearin = year-Int32.Parse(sGrade.SelectedValue);
break;
default :
yearin = year-Int32.Parse(sGrade.SelectedValue)+4;
break;
}
//学生性别
switch(sSex.SelectedValue)
{
case "男" :
sSexs = "1";
break;
default :
sSexs = "0";
break;
}
month = month/9; //学校的学年是从九月份开始
yearin = yearin + month; //入学日期,如果当前时间是九月到十二月则加一
sIn = yearin.ToString();
sDeps = sDep.SelectedValue;//学部
sNum = sNum_Get();//返回函数得到学生学号
sId = sIn+sDeps+sNum+sSexs;//学生ID=入学年份+学部+学号+性别;
return sId;
}

//生成学生学号
protected string sNum_Get()
{
//string numSql = "select [学号] from [基本情况表] where [职业]='"+sDep.SelectedValue.ToString().Trim()+"' and [年级]='"+sGrade.SelectedValue.ToString().Trim()+"' order by [学号]";
int sNumInt=0;//临时存放学号,再转换成string
string sNum;


string sql = "select substring(sNum,7,3) as [学号] from student where sDep='"+sDep.SelectedValue.ToString().Trim()+"' and grade='"+sGrade.SelectedValue.ToString().Trim()+"' order by [学号]";
DataSet studentDs = new DataSet();
studentDs = sqlLink.myDataSet(ref studentDs,sql);
int numCount = studentDs.Tables[0].Rows.Count;

//如果numCount为零则学号为1,否则开始计算学号
if(numCount!=0)
{

//后一数据与前一数据相差大于等于2的话可以插入一新的数据
for(int i=0;i<numCount-1;i++)
{
if(Convert.ToInt32(studentDs.Tables[0].Rows[i+1][0])-Convert.ToInt32(studentDs.Tables[0].Rows[i][0])>=2)
{
sNumInt = Convert.ToInt32(studentDs.Tables[0].Rows[i][0])+1;
break;
}
}

//当遍历之后找不到后一数据与前一数据相差大于等于2的数据,则sNumInt为最后一数据加1
if(sNumInt == 0)
{
sNumInt = Convert.ToInt32(studentDs.Tables[0].Rows[numCount-1][0])+1;
}
}
else
{
sNumInt = 1;
}
string sNumPre=null;//到目前为止生成的sNumInt的前面的"0"
sNum = sNumInt.ToString();
switch(sNum.Length)
{
case 1 :
sNumPre = "00";
break;
case 2 :
sNumPre = "0";
break;
default :
sNumPre = "";
break;
}

sNum = sNumPre+sNum;//最终生成的学号

return sNum;
}
}
}

2006-06-14 11:15
快速回复:[求助]把.NET转ASP?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.027448 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved