protected void GrdMvtos_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
 {
     GrdMvtos.EditIndex = -1; DSSM = (DataSet)ViewState["DSSM"]; GrdMvtos.DataSource = DSSM.Tables[2]; GrdMvtos.DataBind();
 }
        //**************** Ejecutar ***********************************
        protected void BindEjecutar()
        {
            Idioma = (DataTable)ViewState["TablaIdioma"];
            try
            {
                if (DdlPN.Text.Trim().Equals(""))
                {
                    GrdStokAlma.DataSource = null; GrdStokAlma.DataBind(); return;
                }
                Cnx.SelecBD();
                using (SqlConnection sqlConB = new SqlConnection(Cnx.GetConex()))
                {
                    string VbPn  = DdlPN.Text.Trim();
                    string VbSn  = DdlSN.Text.Trim();
                    string VbLot = DdlLote.Text.Trim();
                    if (CkbAlterno.Checked == true)
                    {
                        VbPn = ""; VbSn = ""; VbLot = "";
                    }

                    CsTypExportarIdioma CursorIdioma = new CsTypExportarIdioma();
                    CursorIdioma.Alimentar("CURDATOSCONSULTA1", Session["77IDM"].ToString().Trim());
                    string VbTxtSql = "EXEC SP_TablasLogistica 5, @Rf,@Pn,@Sn,@Lt,'','','','','CURDATOSCONSULTA1',0,0,@ExpVlr,1,@Idm,@ICC,'01-01-1','02-01-1','03-01-1'";
                    sqlConB.Open();
                    using (SqlCommand SC = new SqlCommand(VbTxtSql, sqlConB))
                    {
                        SC.Parameters.AddWithValue("@Rf", ViewState["CodReferencia"]);
                        SC.Parameters.AddWithValue("@Pn", VbPn);
                        SC.Parameters.AddWithValue("@Sn", VbSn);
                        SC.Parameters.AddWithValue("@Lt", VbLot);
                        SC.Parameters.AddWithValue("@ExpVlr", ViewState["VblCE4"]);
                        SC.Parameters.AddWithValue("@Idm", Session["77IDM"]);
                        SC.Parameters.AddWithValue("@ICC", Session["!dC!@"]);
                        using (SqlDataAdapter SDA = new SqlDataAdapter())
                        {
                            using (DataSet DSSM = new DataSet())
                            {
                                SDA.SelectCommand = SC;
                                SDA.Fill(DSSM);
                                DSSM.Tables[0].TableName = "Stock";
                                DSSM.Tables[1].TableName = "StockActual";
                                DSSM.Tables[2].TableName = "Mvtos";
                                DSSM.Tables[3].TableName = "Exprtr";
                                ViewState["DSSM"]        = DSSM;

                                GrdStokAlma.DataSource = DSSM.Tables[0]; GrdStokAlma.DataBind();
                                TxtStockActual.Text    = DSSM.Tables[1].Rows[0]["CantTtl"].ToString().Trim();
                                GrdMvtos.DataSource    = DSSM.Tables[2]; GrdMvtos.DataBind();
                            }
                        }
                    }
                }
            }
            catch (Exception Ex)
            {
                DataRow[] Result = Idioma.Select("Objeto= 'MensIncovCons'");
                foreach (DataRow row in Result)
                {
                    ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "alert", "alert('" + row["Texto"].ToString() + "');", true);
                }                                                                                                                                       //

                Cnx.UpdateErrorV2(Session["C77U"].ToString(), ViewState["PFileName"].ToString().Trim(), "UPDATE Detalle PPT", Ex.StackTrace.Substring(Ex.StackTrace.Length > 300 ? Ex.StackTrace.Length - 300 : 0, 300), Ex.Message, Session["77Version"].ToString(), Session["77Act"].ToString());
            }
        }
 //**************** Detalle Movimeintos ***********************************
 protected void GrdMvtos_RowEditing(object sender, GridViewEditEventArgs e)
 {
     GrdMvtos.EditIndex = e.NewEditIndex; DSSM = (DataSet)ViewState["DSSM"]; GrdMvtos.DataSource = DSSM.Tables[2]; GrdMvtos.DataBind();
 }
        protected void BindBusPn(string PN)
        {
            DSTPSL = (DataSet)ViewState["DSTPSL"];
            DataRow[] DR; DataTable DT = new DataTable();
            GrdAlterno.DataSource  = null; GrdAlterno.DataBind();
            GrdStokAlma.DataSource = null; GrdStokAlma.DataBind();
            GrdMvtos.DataSource    = null; GrdMvtos.DataBind();

            DR = DSTPSL.Tables[0].Select("Codigo ='" + PN + "'");
            if (Cnx.ValidaDataRowVacio(DR))
            {
                DT                         = DR.CopyToDataTable();
                TxtTipo.Text               = DT.Rows[0]["DescTipo"].ToString().Trim();
                TxtDescrPn.Text            = DT.Rows[0]["Descripcion"].ToString().Trim();
                ViewState["CodReferencia"] = DT.Rows[0]["CodReferencia"].ToString().Trim();
                LblTitAlterno.Text         = ViewState["IdimaPnALter"].ToString().Trim() + " [" + ViewState["CodReferencia"] + "]";
                switch (DT.Rows[0]["Identf"].ToString().Trim())
                {
                case "SN":
                    DR = DSTPSL.Tables[1].Select("PN ='" + PN + "' OR Codigo = ''");
                    if (Cnx.ValidaDataRowVacio(DR))
                    {
                        DT = DR.CopyToDataTable();
                        DdlSN.DataSource     = DT;
                        DdlSN.DataTextField  = "SN";
                        DdlSN.DataValueField = "Codigo";
                    }
                    else
                    {
                        DdlSN.DataSource = null;
                    }
                    DdlSN.DataBind();
                    DR = DSTPSL.Tables[2].Select("Codigo = ''");
                    if (Cnx.ValidaDataRowVacio(DR))
                    {
                        DT = DR.CopyToDataTable();
                        DdlLote.DataSource     = DT;
                        DdlLote.DataTextField  = "LOTE";
                        DdlLote.DataValueField = "Codigo";
                        DdlLote.DataBind();
                    }
                    break;

                case "LOTE":
                    DR = DSTPSL.Tables[2].Select("PN ='" + PN + "' OR Codigo = ''");
                    if (Cnx.ValidaDataRowVacio(DR))
                    {
                        DT = DR.CopyToDataTable();
                        DdlLote.DataSource     = DT;
                        DdlLote.DataTextField  = "LOTE";
                        DdlLote.DataValueField = "Codigo";
                    }
                    else
                    {
                        DdlLote.DataSource = null;
                    }
                    DdlLote.DataBind();
                    DR = DSTPSL.Tables[1].Select("Codigo = ''");
                    if (Cnx.ValidaDataRowVacio(DR))
                    {
                        DT = DR.CopyToDataTable();
                        DdlSN.DataSource     = DT;
                        DdlSN.DataTextField  = "SN";
                        DdlSN.DataValueField = "Codigo";
                        DdlSN.DataBind();
                    }
                    break;

                default:
                    DR = DSTPSL.Tables[2].Select("Codigo = ''");
                    if (Cnx.ValidaDataRowVacio(DR))
                    {
                        DT = DR.CopyToDataTable();
                        DdlLote.DataSource     = DT;
                        DdlLote.DataTextField  = "LOTE";
                        DdlLote.DataValueField = "Codigo";
                        DdlLote.DataBind();
                    }
                    DR = DSTPSL.Tables[1].Select("Codigo = ''");
                    if (Cnx.ValidaDataRowVacio(DR))
                    {
                        DT = DR.CopyToDataTable();
                        DdlSN.DataSource     = DT;
                        DdlSN.DataTextField  = "SN";
                        DdlSN.DataValueField = "Codigo";
                        DdlSN.DataBind();
                    }
                    break;
                }

                Cnx.SelecBD();
                using (SqlConnection sqlConB = new SqlConnection(Cnx.GetConex()))
                {
                    string VbTxtSql = "EXEC SP_PANTALLA_ConsultaMovimiento 14,@CRf,'','','',0,0,@Idm,@ICC,'01-1-2009','01-01-1900','01-01-1900'";
                    sqlConB.Open();
                    using (SqlCommand SC = new SqlCommand(VbTxtSql, sqlConB))
                    {
                        SC.Parameters.AddWithValue("@CRf", ViewState["CodReferencia"]);
                        SC.Parameters.AddWithValue("@Idm", Session["77IDM"]);
                        SC.Parameters.AddWithValue("@ICC", Session["!dC!@"]);
                        using (SqlDataAdapter SDA = new SqlDataAdapter())
                        {
                            using (DataTable DTA = new DataTable())
                            {
                                SDA.SelectCommand = SC;
                                SDA.Fill(DTA);
                                GrdAlterno.DataSource = DTA; GrdAlterno.DataBind();
                            }
                        }
                    }
                }
            }
        }