using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI.WebControls; using Extensiones; public partial class CATMotivosMerma :ClsPaginas { #region Propiedades private int CveMotivo { get{return (ViewState["CveMotivo"] == null) ? 0 : Convert.ToInt32(ViewState["CveMotivo"]);} set{ViewState["CveMotivo"] =value;} } #endregion protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack){ CargaMotivosMerma(); } } protected void CargaMotivosMerma() { ClsCGame ObjMoti =new ClsCGame(); if (ObjMoti.GetMotivoMerma(UsuarioActual.CveEmpresa)) { GVMotivosMerma.DataSource = ObjMoti.DtResultados; GVMotivosMerma.DataBind(); } ObjMoti.Dispose(); upDatosMoti.Update(); } protected void LimpiaMotivosMerma() { TxtMotimotivo.Text= ""; UPModalMoti.Update(); } protected void LnkEditarMoti_Click(object sender, EventArgs e) { LimpiaMotivosMerma(); GridViewRow gvRow = (GridViewRow)(((LinkButton)sender).NamingContainer); CveMotivo = gvRow.DataKey("CveMotivo").ToEntero(); TxtMotimotivo.Text= gvRow.DataKey("Motivo"); ChkMotiestatus.Checked = Convert.ToBoolean(gvRow.DataKey("Estatus")); this.RegistraScript("$('#DModalMotivosMerma').modal();"); BtnMotiADD.Visible=false; BtnMotiEdit.Visible=true; DivEstatus.Visible = true; UPModalMoti.Update(); } protected void LnkAgregarMoti_Click(object sender, EventArgs e) { this.RegistraScript("$('#DModalMotivosMerma').modal();"); LimpiaMotivosMerma(); BtnMotiADD.Visible=true; BtnMotiEdit.Visible=false; DivEstatus.Visible = false; UPModalMoti.Update(); } protected void BtnMotiADD_Click(object sender, EventArgs e) { ClsCGame ObjMoti =new ClsCGame(); bool Continuar = ObjMoti.AddMotivoMerma(TxtMotimotivo.Text, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa); ObjMoti.Dispose(); if(Continuar) { this.RegistraScript("$('#DModalMotivosMerma').modal('hide');"); LimpiaMotivosMerma(); UPModalMoti.Update(); Alert("El Motivo de Merma se ha agregado"); CargaMotivosMerma(); } } protected void BtnMotiEdit_Click(object sender, EventArgs e) { ClsCGame ObjMoti =new ClsCGame(); bool Continuar = ObjMoti.UpdateMotivoMerma(CveMotivo, TxtMotimotivo.Text, ChkMotiestatus.Checked, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa); ObjMoti.Dispose(); if(Continuar) { this.RegistraScript("$('#DModalMotivosMerma').modal('hide');"); LimpiaMotivosMerma(); UPModalMoti.Update(); Alert("El Motivo de Merma se ha actualizado"); CargaMotivosMerma(); } } protected void LnkEliminarMoti_Click(object sender, EventArgs e) { GridViewRow gvRow = (GridViewRow)(((LinkButton)sender).NamingContainer); ClsCGame ObjMoti = new ClsCGame(); bool Continuar = ObjMoti.RemoveMotivoMerma(gvRow.DataKey("CveMotivo").ToEntero()); ObjMoti.Dispose(); if(Continuar) { CargaMotivosMerma(); Alert("El Motivo de Merma se ha eliminado"); } } protected void GvMotivoMerma_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; } } } }