示例#1
0
 // 添加管理员
 private void Button1_Click(object sender, EventArgs e)
 {
     adminName = textBox1.Text;
     pwd       = textBox2.Text;
     rePwd     = textBox3.Text;
     if (radioButton1.Checked)
     {
         changeStuPower = "1";
     }
     else
     {
         changeStuPower = "0";
     }
     if (radioButton3.Checked)
     {
         isSuperAdmin = "1";
     }
     else
     {
         isSuperAdmin = "0";
     }
     if (adminName != "" || pwd != "")
     {
         if (pwd == rePwd)
         {
             pwd = otherFunction.SHA1(pwd, Encoding.UTF8);
             DataSet  dataSet  = SqlFunction.GetDs("SELECT * FROM Admin Where adminName='" + adminName + "'");
             DataView dataView = dataSet.Tables[0].DefaultView;
             if (dataView.Count == 0)  // 先和数据库里的进行判断 是否存在
             {
                 String sqlLanguage = "INSERT Admin VALUES('" + adminName + "','" + pwd + "','" + changeStuPower + "','" + isSuperAdmin + "')";
                 if (SqlFunction.Execute(sqlLanguage) > 0)
                 {
                     MessageBox.Show("插入成功!");
                     GetNewValues();
                 }
                 else
                 {
                     MessageBox.Show("插入失败!");
                 }
             }
             else
             {
                 MessageBox.Show("已经存在当前管理员");
             }
         }
         else
         {
             MessageBox.Show("确认密码不相符,请确认密码");
         }
     }
     else
     {
         MessageBox.Show("用户名和密码均不能空!!");
     }
 }
        private void Button1_Click(object sender, EventArgs e)
        {
            String adminName = textBox1.Text;
            String pwd       = textBox2.Text;
            String rePwd     = textBox3.Text;

            if (adminName != "" || pwd != "")
            {
                if (pwd == rePwd)
                {
                    pwd = otherFunction.SHA1(pwd, Encoding.UTF8);
                    DataSet  dataSet  = SqlFunction.GetDs("SELECT * FROM Admin Where adminName='" + adminName + "'");
                    DataView dataView = dataSet.Tables[0].DefaultView;
                    if (dataView.Count == 0 || adminName == otherFunction.LoginName)
                    {
                        if (MessageBox.Show("确认修改?", "是否提交修改?", MessageBoxButtons.OKCancel) == DialogResult.OK)
                        {
                            String sqlLanguage = "UPDATE Admin SET adminName='" + adminName + "',pwd='" + pwd + "' WHERE adminName = '" + otherFunction.LoginName + "'";
                            if (SqlFunction.Execute(sqlLanguage) > 0)
                            {
                                MessageBox.Show("修改成功!");
                                otherFunction.LoginName = adminName;
                            }
                            else
                            {
                                MessageBox.Show("妈呀!修改失败咯!!!!怎么肥事?");
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("已经存在当前管理员");
                    }
                }
                else
                {
                    MessageBox.Show("确认密码不相符,请确认密码");
                }
            }
            else
            {
                MessageBox.Show("用户名和密码均不能空!!");
            }
        }
        private void Button1_Click(object sender, EventArgs e)
        {
            string   adminName = textBox1.Text, pwd = otherFunction.SHA1(textBox2.Text, Encoding.UTF8);
            DataSet  dataSet  = SqlFunction.GetDs("SELECT * FROM Admin WHERE adminName='" + adminName + "' AND pwd='" + pwd + "'");
            DataView dataView = dataSet.Tables[0].DefaultView;

            if (dataView.Count != 0)
            {
                otherFunction.LoginName      = dataView[0]["adminName"].ToString();
                otherFunction.ChangeStuPower = dataView[0]["changeStuPower"].ToString();
                otherFunction.IsSuperAdmin   = dataView[0]["isSuperAdmin"].ToString();
                if (MessageBox.Show("登陆成功", "登陆成功,是否进入系统?", MessageBoxButtons.OKCancel) == DialogResult.OK)
                {
                    this.Hide();
                    MainFram mainFram = new MainFram();
                    mainFram.ShowDialog();
                }
            }
            else
            {
                MessageBox.Show("用户名或密码错误!!");
            }
        }