/// <summary> /// Generuje liczniki losowo dobierając wartości pól. Losuje adres i klienta przypisanego do danego licznika. /// </summary> static void GenerateCounters() { Random rnd = new Random(); Counter counter; for (int i = 0; i < numberOfCounters; i++) { counter = new Counter(); counter.CounterNo = rnd.Next(1000, 10000); while (MainValidation.CounterExists(counter.CounterNo)) counter.CounterNo = rnd.Next(1000, 10000); counter.CircuitNo = rnd.Next(1000, 10000); counter.AddressId = new Guid(ChooseRandomId(1)); counter.CustomerId = ChooseRandomId(0); counter.InsertIntoDB(); } }
private bool InsertCounter() { int Parse; Counter c = new Counter(); Int32.TryParse(tbCounterNo.Text, out Parse); c.CounterNo = Parse; Int32.TryParse(tbCircuitNo.Text, out Parse); c.CircuitNo = Parse; if (Auxiliary.IsCurrentValueOK(Current_ControlToBool_Dict)) { if (cbcAddress.comboBox.SelectedIndex != 0) //jeśli w jednym comboboxie index jest różny od 0, to w drugim też { c.AddressId = new Guid(cbcAddress.ReturnForeignKey()); c.CustomerId = cbcCustomer.ReturnForeignKey(); } c.InsertIntoDB(); modified = true; InsertedTo = Tables.Counters; return true; } else { MessageBox.Show(LangPL.InsertFormLang["Fill in all fields"]); return false; } }
/// <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; } }
public static string CounterValidateString(Counter c) { string checkBug = String.Empty; checkBug += CheckCircuitAndCounterAndHouseAndFlatNumber(c.CounterNo) ? String.Empty : LangPL.InsertFormLang["textBoxCounterNo"]; checkBug += CheckCircuitAndCounterAndHouseAndFlatNumber(c.CircuitNo) ? String.Empty : LangPL.InsertFormLang["textBoxCircuitNo"]; checkBug += (EmptyString(c.AddressId.Value.ToString())) ? String.Empty : LangPL.InsertFormLang["textBoxAddress"]; //if (checkBug == String.Empty) // checkBug += AddressExists(c.AddressId.Value) ? LangPL.InsertFormLang["textBoxAddressID"] : String.Empty; checkBug += CustomerExists(c.CustomerId) ? String.Empty : LangPL.InsertFormLang["textBoxCustomerID"]; return checkBug; }