private void btnDisable_Click(object sender, EventArgs e)
        {
            int ID = Convert.ToInt32(viewSystemUsers_Divisions.GetFocusedRowCellValue("SystemUsers_Divisions_ID"));
            DialogResult result = MessageBox.Show("Bạn có chắc chắn muốn thực hiện ???", "Câu hỏi", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (DialogResult.Yes == result)
            {
                try
                {
                    SystemUsers_DivisionsBO aSystemUsers_DivisionsBO = new SystemUsers_DivisionsBO();
                    SystemUsers_Divisions aSystemUsers_Divisions = aSystemUsers_DivisionsBO.Select_ByID(ID);
                    aSystemUsers_Divisions.Disable = true;
                    SystemUsersBO aSystemUsersBO = new SystemUsersBO();
                    SystemUsers aSystemUsers = aSystemUsersBO.Select_ByID(aSystemUsers_Divisions.IDSystemUser);
                    aSystemUsers.Disable = false;
                    aSystemUsers_DivisionsBO.Update(aSystemUsers_Divisions);
                    aSystemUsersBO.Update(aSystemUsers);

                    MessageBox.Show("Bạn đã thực hiện thành công.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("frmLst_SystemUsers_Divisions.btnDisable_Click\n" + ex.ToString(), "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            ReloadData();
        }
        public void ReloadData()
        {
            try
            {
                SystemUsers_DivisionsBO aSystemUsers_DivisionsBO = new SystemUsers_DivisionsBO();
                colSystemUsers_Birthday.DisplayFormat.FormatType = FormatType.DateTime;
                colSystemUsers_Birthday.DisplayFormat.FormatString = "{0:dd/MM/yyyy}";
                colSystemUsers_Divisions_AvaiableDate.DisplayFormat.FormatType = FormatType.DateTime;
                colSystemUsers_Divisions_AvaiableDate.DisplayFormat.FormatString = "{0:dd/MM/yyyy}";
                colSystemUsers_Divisions_ExpireDate.DisplayFormat.FormatType = FormatType.DateTime;
                colSystemUsers_Divisions_ExpireDate.DisplayFormat.FormatString = "{0:dd/MM/yyyy}";

                dgvSystemUsers_Divisions.DataSource = aSystemUsers_DivisionsBO.Select_BySystemUsersDivisions_Disable();
            }
            catch (Exception ex)
            {
                MessageBox.Show("frmLst_SystemUsers_Divisions.ReloadData\n" + ex.ToString(), "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void btnSearch_Click(object sender, EventArgs e)
        {
            try
            {
                string NameDivision = cboDivisions.Text;
                DateTime ChooseDate = dtpChooseDate.DateTime;

                if (NameDivision == "Tất cả")
                {
                    ReloadData();
                }
                else
                {
                    SystemUsers_DivisionsBO aSystemUsers_DivisionsBO = new SystemUsers_DivisionsBO();
                    colSystemUsers_Birthday.DisplayFormat.FormatType = FormatType.DateTime;
                    colSystemUsers_Birthday.DisplayFormat.FormatString = "{0:dd/MM/yyyy}";
                    colSystemUsers_Divisions_AvaiableDate.DisplayFormat.FormatType = FormatType.DateTime;
                    colSystemUsers_Divisions_AvaiableDate.DisplayFormat.FormatString = "{0:dd/MM/yyyy}";
                    colSystemUsers_Divisions_ExpireDate.DisplayFormat.FormatType = FormatType.DateTime;
                    colSystemUsers_Divisions_ExpireDate.DisplayFormat.FormatString = "{0:dd/MM/yyyy}";
                    dgvSystemUsers_Divisions.DataSource = aSystemUsers_DivisionsBO.Select_ByIDDivisionAndDate(NameDivision, ChooseDate);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("frmLst_SystemUsers_Divisions.btnSearch_Click\n" + ex.ToString(), "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
 //Author:Hiennv
 public List<SystemUsers> SelectListSystemUsers_ByIDDivision(int IDDivision)
 {
     try
     {
         SystemUsers_DivisionsBO aSystemUsers_DivisionsBO = new SystemUsers_DivisionsBO();
         List<int> aListIDSystemUsers = aSystemUsers_DivisionsBO.Select_ByIDDivision(IDDivision).Where(s=>s.Disable == false).Select(s => s.IDSystemUser).Distinct().ToList();
         return this.SelectListSystemUsers_ByListIDSystemUsers(aListIDSystemUsers).Where(s => s.Disable == false).ToList();
     }
     catch (Exception ex)
     {
         throw new Exception("SystemUsersBO.SelectListSystemUsers_ByIDDivision\n" + ex.ToString());
     }
 }
        //Author : Hiennv
        public void InsertSystemUsersToDivisions(SystemUsers_DivisionsEN aSystemUsers_DivisionsEN)
        {
            try
            {
                SystemUsers_DivisionsBO aSystemUsers_DivisionsBO;
                List<SystemUsers_Divisions> aListTemp;
                SystemUsers_Divisions aSystemUsers_Divisions = new SystemUsers_Divisions();
                aSystemUsers_Divisions.CreatedDate = DateTime.Now;
                aSystemUsers_Divisions.AvaiableDate = aSystemUsers_DivisionsEN.AvaiableDate;
                aSystemUsers_Divisions.Type = aSystemUsers_DivisionsEN.Type;
                aSystemUsers_Divisions.Status = aSystemUsers_DivisionsEN.Status;
                aSystemUsers_Divisions.Disable = aSystemUsers_DivisionsEN.Disable;
                aSystemUsers_Divisions.ExpireDate = aSystemUsers_DivisionsEN.ExpireDate;

                for (int i = 0; i < aSystemUsers_DivisionsEN.aListDivisionsEN.Count; i++)
                {
                    aSystemUsers_Divisions.IDDivision = aSystemUsers_DivisionsEN.aListDivisionsEN[i].ID;

                    for (int j = 0; j < aSystemUsers_DivisionsEN.aListDivisionsEN[i].aListSystemUsers.Count; j++)
                    {
                        aSystemUsers_DivisionsBO = new SystemUsers_DivisionsBO();
                        aSystemUsers_Divisions.IDSystemUser = aSystemUsers_DivisionsEN.aListDivisionsEN[i].aListSystemUsers[j].ID;
                        aListTemp = new List<SystemUsers_Divisions>();
                        aListTemp = aSystemUsers_DivisionsBO.Select_ByIDSystemUsersAndIDDivisionAndDisable(aSystemUsers_DivisionsEN.aListDivisionsEN[i].ID, aSystemUsers_DivisionsEN.aListDivisionsEN[i].aListSystemUsers[j].ID, false);
                        if (aListTemp.Count > 0)
                        {
                            foreach (SystemUsers_Divisions item in aListTemp)
                            {

                                SystemUsers_Divisions aTemp = aSystemUsers_DivisionsBO.Select_ByID(item.ID);
                                aTemp.Disable = true;
                                aSystemUsers_DivisionsBO.Update(aTemp);
                            }
                        }
                        aDatabaseDA.SystemUsers_Divisions.Add(aSystemUsers_Divisions);
                        aDatabaseDA.SaveChanges();
                    }
                }

            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("ReceptionTaskBO.InsertSystemUsersToDivisions :" + ex.Message.ToString()));
            }
        }