public FmAdminMain(FmLogin fmLogin, UserModel userModel)
 {
     this.fmLogin = fmLogin;
     InitializeComponent();
     this.fmLogin.Hide();
     this.userModel = userModel;
 }
 public int CheckPasswd(string username, string password)
 {
     UserModel userModel = new UserModel();
     try
     {
         MySqlConnection conn = GetConn.getConn();
         conn.Open();
         MySqlCommand cmd = new MySqlCommand("select * from `tb_user` where `username`=@username and `password`=@password", conn);
         cmd.Parameters.AddWithValue("@username", username);
         cmd.Parameters.AddWithValue("@password", password);
         MySqlDataReader reader = cmd.ExecuteReader();
         int type;
         if (reader.Read())
         {
             userModel.Type = (int)reader["type"];
             type = userModel.Type;
             conn.Close();
             return type;
         }
         else
         {
             conn.Close();
             return 0;
         }
     }
     catch (Exception)
     {
         return 0;
     }
 }
 public FmTeacherMain(FmLogin fmLogin, UserModel userModel)
 {
     InitializeComponent();
     this.fmLogin = fmLogin;
     this.userModel = userModel;
     fmLogin.Hide();
 }
 public FmStudentMain(FmLogin fmLogin, UserModel userModel)
 {
     InitializeComponent();
     this.fmLogin = fmLogin;
     this.userModel = userModel;
     StudentBusiness sBusiness = new StudentBusiness();
     this.studentModel = sBusiness.getStuBySid(sBusiness.getSidByUid(userModel.Uid));
     fmLogin.Hide();
 }
        private void button1_Click(object sender, EventArgs e)
        {
            string username = this.textBox1.Text;
            string password = this.textBox2.Text;
            int type = 0 ;
            if (username == "" || password == "")
            {
                MessageBox.Show("请输入用户名或密码");
                this.textBox1.Focus();
            }
            else
            {
                this.button1.Text = "正在登陆...";
                this.button1.Enabled = false;
                this.textBox1.Enabled = false;
                this.textBox2.Enabled = false;

                UserBusiness userBusiness = new UserBusiness();
                type = userBusiness.CheckPasswd(username, password);
                UserModel userModel = new UserModel();
                userModel.Username = username;
                userModel.Password = password;

                //1:学生
                if (type == 1)
                {
                    userModel.Uid = userBusiness.getUidByUsername(username);
                    FmStudentMain fmStudentMain = new FmStudentMain(this, userModel);
                    fmStudentMain.Show();
                }
                //2:老师
                else if (type == 2)
                {
                    userModel.Uid = userBusiness.getUidByUsername(username);
                    FmTeacherMain fmTeacherMain = new FmTeacherMain(this, userModel);
                    fmTeacherMain.Show();
                }
                //3:管理员
                else if (type == 3)
                {
                    userModel.Uid = userBusiness.getUidByUsername(username);
                    FmAdminMain fmAdminMain = new FmAdminMain(this, userModel);
                    fmAdminMain.Show();
                }
                //0:登陆失败
                else if (type == 0)
                {
                    MessageBox.Show("登陆失败,请重试");
                    this.button1.Text = "登陆";
                    this.button1.Enabled = true;
                    this.textBox1.Enabled = true;
                    this.textBox2.Enabled = true;
                }
            }
        }
Exemple #6
0
        public UserModel GetUser(string user)
        {
            var res = new UserModel();

            var Temp = new UserFile<UserModel>().Read(user);
            if (Temp != null)
            {
                res = Temp;
            }
            res.UserID = user;

            return res;
        }
 protected void Button1_Click(object sender, EventArgs e)
 {
     String name = this.InputName.Text;
     //若input没有设name="InputPwd",则Request那一句不行,得不到参数的值
     //Request.Form[XX] 是从url里取值
     String pwd = Request["InputPwd"];
     UserModel u = new UserModel(name, pwd);
     if (UserInfo.checkUser(u)) {
         Session.Add("user", name);
         Server.Transfer("carInfo.aspx");
     }
     else {
         //使用Response.Redirect的话,request的数据会消失(不确定是否request),要用session
         Page.ClientScript.RegisterStartupScript(this.GetType(), "tes", "<script>alert('没有此用户或密码错误');</script>");
         //Server.Transfer("Default.aspx");
     }
 }