Esempio n. 1
0
        public void Carga_de_Grilla()
        {
            try
            {
                IImportarArchivos     IService_Tipo_Cambio = new IImportarArchivos();
                List <BELog_Importar> lstBE = new List <BELog_Importar>();
                lstBE = IService_Tipo_Cambio.IgetLog_Importar();

                if (lstBE.Count == 0)
                {
                    Grid_Detalle.Visible     = false;
                    this.Lbl_Errores.Visible = false;
                    Grid_Detalle.DataSource  = null;
                    Grid_Detalle.DataBind();
                }
                else
                {
                    Grid_Detalle.Visible     = true;
                    Grid_Detalle.DataSource  = lstBE;
                    this.Lbl_Errores.Visible = true;
                    Grid_Detalle.DataBind();
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
            }
        }
Esempio n. 2
0
 protected void btnImpotar_Click(object sender, EventArgs e)
 {
     if (fupHospedaje.HasFile)
     {
         //Store file name in the string variable
         string filename = FileUpload1.FileName;
         //Save file upload file in to server path for temporary
         FileUpload1.SaveAs(Server.MapPath(filename));
         //Export excel data into Gridview using below method
         ExportToGrid(Server.MapPath(filename));
     }
     IImportarArchivos IService = new IImportarArchivos();
 }
Esempio n. 3
0
        static void Main(string[] args)
        {
            Properties.Settings props = new Properties.Settings();
            List <string>       Errors = new List <string>();
            int intVentas = 0, intCompras = 0, intHospedaje = 0, intTipoCambio = 0,
                intErrVentas = 0, intErrCompras = 0, intErrHospedaje = 0, intErrTipoCambio = 0;

            try
            {
                string[] AllfilePaths = Directory.GetFiles(@props.strRuta, "*.txt", SearchOption.AllDirectories);

                //crea el folder del bu
                string destinoBU = Path.Combine(@props.strRutaResults, "BUCargas", DateTime.Now.ToString("yyyy_MM_dd"));

                Int32 counExis = 0;

                if (!Directory.Exists(destinoBU))
                {
                    Directory.CreateDirectory(destinoBU);
                }
                else
                {
                    while (Directory.Exists(destinoBU))
                    {
                        //destinoBU = destinoBU.Substring(0, destinoBU.Length - counExis.ToString().Length - 1);
                        destinoBU = destinoBU.Replace("(" + counExis.ToString() + ")", "");
                        counExis++;
                        destinoBU = destinoBU + "(" + counExis.ToString() + ")";
                    }
                    Directory.CreateDirectory(destinoBU);
                }
                //
                BEUser user = new BEUser();
                user.UserName     = props.strUsuario;
                user.UserPassword = props.strpw;
                IUsers iUsers = new IUsers();

                user = iUsers.IvalidateLoguinUser(user);

                Console.Write(string.Format("\r{0} archivos en total", AllfilePaths.Length.ToString()));
                int total    = 0;
                int restante = AllfilePaths.Length;
                foreach (string strPath in AllfilePaths)
                {
                    total++;
                    restante--;
                    Console.Write(string.Format("\r Procesando {0} de {2} ({1}%)",
                                                total.ToString("0000"),
                                                ((int)(Convert.ToDecimal(AllfilePaths.Length - restante) / Convert.ToDecimal(AllfilePaths.Length) * 100)).ToString(),
                                                AllfilePaths.Length)
                                  );

                    string[]          nombreArchivo = strPath.Split('\\');
                    int               index         = nombreArchivo.Length - 1;
                    IImportarArchivos IService      = new IImportarArchivos();
                    string            strRespuesta;

                    try
                    {
                        if (nombreArchivo[index].Substring(0, 1).ToUpper().Equals("C"))
                        {
                            strRespuesta = IService.IComprasImportar(strPath, user);
                            if (strRespuesta.Substring(0, 1) == "1")
                            {
                                intCompras++;
                            }
                            else
                            {
                                intErrCompras++;
                                throw new Exception(strRespuesta.Split('|')[1]);
                            }
                        }
                        else if (nombreArchivo[index].Substring(0, 1).ToUpper().Equals("V"))
                        {
                            strRespuesta = IService.IVentasImportar(strPath, user);
                            if (strRespuesta.Substring(0, 1) == "1")
                            {
                                intVentas++;
                            }
                            else
                            {
                                intErrVentas++;
                                throw new Exception(strRespuesta.Split('|')[1]);
                            }
                        }
                        else if (nombreArchivo[index].Substring(0, 1).ToUpper().Equals("T"))
                        {
                            strRespuesta = IService.ITipo_CambioImportar(strPath, user);
                            if (strRespuesta.Substring(0, 1) == "1")
                            {
                                intTipoCambio++;
                            }
                            else
                            {
                                intErrTipoCambio++;
                                throw new Exception(strRespuesta.Split('|')[1]);
                            }
                        }
                        else if (nombreArchivo[index].Substring(0, 1).ToUpper().Equals("L"))
                        {
                            strRespuesta = IService.IHospedajeImportar(strPath, user);
                            if (strRespuesta.Substring(0, 1) == "1")
                            {
                                intHospedaje++;
                            }
                            else
                            {
                                intErrHospedaje++;
                                throw new Exception(strRespuesta.Split('|')[1]);
                            }
                        }
                        else
                        {
                            throw new Exception("Archivo irreconocible");
                        }
                    }
                    catch (Exception ex)
                    {
                        Errors.Add("  - archivo " + nombreArchivo[index] + " : " + ex.Message);
                    }
                    finally
                    {
                        File.Move(strPath, Path.Combine(destinoBU, nombreArchivo[index]));
                    }
                }

                if (Errors.Count > 0)
                {
                    throw new Exception("");
                }

                Console.WriteLine(" ---Carga satisfactoria, se cargaron: ");
            }
            catch (Exception ex)
            {
                string destinoBU = Path.Combine(@props.strRutaResults, "LogCargas");
                if (!Directory.Exists(destinoBU))
                {
                    Directory.CreateDirectory(destinoBU);
                }
                if (Errors.Count == 0)
                {
                    Console.WriteLine(" ---Carga fallida: ");

                    Console.WriteLine(ex.Message);
                    using (StreamWriter strLog = File.CreateText(Path.Combine(destinoBU, "log_" + DateTime.Now.ToString("yyyy_MM_dd") + ".txt")))
                    {
                        strLog.WriteLine(ex.Message);
                    }
                }
                else
                {
                    Console.WriteLine(" ---Carga con errores, ver archivo log: ");

                    using (StreamWriter strLog = File.CreateText(Path.Combine(destinoBU, "log_" + DateTime.Now.ToString("yyyy_MM_dd") + ".txt")))
                    {
                        foreach (string strerr in Errors)
                        {
                            strLog.WriteLine(strerr);
                        }
                    }
                }
            }
            finally
            {
                WriteAt(string.Format("VENTAS      {0} correctos", intVentas.ToString()), 2, 1);
                WriteAt(string.Format("COMPRAS     {0} correctos", intCompras.ToString()), 2, 2);
                WriteAt(string.Format("HOSPEDAJES  {0} correctos", intHospedaje.ToString()), 2, 3);
                WriteAt(string.Format("TIPO CAMBIO {0} correctos", intTipoCambio.ToString()), 2, 4);

                WriteAt(string.Format("{0} con Errores", intErrVentas.ToString()), 50, 1);
                WriteAt(string.Format("{0} con Errores", intErrCompras.ToString()), 50, 2);
                WriteAt(string.Format("{0} con Errores", intErrHospedaje.ToString()), 50, 3);
                WriteAt(string.Format("{0} con Errores", intErrTipoCambio.ToString()), 50, 4);
                System.Threading.Thread.Sleep(10000);
            }
        }
Esempio n. 4
0
        protected void btnImpotar_Click(object sender, EventArgs e)
        {
            try
            {
                if (fupHospedaje.HasFile)
                {
                    BEUser BE = new BEUser();
                    BE = (BEUser)Session["LoginUser"];
                    //Store file name in the string variable
                    string filename = fupHospedaje.FileName;
                    //Save file upload file in to server path for temporary
                    fupHospedaje.SaveAs(Server.MapPath(filename));
                    //Export excel data into Gridview using below method
                    IImportarArchivos IService = new IImportarArchivos();
                    //IService.IHospedajeImportar(Server.MapPath(filename), BE);

                    //if ( filename.Substring(0,1) !="C" || filename.Substring(0,1) !="V" )
                    //{
                    //    lblRespuesta1.Text = "El archivo es incorrecto porfavor validar que se ha seleccionado el archivo correcto.";
                    //}else
                    //{
                    if (IService.IHospedajeImportar(Server.MapPath(filename), BE).Substring(0, 1) == "1")
                    {
                        lblRespuesta1.Text = "Archivo hospedaje importado correctamente";
                    }
                    else
                    {
                        lblRespuesta1.Text = "No se realizó la importación del archivo hospedaje por que ya fué importado u ocurrió algún error.";
                    }
                    //}
                }
                if (fupVentas.HasFile)
                {
                    BEUser BE = new BEUser();
                    BE = (BEUser)Session["LoginUser"];
                    //Store file name in the string variable
                    string filename = fupVentas.FileName;
                    //Save file upload file in to server path for temporary
                    fupVentas.SaveAs(Server.MapPath(filename));
                    //Export excel data into Gridview using below method
                    IImportarArchivos IService = new IImportarArchivos();


                    if (filename.Substring(0, 1) == "V" && filename.Substring(1, 11) == "20114803228")
                    {
                        if (IService.IVentasImportar(Server.MapPath(filename), BE).Substring(0, 1) == "1")
                        {
                            lblRespuesta1.Text = "Archivo ventas importado correctamente";
                        }
                        else
                        {
                            lblRespuesta1.Text = "No se realizó la importación del archivo ventas por que ya fué importado u ocurrió algún error.s";
                        }
                    }
                    else
                    {
                        lblRespuesta1.Text = "El archivo es incorrecto porfavor validar que se ha seleccionado el archivo correcto.";
                    }
                }
                if (fupCompras.HasFile)
                {
                    BEUser BE = new BEUser();
                    BE = (BEUser)Session["LoginUser"];
                    //Store file name in the string variable
                    string filename = fupCompras.FileName;
                    //Save file upload file in to server path for temporary
                    fupCompras.SaveAs(Server.MapPath(filename));
                    //Export excel data into Gridview using below method
                    IImportarArchivos IService = new IImportarArchivos();

                    if (filename.Substring(0, 1) == "C" && filename.Substring(1, 11) == "20114803228")
                    {
                        if (IService.IComprasImportar(Server.MapPath(filename), BE).Substring(0, 1) == "1")
                        {
                            lblRespuesta1.Text = "Archivo compras importado correctamente";
                        }
                        else
                        {
                            lblRespuesta1.Text = "No se realizó la importación del archivo compras que ya fué importado u ocurrió algún error.";
                        }
                    }
                    else
                    {
                        lblRespuesta1.Text = "El archivo es incorrecto porfavor validar que se ha seleccionado el archivo correcto.";
                    }
                }
                if (fupTipCambio.HasFile)
                {
                    BEUser BE = new BEUser();
                    BE = (BEUser)Session["LoginUser"];
                    //Store file name in the string variable
                    string filename = fupTipCambio.FileName;
                    //Save file upload file in to server path for temporary
                    fupTipCambio.SaveAs(Server.MapPath(filename));
                    //Export excel data into Gridview using below method
                    IImportarArchivos IService = new IImportarArchivos();

                    if (IService.ITipo_CambioImportar(Server.MapPath(filename), BE).Substring(0, 1) == "1")
                    {
                        lblRespuesta1.Text = "Archivo Tipo de Cambio importado correctamente";
                    }
                    else
                    {
                        lblRespuesta1.Text = "No se realizó la importación del archivo tipo de cambio por que ya fué importado u ocurrió algún error.";
                    }
                }

                Carga_de_Grilla();
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message;
            }
        }