Commit inicial Ventas Productivo
This commit is contained in:
334
CGame/CorteGasto.aspx.cs
Normal file
334
CGame/CorteGasto.aspx.cs
Normal file
@@ -0,0 +1,334 @@
|
||||
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 CGame_CorteGasto : ClsPaginas
|
||||
{
|
||||
|
||||
#region PROPIEDADES
|
||||
|
||||
private int CveCorteGasto
|
||||
{
|
||||
get { return (ViewState["CveCorteGasto"] == null) ? 0 : Convert.ToInt32(ViewState["CveCorteGasto"]); }
|
||||
set { ViewState["CveCorteGasto"] = value; }
|
||||
}
|
||||
private int CveOrdenCorteOpcion
|
||||
{
|
||||
get { return (ViewState["CveOrdenCorteOpcion"] == null) ? 0 : Convert.ToInt32(ViewState["CveOrdenCorteOpcion"]); }
|
||||
set { ViewState["CveOrdenCorteOpcion"] = value; }
|
||||
}
|
||||
private DataTable DtCorteGastoDetalle
|
||||
{
|
||||
get { return DtCorteGastoDetalle = (DataTable)ViewState["DtCorteGastoDetalle"]; }
|
||||
set { ViewState["DtCorteGastoDetalle"] = value; }
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
if (!IsPostBack)
|
||||
{
|
||||
CveCorteGasto = Request["CveCorteGasto"] == null ? 0 : Request["CveCorteGasto"].ToString().ToEntero();
|
||||
CveOrdenCorteOpcion = Request["CveOrdenCorte"] == null ? 0 : Request["CveOrdenCorte"].ToString().ToEntero();
|
||||
CargaOrdenCorte();
|
||||
CargaConceptos();
|
||||
CargaDatos();
|
||||
if (CveOrdenCorteOpcion > 0) { DdlOrdenCorte.SelectedValueExist(CveOrdenCorteOpcion); }
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
#region CARGAS
|
||||
|
||||
protected void CargaDatos()
|
||||
{
|
||||
if (CveCorteGasto > 0)
|
||||
{
|
||||
CargaCorteGasto();
|
||||
CargaCorteGastoDetalle();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
TxtFechaRegistro.Text = DateTime.Now.ToShortDateString();
|
||||
txtFechaI.Text = DateTime.Now.ToShortDateString();
|
||||
lblNombreUsuario.Text = UsuarioActual.Usuario;
|
||||
UpDatosCorteGasto.Update();
|
||||
UpDatosRegistro.Update();
|
||||
}
|
||||
}
|
||||
|
||||
protected void CargaOrdenCorte()
|
||||
{
|
||||
ClsCGame ObjCGame = new ClsCGame();
|
||||
if (ObjCGame.GetOrdenCorte(UsuarioActual.CveEmpresa))
|
||||
{
|
||||
DdlOrdenCorte.DataSource = ObjCGame.DtResultados.FiltraParametros("Disponible = 1");
|
||||
DdlOrdenCorte.Items.Insert(0, new ListItem("Seleccione", "-1"));
|
||||
DdlOrdenCorte.DataBind();
|
||||
}
|
||||
ObjCGame.Dispose();
|
||||
UpDatosCorteGasto.Update();
|
||||
}
|
||||
|
||||
protected void CargaConceptos()
|
||||
{
|
||||
ClsCGame ObjCGame = new ClsCGame();
|
||||
if (ObjCGame.GetConceptoGastoCorte(UsuarioActual.CveEmpresa, Estatus: 1))
|
||||
{
|
||||
GVCorteGasto.DataSource = ObjCGame.DtResultados;
|
||||
GVCorteGasto.DataBind();
|
||||
}
|
||||
ObjCGame.Dispose();
|
||||
UpCorteGasto.Update();
|
||||
}
|
||||
|
||||
protected void CargaCorteGasto()
|
||||
{
|
||||
ClsCGame ObjCGame = new ClsCGame();
|
||||
if (ObjCGame.GetCorteGasto(UsuarioActual.CveEmpresa, CveCorteGasto: CveCorteGasto))
|
||||
{
|
||||
DdlOrdenCorte.SelectedValueExist(ObjCGame.DtResultados.Rows[0]["CveOrdenCorte"].ToString());
|
||||
TxtFechaRegistro.Text = ObjCGame.DtResultados.Rows[0]["FechaIng"].ToString().ToDateTime().ToShortDateString();
|
||||
lblNombreUsuario.Text = ObjCGame.DtResultados.Rows[0]["Usuario"].ToString();
|
||||
TxtCuadro.Text = ObjCGame.DtResultados.Rows[0]["Cuadro"].ToString();
|
||||
txtFechaI.Text= ObjCGame.DtResultados.Rows[0]["FechaCorteGasto"].ToString().ToDateTime().ToShortDateString();
|
||||
}
|
||||
ObjCGame.Dispose();
|
||||
UpDatosCorteGasto.Update();
|
||||
UpDatosRegistro.Update();
|
||||
}
|
||||
|
||||
protected void CargaCorteGastoDetalle()
|
||||
{
|
||||
ClsCGame ObjCGame = new ClsCGame();
|
||||
if (ObjCGame.GetCorteGastoDetalle(CveCorteGasto))
|
||||
{
|
||||
DtCorteGastoDetalle = ObjCGame.DtResultados;
|
||||
DtCorteGastoDetalle.AcceptChanges();
|
||||
}
|
||||
ObjCGame.Dispose();
|
||||
foreach (DataRow Dt in DtCorteGastoDetalle.Rows)
|
||||
{
|
||||
foreach (GridViewRow Gv in GVCorteGasto.Rows)
|
||||
{
|
||||
if (Dt["CveConceptoGastoCorte"].ToEntero() == Gv.DataKey("CveConceptoGastoCorte").ToEntero())
|
||||
{
|
||||
Gv.FCTextBox("TxtCantidad").Text = Dt["Cantidad"].ToString().FormatoNumero();
|
||||
Gv.FCTextBox("TxtPU").Text = Dt["PU"].ToString().FormatoNumero();
|
||||
Gv.FCLabel("LblImporte").Text = (Dt["Cantidad"].ToString().ToDouble() * Dt["PU"].ToString().ToDouble()).ToString().FormatoNumero();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
UpCorteGasto.Update();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region "LIMPIA"
|
||||
|
||||
protected void Limpia()
|
||||
{
|
||||
TxtFechaRegistro.Text = DateTime.Now.ToShortDateString();
|
||||
lblNombreUsuario.Text = UsuarioActual.Usuario;
|
||||
TxtFechaRegistro.Text = DateTime.Now.ToShortDateString();
|
||||
DdlOrdenCorte.SelectedIndex = 0;
|
||||
UpDatosCorteGasto.Update();
|
||||
UpDatosRegistro.Update();
|
||||
GVCorteGasto.DataSource = null;
|
||||
GVCorteGasto.DataBind();
|
||||
CargaConceptos();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region BOTONES
|
||||
|
||||
protected void BtnGuardar_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (DdlOrdenCorte.SelectedValue == "-1")
|
||||
{
|
||||
Alert("Tiene que seleccionar una orden de corte", TipoMensaje.MsgAdvertencia);
|
||||
return;
|
||||
}
|
||||
ClsCGame ObjCGame = new ClsCGame();
|
||||
ObjCGame.IniciaTransacSQL();
|
||||
var Error = false;
|
||||
var CveOrdenCorte = DdlOrdenCorte.SelectedValue.ToEntero();
|
||||
var _CveCorteGasto = CveCorteGasto;
|
||||
if (CveCorteGasto > 0)
|
||||
{
|
||||
if (ObjCGame.UpdateCorteGasto(CveCorteGasto, DdlOrdenCorte.SelectedValue.ToEntero(), UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa,txtFechaI.Text.ToDate(),TxtCuadro.Text.ToDouble()))
|
||||
{
|
||||
_CveCorteGasto = CveCorteGasto;
|
||||
}
|
||||
else
|
||||
{
|
||||
Error = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ObjCGame.AddCorteGasto(DdlOrdenCorte.SelectedValue.ToEntero(), UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, txtFechaI.Text.ToDate(), TxtCuadro.Text.ToDouble()))
|
||||
{
|
||||
_CveCorteGasto = ObjCGame.CveCorteGasto;
|
||||
}
|
||||
else
|
||||
{
|
||||
Error = true;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (GridViewRow Gv in GVCorteGasto.Rows)
|
||||
{
|
||||
int x = 0;
|
||||
if (DtCorteGastoDetalle!=null)
|
||||
{
|
||||
foreach (DataRow Dt in DtCorteGastoDetalle.Rows)
|
||||
{
|
||||
if (Gv.DataKey("CveConceptoGastoCorte").ToEntero() == Dt["CveConceptoGastoCorte"].ToEntero())
|
||||
{
|
||||
x = 1;
|
||||
if (Gv.FCTextBox("TxtCantidad").Text.ToString() == "" || Gv.FCTextBox("TxtPU").Text.ToString() == "")
|
||||
{
|
||||
if (ObjCGame.RemoveCorteGastoDetalle(Dt["CveCorteGastoDetalle"].ToEntero()) == false)
|
||||
{
|
||||
Error = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ObjCGame.UpdateCorteGastoDetalle(Dt["CveCorteGastoDetalle"].ToEntero(), _CveCorteGasto, Dt["CveConceptoGastoCorte"].ToEntero(), Gv.FCTextBox("TxtCantidad").Text.ToDouble(), Gv.FCTextBox("TxtPU").Text.ToDouble()) == false)
|
||||
{
|
||||
Error = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (Gv.FCTextBox("TxtCantidad").Text.ToString() != "" && Gv.FCTextBox("TxtPU").Text.ToString() != "" && x == 0)
|
||||
{
|
||||
if (ObjCGame.AddCorteGastoDetalle(_CveCorteGasto, Gv.DataKey("CveConceptoGastoCorte").ToEntero(), Gv.FCTextBox("TxtCantidad").Text.ToString().ToDouble(), Gv.FCTextBox("TxtPU").Text.ToString().ToDouble()) == false)
|
||||
{
|
||||
Error = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Error)
|
||||
{
|
||||
ObjCGame.RollBack();
|
||||
}
|
||||
else
|
||||
{
|
||||
ObjCGame.Commit();
|
||||
if (CveCorteGasto > 0)
|
||||
{
|
||||
Alert("Actualizado Correctamente");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (CveOrdenCorte > 0)
|
||||
{
|
||||
Alert("Guardado Correctamente", TipoMensaje.MsgInformacion, $"document.location.href=\"/CGame/RepOrdenCorteDetalle.aspx?CveOrdenCorte={CveOrdenCorte}\"");
|
||||
}
|
||||
|
||||
Limpia();
|
||||
}
|
||||
}
|
||||
ObjCGame.Dispose();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region GRIDVIEW
|
||||
|
||||
protected void GVCorteGasto_RowDataBound(object sender, GridViewRowEventArgs e)
|
||||
{
|
||||
if (e.Row.RowType == DataControlRowType.DataRow)
|
||||
{
|
||||
//e.Row.FCTextBox("TxtCantidad").Attributes.Add("onKeyUp ", "Recalcula();");
|
||||
//e.Row.FCTextBox("TxtPU").Attributes.Add("onKeyUp ", "Recalcula();");
|
||||
//if (e.Row.DBCampo("CveConceptoGastoCorte").ToEntero() == 16) { e.Row.Visible = false; }
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region TEXTCHANGE
|
||||
|
||||
//protected void TxtPU_TextChanged(object sender, EventArgs e)
|
||||
//{
|
||||
// GridViewRow gvRow = (GridViewRow)(((TextBox)sender).NamingContainer);
|
||||
// if (gvRow.FCTextBox("TxtCantidad").Text != "" && gvRow.FCTextBox("TxtPU").Text != "")
|
||||
// {
|
||||
// gvRow.FCLabel("LblImporte").Text = "$" + (gvRow.FCTextBox("TxtCantidad").Text.ToDouble() * gvRow.FCTextBox("TxtPU").Text.ToDouble()).ToString().FormatoNumero();
|
||||
// }
|
||||
//}
|
||||
|
||||
//protected void TxtCantidad_TextChanged(object sender, EventArgs e)
|
||||
//{
|
||||
// GridViewRow gvRow = (GridViewRow)(((TextBox)sender).NamingContainer);
|
||||
// if (gvRow.FCTextBox("TxtCantidad").Text != "" && gvRow.FCTextBox("TxtPU").Text != "")
|
||||
// {
|
||||
// gvRow.FCLabel("LblImporte").Text = "$" + (gvRow.FCTextBox("TxtCantidad").Text.ToDouble() * gvRow.FCTextBox("TxtPU").Text.ToDouble()).ToString().FormatoNumero();
|
||||
// }
|
||||
//}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
protected void GVCorteGasto_RowCreated(object sender, GridViewRowEventArgs e)
|
||||
{
|
||||
if (e.Row.RowType == DataControlRowType.DataRow)
|
||||
{
|
||||
int index = e.Row.RowIndex;
|
||||
e.Row.FCTextBox("TxtCantidad").Attributes.Add("onKeyUp ", "Recalcula(" + index + ");");
|
||||
e.Row.FCTextBox("TxtPU").Attributes.Add("onKeyUp ", "Recalcula(" + index + ");");
|
||||
}
|
||||
}
|
||||
|
||||
protected void BtnEliminar_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (CveCorteGasto > 0)
|
||||
{
|
||||
ClsCGame ObjCGame = new ClsCGame();
|
||||
ObjCGame.IniciaTransacSQL();
|
||||
bool Error = false;
|
||||
if (!ObjCGame.RemoveCorteGastoDetalle(-1, CveCorteGasto))
|
||||
{
|
||||
Error = true;
|
||||
}
|
||||
if (!ObjCGame.RemoveCorteGasto(CveCorteGasto))
|
||||
{
|
||||
Error = true;
|
||||
}
|
||||
if (!Error)
|
||||
{
|
||||
ObjCGame.Commit();
|
||||
Alert("Eliminado Correctamente",TipoMensaje.MsgInformacion, $"document.location.href=\"/CGame/CorteGasto.aspx\"");
|
||||
Limpia();
|
||||
}
|
||||
else
|
||||
{
|
||||
ObjCGame.RollBack();
|
||||
}
|
||||
ObjCGame.Dispose();
|
||||
}
|
||||
else
|
||||
{
|
||||
Alert("Tiene que tener un corte de gasto seleccionada.", TipoMensaje.MsgAdvertencia);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user