private void btnAceptar_Click(object sender, EventArgs e)
        {
            bool isEmpty = !Helper.Llenos(txtCodigo, txtDescripcion, txtPrecioMinimo);

            if (isEmpty)
            {
                MessageBox.Show("Llene todos los campos, por favor", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Warning); return;
            }

            decimal minimo;

            string code           = txtCodigo.Text;
            string descripcion    = txtDescripcion.Text;
            bool   parseIncorrect = !decimal.TryParse(txtPrecioMinimo.Text, out minimo);

            if (parseIncorrect)
            {
                MessageBox.Show("El precio no es valido", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Warning); return;
            }
            minimo = Math.Round(minimo, 2);

            if (CurrentRefaccion == null)
            {
                var toAdd = new Refaccion()
                {
                    Codigo       = code,
                    Descripcion  = descripcion,
                    PrecioMinimo = minimo,
                };

                var res = Validator.Validate(toAdd);
                if (ShowErrorValidation.Valid(res))
                {
                    CurrentRefaccion = RefaccionController.I.Add(toAdd);
                }
            }
            else
            {
                CurrentRefaccion.Codigo       = code;
                CurrentRefaccion.Descripcion  = descripcion;
                CurrentRefaccion.PrecioMinimo = minimo;

                var res = Validator.Validate(CurrentRefaccion);
                if (ShowErrorValidation.Valid(res))
                {
                    CurrentRefaccion = RefaccionController.I.Edit(CurrentRefaccion);
                }
            }

            if (CurrentRefaccion == null)
            {
                MessageBox.Show("Error agregar o editar refaccion", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            CurrentRefaccion = null;
            Helper.VaciarTexto(txtCodigo, txtDescripcion, txtPrecioMinimo);
        }
Esempio n. 2
0
        private void btnAcept_Click(object sender, EventArgs e)
        {
            bool isValid = Helper.Llenos(txtUsuario, txtPassword) && txtPassword.TextLength >= 8;

            if (!isValid)
            {
                MessageBox.Show("Introduzca un usuario y una contraseña validos", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Warning); return;
            }

            if (cUser == null)
            {
                var newUser = new Usuario()
                {
                    Usuario1 = txtUsuario.Text,
                    Password = txtPassword.Text
                };
                var res = UsuarioValidator.Validate(newUser);
                if (ShowErrorValidation.Valid(res))
                {
                    cUser = UsuarioController.I.Add(newUser);
                }
            }
            else
            {
                var isCurrenUser = false;
                if (cUser.Id == CurrentUser.User.Id)
                {
                    isCurrenUser = true;
                    if (MessageBox.Show("Se reiniciara la aplicacion para aplicar cambios\n¿Desea continuar?", "Advertencia", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
                    {
                        return;
                    }
                }
                cUser.Usuario1 = txtUsuario.Text;
                cUser.Password = txtPassword.Text;
                var res = UsuarioValidator.Validate(cUser);
                if (ShowErrorValidation.Valid(res))
                {
                    cUser = UsuarioController.I.Edit(cUser);
                }
                if (cUser != null && isCurrenUser)
                {
                    Application.Restart();
                }
            }

            if (cUser == null)
            {
                MessageBox.Show("No se pudo agregar o editar el usuario", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }


            cUser = null;
            this.Dispose();
        }
        private void btnAceptar_Click(object sender, EventArgs e)
        {
            bool isValid = Helper.Llenos(txtNombre, txtDir, txtTel);

            if (!isValid)
            {
                return;
            }

            if (CurrentCliente == null)
            {
                var newCliente = new Cliente
                {
                    Direccion = txtDir.Text,
                    Nombre    = txtNombre.Text,
                    Telefono  = txtTel.Text
                };

                var res = ClienteValidator.Validate(newCliente);

                if (ShowErrorValidation.Valid(res))
                {
                    CurrentCliente = ClienteController.I.Add(newCliente);
                }
            }
            else
            {
                CurrentCliente.Direccion = txtDir.Text;
                CurrentCliente.Nombre    = txtNombre.Text;
                CurrentCliente.Telefono  = txtTel.Text;

                var res = ClienteValidator.Validate(CurrentCliente);
                if (ShowErrorValidation.Valid(res))
                {
                    CurrentCliente = ClienteController.I.Edit(CurrentCliente);
                }
            }

            if (CurrentCliente == null)
            {
                MessageBox.Show("No se pudo agregar o editar el cliente, intente de nuevo", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            Actualizar();

            Helper.VaciarTexto(txtNombre, txtDir, txtTel);
            CurrentCliente = null;

            lblTittle.Hide();
            dataPanel.Hide();
        }
        private void btnAceptar_Click(object sender, EventArgs e)
        {
            bool isValid = Helper.Llenos(txtNombre) && txtNombre.TextLength < 25;

            if (!isValid)
            {
                MessageBox.Show("El nombre no puede pasar de 25 caracteres", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Warning); return;
            }

            if (CurrentMecanico == null)
            {
                var newMec = new Mecanico
                {
                    Nombre = txtNombre.Text
                };

                var res = MecanicoValidator.Validate(newMec);

                if (ShowErrorValidation.Valid(res))
                {
                    CurrentMecanico = MecanicoController.I.Add(newMec);
                }
            }
            else
            {
                CurrentMecanico.Nombre = txtNombre.Text;

                var res = MecanicoValidator.Validate(CurrentMecanico);

                if (ShowErrorValidation.Valid(res))
                {
                    CurrentMecanico = MecanicoController.I.Edit(CurrentMecanico);
                }
            }

            if (CurrentMecanico == null)
            {
                MessageBox.Show("No se pudo agregar o editar el mecanico, intente de nuevo", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            Actualizar();

            Helper.VaciarTexto(txtNombre);
            CurrentMecanico = null;

            lblTittle.Hide();
            dataPanel.Hide();
        }
Esempio n. 5
0
        private void btnAceptar_Click(object sender, EventArgs e)
        {
            if (MessageDialog.ShowMessageDialog("", "¿Toda la infotmacion ingresada es correcta?", false) == (int)MessageDialogResult.No)
            {
                return;
            }

            switch (_status)
            {
            case OrdenStatus.GARANTIA_POR_ENTREGAR:
                _FechaEntrega             = cdtpFechaEntrega.Value;
                CurrentOrden.FechaEntrega = _FechaEntrega;
                break;

            case OrdenStatus.POR_ENTREGAR:
                _MetodoPago               = (TipoPago)Enum.Parse(typeof(TipoPago), cbFormaDePago.SelectedValue.ToString());
                _FechaEntrega             = cdtpFechaEntrega.Value;
                _Referencia               = txtRef.Text;
                CurrentOrden.Referencia   = _Referencia;
                CurrentOrden.FechaEntrega = _FechaEntrega;
                CurrentOrden.TipoPago     = (int)_MetodoPago;
                break;

            default:
                break;
            }


            var res = OrdenValidator.Validate(CurrentOrden);

            if (ShowErrorValidation.Valid(res))
            {
                _Result = true;
            }
            else
            {
                _Result = false;
            }

            this.Dispose();
        }
        private void btnAgregar_Click(object sender, EventArgs e)
        {
            bool isValid = Helper.Llenos(txtCant, txtCodigo, txtPrecio) && CurrentRefaccion != null;

            if (!isValid)
            {
                return;
            }

            int     cantidad = int.Parse(txtCant.Text);
            decimal precio   = decimal.Parse(txtPrecio.Text);

            if (precio < CurrentRefaccion.PrecioMinimo)
            {
                MessageBox.Show("El precio es menor que el costo minimo", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Warning); return;
            }

            var newRef = new RefaccionDTO()
            {
                Id            = CurrentRefaccion.Id,
                Codigo        = CurrentRefaccion.Codigo,
                Descripcion   = CurrentRefaccion.Descripcion,
                Cantidad      = cantidad,
                PrecioUnitrio = precio,
            };

            var resp = RefaccionValidator.Validate(newRef);

            if (ShowErrorValidation.Valid(resp))
            {
                Refacciones.Add(newRef);
            }

            MessageDialog.ShowMessageDialog("", $"Se ha agregado la refaccion {CurrentRefaccion.Codigo} a la orden ", true);
            Helper.VaciarTexto(txtCant, txtCodigo, txtPrecio);
            CurrentRefaccion = null;
        }
        private void fbtnAdd_Click(object sender, EventArgs e)
        {
            var orden = WarrantyDialog.showWarrantyDialog();

            if (orden == null)
            {
                return;
            }

            orden = OrdenController.I.GetOrdenById(orden.Id);

            /* Siempre entra en el if si la garantia es valida
             *
             * //Si la orden se entrego hace mas de 3 meses, y se aprueba por el usuario se edita
             * bool isInvalidWarranty = orden.FechaEntrega <= DateTime.Now.AddMonths(-3);
             * isInvalidWarranty = isInvalidWarranty ? MessageDialog.ShowMessageDialog("Confirmacion", "La garantia ha vencido\n¿Desea agregar la orden aun asi?", false) == (int)MessageDialogResult.Yes : false;
             * if (!isInvalidWarranty)
             *  return;
             */
            bool ForceWarranty     = false;
            bool isInvalidWarranty = orden.FechaEntrega <= DateTime.Now.AddMonths(-3);

            if (!isInvalidWarranty)
            {
                ForceWarranty = MessageDialog.ShowMessageDialog("Confirmacion", "La garantia ha vencido\n¿Desea agregar la orden aun asi?", false) == (int)MessageDialogResult.Yes;
            }

            if (!isInvalidWarranty && !ForceWarranty) //Si no es valida y no se va a forzar la garantia: no continua
            {
                return;
            }

            //si es valida la garantia O se va a forzar: continua

            orden.Status = (int)OrdenStatus.GARANTIA;
            //validar Orden antes de modificar
            var res = OrdenValidator.Validate(orden);

            if (ShowErrorValidation.Valid(res))
            {
                orden = OrdenController.I.Edit(orden);
            }

            if (orden == null)
            {
                MessageBox.Show("Error al cambiar el status de la orden", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            var ordenHistorial = new OrdenHistorial()
            {
                IdOrden     = orden.Id,
                FechaStatus = DateTime.Now,
                Status      = (int)OrdenStatus.GARANTIA,
            };

            //Agrega el estado de la orden al historial
            res = OrdenHistorialValidator.Validate(ordenHistorial);
            if (ShowErrorValidation.Valid(res))
            {
                //Agrega el estado de la orden al historial
                var saved = OrdenHistorialController.I.Add(ordenHistorial);
                if (saved == null)
                {
                    MessageBox.Show("No se puede agregar al historial de ordenes", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            loadOrdenes();
        }
        private void btnAceptar_Click(object sender, EventArgs e)
        {
            bool isEmpty = !Helper.Llenos(txtEquipo, txtObservaciones, txtFolio);

            if (cliente == null || isEmpty)
            {
                return;
            }

            int      folio         = int.Parse(txtFolio.Text);
            string   equipo        = txtEquipo.Text;
            string   observaciones = txtObservaciones.Text;
            DateTime recepcion     = cdtpFechaRecepcion.Value;

            var orden = new Orden()
            {
                Folio          = folio,
                Equipo         = equipo,
                FechaRecepcion = recepcion,
                Observaciones  = observaciones,
                Status         = (int)OrdenStatus.ESPERA,
                IdCliente      = cliente.Id
            };

            var res = OrdenValidator.Validate(orden);

            if (ShowErrorValidation.Valid(res))
            {
                orden = OrdenController.I.Add(orden);
            }


            if (orden == null)
            {
                MessageBox.Show("Error al agregar a la base de datos", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return;
            }

            //Agrega el estado de la orden al historial
            var ordenHistorial = new OrdenHistorial()
            {
                IdOrden     = orden.Id,
                FechaStatus = DateTime.Now,
                Status      = (int)OrdenStatus.ESPERA
            };

            res = OrdenHistorialValidator.Validate(ordenHistorial);
            if (ShowErrorValidation.Valid(res))
            {
                var saved = OrdenHistorialController.I.Add(ordenHistorial);
                if (saved == null)
                {
                    MessageBox.Show("No se puede agregar al historial de ordenes", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            if (orden != null)
            {
                Helper.VaciarTexto(txtFolio, txtEquipo, txtObservaciones, txtTelefono, txtDireccion, txtCliente);
                Console.WriteLine(orden.ToString());
                orden          = null;
                cliente        = null;
                ordenHistorial = null;
            }
        }
Esempio n. 9
0
        async void showOrdenes()
        {
            ListaOrdenes = await Task.Run(() => OrdenController.I.GetLista((int)Estado).Select(el => new OrdenItemList(el)).ToList());

            this.flpList.Controls.Clear();
            foreach (OrdenItemList item in ListaOrdenes)
            {
                switch (Estado)
                {
                case OrdenStatus.ESPERA:
                    this.flpList.Controls.Add(item);
                    item.btnAction.Click += (s, e) =>
                    {
                        CurrentOrden    = item.Orden;
                        CurrentMecanico = MecanicoDialog.showClientDialog(CurrentOrden);
                        if (CurrentMecanico == null)
                        {
                            return;
                        }

                        CurrentOrden.Status = AssignNextStatusOrder();

                        //validar Orden antes de modificar
                        var res = OrdenValidator.Validate(CurrentOrden);
                        if (ShowErrorValidation.Valid(res))
                        {
                            CurrentOrden = OrdenController.I.Edit(CurrentOrden);
                        }

                        if (CurrentOrden == null)
                        {
                            MessageBox.Show("No se puede cambiar el status, intente de nuevo", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return;
                        }

                        var ordenMecanico = OrdenMecanicoController.I.Add(new OrdenMecanico()
                        {
                            IdOrden    = CurrentOrden.Id,
                            IdMecanico = CurrentMecanico.Id
                        });

                        if (ordenMecanico == null)
                        {
                            MessageBox.Show("No se puede asignar el mecanico a la orden", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return;
                        }

                        var oh = new OrdenHistorial()
                        {
                            IdOrden     = CurrentOrden.Id,
                            FechaStatus = DateTime.Now,
                            Status      = AssignNextStatusOrder()
                        };

                        res = OrdenHistorialValidator.Validate(oh);
                        if (ShowErrorValidation.Valid(res))
                        {
                            //Agrega el estado de la orden al historial
                            var saved = OrdenHistorialController.I.Add(oh);
                            if (saved == null)
                            {
                                MessageBox.Show("No se puede agregar al historial de ordenes", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                        //Repaint controls with new data
                        showOrdenes();
                    };

                    break;

                case OrdenStatus.POR_ENTREGAR:
                    this.flpList.Controls.Add(item);
                    item.btnAction.Click += (s, e) =>
                    {
                        CurrentOrden = item.Orden;

                        var aux = EntregarDialog.ShowEntregarOrden(CurrentOrden);
                        if (!aux.Result)
                        {
                            return;
                        }

                        CurrentOrden.TipoPago     = (int)aux.MetodoPago;
                        CurrentOrden.FechaEntrega = aux.FechaEntrega;
                        CurrentOrden.Referencia   = aux.Referencia;
                        CurrentOrden.Status       = AssignNextStatusOrder();

                        //validar Orden antes de modificar
                        var res = OrdenValidator.Validate(CurrentOrden);
                        if (ShowErrorValidation.Valid(res))
                        {
                            CurrentOrden = OrdenController.I.Edit(CurrentOrden);
                        }

                        if (CurrentOrden == null)
                        {
                            MessageBox.Show("No se puede cambiar el status, intente de nuevo", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return;
                        }

                        var ordenHistorial = new OrdenHistorial()
                        {
                            IdOrden     = CurrentOrden.Id,
                            FechaStatus = aux.FechaEntrega,
                            Status      = AssignNextStatusOrder()
                        };

                        res = OrdenHistorialValidator.Validate(ordenHistorial);
                        if (ShowErrorValidation.Valid(res))
                        {
                            //Agrega el estado de la orden al historial
                            var saved = OrdenHistorialController.I.Add(ordenHistorial);
                            if (saved == null)
                            {
                                MessageBox.Show("No se puede agregar al historial de ordenes", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                        //Repaint controls with new data
                        showOrdenes();
                    };
                    break;

                case OrdenStatus.GARANTIA_POR_ENTREGAR:
                    this.flpList.Controls.Add(item);
                    item.btnAction.Click += (s, e) =>
                    {
                        CurrentOrden = item.Orden;

                        var aux = EntregarDialog.ShowEntregarOrden(CurrentOrden);
                        if (!aux.Result)
                        {
                            return;
                        }

                        CurrentOrden.FechaEntrega = aux.FechaEntrega;
                        CurrentOrden.Status       = AssignNextStatusOrder();

                        //validar Orden antes de modificar
                        var res = OrdenValidator.Validate(CurrentOrden);
                        if (ShowErrorValidation.Valid(res))
                        {
                            CurrentOrden = OrdenController.I.Edit(CurrentOrden);
                        }

                        if (CurrentOrden == null)
                        {
                            MessageBox.Show("No se puede cambiar el status, intente de nuevo", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return;
                        }

                        var ordenHistorial = new OrdenHistorial()
                        {
                            IdOrden     = CurrentOrden.Id,
                            FechaStatus = aux.FechaEntrega,
                            Status      = AssignNextStatusOrder()
                        };

                        res = OrdenHistorialValidator.Validate(ordenHistorial);
                        if (ShowErrorValidation.Valid(res))
                        {
                            //Agrega el estado de la orden al historial
                            var saved = OrdenHistorialController.I.Add(ordenHistorial);
                            if (saved == null)
                            {
                                MessageBox.Show("No se puede agregar al historial de ordenes", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                        //Repaint controls with new data
                        showOrdenes();
                    };
                    break;

                default:
                    throw new ArgumentException("No se soporta el status", nameof(OrdenStatus));
                }
            }
        }