示例#1
0
        void InsertAdminInfo()
        {
            CDataBase.conn.ConnectionString = CDataBase.connStr;
            string psw     = CPublic.GetMd5Str(txtSAPassword.Text.Trim());
            string sqlStr1 = "insert into tbl_User values('" + txtSuperAdmin.Text.Trim() + "','" + psw.Trim() + "','超级管理员','是')";
            string sqlStr2 = "insert into tbl_Admin values('" + txtSuperAdmin.Text.Trim() + "','" +
                             txtSuperName.Text.Trim() + "','" + "000" + "','" + cmbSuperSex.Text.Trim() + "','" +
                             txtSuperAge.Text.Trim() + "','" + "超级管理员" + "','" + "2014-01-01" + "','" + "10000" + "')";

            if (CDataBase.UpdateDB(sqlStr1) && CDataBase.UpdateDB(sqlStr2))
            {
                MessageBox.Show("超级管理员: " + txtSuperAdmin.Text + " 注册成功!");
            }
        }
示例#2
0
 private void btnChagePassword_Click(object sender, EventArgs e)
 {
     try
     {
         if (CPublic.GetMd5Str(txtOldPassword.Text.Trim()) != CPublic.userInfo[1])
         {
             MessageBox.Show("旧密码错误,请重新输入", "提示");
             txtOldPassword.Text  = "";
             txtNewPassword1.Text = "";
             txtNewPassword2.Text = "";
             txtOldPassword.Focus();
         }
         else if (txtNewPassword1.Text.Trim() == "" && txtNewPassword2.Text.Trim() == "")
         {
             MessageBox.Show("密码不能为空", "提示");
             txtNewPassword1.Focus();
         }
         else if (txtNewPassword1.Text.Trim() == txtNewPassword2.Text.Trim())
         {
             string psw    = CPublic.GetMd5Str(txtNewPassword1.Text.Trim());
             string sqlStr = "update tbl_User set userPassword='******' where userName='******'";
             if (CDataBase.UpdateDB(sqlStr))
             {
                 CPublic.userInfo[1] = psw.Trim();
                 MessageBox.Show("修改成功,请记住您的新密码", "修改密码");
                 txtOldPassword.Text  = "";
                 txtNewPassword1.Text = "";
                 txtNewPassword2.Text = "";
             }
         }
         else
         {
             MessageBox.Show("两次输入的密码不一致", "提示");
             txtNewPassword1.Text = "";
             txtNewPassword2.Text = "";
             txtNewPassword1.Focus();
         }
     }
     catch (Exception ex)
     {
         CDataBase.conn.Close();
         MessageBox.Show(ex.Message);
     }
 }
示例#3
0
 private void btnRegedit_Click(object sender, EventArgs e)
 {
     try
     {
         if (btnRegedit.Text == "注册")
         {
             btnRegedit.Text   = "确定";
             btnCancel.Enabled = true;
             ObjOpen();
         }
         else if (txtUserName.Text.Trim() == "")
         {
             MessageBox.Show("用户名不能为空", "提示");
             txtUserName.Focus();
         }
         else if (txtPassword.Text.Trim() == "")
         {
             MessageBox.Show("密码不能为空", "提示");
             txtPassword.Focus();
         }
         else if (!UserNameExist(txtUserName.Text.Trim()))
         {
             MessageBox.Show("该用户已存在!", "提示");
             txtUserName.Text = "";
             txtPassword.Text = "";
             ObjOpen();
             btnRegedit.Text = "注册";
             txtUserName.Focus();
         }
         else
         {
             btnRegedit.Text = "注册";
             string psw    = CPublic.GetMd5Str(txtPassword.Text.Trim());
             string sqlStr = "insert into tbl_User values('" + txtUserName.Text.Trim() + "','" +
                             psw.Trim() + "','" + cmbPurview.Text.Trim() + "','是')";
             string regType = cmbPurview.Text.Trim();
             if (CDataBase.UpdateDB(sqlStr))
             {
                 MessageBox.Show(cmbPurview.Text + " " + txtUserName.Text + " 注册成功!\n" +
                                 "请进一步完善用户信息", "注册用户");
             }
             CPublic.userName = txtUserName.Text.Trim();
             if (regType == "普通管理员")
             {
                 if (ob_FrmCompleteAdminInfo == null || ob_FrmCompleteAdminInfo.IsDisposed)
                 {
                     ob_FrmCompleteAdminInfo = new FrmCompleteAdminInfo();
                     ob_FrmCompleteAdminInfo.Show();
                 }
                 else
                 {
                     ob_FrmCompleteAdminInfo.Activate();
                 }
             }
             else if (regType == "顾客")
             {
                 if (ob_FrmCompleteCustomerInfo == null || ob_FrmCompleteCustomerInfo.IsDisposed)
                 {
                     ob_FrmCompleteCustomerInfo = new FrmCompleteCustomerInfo();
                     ob_FrmCompleteCustomerInfo.Show();
                 }
                 else
                 {
                     ob_FrmCompleteCustomerInfo.Activate();
                 }
             }
             ClearAll();
             ObjClose();
             btnCancel.Enabled = false;
         }
     }
     catch (Exception ex)
     {
         CDataBase.conn.Close();
         MessageBox.Show(ex.Message);
         ClearAll();
         ObjClose();
         btnCancel.Enabled = false;
     }
 }
