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 (string.IsNullOrEmpty(full_nameTextBox.Text) || string.IsNullOrEmpty(phone_numberTextBox.Text)) { MessageBox.Show("Los campos nombre y telefono no deben estar vacios"); return; } using (Models.solutecEntities context = new Models.solutecEntities()) { Models.customers newCustomer = new Models.customers(); newCustomer.full_name = full_nameTextBox.Text; newCustomer.phone_number = phone_numberTextBox.Text; newCustomer.is_active = true; newCustomer.nit = nitTextBox.Text; newCustomer.dui = duiTextBox.Text; newCustomer.address = addressTextBox.Text; if (direct_customer.IsChecked == true) { newCustomer.customer_type = 1; newCustomer.nrc = ""; } else { newCustomer.customer_type = 2; newCustomer.nrc = nrcTextBox.Text; } context.customers.Add(newCustomer); context.SaveChanges(); lblNotification.Content = "Cliente registrado correctamente"; notification.Visibility = Visibility.Visible; direct_customer.IsEnabled = false; thirdParty_customer.IsEnabled = false; full_nameTextBox.IsEnabled = false; phone_numberTextBox.IsEnabled = false; nitTextBox.IsEnabled = false; nrcTextBox.IsEnabled = false; duiTextBox.IsEnabled = false; addressTextBox.IsEnabled = false; btnSave.IsEnabled = false; mainw.Succesful("customer"); } }
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; } }
private void SaveCommandHandler(Object sender, ExecutedRoutedEventArgs e) { if (userTextBox.Text == "" || password.Password == "") { MessageBox.Show("Los campos usuario y contraseña no deben estar vacios"); return; } try { using (Models.solutecEntities context = new Models.solutecEntities()) { Models.users newUser = new Models.users(); newUser.user = userTextBox.Text; newUser.is_active = true; newUser.password = mainw.GetSHA1(password.Password); short user_type = 0; switch (user_typeComboBox.Text) { case "Administrador": user_type = 1; break; case "Atencion al cliente": user_type = 2; break; case "Tecnico": user_type = 3; break; default: user_type = 1; break; } newUser.user_type = user_type; context.users.Add(newUser); context.SaveChanges(); lblNotification.Content = "Usuario registrado correctamente"; notification.Visibility = Visibility.Visible; userTextBox.IsEnabled = false; password.IsEnabled = false; user_typeComboBox.IsEnabled = false; btnSave.IsEnabled = false; mainw.Succesful("user"); } } 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; } }