Example #1
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);
        }