271 lines
8.7 KiB
C#
271 lines
8.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Web.UI.WebControls;
|
|
using Extensiones;
|
|
using System.Data;
|
|
//using static Extensiones.ModExtensiones;
|
|
|
|
public partial class Inventarios_CatGrupoPSaspx : ClsPaginas
|
|
{
|
|
#region PROPIEDADES
|
|
|
|
private int CveGrupoPS
|
|
{
|
|
get { return (ViewState["CveGrupoPS"] == null) ? 0 : Convert.ToInt32(ViewState["CveGrupoPS"]); }
|
|
set { ViewState["CveGrupoPS"] = value; }
|
|
}
|
|
private int Index
|
|
{
|
|
get { return (ViewState["Index"] == null) ? 0 : Convert.ToInt32(ViewState["Index"]); }
|
|
set { ViewState["Index"] = value; }
|
|
}
|
|
private DataTable DtGrupoPSDetalle
|
|
{
|
|
get { return DtGrupoPSDetalle = (DataTable)ViewState["DtGrupoPSDetalle"]; }
|
|
set { ViewState["DtGrupoPSDetalle"] = value; }
|
|
}
|
|
private String Modalidad
|
|
{
|
|
get { return (ViewState["Modalidad"] == null) ? "" : (String)ViewState["Modalidad"]; }
|
|
set { ViewState["Modalidad"] = value; }
|
|
}
|
|
#endregion
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
if (!IsPostBack)
|
|
{
|
|
CargaGrupoPS();
|
|
CargaPS();
|
|
CreaDtGrupoPSDetalle();
|
|
}
|
|
}
|
|
|
|
protected void CargaPS()
|
|
{
|
|
DdlPS.DataSource = get_GlobalDTPSSimplificado(UsuarioActual.CveEmpresa);
|
|
DdlPS.Items.Insert(0, new ListItem("Seleccione", "-1"));
|
|
DdlPS.DataBind();
|
|
UpModal.Update();
|
|
}
|
|
|
|
protected void CargaGrupoPS()
|
|
{
|
|
ClsInventarios ObjInv = new ClsInventarios();
|
|
if (ObjInv.GetGrupoPS(UsuarioActual.CveEmpresa))
|
|
{
|
|
GvGrupoPS.DataSource = ObjInv.DtResultados;
|
|
}
|
|
ObjInv.Dispose();
|
|
GvGrupoPS.DataBind();
|
|
UpDatos.Update();
|
|
}
|
|
|
|
protected void CargaGrupoPSDetalle()
|
|
{
|
|
ClsInventarios ObjInv = new ClsInventarios();
|
|
if (ObjInv.GetGrupoPSDetalle(CveGrupoPS))
|
|
{
|
|
GvPS.DataSource = ObjInv.DtResultados;
|
|
DtGrupoPSDetalle = ObjInv.DtResultados;
|
|
}
|
|
ObjInv.Dispose();
|
|
GvPS.DataBind();
|
|
}
|
|
|
|
protected void CreaDtGrupoPSDetalle()
|
|
{
|
|
DtGrupoPSDetalle = new DataTable();
|
|
DtGrupoPSDetalle.Columns.Add("CveGrupoPSDetalle");
|
|
DtGrupoPSDetalle.Columns.Add("CveGrupoPS");
|
|
DtGrupoPSDetalle.Columns.Add("CvePS");
|
|
DtGrupoPSDetalle.Columns.Add("PSCodigo");
|
|
}
|
|
|
|
protected void LimpiaModal()
|
|
{
|
|
TxtDescripcion.Text = "";
|
|
DdlPS.SelectedIndex = 0;
|
|
GvPS.DataSource = null;
|
|
GvPS.DataBind();
|
|
DtGrupoPSDetalle.Rows.Clear();
|
|
UpModal.Update();
|
|
}
|
|
|
|
|
|
protected void LnkAddGrupoPS_Click(object sender, EventArgs e)
|
|
{
|
|
this.RegistraScript("$('#DModalGrupoPS').modal();");
|
|
Modalidad = "A";
|
|
LimpiaModal();
|
|
BtnGrupoPSAdd.Text = "Guardar";
|
|
DivEstatus.Visible = false;
|
|
UpModal.Update();
|
|
}
|
|
|
|
protected void LnkEliminar_Click(object sender, EventArgs e)
|
|
{
|
|
GridViewRow gvRow = (GridViewRow)(((LinkButton)sender).NamingContainer);
|
|
ClsInventarios ObjInv = new ClsInventarios();
|
|
var Error = false;
|
|
ObjInv.IniciaTransacSQL();
|
|
if (!ObjInv.RemoveGrupoPSDetalle(-1,gvRow.DataKey("CveGrupoPS").ToEntero()))
|
|
{
|
|
Error = true;
|
|
}
|
|
if (!ObjInv.RemoveGrupoPS(gvRow.DataKey("CveGrupoPS").ToEntero()))
|
|
{
|
|
Error = true;
|
|
}
|
|
if (!Error)
|
|
{
|
|
ObjInv.Commit();
|
|
Alert("El grupo ps se ha eliminado correctamente.");
|
|
}
|
|
else
|
|
{
|
|
ObjInv.RollBack();
|
|
}
|
|
ObjInv.Dispose();
|
|
CargaGrupoPS();
|
|
}
|
|
|
|
protected void LnkEditar_Click(object sender, EventArgs e)
|
|
{
|
|
LimpiaModal();
|
|
GridViewRow gvRow = (GridViewRow)(((LinkButton)sender).NamingContainer);
|
|
Modalidad = "U";
|
|
CveGrupoPS = gvRow.DataKey("CveGrupoPS").ToEntero();
|
|
TxtDescripcion.Text = gvRow.DataKey("Descripcion");
|
|
DivEstatus.Visible = true;
|
|
ChkEstatus.Checked = Convert.ToBoolean((gvRow.DataKey("Estatus")));
|
|
CargaGrupoPSDetalle();
|
|
BtnGrupoPSAdd.Text = "Actualizar";
|
|
this.RegistraScript("$('#DModalGrupoPS').modal();");
|
|
UpModal.Update();
|
|
}
|
|
|
|
protected void GvGrupoPS_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;
|
|
}
|
|
}
|
|
}
|
|
|
|
protected void BtnGrupoPSAdd_Click(object sender, EventArgs e)
|
|
{
|
|
ClsInventarios ObjInv = new ClsInventarios();
|
|
ObjInv.IniciaTransacSQL();
|
|
var Error = false;
|
|
var _CveGrupoPS = -1;
|
|
if (GvPS.Rows.Count < 1)
|
|
{
|
|
Alert("Tiene que agregar al menos un producto.",ModExtensiones.TipoMensaje.MsgAdvertencia);
|
|
return;
|
|
}
|
|
if (Modalidad == "A")
|
|
{
|
|
if (!ObjInv.AddGrupoPS(TxtDescripcion.Text, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa))
|
|
{
|
|
Error = true;
|
|
}
|
|
else
|
|
{
|
|
_CveGrupoPS = ObjInv.CveGrupoPS;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (!ObjInv.UpdateGrupoPS(CveGrupoPS, TxtDescripcion.Text, ChkEstatus.Checked, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa))
|
|
{
|
|
Error = true;
|
|
}
|
|
else
|
|
{
|
|
_CveGrupoPS = CveGrupoPS;
|
|
}
|
|
}
|
|
foreach (DataRow Dr in DtGrupoPSDetalle.Rows)
|
|
{
|
|
if (Dr["CveGrupoPSDetalle"].ToEntero() == -1)
|
|
{
|
|
if (!ObjInv.AddGrupoPSDetalle(_CveGrupoPS, Dr["CvePS"].ToEntero()))
|
|
{
|
|
Error = true;
|
|
}
|
|
}
|
|
else if (Dr["CveGrupoPS"].ToEntero() == -1)
|
|
{
|
|
if (!ObjInv.RemoveGrupoPSDetalle(Dr["CveGrupoPSDetalle"].ToEntero()))
|
|
{
|
|
Error = true;
|
|
}
|
|
}
|
|
}
|
|
if (!Error)
|
|
{
|
|
ObjInv.Commit();
|
|
if (Modalidad == "A")
|
|
{
|
|
Alert("El grupo de productos se agrego correctamente.");
|
|
}else
|
|
{
|
|
Alert("El grupo de productos se actualizo correctamente.");
|
|
}
|
|
this.RegistraScript("$('#DModalGrupoPS').modal('hide');");
|
|
}
|
|
else
|
|
{
|
|
ObjInv.RollBack();
|
|
}
|
|
ObjInv.Dispose();
|
|
CargaGrupoPS();
|
|
}
|
|
|
|
protected void LnkEliminarPS_Click(object sender, EventArgs e)
|
|
{
|
|
GridViewRow gvRow = (GridViewRow)(((LinkButton)sender).NamingContainer);
|
|
DtGrupoPSDetalle.Rows[gvRow.RowIndex]["CveGrupoPS"] = -1;
|
|
if (DtGrupoPSDetalle.Rows[gvRow.RowIndex]["CveGrupoPSDetalle"].ToEntero() == -1)
|
|
{
|
|
DtGrupoPSDetalle.Rows[gvRow.RowIndex].Delete();
|
|
}
|
|
DtGrupoPSDetalle.AcceptChanges();
|
|
GvPS.DataSource = DtGrupoPSDetalle;
|
|
GvPS.DataBind();
|
|
UpModal.Update();
|
|
}
|
|
|
|
protected void BtnAddPS_Click(object sender, EventArgs e)
|
|
{
|
|
if (DdlPS.SelectedValue.ToEntero() > 0)
|
|
{
|
|
DataRow Row = null;
|
|
Row = DtGrupoPSDetalle.NewRow();
|
|
Row["CveGrupoPSDetalle"] = -1;
|
|
Row["CveGrupoPS"] = CveGrupoPS;
|
|
Row["CvePS"] = DdlPS.SelectedValue.ToEntero();
|
|
Row["PSCodigo"] = DdlPS.SelectedItem.Text;
|
|
DtGrupoPSDetalle.Rows.Add(Row);
|
|
DtGrupoPSDetalle.AcceptChanges();
|
|
GvPS.DataSource = DtGrupoPSDetalle;
|
|
GvPS.DataBind();
|
|
UpModal.Update();
|
|
}
|
|
else
|
|
{
|
|
Alert("Tiene que seleccionar un producto", ModExtensiones.TipoMensaje.MsgAdvertencia);
|
|
}
|
|
|
|
}
|
|
|
|
protected void GvPS_RowDataBound(object sender, GridViewRowEventArgs e)
|
|
{
|
|
if (e.Row.RowType == DataControlRowType.DataRow)
|
|
{
|
|
if (e.Row.DataKey("CveGrupoPS").ToEntero() == -1)
|
|
{
|
|
e.Row.Visible = false;
|
|
}
|
|
}
|
|
}
|
|
} |