private void btnAddNew_Click(object sender, EventArgs e)
 {
     try
     {
         if (ValidateData() == true)
         {
             DivisionsBO aDivisionsBO = new DivisionsBO();
             Divisions aDivisions = new Divisions();
             aDivisions.Name = txtName.Text;
             aDivisions.Type = cboType.SelectedIndex + 1;
             aDivisions.Status = cboStatus.SelectedIndex + 1;
             aDivisions.Disable = Convert.ToBoolean(cboDisable.Text);
             aDivisionsBO.Insert(aDivisions);
             if (this.afrmLst_Divisions != null)
             {
                 this.afrmLst_Divisions.ReloadData();
             }
             MessageBox.Show("Thêm mới thành công.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
             this.Close();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("frmIns_Divisions.btnAddNew_Click\n" + ex.ToString(), "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
 public void ReloadData()
 {
     try
     {
         DivisionsBO aDivisionBO = new DivisionsBO();
         dgvDivisions.DataSource = aDivisionBO.Select_All();
     }
     catch (Exception ex)
     {
         MessageBox.Show("frmLst_Divisions.ReloadData\n" + ex.ToString(), "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
 private void frmUpd_Divisions_Load(object sender, EventArgs e)
 {
     try
     {
         DivisionsBO aDivisionsBO = new DivisionsBO();
         Divisions aDivisions = aDivisionsBO.Select_ByID(ID);
         lblID.Text = aDivisions.ID.ToString();
         txtName.Text = aDivisions.Name.ToString();
         cboType.SelectedIndex = Convert.ToInt32(aDivisions.Type -1);
         cboStatus.SelectedIndex = Convert.ToInt32(aDivisions.Type - 1);
         cboDisable.Text = aDivisions.Disable.ToString();
     }
     catch (Exception ex)
     {
         MessageBox.Show("frmUpd_Divisions.frmUpd_Divisions_Load\n" + ex.ToString(), "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 private void btnDelete_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
 {
     int ID = Convert.ToInt32(viewDivisions.GetFocusedRowCellValue("ID"));
     DialogResult result = MessageBox.Show("Bạn có chắc chắn muốn xóa ???", "Câu hỏi", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
     if (DialogResult.Yes == result)
     {
         try
         {
             DivisionsBO aDivisionBO = new DivisionsBO();
             aDivisionBO.Delete(ID);
             MessageBox.Show("Bạn đã xóa dữ liệu thành công .", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
         catch (Exception ex)
         {
             MessageBox.Show("frmLst_Divisions.btnDelete_ButtonClick\n" + ex.ToString(), "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
     ReloadData();
 }
 private void btnSave_Click(object sender, EventArgs e)
 {
     try
     {
         if (ValidateData() == true)
         {
             DivisionsBO aDivisionsBO = new DivisionsBO();
             Divisions aDivisions = aDivisionsBO.Select_ByID(ID);
             aDivisions.Name = txtName.Text;
             aDivisions.Type = cboType.SelectedIndex + 1;
             aDivisions.Status = cboStatus.SelectedIndex + 1;
             aDivisions.Disable = Convert.ToBoolean(cboDisable.Text);
             aDivisionsBO.Update(aDivisions);
             this.afrmLst_Divisions.ReloadData();
             MessageBox.Show("Cập nhật dữ liệu thành công.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
             this.Close();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("frmUpd_Divisions.btnSave_Click\n" + ex.ToString(), "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 private void frmLst_SystemUsers_Divisions_Load(object sender, EventArgs e)
 {
     try
     {
         dtpChooseDate.DateTime = DateTime.Now;
         DivisionsBO aDivisonsBO = new DivisionsBO();
         List<Divisions> aListDivisions = aDivisonsBO.Select_All();
         cboDivisions.Properties.Items.Add("Tất cả");
         foreach(Divisions aDivisions in aListDivisions)
         {
             cboDivisions.Properties.Items.Add(aDivisions.Name);
         }
         ReloadData();
     }
     catch (Exception ex)
     {
         MessageBox.Show("frmLst_SystemUsers_Divisions.frmLst_SystemUsers_Divisions_Load\n" + ex.ToString(), "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
        private void lueIDDivision_EditValueChanged(object sender, EventArgs e)
        {
            try
            {
                this.IDDivision = Convert.ToInt32(lueIDDivision.EditValue);
                DivisionsBO aDivisionsBO = new DivisionsBO();

                Divisions aDivisions = aDivisionsBO.Select_ByID(this.IDDivision);

                DivisionsEN aTemp = new DivisionsEN();
                aTemp.ID = aDivisions.ID;

                if (this.aSystemUsers_DivisionsEN.aListDivisionsEN.Where(d=>d.ID == this.IDDivision).ToList().Count == 0)
                {
                    this.aSystemUsers_DivisionsEN.aListDivisionsEN.Add(aTemp);
                }

                SystemUsersBO aSystemUsersBO = new SystemUsersBO();
                List<SystemUsers> aListTemp = aSystemUsersBO.SelectListAllSystemUsers_ByIDDivision(this.IDDivision);
                SystemUsers aSystemUsers;

                foreach (DivisionsEN aDivisionsEN in this.aSystemUsers_DivisionsEN.aListDivisionsEN)
                {
                    if(aDivisionsEN.ID == this.IDDivision)
                    {
                        if (aDivisionsEN.aListSystemUsers.Count <= 0)
                        {
                            foreach (SystemUsers item in aListTemp)
                            {
                                aSystemUsers = new SystemUsers();
                                aSystemUsers.ID = item.ID;
                                aSystemUsers.Username = item.Username;
                                aSystemUsers.Name = item.Name;
                                aSystemUsers.Identifier1 = item.Identifier1;
                                aDivisionsEN.aListSystemUsers.Add(aSystemUsers);
                            }
                        }
                    }
                }

                List<DivisionsEN> aListTemps = this.aSystemUsers_DivisionsEN.aListDivisionsEN.Where(d => d.ID == this.IDDivision).ToList();
                if (aListTemps.Count > 0)
                {
                    DivisionsEN aDivisionsEN = this.aSystemUsers_DivisionsEN.aListDivisionsEN.Where(d => d.ID == this.IDDivision).ToList()[0];
                    int Index = this.aSystemUsers_DivisionsEN.aListDivisionsEN.IndexOf(aDivisionsEN);
                    dgvSelectSystemUsers.DataSource = this.aSystemUsers_DivisionsEN.aListDivisionsEN[Index].aListSystemUsers.Distinct();
                    dgvSelectSystemUsers.RefreshDataSource();
                    this.aSystemUsers_DivisionsEN.aListDivisionsEN.Clear();
                }
                else
                {
                    dgvSelectSystemUsers.DataSource = null;
                    dgvSelectSystemUsers.RefreshDataSource();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("frmIns_SystemUsers_Divisions.lueIDDivision_EditValueChanged\n" + ex.ToString(), "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void frmIns_SystemUsers_Divisions_Load(object sender, EventArgs e)
        {
            try
            {
                DivisionsBO aDivisionsBO = new DivisionsBO();
                List<Divisions> aListDivisions = aDivisionsBO.Select_All();
                lueIDDivision.Properties.DataSource = aListDivisions;
                lueIDDivision.Properties.DisplayMember = "Name";
                lueIDDivision.Properties.ValueMember = "ID";

                if (aListDivisions.Count > 0)
                {
                    lueIDDivision.EditValue = aListDivisions[0].ID;
                }
                SystemUsersBO aSystemUsersBO = new SystemUsersBO();
                this.aListAvailableSystemUsers = aSystemUsersBO.Select_ByDisable(false); //Disable = false
                this.LoadListAvailableSystemUsers();
            }
            catch (Exception ex)
            {
                MessageBox.Show("frmIns_SystemUsers_Divisions.frmIns_SystemUsers_Divisions_Load\n" + ex.ToString(), "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }