Пример #1
0
        private void btnCierreManual_Click(object sender, RoutedEventArgs e)
        {
            Temporizador.Stop();
            if (oPesos.Count > 0 && oPesos.Sum(p => p.Peso) > decimal.Zero)
            {
                if (oPesos.Any()) //Comprueba si hay una pesada
                {
                    if (MessageBox.Show("¿Cerrar la caja?", "Cierre Manual", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                    {
                        Caja oCaja = new Caja()
                        {
                            IdTrabajo = TrabajoActivo.Id,
                            Lote      = TrabajoActivo.Lote,
                            Fecha     = TrabajoActivo.Fecha,
                            Numero    = oPesosCajas.Count + 1,
                            Peso      = oPesos.Sum(p => p.Peso)
                        };
                        int idcaja = CajaGestor.GuardarCaja(oCaja);
                        if (idcaja > 0)
                        {
                            oCaja.Id = idcaja;
                            oPesosCajas.Add(oCaja);
                            lvCajas.ScrollIntoView(oPesosCajas.Last());
                            oPesos.Clear();
                            // Imprimir la etiqueta de caja

                            //Actualizar EtiquetaCaja
                            foreach (var x in EtiquetaCaja.SubStrings)
                            {
                                switch (x.Name.ToLower())
                                {
                                case "pesaje_peso": x.Value = oCaja.Peso.ToString(); break;

                                case "pesaje_lote": x.Value = TrabajoActivo.Lote; break;

                                case "pesaje_fecha": x.Value = TrabajoActivo.Fecha.ToShortDateString(); break;

                                case "pesaje_numero": x.Value = oCaja.Numero.ToString(); break;

                                case "pesaje_numeroproductos": x.Value = oPesosProductos.Where(c => c.IdCaja == oCaja.Id).Count().ToString(); break;

                                default: break;
                                }
                            }

                            try {
                                ImprimeEtiquetaWorker.RunWorkerAsync(EtiquetaCaja);
                            } catch (Exception) {
                                MessageBox.Show("Espere mientras se completa la impresión", "Aviso", MessageBoxButton.OK, MessageBoxImage.Information);
                            };
                        }
                    }
                }
            }
            Temporizador.Start();
        }
Пример #2
0
        private void CargaCajasActivas(int idTrabajo)
        {
            Cajas lstCajas = CajaGestor.ObtenerCajas(idTrabajo);

            foreach (Caja caja in lstCajas)
            {
                if (caja != null)
                {
                    oPesosCajas.Add(caja);
                }
            }
            if (lstCajas.Count > 0)
            {
                lvCajas.ScrollIntoView(lstCajas.Last());
            }
        }
Пример #3
0
 private void btnEliminaCaja_Click(object sender, RoutedEventArgs e)
 {
     Temporizador.Start();
     if (oPesosCajas.Count > 0)
     {
         if (MessageBox.Show("¿Eliminar la última caja?", "Eliminar caja", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
         {
             Caja oCaja = oPesosCajas.Last();
             if (CajaGestor.EliminaCaja(oCaja.Id))
             {
                 oPesosCajas.Remove(oCaja);
                 ActualizaLabels();
             }
         }
     }
     Temporizador.Start();
 }
Пример #4
0
        private void PuertoCOM_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            var serialDevice = sender as SerialPort;

            // obtener el peso del buffer
            //var buffer = new byte[serialDevice.BytesToRead];
            //serialDevice.Read(buffer, 0, buffer.Length);
            bufferCOM += serialDevice.ReadExisting();
            if (bufferCOM.Length < 10)
            {
                return;
            }
            bool          pesadavalida = false;
            List <string> lstPesos     = bufferCOM.Replace(".", ",").Split(new string[] { "\r" }, StringSplitOptions.None).ToList();

            foreach (string p in lstPesos)
            {
                string pp = p.Replace(((char)0x02).ToString(), "").Replace("\u0002", "").Replace("\x02", "");
                if (!string.IsNullOrEmpty(p) && (pp.StartsWith("A") || pp.StartsWith("B") || pp.StartsWith("I")) && pp.Length > 8)
                {
                    pesadavalida = true;
                    strpeso      = pp.Replace("A", "").Replace("B", "").Replace("I", "").Replace(".", ",").Trim();
                    decimal.TryParse(strpeso, out peso);
                    //if (peso > 0)
                    if (peso > Configuracion.PesoMinimoPesada)
                    {
                        bufferCOM = string.Empty;
                    }
                }
            }

            //string pesoBuffer = bufferCOM.ToString().Replace(".", ",").Replace("\x02", "");
            //pesoBuffer = pesoBuffer.Remove(0, 5).Replace("\r", "");
            //if (!string.IsNullOrEmpty(pesoBuffer) && (pesoBuffer.StartsWith("A") || pesoBuffer.StartsWith("B") || pesoBuffer.StartsWith("I")))
            //{
            //    pesadavalida = true;
            //    decimal.TryParse(pesoBuffer, out peso);
            //    strpeso = pesoBuffer;
            //}

            if (!pesadavalida)
            {
                return;
            }
            bufferCOM = string.Empty;
            // Controlar peso mayor que peso mínimo (-a cero-)
            if (peso > Configuracion.PesoMinimoPesada && EsperandoNuevaPesada)
            {
                EsperandoNuevaPesada = false;
                // process data on the GUI thread
                Application.Current.Dispatcher.BeginInvoke(new Action(() => {
                    List <Bartender.LabelFormatDocument> lstEtiquetas = new List <Bartender.LabelFormatDocument>();
                    if (TrabajoActivo != null && TrabajoActivo.Id > 0)
                    {
                        if (EstoyPesandoCajas)
                        {
                            #region Genera Caja y la imprime
                            Caja oCaja = new Caja()
                            {
                                Fecha = TrabajoActivo.Fecha, IdTrabajo = TrabajoActivo.Id, Lote = TrabajoActivo.Lote, Peso = peso
                            };
                            int idcaja = CajaGestor.GuardarCaja(oCaja);
                            if (idcaja > 0)
                            {
                                oCaja.Id     = idcaja;
                                oCaja.Numero = oPesosCajas.Count + 1;
                                oPesosCajas.Add(oCaja);
                                lvCajas.ScrollIntoView(oPesosCajas.Last());
                                lblCajas.Content = oPesosCajas.Count.ToString("N0");
                                foreach (var x in EtiquetaCaja.SubStrings)
                                {
                                    switch (x.Name.ToLower())
                                    {
                                    case "pesaje_peso": x.Value = oCaja.Peso.ToString(); break;

                                    case "pesaje_lote": x.Value = TrabajoActivo.Lote; break;

                                    case "pesaje_fecha": x.Value = TrabajoActivo.Fecha.ToShortDateString(); break;

                                    case "pesaje_numero": x.Value = oCaja.Numero.ToString(); break;

                                    case "pesaje_numeroproductos": x.Value = oPesosProductos.Where(c => c.IdCaja == oCaja.Id).Count().ToString(); break;

                                    default: break;
                                    }
                                }
                                //ImprimeEtiquetaWorker.RunWorkerAsync(EtiquetaCaja);
                                lstEtiquetas.Add(EtiquetaCaja);
                            }
                            #endregion
                        }
                        else
                        {
                            int idcaja            = 0;
                            bool limpiarPesosCaja = false;
                            Producto oProducto    = new Producto()
                            {
                                Fecha = TrabajoActivo.Fecha, IdTrabajo = TrabajoActivo.Id, Lote = TrabajoActivo.Lote, Peso = peso
                            };
                            oProducto.Numero = oPesosProductos.Count + 1;
                            #region Genera Caja y laImprime
                            if (TrabajoActivo.NumeroProductosCierre > 0 && oPesos.Count + 1 == TrabajoActivo.NumeroProductosCierre)
                            {
                                // Generar caja
                                limpiarPesosCaja = true;
                                Caja oCaja       = new Caja()
                                {
                                    Fecha = TrabajoActivo.Fecha, IdTrabajo = TrabajoActivo.Id, Lote = TrabajoActivo.Lote, Peso = peso
                                };
                                oCaja.Peso   = oPesos.Sum(p => p.Peso) + peso;
                                oCaja.Numero = oPesosCajas.Count + 1;
                                idcaja       = CajaGestor.GuardarCaja(oCaja);
                                if (idcaja > 0)
                                {
                                    oCaja.Id = idcaja;
                                    oPesosCajas.Add(oCaja);
                                    lvCajas.ScrollIntoView(oPesosCajas.Last());
                                    foreach (var x in EtiquetaCaja.SubStrings)
                                    {
                                        switch (x.Name.ToLower())
                                        {
                                        case "pesaje_peso": x.Value = oCaja.Peso.ToString(); break;

                                        case "pesaje_lote": x.Value = TrabajoActivo.Lote; break;

                                        case "pesaje_fecha": x.Value = TrabajoActivo.Fecha.ToShortDateString(); break;

                                        case "pesaje_numero": x.Value = oCaja.Numero.ToString(); break;

                                        case "pesaje_numeroproductos": x.Value = (oPesosProductos.Where(c => c.IdCaja == oCaja.Id).Count() + 1).ToString(); break;

                                        default: break;
                                        }
                                    }
                                    //ImprimeEtiquetaWorker.RunWorkerAsync(EtiquetaCaja);
                                    lstEtiquetas.Add(EtiquetaCaja);
                                    lblCajas.Content = oPesosCajas.Count.ToString("N0");
                                }
                            }
                            #endregion
                            #region Genera el Producto y lo imprime
                            oProducto.IdCaja = idcaja;  //¿Esto sigue haciendo falta con el nuevo método?
                            oProducto.Numero = oPesosProductos.Count + 1;
                            // Guardar peso del producto y controlar el número de productos que finalizan una caja
                            int idproducto = ProductoGestor.GuardaProducto(oProducto);
                            if (idproducto > 0)
                            {
                                oProducto.Id = idproducto;
                                oPesosProductos.Add(oProducto);
                                oPesos.Add(oProducto);
                                lvProdutos.ScrollIntoView(oPesos.Last());
                                foreach (var x in EtiquetaProducto.SubStrings)
                                {
                                    switch (x.Name.ToLower())
                                    {
                                    case "pesaje_peso": x.Value = oProducto.Peso.ToString(); break;

                                    case "pesaje_lote": x.Value = TrabajoActivo.Lote; break;

                                    case "pesaje_fecha": x.Value = TrabajoActivo.Fecha.ToShortDateString(); break;

                                    case "pesaje_numero": x.Value = oProducto.Numero.ToString(); break;

                                    default: break;
                                    }
                                }
                                //ImprimeEtiquetaWorker.RunWorkerAsync(EtiquetaProducto);
                                lstEtiquetas.Insert(0, EtiquetaProducto);

                                if (limpiarPesosCaja)
                                {
                                    foreach (Producto p in oPesos)
                                    {
                                        ProductoGestor.AsignaCajaProducto(p.Id, idcaja);
                                    }
                                    oPesos.Clear();
                                }
                                lblProductos.Content = oPesosProductos.Count.ToString("N0");
                            }
                            #endregion
                        }
                        if (lstEtiquetas.Count > 0)
                        {
                            ImprimeEtiquetaWorker.RunWorkerAsync(lstEtiquetas);
                        }
                        // Mostrar el peso de las cajas/productos
                        if (oPesosCajas.Count == 0)
                        {
                            lblKilos.Content = oPesosProductos.Sum(p => p.Peso).ToString();
                        }
                        else
                        {
                            lblKilos.Content = oPesosCajas.Sum(p => p.Peso).ToString("N3");
                        }
                    }
                }));
            }
            else
            {
                //if (peso == 0) {
                if (peso < Configuracion.PesoMinimoPesada)
                {
                    //Application.Current.Dispatcher.BeginInvoke(new Action(() => {
                    //    lblPeso.Content = peso.ToString("N3");
                    //}));
                    EsperandoNuevaPesada = true;
                }
            }
            EnviarElDolar = true;
        }