Exemple #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            MySqlHelper h = new MySqlHelper();

            try
            {
                if (this.textBox1.Text.Length == 0)
                {
                    MessageBox.Show("用户名不能为空!");
                }
                else if (this.textBox2.Text.Length == 0)
                {
                    MessageBox.Show("密码不能为空!");
                }
                else
                {
                    userCtrl  ctrl   = new userCtrl();
                    string    sql    = "select * from user where userName='******' and hashed_password='******'";
                    DataTable dtuser = h.ExecuteQuery(sql, CommandType.Text);//DBHelp.GetDataSet(sql);

                    if (dtuser.Rows.Count > 0)
                    {
                        if (dtuser.Rows[0]["isActive"].ToString() == "1")
                        {
                            saveLocal();
                            PropertyClass.SendNameValue = dtuser.Rows[0]["fullName"].ToString();
                            PropertyClass.UserId        = Convert.ToInt32(dtuser.Rows[0]["id"]);
                            //PropertyClass.SendPopedomValue = dtuser.Rows[0]["user_competence"].ToString();
                            //PropertyClass.Password = dtuser.Rows[0]["user_password"].ToString();
                            PropertyClass.Role = Convert.ToInt32(dtuser.Rows[0]["role"]);
                            MainForm mainform = new MainForm();
                            this.Hide();
                            mainform.ShowDialog();
                            this.Close();
                        }
                        else
                        {
                            MessageBox.Show("用户已被注销!");
                        }
                    }
                    else
                    {
                        MessageBox.Show("用户名或者密码错误!");
                        this.textBox2.Focus();
                        this.textBox2.SelectAll();
                    }
                }
            }
            catch (Exception)
            {
                MessageBox.Show("服务器登陆失败!");
                return;
            }
        }