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 btnSelectSystemUsers_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e) { try { SystemUsers aSystemUsers = new SystemUsers(); aSystemUsers.ID = Convert.ToInt32(viewAvailableSystemUsers.GetFocusedRowCellValue("ID")); aSystemUsers.Username = Convert.ToString(viewAvailableSystemUsers.GetFocusedRowCellValue("Username")); aSystemUsers.Name = Convert.ToString(viewAvailableSystemUsers.GetFocusedRowCellValue("Name")); aSystemUsers.Identifier1 = Convert.ToString(viewAvailableSystemUsers.GetFocusedRowCellValue("Identifier1")); DivisionsEN aDivisionsEN = new DivisionsEN(); List<DivisionsEN> aListTemps = aSystemUsers_DivisionsEN.aListDivisionsEN.Where(d => d.ID ==IDDivision).ToList(); if (aListTemps.Count == 0) { aDivisionsEN.ID = Convert.ToInt32(lueIDDivision.EditValue); aSystemUsers_DivisionsEN.aListDivisionsEN.Add(aDivisionsEN); } aDivisionsEN = aSystemUsers_DivisionsEN.aListDivisionsEN.Where(d => d.ID == IDDivision).ToList()[0]; int Index = aSystemUsers_DivisionsEN.aListDivisionsEN.IndexOf(aDivisionsEN); if (aSystemUsers_DivisionsEN.aListDivisionsEN[Index].aListSystemUsers.Where(s => s.ID == aSystemUsers.ID).ToList().Count > 0) { SystemUsers aSystemUsersTemps = aSystemUsers_DivisionsEN.aListDivisionsEN[Index].aListSystemUsers.Where(d => d.ID == aSystemUsers.ID).ToList()[0]; aSystemUsers_DivisionsEN.aListDivisionsEN[Index].aListSystemUsers.Remove(aSystemUsersTemps); } aSystemUsers_DivisionsEN.aListDivisionsEN[Index].aListSystemUsers.Add(aSystemUsers); dgvSelectSystemUsers.DataSource = aSystemUsers_DivisionsEN.aListDivisionsEN[Index].aListSystemUsers; dgvSelectSystemUsers.RefreshDataSource(); SystemUsers Temps = aListAvailableSystemUsers.Where(d => d.ID == Convert.ToInt32(viewAvailableSystemUsers.GetFocusedRowCellValue("ID"))).ToList()[0]; aListAvailableSystemUsers.Remove(Temps); dgvAvailableSystemUsers.DataSource = aListAvailableSystemUsers; dgvAvailableSystemUsers.RefreshDataSource(); } catch (Exception ex) { MessageBox.Show("frmIns_SystemUsers_Divisions.btnSelectSystemUsers_ButtonClick\n" + ex.ToString(), "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } }