Beispiel #1
0
 private void btnModify_Click(object sender, EventArgs e)
 {
     if (txtOldPass.Text.Trim() == "")
     {
         toolTip1.Show("原密码不能为空!", txtOldPass, 0, txtOldPass.Height, 2000);
         return;
     }
     if (txtNewPass.Text.Trim() == "")
     {
         toolTip1.Show("新密码不能为空!", txtNewPass, 0, txtNewPass.Height, 2000);
         return;
     }
     if (txtRePass.Text.Trim() == "")
     {
         toolTip1.Show("新密码不能为空!", txtRePass, 0, txtRePass.Height, 2000);
         return;
     }
     if (txtNewPass.Text.Trim() != txtRePass.Text.Trim())
     {
         toolTip1.Show("两次密码输入不一致!", txtRePass, 0, txtRePass.Height, 2000);
         return;
     }
     try
     {
         string oldPass = txtOldPass.Text.Trim();
         oldPass = Classes.MD5.Md5Encrypt(oldPass);
         T_UsersTableAdapter adapter = new T_UsersTableAdapter();
         var mTable = adapter.GetDataByLoginName(txtLoginName.Text.Trim());
         if (mTable.Rows.Count > 0)
         {
             var mRow = (销售管理.DAL.DataSetUsers.T_UsersRow)mTable.Rows[0];
             if (oldPass != mRow.PassWord)
             {
                 MessageBox.Show("原密码输入错误");
                 return;
             }
             int ret = adapter.UpdatePass(Classes.MD5.Md5Encrypt(txtNewPass.Text.Trim()), txtLoginName.Text.Trim(), oldPass);
             if (ret > 0)
             {
                 MessageBox.Show("修改成功");
                 return;
             }
             else
             {
                 MessageBox.Show("修改失败");
                 return;
             }
         }
         else
         {
             MessageBox.Show("没有找到此用户信息");
             return;
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message.ToString());
     }
 }
Beispiel #2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            int ret = 0;

            btnAdd.Enabled = true;

            if (txtLoginName.Text.Trim() == "")
            {
                toolTip1.Show("登录名不能为空", txtLoginName, 0, txtLoginName.Height, 2000);
                return;
            }
            if (txtUserName.Text.Trim() == "")
            {
                toolTip1.Show("用户名不能为空", txtUserName, 0, txtUserName.Height, 2000);
                return;
            }
            //if (txtPass.Text.Trim() == "")
            //{
            //    toolTip1.Show("密码不能为空", txtPass, 0, txtPass.Height, 2000);
            //    return;
            //}
            //if (txtRePass.Text.Trim() == "")
            //{
            //    toolTip1.Show("确认密码不能为空", txtRePass, 0, txtRePass.Height, 2000);
            //    return;
            //}
            //if (txtPass.Text.Trim() != txtRePass.Text.Trim())
            //{
            //    toolTip1.Show("两次密码不一致", txtRePass, 0, txtRePass.Height, 2000);
            //    return;
            //}

            try
            {
                if (mId >= 0)
                {
                    T_UsersTableAdapter adapter = new T_UsersTableAdapter();
                    var mTable = adapter.GetDataByLoginName(txtLoginName.Text.Trim());
                    if (mTable.Rows.Count > 0)
                    {
                        var mRow = (销售管理.DAL.DataSetUsers.T_UsersRow)mTable.Rows[0];
                        if (mRow.id != mId)
                        {
                            MessageBox.Show("此登录名已存在!");
                            txtLoginName.Focus();
                            txtLoginName.SelectionStart  = 0;
                            txtLoginName.SelectionLength = txtLoginName.Text.Length;
                            return;
                        }
                    }

                    ret = adapter.UpdateById(txtLoginName.Text.Trim(), txtUserName.Text.Trim(), cmbRight.Text, txtUserChar.Text.Trim(), cmbUserStatus.Text, mId);
                    if (ret > 0)
                    {
                        MessageBox.Show("修改成功");
                        tvShow();
                    }
                    else
                    {
                        MessageBox.Show("修改失败");
                    }
                }
                else
                {
                    T_UsersTableAdapter adapter = new T_UsersTableAdapter();
                    var mTable = adapter.GetDataByLoginName(txtLoginName.Text.Trim());
                    if (mTable.Rows.Count > 0)
                    {
                        MessageBox.Show("此登录名已存在!");
                        txtLoginName.Focus();
                        txtLoginName.SelectionStart  = 0;
                        txtLoginName.SelectionLength = txtLoginName.Text.Length;
                        return;
                    }
                    ret = adapter.Insert(txtLoginName.Text.Trim(), Classes.MD5.Md5Encrypt("1"), txtUserName.Text.Trim(), cmbRight.Text, cmbRight.Text, txtUserChar.Text.Trim(), cmbUserStatus.Text, 0, 0);
                    if (ret > 0)
                    {
                        MessageBox.Show("添加成功");
                        tvShow();
                        btnSave.Enabled = false;
                    }
                    else
                    {
                        MessageBox.Show("添加失败");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }