Asp.net 项目短暂心得

最近做项目,因为基本都是从0开始,所以就是发现一个问题解决一个,上各种网站各种搜索引擎,翻墙次数也达到今年最多次了,怕被学校警告了哈哈,贴点代码以后查的时候方便:

登录注册:

public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            UserName.BackColor = System.Drawing.Color.Transparent;
            Session["name"] = UserName.Text;
        }

        protected void btncheck_Click(object sender, EventArgs e)
        {
             string UserName1 = UserName.Text.Trim();
             string PassWord1 = PassWord.Text.Trim();
             SqlConnection conn = new SqlConnection();//uid=;pwd=; 创建一个连接数据库的对象
             conn.ConnectionString = @"server=ACER\SQLEXPRESS;Integrated Security=true;Initial Catalog=GradeManage;database=vs_test"; //用这行登录访问所要的数据库
             string sqlString = "select  *  from [vstudent] where UserName='" + UserName1 + "' and PassWord='" + PassWord1 + "'"; //在数据库里面执行的语句

             SqlDataAdapter sda = new SqlDataAdapter(sqlString, conn);//创建DataAdapter数据适配器实例
             DataSet ds = new DataSet();//创建DataSet实例,里面可以放很多的table
             sda.Fill(ds);//使用DataAdapter的Fill方法(填充),调用SELECT命令
            if (ds.Tables[0].Rows.Count == 1)//ds里面的第一个表存在这一行数据 匹配成功
            {
                 
             //  Response.Write("<script language='javascript'>alert('登录成功!');history.back();</script>");
                //Response.Write("<script language='javascript'>alert('登录成功!');history.back();</script>;window.location.href='**界面.aspx'</script>");
               Response.Write("<script>location.href='**界面.aspx';</script>");
                //alert('登录成功!');
             //  TextBox1.Text = "登录成功";
            }
            else
            {
                
                Response.Write("<script language='javascript'>alert('登录失败!');history.back();</script>");
             }
           
        }

查看订单:

  protected void Page_Load(object sender, EventArgs e)
        {   //此处应用select 的sql语句
            
            string stuname = Session["name"].ToString();
            CekUserName.Text = stuname; // 通过名字查找
            string CekUserName1 = CekUserName.Text.Trim();
            SqlConnection conn = new SqlConnection();//uid=;pwd=; 创建一个连接数据库的对象
            conn.ConnectionString = @"server=ACER\SQLEXPRESS;Integrated Security=true;Initial Catalog=GradeManage;database=vs_test"; //用这行登录访问所要的数据库
           string SqlCek = @"select CustUserBegin,CustUserEnd,CustUserTime,CustUserPNum from StuOrder where CustUserName =  '" + CekUserName1 + "'";
           conn.Open();
           SqlCommand cmd = new SqlCommand(SqlCek, conn);
           SqlDataReader rdr = cmd.ExecuteReader();
           rdr.Read();
           CekUserBegin.Text += rdr[0];
           CekUserEnd.Text += rdr[1];
           CekUserTime.Text += rdr[2];
           CekUserPNum.Text += rdr[3];
           conn.Close();
           rdr.Close();
            /*  
            string sql = "select column1,column2....columnn from database where column = '" + textBox1.Text.Trim() + "'";
            conn.Open();
            SqlCommand cmd = new SqlCommand(sql, conn);
            SqlDataReader rdr = cmd.EndExecuteReader();
            rdr.Read();
            textBox2.Text += rdr[0];
            textBox2.Text += rdr[1];
            textBox2.Text += rdr[2];
            conn.Close();
            rdr.Close();*/
            /*string stubegin = Session["begin"].ToString();
            CekUserBegin.Text = stubegin;
            string stuend = Session["end"].ToString();
            CekUserEnd.Text = stuend;
            string stutime = Session["time"].ToString();
            CekUserTime.Text = stutime;
            string stupnum = Session["phonenumber"].ToString();
            CekUserPNum.Text = stupnum;
             */






        }

下订单:
tring CustUserName1 = Request.Form["CustUserName"];//获取窗体内的变量
            string CustUserSex1 = Request.Form["CustUserSex"];//获取窗体内的变量
            string CustUserBegin1 = Request.Form["CustUserBegin"];//获取窗体内的变量
            string CustUserEnd1 = Request.Form["CustUserEnd"];//获取窗体内的变量
            string CustUserTime1 = Request.Form["CustUserTime"];//获取窗体内的变量
            string CustUserAddr1 = Request.Form["CustUserAddr"];//获取窗体内的变量
            string CustUserPNum1 = Request.Form["CustUserPNum"];//获取窗体内的变量
            string CustUserEMail1 = Request.Form["CustUserEMail"];//获取窗体内的变量
                
            SqlConnection conn = new SqlConnection();//创建一个连接数据库的对象
            conn.ConnectionString = @"server=ACER\SQLEXPRESS;Integrated Security=true;Initial Catalog=GradeManage;database=vs_test";
            string sqlString = "Insert into StuOrder(CustUserName,CustUserSex,CustUserBegin,CustUserEnd,CustUserTime,CustUserAddr,CustUserPNum,CustUserEMail) values ('" +CustUserName1  + "','" +CustUserSex1  + "','" +CustUserBegin1  + "','" +CustUserEnd1  + "','" +CustUserTime1  + "','" +CustUserAddr1  + "','" +CustUserPNum1  + "','" +CustUserEMail1  + "')";
            conn.Open(); // 打开所连接的数据库

            CustUserName.Text = sqlString  ;  
            SqlCommand cmd = new SqlCommand(sqlString, conn);
            cmd.ExecuteNonQuery();
            sqlString = "select*  from StuOrder where CustUserPNum = '" +CustUserPNum1 +"' and CustUserTime ='"+CustUserTime1+"'";
            SqlDataAdapter sda = new SqlDataAdapter(sqlString, conn);//适配器放数据集的
            DataSet ds = new DataSet();//数据集
            sda.Fill(ds,"Table");//表
          
            if (ds.Tables[0].Rows.Count ==1)
            {

                //  Response.Write("<script language='javascript'>alert('登录成功!');history.back();</script>");
                //Response.Write("<script language='javascript'>alert('登录成功!');history.back();</script>;window.location.href='**界面.aspx'</script>");
                //Response.Write("<script>alert('下单成功!');");
                Response.Write("<script>alert('下单成功!');location.href='**界面.aspx';</script>");
            }
            else
            {

                Response.Write("<script language='javascript'>alert('下单失败!');history.back();</script>");
            } 
           

心得:并不难。。

没有想象中难度那么大,而且做这个项目之前也对自己项目有了一条明确的项目规划,希望这个能真的做下去,解决一部分需求,而且发现google真是个好东西,至少比百度好

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。