private void Button_Click(object sender, RoutedEventArgs e) { using (var context = new CepikDB()) { var ip = new InsurancePolicy(); var RegexID = new Regex(@"^[0-9]{1,6}$"); var RegexDate = new Regex(@"^[0-3][0-9]\/[0-1][0-9]\/[0-2][0-9]{3}$"); bool IpIdCondition = false; bool CarIdCondition = false; bool firstDateCondition = false; bool secondDateCondition = false; //IP id int number; bool success = Int32.TryParse(IpIdTextBox.Text, out number); if (string.IsNullOrEmpty(IpIdTextBox.Text)) { IpIdNotEmpty.Visibility = Visibility.Visible; } else if (!success || !RegexID.IsMatch(IpIdTextBox.Text)) { IpIdIncorrect.Visibility = Visibility.Visible; } else { ip.InsuranceId = number; IpIdCondition = true; }; //first date if (string.IsNullOrEmpty(firstDateTextBox.Text)) { FirstDateNotEmpty.Visibility = Visibility.Visible; } else if (!RegexDate.IsMatch(firstDateTextBox.Text)) { FirstDateIncorrect.Visibility = Visibility.Visible; } else { ip.PolicyStartDay = DateTime.Parse(firstDateTextBox.Text); firstDateCondition = true; }; //last name if (string.IsNullOrEmpty(secondDateTextBox.Text)) { SecondDateNotEmpty.Visibility = Visibility.Visible; } else if (!RegexDate.IsMatch(secondDateTextBox.Text)) { SecondDateIncorrect.Visibility = Visibility.Visible; } else { ip.PolicyExpiryDate = DateTime.Parse(secondDateTextBox.Text); secondDateCondition = true; }; //car id bool success2 = Int32.TryParse(carIdTextBox.Text, out number); if (string.IsNullOrEmpty(IpIdTextBox.Text)) { CarIdNotEmpty.Visibility = Visibility.Visible; } else if (!success || !RegexID.IsMatch(carIdTextBox.Text)) { CarIdIncorrect.Visibility = Visibility.Visible; } else { ip.CarId = number; CarIdCondition = true; }; { if (IpIdCondition && CarIdCondition && firstDateCondition && secondDateCondition) { try { backButton.IsEnabled = false; saveButton.IsEnabled = false; saveData.Content = "Trwa zapisywanie danych do bazy"; saveData.Visibility = Visibility.Visible; context.Polisa.Add(ip); context.SaveChanges(); saveData.Content = "Dane zostały zapisane"; backButton.IsEnabled = true; saveButton.IsEnabled = true; foreach (Control ctl in Container.Children) { if (ctl.GetType() == typeof(Label)) { ((Label)ctl).Visibility = Visibility.Hidden; } if (ctl.GetType() == typeof(TextBox)) { ((TextBox)ctl).Text = String.Empty; } } Thread.Sleep(TimeSpan.FromSeconds(2)); saveData.Visibility = Visibility.Hidden; } catch (System.Data.Entity.Infrastructure.DbUpdateException) { ErrorWindow ew = new ErrorWindow(); ew.Owner = this; ew.ShowDialog(); } } } } }
private void Button_Click(object sender, RoutedEventArgs e) { using (var context = new CepikDB()) { var carInfo = new CarDocsAndInfo(); var RegexVIN = new Regex(@"^[A-Z0-9]{17}$"); var RegexDate = new Regex(@"^[0-3][0-9]\/[0-1][0-9]\/[0-2][0-9]{3}$"); var RegexCarId = new Regex(@"^[0-9]$"); bool VINcondition = false; bool DateCondition = false; bool IdCondition = false; bool carCardCondition = false; //czy mniej kodu jest tu, czy jak zrobie to dynamicznie? //vin number if (string.IsNullOrEmpty(vinTextBox.Text)) { vinNotEmpty.Visibility = Visibility.Visible; } else if (!RegexDate.IsMatch(vinTextBox.Text)) { vinIncorrect.Visibility = Visibility.Hidden; } else { carInfo.VinNumber = vinTextBox.Text; VINcondition = true; }; //car card nr if (string.IsNullOrEmpty(carCardTextBox.Text)) { carCardNotEmpty.Visibility = Visibility.Visible; } else { carInfo.CarCardNumber = carCardTextBox.Text; carCardCondition = true; }; //date if (string.IsNullOrEmpty(firstRegistryTextBox.Text)) { DateNotEmpty.Visibility = Visibility.Visible; } else if (!RegexDate.IsMatch(firstRegistryTextBox.Text)) { firstRegistryIncorrect.Visibility = Visibility.Visible; } else { carInfo.FirstRegistrationDate = DateTime.Parse(firstRegistryTextBox.Text); DateCondition = true; } //car id int number; bool success = Int32.TryParse(carIdTextBox.Text, out number); if (!success || !RegexCarId.IsMatch(carIdTextBox.Text)) { carIdIncorrect.Visibility = Visibility.Visible; } else if (string.IsNullOrEmpty(carIdTextBox.Text)) { IdNotEmpty.Visibility = Visibility.Visible; } else { carInfo.CarId = number; IdCondition = true; } if (IdCondition && DateCondition && VINcondition && carCardCondition) { try { backButton.IsEnabled = false; saveButton.IsEnabled = false; saveData.Content = "Trwa zapisywanie danych do bazy"; saveData.Visibility = Visibility.Visible; context.Informacje.Add(carInfo); context.SaveChanges(); saveData.Content = "Dane zostały zapisane"; backButton.IsEnabled = true; saveButton.IsEnabled = true; foreach (Control ctl in Container.Children) { if (ctl.GetType() == typeof(Label)) { ((Label)ctl).Visibility = Visibility.Hidden; } if (ctl.GetType() == typeof(TextBox)) { ((TextBox)ctl).Text = String.Empty; } } Thread.Sleep(TimeSpan.FromSeconds(2)); saveData.Visibility = Visibility.Hidden; } catch (System.Data.Entity.Infrastructure.DbUpdateException) { ErrorWindow ew = new ErrorWindow(); ew.Owner = this; ew.ShowDialog(); } } } }
private void Button_Click(object sender, RoutedEventArgs e) { using (var context = new CepikDB()) { var tr = new TechnicalReview(); var RegexID = new Regex(@"^[0-9]{1,6}$"); var RegexDate = new Regex(@"^[0-3][0-9]\/[0-1][0-9]\/[0-2][0-9]{3}$"); bool TrIdCondition = false; bool CarIdCondition = false; bool firstDateCondition = false; bool secondDateCondition = false; bool checkBoxCondition = false; //IP id int number; bool success = Int32.TryParse(trIdTextBox.Text, out number); if (string.IsNullOrEmpty(trIdTextBox.Text)) { TrIdNotEmpty.Visibility = Visibility.Visible; } else if (!success || !RegexID.IsMatch(trIdTextBox.Text)) { TrIdIncorrect.Visibility = Visibility.Visible; } else { tr.TechnicalReviewID = number; TrIdCondition = true; }; //first date if (string.IsNullOrEmpty(firstDateTextBox.Text)) { TrDateNotEmpty.Visibility = Visibility.Visible; } else if (!RegexDate.IsMatch(firstDateTextBox.Text)) { TrDateIncorrect.Visibility = Visibility.Visible; } else { tr.TechnicalReviewDate = DateTime.Parse(firstDateTextBox.Text); firstDateCondition = true; }; //2nd date if (string.IsNullOrEmpty(secondDateTextBox.Text)) { TrExpiryNotEmpty.Visibility = Visibility.Visible; } else if (!RegexDate.IsMatch(secondDateTextBox.Text)) { TrExpiryIncorect.Visibility = Visibility.Visible; } else { tr.TechnicalReviewExpiryDate = DateTime.Parse(secondDateTextBox.Text); secondDateCondition = true; }; //car id bool success2 = Int32.TryParse(carIdTextBox.Text, out number); if (string.IsNullOrEmpty(carIdTextBox.Text)) { CarIdNotEmpty.Visibility = Visibility.Visible; } else if (!success || !RegexID.IsMatch(carIdTextBox.Text)) { CarIdIncorrect.Visibility = Visibility.Visible; } else { tr.CarId = number; CarIdCondition = true; }; if (positiveCheckBox.IsChecked == false && negativeCheckBox.IsChecked == false) { noCheck.Visibility = Visibility.Visible; } else if (positiveCheckBox.IsChecked == true) { tr.TechnicalReviewStatus = true; checkBoxCondition = true; } else { tr.TechnicalReviewStatus = false; checkBoxCondition = true; } if (TrIdCondition && CarIdCondition && firstDateCondition && secondDateCondition && checkBoxCondition) { try { backButton.IsEnabled = false; saveButton.IsEnabled = false; saveData.Content = "Trwa zapisywanie danych do bazy"; saveData.Visibility = Visibility.Visible; context.BadanieTechniczne.Add(tr); context.SaveChanges(); saveData.Content = "Dane zostały zapisane do bazy"; backButton.IsEnabled = true; saveButton.IsEnabled = true; foreach (Control ctl in Container.Children) { if (ctl.GetType() == typeof(Label)) { ((Label)ctl).Visibility = Visibility.Hidden; } if (ctl.GetType() == typeof(TextBox)) { ((TextBox)ctl).Text = String.Empty; } if (ctl.GetType() == typeof(TextBox)) { ((TextBox)ctl).Text = String.Empty; } } Thread.Sleep(TimeSpan.FromSeconds(2)); saveData.Visibility = Visibility.Hidden; } catch (System.Data.Entity.Infrastructure.DbUpdateException) { ErrorWindow ew = new ErrorWindow(); ew.Owner = this; ew.ShowDialog(); } } } }