private void dataGridCA_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex != -1) { CadastralView cv = new CadastralView(this.Program.Find(new CadastralAreaByID(new CadastralArea(Int32.Parse(dataGridCA.Rows[e.RowIndex].Cells["ID"].Value.ToString()))))); cv.onDispose += (ca, c) => this.InitCadastralAreas(); cv.ShowDialog(); } }
private void btnFind_Click(object sender, EventArgs e) { switch (comboTypes.SelectedIndex) { case 0: // Persons Person p = this.Program.Find(new Person(textSearch.Text)); if (p == null) { goto Error; } PersonView pv = new PersonView(p, this); pv.onDispose += (person) => { p = person; }; pv.ShowDialog(); goto Finish; case 1: // Cadastral Area CadastralArea c = null; if (Int32.TryParse(textSearch.Text, out int search)) { c = new CadastralArea(search); c = this.Program.Find(new CadastralAreaByID(new CadastralArea(search))); } else { c = new CadastralArea(0, textSearch.Text); c = this.Program.Find(new CadastralAreaByName(c)); } if (c == null) { goto Error; } CadastralView cv = new CadastralView(c); cv.onDispose += (cArea, oldName) => { if (oldName != c.Name) { this.Program.UpdateCadastralArea(c, oldName); } }; cv.ShowDialog(); goto Finish; case 2: // Property list InputDialog id = new InputDialog("Catastral area:"); id.onDispose += (caId) => { if (caId != "") { CadastralArea ca = null; if (Int32.TryParse(caId, out int s)) { ca = this.Program.Find(new CadastralAreaByID(new CadastralArea(s, ""))); } else { ca = this.Program.Find(new CadastralAreaByName(new CadastralArea(0, caId))); } if (ca != null) { PropertyList pl = ca.FindPropertyList(textSearch.Text); if (pl == null) { MessageBox.Show("Property list with this id does not exist"); } else { PropertyListView plv = new PropertyListView(pl, this); plv.ShowDialog(); } } else { MessageBox.Show("Cadastral area with this id/name does not exist"); } } else { MessageBox.Show("You have to write something"); } }; id.ShowDialog(); goto Finish; case 3: // Property InputDialog id2 = new InputDialog("Catastral area:"); id2.onDispose += (caId) => { if (caId != "") { CadastralArea ca = null; if (Int32.TryParse(caId, out int s)) { ca = this.Program.Find(new CadastralAreaByID(new CadastralArea(s, ""))); } else { ca = this.Program.Find(new CadastralAreaByName(new CadastralArea(0, caId))); } if (ca != null) { Property prop = ca.FindProperty(textSearch.Text); if (prop == null) { MessageBox.Show("Property with this id does not exist"); } else { PropertyView propv = new PropertyView(prop); propv.ShowDialog(); } } else { MessageBox.Show("Cadastral area with this id/name does not exist"); } } else { MessageBox.Show("You have to write something"); } }; id2.ShowDialog(); goto Finish; } Error: MessageBox.Show("Could not find specified item"); Finish :; }
private void btnAdd_Click(object sender, EventArgs e) { switch (comboTypes.SelectedIndex) { case 0 : // Persons PersonView pv = new PersonView(null, this); pv.onDispose += (person) => { if (this.Program.AddPerson(person)) { MessageBox.Show("Person was successfully added!"); this.InitPersons(); } else { MessageBox.Show("Person could not be added, probably already added!"); } }; pv.ShowDialog(); break; case 1: // Cadastral Area CadastralView cv = new CadastralView(); cv.onDispose += (cArea, name) => { if (this.Program.AddCadastralArea(cArea)) { MessageBox.Show("Cadastral area was successfully added!"); this.InitCadastralAreas(); } else { MessageBox.Show("Cadastral area could not be added, probably already added!"); } }; cv.ShowDialog(); break; case 2: // Property list InputDialog id = new InputDialog("Catastral area name:"); id.onDispose += (search) => { if (search != "") { CadastralArea ca = this.Program.Find(new CadastralAreaByName(new CadastralArea(0, (string)search))); if (ca != null) { PropertyListView plv = new PropertyListView(new PropertyList(-1, ca), this); plv.onDispose += (pl) => { if (pl.ID >= 0) { if (this.Program.AddPropertyList(pl)) { MessageBox.Show("Property list was successfully added!"); } else { MessageBox.Show("Cadastral area could not be added, probably already added!"); } } }; plv.ShowDialog(); } else { MessageBox.Show("Cadastral area with this name does not exist"); } } }; id.ShowDialog(); break; default: MessageBox.Show("This option is not supported"); break; } }