Exemplo n.º 1
0
        public List <BOCargueLotes> ObtenerRegistrosArchivoCSV(string path, string fileName, decimal Cliente, string LoteScaner, decimal idUsuario)
        {
            List <BOCargueLotes> list2;

            try
            {
                StreamReader reader = new StreamReader(path);
                //Obtenemos la informacion de los parametros de :  columna donde se encuentra el nombre del archivo  y la exttension que se usara al escanear
                COLUMNA_NOMBRE    = int.Parse((bd.Parametros.Where(c => c.codigo == "COLUMNA_NOMBRE").First().valor));
                EXTENSION_ARCHIVO = (bd.Parametros.Where(c => c.codigo == "EXTENSION_ARCHIVO").First().valor).ToString();

                List <BOCargueLotes> list = new List <BOCargueLotes>();
                string lote = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString("00") + DateTime.Now.Day.ToString("00");
                int    num2 = this.ObtenerConsecutivoLote(lote);
                while (!reader.EndOfStream)
                {
                    string[]      strArray = reader.ReadLine().Split(new char[] { ';' });
                    BOCargueLotes item     = new BOCargueLotes
                    {
                        //LoteFecha = Convert.ToDateTime(strArray[0].ToString())
                        LoteFecha = Convert.ToDateTime(DateTime.Now)
                    };
                    //int upperBound = strArray[1].ToString().Split(new char[] { '\\' }).GetUpperBound(0);
                    //item.NomArchivo = strArray[1].ToString().Split(new char[] { '\\' }).GetValue(upperBound).ToString();
                    item.NomArchivo = strArray[COLUMNA_NOMBRE].Trim(new char[] { '"' }) + EXTENSION_ARCHIVO;
                    //item.NomArchivo = strArray[2] + ".tif";
                    //item.Paginas = Convert.ToInt32(strArray[2].ToString());

                    //ITEM DEL CODIGO DE BARRAS
                    item.CodBarras       = (strArray[5]).ToString().Replace('"', ' ').Trim();
                    item.Paginas         = 5;
                    item.FechaCargue     = DateTime.Now;
                    item.Lote            = lote;
                    item.Usuario         = idUsuario;
                    item.ConsecutivoLote = num2;
                    item.Cliente         = Cliente;
                    item.LoteScaner      = LoteScaner;
                    list.Add(item);
                }
                reader.Close();
                list2 = list;
            }
            catch (Exception exception)
            {
                log.WriteEntry("Error en BLLCargue  " + exception.Message, EventLogEntryType.Error);
                throw exception;
            }

            return(list2);
        }
Exemplo n.º 2
0
        public void ObtenerArchivoCSV(string Location, decimal nitCli, decimal idUser)
        {
            try
            {
                //EN CASO DE QUE OMITA LA RECEPCION ESTO SON LOS DATOS POR DEFAULT
                decimal nitCliente = nitCli;
                decimal idUsuario  = idUser;

                DirectoryInfo info = new DirectoryInfo(Location);
                foreach (DirectoryInfo info2 in info.GetDirectories())
                {
                    long    idRecepcion = 0;
                    decimal numeroLote  = 0;

                    //SI ENCUENTRA UNA CARPETA CON STRINGS LA OMITE
                    try
                    {
                        numeroLote = Convert.ToDecimal(info2.Name);
                    }
                    catch (Exception)
                    {
                        continue;
                    }

                    int omiteRecepcion = Int16.Parse(bd.Parametros.Where(c => c.codigo == "OMITE_RECEP").First().valor);

                    //OMITO EL MODULO DE RECEPCION
                    if (omiteRecepcion == 0)
                    {
                        int reg_recep = bd.Recepcion.Where(c => c.numeroLote == numeroLote && c.estado == 0 && c.activo == true).Count();
                        //BUSCO QUE EL LOTE HAYA SIDO RECEPCIONADO DE LO CONTRARIO NO LO CARGA
                        if (reg_recep > 0)
                        {
                            Recepcion reg_recepcion = bd.Recepcion.Where(c => c.numeroLote == numeroLote && c.estado == 0 && c.activo == true).First();
                            idRecepcion = reg_recepcion.id;

                            reg_recepcion.estado      = 1;
                            reg_recepcion.fechaCargue = DateTime.Now;

                            nitCliente = (decimal)reg_recepcion.nitCliente;
                            idUsuario  = (decimal)reg_recepcion.idUsuario;

                            bd.SubmitChanges();
                        }
                        else
                        {
                            continue;
                        }
                    }

                    foreach (FileInfo info3 in info2.GetFiles("*.CSV"))
                    {
                        var source = from b in this.ObtenerRegistrosArchivoCSV(info3.FullName, Path.GetFileName(info3.Name), nitCliente, info2.Name, idUsuario)
                                     group b by new { NomArchivo = b.NomArchivo, lfecha = b.LoteFecha.ToString("MM/dd/yyyy"), Lote = b.Lote, ConsecutivoLote = b.ConsecutivoLote, CodBarras = b.CodBarras } into g
                                             select new { NomArchivo = g.Key.NomArchivo, lfecha = g.Key.lfecha, Lote = g.Key.Lote, ConsecutivoLote = g.Key.ConsecutivoLote, cuenta = g.Count <BOCargueLotes>(), CodBarras = g.Key.CodBarras };
                        List <BOCargueLotes> lst = new List <BOCargueLotes>();
                        foreach (var type in source.ToList())
                        {
                            BOCargueLotes item = new BOCargueLotes
                            {
                                NomArchivo      = type.NomArchivo,
                                Lote            = type.Lote,
                                Paginas         = type.cuenta,
                                ConsecutivoLote = type.ConsecutivoLote,
                                FechaCargue     = DateTime.Now,
                                Usuario         = idUsuario,
                                idRecepcion     = idRecepcion,
                                CodBarras       = type.CodBarras,
                                //LoteFecha = Convert.ToDateTime(type.lfecha),
                                LoteFecha  = DateTime.Now,
                                Cliente    = nitCliente,
                                LoteScaner = info2.Name
                            };
                            lst.Add(item);
                        }
                        this.InsertarCargueLotes(lst);
                    }
                }
            }
            catch (Exception exception)
            {
                log.WriteEntry("Error en BLLCargue  " + exception.Message, EventLogEntryType.Error);
                throw;
            }
        }