protected void Import(string FilePath, string Extension)
        {
            string ip   = Request.ServerVariables["REMOTE_ADDR"];
            string VbPC = System.Net.Dns.GetHostEntry(Request.ServerVariables["remote_addr"]).HostName;

            DataRow[] Result;

            FileStream       stream = File.Open(FilePath, FileMode.Open, FileAccess.Read);
            IExcelDataReader ExcelReader;

            ExcelReader = ExcelDataReader.ExcelReaderFactory.CreateReader(stream);

            //// para que tome la primera fila como titulo de campos
            var conf = new ExcelDataSetConfiguration
            {
                ConfigureDataTable = _ => new ExcelDataTableConfiguration
                {
                    UseHeaderRow = true
                }
            };
            var       dataSet = ExcelReader.AsDataSet(conf);
            DataTable DT      = dataSet.Tables[0];

            if (DT.Rows.Count > 0)
            {
                Cnx.SelecBD();
                using (SqlConnection sqlCon = new SqlConnection(Cnx.GetConex()))
                {
                    sqlCon.Open();
                    string VBQuery = "AjusteSP";

                    using (SqlCommand SC = new SqlCommand(VBQuery, sqlCon))
                    {
                        try
                        {
                            string PMensj = "";
                            SC.CommandType = CommandType.StoredProcedure;
                            SqlParameter Prmtrs1  = SC.Parameters.AddWithValue("@Ajuste", DT);
                            SqlParameter Prmtrs2  = SC.Parameters.AddWithValue("@Usu", Session["C77U"].ToString());
                            SqlParameter Prmtrs3  = SC.Parameters.AddWithValue("@IdCia", Session["!dC!@"]);
                            SqlParameter Prmtrs4  = SC.Parameters.AddWithValue("@NIT", Session["Nit77Cia"]);
                            SqlParameter Prmtrs5  = SC.Parameters.AddWithValue("@NomMaquina", VbPC.Trim());
                            SqlParameter Prmtrs6  = SC.Parameters.AddWithValue("@FecAjuste", Convert.ToDateTime(TxtFech.Text));
                            SqlParameter Prmtrs7  = SC.Parameters.AddWithValue("@CodMvto", DdlMvto.Text.Trim());
                            SqlParameter Prmtrs8  = SC.Parameters.AddWithValue("@CodAlma", DdlAlmac.SelectedItem.Text.Trim());
                            SqlParameter Prmtrs9  = SC.Parameters.AddWithValue("@CCost", DdlCcost.Text.Trim());
                            SqlParameter Prmtrs10 = SC.Parameters.AddWithValue("@Mtv", TxtMotvo.Text.Trim());
                            Prmtrs1.SqlDbType = SqlDbType.Structured;
                            using (SqlDataAdapter SDA = new SqlDataAdapter())
                            {
                                using (DataSet DST = new DataSet())
                                {
                                    SDA.SelectCommand = SC; SDA.Fill(DST); ViewState["DST"] = DST;
                                    PMensj            = DST.Tables[1].Rows[0]["Mensj"].ToString().Trim();
                                    if (!PMensj.Trim().Equals(""))
                                    {
                                        Result = Idioma.Select("Objeto= '" + PMensj.ToString().Trim() + "'");
                                        foreach (DataRow row in Result)
                                        {
                                            PMensj = row["Texto"].ToString().Trim();
                                        }                                           //LblTitIncosistnc.Text = PMensj;

                                        ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "alert", "alert('" + PMensj + "');", true);
                                        LblTitInconsist.Text          = PMensj;
                                        GrdInconsist.DataSource       = DST.Tables[0]; GrdInconsist.DataBind();
                                        BtnCargarInvIni.OnClientClick = "";
                                        return;
                                    }
                                    PMensj = DST.Tables[0].Rows[0]["Mensj"].ToString().Trim();
                                    Result = Idioma.Select("Objeto= '" + PMensj.ToString().Trim() + "'");
                                    foreach (DataRow row in Result)
                                    {
                                        LblTitInconsist.Text = row["Texto"].ToString().Trim();
                                    }                                                         //LblTitIncosistnc.Text = PMensj;
                                    GrdInconsist.DataSource = null; GrdInconsist.DataBind();
                                    BtnCargarInvIni.Visible = false; BtnSubirInventario.Visible = true;
                                }
                            }
                        }
                        catch (Exception Ex)
                        {
                            BtnCargarInvIni.OnClientClick = "";
                            Result = Idioma.Select("Objeto= 'MensAjt03'");// Inconvenientes con el archivos, verifique si tiene la estructura requerida.
                            foreach (DataRow row in Result)
                            {
                                ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "alert", "alert('" + row["Texto"].ToString() + "');", true);
                            }                                                                                                                                       //
                            string VbcatUs = Session["C77U"].ToString(), VbcatNArc = ViewState["PFileName"].ToString(), VbcatVer = Session["77Version"].ToString(), VbcatAct = Session["77Act"].ToString();
                            Cnx.UpdateErrorV2(VbcatUs, VbcatNArc, "Import Detalle Sol Pedido", Ex.StackTrace.Substring(Ex.StackTrace.Length > 300 ? Ex.StackTrace.Length - 300 : 0, 300), Ex.Message, VbcatVer, VbcatAct);
                        }
                    }
                }
            }
        }
        protected void BtnCargarInvIni_Click(object sender, EventArgs e)
        {
            Idioma     = (DataTable)ViewState["TablaIdioma"];
            Page.Title = ViewState["PageTit"].ToString().Trim();
            DataRow[] Result;
            if (DdlMvto.Text.Equals(""))
            {
                Result = Idioma.Select("Objeto= 'MensAjt01'");//Debe ingresar un tipo de movimiento.
                foreach (DataRow row in Result)
                {
                    ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "alert", "alert('" + row["Texto"].ToString() + "');", true);
                }
                return;
            }
            if (DdlAlmac.Text.Equals("0"))
            {
                Result = Idioma.Select("Objeto= 'MstrMens19'");//Debe ingresar el almacén.
                foreach (DataRow row in Result)
                {
                    ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "alert", "alert('" + row["Texto"].ToString() + "');", true);
                }
                return;
            }
            if (DdlCcost.Text.Equals(""))
            {
                Result = Idioma.Select("Objeto= 'MensAjt02'");//Debe ingresar un centro de costo.
                foreach (DataRow row in Result)
                {
                    ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "alert", "alert('" + row["Texto"].ToString() + "');", true);
                }
                return;
            }
            if (TxtFech.Text.Equals(""))
            {
                Result = Idioma.Select("Objeto= 'MstrMens08'");//Fecha inválida.
                foreach (DataRow row in Result)
                {
                    ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "alert", "alert('" + row["Texto"].ToString() + "');", true);
                }
                TxtFech.Focus(); return;
            }
            string FechI  = Cnx.ReturnFecha(Convert.ToString(DateTime.UtcNow));
            string VbMnsj = Cnx.ValidarFechas2(TxtFech.Text.Trim(), FechI, 2);

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

            if (TxtMotvo.Text.Equals(""))
            {
                Result = Idioma.Select("Objeto= 'MstrMens22'");//Debe ingresar una observación.
                foreach (DataRow row in Result)
                {
                    ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "alert", "alert('" + row["Texto"].ToString() + "');", true);
                }
                TxtMotvo.Focus(); return;
            }
            if (FUpCargaInvIni.Visible == false)
            {
                FUpCargaInvIni.Visible = true; LblTitInconsist.Text = ""; GrdInconsist.Visible = true; GrdInconsist.DataSource = null; GrdInconsist.DataBind();
            }
            else
            {
                try
                {
                    Result = Idioma.Select("Objeto= 'MensAjt23'");
                    foreach (DataRow row in Result)
                    {
                        BtnCargarInvIni.OnClientClick = "return confirm('" + row["Texto"].ToString().Trim() + "');";
                    }

                    DataTable DT = new DataTable();
                    if (FUpCargaInvIni.Visible == false)
                    {
                        FUpCargaInvIni.Visible = true;
                    }
                    else
                    {
                        if (FUpCargaInvIni.HasFile == true)
                        {
                            //BtnCargarInvIni.CssClass = "btn btn-success";
                            string FolderPath;
                            string FileName = Path.GetFileName(FUpCargaInvIni.PostedFile.FileName);
                            string VblExt   = Path.GetExtension(FUpCargaInvIni.PostedFile.FileName);
                            if (Cnx.GetProduccion().Trim().Equals("Y"))
                            {
                                FolderPath = ConfigurationManager.AppSettings["FolderPath"];
                            }                                                                                                           //Azure
                            else
                            {
                                FolderPath = ConfigurationManager.AppSettings["FoldPathLcl"];
                            }

                            VblExt = VblExt.Substring(VblExt.LastIndexOf(".") + 1).ToLower();
                            string[] formatos = new string[] { "xls", "xlsx" };
                            if (Array.IndexOf(formatos, VblExt) < 0)
                            {
                                BtnCargarInvIni.OnClientClick = "";
                                Result = Idioma.Select("Objeto= 'RteMens40'");//Archivo inválido
                                foreach (DataRow row in Result)
                                {
                                    ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "alert", "alert('" + row["Texto"].ToString() + "');", true);
                                }
                                return;
                            }
                            string FilePath = FolderPath + FileName;
                            FUpCargaInvIni.SaveAs(FilePath);
                            Import(FilePath, VblExt);
                            FUpCargaInvIni.Visible = false;
                        }
                        else
                        {
                            Result = Idioma.Select("Objeto= 'MstrMens34'");//Debe seleccionar un archivo.
                            foreach (DataRow row in Result)
                            {
                                ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "alert", "alert('" + row["Texto"].ToString() + "');", true);
                            }
                            return;
                        }
                    }
                }
                catch (Exception Ex)
                {
                    BtnCargarInvIni.OnClientClick = "";
                    Result = Idioma.Select("Objeto= 'MensErrMod'");
                    foreach (DataRow row in Result)
                    {
                        ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "alert", "alert('" + row["Texto"].ToString() + "');", true);
                    }                                                                                                                                       //
                    string VbcatUs = Session["C77U"].ToString(), VbcatNArc = ViewState["PFileName"].ToString(), VbcatVer = Session["77Version"].ToString(), VbcatAct = Session["77Act"].ToString();
                    Cnx.UpdateErrorV2(VbcatUs, VbcatNArc, "Cargar Masiva Ajuste", Ex.StackTrace.Substring(Ex.StackTrace.Length > 300 ? Ex.StackTrace.Length - 300 : 0, 300), Ex.Message, VbcatVer, VbcatAct);
                }
                FUpCargaInvIni.Visible = false;
            }
        }