using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI.WebControls; using Extensiones; public partial class CATProductos : ClsPaginas { #region Propiedades private int CvePS { get{return (ViewState["CvePS"] == null) ? 0 : Convert.ToInt32(ViewState["CvePS"]);} set{ViewState["CvePS"] =value;} } #endregion protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack){ CargaProductos(); } } protected void CargaProductos() { ClsCGame ObjCGame =new ClsCGame(); if (ObjCGame.GetPS(UsuarioActual.CveEmpresa)) { GVProductos.DataSource = ObjCGame.DtResultados; GVProductos.DataBind(); } ObjCGame.Dispose(); upDatosProd.Update(); } protected void LimpiaProductos() { TxtProdpS.Text= ""; UPModalProd.Update(); } protected void LnkEditarProd_Click(object sender, EventArgs e) { LimpiaProductos(); GridViewRow gvRow = (GridViewRow)(((LinkButton)sender).NamingContainer); CvePS = gvRow.DataKey("CvePS").ToEntero(); TxtProdpS.Text = gvRow.DataKey("PS"); ChkProdestatus.Checked = Convert.ToBoolean(gvRow.DataKey("Estatus")); this.RegistraScript("$('#DModalProductos').modal();"); BtnProdADD.Visible = false; BtnProdEdit.Visible = true; DivEstatus.Visible = true; UPModalProd.Update(); } protected void LnkAgregarProd_Click(object sender, EventArgs e) { this.RegistraScript("$('#DModalProductos').modal();"); LimpiaProductos(); BtnProdADD.Visible=true; BtnProdEdit.Visible=false; DivEstatus.Visible = false; UPModalProd.Update(); } protected void BtnProdADD_Click(object sender, EventArgs e) { ClsCGame ObjCGame = new ClsCGame(); bool Continuar = ObjCGame.AddPS(TxtProdpS.Text, 1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa); ObjCGame.Dispose(); if (Continuar) { this.RegistraScript("$('#DModalProductos').modal('hide');"); LimpiaProductos(); UPModalProd.Update(); Alert("El Producto se ha agregado"); CargaProductos(); } } protected void BtnProdEdit_Click(object sender, EventArgs e) { ClsCGame ObjCGame = new ClsCGame(); bool Continuar = ObjCGame.UpdatePS(CvePS, TxtProdpS.Text, 1, ChkProdestatus.Checked, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa); ObjCGame.Dispose(); if (Continuar) { this.RegistraScript("$('#DModalProductos').modal('hide');"); LimpiaProductos(); UPModalProd.Update(); Alert("El Producto se ha actualizado"); CargaProductos(); } } protected void LnkEliminarProd_Click(object sender, EventArgs e) { GridViewRow gvRow = (GridViewRow)(((LinkButton)sender).NamingContainer); ClsCGame ObjCGame = new ClsCGame(); bool Continuar = ObjCGame.RemovePS(gvRow.DataKey("CvePS").ToEntero()); ObjCGame.Dispose(); if (Continuar) { CargaProductos(); Alert("El Producto se ha eliminado"); } } protected void GVProductos_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { if (Convert.ToBoolean(e.Row.DBCampo("Estatus")) == true) { e.Row.FCLabel("lblestatus").Text = "Activo"; e.Row.FCLabel("lblestatus").ForeColor = System.Drawing.Color.Green; } else { e.Row.FCLabel("lblestatus").Text = "Inactivo"; e.Row.FCLabel("lblestatus").ForeColor = System.Drawing.Color.Red; } } } }