Ejemplo n.º 1
0
        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;
            }
        }
        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();
        }
Ejemplo n.º 3
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));
                }
            }
        }