/// <summary> /// Wywoływana po naciśnięciu przycisku "Zapisz". Zapisuje zmiany i zamyka formularz, jeśli wprowadzone zmiany są poprawnie. /// </summary> /// <param name="sender">Przycisk "Zapisz".</param> /// <param name="e">Argumenty zdarzenia.</param> private void btSave_Click(object sender, EventArgs e) { int Parse; switch (Table) { case Tables.Collectors: if (Auxiliary.IsCurrentValueOK(ControlToBool_Dict)) { Collector modifiedCollector = new Collector(); modifiedCollector.CollectorId = this.Controls.Find("CollectorId", true)[0].Text; modifiedCollector.Name = this.Controls.Find("Name", true)[0].Text; modifiedCollector.LastName = this.Controls.Find("LastName", true)[0].Text; modifiedCollector.PostalCode = this.Controls.Find("PostalCode", true)[0].Text; modifiedCollector.City = this.Controls.Find("City", true)[0].Text; modifiedCollector.Address = this.Controls.Find("Address", true)[0].Text; modifiedCollector.PhoneNumber = this.Controls.Find("PhoneNumber", true)[0].Text; modifiedCollector.ModifyRecord(ids.ElementAt(0)); modified = true; this.Close(); } else MessageBox.Show(LangPL.InsertFormLang["Fill in all fields"]); break; case Tables.Customers: if (Auxiliary.IsCurrentValueOK(ControlToBool_Dict)) { Customer modifiedCustomer = new Customer(); modifiedCustomer.CustomerId = this.Controls.Find("CustomerId", true)[0].Text; modifiedCustomer.Name = this.Controls.Find("Name", true)[0].Text; modifiedCustomer.LastName = this.Controls.Find("LastName", true)[0].Text; modifiedCustomer.PostalCode = this.Controls.Find("PostalCode", true)[0].Text; modifiedCustomer.City = this.Controls.Find("City", true)[0].Text; modifiedCustomer.Address = this.Controls.Find("Address", true)[0].Text; modifiedCustomer.PhoneNumber = this.Controls.Find("PhoneNumber", true)[0].Text; modifiedCustomer.ModifyRecord(ids.ElementAt(0)); modified = true; this.Close(); } else MessageBox.Show(LangPL.InsertFormLang["Fill in all fields"]); break; case Tables.Areas: if (Auxiliary.IsCurrentValueOK(ControlToBool_Dict)) { Area modifiedArea = new Area(); modifiedArea.AreaId = new Guid(this.Controls.Find("AreaId", true)[0].Text); modifiedArea.Street = this.Controls.Find("Street", true)[0].Text; if (CBConfigs[0].ReturnForeignKey() == "") modifiedArea.CollectorId = ""; else modifiedArea.CollectorId = CBConfigs[0].ReturnForeignKey(); modifiedArea.ModifyRecord(ids.ElementAt(0)); modified = true; this.Close(); } else MessageBox.Show(LangPL.InsertFormLang["Fill in all fields"]); break; case Tables.Counters: if (Auxiliary.IsCurrentValueOK(ControlToBool_Dict)) { Counter modifiedCounter = new Counter(); modifiedCounter.CounterNo = Convert.ToInt32(this.Controls.Find("CounterNo", true)[0].Text); Int32.TryParse(this.Controls.Find("CircuitNo", true)[0].Text, out Parse); modifiedCounter.CircuitNo = Parse; if (CBConfigs[0].comboBox.SelectedIndex != 0) //jeśli w jednym comboboxie index jest różny od 0, to w drugim też { modifiedCounter.AddressId = new Guid(CBConfigs[0].ReturnForeignKey()); modifiedCounter.CustomerId = CBConfigs[1].ReturnForeignKey(); } else { modifiedCounter.AddressId = null; modifiedCounter.CustomerId = null; } modifiedCounter.ModifyRecord(ids.ElementAt(0)); modified = true; this.Close(); } else MessageBox.Show(LangPL.InsertFormLang["Fill in all fields"]); break; case Tables.Addresses: if (Auxiliary.IsCurrentValueOK(ControlToBool_Dict)) { Address modifiedAddress = new Address(); modifiedAddress.AddressId = new Guid(this.Controls.Find("AddressId", true)[0].Text); Int32.TryParse(this.Controls.Find("HouseNo", true)[0].Text, out Parse); modifiedAddress.HouseNo = Parse; Int32.TryParse(this.Controls.Find("FlatNo", true)[0].Text, out Parse); if (Parse > 0) modifiedAddress.FlatNo = Parse; else modifiedAddress.FlatNo = null; modifiedAddress.AreaId = new Guid(CBConfigs[0].ReturnForeignKey()); modifiedAddress.ModifyRecord(ids.ElementAt(0)); modified = true; this.Close(); } else MessageBox.Show(LangPL.InsertFormLang["Fill in all fields"]); break; } }
/// <summary> /// Generuje adresy losowo dobierając wartości pól. Losuje teren przypisany do danego adresu. /// </summary> static void GenerateAddresses() { Random rnd = new Random(); Address address; for (int i = 0; i < numberOfAddresses; i++) { address = new Address(); address.AddressId = Guid.NewGuid(); address.HouseNo = rnd.Next(1, 100); address.FlatNo = rnd.Next(1, 100); address.AreaId = new Guid(ChooseRandomId(0)); address.InsertIntoDB(); } }
private bool InsertAddress() { int Parse; Address a = new Address(); a.AddressId = Guid.NewGuid(); Int32.TryParse(tbHouseNo.Text, out Parse); a.HouseNo = Parse; Int32.TryParse(tbFlatNo.Text, out Parse); if (Parse > 0) a.FlatNo = Parse; if (Auxiliary.IsCurrentValueOK(Current_ControlToBool_Dict)) { a.AreaId = new Guid(cbcArea.ReturnForeignKey()); a.InsertIntoDB(); modified = true; InsertedTo = Tables.Addresses; return true; } else { MessageBox.Show(LangPL.InsertFormLang["Fill in all fields"]); return false; } }