Exemplo n.º 1
0
        protected void btnRsgister_Click(object sender, EventArgs e)
        {
            Sign     si = new Sign();
            MallUser u  = new MallUser();

            //u.UserID自增长?????????????????????????????????????????????
            //    u.UserID = "2";
            u.UserName = tbxName.Text;
            u.Password = tbxPassword.Text;
            u.UserTel  = UserTel.Text;


            if (si.Reg(u))
            {
                //put in session,MainForm.aspx;
                Session["User"] = u;
                Response.Redirect("MainForm.aspx");
            }
            else
            {
                Label3.Text      = "对不起!用户名已占用,请选择其他用户名!";
                tbxName.Text     = "";
                UserTel.Text     = "";
                tbxPassword.Text = "";
            }
        }
Exemplo n.º 2
0
        public bool Reg(MallUser u)
        {
            // string db = Server.MapPath("/App_Data/bbs.mdb");
            //string strConn = "Data Source=" + db + ";Provider=Microsoft.Jet.OLEDB.4.0";
            OleDbConnection oleConnection = new OleDbConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ToString());
            OleDbCommand    comm          = oleConnection.CreateCommand();

            comm.CommandType = CommandType.Text;
            comm.CommandText = "select count(*) from MallUser where UserName like @username";
            OleDbParameter[] param =
            {
                new  OleDbParameter("@username", u.UserName)
            };
            comm.Parameters.AddRange(param);
            // string strCmd = "select count(*) from MallUser where UserName like @username";

            //oleConnection.ConnectionString = strConn;
            OleDbCommand myCommand = new OleDbCommand(comm.CommandText, oleConnection);

            myCommand.Connection.Open();
            int flag = 1;

            flag = (int)comm.ExecuteScalar();
            myCommand.Connection.Close();
            if (flag == 0)
            {
                //string str = "insert into MallUser ([UserID],[UserName],[PassWord],[UserTel]) values ('" + u.UserID + "','" + u.UserName + "','" + u.Password + "','" + u.UserTel + "')";
                string str = "insert into MallUser ([UserName],[PassWord],[UserTel]) values ('" + u.UserName + "','" + u.Password + "','" + u.UserTel + "')";

                //  Label3.Text = str;
                OleDbCommand myIns = new OleDbCommand(str, oleConnection);
                myIns.Connection.Open();
                myIns.ExecuteNonQuery();
                myIns.Connection.Close();
                oleConnection.Close();
                return(true);
                //  Session["username"] = tbxName.Text;
                //Session["UserTel"] = UserTel.Text;
                //  Response.Redirect("MainForm.aspx");
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 3
0
        protected void Btnlogin_Click(object sender, EventArgs e)
        {
            if (Name.Text == "" || Password.Text == "")
            {
                Response.Write("<script language=javascript>alert('用户名或密码不能为空!');</script>");
                return;
            }

            Log lo = new Log();

            if (lo.CheckUser(Name.Text, Password.Text))
            {
                Session["UserName"] = Name.Text;
                MallUser u = new MallUser();
                u.UserName = Name.Text;
                // u.Password = Password.Text;
                Session["user"] = u;
                // Session["user"] = Name.Text;


                if (Session["user"] != null)
                {
                    MallUser user = (MallUser)Session["user"];
                    // Response.Write(user.UserName);
                    //  Response.Write(user.Password);
                }
                Response.Redirect("MainForm.aspx");
            }
            else
            {
                Response.Write("<script language=javascript>alert('用户名或密码错误!');</script>");
                Name.Text     = "";
                Password.Text = "";
                Name.Focus();
            }
        }