Exemple #1
0
 protected void BtnConsultar_Click(object sender, EventArgs e)
 {
     Idioma = (DataTable)ViewState["TablaIdioma"];
     PerfilesGrid();
     if (TxtFechI.Text.Length > 10 || TxtFechF.Text.Length > 10)
     {
         DataRow[] Result = Idioma.Select("Objeto= 'Mens01HIR'");
         foreach (DataRow row in Result)
         {
             ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "alert", "alert('" + row["Texto"].ToString() + "');", true);
         }                                                                                                                                       // fecha invalida
         TxtFechI.Focus(); return;
     }
     if (!TxtFechI.Text.Trim().Equals("") && TxtFechF.Text.Trim().Equals(""))
     {
         DataRow[] Result = Idioma.Select("Objeto= 'Mens02HIR'");
         foreach (DataRow row in Result)
         {
             ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "alert", "alert('" + row["Texto"].ToString() + "');", true);
         }                                                                                                                                       // Campo fecha requerido.
         TxtFechF.Focus(); return;
     }
     if (TxtFechI.Text.Trim().Equals("") && !TxtFechF.Text.Trim().Equals(""))
     {
         DataRow[] Result = Idioma.Select("Objeto= 'Mens02HIR'");
         foreach (DataRow row in Result)
         {
             ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "alert", "alert('" + row["Texto"].ToString() + "');", true);
         }                                                                                                                                       // Campo fecha requerido.
         TxtFechI.Focus(); return;
     }
     BindHistorico();
 }
 protected void BtnReparaciones_Click(object sender, EventArgs e)
 {
     MlVw.ActiveViewIndex = 1; TxtFechI.Focus();
 }
        protected void IbtExcelRepa_Click(object sender, ImageClickEventArgs e)
        {
            Page.Title = ViewState["PageTit"].ToString().Trim();
            DataRow[] Result;
            Idioma = (DataTable)ViewState["TablaIdioma"];
            if (TxtFechI.Text.Equals("") || TxtFechF.Text.Equals(""))
            {
                Result = Idioma.Select("Objeto= 'MensCampoReq'");
                foreach (DataRow row in Result)
                {
                    ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "alert", "alert('" + row["Texto"].ToString().Trim() + "');", true);
                }
                if (TxtFechF.Text.Equals(""))
                {
                    TxtFechI.Focus();
                }
                if (TxtFechI.Text.Equals(""))
                {
                    TxtFechI.Focus();
                }
                return;
            }
            Cnx.ValidarFechas(TxtFechI.Text.Trim(), TxtFechF.Text.Trim(), 2);
            var MensjF = Cnx.GetMensj();

            if (!MensjF.ToString().Trim().Equals(""))
            {
                Result = Idioma.Select("Objeto= '" + MensjF.ToString().Trim() + "'");
                foreach (DataRow row in Result)
                {
                    MensjF = row["Texto"].ToString().Trim();
                }
                ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "alert", "alert('" + MensjF + "');", true);
                Page.Title = ViewState["PageTit"].ToString();
                return;
            }

            string VbNomArchivo = "";

            Result = Idioma.Select("Objeto= 'NomArcRepa'");
            foreach (DataRow row in Result)
            {
                VbNomArchivo = row["Texto"].ToString().Trim();
            }

            CsTypExportarIdioma CursorIdioma = new CsTypExportarIdioma();

            CursorIdioma.Alimentar("CurExportLogstcRepa", Session["77IDM"].ToString().Trim());

            string Query = "EXEC SP_Mvto_Entrada_Repa @FI, @FF, '', @NA, @Idm, @ICC";

            Cnx.SelecBD();
            using (SqlConnection con = new SqlConnection(Cnx.GetConex()))
            {
                using (SqlCommand cmd = new SqlCommand(Query, con))
                {
                    cmd.CommandTimeout = 90000000;
                    cmd.Parameters.AddWithValue("@FI", Convert.ToDateTime(TxtFechI.Text.Trim()));
                    cmd.Parameters.AddWithValue("@FF", Convert.ToDateTime(TxtFechF.Text.Trim()));
                    cmd.Parameters.AddWithValue("@NA", "CurExportLogstcRepa");
                    cmd.Parameters.AddWithValue("@Idm", Session["77IDM"]);
                    cmd.Parameters.AddWithValue("@ICC", Session["!dC!@"]);

                    using (SqlDataAdapter sda = new SqlDataAdapter())
                    {
                        cmd.Connection    = con;
                        sda.SelectCommand = cmd;
                        using (DataSet ds = new DataSet())
                        {
                            sda.Fill(ds);
                            ds.Tables[0].TableName = "Historic";
                            using (XLWorkbook wb = new XLWorkbook())
                            {
                                foreach (DataTable dt in ds.Tables)
                                {
                                    wb.Worksheets.Add(dt);
                                }
                                Response.Clear();
                                Response.Buffer      = true;
                                Response.ContentType = "application/ms-excel";
                                Response.AddHeader("content-disposition", string.Format("attachment;filename={0}.xlsx", VbNomArchivo));
                                Response.Charset = "";
                                using (MemoryStream MyMemoryStream = new MemoryStream())
                                {
                                    wb.SaveAs(MyMemoryStream);
                                    MyMemoryStream.WriteTo(Response.OutputStream);
                                    Response.Flush();
                                    Response.End();
                                }
                            }
                        }
                    }
                }
            }
        }