Example #1
0
        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;
            }
        }
Example #2
0
        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");
        }