Пример #1
0
        private void btnEdit_Click(object sender, EventArgs e)
        {
            if (isEdit)
            {
                // MessageBox.Show("hiii");
                if (ValidateChildren(ValidationConstraints.Enabled))
                {
                    string   tenAD    = txtTenAD.Text.Trim();
                    string   gioiTinh = cbxGioiTinh.SelectedIndex == 1 ? gioiTinh = "Nữ" : gioiTinh = "Nam";
                    DateTime ngaySinh = dtpNgaySinh.Value;
                    string   sdt      = txtSDT.Text.Trim();
                    string   email    = txtEmail.Text.Trim();
                    string   diaChi   = txtDiaChi.Text.Trim();

                    ClassEmployee.Employee empl = new ClassEmployee.Employee()
                    {
                        TenNV = tenAD, GioiTinh = gioiTinh, NgaySinh = ngaySinh, SDT = sdt, Email = email, DiaChi = diaChi, MaNV = MaNV
                    };
                    if (ClassEmployee.HandleEmployee.Instance.Edit(empl))
                    {
                        MessageBox.Show("Cập nhập thông tin thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        LoadInfoEmpl();
                    }
                    else
                    {
                        MessageBox.Show("Cập nhập thông tin thất bại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    isEdit       = !isEdit;
                    btnEdit.Text = "Chỉnh sửa";
                }
                else
                {
                    MessageBox.Show("Thao tác thất bại, Vui lòng xem lại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                isEdit       = !isEdit;
                btnEdit.Text = "Cập Nhật";

                txtTenAD.ReadOnly   = false;
                txtSDT.ReadOnly     = false;
                txtEmail.ReadOnly   = false;
                txtDiaChi.ReadOnly  = false;
                dtpNgaySinh.Enabled = true;
                cbxGioiTinh.Enabled = true;
            }
        }
Пример #2
0
        private void btnLuu_Click(object sender, EventArgs e)
        {
            if (ValidateChildren(ValidationConstraints.Enabled))
            {
                string   maNV     = txtMaNV.Text.Trim();
                string   tenNV    = txtTenNV.Text.Trim();
                string   gioiTinh = cbxGioiTinh.SelectedIndex == 1 ? gioiTinh = "Nữ" : gioiTinh = "Nam";
                DateTime ngaySinh = dtpNgaySinh.Value;
                string   sdt      = txtSDT.Text.Trim();
                string   email    = txtEmail.Text.Trim();
                string   diaChi   = txtDiaChi.Text.Trim();

                ClassEmployee.Employee employee = new ClassEmployee.Employee()
                {
                    MaNV = maNV, TenNV = tenNV, GioiTinh = gioiTinh, NgaySinh = ngaySinh, SDT = sdt, Email = email, DiaChi = diaChi
                };

                if (isSave)
                {
                    if (ClassEmployee.HandleEmployee.Instance.Add(employee))
                    {
                        ResetValue();
                        frmEmployee_Load(sender, e);
                        LoadDGV();
                    }
                    else
                    {
                        MessageBox.Show("Thêm nhân viên thất bại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                    if (ClassEmployee.HandleEmployee.Instance.Edit(employee))
                    {
                        ResetValue();
                        frmEmployee_Load(sender, e);
                        LoadDGV();
                    }
                    else
                    {
                        MessageBox.Show("Sửa nhân viên thất bại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            else
            {
                MessageBox.Show("Thao tác thất bại, Vui lòng xem lại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }