using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI.WebControls; using Extensiones; public partial class CGame_CatCargosFijos : ClsPaginas { #region PROPIEDADES private int CveCargoFijo { get { return (ViewState["CveCargoFijo"] == null) ? 0 : ViewState["CveCargoFijo"].ToEntero(); } set { ViewState["CveCargoFijo"] = value; } } private string Modalidad { get { return (ViewState["Modalidad"] == null) ? "" : ViewState["Modalidad"].ToString(); } set { ViewState["Modalidad"] = value; } } #endregion protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { CargaMoneda(); CargaCargosFijos(); } } protected void CargaCargosFijos() { ClsCGame ObjCGame = new ClsCGame(); if (ObjCGame.GetCargoFijo(UsuarioActual.CveEmpresa)) { GvCargosFijos.DataSource = ObjCGame.DtResultados; } ObjCGame.Dispose(); GvCargosFijos.DataBind(); UpDatos.Update(); } protected void LimpiaModal() { TxtConcepto.Text = ""; DdlTipo.SelectedIndex = 0; DdlTipoCalculado.SelectedIndex = 0; DdlMoneda.SelectedIndex = 0; DdlTipoLiquidacion.SelectedIndex = 0; UpModalCargoFijo.Update(); } protected void LnkAgregarCargoFijo_Click(object sender, EventArgs e) { RegistraScript("$('#ModalAgregarCargoFijo').modal();"); LimpiaModal(); BtnAddCargoFijo.Text = "Agregar"; Modalidad = "A"; DivEstatus.Visible = false; DivTipoCalculado.Visible = false; UpModalCargoFijo.Update(); } protected void LnkEliminar_Click(object sender, EventArgs e) { GridViewRow gvRow = (GridViewRow)(((LinkButton)sender).NamingContainer); CveCargoFijo = gvRow.DataKey("CveCargoFijo").ToEntero(); ClsCGame ObjCGame = new ClsCGame(); if (ObjCGame.RemoveCargoFijo(CveCargoFijo)) { RegistraScript("$('#ModalAgregarCargoFijo').modal('hide');"); CargaCargosFijos(); Alert("Eliminado Correctamente."); } ObjCGame.Dispose(); } protected void LnkEditar_Click(object sender, EventArgs e) { LimpiaModal(); GridViewRow gvRow = (GridViewRow)(((LinkButton)sender).NamingContainer); CveCargoFijo = gvRow.DataKey("CveCargoFijo").ToEntero(); Modalidad = "U"; TxtConcepto.Text = gvRow.DataKey("Concepto"); DdlTipo.SelectedValueExist(gvRow.DataKey("Tipo")); DdlTipoCalculado.SelectedValueExist(gvRow.DataKey("TipoCalculado")); DdlTipoLiquidacion.SelectedValueExist(gvRow.DataKey("TipoLiquidacion")); DdlMoneda.SelectedValueExist(gvRow.DataKey("CveMoneda")); ChkEstatus.Checked = Convert.ToBoolean(gvRow.DataKey("Estatus")); CambioTipo(); RegistraScript("$('#ModalAgregarCargoFijo').modal();"); DivEstatus.Visible = true; BtnAddCargoFijo.Text = "Actualizar"; UpModalCargoFijo.Update(); } protected void BtnAddCargoFijo_Click(object sender, EventArgs e) { if (DdlTipo.SelectedValue.ToEntero() < 1) { Alert("Tiene que seleccionar un tipo.", ModExtensiones.TipoMensaje.MsgAdvertencia); return; } if (DdlTipoLiquidacion.SelectedValue == "1") { Alert("Tiene que seleccionar un tipo de liquidación.", ModExtensiones.TipoMensaje.MsgAdvertencia); return; } if (DdlMoneda.SelectedValue.ToEntero() < 1) { Alert("Tiene que seleccionar una moneda.", ModExtensiones.TipoMensaje.MsgAdvertencia); return; } if (DdlTipo.SelectedValue.ToEntero() == 1) { if (DdlTipoCalculado.SelectedValue == "-1") { Alert("Tiene que seleccionar un tipo calculado.", ModExtensiones.TipoMensaje.MsgAdvertencia); return; } foreach (GridViewRow Gvr in GvCargosFijos.Rows) { if (Gvr.DataKey("TipoCalculado").ToString()== DdlTipoCalculado.SelectedValue && Gvr.DataKey("CveCargoFijo").ToEntero() != CveCargoFijo) { Alert("Este tipo calculado ya ha sido registrado.", ModExtensiones.TipoMensaje.MsgAdvertencia); return; } } } bool Error = false; ClsCGame ObjCGame = new ClsCGame(); if (Modalidad == "A") { if (!ObjCGame.AddCargoFijo(UsuarioActual.CveEmpresa, TxtConcepto.Text, UsuarioActual.CveUsuario,DdlTipo.SelectedValue.ToEntero(),DdlTipoCalculado.SelectedValue,DdlMoneda.SelectedValue.ToEntero(), DdlTipoLiquidacion.SelectedValue)) { Error = true; } }else if (Modalidad == "U") { if (!ObjCGame.UpdateCargoFijo(CveCargoFijo, TxtConcepto.Text,ChkEstatus.Checked, DdlTipo.SelectedValue.ToEntero(), DdlTipoCalculado.SelectedValue, DdlMoneda.SelectedValue.ToEntero(), DdlTipoLiquidacion.SelectedValue)) { Error = true; } } if (!Error) { RegistraScript("$('#ModalAgregarCargoFijo').modal('hide');"); CargaCargosFijos(); if (Modalidad=="A") { Alert("Agregado Correctamente."); } else if (Modalidad == "U") { Alert("Actualizado Correctamente."); } } ObjCGame.Dispose(); } protected void GvCargosFijos_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { if (Convert.ToBoolean(e.Row.DBCampo("Estatus")) == true) { e.Row.Cells[3].Text = "Activo"; e.Row.Cells[3].ForeColor = System.Drawing.Color.Green; } else { e.Row.Cells[3].Text = "Inactivo"; e.Row.Cells[3].ForeColor = System.Drawing.Color.Red; } if (e.Row.DBCampo("Tipo").ToEntero() == 1) { e.Row.Cells[1].Text = "Calculado"; } else if (e.Row.DBCampo("Tipo").ToEntero() == 2) { e.Row.Cells[1].Text = "Fijo"; } } } private void CambioTipo() { if (DdlTipo.SelectedValue.ToEntero() == 1) { DivTipoCalculado.Visible = true; }else { DdlTipoCalculado.SelectedIndex = 0; DivTipoCalculado.Visible = false; } } protected void DdlTipo_SelectedIndexChanged(object sender, EventArgs e) { CambioTipo(); UpModalCargoFijo.Update(); } private void CargaMoneda() { DdlMoneda.DataSource = GlobalDTMonedas; DdlMoneda.Items.Insert(0, new ListItem("Seleccione", "-1")); DdlMoneda.DataBind(); UpModalCargoFijo.Update(); } }