Exemplo n.º 1
0
        public CL_ImportacionMasiva(int IdNegocio, int IdLayout, INF_Archive Archivo, string Usuario = "SYS")
        {
            // Inicializa variables
            archivo = Archivo;
            strUsuario = Usuario;
            intIdNegocio = IdNegocio;
            intIdLayout = IdLayout;
            dteInicio = DateTime.Now;
            dteTermino = null;
            lngCorrectos = 0;
            lngOmitidos = 0;
            lngErroneos = 0;
            strObservaciones = string.Empty;
            encabezados = null;

            if(cnf.Estatus == Configuracion.Status.Correcto)
            {
                db.DBConString = cnf.CnnString;

                CL_Layout loadLayout = new CL_Layout(IdNegocio, IdLayout, db);
                this.layout = loadLayout;
                strNegocio = this.layout.Negocio;
                strLayout = this.layout.Nombre;

                // Prepara contenedor de resultados
                this.resultados = new DataTable();

                this.resultados.Columns.Add("NUM_REGISTRO", Type.GetType("System.Int64"));
                this.resultados.Columns.Add("RES_ROK", Type.GetType("System.Boolean"));
                this.resultados.Columns.Add("RES_ROM", Type.GetType("System.Boolean"));
                this.resultados.Columns.Add("RES_RER", Type.GetType("System.Boolean"));
                this.resultados.Columns.Add("OBSERVACIONES", Type.GetType("System.String"));

                // Carga archivo
                CargarArchivo();

                dteTermino = DateTime.Now;

                // Registra en base de datos
                registrarDatosEnBD();

                File.Delete(archivo.Ruta);
            }
        }
Exemplo n.º 2
0
        private bool GenerarArchivoOmitidos()
        {
            try
            {
                if ((this.lngOmitidos > 0) || (this.lngErroneos > 0))
                {
                    string strProceso = "ImportacionMasiva";
                    string strFolder = Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase).ToString().Replace("file:\\",""),
                                                    "files");
                    string strNombre = "ERR_" + this.strUsuario + "_" + strProceso + ".csv";
                    string strRuta = Path.Combine(strFolder, strNombre);

                    ComprobarRuta(strFolder);

                    this.archivoDesviaciones = new INF_Archive(strRuta, 3);

                    this.archivoDesviaciones.Separador = ",";
                    this.archivoDesviaciones.Proceso = strProceso;

                    this.archivoDesviaciones.CrearArchivoTexto(false, true);

                    using (StreamWriter pfile = new StreamWriter(this.archivoDesviaciones.Ruta))
                    {
                        DataRow[] rowFind = this.resultados.Select("RES_ROM = true OR RES_RER = true","NUM_REGISTRO ASC");

                        pfile.WriteLine("RENGLON,OBSERVACIONES");

                        foreach (DataRow row in rowFind)
                        {
                            string strLine = row["NUM_REGISTRO"].ToString() +
                                             this.archivoDesviaciones.Separador +
                                             row["OBSERVACIONES"].ToString();

                            pfile.WriteLine(strLine);
                        }
                    }

                    return true;
                }
                else
                {
                    // No se creo archivo
                    return false;
                }
            }
            catch (Exception Error)
            {
                string strMsgError = Error.Message;
                return false;
            }
        }