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); }
private async void buttonModify_Click(object sender, EventArgs e) { // 首先进行容错 if (this.textBoxName.Text.Trim() == "" || this.textBoxPosition.Text.Trim() == "") { MessageBox.Show("请将信息填写完整!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (this.CanSign.Checked && this.PictureBox.ImageLocation == null) //if (this.m_isRepicture == false) { MessageBox.Show("签字人需要提交签字图片!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } //if (UserHelper.EmpList.Where(o => o. == this.textBoxName.Text).ToList().Count > 0) //{ // MessageBox.Show("员工信息已经存在,无法再次插入\n请检查用户名是否与他人重复!!!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); // return; //} try { this.m_employee.Name = this.textBoxName.Text; this.m_employee.Department.Id = Convert.ToInt32(this.comboBoxDepartment.SelectedValue); this.m_employee.Department.Name = this.comboBoxDepartment.SelectedItem.ToString(); this.m_employee.Position = this.textBoxPosition.Text; if (this.CanSubmit.Checked) { this.m_employee.CanSubmit = 1; } else { this.m_employee.CanSubmit = 0; } if (this.CanSign.Checked) { this.m_employee.CanSign = 1; this.PicturrName.Visible = true; // 图片路径 this.UploadButton.Visible = true; // 上传按钮 this.PictureBox.Visible = true; // } else { this.m_employee.CanSign = 0; this.PicturrName.Visible = false; this.UploadButton.Visible = false; this.PictureBox.Visible = false; // } if (this.CanAdmin.Checked) { this.m_employee.IsAdmin = 1; } else { this.m_employee.IsAdmin = 0; } if (this.CanStatistic.Checked) { this.m_employee.CanStatistic = 1; } else { this.m_employee.CanStatistic = 0; } string result = _sc.ModifyEmployee(this.m_employee); if (result == Response.MODIFY_EMPLOYEE_SUCCESS.ToString()) { MessageBox.Show("修改员工信息成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); //////////////////////////////////////// // 绑定底层数据信息 //UserHelper.UserInfo = this.m_employee; //////////////////////////////////////// if (this.CanSign.Checked && this.PictureBox.ImageLocation != null && this.m_isRepicture == true) { await _sc.UploadPicture(this.m_employee.Id, this.PictureBox.ImageLocation); MessageBox.Show("重新上传签字信息成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else if (result == "服务器连接中断") { MessageBox.Show("服务器连接中断,修改员工信息失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show("修改员工信息失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } this.DialogResult = DialogResult.OK; } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }