private void connect_Click(object sender, RoutedEventArgs e) { //if (int.Parse(personalIDTextBox.Text) != 0) if (personalIDTextBox.Text == null || personalIDTextBox.Text == "") { var list = from p in context.Personals select p; ObservableCollection <Personal> personals = new ObservableCollection <Personal>(list); Personal personal = new Personal(); foreach (var per in personals) { if (per.UserID == int.Parse(personalIDTextBox.Text)) { MessageBox.Show("personal ID is valid"); //var newForm = new MainPersonal(per); //create your new form. ////var newForm = new MainPerson(int.Parse(personalIDTextBox.Text)); //create your new form. //newForm.Show(); //show the new form } } } else { // MessageBox.Show("personal ID is not valid"); } MainPersonal newForm = new MainPersonal(); //create your new form. this.Hide(); newForm.Show(); //show the new form }
private void add_Click(object sender, RoutedEventArgs e) { NorthwindEntities context = new NorthwindEntities(); //if (int.Parse(personalIDTextBox.Text) != 0) if (personalIDTextBox.Text != null && personalIDTextBox.Text != "") { var list = from p in context.Personals select p; ObservableCollection <Personal> personals = new ObservableCollection <Personal>(list); Personal personal = new Personal(); foreach (var per in personals) { if (per.UserID == int.Parse(personalIDTextBox.Text)) { MessageBox.Show("personal ID is exit"); //var newForm = new MainPersonal(per); //create your new form. ////var newForm = new MainPerson(int.Parse(personalIDTextBox.Text)); //create your new form. //newForm.Show(); //show the new form } else { //personal.UserID //personal.FirstName //personal.LastName //personal.Gender //personal.Status //personal.CityId //personal.Age //personal.Children //context.Expenses.Add(expense); context.SaveChanges(); context.SaveChanges(); // Refresh the grids so the database generated values show up. //this.p.Items.Refresh(); //this.productsDataGrid.Items.Refresh(); } } } else { // MessageBox.Show("personal ID is not valid"); } MainPersonal newForm = new MainPersonal(); //create your new form. this.Hide(); newForm.Show(); //show the new form }
private void add_Click(object sender, RoutedEventArgs e) { if (personal.Gender != 1 && personal.Gender != 2) { MessageBox.Show("Gender Required"); return; } if ((Regex.IsMatch(personalId.Text, "[^0-9]+")) || personalId.Text == null || personalId.Text == "" || personalId.Text.Length > 9) { MessageBox.Show("personal ID is not valid"); return; } if (Regex.IsMatch(firstName.Text, "[^a-zA-Z]+") || firstName.Text == null || firstName.Text == "") { MessageBox.Show("This textbox accepts only alphabetical characters"); return; } if (Regex.IsMatch(lastName.Text, "[^a-zA-Z]+") || lastName.Text == null || lastName.Text == "") { MessageBox.Show("This textbox accepts only alphabetical characters"); return; } if (Regex.IsMatch(age.Text, "[^0-9]+") || age.Text == null || age.Text == "") { MessageBox.Show("age is not valid"); return; } if (Regex.IsMatch(numChildren.Text, "[^0-9]+") || numChildren.Text == null || numChildren.Text == "") { MessageBox.Show("num children is not valid"); return; } if (personalId.Text != null && personalId.Text != "") { var list = from p in context.Personals select p; ObservableCollection <Personal> personals = new ObservableCollection <Personal>(list); //Personal personal = new Personal(); foreach (var per in personals) { if (per.UserID == int.Parse(personalId.Text)) { MessageBox.Show("personal ID is exit"); return; //var newForm = new MainPersonal(per); //create your new form. ////var newForm = new MainPerson(int.Parse(personalIDTextBox.Text)); //create your new form. //newForm.Show(); //show the new form } } try { personal.UserID = int.Parse(personalId.Text); personal.FirstName = firstName.Text; personal.LastName = lastName.Text; personal.Age = float.Parse(age.Text); personal.Children = int.Parse(numChildren.Text); //personal.Gender = personal.Gender; // Refresh the grids so the database generated values show up. //this.p.Items.Refresh(); //this.productsDataGrid.Items.Refresh(); context.Personals.Add(personal); context.SaveChanges(); MainPersonal newForm = new MainPersonal(); //create your new form. this.Hide(); newForm.Show(); //show the new form } catch (DbEntityValidationException eee) { MessageBox.Show(eee.EntityValidationErrors.ToString()); } } else { // MessageBox.Show("personal ID is not valid"); } }