Files
SIG/CGame/GenerarOrdenCorte.aspx.cs
Raul Pimienta 8eee743395 Se quitaron warnings de cgame
Se puso la existencia en el dropdownlost para econollantas
Se agrego pagina de traspasos emitidos
Se agrego porlet de secciones de almacen enproductos servicios
2019-09-05 11:12:50 -07:00

492 lines
20 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 DocumentFormat.OpenXml.Spreadsheet;
using System.Web.UI;
public partial class CGame_GenerarOrdenCorte : ClsPaginas
{
#region PROPIEDADES
private DataTable DtResultado
{
get { return DtResultado = (DataTable)ViewState["DtResultado"]; }
set { ViewState["DtResultado"] = value; }
}
private string Folio
{
get { return (ViewState["Folio"] == null) ? "" : (ViewState["Folio"]).ToString(); }
set { ViewState["Folio"] = value; }
}
#endregion
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
CargaHuerta();
CargaCliente();
CargaPS();
LimpiaModal();
CargaOrdenProduccionDetalle();
MostrarPanel(true);
}
}
#region CARGAS
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();
UpOCAdd.Update();
DdlHuerta.DataBind();
}
protected void CargaCliente()
{
ClsCGame ObjCGame = new ClsCGame();
if (ObjCGame.GetCliente(-1, -1, UsuarioActual.CveEmpresa))
{
DdlCliente.DataSource = ObjCGame.DtResultados;
DdlCliente.Items.Insert(0, new ListItem("Todos", "-1"));
}
ObjCGame.Dispose();
DdlCliente.DataBind();
UPFiltros.Update();
}
protected void CargaPS()
{
ClsCGame ObjCGame = new ClsCGame();
if (ObjCGame.GetPS(UsuarioActual.CveEmpresa, Estatus: 1))
{
DdlFruto.DataSource = ObjCGame.DtResultados;
DdlFruto.Items.Insert(0, new ListItem("Todos", "-1"));
}
ObjCGame.Dispose();
DdlFruto.DataBind();
UPFiltros.Update();
}
protected void CargaOrdenProduccionDetalle()
{
var Folio = "-1";
if (TxtFolio.Text != "") { Folio = TxtFolio.Text; }
ClsCGame ObjCGame = new ClsCGame();
if (ObjCGame.GetGenerarOrdenCorte(-1, UsuarioActual.CveEmpresa, txtFechaI.Text.ToDate(), txtFechaF.Text.ToDate(), DdlCliente.SelectedValue.ToEntero(), DdlTipoEmpaque.SelectedValue.ToEntero(), DdlFruto.SelectedValue.ToEntero(), Folio))
{
GvOrdenProduccionDetalle.DataSource = ObjCGame.DtResultados.FiltraParametros("Restante > 0 OR CveOrdenProduccionDetalle IS NULL");
DtResultado = ObjCGame.DtResultados.FiltraParametros("Restante > 0 OR CveOrdenProduccionDetalle IS NULL");
DtResultado.Columns.Add("Seleccion");
ObjCGame.Dispose();
}
GvOrdenProduccionDetalle.DataBind();
UpOrdenCorte.Update();
}
#endregion
#region LIMPIAS
protected void LimpiaModal()
{
TxtFechaCorte.Text = DateTime.Now.ToShortDateString();
DdlHuerta.SelectedIndex = 0;
TxtCuadro.Text = "";
TxtPeso.Text = "";
TxtObservacion.Text = "";
UpOCAdd.Update();
}
#endregion
#region BOTONES
protected void BtnGenerarOC_Click(object sender, EventArgs e)
{
GeneraOC();
}
private void GeneraOC()
{
var SiSelecciono = false;
foreach (GridViewRow GvRow in GvOrdenProduccionDetalle.Rows)
{
if (GvRow.FCCheckBox("ChkOC").Checked == true)
{
SiSelecciono = true;
}
}
if (SiSelecciono || RblTipoOC.SelectedValue.ToEntero()==2)
{
this.RegistraScript("recorreGrilla();", "recorre");
this.RegistraScript("$('#DivModalOC').modal();");
LimpiaModal();
UpAccion.Update();
}
else
{
Alert("Tiene que seleccionar al menos un producto.", TipoMensaje.MsgAdvertencia);
}
}
protected void BtnOrdenCorteAdd_Click(object sender, EventArgs e)
{
if (DdlHuerta.SelectedValue == "-1")
{
Alert("Tiene que seleccionar una huerta.", TipoMensaje.MsgAdvertencia);
return;
}
ClsCGame ObjCGame = new ClsCGame();
ObjCGame.IniciaTransacSQL();
var Error = false;
var CveOrdenCorte = 0;
if (ObjCGame.AddOrdenCorte(DdlHuerta.SelectedValue.ToEntero(), "", TxtFechaCorte.Text.ToDate(), UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, TxtPeso.Text.ToDouble(), TxtCuadro.Text.ToEntero(), TxtObservacion.Text))
{
CveOrdenCorte = ObjCGame.CveOrdenCorte;
}
else
{
Error = true;
}
foreach (GridViewRow GvRow in GvOrdenProduccionDetalle.Rows)
{
if (GvRow.FCCheckBox("ChkOC").Checked == true)
{
if (ObjCGame.AddOrdenCorteDetalle(GvRow.FCLabel("LblCantidad").Text.ToEntero(), CveOrdenCorte, GvRow.DataKey("CveOrdenProduccionDetalle").ToEntero()) == false)
{
Error = true;
}
}
}
if (!Error)
{
if (ObjCGame.GetOrdenCorte(UsuarioActual.CveEmpresa, CveOrdenCorte: CveOrdenCorte))
{
Folio = ObjCGame.DtResultados.Rows[0]["FolioOC"].ToString();
}
ObjCGame.Commit();
EnviarCorreo(CveOrdenCorte);
Alert("Se genero la orden de corte correctamente con el folio <b>" + Folio + "</b>.", TipoMensaje.MsgInformacion);
this.RegistraScript("$('#DivModalOC').modal('hide');");
CargaOrdenProduccionDetalle();
this.RegistraScript("recorreGrilla();", "recorre");
}
else
{
ObjCGame.RollBack();
}
ObjCGame.Dispose();
}
#endregion
#region GRIDVIEW
protected void GvOrdenProduccionDetalle_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.RowIndex == 0)
{
e.Row.CssClass = "Totales";
e.Row.FCLabel("LblCantidad").Text = e.Row.DBCampo("Restante");
e.Row.Cells[0].Text = "";
e.Row.Cells[8].Text = "";
e.Row.Cells[11].Text = "";
}
else
{
e.Row.FCCheckBox("ChkOC").Attributes.Add("onchange", "recorreGrilla();");
e.Row.FCLinkButton("BtnDividir").Attributes.Add("onclick", String.Format("Dividir('{0}');", e.Row.FCTextBox("TxtCantDividir").ClientID));
e.Row.FCLinkButton("BtnDividir").CommandArgument = e.Row.RowIndex.ToString();
e.Row.FCTextBox("TxtCantDividir").Attributes.Add("onkeyup", String.Format("LimitaCantidad({0},this,'{1}');", e.Row.DBCampo("Restante"), e.Row.FCLinkButton("BtnDividir").ClientID));
if (e.Row.DataKey("CveTipoEtiqueta").ToEntero() == 1)
{
e.Row.FCLabel("LblTipoEtiqueta").Text = "Si";
}
else
{
e.Row.FCLabel("LblTipoEtiqueta").Text = "No";
}
}
}
}
#endregion
#region DIVIDIR
protected void Dividir(object sender, EventArgs e)
{
int Index = ((LinkButton)sender).CommandArgument.ToString().ToEntero();
int Cantidad = HdnCantidad.Value.ToEntero();
foreach (GridViewRow GvRow in GvOrdenProduccionDetalle.Rows)
{
if (GvRow.FCCheckBox("ChkOC").Checked == true)
{
DtResultado.Rows[GvRow.RowIndex]["Seleccion"] = 1;
}
else
{
DtResultado.Rows[GvRow.RowIndex]["Seleccion"] = 0;
}
}
DataRow Dr = DtResultado.Rows[Index];
DataRow DrNew = DtResultado.NewRow();
DrNew.ItemArray = Dr.ItemArray;
Dr["Restante"] = (Dr["Restante"].ToString().ToEntero() - Cantidad);
DrNew["Restante"] = Cantidad;
DrNew["Seleccion"] = 0;
DtResultado.Rows.InsertAt(DrNew, Index);
DtResultado.AcceptChanges();
GvOrdenProduccionDetalle.DataSource = DtResultado;
GvOrdenProduccionDetalle.DataBind();
foreach (GridViewRow GvRow in GvOrdenProduccionDetalle.Rows)
{
if (DtResultado.Rows[GvRow.RowIndex]["Seleccion"].ToEntero() == 1)
{
GvRow.FCCheckBox("ChkOC").Checked = true;
}
}
this.RegistraScript("recorreGrilla();");
}
#endregion
#region CORREO
private void MandaCorreo(String Para, String Asunto, String Body)
{
ClsSisMail Mail = new ClsSisMail();
Mail.SendMail(ClsPaginas.EmpresaNotificaciones, Para, Asunto, Body);
}
private string GeneraBody(int CveOrdenCorte)
{
ClsCGame ObjCGame = new ClsCGame();
ObjCGame.GetOrdenCorte(UsuarioActual.CveEmpresa, CveOrdenCorte: CveOrdenCorte);
StringBuilder strBody = new StringBuilder();
strBody.Append("<html xmlns=\"http://www.w3.org/1999/xhtml \"> ");
strBody.Append("<head> ");
strBody.Append(" <style type='text/css'> ");
strBody.Append(" body ");
strBody.Append(" { ");
strBody.Append(" margin:0px; ");
strBody.Append(" padding:0px 0px 0px 0px; ");
strBody.Append(" font-family: Verdana, Arial, Helvetica, sans-serif; ");
strBody.Append(" font-size: 10px; ");
strBody.Append(" background-color:#F0F0F0; ");
strBody.Append(" } ");
strBody.Append(" a.Texto ");
strBody.Append(" { ");
strBody.Append(" font-size:11px; ");
strBody.Append(" background-color:#F7F6F3; ");
strBody.Append(" text-decoration:none; ");
strBody.Append(" font-weight:bold; ");
strBody.Append(" } ");
strBody.Append(" .Texto ");
strBody.Append(" { ");
strBody.Append(" background-color:#F7F6F3; color:Black; font-family:Verdana; font-size:10px; text-align:center; vertical-align:middle; height:20px;");
strBody.Append(" } ");
strBody.Append(" .TextoAlterno ");
strBody.Append(" { ");
strBody.Append(" background-color:White; color:Black; font-family:Verdana; font-size:10px; text-align:center; ");
strBody.Append(" vertical-align:middle; height:20px;");
strBody.Append(" } ");
strBody.Append(" .BarraIdentidad ");
strBody.Append(" { ");
strBody.Append(" color:#FFFFFF; ");
strBody.Append(" background:#F0F0F0; ");
strBody.Append(" font-weight:bold; ");
strBody.Append(" font-size:19px; ");
strBody.Append(" font-style:oblique; ");
strBody.Append(" } ");
strBody.Append(" .Titulos ");
strBody.Append(" { ");
strBody.Append(" background-color: Gray;");
strBody.Append(" color:White; ");
strBody.Append(" font-family:Verdana; font-size:12px; text-align:center; ");
strBody.Append(" vertical-align:middle; font-weight:bold; height:30px; ");
strBody.Append(" text-decoration:none; ");
strBody.Append(" } ");
strBody.Append(" .Contenido2 ");
strBody.Append(" { ");
strBody.Append(" background-color: White;");
strBody.Append(" font-family:Verdana; font-size:12px; text-align:center; ");
strBody.Append(" vertical-align:middle; font-weight:bold; height:30px; ");
strBody.Append(" text-decoration:none; ");
strBody.Append(" } ");
strBody.Append(" .Verde {color: #00CC00;} ");
strBody.Append(" .Negro {color: #000000;} ");
strBody.Append(" .Rojo {color: #FF0000;} ");
strBody.Append(" </style> ");
strBody.Append("</head> ");
strBody.Append("<body> ");
strBody.Append("<div class='Contenido2' style='display: table!important'>");
strBody.AppendFormat(" <div id=\"C_divOC\" style=\"width: 550px\"> <fieldset> <legend><b>Datos {0}</b></legend> ", "de la orden de corte");
strBody.Append(" <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\"> ");
strBody.Append(" <tr style=\"height: 22px\"> ");
strBody.AppendFormat(" <td style=\"width: 90px\"> Folio OC:</td><td colspan=\"3\"><a href=" + UrlSitio + "CGame/RepOrdenCorteDetalle.aspx?CveOrdenCorte=" + CveOrdenCorte.ToString() + "><b>" + ObjCGame.DtResultados.Rows[0]["FolioOC"].ToString() + "</b><a/></td> ");
strBody.AppendFormat(" <td style=\"width: 90px\"> F. Termino:</td><td colspan=\"3\"><b>{0}</b></td> ", ObjCGame.DtResultados.Rows[0]["FechaEntregaOC"].ToString().ToDate().ToShortDateString());
strBody.Append(" </tr> ");
strBody.Append(" <tr style=\"height: 22px\"> ");
strBody.AppendFormat(" <td>Huerta:</td><td><b>{0}</b></td><td>&nbsp;</td><td><b>&nbsp;</b></td> ", ObjCGame.DtResultados.Rows[0]["Huerta"]);
strBody.Append(" </tr> ");
strBody.Append(" <tr style=\"height: 22px\"> ");
strBody.AppendFormat(" <td>Cuadro:</td><td><b>{0}</b></td><td>&nbsp;</td><td><b>&nbsp;</b></td> ", ObjCGame.DtResultados.Rows[0]["Cuadro"]);
strBody.Append(" </tr> ");
strBody.Append(" <tr style=\"height: 22px\"> ");
strBody.AppendFormat(" <td>Peso (TON):</td><td><b>{0}</b></td><td>&nbsp;</td><td><b>&nbsp;</b></td> ", ObjCGame.DtResultados.Rows[0]["Peso"]);
strBody.Append(" </tr> ");
strBody.Append(" <tr style=\"height: 22px\"> ");
strBody.AppendFormat(" <td>Observaciones:</td><td><b>{0}</b></td><td>&nbsp;</td><td><b>&nbsp;</b></td> ", ObjCGame.DtResultados.Rows[0]["ObservacionesOC"]);
strBody.Append(" </tr> ");
strBody.Append(" <tr style=\"height: 22px\"> ");
strBody.AppendFormat(" <td>Solicita:</td><td><b>{0}</b></td><td>&nbsp;</td><td><b>&nbsp;</b></td> ", UsuarioActual.Nombre);
strBody.Append(" </tr> ");
strBody.Append(" </table> ");
strBody.Append(" </fieldset> ");
strBody.Append(" </div> ");
strBody.Append(" <div style='width: 550px'> ");
strBody.Append(" <fieldset> ");
strBody.Append(" <legend>Instrucciones del corte</legend> ");
strBody.Append(" <table width=\"1000px\"> <tr style='background-color:gray;color:White;font-family:Verdana;font-size:10px;text-align:center;vertical-align:middle;font-weight:bold;height:20px;text-decoration:none;'><th scope='col' style='width: 150px'>Folio OP</th><th scope='col' style='width: 50px'>Cantidad</th><th scope='col' style='width: 150px'>Fruto</th><th scope='col' style='width: 150px'>Tipo Producción</th><th scope='col' style='width: 150px'>Variedad</th><th scope='col' style='width: 150px'>Tipo Empaque</th><th scope='col' style='width: 150px'>Tamaño</th><th scope='col' style='width: 150px'>PLU</th><th scope='col' style='width: 150px'>Calidad</th><th scope='col' style='width: 150px'>Etiqueta</th><th scope='col' style='width: 150px'>Instrucciones</th><th scope='col' style='width: 150px'>Observaciones</th>");
strBody.Append(" </tr>");
DataTable DtOrdenCorteDetalle = new DataTable();
if (ObjCGame.GetOrdenCorteDetalle(UsuarioActual.CveEmpresa, CveOrdenCorte: CveOrdenCorte))
{
foreach (DataRow dr in ObjCGame.DtResultados.Rows)
{
var TipoEtiqueta = "";
if (Convert.ToBoolean(dr["CveTipoEtiqueta"]))
{
TipoEtiqueta = "Si";
}
else
{
TipoEtiqueta = "No";
}
strBody.AppendFormat("<tr class='Texto'><td align='center' style='width:100px;'>{0}</td><td align='center' style='width:50px;'>{1}</td><td align='left' style='width:100px;'>{2}</td><td align='left' style='width:100px;'>{3}</td><td align='left' style='width:100px;'>{4}</td><td align='left' style='width:100px;'>{5}</td><td align='left' style='width:100px;'>{6}</td><td align='left' style='width:100px;'>{7}</td><td align='left' style='width:100px;'>{8}</td><td align='left' style='width:100px;'>{9}</td><td align='left' style='width:100px;'>{10}</td><td align='left' style='width:100px;'>{11}</td></tr>", "<a href=" + UrlSitio + "CGame/OrdenProduccion.aspx?CveOrdenProduccion=" + dr["CveOrdenProduccion"].ToString() + ">" + dr["FolioOP"].ToString() + "<a/>", dr["Cantidad"].ToString().FormatoNumero(0), dr["PS"], dr["TipoProducto"], dr["TipoMaduracion"], dr["TipoEmpaque"], dr["Tamaño"], TipoEtiqueta, dr["Calidad"], dr["TipoCaja"], dr["Instrucciones"], dr["Observaciones"]);
}
}
strBody.Append(" </table> ");
strBody.Append(" </fieldset> ");
strBody.Append(" </div> ");
strBody.Append(" <br> ");
strBody.AppendFormat("<a href={0}CGame/RepOrdenCorteDetalle.aspx?CveOrdenCorte={1}> Ir a la Orden de Corte <a/>", UrlSitio, CveOrdenCorte);
strBody.Append("</div>");
strBody.Append("</body></html>");
ObjCGame.Dispose();
return strBody.ToString();
}
private void EnviarCorreo(int CveOrdenCorte)
{
var Asunto = "SIG - Se Genero una Orden de Corte con el folio:" + Folio;
//var Para = "julian@adsistemas.mx";
//var Para = "dany_pimi@hotmail.com";
var Para = "norberto@citrusgame.com.mx;";
var Body = GeneraBody(CveOrdenCorte);
try
{
var Hilo = new System.Threading.Thread(() => MandaCorreo(Para, Asunto, Body));
Hilo.Start();
}
catch (Exception ex)
{
Alert("Ocurrio un error al mandar el mail " + ex);
}
}
#endregion
#region TIPO DE OC
private void PresionarBotonModal(String Boton)
{
try
{
String script = $"document.getElementById(\"{Boton}\").click();";
System.Web.UI.Page Pag = (System.Web.UI.Page)(System.Web.HttpContext.Current.Handler);
ScriptManager.RegisterStartupScript(Pag, Pag.GetType(), Boton, script, true);
Pag = null;
}
catch (Exception ex)
{
Alert("Ocurrio un error " + ex);
throw;
}
}
protected void BtnTipoOC_Click(object sender, EventArgs e)
{
if (RblTipoOC.SelectedValue.ToEntero() ==0)
{
//Alert("Tiene que seleccionar un tipo de OC",TipoMensaje.MsgAdvertencia);
return;
}
PresionarBotonModal("C_BtnCerrarPanel");
if (RblTipoOC.SelectedValue.ToEntero() == 2)
{
GvOrdenProduccionDetalle.Visible = false;
LblCantTotal.Visible = false;
LblTotalCantidad.Visible = false;
UpAccion.Update();
UpOrdenCorte.Update();
GeneraOC();
}
}
private void MostrarPanel(Boolean AfterPageLoad = false)
{
if (AfterPageLoad)
{
RegistraScript("window.onload = function MuestraPanel() { document.getElementById(\"C_BtnMostrarPanel\").click(); }");
}
}
#endregion
protected void BtnConsultar_Click(object sender, EventArgs e)
{
CargaOrdenProduccionDetalle();
}
}