public static string AreaValidateString(Area a) { string checkBug = String.Empty; bool IsOK; checkBug += (IsOK = StreetValidation(a.Street)) ? String.Empty : LangPL.InsertFormLang["textBoxStreet"]; if (IsOK) a.Street = UppercaseFirst(a.Street); checkBug += CollectorExists(a.CollectorId) ? String.Empty : LangPL.InsertFormLang["textBoxCollectorID"]; return checkBug; }
/// <summary> /// Generuje tereny losowo dobierając wartości pól. Losuje inkasenta przypisanego do danego terenu. /// </summary> static void GenerateAreas() { Random rnd = new Random(); Area area; for (int i = 0; i < numberOfAreas; i++) { area = new Area(); area.AreaId = Guid.NewGuid(); area.Street = SampleDataSource.streets[i]; area.CollectorId = ChooseRandomId(0); area.InsertIntoDB(); } }
/// <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; } }
private bool InsertArea() { Area a = new Area(); a.AreaId = Guid.NewGuid(); a.CollectorId = cbcCollector.ReturnForeignKey(); a.Street = tbStreet.Text; if (Auxiliary.IsCurrentValueOK(Current_ControlToBool_Dict)) { a.InsertIntoDB(); modified = true; InsertedTo = Tables.Areas; return true; } else { MessageBox.Show(LangPL.InsertFormLang["Fill in all fields"]); return false; } }