示例#4
0
 private void btnLogin_Click(object sender, EventArgs e)
 {
     try
     {
         if (txtUserName.Text.Trim() == "")
         {
             MessageBox.Show("用户名不能为空!", "错误");
             txtUserName.Focus();
             return;
         }
         else if (txtUserPassword.Text.Trim() == "")
         {
             MessageBox.Show("密码不能为空!", "错误");
             txtUserPassword.Focus();
             return;
         }
         this.Text   = "正在验证...";
         this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
         string psw    = CPublic.GetMd5Str(txtUserPassword.Text.Trim());
         string sqlStr = "select userPassword, userPurview, firstLogin from tbl_User where userName='******'";
         CDataBase.conn.ConnectionString = CDataBase.connStr;
         CDataBase.conn.Open();
         SqlCommand    cmd = new SqlCommand(sqlStr, CDataBase.conn);
         SqlDataReader sdr = cmd.ExecuteReader();
         if (!sdr.Read())
         {
             MessageBox.Show("用户名错误,请重新输入!", "错误");
             this.Cursor          = System.Windows.Forms.Cursors.Arrow;
             this.Text            = "登录";
             txtUserName.Text     = "";
             txtUserPassword.Text = "";
             txtUserName.Focus();
         }
         else if (sdr["userPassword"].ToString().Trim() == psw.Trim())
         {
             CPublic.userInfo[0] = txtUserName.Text.Trim();
             CPublic.userInfo[1] = psw.Trim();
             CPublic.userInfo[2] = sdr["userPurview"].ToString().Trim();
             CPublic.userInfo[3] = sdr["firstLogin"].ToString().Trim();
             this.Cursor         = System.Windows.Forms.Cursors.Arrow;
             this.Text           = "登录";
             if (CPublic.userInfo[2] == "顾客")
             {
                 FrmCustomerMain ob_FrmCustomerMain = new FrmCustomerMain();
                 ob_FrmCustomerMain.Show();
             }
             else
             {
                 FrmAdminMain ob_FrmAdminMain = new FrmAdminMain();
                 ob_FrmAdminMain.Show();
             }
             this.Hide();
             CDataBase.conn.Close();
             if (CPublic.userInfo[3] == "是")
             {
                 if (CPublic.userInfo[2] == "普通管理员")
                 {
                     MessageBox.Show("未设置个人信息,请先设置,否则一旦忘记密码,将无法找回!",
                                     "严重警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                     FrmInfoAdmin ob_FrmInformation = new FrmInfoAdmin();
                     ob_FrmInformation.Show();
                 }
                 else if (CPublic.userInfo[2] == "顾客")
                 {
                     MessageBox.Show("未设置个人信息,请先设置,否则一旦忘记密码,将无法找回!",
                                     "严重警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                     FrmInfoCustomer ob_FrmInformation = new FrmInfoCustomer();
                     ob_FrmInformation.Show();
                 }
             }
         }
         else
         {
             MessageBox.Show("密码错误,请重新输入!", "错误");
             this.Cursor          = System.Windows.Forms.Cursors.Arrow;
             this.Text            = "登录";
             txtUserPassword.Text = "";
             txtUserPassword.Focus();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "登录异常");
         this.Cursor          = System.Windows.Forms.Cursors.Arrow;
         this.Text            = "登录";
         txtUserName.Text     = "";
         txtUserPassword.Text = "";
         txtUserName.Focus();
     }
     finally
     {
         CDataBase.conn.Close();
     }
 }
 private void btnOK_Click(object sender, EventArgs e)
 {
     try
     {
         if (txtUserName.Text.Trim() == "")
         {
             MessageBox.Show("注册邮箱不能为空", "提示");
             txtUserName.Focus();
         }
         else if (!UserName(txtUserName.Text.Trim()))
         {
             MessageBox.Show("该用户已存在!", "提示");
             txtUserName.Text = "";
             txtUserName.Focus();
         }
         else if (txtName.Text.Trim() == "")
         {
             MessageBox.Show("姓名不能为空", "提示");
             txtName.Focus();
         }
         else if (txtPhone.Text.Trim() == "")
         {
             MessageBox.Show("电话不能为空", "提示");
             txtPhone.Focus();
         }
         else if (txtAddress.Text.Trim() == "")
         {
             MessageBox.Show("地址不能为空", "提示");
             txtAddress.Focus();
         }
         else if (txtPassword.Text.Trim() == "" && txtComfirmPassword.Text.Trim() == "")
         {
             MessageBox.Show("密码不能为空", "提示");
             txtPassword.Focus();
         }
         else if (txtPassword.Text.Trim() != txtComfirmPassword.Text.Trim())
         {
             MessageBox.Show("两次密码不一致", "提示");
             txtPassword.Text        = "";
             txtComfirmPassword.Text = "";
             txtPassword.Focus();
         }
         else
         {
             string sqlStr1 = "insert into tbl_User values('" + txtUserName.Text.Trim() + "','" +
                              CPublic.GetMd5Str(txtPassword.Text.Trim()) + "','" + "顾客" + "','" + "是" + "')";
             string sqlStr2 = "insert into tbl_Customer values('" + txtUserName.Text.Trim() + "','" +
                              txtName.Text.Trim() + "','" + txtPhone.Text.Trim() + "','" + txtAddress.Text.Trim() + "','" + "10000.00" + "')";
             if (CDataBase.UpdateDB(sqlStr1) && CDataBase.UpdateDB(sqlStr2))
             {
                 MessageBox.Show("顾客:" + txtUserName.Text + " 注册成功!", "恭喜");
             }
             this.Close();
         }
     }
     catch (Exception ex)
     {
         CDataBase.conn.Close();
         MessageBox.Show(ex.Message);
         this.Close();
     }
 }