-RegistraScript se unifica en una sola clase static/shared y se simplica el código -Alert se vuelve estático -Random() no se manda a crear cada vez que se registra un script (esto tenía un costo alto) -Se corrigieron unos errores en los nombres de funciones -Las clases que ya heredan de Clspaginas, se les quita el this a RegistraScript y a Alert puesto que era innecesario (y además al haberlos vuelto métodos estáticos, NO pueden llamarse de un this)
1339 lines
50 KiB
C#
1339 lines
50 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;
|
|
using System.Text;
|
|
using Microsoft.Reporting.WebForms;
|
|
|
|
public partial class Empaque : ClsPaginas
|
|
{
|
|
|
|
#region Propiedades
|
|
|
|
private int CveProduccion
|
|
{
|
|
get { return (ViewState["CveProduccion"] == null) ? 0 : Convert.ToInt32(ViewState["CveProduccion"]); }
|
|
set { ViewState["CveProduccion"] = value; }
|
|
}
|
|
private int Index
|
|
{
|
|
get { return (ViewState["Index"] == null) ? 0 : Convert.ToInt32(ViewState["Index"]); }
|
|
set { ViewState["Index"] = value; }
|
|
}
|
|
private String Modalidad
|
|
{
|
|
get { return (ViewState["Modalidad"] == null) ? "" : (String)ViewState["Modalidad"]; }
|
|
set { ViewState["Modalidad"] = value; }
|
|
}
|
|
private String Folio
|
|
{
|
|
get { return (ViewState["Folio"] == null) ? "" : (String)ViewState["Folio"]; }
|
|
set { ViewState["Folio"] = value; }
|
|
}
|
|
private DataTable DtCorte
|
|
{
|
|
get { return DtCorte = (DataTable)ViewState["DtCorte"]; }
|
|
set { ViewState["DtCorte"] = value; }
|
|
}
|
|
private DataTable DtResultado
|
|
{
|
|
get { return DtResultado = (DataTable)ViewState["DtResultado"]; }
|
|
set { ViewState["DtResultado"] = value; }
|
|
}
|
|
private int CveMovimiento
|
|
{
|
|
get { return (ViewState["CveMovimiento"] == null) ? 0 : Convert.ToInt32(ViewState["CveMovimiento"]); }
|
|
set { ViewState["CveMovimiento"] = value; }
|
|
}
|
|
|
|
#endregion
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
if (!IsPostBack)
|
|
{
|
|
CveProduccion = Request["CveProduccion"] == null ? 0 : Request["CveProduccion"].ToString().ToEntero();
|
|
CreaDtCort();
|
|
CreaDtResultado();
|
|
CargaHuerta();
|
|
CargaPS();
|
|
CargaTipoEmpaque();
|
|
CargaTipoProducto();
|
|
CargaTamaño();
|
|
CargaTipoCaja();
|
|
CargaCalidad();
|
|
CargaAlmacen();
|
|
CargaProduccion();
|
|
}
|
|
}
|
|
|
|
#region Cargas
|
|
protected void CargaProduccion()
|
|
{
|
|
if (CveProduccion > 0)
|
|
{
|
|
ClsCGame ObjProd = new ClsCGame();
|
|
if (ObjProd.GetProduccion(UsuarioActual.CveEmpresa, CveProduccion: CveProduccion))
|
|
{
|
|
if (ObjProd.DtResultados.Rows.Count > 0)
|
|
{
|
|
DdlHuerta.SelectedValueExist(ObjProd.DtResultados.Rows[0]["CveHuerta"]);
|
|
DdlHuertaIndexChange();
|
|
lblFolio.Text = "EMP" + ObjProd.DtResultados.Rows[0]["Folio"];
|
|
Folio = ObjProd.DtResultados.Rows[0]["Folio"].ToString();
|
|
TxtFecha.Text = ObjProd.DtResultados.Rows[0]["Fecha"].ToString();
|
|
TxtFechaRegistro.Text = ObjProd.DtResultados.Rows[0]["Fecha"].ToDate().ToShortDateString();
|
|
lblNombreUsuario.Text = ObjProd.DtResultados.Rows[0]["Nombre"].ToString();
|
|
TxtObservacion.Text = ObjProd.DtResultados.Rows[0]["Observaciones"].ToString();
|
|
TxtMerma.Text = ObjProd.DtResultados.Rows[0]["Merma"].ToString().FormatoNumero(4);
|
|
CveMovimiento = ObjProd.DtResultados.Rows[0]["CveMovimiento"].ToEntero();
|
|
if (CveMovimiento > 0) { HplIrMovimiento.Visible = true; HplIrMovimiento.NavigateUrl = String.Format("/Inventarios/EntradasSalidas.aspx?CveMovimiento={0}", CveMovimiento); }
|
|
if (ObjProd.GetProduccionDetalle(CveProduccion)) { DtCorte = ObjProd.DtResultados; GVCorte.DataSource = ObjProd.DtResultados; }
|
|
if (ObjProd.GetProduccionResultado(CveProduccion, Opcion: 1)) { DtResultado = ObjProd.DtResultados; CreaColumnasTotales(); GvResultado.DataSource = DtResultado; }
|
|
TxtFecha.Enabled = false;
|
|
DdlHuerta.Enabled = false;
|
|
LnlEliminarProduccion.Visible = true;
|
|
LnkPdf.Visible = true;
|
|
ObjProd.Dispose();
|
|
GvResultado.DataBind();
|
|
GVCorte.DataBind();
|
|
UpDatosProduccion.Update();
|
|
UpDatosRegistro.Update();
|
|
UpCorte.Update();
|
|
UpResultado.Update();
|
|
UpAcciones.Update();
|
|
foreach (GridViewRow Gvr in GVCorte.Rows) { Gvr.FCCheckBox("ChkCorte").Checked = true; Gvr.FCCheckBox("ChkCorte").Enabled = false; }
|
|
CalculaTotales();
|
|
}
|
|
else
|
|
{
|
|
Alert("No se encontro el empaque solicitado", TipoMensaje.MsgAdvertencia);
|
|
LimpiarPagina();
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
LimpiarPagina();
|
|
}
|
|
}
|
|
|
|
protected void CargaAlmacen()
|
|
{
|
|
DdlAlmacen.DataSource = get_GlobalDTAlmacenUsuarios(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1).FiltraParametros("CveTipoAlmacen NOT IN (9,11)");
|
|
DdlAlmacen.Items.Insert(0, new ListItem("Seleccione", "-1"));
|
|
DdlAlmacen.DataBind();
|
|
}
|
|
protected void CargaHuerta()
|
|
{
|
|
ClsCGame ObjCort = new ClsCGame();
|
|
if (ObjCort.GetHuerta(UsuarioActual.CveEmpresa))
|
|
{
|
|
DdlHuerta.DataSource = ObjCort.DtResultados;
|
|
DdlHuerta.Items.Insert(0, new ListItem("Seleccione", "-1"));
|
|
|
|
}
|
|
ObjCort.Dispose();
|
|
UpDatosProduccion.Update();
|
|
DdlHuerta.DataBind();
|
|
}
|
|
protected void CargaPS()
|
|
{
|
|
ClsCGame ObjCort = new ClsCGame();
|
|
if (ObjCort.GetPS(UsuarioActual.CveEmpresa))
|
|
{
|
|
DdlPS.DataSource = ObjCort.DtResultados;
|
|
DdlPS.Items.Insert(0, new ListItem("Seleccione", "-1"));
|
|
|
|
}
|
|
ObjCort.Dispose();
|
|
UpModalAdd.Update();
|
|
DdlPS.DataBind();
|
|
}
|
|
|
|
protected void CargaTipoProducto()
|
|
{
|
|
ClsCGame ObjCGame = new ClsCGame();
|
|
if (ObjCGame.GetTipoProducto(UsuarioActual.CveEmpresa))
|
|
{
|
|
DdlTipoProducto.DataSource = ObjCGame.DtResultados;
|
|
DdlTipoProducto.Items.Insert(0, new ListItem("Seleccione", "-1"));
|
|
|
|
}
|
|
ObjCGame.Dispose();
|
|
UpModalAdd.Update();
|
|
DdlTipoProducto.DataBind();
|
|
}
|
|
|
|
|
|
protected void CargaTipoMaduracion(Int32 CvePS)
|
|
{
|
|
DdlTipoMaduracion.Items.Clear();
|
|
DdlTipoMaduracion.Items.Insert(0, new ListItem("Seleccione", "-1"));
|
|
if (CvePS > 0)
|
|
{
|
|
ClsCGame ObjCGame = new ClsCGame();
|
|
if (ObjCGame.GetTipoMaduracion(CvePS, -1, -1, UsuarioActual.CveEmpresa))
|
|
{
|
|
DdlTipoMaduracion.DataSource = ObjCGame.DtResultados;
|
|
}
|
|
ObjCGame.Dispose();
|
|
}
|
|
DdlTipoMaduracion.DataBind();
|
|
UpModalAdd.Update();
|
|
}
|
|
|
|
protected void CargaTipoEmpaque()
|
|
{
|
|
ClsCGame ObjCGame = new ClsCGame();
|
|
if (ObjCGame.GetTipoEmpaque(-1, -1, UsuarioActual.CveEmpresa))
|
|
{
|
|
DdlTipoEmpaque.DataSource = ObjCGame.DtResultados;
|
|
DdlTipoEmpaque.Items.Insert(0, new ListItem("Seleccione", "-1"));
|
|
DdlTipoEmpaque.DataBind();
|
|
}
|
|
ObjCGame.Dispose();
|
|
UpModalAdd.Update();
|
|
}
|
|
|
|
protected void CargaTamaño()
|
|
{
|
|
ClsCGame ObjTam = new ClsCGame();
|
|
if (ObjTam.GetTamaños(UsuarioActual.CveEmpresa))
|
|
{
|
|
DdlTamaño.DataSource = ObjTam.DtResultados;
|
|
DdlTamaño.Items.Insert(0, new ListItem("Seleccione", "-1"));
|
|
|
|
}
|
|
ObjTam.Dispose();
|
|
UpModalAdd.Update();
|
|
DdlTamaño.DataBind();
|
|
}
|
|
|
|
protected void CargaTipoCaja()
|
|
{
|
|
ClsCGame ObjTipo = new ClsCGame();
|
|
if (ObjTipo.GetTipoCaja(UsuarioActual.CveEmpresa))
|
|
{
|
|
DdlTipoCaja.DataSource = ObjTipo.DtResultados;
|
|
DdlTipoCaja.Items.Insert(0, new ListItem("Seleccione", "-1"));
|
|
|
|
}
|
|
ObjTipo.Dispose();
|
|
UpModalAdd.Update();
|
|
DdlTipoCaja.DataBind();
|
|
}
|
|
protected void CargaCalidad()
|
|
{
|
|
ClsCGame ObjCal = new ClsCGame();
|
|
if (ObjCal.GetCalidad(UsuarioActual.CveEmpresa))
|
|
{
|
|
DdlCalidad.DataSource = ObjCal.DtResultados;
|
|
DdlCalidad.Items.Insert(0, new ListItem("Seleccione", "-1"));
|
|
|
|
}
|
|
ObjCal.Dispose();
|
|
UpModalAdd.Update();
|
|
DdlCalidad.DataBind();
|
|
}
|
|
|
|
protected void CargaFolio()
|
|
{
|
|
ClsGralFolios ObjFol = new ClsGralFolios();
|
|
if (ObjFol.GetFolios("EMP", UsuarioActual.CveEmpresa))
|
|
{
|
|
if (ObjFol.DtResultados.Rows.Count > 0)
|
|
{
|
|
lblFolio.Text = "EMP" + ObjFol.DtResultados.Rows[0]["FActual"].ToString();
|
|
Folio = ObjFol.DtResultados.Rows[0]["FActual"].ToString();
|
|
}
|
|
else
|
|
{
|
|
Alert("Necesita registrar un folio de produccion", ModExtensiones.TipoMensaje.MsgAdvertencia);
|
|
BtnGuardar.Enabled = false;
|
|
}
|
|
}
|
|
ObjFol.Dispose();
|
|
UpDatosProduccion.Update();
|
|
}
|
|
|
|
private void CargaExistencias()
|
|
{
|
|
if (DdlAlmacen.SelectedValue.ToEntero() > 0)
|
|
{
|
|
ClsInventarios ObjInv = new ClsInventarios();
|
|
if (ObjInv.GetExistenciasPSEmpaque(-1, -1, UsuarioActual.CveEmpresa, DdlAlmacen.SelectedValue.ToEntero()))
|
|
{
|
|
GvPS.DataSource = ObjInv.DtResultados.FiltraParametros("Existencia > 0");
|
|
}
|
|
ObjInv.Dispose();
|
|
GvPS.DataBind();
|
|
}
|
|
else
|
|
{
|
|
GvPS.DataSource = null;
|
|
GvPS.DataBind();
|
|
}
|
|
UpSalida.Update();
|
|
}
|
|
|
|
private void CalculaTotales()
|
|
{
|
|
if (DtResultado.Rows.Count > 0)
|
|
{
|
|
Double TotalPeso = 0, TotalPesoPrimera = 0, TotalPesoSegunda = 0,TotalPesoJugo=0 ,TotalPesoEntradas = 0, TotalPesoEnPiso = 0;
|
|
if (DtResultado.Rows[0]["TipoColumna"].ToEntero() == 4)
|
|
{
|
|
TotalPeso = DtResultado.Rows[0]["Peso"].ToString().ToDouble();
|
|
}
|
|
foreach (DataRow Dr in DtResultado.Rows)
|
|
{
|
|
if (Dr["TipoColumna"].ToEntero() == 1)
|
|
{
|
|
TotalPesoPrimera = TotalPesoPrimera + Dr["Peso"].ToString().ToDouble();
|
|
}
|
|
else if (Dr["TipoColumna"].ToEntero() == 2)
|
|
{
|
|
TotalPesoSegunda = TotalPesoSegunda + Dr["Peso"].ToString().ToDouble();
|
|
}
|
|
else if (Dr["TipoColumna"].ToEntero() == 3)
|
|
{
|
|
TotalPesoJugo = TotalPesoJugo + Dr["Peso"].ToString().ToDouble();
|
|
}
|
|
|
|
}
|
|
foreach (GridViewRow Gvr in GVCorte.Rows)
|
|
{
|
|
if (Gvr.FCCheckBox("ChkCorte").Checked)
|
|
{
|
|
TotalPesoEntradas = TotalPesoEntradas + Gvr.DataKey("Peso").ToString().ToDouble();
|
|
}
|
|
}
|
|
TotalPesoEnPiso = TotalPesoEntradas - TotalPeso - TxtMerma.Text.ToDouble();
|
|
LblPesoTotal.Text = TotalPeso.FormatoNumero(4);
|
|
LblPrimera.Text = TotalPesoPrimera.FormatoNumero(4);
|
|
LblPorcentajePrimera.Text = ((TotalPesoPrimera * 100) / (TotalPeso + TxtMerma.Text.ToDouble())).FormatoNumero();
|
|
LblSegunda.Text = TotalPesoSegunda.FormatoNumero(4);
|
|
LblPorcentajeSegunda.Text = ((TotalPesoSegunda * 100) / (TotalPeso + TxtMerma.Text.ToDouble())).FormatoNumero();
|
|
LblJugo.Text = TotalPesoJugo.FormatoNumero(4);
|
|
LblPorcentajeJugo.Text = ((TotalPesoJugo * 100) / (TotalPeso + TxtMerma.Text.ToDouble())).FormatoNumero();
|
|
LblMerma.Text = TxtMerma.Text.FormatoNumero(4);
|
|
LblPorcentajeMerma.Text = ((TxtMerma.Text.ToDouble() * 100) / (TotalPeso + TxtMerma.Text.ToDouble())).FormatoNumero();
|
|
LblPiso.Text = TotalPesoEnPiso.FormatoNumero(4);
|
|
LblPorcentajeEnPiso.Text = (TotalPesoEnPiso * 100 / TotalPesoEntradas).FormatoNumero();
|
|
UpIndicadores.Update();
|
|
}
|
|
CargaGvResultado();
|
|
}
|
|
|
|
private void CargaGvResultado()
|
|
{
|
|
GvResultado.DataSource = DtResultado;
|
|
GvResultado.DataBind();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Crea Datatables
|
|
protected void CreaDtCort()
|
|
{
|
|
DtCorte = new DataTable();
|
|
DtCorte.Columns.Add("CveCorte");
|
|
DtCorte.Columns.Add("CveProduccionDetalle");
|
|
}
|
|
protected void CreaDtResultado()
|
|
{
|
|
DtResultado = new DataTable();
|
|
DtResultado.Columns.Add("CveProduccionResultado");
|
|
DtResultado.Columns.Add("CveOrdenProduccionDetalle");
|
|
DtResultado.Columns.Add("Cantidad");
|
|
DtResultado.Columns.Add("TipoEmpaque");
|
|
DtResultado.Columns.Add("CvePS");
|
|
DtResultado.Columns.Add("PS");
|
|
DtResultado.Columns.Add("CveTamaño");
|
|
DtResultado.Columns.Add("Tamaño");
|
|
DtResultado.Columns.Add("CveTipoEtiqueta");
|
|
DtResultado.Columns.Add("CveCalidad");
|
|
DtResultado.Columns.Add("Calidad");
|
|
DtResultado.Columns.Add("CveTipoCaja");
|
|
DtResultado.Columns.Add("TipoCaja");
|
|
DtResultado.Columns.Add("Peso");
|
|
DtResultado.Columns.Add("CveTipoEmpaque");
|
|
DtResultado.Columns.Add("CveTipoMaduracion");
|
|
DtResultado.Columns.Add("CveTipoProducto");
|
|
DtResultado.Columns.Add("TipoMaduracion");
|
|
DtResultado.Columns.Add("TipoProducto");
|
|
DtResultado.Columns.Add("Tipo");
|
|
DtResultado.Columns.Add("TipoColumna");
|
|
DtResultado.Columns.Add("Gpo");
|
|
DtResultado.Columns.Add("PesoXCaja");
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
#region Acciones DataTable
|
|
protected void AddDtResultado(int CveOrdenProduccionDetalle, double Cantidad, int CvePS, int CveTamaño, bool CveTipoEtiqueta, int CveCalidad, int CveTipoCaja, Double Peso, String PS, String Tamaño, String Calidad, String TipoCaja, String TipoEmpaque, int CveTipoEmpaque, int CveTipoMaduracion, int CveTipoProducto, String TipoMaduracion, String TipoProducto)
|
|
{
|
|
DataRow Row = null;
|
|
Row = DtResultado.NewRow();
|
|
Row["CveProduccionResultado"] = -1;
|
|
Row["CveOrdenProduccionDetalle"] = CveOrdenProduccionDetalle;
|
|
Row["Cantidad"] = Cantidad;
|
|
Row["CvePS"] = CvePS;
|
|
Row["CveTamaño"] = CveTamaño;
|
|
Row["CveTipoEtiqueta"] = CveTipoEtiqueta;
|
|
Row["CveCalidad"] = CveCalidad;
|
|
Row["CveTipoCaja"] = CveTipoCaja;
|
|
Row["Peso"] = Peso;
|
|
Row["PS"] = PS;
|
|
Row["Tamaño"] = Tamaño;
|
|
Row["Calidad"] = Calidad;
|
|
Row["TipoCaja"] = TipoCaja;
|
|
Row["TipoEmpaque"] = TipoEmpaque;
|
|
Row["CveTipoMaduracion"] = CveTipoMaduracion;
|
|
Row["CveTipoProducto"] = CveTipoProducto;
|
|
Row["CveTipoEmpaque"] = CveTipoEmpaque;
|
|
Row["TipoMaduracion"] = TipoMaduracion;
|
|
Row["TipoProducto"] = TipoProducto;
|
|
Row["PesoXCaja"] = Math.Round(Peso / Cantidad,4);
|
|
ClsCGame ObjCGame = new ClsCGame();
|
|
if (ObjCGame.GetTipoEmpaque(CveTipoEmpaque, -1, UsuarioActual.CveEmpresa))
|
|
{
|
|
if (ObjCGame.DtResultados.Rows.Count > 0)
|
|
{
|
|
Row["Tipo"] = ObjCGame.DtResultados.Rows[0]["Tipo"];
|
|
}
|
|
}
|
|
ObjCGame.Dispose();
|
|
int Pocision = CreaColumnaSeparadora(Row["Tipo"].ToEntero(), Row["Cantidad"].ToString().ToDouble(), Row["Peso"].ToString().ToDouble(), "A");
|
|
DtResultado.Rows.InsertAt(Row, Pocision);
|
|
DtResultado.AcceptChanges();
|
|
CreaColumnasTotales();
|
|
}
|
|
protected void UpdateDtResultado(double Cantidad, int CvePS, int CveTamaño, bool CveTipoEtiqueta, int CveCalidad, int CveTipoCaja, Double Peso, String PS, String Tamaño, String Calidad, String TipoCaja, String TipoEmpaque, int CveTipoEmpaque, int CveTipoMaduracion, int CveTipoProducto, String TipoMaduracion, String TipoProducto)
|
|
{
|
|
int Tip = 0,TipoCalidad=0;
|
|
DtResultado.Rows[Index]["Cantidad"] = Cantidad;
|
|
DtResultado.Rows[Index]["CvePS"] = CvePS;
|
|
DtResultado.Rows[Index]["CveTamaño"] = CveTamaño;
|
|
DtResultado.Rows[Index]["CveTipoEtiqueta"] = CveTipoEtiqueta;
|
|
DtResultado.Rows[Index]["CveCalidad"] = CveCalidad;
|
|
DtResultado.Rows[Index]["CveTipoCaja"] = CveTipoCaja;
|
|
DtResultado.Rows[Index]["CveTipoProducto"] = CveTipoProducto;
|
|
DtResultado.Rows[Index]["Peso"] = Peso;
|
|
DtResultado.Rows[Index]["PS"] = PS;
|
|
DtResultado.Rows[Index]["Tamaño"] = Tamaño;
|
|
DtResultado.Rows[Index]["Calidad"] = Calidad;
|
|
DtResultado.Rows[Index]["TipoCaja"] = TipoCaja;
|
|
DtResultado.Rows[Index]["TipoEmpaque"] = TipoEmpaque;
|
|
DtResultado.Rows[Index]["CveTipoEmpaque"] = CveTipoEmpaque;
|
|
DtResultado.Rows[Index]["CveTipoMaduracion"] = CveTipoMaduracion;
|
|
DtResultado.Rows[Index]["TipoMaduracion"] = TipoMaduracion;
|
|
DtResultado.Rows[Index]["TipoProducto"] = TipoProducto;
|
|
DtResultado.Rows[Index]["PesoXCaja"] = Math.Round(Peso / Cantidad, 4);
|
|
ClsCGame ObjCGame = new ClsCGame();
|
|
if (ObjCGame.GetTipoEmpaque(CveTipoEmpaque, -1, UsuarioActual.CveEmpresa))
|
|
{
|
|
if (ObjCGame.DtResultados.Rows.Count > 0)
|
|
{
|
|
Tip = ObjCGame.DtResultados.Rows[0]["Tipo"].ToEntero();
|
|
}
|
|
}
|
|
if (ObjCGame.GetTipoCalidad(CveTipoCaja,CveCalidad))
|
|
{
|
|
if (ObjCGame.DtResultados.Rows.Count > 0)
|
|
{
|
|
TipoCalidad = ObjCGame.DtResultados.Rows[0]["Tipo"].ToEntero();
|
|
}
|
|
}
|
|
if (Tip == 3) { TipoCalidad = 3; }
|
|
|
|
DtResultado.Rows[Index]["Tipo"] = TipoCalidad;
|
|
|
|
ObjCGame.Dispose();
|
|
DataRow Row = null;
|
|
Row = DtResultado.NewRow();
|
|
Row.ItemArray = DtResultado.Rows[Index].ItemArray;
|
|
int Pocision = CreaColumnaSeparadora(DtResultado.Rows[Index]["Tipo"].ToEntero(), DtResultado.Rows[Index]["Cantidad"].ToString().ToDouble(), DtResultado.Rows[Index]["Peso"].ToString().ToDouble(), "U");
|
|
DtResultado.Rows[Index].Delete();
|
|
DtResultado.Rows.InsertAt(Row, Pocision);
|
|
DtResultado.AcceptChanges();
|
|
int x = CreaColumnaSeparadora(3, 0, 0, "U");
|
|
int y = CreaColumnaSeparadora(2, 0, 0, "U");
|
|
int z = CreaColumnaSeparadora(1, 0, 0, "U");
|
|
CreaColumnasTotales();
|
|
EliminaColumnas();
|
|
}
|
|
|
|
private void CreaColumnasTotales()
|
|
{
|
|
Double Peso = 0, Cantidad = 0;
|
|
DataTable Dt = DtResultado.FiltraParametros("CvePS > 0 AND TipoColumna IS NULL");
|
|
foreach (DataRow Dr in Dt.Rows)
|
|
{
|
|
Peso = Peso + Dr["Peso"].ToString().ToDouble();
|
|
Cantidad = Cantidad + Dr["Cantidad"].ToString().ToDouble();
|
|
}
|
|
if (DtResultado.Rows.Count > 0)
|
|
{
|
|
if (DtResultado.Rows[0]["TipoColumna"].ToEntero() == 4)
|
|
{
|
|
DtResultado.Rows[0]["Peso"] = Peso;
|
|
DtResultado.Rows[0]["Cantidad"] = Cantidad;
|
|
DtResultado.Rows[0]["PesoXCaja"] = Math.Round(Peso / Cantidad,4);
|
|
}
|
|
else
|
|
{
|
|
DataRow Row = null;
|
|
DtResultado.AcceptChanges();
|
|
Row = DtResultado.NewRow();
|
|
Row["Cantidad"] = Cantidad;
|
|
Row["Peso"] = Peso;
|
|
Row["TipoColumna"] = 4;
|
|
Row["PesoXCaja"] = Math.Round(Peso / Cantidad,4);
|
|
DtResultado.Rows.InsertAt(Row, 0);
|
|
DtResultado.AcceptChanges();
|
|
}
|
|
}
|
|
}
|
|
|
|
private int CreaColumnaSeparadora(int TipoEmpaque, double CantidadDr, double PesoDr, String Opcion)
|
|
{
|
|
|
|
int Pocision = 0;
|
|
Double Peso = 0, Cantidad = 0;
|
|
DataTable Dt = DtResultado.FiltraParametros(String.Format("CvePS > 0 AND Tipo={0}", TipoEmpaque));
|
|
foreach (DataRow Dr in Dt.Rows)
|
|
{
|
|
Peso = Peso + Dr["Peso"].ToString().ToDouble();
|
|
Cantidad = Cantidad + Dr["Cantidad"].ToString().ToDouble();
|
|
}
|
|
if (DtResultado.FiltraParametros(String.Format("TipoColumna={0}", TipoEmpaque)).Rows.Count > 0)
|
|
{
|
|
bool Encontro = false;
|
|
int cont = 0;
|
|
foreach (DataRow Dr in DtResultado.Rows)
|
|
{
|
|
if (Dr["TipoColumna"].ToEntero() == TipoEmpaque)
|
|
{
|
|
if (Opcion == "U" || Opcion == "A")
|
|
{
|
|
Dr["Peso"] = Peso + PesoDr;
|
|
Dr["Cantidad"] = Cantidad + CantidadDr;
|
|
Dr["PesoXCaja"] = Math.Round(Dr["Peso"].ToString().ToDouble() / Dr["Cantidad"].ToString().ToDouble(),4);
|
|
}
|
|
else if (Opcion == "R")
|
|
{
|
|
Dr["Peso"] = Peso - PesoDr;
|
|
Dr["Cantidad"] = Cantidad - CantidadDr;
|
|
Dr["PesoXCaja"] = Math.Round(Dr["Peso"].ToString().ToDouble() / Dr["Cantidad"].ToString().ToDouble(),4);
|
|
}
|
|
Encontro = true;
|
|
}
|
|
if (Encontro)
|
|
{
|
|
Pocision = cont + 1;
|
|
if (Dr["Tipo"].ToEntero() != TipoEmpaque)
|
|
{
|
|
Pocision = cont;
|
|
break;
|
|
}
|
|
}
|
|
cont = cont + 1;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
DataRow Row = null;
|
|
Row = DtResultado.NewRow();
|
|
Row["Cantidad"] = CantidadDr;
|
|
Row["Peso"] = PesoDr;
|
|
Row["PesoXCaja"] = Math.Round(PesoDr / CantidadDr,4);
|
|
Row["TipoColumna"] = TipoEmpaque;
|
|
Row["Tipo"] = TipoEmpaque;
|
|
if (TipoEmpaque == 1) { Row["Gpo"] = "Primera"; } else if (TipoEmpaque == 2) { Row["Gpo"] = "Segunda"; } else { Row["Gpo"] = "Jugo"; }
|
|
DtResultado.Rows.InsertAt(Row, DtResultado.Rows.Count);
|
|
DtResultado.AcceptChanges();
|
|
Pocision = DtResultado.Rows.Count;
|
|
}
|
|
return Pocision;
|
|
}
|
|
|
|
private void EliminaColumnas()
|
|
{
|
|
bool SeBorra = false;
|
|
int Pocision = 0, PocisionBorrar = 0;
|
|
SeBorra = false;
|
|
Pocision = 0;
|
|
PocisionBorrar = 0;
|
|
foreach (DataRow Dr in DtResultado.Rows)
|
|
{
|
|
|
|
if (Dr["TipoColumna"].ToEntero() == 3)
|
|
{
|
|
PocisionBorrar = Pocision;
|
|
if (Pocision == DtResultado.Rows.Count - 1)
|
|
{
|
|
SeBorra = true;
|
|
break;
|
|
}
|
|
}
|
|
else if (PocisionBorrar > 0)
|
|
{
|
|
if (DtResultado.Rows[Pocision]["Tipo"].ToEntero() == 3 && DtResultado.Rows[Pocision]["CvePS"].ToEntero() > 0)
|
|
{
|
|
SeBorra = false;
|
|
break;
|
|
}
|
|
else if ((DtResultado.Rows[Pocision]["Tipo"].ToEntero() != 3) || (DtResultado.Rows[Pocision]["Tipo"].ToEntero() == 3 && DtResultado.Rows[Pocision]["CvePS"].ToEntero() < 1))
|
|
{
|
|
SeBorra = true;
|
|
}
|
|
|
|
}
|
|
Pocision = Pocision + 1;
|
|
}
|
|
|
|
if (SeBorra)
|
|
{
|
|
DtResultado.Rows[PocisionBorrar].Delete();
|
|
DtResultado.AcceptChanges();
|
|
}
|
|
|
|
SeBorra = false;
|
|
Pocision = 0;
|
|
PocisionBorrar = 0;
|
|
foreach (DataRow Dr in DtResultado.Rows)
|
|
{
|
|
|
|
if (Dr["TipoColumna"].ToEntero() == 2)
|
|
{
|
|
PocisionBorrar = Pocision;
|
|
if (Pocision == DtResultado.Rows.Count - 1)
|
|
{
|
|
SeBorra = true;
|
|
break;
|
|
}
|
|
}
|
|
else if (PocisionBorrar > 0)
|
|
{
|
|
if (DtResultado.Rows[Pocision]["Tipo"].ToEntero() == 2 && DtResultado.Rows[Pocision]["CvePS"].ToEntero() > 0)
|
|
{
|
|
SeBorra = false;
|
|
break;
|
|
}
|
|
else if ((DtResultado.Rows[Pocision]["Tipo"].ToEntero() != 2) || (DtResultado.Rows[Pocision]["Tipo"].ToEntero() == 2 && DtResultado.Rows[Pocision]["CvePS"].ToEntero() < 1))
|
|
{
|
|
SeBorra = true;
|
|
}
|
|
|
|
}
|
|
Pocision = Pocision + 1;
|
|
}
|
|
|
|
if (SeBorra)
|
|
{
|
|
DtResultado.Rows[PocisionBorrar].Delete();
|
|
DtResultado.AcceptChanges();
|
|
}
|
|
|
|
SeBorra = false;
|
|
Pocision = 0;
|
|
PocisionBorrar = 0;
|
|
foreach (DataRow Dr in DtResultado.Rows)
|
|
{
|
|
|
|
if (Dr["TipoColumna"].ToEntero() == 1)
|
|
{
|
|
PocisionBorrar = Pocision;
|
|
if (Pocision == DtResultado.Rows.Count - 1)
|
|
{
|
|
SeBorra = true;
|
|
break;
|
|
}
|
|
}
|
|
else if (PocisionBorrar > 0)
|
|
{
|
|
if (DtResultado.Rows[Pocision]["Tipo"].ToEntero() == 1 && DtResultado.Rows[Pocision]["CvePS"].ToEntero() > 0)
|
|
{
|
|
SeBorra = false;
|
|
break;
|
|
}
|
|
else if ((DtResultado.Rows[Pocision]["Tipo"].ToEntero() != 1) || (DtResultado.Rows[Pocision]["Tipo"].ToEntero() == 1 && DtResultado.Rows[Pocision]["CvePS"].ToEntero() < 1))
|
|
{
|
|
SeBorra = true;
|
|
}
|
|
|
|
}
|
|
Pocision = Pocision + 1;
|
|
}
|
|
|
|
if (SeBorra)
|
|
{
|
|
DtResultado.Rows[PocisionBorrar].Delete();
|
|
DtResultado.AcceptChanges();
|
|
}
|
|
|
|
int ConceptosEliminados = 0;
|
|
foreach (DataRow Dr in DtResultado.Rows)
|
|
{
|
|
if (Dr["TipoColumna"].ToString() == "" && Dr["CvePS"].ToEntero() < 1)
|
|
{
|
|
ConceptosEliminados = ConceptosEliminados + 1;
|
|
}
|
|
}
|
|
if (DtResultado.Rows.Count - ConceptosEliminados < 2)
|
|
{
|
|
DtResultado.Rows[0].Delete();
|
|
DtResultado.AcceptChanges();
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Limpia
|
|
protected void LimpiaModal()
|
|
{
|
|
DdlPS.SelectedIndex = 0;
|
|
DdlTipoEmpaque.SelectedIndex = 0;
|
|
CargaTipoMaduracion(DdlPS.SelectedValue.ToEntero());
|
|
DdlTipoProducto.SelectedIndex = 0;
|
|
TxtFecha.Text = DateTime.Now.ToString();
|
|
TxtPeso.Text = "";
|
|
TxtCantidad.Text = "";
|
|
DdlCalidad.SelectedIndex = 0;
|
|
ChkTipoEtiqueta.Checked = false;
|
|
DdlTamaño.SelectedIndex = 0;
|
|
DdlTipoCaja.SelectedIndex = 0;
|
|
}
|
|
|
|
protected void LimpiarPagina()
|
|
{
|
|
DdlHuerta.SelectedValue = "-1";
|
|
lblNombreUsuario.Text = UsuarioActual.Nombre;
|
|
TxtFechaRegistro.Text = DateTime.Now.ToShortDateString();
|
|
TxtFecha.Text = DateTime.Now.ToString();
|
|
CargaFolio();
|
|
LimpiarGvCorteShowHeader();
|
|
LimpiarGvResultadoShowHeader();
|
|
DtResultado.Clear();
|
|
DtCorte.Clear();
|
|
UpDatosProduccion.Update();
|
|
UpDatosRegistro.Update();
|
|
}
|
|
|
|
protected void LimpiarGvCorteShowHeader()
|
|
{
|
|
DataSet Dt = new DataSet();
|
|
Dt.Tables.Add("Datos");
|
|
Dt.Tables["Datos"].Columns.Add("");
|
|
GVCorte.DataSource = Dt.Tables["Datos"];
|
|
GVCorte.DataBind();
|
|
UpCorte.Update();
|
|
}
|
|
protected void LimpiarGvResultadoShowHeader()
|
|
{
|
|
DataSet Dt = new DataSet();
|
|
Dt.Tables.Add("Datos");
|
|
Dt.Tables["Datos"].Columns.Add("");
|
|
GvResultado.DataSource = Dt.Tables["Datos"];
|
|
GvResultado.DataBind();
|
|
UpResultado.Update();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Validaciones
|
|
|
|
public bool Valida()
|
|
{
|
|
|
|
if (DdlPS.SelectedValue == "-1")
|
|
{
|
|
Alert("Tiene que seleccionar un producto o servicio", ModExtensiones.TipoMensaje.MsgAdvertencia);
|
|
return false;
|
|
}
|
|
if (DdlTamaño.SelectedValue == "-1")
|
|
{
|
|
Alert("Tiene que seleccionar un tamaño", ModExtensiones.TipoMensaje.MsgAdvertencia);
|
|
return false;
|
|
}
|
|
if (DdlTipoEmpaque.SelectedValue == "-1")
|
|
{
|
|
Alert("Tiene que seleccionar un tipo de empaque", ModExtensiones.TipoMensaje.MsgAdvertencia);
|
|
return false;
|
|
}
|
|
if (DdlTipoMaduracion.SelectedValue == "-1")
|
|
{
|
|
Alert("Tiene que seleccionar un tipo de maduracion", ModExtensiones.TipoMensaje.MsgAdvertencia);
|
|
return false;
|
|
}
|
|
if (DdlTipoProducto.SelectedValue == "-1")
|
|
{
|
|
Alert("Tiene que seleccionar un tipo de producto", ModExtensiones.TipoMensaje.MsgAdvertencia);
|
|
return false;
|
|
}
|
|
if (DdlCalidad.SelectedValue == "-1")
|
|
{
|
|
Alert("Tiene que seleccionar una calidad", ModExtensiones.TipoMensaje.MsgAdvertencia);
|
|
return false;
|
|
}
|
|
if (DdlTipoCaja.SelectedValue == "-1")
|
|
{
|
|
Alert("Tiene que seleccionar un tipo de caja", ModExtensiones.TipoMensaje.MsgAdvertencia);
|
|
return false;
|
|
}
|
|
|
|
|
|
return true;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Botones
|
|
|
|
protected void LnkEditar_Click(object sender, EventArgs e)
|
|
{
|
|
Modalidad = "U";
|
|
LimpiaModal();
|
|
GridViewRow gvRow = (GridViewRow)(((LinkButton)sender).NamingContainer);
|
|
Index = gvRow.RowIndex;
|
|
TxtCantidad.Text = gvRow.DataKey("Cantidad");
|
|
TxtPeso.Text = gvRow.DataKey("Peso");
|
|
DdlPS.SelectedValueExist(gvRow.DataKey("CvePS").ToEntero());
|
|
DdlTipoProducto.SelectedValueExist(gvRow.DataKey("CveTipoProducto").ToEntero());
|
|
CargaTipoMaduracion(DdlPS.SelectedValue.ToEntero());
|
|
DdlTipoMaduracion.SelectedValueExist(gvRow.DataKey("CveTipoMaduracion").ToEntero());
|
|
DdlTipoEmpaque.SelectedValueExist(gvRow.DataKey("CveTipoEmpaque").ToEntero());
|
|
DdlCalidad.SelectedValueExist(gvRow.DataKey("CveCalidad").ToEntero());
|
|
DdlTamaño.SelectedValueExist(gvRow.DataKey("CveTamaño").ToEntero());
|
|
DdlTipoCaja.SelectedValueExist(gvRow.DataKey("CveTipoCaja").ToEntero());
|
|
ChkTipoEtiqueta.Checked = Convert.ToBoolean((gvRow.DataKey("CveTipoEtiqueta")));
|
|
BtnOPADD.Text = "Actualizar";
|
|
CargaGvResultado();
|
|
UpModalAdd.Update();
|
|
UpResultado.Update();
|
|
RegistraScript("$('#DivResultado').modal();");
|
|
}
|
|
protected void LnkAgregarResultado_Click(object sender, EventArgs e)
|
|
{
|
|
Modalidad = "A";
|
|
RegistraScript("$('#DivResultado').modal();");
|
|
LimpiaModal();
|
|
BtnOPADD.Text = "Agregar";
|
|
CargaGvResultado();
|
|
UpModalAdd.Update();
|
|
UpResultado.Update();
|
|
}
|
|
protected void LnlEliminarProduccion_Click(object sender, EventArgs e)
|
|
{
|
|
if (CveProduccion > 0)
|
|
{
|
|
ClsCGame ObjCGame = new ClsCGame();
|
|
ObjCGame.IniciaTransacSQL();
|
|
var Error = false;
|
|
if (!ObjCGame.RemoveProduccionDetalle(-1, CveProduccion))
|
|
{
|
|
Error = true;
|
|
}
|
|
if (!ObjCGame.RemoveProduccionResultado(-1, CveProduccion))
|
|
{
|
|
Error = true;
|
|
}
|
|
if (!ObjCGame.RemoveProduccion(CveProduccion))
|
|
{
|
|
Error = true;
|
|
}
|
|
if (!Error)
|
|
{
|
|
ObjCGame.Commit();
|
|
Alert("La producción se elimino correctamente");
|
|
LimpiarPagina();
|
|
}
|
|
else
|
|
{
|
|
ObjCGame.RollBack();
|
|
}
|
|
ObjCGame.Dispose();
|
|
}
|
|
}
|
|
|
|
protected void LnkEliminar_Click(object sender, EventArgs e)
|
|
{
|
|
GridViewRow gvRow = (GridViewRow)(((LinkButton)sender).NamingContainer);
|
|
int Pocision = CreaColumnaSeparadora(DtResultado.Rows[gvRow.RowIndex]["Tipo"].ToEntero(), DtResultado.Rows[gvRow.RowIndex]["Cantidad"].ToString().ToDouble(), DtResultado.Rows[gvRow.RowIndex]["Peso"].ToString().ToDouble(), "R");
|
|
DtResultado.Rows[gvRow.RowIndex]["CvePS"] = -1;
|
|
DtResultado.AcceptChanges();
|
|
if (DtResultado.Rows[gvRow.RowIndex]["CveProduccionResultado"].ToEntero() == -1)
|
|
{
|
|
DtResultado.Rows[gvRow.RowIndex].Delete();
|
|
DtResultado.AcceptChanges();
|
|
}
|
|
CreaColumnasTotales();
|
|
EliminaColumnas();
|
|
CalculaTotales();
|
|
GvResultado.DataSource = DtResultado;
|
|
GvResultado.DataBind();
|
|
if (GvResultado.Rows.Count < 1)
|
|
{
|
|
LimpiarGvResultadoShowHeader();
|
|
}
|
|
UpResultado.Update();
|
|
}
|
|
|
|
protected void BtnOPADD_Click(object sender, EventArgs e)
|
|
{
|
|
if (Valida())
|
|
{
|
|
|
|
if (Modalidad == "A")
|
|
{
|
|
AddDtResultado(-1, TxtCantidad.Text.ToDouble(), DdlPS.SelectedValue.ToEntero(), DdlTamaño.SelectedValue.ToEntero(),
|
|
ChkTipoEtiqueta.Checked, DdlCalidad.SelectedValue.ToEntero(), DdlTipoCaja.SelectedValue.ToEntero(), TxtPeso.Text.ToDouble(),
|
|
DdlPS.SelectedItem.Text, DdlTamaño.SelectedItem.Text, DdlCalidad.SelectedItem.Text, DdlTipoCaja.SelectedItem.Text, DdlTipoEmpaque.SelectedItem.Text, DdlTipoEmpaque.SelectedValue.ToEntero(), DdlTipoMaduracion.SelectedValue.ToEntero(), DdlTipoProducto.SelectedValue.ToEntero(), DdlTipoMaduracion.SelectedItem.Text, DdlTipoProducto.SelectedItem.Text);
|
|
}
|
|
else if (Modalidad == "U")
|
|
{
|
|
UpdateDtResultado(TxtCantidad.Text.ToDouble(), DdlPS.SelectedValue.ToEntero(), DdlTamaño.SelectedValue.ToEntero(),
|
|
ChkTipoEtiqueta.Checked, DdlCalidad.SelectedValue.ToEntero(), DdlTipoCaja.SelectedValue.ToEntero(), TxtPeso.Text.ToDouble(),
|
|
DdlPS.SelectedItem.Text, DdlTamaño.SelectedItem.Text, DdlCalidad.SelectedItem.Text, DdlTipoCaja.SelectedItem.Text, DdlTipoEmpaque.SelectedItem.Text, DdlTipoEmpaque.SelectedValue.ToEntero(), DdlTipoMaduracion.SelectedValue.ToEntero(), DdlTipoProducto.SelectedValue.ToEntero(), DdlTipoMaduracion.SelectedItem.Text, DdlTipoProducto.SelectedItem.Text);
|
|
}
|
|
RegistraScript("$('#DivResultado').modal('hide');");
|
|
GvResultado.DataSource = DtResultado;
|
|
GvResultado.DataBind();
|
|
UpResultado.Update();
|
|
CalculaTotales();
|
|
}
|
|
}
|
|
|
|
protected void BtnGuardar_Click(object sender, EventArgs e)
|
|
{
|
|
if (DdlHuerta.SelectedValue == "-1")
|
|
{
|
|
Alert("Tiene que seleccionar una huerta", TipoMensaje.MsgAdvertencia);
|
|
return;
|
|
}
|
|
if (lblFolio.Text == "")
|
|
{
|
|
Alert("Tiene que tener un folio", TipoMensaje.MsgAdvertencia);
|
|
return;
|
|
}
|
|
int y = 0;
|
|
foreach (GridViewRow Gvr in GVCorte.Rows)
|
|
{
|
|
if (Gvr.FCCheckBox("ChkCorte").Checked == true)
|
|
{
|
|
y = 1;
|
|
}
|
|
}
|
|
if (y == 0)
|
|
{
|
|
Alert("Tiene que tener al menos un corte seleccionado", TipoMensaje.MsgAdvertencia);
|
|
return;
|
|
}
|
|
int q = 0;
|
|
foreach (GridViewRow Gvr in GvPS.Rows)
|
|
{
|
|
if (Gvr.FCTextBox("TxtCantidad").Text.ToDouble() > 0)
|
|
{
|
|
q = 1;
|
|
}
|
|
}
|
|
|
|
if (GvResultado.Rows.Count < 1)
|
|
{
|
|
Alert("Tiene que tener al menos un resultado agregado", TipoMensaje.MsgAdvertencia);
|
|
return;
|
|
}
|
|
|
|
|
|
bool Error = false;
|
|
int _CveProduccion = 0;
|
|
ClsCGame ObjProd = new ClsCGame();
|
|
ClsInventarios ObjInv = new ClsInventarios(ObjProd.IniciaTransacSQL());
|
|
var CveAlmacen = DdlAlmacen.SelectedValue.ToEntero();
|
|
var Concepto = 3;
|
|
var Fecha = DateTime.Now;
|
|
var CveCorte = 0;
|
|
StringBuilder MensajeExistencias = new StringBuilder();
|
|
var ExistenciaActual = 0.0;
|
|
var Existencia = 0.0;
|
|
if (q == 1)
|
|
{
|
|
if (DdlAlmacen.SelectedValue.ToEntero() == 1)
|
|
{
|
|
Alert("Tiene que seleccionar un almacen.", TipoMensaje.MsgAdvertencia);
|
|
ObjProd.RollBack();
|
|
ObjProd.Dispose();
|
|
ObjInv.Dispose();
|
|
return;
|
|
}
|
|
if (CveMovimiento < 1)
|
|
{
|
|
CveMovimiento = ObjInv.AddMovimiento(CveAlmacen, Concepto, 1, Fecha, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, -1, -1, -1);
|
|
}
|
|
if (CveMovimiento > 0)
|
|
{
|
|
foreach (GridViewRow Row in GvPS.Rows)
|
|
{
|
|
if (Row.FCTextBox("TxtCantidad").Text != "")
|
|
{
|
|
ExistenciaActual = Row.FCTextBox("TxtCantidad").Text.ToDouble();
|
|
Existencia = ObjInv.GetExistenciasPS(Row.DataKey("CvePS").ToEntero(), Row.DataKey("CveUnidadMedida").ToEntero(), UsuarioActual.CveEmpresa, CveAlmacen).ToString().ToDouble();
|
|
if (Existencia < ExistenciaActual)
|
|
{
|
|
Error = true;
|
|
MensajeExistencias.Append($"Producto: <b>{get_GlobalDTPS(UsuarioActual.CveEmpresa, CvePS: Row.DataKey("CvePS").ToString().ToEntero()).FiltroPrimeroValor("PSCodigo")}</b>.</br>");
|
|
}
|
|
else
|
|
{
|
|
if (!ObjInv.AddMovimientoDetalle(CveMovimiento, Row.FCTextBox("TxtCantidad").Text.ToDouble(), Row.DataKey("CveUnidadMedida").ToString().ToEntero(), Row.DataKey("CvePS").ToString().ToEntero(), 0, -1))
|
|
{
|
|
Alert("Ocurrió un error al guardar los detalles del movimiento de almacén", TipoMensaje.MsgError);
|
|
Error = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Alert("Ocurrió un error al guardar el movimiento de almacén", TipoMensaje.MsgError);
|
|
Error = true;
|
|
}
|
|
}
|
|
if (CveProduccion > 0)
|
|
{
|
|
if (ObjProd.UpdateProduccion(CveProduccion, Folio, DdlHuerta.SelectedValue.ToEntero(), TxtFecha.Text.ToDate(), UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveMovimiento, TxtMerma.Text.ToDouble(), TxtObservacion.Text) == false)
|
|
{
|
|
Error = true;
|
|
}
|
|
else
|
|
{
|
|
_CveProduccion = CveProduccion;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (ObjProd.AddProduccion(Folio, DdlHuerta.SelectedValue.ToEntero(), TxtFecha.Text.ToDate(), UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveMovimiento, TxtMerma.Text.ToDouble(), TxtObservacion.Text) == false)
|
|
{
|
|
Error = true;
|
|
}
|
|
else
|
|
{
|
|
_CveProduccion = ObjProd.CveProduccion;
|
|
}
|
|
}
|
|
if (Error == false)
|
|
{
|
|
foreach (GridViewRow Row in GVCorte.Rows)
|
|
{
|
|
if (Row.FCCheckBox("ChkCorte").Checked)
|
|
{
|
|
if (CveProduccion > 0)
|
|
{
|
|
if (CveCorte < 1)
|
|
{
|
|
CveCorte = Row.DataKey("CveCorte").ToEntero();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (!ObjProd.AddProduccionDetalle(_CveProduccion, Row.DataKey("CveCorte").ToEntero(), UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa))
|
|
{
|
|
Error = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
//if (Error == false)
|
|
//{
|
|
// foreach (GridViewRow Row in GVCorte.Rows)
|
|
// {
|
|
// int x = 0;
|
|
// if (CveProduccion > 0)
|
|
// {
|
|
// foreach (DataRow Dr in DtCorte.Rows)
|
|
// {
|
|
// if (Row.DataKey("CveCorte").ToEntero() == Dr["CveCorte"].ToEntero())
|
|
// {
|
|
// if (Row.FCCheckBox("ChkCorte").Checked == false)
|
|
// {
|
|
// if (ObjProd.RemoveProduccionDetalle(Dr["CveProduccionDetalle"].ToEntero()) == false)
|
|
// {
|
|
// Error = true;
|
|
// }
|
|
// else
|
|
// {
|
|
// x = 1;
|
|
// break;
|
|
// }
|
|
// }
|
|
// else if (CveCorte < 1)
|
|
// {
|
|
// CveCorte = Row.DataKey("CveCorte").ToEntero();
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
// if (Row.FCCheckBox("ChkCorte").Checked == true && x == 0)
|
|
// {
|
|
// if (ObjProd.AddProduccionDetalle(_CveProduccion, Row.DataKey("CveCorte").ToEntero(), UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) == false)
|
|
// {
|
|
// Error = true;
|
|
// }
|
|
// else if (CveCorte < 1)
|
|
// {
|
|
// CveCorte = Row.DataKey("CveCorte").ToEntero();
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
//}
|
|
if (Error == false)
|
|
{
|
|
foreach (DataRow Dr in DtResultado.Rows)
|
|
{
|
|
if (Dr["CveProduccionResultado"].ToEntero() == -1)
|
|
{
|
|
if (ObjProd.AddProduccionResultado(_CveProduccion, Dr["CvePS"].ToEntero(), Dr["Cantidad"].ToString().ToDouble(),
|
|
Dr["Peso"].ToString().ToDouble(), Dr["CveTamaño"].ToEntero(), Dr["CveCalidad"].ToEntero(), Dr["CveTipoCaja"].ToEntero(), Convert.ToBoolean(Dr["CveTipoEtiqueta"]),
|
|
Dr["CveOrdenProduccionDetalle"].ToEntero(), UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, Dr["CveTipoEmpaque"].ToEntero(), Dr["CveTipoMaduracion"].ToEntero(), Dr["CveTipoProducto"].ToEntero(), CveCorte) == false)
|
|
{
|
|
Error = true;
|
|
}
|
|
}
|
|
else if (Dr["CvePS"].ToEntero() == -1)
|
|
{
|
|
if (ObjProd.RemoveProduccionResultado(Dr["CveProduccionResultado"].ToEntero()) == false)
|
|
{
|
|
Error = true;
|
|
}
|
|
}
|
|
else if (Dr["CveProduccionResultado"].ToEntero() > 0)
|
|
{
|
|
if (ObjProd.UpdateProduccionResultado(Dr["CveProduccionResultado"].ToEntero(), _CveProduccion, Dr["CvePS"].ToEntero(), Dr["Cantidad"].ToString().ToDouble(),
|
|
Dr["Peso"].ToString().ToDouble(), Dr["CveTamaño"].ToEntero(), Dr["CveCalidad"].ToEntero(), Dr["CveTipoCaja"].ToEntero(), Convert.ToBoolean(Dr["CveTipoEtiqueta"]),
|
|
Dr["CveOrdenProduccionDetalle"].ToEntero(), UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, Dr["CveTipoEmpaque"].ToEntero(), Dr["CveTipoMaduracion"].ToEntero(), Dr["CveTipoProducto"].ToEntero(), CveCorte) == false)
|
|
{
|
|
Error = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (Error == false)
|
|
{
|
|
ObjProd.Commit();
|
|
if (CveProduccion > 0)
|
|
{
|
|
Alert("Actualizado Correctamente");
|
|
CargaProduccion();
|
|
}
|
|
else
|
|
{
|
|
Alert("Guardado Correctamente", TipoMensaje.MsgInformacion, $"document.location.href=\"/CGame/RepEmpaque.aspx\"");
|
|
LimpiarPagina();
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
ObjProd.RollBack();
|
|
if (MensajeExistencias.ToString() != "")
|
|
{
|
|
Alert($"Los siguientes productos no cuentan con la existencia suficiente para hacer la devolución. </br></br> {MensajeExistencias.ToString()}", TipoMensaje.MsgAdvertencia);
|
|
}
|
|
}
|
|
ObjProd.Dispose();
|
|
ObjInv.Dispose();
|
|
}
|
|
|
|
|
|
protected void BtnCalcularGenerales_Click(object sender, EventArgs e)
|
|
{
|
|
CalculaTotales();
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
#region AutopostBack
|
|
|
|
protected void DdlPS_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
CargaTipoMaduracion(DdlPS.SelectedValue.ToEntero());
|
|
}
|
|
|
|
protected void DdlHuertaIndexChange()
|
|
{
|
|
LimpiarGvCorteShowHeader();
|
|
if (DdlHuerta.SelectedValue != "-1")
|
|
{
|
|
ClsCGame ObjProd = new ClsCGame();
|
|
if (ObjProd.GetCorte(UsuarioActual.CveEmpresa, CveHuerta: DdlHuerta.SelectedValue.ToEntero()))
|
|
{
|
|
GVCorte.DataSource = ObjProd.DtResultados;
|
|
GVCorte.DataBind();
|
|
}
|
|
ObjProd.Dispose();
|
|
}
|
|
UpCorte.Update();
|
|
}
|
|
protected void DdlHuerta_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
DdlHuertaIndexChange();
|
|
}
|
|
|
|
protected void DdlClasificacion_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
CargaPS();
|
|
}
|
|
|
|
protected void DdlAlmacen_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
CargaExistencias();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region GridView
|
|
protected void GvResultado_RowDataBound(object sender, GridViewRowEventArgs e)
|
|
{
|
|
if (e.Row.RowType == DataControlRowType.DataRow)
|
|
{
|
|
if (e.Row.DBCampo("TipoColumna").ToEntero() == 4)
|
|
{
|
|
e.Row.CssClass = "Totales";
|
|
e.Row.Cells[0].Text = "Total";
|
|
e.Row.Cells[11].Text = "";
|
|
}
|
|
else if (e.Row.DBCampo("TipoColumna").ToEntero() == 1 || e.Row.DBCampo("TipoColumna").ToEntero() == 2 || e.Row.DBCampo("TipoColumna").ToEntero() == 3)
|
|
{
|
|
e.Row.CssClass = "SubTotales";
|
|
e.Row.Cells[0].Text = e.Row.DBCampo("Gpo");
|
|
e.Row.Cells[11].Text = "";
|
|
}
|
|
else
|
|
{
|
|
if (e.Row.DataKey("CvePS").ToEntero() == -1)
|
|
{
|
|
e.Row.Visible = false;
|
|
}
|
|
|
|
if (e.Row.DataKey("CveTipoEtiqueta").ToEntero() == 1)
|
|
{
|
|
e.Row.FCLabel("LblTipoEtiqueta").Text = "Si";
|
|
}
|
|
else if (e.Row.DataKey("CveTipoEtiqueta").ToEntero() == 0)
|
|
{
|
|
e.Row.FCLabel("LblTipoEtiqueta").Text = "No";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
protected void GvCorte_RowDataBound(object sender, GridViewRowEventArgs e)
|
|
{
|
|
if (e.Row.RowType == DataControlRowType.DataRow)
|
|
{
|
|
|
|
if (e.Row.DBCampo("CveProduccion") != "" && CveProduccion < 1)
|
|
{
|
|
e.Row.Visible = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
protected void GvPS_RowCreated(object sender, GridViewRowEventArgs e)
|
|
{
|
|
if (e.Row.RowType == DataControlRowType.DataRow)
|
|
{
|
|
int Index = e.Row.RowIndex;
|
|
e.Row.FCTextBox("TxtCantidad").Attributes.Add("onKeyUp", String.Format("ValidarCantidad({0});", Index));
|
|
}
|
|
}
|
|
|
|
protected void GvPS_RowDataBound(object sender, GridViewRowEventArgs e)
|
|
{
|
|
if (e.Row.RowType == DataControlRowType.DataRow)
|
|
{
|
|
|
|
e.Row.FCLabel("LblExistencia").Text = e.Row.FCLabel("LblExistencia").Text.FormatoNumero(0);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region PDF
|
|
|
|
protected void GenerarPDF(String Opcion)
|
|
{
|
|
|
|
if (DtCorte.Rows.Count > 0 && DtResultado.Rows.Count > 0)
|
|
{
|
|
System.IO.FileInfo Imagen = new System.IO.FileInfo($"{UsuarioActual.Empresa.Ruta}/Logo.png");
|
|
String logouri = String.Format("{0}://{1}:{2}/Empresas/{3}/Logo.png", Request.Url.Scheme, Request.Url.Host, Request.Url.Port, UsuarioActual.CveEmpresa);
|
|
List<ReportParameter> para = new List<ReportParameter>();
|
|
para.Add(new ReportParameter("NombreEmpresa", UsuarioActual.Empresa.Empresa));
|
|
para.Add(new ReportParameter("UsuarioImprimio", UsuarioActual.Nombre));
|
|
para.Add(new ReportParameter("FechaImpresion", DateTime.Now.ToString()));
|
|
para.Add(new ReportParameter("Folio", Folio));
|
|
para.Add(new ReportParameter("Huerta", DdlHuerta.SelectedItem.Text));
|
|
para.Add(new ReportParameter("Observaciones", TxtObservacion.Text));
|
|
para.Add(new ReportParameter("Fecha", TxtFecha.Text.ToDate().ToShortDateString()));
|
|
para.Add(new ReportParameter("FechaRegistro", TxtFechaRegistro.Text));
|
|
para.Add(new ReportParameter("Capturo", lblNombreUsuario.Text));
|
|
para.Add(new ReportParameter("TotPeso", LblPesoTotal.Text));
|
|
para.Add(new ReportParameter("TotPrimera", LblPrimera.Text));
|
|
para.Add(new ReportParameter("PorcentajePrimera", LblPorcentajePrimera.Text));
|
|
para.Add(new ReportParameter("TotSegunda", LblSegunda.Text));
|
|
para.Add(new ReportParameter("PorcentajeSegunda", LblPorcentajeSegunda.Text));
|
|
para.Add(new ReportParameter("TotMerma", LblMerma.Text));
|
|
para.Add(new ReportParameter("PorcentajeMerma", LblPorcentajeMerma.Text));
|
|
para.Add(new ReportParameter("TotEnPiso", LblPiso.Text));
|
|
para.Add(new ReportParameter("PorcentajeEnPiso", LblPorcentajeEnPiso.Text));
|
|
|
|
if (Imagen.Exists)
|
|
{
|
|
para.Add(new ReportParameter("LogoPath", logouri));
|
|
}
|
|
else
|
|
{
|
|
para.Add(new ReportParameter("LogoPath", ""));
|
|
}
|
|
List<ReportDataSource> lrds = new List<ReportDataSource>();
|
|
ReportDataSource rds = new ReportDataSource();
|
|
rds.Name = "DataSet1"; rds.Value = DtCorte;
|
|
ReportDataSource rds2 = new ReportDataSource();
|
|
rds2.Name = "DataSet2"; rds2.Value = DtResultado;
|
|
lrds.Add(rds);
|
|
lrds.Add(rds2);
|
|
|
|
ImprimirPDF("Empresas/Grales/Formatos/Empaque.rdlc", lrds, para, "Empaque", Opcion);
|
|
}
|
|
else
|
|
{
|
|
Alert("No hay datos consultados", TipoMensaje.MsgAdvertencia);
|
|
}
|
|
}
|
|
|
|
|
|
protected void LnkPdf_Click(object sender, EventArgs e)
|
|
{
|
|
GenerarPDF("PDF");
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
}
|