Example #1
0
        private void dataGridView3_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex < 0)
            {
                return;
            }
            if (e.ColumnIndex == 9)         // 修改员工
            {
                if (MessageBox.Show("确定要修改此员工信息?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    //int Id = Convert.ToInt32(this.dataGridView3.Rows[e.RowIndex].Cells[0].Value);
                    //string result = await _sc.ModifyEmployee(Id);
                    int row = Convert.ToInt32(e.RowIndex);              // 获取当前的信息行
                    Employee employee = UserHelper.EmpList[row];        // 获取数据源中第row个员工的信息
                    EditEmployee editEmployee = new EditEmployee(employee, _sc);
                    editEmployee.ShowDialog();


                    if (editEmployee.DialogResult == DialogResult.OK)
                    {
                        editEmployee.Close();

                        BindEmployee(0);
                    }
                }
            }
            else if (e.ColumnIndex == 10)  // 重置密码
            {
                String Name = this.dataGridView3.Rows[e.RowIndex].Cells[1].Value.ToString();
                if (MessageBox.Show("确定重置员工" + Name + "的密码?员工密码将被重置为111", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    int Id = Convert.ToInt32(this.dataGridView3.Rows[e.RowIndex].Cells[0].Value);
                    String Username = this.dataGridView3.Rows[e.RowIndex].Cells[2].Value.ToString();
                    String Password = "******";
                    User user = new User { Username = Username, Password = Password };
                    string result = _sc.ModifyEmployeePassword(user);      //  重置员工密码

                    if (result == Response.MODIFY_EMP_PWD_SUCCESS.ToString())
                    {
                        MessageBox.Show("重置密码成功!", "提示", MessageBoxButtons.OK);
                    }
                    else if (result == "服务器连接中断")
                    {
                        MessageBox.Show("服务器连接中断,重置密码失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        MessageBox.Show("重置密码成功失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    BindEmployee(0);
                }
            }
            else if (e.ColumnIndex == 11)         // 删除员工
            {
                if (MessageBox.Show("确定要删除此人员?\n危险操作,谨慎进行\n由于该员工可能关联了很多会签单模版以及会签单信息,请谨慎操作", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    int Id = Convert.ToInt32(this.dataGridView3.Rows[e.RowIndex].Cells[0].Value);
                    string result = _sc.DeleteEmployee(Id);

                    if (result == Response.DELETE_EMPLOYEE_SUCCESS.ToString())
                    {
                        MessageBox.Show("删除人员成功!", "提示", MessageBoxButtons.OK);
                    }
                    else if (result == "服务器连接中断")
                    {
                        MessageBox.Show("服务器连接中断,删除失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else if (result == Response.DELETE_EMPLOYEE_EXIST_CONTRACT.ToString())
                    {
                        MessageBox.Show("该人员存在会签单信息中,无法删除!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else if (result == Response.DELETE_EMPLOYEE_EXIST_CONTEMP.ToString())
                    {
                        MessageBox.Show("该人员存在会签单模版信息中,无法删除!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else
                    {
                        MessageBox.Show("删除人员失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    BindEmployee(0);
                }
            }
        }
Example #2
0
        private async void button1_Click(object sender, EventArgs e)                //添加人员
        {
            //  首先进行容错
            if (this.Position.Text.Trim() == ""
            || this.UserName.Text.Trim() == ""
            || this.UserPassword.Text.Trim() == "")
            {
                MessageBox.Show("请将信息填写完整!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (this.CanSign.Checked
            && this.pictureBox1.ImageLocation == null)
            {
                MessageBox.Show("签字人需要提交签字图片!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (UserHelper.EmpList.Where(o => o.User.Username == this.UserName.Text.Trim()).ToList().Count > 0)
            {
                MessageBox.Show("员工信息已经存在,无法再次插入\n请检查用户名是否与他人重复!!!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            Employee emp = new Employee();
            emp.Name = this.eName.Text.Trim();

            Department d = new Department();
            d.Id = Convert.ToInt32(this.SelectedDepartment.SelectedValue);
            d.Name = this.SelectedDepartment.SelectedItem.ToString();
            emp.Department = d;

            emp.Position = this.Position.Text.Trim();
            User u = new User();
            u.Username = this.UserName.Text.Trim();
            u.Password = this.UserPassword.Text.Trim();
            emp.User = u;

            if (this.CanSubmit.Checked)
            {
                emp.CanSubmit = 1;
            }
            else
            {
                emp.CanSubmit = 0;
            }

            if (this.CanSign.Checked)
            {
                emp.CanSign = 1;
            }
            else
            {
                emp.CanSign = 0;
            }

            if (this.CanAdmin.Checked)
            {
                emp.IsAdmin = 1;
            }
            else
            {
                emp.IsAdmin = 0;
            }

            if (this.CanStatistic.Checked)
            {
                emp.CanStatistic = 1;
            }
            else
            {
                emp.CanStatistic = 0;
            }

            int id = _sc.InsertEmployee(emp);
            if (id == -2)
            {
                MessageBox.Show("员工信息已经存在,无法再次插入\n请检查用户名是否与他人重复!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else if (id == -1)
            {
                MessageBox.Show("添加人员失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else if (id == 0)
            {
                MessageBox.Show("服务器连接中断!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                MessageBox.Show("添加人员成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                if (this.CanSign.Checked && this.pictureBox1.ImageLocation != null)
                {
                    await _sc.UploadPicture(id, this.pictureBox1.ImageLocation);
                }
            }
            BindEmployee(0);
        }
        /// <summary>
        /// 登陆验证
        /// </summary>
        /// <param name="UserName"></param>
        /// <param name="PassWord"></param>
        /// <returns></returns>
        public Task<Employee> Login(string UserName, string PassWord)
        {
            return Task.Factory.StartNew(() =>
            {
                    User user = new User { Username = UserName, Password = PassWord };
                    SocketMessage sm = new SocketMessage(Request.LOGIN_REQUEST, user);
                    try
                    {
                        //  scoket发送请求信息
                        ClientSocket.Send(Encoding.UTF8.GetBytes(sm.Package));

                        //socket接收信息
                        recLength = ClientSocket.Receive(recivebuffer);
                        string recMsg = Encoding.UTF8.GetString(recivebuffer, 0, recLength);
                        string[] Msg = recMsg.Split(SocketMessage.DEFAULT_SEPARATOR);
                        
                        if (Msg[0] == Response.LOGIN_SUCCESS.ToString().Trim())
                        {
                            //将接收的信息(json格式)转化为类
                            Employee emp = new Employee();
                            emp = JsonConvert.DeserializeObject<Employee>(Msg[2]);

                            return emp;
                        }
                        else
                        {
                            Logging.AddLog("登录失败!");
                            return null;
                        }
                    }
                    catch
                    {
                        if (ClientSocket.Connected)
                        {
                            return null;
                        }
                        else
                        {
                            Logging.AddLog("连接服务器失败!");
                            return null;
                        }
                    }
                });
        }
         public String ModifyEmployeePassword(User user)
         {
             //return Task.Factory.StartNew(() =>
             {
                 try
                 {
                     SocketMessage sm = new SocketMessage(Request.MODIFY_EMP_PWD_REQUEST, user);
                     ClientSocket.Send(Encoding.UTF8.GetBytes(sm.Package));

                     recLength = ClientSocket.Receive(recivebuffer);
                     string recMsg = Encoding.UTF8.GetString(recivebuffer, 0, recLength);

                     string[] Msg = recMsg.Split(SocketMessage.DEFAULT_SEPARATOR);

                     if (Msg[0] == Response.MODIFY_EMP_PWD_SUCCESS.ToString())
                     {
                     }
                     else
                     {
                         Logging.AddLog("重置用户密码失败!");
                     }
                     return Msg[0];
                 }
                 catch
                 {
                     Logging.AddLog("重置用户密码失败(服务器连接中断)!");
                     return "服务器连接中断";
                 }
             //});
             }
         }
Example #5
0
        private async void Submit_Click(object sender, EventArgs e)                       //登陆验证
        {
            string username = this.UserName.Text.Trim();
            string password = this.PassWord.Text.Trim();

            if (username == "")
            {
                errormessage.IsBalloon = true;
                errormessage.SetToolTip(this.UserName, "请填写用户名后再登录");
                errormessage.Show("请填写用户名后再登录", this.UserName, 1, this.UserName.Height / 2, 2000);
                errormessage.UseFading = false;
                UserName.Focus();
                return;
            }
            else if (password == "")
            {
                errormessage.IsBalloon = true;
                errormessage.SetToolTip(this.PassWord, "请填写密码后再登录");
                errormessage.Show("请填写密码后再登录", this.PassWord, 1, this.PassWord.Height / 2, 2000);
                errormessage.UseFading = false;
                PassWord.Focus();
                return;
            }
            else
            {
                User user = new User();
                //BUser bUser = new BUser();
                FileStream fs = new FileStream("data.bin", FileMode.Create);
                BinaryFormatter bf = new BinaryFormatter();
                user.Username = username;
                if (this.RemeberPassword.Checked)       //  如果单击了记住密码的功能
                {   //  在文件中保存密码
                    user.Password = password;
                }
                else
                {   //  不在文件中保存密码
                    user.Password = "";
                }
                
                //  选在集合中是否存在用户名 
                if (users.ContainsKey(user.Username))
                {
                    users.Remove(user.Username);
                }
                users.Add(user.Username, user);
                //要先将User类先设为可以序列化(即在类的前面加[Serializable])
                bf.Serialize(fs, users);
                //user.Password = this.PassWord.Text;
                fs.Close();
            
                try
                {
                    _sc = new SignSocketClient();
                    cmd.ShowOpaqueLayer(AllForm, 125, true, true, "正在登录");
                    Employee emp = new Employee();

                    emp = await _sc.Login(username, password);

                    if (emp != null)
                    {
                        UserHelper.UserInfo = emp;
                        this.DialogResult = DialogResult.OK;
                        cmd.HideOpaqueLayer();
                        this.Close();
                        
                        Logging.AddLog("用户:" + emp.Name + "登陆成功!");
                    }
                    else
                    {
                        cmd.HideOpaqueLayer();
                        PassWord.Text = "";
                        errormessage.IsBalloon = true;
                        errormessage.SetToolTip(this.PassWord, "用户名与密码不匹配");
                        errormessage.Show("用户名与密码不匹配", this.PassWord, 1, this.PassWord.Height / 2, 2000);
                        errormessage.UseFading = false;
                        PassWord.Focus();
                        return;
                    }
                }
                catch
                {
                    MessageBox.Show("无法连接服务器", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
        }
Example #6
0
        private void buttonModifyPWDConfirm_Click(object sender, EventArgs e)
        {
            String username = UserHelper.UserInfo.User.Username;
            String oldPassword = this.textBoxOldPassword.Text.Trim();
            String newPassword = this.textBoxNewPassword.Text.Trim();
            String rePassword = this.textBoxRePassword.Text.Trim();

            if (oldPassword == ""
             || newPassword == ""
             || rePassword == "")
            {
                MessageBox.Show("请填写完整信息", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            else if (newPassword != rePassword)
            {
                MessageBox.Show("重复输入的新密码不同,无法修改", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;

            }
            else if (newPassword == oldPassword)
            {
                MessageBox.Show("新密码与原密码相同,无需修改", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            else if (oldPassword != UserHelper.UserInfo.User.Password)
            {

                MessageBox.Show("原密码验证失败,无法修改", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            // 用户修改密码
            User user = new User
            {
                Username = username,
                Password = newPassword
            };
            String result = _sc.ModifyEmployeePassword(user);

            if (result == Response.MODIFY_EMP_PWD_SUCCESS.ToString())
            {
                MessageBox.Show("修改密码成功!", "提示", MessageBoxButtons.OK);
                UserHelper.UserInfo.User.Password = newPassword;
            }
            else if (result == "服务器连接中断")
            {
                MessageBox.Show("服务器连接中断,修改密码失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {

                MessageBox.Show("修改密码失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }