コード例 #1
0
        private void CargarDGVListarPedidos()
        {
            dgvListaPedidos.Rows.Clear();

            string InformacionDelError = string.Empty;

            ClsPedidos    Pedidos          = new ClsPedidos();
            List <Pedido> PedidosEnProceso = Pedidos.LeerListado(ClsPedidos.ETipoDeListado.PedidosEnProceso, ref InformacionDelError);

            if (PedidosEnProceso != null)
            {
                foreach (Pedido Elemento in PedidosEnProceso)
                {
                    int NumeroDeFila = dgvListaPedidos.Rows.Add();

                    dgvListaPedidos.Columns[(int)ENumColDGVListaPedidos.ID_Pedido].SortMode    = DataGridViewColumnSortMode.NotSortable;
                    dgvListaPedidos.Columns[(int)ENumColDGVListaPedidos.TiempoEspera].SortMode = DataGridViewColumnSortMode.NotSortable;
                    dgvListaPedidos.Columns[(int)ENumColDGVListaPedidos.EsDelivery].SortMode   = DataGridViewColumnSortMode.NotSortable;
                    dgvListaPedidos.Columns[(int)ENumColDGVListaPedidos.Mozos].SortMode        = DataGridViewColumnSortMode.NotSortable;
                    dgvListaPedidos.Columns[(int)ENumColDGVListaPedidos.Mesas].SortMode        = DataGridViewColumnSortMode.NotSortable;
                    dgvListaPedidos.Columns[(int)ENumColDGVListaPedidos.Seleccionar].SortMode  = DataGridViewColumnSortMode.NotSortable;

                    dgvListaPedidos.Rows[NumeroDeFila].Cells[(int)ENumColDGVListaPedidos.ID_Pedido].Value = Elemento.ID_Pedido;

                    string[] Tiempo;
                    int      Horas   = 0;
                    int      Minutos = 0;

                    if (Elemento.TiempoEspera.Value.Date == DateTime.Now.Date && (Horas < 24 && Minutos < 60))
                    {
                        Tiempo = (DateTime.Now.TimeOfDay - Elemento.TiempoEspera.Value.TimeOfDay).ToString(@"hh\:mm").Split(':');

                        Horas   = Convert.ToInt32(Tiempo[0]);
                        Minutos = Convert.ToInt32(Tiempo[1]);

                        dgvListaPedidos.Rows[NumeroDeFila].Cells[(int)ENumColDGVListaPedidos.TiempoEspera].Value = (DateTime.Now.TimeOfDay - Elemento.TiempoEspera.Value.TimeOfDay).ToString(@"hh\:mm");
                    }
                    else
                    {
                        // Hay un dia de diferencia solamente
                        if (Elemento.TiempoEspera.Value.Day == DateTime.Now.AddDays(-1).Day)
                        {
                            Tiempo = (new TimeSpan(24, 0, 0) - Elemento.TiempoEspera.Value.TimeOfDay).ToString(@"hh\:mm").Split(':');

                            Horas   = Convert.ToInt32(Tiempo[0]) + DateTime.Now.Hour;
                            Minutos = Convert.ToInt32(Tiempo[1]) + DateTime.Now.Minute;

                            // Calcular aumento de hora
                            if (Minutos >= 60)
                            {
                                Horas   += 1;
                                Minutos += (60 - Minutos);
                            }

                            // Este if evitara mostrar una hora mayor a 24 en caso de problemas con la sincronizacion del
                            // reloj de la computadora
                            if (Horas < 24)
                            {
                                if (Minutos < 10)
                                {
                                    if (Horas < 10)
                                    {
                                        dgvListaPedidos.Rows[NumeroDeFila].Cells[(int)ENumColDGVListaPedidos.TiempoEspera].Value = $"0{Horas}:0{Minutos}";
                                    }
                                    else
                                    {
                                        dgvListaPedidos.Rows[NumeroDeFila].Cells[(int)ENumColDGVListaPedidos.TiempoEspera].Value = $"{Horas}:0{Minutos}";
                                    }
                                }
                                else
                                {
                                    if (Horas < 10)
                                    {
                                        dgvListaPedidos.Rows[NumeroDeFila].Cells[(int)ENumColDGVListaPedidos.TiempoEspera].Value = $"0{Horas}:{Minutos}";
                                    }
                                    else
                                    {
                                        dgvListaPedidos.Rows[NumeroDeFila].Cells[(int)ENumColDGVListaPedidos.TiempoEspera].Value = $"{Horas}:{Minutos}";
                                    }
                                }
                            }
                            else
                            {
                                dgvListaPedidos.Rows[NumeroDeFila].Cells[(int)ENumColDGVListaPedidos.TiempoEspera].Value = "--:--";
                            }
                        }
                        else
                        {
                            dgvListaPedidos.Rows[NumeroDeFila].Cells[(int)ENumColDGVListaPedidos.TiempoEspera].Value = "--:--";
                        }
                    }

                    if (Horas > 0 || Minutos > 40)
                    {
                        dgvListaPedidos.Rows[NumeroDeFila].DefaultCellStyle.BackColor = ClsColores.Rojo;
                    }
                    else if (Minutos >= 20)
                    {
                        dgvListaPedidos.Rows[NumeroDeFila].DefaultCellStyle.BackColor = ClsColores.NaranjaClaro;
                    }

                    string NombreMozo = string.Empty;

                    if (Elemento.ID_Delivery == null)
                    {
                        dgvListaPedidos.Rows[NumeroDeFila].Cells[(int)ENumColDGVListaPedidos.EsDelivery].Value = "NO";

                        ClsPedidosXMesas PedidosXMesas = new ClsPedidosXMesas();
                        PedidoXMesa      BuscarDatos   = PedidosXMesas.LeerPorNumero(Elemento.ID_Pedido, ref InformacionDelError);

                        if (BuscarDatos != null)
                        {
                            NombreMozo = $"{BuscarDatos.Mesa.Usuario.Nombre} {BuscarDatos.Mesa.Usuario.Apellido}";
                        }
                    }
                    else
                    {
                        dgvListaPedidos.Rows[NumeroDeFila].Cells[(int)ENumColDGVListaPedidos.EsDelivery].Value = "SI";
                    }

                    dgvListaPedidos.Rows[NumeroDeFila].Cells[(int)ENumColDGVListaPedidos.Mozos].Value       = NombreMozo;
                    dgvListaPedidos.Rows[NumeroDeFila].Cells[(int)ENumColDGVListaPedidos.Mesas].Value       = "Ver";
                    dgvListaPedidos.Rows[NumeroDeFila].Cells[(int)ENumColDGVListaPedidos.Seleccionar].Value = false;

                    dgvListaPedidos.Rows[NumeroDeFila].Cells[(int)ENumColDGVListaPedidos.Mesas].Style.SelectionBackColor       = ClsColores.Transparente;
                    dgvListaPedidos.Rows[NumeroDeFila].Cells[(int)ENumColDGVListaPedidos.Seleccionar].Style.SelectionBackColor = ClsColores.Transparente;

                    // Quitarle el color de toda la fila a estas casillas
                    dgvListaPedidos.Rows[NumeroDeFila].Cells[(int)ENumColDGVListaPedidos.Mesas].Style.BackColor       = ClsColores.GrisOscuroFondo;
                    dgvListaPedidos.Rows[NumeroDeFila].Cells[(int)ENumColDGVListaPedidos.Seleccionar].Style.BackColor = ClsColores.GrisOscuroFondo;

                    UltimaFilaSeleccionada = -1;

                    dgvListaPedidos.ClearSelection();
                }
            }
            else if (InformacionDelError == string.Empty)
            {
                FrmPrincipal.ObtenerInstancia().MensajeAdvertencia("Fallo al cargar el pedido");
            }
            else
            {
                FrmPrincipal.ObtenerInstancia().MensajeAdvertencia("Fallo al cargar el pedido");
                MessageBox.Show($"{InformacionDelError}", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            // Comprobar si el pedido que estaba en pantalla sigue disponible al actualizar
            if (dgvPlatosPorMesa.Rows.Count > 0)
            {
                int  PedidoCargado      = (int)dgvPlatosPorMesa.Rows[0].Cells[(int)ENumColDGVPlatosPorMesa.ID_Pedido].Value;
                int  TotalDeFilas       = dgvListaPedidos.Rows.Count;
                bool PedidoNoEncontrado = true;

                for (int Indice = 0; Indice < TotalDeFilas; Indice++)
                {
                    if (PedidoCargado == (int)dgvListaPedidos.Rows[Indice].Cells[(int)ENumColDGVPlatosPorMesa.ID_Pedido].Value)
                    {
                        PedidoNoEncontrado = false;
                    }
                }

                if (PedidoNoEncontrado)
                {
                    dgvPlatosPorMesa.Rows.Clear();
                    lblDetallesDelPedido.Text = string.Empty;
                }
                else
                {
                    // Encontro el pedido, lo actualizo
                    ActualizaInformacionPedido(PedidoCargado);
                }
            }

            PedidosCancelados();
        }
コード例 #2
0
        /// <summary>
        /// Carga el DGV
        /// </summary>
        /// <param name="_TipoDeListado">Indica el tipo de listado que se cargara.</param>
        /// <param name="_DeliveryEnCocinaYNoEntregado">Si es true, listara los deliveries en cocina y no entregados del dia
        /// anterior en adelante.</param>
        private void CargarDGVDelivery(ClsPedidos.ETipoDeListado _TipoDeListado, bool _DeliveryEnCocinaYNoEntregado = false)
        {
            dgvDelivery.Rows.Clear();

            string InformacionDelError = string.Empty;

            // Inicio preparacion de filtros ----
            string NombreCliente = string.Empty;

            int ID_EstadoDelivery = 0;

            if (cmbEstadoEnvio.SelectedValue != null)
            {
                EstadoDelivery EstadoDeliverySeleccionado = (EstadoDelivery)cmbEstadoEnvio.SelectedItem;
                ID_EstadoDelivery = EstadoDeliverySeleccionado.ID_EstadoDelivery;
            }

            if (txtBuscarPorNombre.Text != TEXTO_VISUAL_BUSCAR)
            {
                NombreCliente = txtBuscarPorNombre.Text;
            }

            string FechaDesde = Convert.ToString(dtpFechaDesde.Value.Date);
            string FechaHasta = Convert.ToString(dtpDechaHasta.Value.Date);

            if (!ckbIncluirFechaDesde.Checked)
            {
                FechaDesde = string.Empty;
            }
            if (!ckbIncluirFechaHasta.Checked)
            {
                FechaHasta = string.Empty;
            }
            // Fin preparacion de filtros ----

            ClsPedidos Pedidos = new ClsPedidos();

            List <Pedido> CargarDGVDelivery = Pedidos.LeerListado(_TipoDeListado, ref InformacionDelError, FechaDesde, FechaHasta, NombreCliente, ID_EstadoDelivery, _DeliveryEnCocinaYNoEntregado);

            if (CargarDGVDelivery != null)
            {
                foreach (Pedido Elemento in CargarDGVDelivery)
                {
                    int NumeroDeFila = dgvDelivery.Rows.Add();

                    dgvDelivery.Columns[(int)ENumColDGVDelivery.ID_Delivery].SortMode        = DataGridViewColumnSortMode.NotSortable;
                    dgvDelivery.Columns[(int)ENumColDGVDelivery.ID_Pedido].SortMode          = DataGridViewColumnSortMode.NotSortable;
                    dgvDelivery.Columns[(int)ENumColDGVDelivery.Fecha].SortMode              = DataGridViewColumnSortMode.NotSortable;
                    dgvDelivery.Columns[(int)ENumColDGVDelivery.Hora].SortMode               = DataGridViewColumnSortMode.NotSortable;
                    dgvDelivery.Columns[(int)ENumColDGVDelivery.Nombre].SortMode             = DataGridViewColumnSortMode.NotSortable;
                    dgvDelivery.Columns[(int)ENumColDGVDelivery.Apellido].SortMode           = DataGridViewColumnSortMode.NotSortable;
                    dgvDelivery.Columns[(int)ENumColDGVDelivery.Telefono].SortMode           = DataGridViewColumnSortMode.NotSortable;
                    dgvDelivery.Columns[(int)ENumColDGVDelivery.TelefonoCadete].SortMode     = DataGridViewColumnSortMode.NotSortable;
                    dgvDelivery.Columns[(int)ENumColDGVDelivery.DireccionDeDestino].SortMode = DataGridViewColumnSortMode.NotSortable;
                    dgvDelivery.Columns[(int)ENumColDGVDelivery.Pedido].SortMode             = DataGridViewColumnSortMode.NotSortable;
                    dgvDelivery.Columns[(int)ENumColDGVDelivery.Estado].SortMode             = DataGridViewColumnSortMode.NotSortable;
                    dgvDelivery.Columns[(int)ENumColDGVDelivery.Seleccionar].SortMode        = DataGridViewColumnSortMode.NotSortable;

                    dgvDelivery.Rows[NumeroDeFila].Cells[(int)ENumColDGVDelivery.ID_Delivery].Value = Elemento.ID_Cliente;
                    dgvDelivery.Rows[NumeroDeFila].Cells[(int)ENumColDGVDelivery.ID_Pedido].Value   = Elemento.ID_Pedido;
                    dgvDelivery.Rows[NumeroDeFila].Cells[(int)ENumColDGVDelivery.Fecha].Value       = Elemento.Fecha.ToShortDateString();
                    dgvDelivery.Rows[NumeroDeFila].Cells[(int)ENumColDGVDelivery.Hora].Value        = Elemento.Hora.ToString(@"hh\:mm");
                    dgvDelivery.Rows[NumeroDeFila].Cells[(int)ENumColDGVDelivery.Nombre].Value      = Elemento.Cliente.Nombre;
                    dgvDelivery.Rows[NumeroDeFila].Cells[(int)ENumColDGVDelivery.Apellido].Value    = Elemento.Cliente.Apellido;
                    dgvDelivery.Rows[NumeroDeFila].Cells[(int)ENumColDGVDelivery.Telefono].Value    = Convert.ToString(Elemento.Cliente.Telefono);

                    if (Elemento.Delivery.Telefono == null)
                    {
                        dgvDelivery.Rows[NumeroDeFila].Cells[(int)ENumColDGVDelivery.TelefonoCadete].Value = string.Empty;
                    }
                    else
                    {
                        dgvDelivery.Rows[NumeroDeFila].Cells[(int)ENumColDGVDelivery.TelefonoCadete].Value = Convert.ToString(Elemento.Delivery.Telefono);
                    }

                    if (Elemento.Delivery.Destino == null)
                    {
                        dgvDelivery.Rows[NumeroDeFila].Cells[(int)ENumColDGVDelivery.DireccionDeDestino].Value = ClsDeliveries.DireccionPorDefecto;
                    }
                    else
                    {
                        dgvDelivery.Rows[NumeroDeFila].Cells[(int)ENumColDGVDelivery.DireccionDeDestino].Value = Elemento.Delivery.Destino;
                    }

                    dgvDelivery.Rows[NumeroDeFila].Cells[(int)ENumColDGVDelivery.Pedido].Value      = "Ver";
                    dgvDelivery.Rows[NumeroDeFila].Cells[(int)ENumColDGVDelivery.Estado].Value      = Elemento.Delivery.EstadoDelivery.Nombre;
                    dgvDelivery.Rows[NumeroDeFila].Cells[(int)ENumColDGVDelivery.Seleccionar].Value = false;
                }

                dgvDelivery.ClearSelection();

                UltimaFilaSeleccionada = -1;
            }
            else if (InformacionDelError == string.Empty)
            {
                FrmPrincipal.ObtenerInstancia().MensajeAdvertencia("Ocurrio un fallo al cargar la lista");
            }
            else
            {
                FrmPrincipal.ObtenerInstancia().MensajeAdvertencia("Ocurrio un fallo al cargar la lista");
                MessageBox.Show($"{InformacionDelError}", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }