private void BtnMale_Checked(object sender, RoutedEventArgs e) { this.user.Gender = "Male"; context.SaveChanges(); this._Gender = true; OnPropertyChanged("Gender"); }
public void Add() { Repair c = new Repair(); c.DayOfRepair = DateTime.Now; c.Description = "Engine"; c.PriceOfRepair = 120.50; c.CarID = carID; context.Repairs.Add(c); context.SaveChanges(); }
public void delete() { using (var contex = new CarServiceDBEntities1()) { foreach (Car c in contex.Cars) { contex.Cars.Remove(c); } contex.SaveChanges(); } }
private void BtnAdd_Click(object sender, RoutedEventArgs e) { int result = 0; txtVinNumber.GetBindingExpression(TextBox.TextProperty).UpdateSource(); txtRegNumber.GetBindingExpression(TextBox.TextProperty).UpdateSource(); foreach (TextBox txt in gr.Children.OfType <TextBox>()) { result += System.Windows.Controls.Validation.GetErrors(txt).Count; } if (result == 0) { using (CarServiceDBEntities1 context = new CarServiceDBEntities1()) { foreach (Car car in context.Cars) { if (car.WINnumber == this.VINNumber) { MessageBox.Show("Car with this VIN number already exists"); return; } if (car.RegNumber == this.RegNumber) { MessageBox.Show("Car with this registration number already exists"); return; } } Car c = new Car(); c.BrandID = br.Id; c.ModelID = context.Models.Where(i => i.Name == SelectedModel).Select(i => i.Id).First(); c.WINnumber = VINNumber; c.RegNumber = RegNumber; c.Colour = SelectedColour; c.UserID = this.id; context.Cars.Add(c); context.SaveChanges(); MessageBox.Show("Done"); this.Close(); } } }
private void BtnAdd_Click(object sender, RoutedEventArgs e) { if (!Regex.Match(txtRead.Text, @"^[A-Z]{1}[a-z]*$").Success) { MessageBox.Show("Brand name can contain only letters and must start with upper case!"); return; } else { using (CarServiceDBEntities1 context = new CarServiceDBEntities1()) { br.Name = txtRead.Text.ToString(); context.Brands.Add(br); context.SaveChanges(); MessageBox.Show("Done!"); this.Close(); } } }
protected void OnCellEditEnding(object sender, DataGridCellEditEndingEventArgs e) { DataGridRow r = (DataGridRow)datagr.ItemContainerGenerator.ContainerFromIndex(datagr.SelectedIndex); DataGridCell RowColumn = datagr.Columns[0].GetCellContent(r).Parent as DataGridCell; string modelName = ((TextBox)RowColumn.Content).Text; ((TextBox)RowColumn.Content).GetBindingExpression(TextBox.TextProperty).UpdateSource(); if (System.Windows.Controls.Validation.GetErrors(((TextBox)RowColumn.Content)).Count != 0) { return; } var model = context.Models.Where(i => i.Name == selectedModel).First(); if (!Regex.Match(modelName, @"^[A-Z]{1}[a-z]*$").Success) { MessageBox.Show("Model name can contain only letters and must start with upper case!"); return; } if (modelName == "" || modelName.Equals(selectedModel)) { return; } foreach (Model m in context.Models) { if (m.Name.Equals(modelName, StringComparison.InvariantCultureIgnoreCase)) { MessageBox.Show("Brand with this name already exists"); return; } } model.Name = modelName; context.SaveChanges(); selectedModel = modelName; ModelList = context.Models.Where(i => i.Brand.Id == this.BrandID).ToList(); OnPropertyChanged("_Models"); }
private void BtnAdd_Click(object sender, RoutedEventArgs e) { txtName.GetBindingExpression(TextBox.TextProperty).UpdateSource(); txtSurename.GetBindingExpression(TextBox.TextProperty).UpdateSource(); txtIdNumber.GetBindingExpression(TextBox.TextProperty).UpdateSource(); txtEGN.GetBindingExpression(TextBox.TextProperty).UpdateSource(); txtCountry.GetBindingExpression(TextBox.TextProperty).UpdateSource(); txtCity.GetBindingExpression(TextBox.TextProperty).UpdateSource(); txtStreet.GetBindingExpression(TextBox.TextProperty).UpdateSource(); txtPhone.GetBindingExpression(TextBox.TextProperty).UpdateSource(); txtEmail.GetBindingExpression(TextBox.TextProperty).UpdateSource(); int result = 0; foreach (TextBox txt in gr.Children.OfType <TextBox>()) { result += System.Windows.Controls.Validation.GetErrors(txt).Count; } if (result == 0) { using (var context = new CarServiceDBEntities1()) { foreach (User user in context.Users) { if (user.EGN == long.Parse(txtEGN.Text)) { MessageBox.Show("User with this EGN already exists!"); return; } if (user.IdCardNumber == long.Parse(txtIdNumber.Text)) { MessageBox.Show("User with this ID card already exists!"); return; } } User u = new User(); u.Name = txtName.Text; u.Surename = txtSurename.Text; u.IdCardNumber = long.Parse(txtIdNumber.Text); u.EGN = long.Parse(txtEGN.Text); u.Address = txtCountry.Text + ", " + txtCity.Text + ", " + txtStreet.Text; if (btnMale.IsChecked == true) { u.Gender = btnMale.Content.ToString(); } if (btnFemale.IsChecked == true) { u.Gender = btnMale.Content.ToString(); } u.PhoneNumber = txtPhone.Text; u.Email = txtEmail.Text; context.Users.Add(u); try { context.SaveChanges(); } catch (DbEntityValidationException ex) { foreach (var errors in ex.EntityValidationErrors) { foreach (var validationError in errors.ValidationErrors) { string errorMessage = validationError.ErrorMessage; MessageBox.Show(errorMessage); } } } } MessageBox.Show("Done"); this.Close(); } }