private void CommandBinding_Executed_1(object sender, ExecutedRoutedEventArgs e) { if (thirdPArty_serviceCmb.IsChecked == true) { if (clientCmb.SelectedItem == null || brandCmb.SelectedItem == null || string.IsNullOrEmpty(unique_referenceTextBox.Text) || string.IsNullOrEmpty(commercial_invoiceTextBox.Text) || purchase_dateDatePicker.DisplayDate.ToString() == "" || userCmb.SelectedItem == null || string.IsNullOrEmpty(in_dateDatePicker.DisplayDate.ToString())) { MessageBox.Show("Los campos cliente, marca, imei o serie, factura, fecha de compra, tecnico encargado y fecha de entrada no deben ser nulas"); return; } } else { if (clientCmb.SelectedItem == null || string.IsNullOrEmpty(unique_referenceTextBox.Text) || userCmb.SelectedItem == null || string.IsNullOrEmpty(in_dateDatePicker.DisplayDate.ToString())) { MessageBox.Show("Los campos cliente, imei o serie, tecnico encargado y fecha de entrada no deben estar vacios"); return; } } var mservice = new Models.services { id_service = service.id_service }; using (var context = new Models.solutecEntities()) { Models.customers newCustomer = (Models.customers)clientCmb.SelectedItem; Models.users newUser = (Models.users)userCmb.SelectedItem; context.services.Attach(mservice); if (thirdPArty_serviceCmb.IsChecked == true) { Models.brands newBrand = (Models.brands)brandCmb.SelectedItem; mservice.id_brand = newBrand.id_brand; mservice.is_warranty = true; mservice.purchase_date = purchase_dateDatePicker.DisplayDate; mservice.commercial_invoice = commercial_invoiceTextBox.Text; } else { mservice.is_warranty = false; } mservice.unique_reference = unique_referenceTextBox.Text; mservice.model = modelTextBox.Text; mservice.technical_operator = newUser.id_user; mservice.in_date = in_dateDatePicker.DisplayDate; context.Configuration.ValidateOnSaveEnabled = false; context.SaveChanges(); } mainw.Succesful("service"); }
private void CommandBinding_Executed(object sender, ExecutedRoutedEventArgs e) { if (thirdPArty_serviceCmb.IsChecked == true) { if (clientCmb.SelectedItem == null || brandCmb.SelectedItem == null || string.IsNullOrEmpty(unique_referenceTextBox.Text) || string.IsNullOrEmpty(commercial_invoiceTextBox.Text) || purchase_dateDatePicker.DisplayDate.ToString() == "" || userCmb.SelectedItem == null || string.IsNullOrEmpty(in_dateDatePicker.DisplayDate.ToString())) { MessageBox.Show("Los campos cliente, marca, imei o serie, factura, fecha de compra, tecnico encargado y fecha de entrada no deben ser nulas"); return; } } else { if (clientCmb.SelectedItem == null || string.IsNullOrEmpty(unique_referenceTextBox.Text) || userCmb.SelectedItem == null || string.IsNullOrEmpty(in_dateDatePicker.DisplayDate.ToString())) { MessageBox.Show("Los campos cliente, imei o serie, tecnico encargado y fecha de entrada no deben estar vacios"); return; } } using (context) { Models.services newService = new Models.services(); Models.customers newCustomer = (Models.customers)clientCmb.SelectedItem; Models.users newUser = (Models.users)userCmb.SelectedItem; newService.id_customer = newCustomer.id_customer; if (thirdPArty_serviceCmb.IsChecked == true) { Models.brands newBrand = (Models.brands)brandCmb.SelectedItem; newService.id_brand = newBrand.id_brand; newService.is_warranty = true; newService.purchase_date = purchase_dateDatePicker.DisplayDate; newService.commercial_invoice = commercial_invoiceTextBox.Text; } else { newService.is_warranty = false; } newService.unique_reference = unique_referenceTextBox.Text; newService.model = modelTextBox.Text; newService.technical_operator = newUser.id_user; newService.in_date = in_dateDatePicker.DisplayDate; context.services.Add(newService); context.SaveChanges(); disableAll(); mainw.Succesful("service"); lblNotification.Content = "Nuevo servicio registrado correctamente"; lblNotification.Visibility = Visibility.Visible; } }
private void SaveCommandHandler(Object sender, ExecutedRoutedEventArgs e) { if (commercial_nameTextBox.Text == "") { MessageBox.Show("El campo nombre comercial no puede estar vacio)"); return; } try { using (Models.solutecEntities context = new Models.solutecEntities()) { Models.brands newBrand = new Models.brands(); newBrand.commercial_name = commercial_nameTextBox.Text; newBrand.is_active = true; newBrand.nit = nitTextBox.Text; newBrand.nrc = nrcTextBox.Text; newBrand.start_date = start_dateDatePicker.DisplayDate; context.brands.Add(newBrand); context.SaveChanges(); lblNotification.Content = "Marca registrada correctamente"; notification.Visibility = Visibility.Visible; commercial_nameTextBox.IsEnabled = false; nitTextBox.IsEnabled = false; nrcTextBox.IsEnabled = false; start_dateDatePicker.IsEnabled = false; btnSave.IsEnabled = false; mainw.Succesful("brand"); } } catch (DbEntityValidationException i) { foreach (var eve in i.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } throw; } }