private void cboMunicipality_SelectedIndexChanged(object sender, EventArgs e) { MUNICIPALITY municipality = cboMunicipality.SelectedItem as MUNICIPALITY; if (municipality != null && !string.IsNullOrEmpty(municipality.CODE)) { List <TERRITORIAL_UNIT> territorialUnits = _basicService.LoadAllTERRITORIAL_UNIT(_businessParam).Where(c => c.ID_MUNICIPALITY == municipality.ID_MUNICIPALITY).OrderBy(c => c.NAME).ToList(); territorialUnits.Insert(0, new TERRITORIAL_UNIT { NAME = "---", CODE = "", ID_TERRITORIAL_UNIT = -1 }); cboTerritorialUnit.DataSource = territorialUnits; cboTerritorialUnit.DisplayMember = "NAME"; cboTerritorialUnit.ValueMember = "ID_TERRITORIAL_UNIT"; CADASTRAL_REGION region = cboRegion.SelectedItem as CADASTRAL_REGION; int prevCodeLength = region.CODE.Length; txtCodeMunicipality.Text = municipality.CODE.Substring(prevCodeLength, municipality.CODE.Length - prevCodeLength); if (territorialUnits == null || territorialUnits.Count == 0) { txtCodeTerriturialUnit.Text = ""; cboTerritorialUnit.DataSource = null; } txtCodeMunicipality.ReadOnly = true; } else { cboTerritorialUnit.DataSource = null; txtCodeMunicipality.Text = ""; txtCodeMunicipality.ReadOnly = false; } }
private void cboRegion_SelectedIndexChanged(object sender, EventArgs e) { CADASTRAL_REGION region = cboRegion.SelectedItem as CADASTRAL_REGION; if (region != null && !string.IsNullOrEmpty(region.CODE)) { List <MUNICIPALITY> municipalities = _basicService.LoadAllMUNICIPALITY(_businessParam).Where(c => c.ID_CADASTRAL_REGION == region.ID_CADASTRAL_REGION).OrderBy(c => c.NAME).ToList(); municipalities.Insert(0, new MUNICIPALITY { NAME = "---", CODE = "", ID_MUNICIPALITY = -1 }); cboMunicipality.DataSource = municipalities; cboMunicipality.DisplayMember = "NAME"; cboMunicipality.ValueMember = "ID_MUNICIPALITY"; CADASTRAL_ZONE cadastreZone = cboRegionZone.SelectedItem as CADASTRAL_ZONE; int prevCodeLength = cadastreZone.CODE.Length; txtCodeRegion.Text = region.CODE.Substring(prevCodeLength, region.CODE.Length - prevCodeLength); if (municipalities == null || municipalities.Count == 0) { txtCodeMunicipality.Text = ""; txtCodeTerriturialUnit.Text = ""; cboMunicipality.DataSource = null; cboTerritorialUnit.DataSource = null; } txtCodeRegion.ReadOnly = true; } else { cboMunicipality.DataSource = null; txtCodeRegion.Text = ""; txtCodeRegion.ReadOnly = false; } }