コード例 #1
0
        /// <summary>
        /// khởi tạo 1 số thuộc tính khi tạo 1 nhân viên mới
        /// </summary>
        public void setup()
        {
            PeoPleBO nvbo = new PeoPleBO();

            nhanVien.ID = nvbo.GetIDNV() + 1;
            nhanVien.HD = DateTime.Now;
        }
コード例 #2
0
        private void cmbPB_ValuaChanged(object sender, EventArgs e)
        {
            ComboBox cmb = sender as ComboBox;

            PeoPleBO    bonv = new PeoPleBO();
            PhongBanDTO pb   = cmb.SelectedValue as PhongBanDTO;

            if (string.Compare(StringThongBao, "Edit") == 0 && Visiblenew == false)
            {
                if (pb.MaPhongBan == nhanVien.MaPB)
                {
                    int temp = nhanVien.MaCV;
                    List <ChucVuDTO> cvnew = new List <ChucVuDTO>(pb.CV);
                    if (nhanVien.MaCV == 1 || nhanVien.MaCV == 4)
                    {
                        int t = cvnew.Count;
                        for (int i = cvnew.Count - 1; i >= 0; i--)
                        {
                            if (cvnew[i] is NhanVienDTO || cvnew[i] is PhoPhongDTO)
                            {
                                cvnew.RemoveAt(i);
                            }
                        }
                        cmbPB.Enabled = false;
                        cmbCV.Enabled = false;
                    }
                    else
                    {
                        foreach (var item in cvnew)
                        {
                            if (item is TruongPhongDTO)
                            {
                                cvnew.Remove(item);
                                break;
                            }
                        }
                    }
                    cmbCV.DataSource    = cvnew;
                    cmbCV.DisplayMember = "nameCV";
                    cmbCV.TextValue     = temp.ToString();
                }

                return;
            }

            if (cmb.SelectedValue != null)
            {
                List <ChucVuDTO> cvnew = new List <ChucVuDTO>(pb.CV);
                Id_NQL         = bonv.test(pb.MaPhongBan);
                nhanVien.IDNQL = id_NQL;
                nhanVien.MaPB  = pb.MaPhongBan;
                nhanVien.KH    = pb.KyHieu;
                if (Id_NQL != 0)
                {
                    foreach (var item in cvnew)
                    {
                        if (item is TruongPhongDTO)
                        {
                            cvnew.Remove(item);
                            break;
                        }
                    }
                    nhanVien.KHNQL = pb.KyHieu;
                }
                else
                {
                    for (int i = cvnew.Count - 1; i >= 0; i--)
                    {
                        if (cvnew[i] is NhanVienDTO || cvnew[i] is PhoPhongDTO)
                        {
                            cvnew.RemoveAt(i);
                        }
                    }

                    nhanVien.IDNQL = null;
                    nhanVien.KHNQL = null;
                }
                cmbCV.DataSource    = cvnew;
                cmbCV.DisplayMember = "namecv";
            }
        }
コード例 #3
0
        /// <summary>
        /// Khi xóa nhân viên các trường hợp có thể xảy ra:
        /// Nếu là trưởng phòng thì chỉ có thể chỉnh sữa lại các thuộc tình
        /// Nếu . phải trưởng phòng thì xóa trực tiếp trong DB
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btDel_Click(object sender, EventArgs e)
        {
            if (dtgv.DataSource == null || row == -1 || dtgv.Rows[row].Cells["Mã Nhân Viên"].Value == null)
            {
                return;
            }
            PeoPleBO     nvbo = new PeoPleBO();
            int          idtp = nvbo.test(MaPB);
            int          id   = int.Parse(dtgv.Rows[row].Cells["Mã Nhân Viên"].Value.ToString());
            DialogResult result;

            if (id == idtp)
            {
                result = MessageBox.Show("Không thể xóa trưởng phong\n Bạn có muốn thay đổi trưởng phòng", "Remove", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result == DialogResult.Yes)
                {
                    PeopleDTO     nv;
                    PhongQuanLyBO bo = new PhongQuanLyBO();
                    bo.GetNhanVienDTO(out nv, id);
                    bo.XoaThanNhan(id);
                    if (nv.ID != 0)
                    {
                        nv.FName    = "";
                        nv.LName    = "";
                        nv.DOB      = new DateTime();
                        nv.HD       = new DateTime();
                        nv.GioiTinh = "";
                        nv.QueQuan  = "";
                        Form4 f4 = new Form4(true);
                        f4.TranslationPeople(nv, listPhongBan, "Edit", false);
                        f4.ShowDialog();
                        txttrang2.Text = null;
                        txttrang2.Text = txtTrang.Text;
                    }
                }
                return;
            }
            result = MessageBox.Show("Bạn có thực sự muốn xóa", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (result == DialogResult.Yes)
            {
                PhongQuanLyBO qlbo = new PhongQuanLyBO();
                //Lưu vào DB temp
                qlbo.SaveTemp(id);
                //Tiến hành xóa

                int kq = qlbo.XoaThanNhan(id);
                kq = qlbo.XoaNVKTKL(id);
                kq = qlbo.XoaNhanVien(id);

                if (kq != -1)
                {
                    MessageBox.Show("Xóa thành công", "Xóa");
                    row--;
                    txttrang2.Text = null;
                    txttrang2.Text = txtTrang.Text;
                }
                else
                {
                    MessageBox.Show("Thất bại", "Xóa");
                }
            }
        }