default.aspx.cs

来自「水晶报表详细资料水晶报表详细资料水晶报表详细资料」· CS 代码 · 共 97 行

CS
97
字号
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page 
{
    SqlConnection myConn;
    SqlDataAdapter adapter;
    DataSet ds;
    SqlCommand myCmd;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.txtID.Text=GetStuID().ToString();
        }
    }
    public static  string stuID;
    protected string  GetStuID()
    { 
        myConn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"].ToString());
        string strSql = "select top 1 学生编号 as 学生编号 from tb_student order by 学生编号 Desc ";
        adapter = new SqlDataAdapter(strSql, myConn);
        ds = new DataSet();
        adapter.Fill(ds);
        if (ds.Tables[0].Rows.Count > 0)
        {
            int IDValue = int.Parse(ds.Tables[0].Rows[0][0].ToString())+1;
            stuID = IDValue.ToString();
            if (IDValue < 10)
            {
                stuID = "0000" + IDValue;
            }
            else if (IDValue >= 10 && IDValue < 100)
            {
                stuID = "000" + IDValue;
            }
            else if (IDValue >= 100 && IDValue < 1000)
            {
                stuID = "00" + IDValue;
            }
            else if (IDValue >= 1000 && IDValue < 10000)
            {
                stuID = "0" + IDValue;
            }
            else
            {
                stuID = IDValue.ToString();
            }
        }
        else
        {
            stuID = "0000";
        }
        return stuID;
    }
    protected void btnReg_Click(object sender, EventArgs e)
    {
        try
        {
            myConn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"].ToString());
            string strSql = "Insert into tb_Student(学生编号,学生姓名,学生性别,出生年月,家庭住址,家庭电话) ";
            strSql += "values('" + this.txtID.Text.Trim() + "','" + this.txtName.Text.Trim() + "','" + this.ddlSex.SelectedValue.ToString() + "','" + this.txtBirthday.Text.Trim() + "','" + this.txtHAddress.Text.Trim() + "','" + this.txtTel.Text.Trim() + "')";
            myCmd = new SqlCommand(strSql,myConn);
            myConn.Open();
            myCmd.ExecuteNonQuery();
            Response.Write("<script>alert('提交成功!');location='Default.aspx';</script>");
        }
        catch(Exception ex)
        {
            Response.Write(ex.ToString());
        }
        finally
        {
            myConn.Close();
            myCmd.Dispose();
        }  
    }
    protected void calDate_SelectionChanged(object sender, EventArgs e)
    {
        this.txtBirthday.Text = this.calDate.SelectedDate.ToShortDateString();
        this.calDate.Visible = false;
    }
    protected void btnSelDate_Click(object sender, EventArgs e)
    {
        calDate.Visible = true;

    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?