protected void btnUpload_Click(object sender, EventArgs e)
        {
            DataTable     dtRsponseImport2Grid = new DataTable();
            clsPorteo     clsBusinessPorteo    = new clsPorteo();
            StringBuilder strHtmlTablePorteo;

            if (IsPostBack)
            {
                clsError.logMessage = "Entra ISPOSTBACK";
                clsError.LogWrite();
                try
                {
                    if (FileUpload1.HasFile)
                    {
                        clsError.logMessage = "Entra FileUpload1.HasFile";
                        clsError.LogWrite();
                        clsBusinessPorteo.strFileName = Path.GetFileName(FileUpload1.PostedFile.FileName);
                        if (!string.IsNullOrEmpty(clsBusinessPorteo.strFileName))
                        {
                            clsError.logMessage = "Entra clsBusinessPorteo.strFileName " + clsBusinessPorteo.strFileName;
                            clsError.LogWrite();
                            clsBusinessPorteo.strExtension = Path.GetExtension(FileUpload1.PostedFile.FileName);
                            //string nombreArchivo = FileUpload1.FileName;
                            clsBusinessPorteo.strFilePath = Server.MapPath(clsBusinessPorteo.strFileName);
                            //GridView1.Caption = FilePath;
                            FileUpload1.SaveAs(clsBusinessPorteo.strFilePath);
                            clsBusinessPorteo.strIsHDR = ExcelHasHeader.Yes;
                            dtRsponseImport2Grid       = clsBusinessPorteo.Import_To_Grid();
                            //Import_To_Grid(clsBusinessPorteo.strFilePath, clsBusinessPorteo.strFileName, "Yes");
                            if (dtRsponseImport2Grid.Rows.Count > 0)
                            {
                                Session["dt_Sess_Porteo"]   = dtRsponseImport2Grid;
                                clsBusinessPorteo.dtShiping = dtRsponseImport2Grid;
                                strHtmlTablePorteo          = clsBusinessPorteo.CreateTableHTML();
                                //CreateTableHTML(dtRsponseImport2Grid);
                                DBDataPlaceHolder.Controls.Add(new Literal {
                                    Text = strHtmlTablePorteo.ToString()
                                });
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    clsError.logMessage = ex.ToString();
                    clsError.logModule  = "btnUpload_Click";
                    clsError.LogWrite();
                }
                finally
                {
                    dtRsponseImport2Grid = null;
                    clsBusinessPorteo    = null;
                    strHtmlTablePorteo   = null;
                }
            }
        }
Exemplo n.º 2
0
        protected void btnUpload_Click(object sender, EventArgs e)
        {
            pnlErrorLoad.Visible = false;
            clsError.logMessage  = "btnUpload_Click";
            clsError.logModule   = "porteoatomatico";
            clsError.LogWrite();

            DataTable     dtRsponseImport2Grid = new DataTable();
            clsPorteo     clsBusinessPorteo    = new clsPorteo();
            StringBuilder strHtmlTablePorteo;

            if (IsPostBack)
            {
                try
                {
                    //CargarDDL();
                    if (cmbCentral.SelectedValue == "" || cmbCentral.SelectedValue == "--TODOS--")
                    {
                        //pnlValidaciones.InnerText = "Se debe seleccionar una Central";
                        //pnlValidaciones.Visible = true;
                        ScriptManager.RegisterStartupScript(this, GetType(), "muestraError", "swal('Error','Debe seleccionar una central','error');", true);

                        clsError.logMessage = "Se debe seleccionar una Central";
                        clsError.logModule  = "porteoatomatico-btnUpload_Click";
                        clsError.LogWrite();
                    }
                    else
                    {
                        if (FileUpload1.HasFile)
                        {
                            clsError.logMessage = "FileUpload1.HasFile";
                            clsError.logModule  = "porteoatomatico-btnUpload_Click";
                            clsError.LogWrite();

                            clsBusinessPorteo.strFileName = Path.GetFileName(FileUpload1.PostedFile.FileName);
                            if (!string.IsNullOrEmpty(clsBusinessPorteo.strFileName))
                            {
                                clsError.logMessage = "!string.IsNullOrEmpty(clsBusinessPorteo.strFileName";
                                clsError.logModule  = "porteoatomatico-btnUpload_Click";
                                clsError.LogWrite();

                                clsBusinessPorteo.strExtension = Path.GetExtension(FileUpload1.PostedFile.FileName);
                                //string nombreArchivo = FileUpload1.FileName;
                                clsBusinessPorteo.strFilePath = Server.MapPath(clsBusinessPorteo.strFileName);
                                //GridView1.Caption = FilePath;
                                FileUpload1.SaveAs(clsBusinessPorteo.strFilePath);
                                clsBusinessPorteo.strIsHDR = ExcelHasHeader.Yes;
                                dtRsponseImport2Grid       = clsBusinessPorteo.Import_To_Grid();
                                //Import_To_Grid(clsBusinessPorteo.strFilePath, clsBusinessPorteo.strFileName, "Yes");
                                if (dtRsponseImport2Grid.Rows.Count > 0 && dtRsponseImport2Grid.Columns.Count == 16)
                                {
                                    clsError.logMessage = "dtRsponseImport2Grid.Rows.Count";
                                    clsError.logModule  = "porteoatomatico-btnUpload_Click";
                                    clsError.LogWrite();


                                    Session["dt_Sess_Porteo"]   = dtRsponseImport2Grid;
                                    clsBusinessPorteo.dtShiping = dtRsponseImport2Grid;
                                    strHtmlTablePorteo          = clsBusinessPorteo.CreateTableHTML();
                                    //CreateTableHTML(dtRsponseImport2Grid);
                                    DBDataPlaceHolder.Controls.Add(new Literal {
                                        Text = strHtmlTablePorteo.ToString()
                                    });
                                    pnlMuestraDatos.Visible = true;
                                    pnlBrowseFile.Visible   = false;
                                    btnCancel.Enabled       = true;
                                    Button1.Disabled        = false;
                                }
                                else
                                {
                                    ScriptManager.RegisterStartupScript(this, GetType(), "muestraError", "swal('Error','Debe seleccionar un archivo valido a cargar.','error');", true);
                                }
                            }
                        }
                        else
                        {
                            clsError.logMessage = "Debes seccionar un archivo a cargar.";
                            clsError.logModule  = "porteoatomatico-btnUpload_Click";
                            clsError.LogWrite();


                            Button1.Disabled  = true;
                            btnCancel.Enabled = false;

                            lblFileLoad.Visible     = false;
                            pnlFileLoad.Visible     = false;
                            pnlMuestraDatos.Visible = false;

                            //pnlBrowseFile.Visible = true;
                            //pnlValidaciones.Visible = true;
                            //pnlValidaciones.InnerText = "Debes seccionar un archivo a cargar.";
                            ScriptManager.RegisterStartupScript(this, GetType(), "muestraError", "swal('Error','Debe seleccionar un archivo a cargar.','error');", true);
                        }
                    }
                }
                catch (Exception ex)
                {
                    clsError.logMessage = ex.ToString();
                    clsError.logModule  = "btnUpload_Click";
                    clsError.LogWrite();
                }
                finally
                {
                    dtRsponseImport2Grid = null;
                    clsBusinessPorteo    = null;
                    strHtmlTablePorteo   = null;
                }
            }
        }
Exemplo n.º 3
0
        //guardar archivo en bd
        protected void save()
        {
            clsPorteoAutomatico clsShiping = new clsPorteoAutomatico();
            string strEmail     = (string)Session["email"];
            string strIdUsuario = (string)Session["IdUsuario"];

            try
            {
                DataTable dtResultado = new DataTable();
                dtResultado = (DataTable)Session["dt_Sess_Porteo"];
                StringBuilder strBullResultado = new StringBuilder();
                clsShiping.dtResult = (DataTable)Session["dt_Sess_Porteo"];


                string strCentral = this.cmbCentral.Items[cmbCentral.SelectedIndex].Value;
                clsShiping.strCentral   = strCentral;
                clsShiping.strIdUsuario = int.Parse(strIdUsuario);
                strBullResultado        = clsShiping.RPU();

                //clsShiping.dtShiping = (DataTable)Session["dt_Sess_Porteo"];
                //clsShiping.strRPUrepeated = clsShiping.RPU();
                //if (clsShiping.strRPUrepeated.Length > 0)
                if (strBullResultado.Length > 0)
                {
                    //ErrorMsg.InnerHtml = "<div class='alert alert-warning alert-dismissible' role='alert'><button type='button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden='true'>&times;</span></button><strong>Los siguientes RPU's ya están en la base de datos y no se importaron: <br></strong> " + clsShiping.strRPUrepeated + "</div>";

                    pnlErrorLoad.Visible    = true;
                    pnlErrorLoadDiv.Visible = true;
                    //pnlErrorLoadDiv.InnerHtml = "<div class='alert alert-warning alert-dismissible' role='alert'><button type='button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden='true'>&times;</span></button><strong>Los siguientes RPU's ya están en la base de datos y no se importaron: <br></strong> " + clsShiping.strRPUrepeated + "</div>";
                    //pnlErrorLoadDiv.InnerHtml = "<div class='alert alert-warning alert-dismissible' role='alert'><button type='button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden='true'>&times;</span></button><strong>Los siguientes RPU's ya están en la base de datos y no se importaron: <br></strong> " + strBullResultado + "</div>";
                    pnlErrorLoadDiv.InnerHtml = "<strong>Los siguientes registros contienen fallas  y no se importaron: <br></strong> " + strBullResultado + "";


                    clsPorteo clsBusinessPorteo = new clsPorteo();
                    clsBusinessPorteo.dtShiping = (DataTable)Session["dt_Sess_Porteo"];
                    StringBuilder strHtmlTablePorteo = new StringBuilder();
                    strHtmlTablePorteo = clsBusinessPorteo.CreateTableHTML();
                    //CreateTableHTML(dtRsponseImport2Grid);
                    DBDataPlaceHolder.Controls.Add(new Literal {
                        Text = strHtmlTablePorteo.ToString()
                    });

                    //Button1.Enabled = false;
                    btnCancel.Enabled = true;
                    ScriptManager.RegisterStartupScript(this, GetType(), "muestraError", "swal('Cargado!', 'Su archivo se ha cargado correctamente.', 'success');", true);
                }
                else
                {
                    pnlMuestraDatos.Visible = false;
                    pnlSuccessLoad.Visible  = true;

                    //Label1.Text = "convenio generado: " + strBullResultado;

                    //Button1.Visible = false;
                    btnCancel.Visible = false;

                    btnRegresar.Enabled = true;
                    btnRegresar.Visible = true;

                    cmbCentral.SelectedValue = "";
                    ScriptManager.RegisterStartupScript(this, GetType(), "muestraError", "swal('Cargado!', 'Su archivo se ha cargado correctamente.', 'success');", true);
                }
            }
            catch (Exception ex)
            {
                clsError.logMessage = ex.ToString();
                clsError.logModule  = "btnUpload_Click";
                clsError.LogWrite();
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                string mensaje = serializer.Serialize(ex.Message);
                ScriptManager.RegisterStartupScript(this, GetType(), "muestraError", "swal('Error  Detalle: " + mensaje + "');", true);
            }
            finally
            {
                Session["dt_Sess_Porteo"] = null;
                clsShiping = null;
            }
        }
Exemplo n.º 4
0
        protected void btnUpload_Click(object sender, EventArgs e)
        {
            pnlErrorLoad.Visible = false;
            clsError.logMessage  = "btnUpload_Click";
            clsError.logModule   = "porteoatomatico";
            clsError.LogWrite();

            DataTable dtRsponseImport2Grid = new DataTable();

            clsPorteo     clsBusinessPorteo = new clsPorteo();
            StringBuilder strHtmlTablePorteo;

            if (IsPostBack)
            {
                try
                {
                    //CargarDDL();
                    if (cmbCentral.SelectedValue == "" || cmbCentral.SelectedValue == "--TODOS--")
                    {
                        //pnlValidaciones.InnerText = "Se debe seleccionar una Central";
                        //pnlValidaciones.Visible = true;
                        ScriptManager.RegisterStartupScript(this, GetType(), "muestraError", "swal('Error','Debe seleccionar una central','error');", true);

                        clsError.logMessage = "Se debe seleccionar una Central";
                        clsError.logModule  = "porteoatomatico-btnUpload_Click";
                        clsError.LogWrite();
                    }
                    else
                    {
                        if (FileUpload1.HasFile)
                        {
                            clsError.logMessage = "FileUpload1.HasFile";
                            clsError.logModule  = "porteoatomatico-btnUpload_Click";
                            clsError.LogWrite();

                            clsBusinessPorteo.strFileName = Path.GetFileName(FileUpload1.PostedFile.FileName);

                            if (!string.IsNullOrEmpty(clsBusinessPorteo.strFileName))
                            {
                                clsError.logMessage = "!string.IsNullOrEmpty(clsBusinessPorteo.strFileName";
                                clsError.logModule  = "porteoatomatico-btnUpload_Click";
                                clsError.LogWrite();

                                //clsBusinessPorteo.strExtension = Path.GetExtension(FileUpload1.PostedFile.FileName);
                                ////string nombreArchivo = FileUpload1.FileName;
                                //clsBusinessPorteo.strFilePath = Server.MapPath(clsBusinessPorteo.strFileName);
                                ////GridView1.Caption = FilePath;
                                //FileUpload1.SaveAs(clsBusinessPorteo.strFilePath);
                                //clsBusinessPorteo.strIsHDR = ExcelHasHeader.Yes;                                                                                                                                                                                                                          dtRsponseImport2Grid = clsBusinessPorteo.Import_To_Grid();
                                //Import_To_Grid(clsBusinessPorteo.strFilePath, clsBusinessPorteo.strFileName, "Yes");
                                //Implementando closedXML--------------------------------------------------------------------------------
                                string filePath = Server.MapPath("~/Files") + Path.GetFileName(FileUpload1.PostedFile.FileName);
                                FileUpload1.SaveAs(filePath);



                                //Open the Excel file using ClosedXML.

                                using (XLWorkbook workBook = new XLWorkbook(filePath))

                                {
                                    //Read the first Sheet from Excel file.

                                    IXLWorksheet workSheet = workBook.Worksheet(1);



                                    //Create a new DataTable.

                                    //   DataTable dt = new DataTable();


                                    //Loop through the Worksheet rows.

                                    bool firstRow = true;

                                    foreach (IXLRow row in workSheet.Rows())

                                    {
                                        //Use the first row to add columns to DataTable.

                                        if (firstRow)

                                        {
                                            foreach (IXLCell cell in row.Cells())

                                            {
                                                dtRsponseImport2Grid.Columns.Add(cell.Value.ToString());
                                            }

                                            firstRow = false;
                                        }

                                        else

                                        {
                                            //Add rows to DataTable.

                                            dtRsponseImport2Grid.Rows.Add();

                                            int i = 0;

                                            foreach (IXLCell cell in row.Cells())

                                            {
                                                dtRsponseImport2Grid.Rows[dtRsponseImport2Grid.Rows.Count - 1][i] = cell.Value.ToString();

                                                i++;
                                            }
                                        }
                                    }
                                }



                                if (dtRsponseImport2Grid.Rows.Count > 0 && dtRsponseImport2Grid.Columns.Count == 16)
                                {
                                    clsError.logMessage = "dtRsponseImport2Grid.Rows.Count";
                                    clsError.logModule  = "porteoatomatico-btnUpload_Click";
                                    clsError.LogWrite();


                                    Session["dt_Sess_Porteo"]   = dtRsponseImport2Grid;
                                    clsBusinessPorteo.dtShiping = dtRsponseImport2Grid;
                                    strHtmlTablePorteo          = clsBusinessPorteo.CreateTableHTML();
                                    //CreateTableHTML(dtRsponseImport2Grid);
                                    DBDataPlaceHolder.Controls.Add(new Literal {
                                        Text = strHtmlTablePorteo.ToString()
                                    });
                                    pnlMuestraDatos.Visible = true;
                                    pnlBrowseFile.Visible   = false;
                                    btnCancel.Enabled       = true;
                                    Button1.Disabled        = false;
                                }
                                else
                                {
                                    ScriptManager.RegisterStartupScript(this, GetType(), "muestraError", "swal('Error','Debe seleccionar un archivo valido a cargar.','error');", true);
                                }
                            }
                        }
                        else
                        {
                            clsError.logMessage = "Debes seccionar un archivo a cargar.";
                            clsError.logModule  = "porteoatomatico-btnUpload_Click";
                            clsError.LogWrite();


                            Button1.Disabled  = true;
                            btnCancel.Enabled = false;

                            lblFileLoad.Visible     = false;
                            pnlFileLoad.Visible     = false;
                            pnlMuestraDatos.Visible = false;

                            //pnlBrowseFile.Visible = true;
                            //pnlValidaciones.Visible = true;
                            //pnlValidaciones.InnerText = "Debes seccionar un archivo a cargar.";
                            ScriptManager.RegisterStartupScript(this, GetType(), "muestraError", "swal('Error','Debe seleccionar un archivo a cargar.','error');", true);
                        }
                    }
                }
                catch (Exception ex)
                {
                    clsError.logMessage = ex.ToString();
                    clsError.logModule  = "btnUpload_Click";
                    clsError.LogWrite();
                    JavaScriptSerializer serializer = new JavaScriptSerializer();
                    string mensaje = serializer.Serialize(ex.Message);
                    ScriptManager.RegisterStartupScript(this, GetType(), "muestraError", "swal('Error  Detalle: " + mensaje + "');", true);
                }
                finally
                {
                    dtRsponseImport2Grid = null;
                    clsBusinessPorteo    = null;
                    strHtmlTablePorteo   = null;
                }
            }
        }