private void dataGridPhongBan_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     updatePhongBan           = _phongBanServices.GetPhongBanById(Convert.ToInt32(dataGridPhongBan.CurrentRow.Cells[0].Value.ToString()));
     txtMaPB.Text             = updatePhongBan.maPhongDoiToLoai;
     txtTenPB.Text            = updatePhongBan.tenPhongDoiToLoai;
     cbPhongBan.SelectedValue = updatePhongBan.idCha;
     btnAdd.Enabled           = false;
     btnSua.Enabled           = true;
 }
        private void InitPhongBanComboBox()
        {
            List <PhongDoiToLoaiTo> listPhongBan       = new List <PhongDoiToLoaiTo>();
            PhongDoiToLoaiTo        khongTrucThuocItem = new PhongDoiToLoaiTo
            {
                tenPhongDoiToLoai = "Không Có",
                idPhongDoiToLoai  = 0
            };

            listPhongBan.Add(khongTrucThuocItem);
            listPhongBan.AddRange(_phongBanServices.GetAllPhongBan());
            cbPhongBan.DataSource    = listPhongBan;
            cbPhongBan.DisplayMember = "tenPhongDoiToLoai";
            cbPhongBan.ValueMember   = "idPhongDoiToLoai";
        }
Beispiel #3
0
        private void InitPhongBan()
        {
            PhongDoiToLoaiTo firstItem = new PhongDoiToLoaiTo
            {
                idPhongDoiToLoai  = 0,
                tenPhongDoiToLoai = "Tất Cả",
                maPhongDoiToLoai  = "All",
                idCha             = 0,
                ThongTinNhanVIens = null
            };
            List <PhongDoiToLoaiTo> listPhongBan = new List <PhongDoiToLoaiTo>();

            listPhongBan.Add(firstItem);
            listPhongBan.AddRange(_phongBanServices.GetAllPhongBan());
            comboBoxPhongBan.DataSource    = listPhongBan;
            comboBoxPhongBan.DisplayMember = "tenPhongDoiToLoai";
            comboBoxPhongBan.ValueMember   = "idPhongDoiToLoai";
        }
 private void btnAdd_Click(object sender, EventArgs e)
 {
     try
     {
         if (String.IsNullOrEmpty(txtTenPB.Text.Trim()) || String.IsNullOrEmpty(txtMaPB.Text.Trim()))
         {
             MessageBox.Show("Thông Tin Chưa Đầy Đủ!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
         else
         {
             if (_phongBanServices.FindPhongBanByNameAndCode(txtMaPB.Text.Trim(), txtTenPB.Text.Trim()) == null)
             {
                 PhongDoiToLoaiTo insertPhongBan = new PhongDoiToLoaiTo
                 {
                     idCha             = (cbPhongBan.SelectedItem as PhongDoiToLoaiTo).idPhongDoiToLoai,
                     maPhongDoiToLoai  = txtMaPB.Text.Trim(),
                     tenPhongDoiToLoai = txtTenPB.Text.Trim()
                 };
                 if (_phongBanServices.AddPhongBan(insertPhongBan))
                 {
                     MessageBox.Show("Đã Thêm Phòng Ban Thành Công!", "Thông Báo", MessageBoxButtons.OK);
                     InitGridView();
                     dataGridPhongBan.Refresh();
                     ClearAllText(this);
                 }
                 else
                 {
                     MessageBox.Show("Đã Có Lỗi Xảy Ra! Vui Lòng Kiểm Tra Lại Thông Tin!", "Error!",
                                     MessageBoxButtons.OK, MessageBoxIcon.Error);
                 }
             }
             else
             {
                 MessageBox.Show("Thông Tin Phòng Ban Đã Có Trong Dữ Liệu!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString(), "Lỗi!", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
 private void btnSua_Click(object sender, EventArgs e)
 {
     try
     {
         if (String.IsNullOrEmpty(txtTenPB.Text.Trim()) || String.IsNullOrEmpty(txtMaPB.Text.Trim()))
         {
             MessageBox.Show("Thông Tin Chưa Đầy Đủ!", "Lỗi!", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
         else
         {
             if (_phongBanServices.FindPhongBanByNameAndCode(txtMaPB.Text.Trim(), txtTenPB.Text.Trim()) == null)
             {
                 updatePhongBan.idCha             = (cbPhongBan.SelectedItem as PhongDoiToLoaiTo).idPhongDoiToLoai;
                 updatePhongBan.maPhongDoiToLoai  = txtMaPB.Text.Trim();
                 updatePhongBan.tenPhongDoiToLoai = txtTenPB.Text.Trim();
                 if (_phongBanServices.UpdatePhongBan(updatePhongBan))
                 {
                     MessageBox.Show("Đã Chỉnh Sử Thông Tin Phòng Ban Thành Công!", "Thông Báo", MessageBoxButtons.OK);
                     InitGridView();
                     dataGridPhongBan.Refresh();
                     btnSua.Enabled = false;
                     btnAdd.Enabled = true;
                     ClearAllText(this);
                     updatePhongBan = null;
                 }
                 else
                 {
                     MessageBox.Show("Đã Có Lỗi Xảy Ra! Vui Lòng Kiểm Tra Lại Thông Tin!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 }
             }
             else
             {
                 MessageBox.Show("Thông Tin Phòng Ban Chỉnh Sửa Bị Trùng!", "Lỗi!", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString(), "Lỗi!", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }