Commit inicial Ventas Productivo
This commit is contained in:
560
Contratos/CatRefrendos.aspx.cs
Normal file
560
Contratos/CatRefrendos.aspx.cs
Normal file
@@ -0,0 +1,560 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Web;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
using ClosedXML.Excel;
|
||||
using Extensiones;
|
||||
using Microsoft.Reporting.WebForms;
|
||||
|
||||
public partial class Contratos_CatRefrendos : ClsPaginas
|
||||
{
|
||||
|
||||
#region "Propiedades"
|
||||
private String FechaInicio
|
||||
{
|
||||
get
|
||||
{
|
||||
return ViewState["FechaInicio"].ToString();
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
ViewState["FechaInicio"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
private String FechaFin
|
||||
{
|
||||
get
|
||||
{
|
||||
return ViewState["FechaFin"].ToString();
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
ViewState["FechaFin"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
private String FechaVencimientoInicio
|
||||
{
|
||||
get
|
||||
{
|
||||
return ViewState["FechaVencimientoInicio"].ToString();
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
ViewState["FechaVencimientoInicio"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
private String FechaVencimientoFin
|
||||
{
|
||||
get
|
||||
{
|
||||
return ViewState["FechaVencimientoFin"].ToString();
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
ViewState["FechaVencimientoFin"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
private int CveUsuario
|
||||
{
|
||||
get
|
||||
{
|
||||
return ViewState["CveUsuario"].ToString().ToEntero();
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
ViewState["CveUsuario"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
private int CveCliente
|
||||
{
|
||||
get
|
||||
{
|
||||
return ViewState["CveCliente"].ToString().ToEntero();
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
ViewState["CveCliente"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
private int CveEmpresa
|
||||
{
|
||||
get
|
||||
{
|
||||
return ViewState["CveEmpresa"].ToString().ToEntero();
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
ViewState["CveEmpresa"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
private int EsEditar
|
||||
{
|
||||
get
|
||||
{
|
||||
return ViewState["EsEditar"].ToString().ToEntero();
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
ViewState["EsEditar"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
private int CveRefrendo
|
||||
{
|
||||
get
|
||||
{
|
||||
return ViewState["CveRefrendo"].ToString().ToEntero();
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
ViewState["CveRefrendo"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
private DataTable TmpDT
|
||||
{
|
||||
get
|
||||
{
|
||||
return (DataTable)ViewState["TmpDT"];
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
ViewState["TmpDT"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
private int CveEstatus
|
||||
{
|
||||
get
|
||||
{
|
||||
return ViewState["CveEstatus"].ToString().ToEntero();
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
ViewState["CveEstatus"] = value;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
{
|
||||
if (!IsPostBack)
|
||||
{
|
||||
InicializaDatos();
|
||||
}
|
||||
}
|
||||
|
||||
#region "CARGA DATOS"
|
||||
|
||||
protected void InicializaDatos()
|
||||
{
|
||||
FechaInicio = "-1";
|
||||
FechaFin = "-1";
|
||||
|
||||
FechaVencimientoInicio = "-1";//DateTime.Today.AddYears(-1).ToShortDateString();
|
||||
FechaVencimientoFin = "-1";//DateTime.Today.AddYears(2).ToShortDateString();
|
||||
|
||||
CveEmpresa = UsuarioActual.CveEmpresa;
|
||||
CveCliente = -1;
|
||||
CveUsuario = -1;
|
||||
|
||||
CveEstatus = -1;
|
||||
|
||||
CargaClientes();
|
||||
CargaUsuarios();
|
||||
CargaFechas();
|
||||
CargaEstatus();
|
||||
|
||||
CargaDatos();
|
||||
CargaModal();
|
||||
}
|
||||
|
||||
protected void CargaDatos()
|
||||
{
|
||||
ClsContratos ObjContrato = new ClsContratos();
|
||||
|
||||
if (ObjContrato.GetRefrendos(FechaVencimientoInicio, FechaVencimientoFin, FechaInicio, FechaFin, CveCliente, CveUsuario, CveEmpresa, CveEstatus))
|
||||
{
|
||||
TmpDT = ObjContrato.DtResultados;
|
||||
GvRefrendos.DataSource = TmpDT;
|
||||
}
|
||||
ObjContrato.Dispose();
|
||||
GvRefrendos.DataBind();
|
||||
UPFiltros.Update();
|
||||
}
|
||||
|
||||
protected void limpiarCamposModal()
|
||||
{
|
||||
DdlClientesRef.SelectedValue = "-1";
|
||||
TxtClienteEspecifico.Text = "";
|
||||
|
||||
TxtCodigoProveedor.Text = "";
|
||||
DdlEstatusRefrendo.SelectedValue = "-1";
|
||||
|
||||
DdlTipoDocto.SelectedValue = "-1";
|
||||
TxtLigaDocumento.Text = "";
|
||||
|
||||
TxtDescripcion.Text = "";
|
||||
|
||||
TxtClienteEspecifico.Visible = false;
|
||||
LblClienteEspecifico.Text = "";
|
||||
LblClienteEspecifico.Visible = false;
|
||||
|
||||
DivLigaDocto.Visible = false;
|
||||
|
||||
txtFecha.Text = DateTime.Today.ToString();
|
||||
txtFechaVenc.Text = DateTime.Today.AddDays(1).ToString();
|
||||
}
|
||||
|
||||
protected void CargaModal()
|
||||
{
|
||||
DdlClientesRef.DataSource = get_GlobalDTCliente(CveEmpresa);
|
||||
DdlClientesRef.DataBind();
|
||||
DdlClientesRef.Items.Insert(0, new ListItem("Seleccione", "-1"));
|
||||
DdlClientesRef.Items.Insert(1, new ListItem("Cliente Específico", "0"));
|
||||
DdlClientesRef.SelectedValue = "-1";
|
||||
|
||||
|
||||
|
||||
DdlEstatusRefrendo.Items.Insert(0, new ListItem("Seleccione", "-1"));
|
||||
DdlEstatusRefrendo.Items.Insert(1, new ListItem("Vigente", "1"));
|
||||
DdlEstatusRefrendo.Items.Insert(2, new ListItem("No Vigente", "2"));
|
||||
DdlEstatusRefrendo.SelectedValue = "-1";
|
||||
|
||||
|
||||
ClsContratos ObjContrato = new ClsContratos();
|
||||
|
||||
if (ObjContrato.GetRefrendosTipoDocumento(CveEmpresa))
|
||||
{
|
||||
DdlTipoDocto.DataSource = ObjContrato.DtResultados;
|
||||
DdlTipoDocto.DataBind();
|
||||
DdlTipoDocto.Items.Insert(0, new ListItem("Seleccione", "-1"));
|
||||
ObjContrato.Dispose();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void CargaClientes()
|
||||
{
|
||||
DdlCliente.DataSource = get_GlobalDTCliente(CveEmpresa);
|
||||
DdlCliente.DataBind();
|
||||
DdlCliente.Items.Insert(0, new ListItem("Todos", "-1"));
|
||||
DdlCliente.SelectedValue = "-1";
|
||||
}
|
||||
|
||||
protected void CargaUsuarios()
|
||||
{
|
||||
DdlUsuario.DataSource = get_GlobalDTUsuarios(-1, CveEmpresa);
|
||||
DdlUsuario.DataBind();
|
||||
DdlUsuario.Items.Insert(0, new ListItem("Todos", "-1"));
|
||||
DdlUsuario.SelectedValue = "-1";
|
||||
}
|
||||
|
||||
protected void CargaFechas()
|
||||
{
|
||||
txtFechaVencI.Text = FechaVencimientoInicio == "-1" ? "" : FechaVencimientoInicio;
|
||||
txtFechaVencF.Text = FechaVencimientoFin == "-1" ? "" : FechaVencimientoFin;
|
||||
|
||||
txtFechaI.Text = FechaInicio == "-1" ? "" : FechaInicio;
|
||||
txtFechaF.Text = FechaFin == "-1" ? "" : FechaFin;
|
||||
}
|
||||
|
||||
protected void CargaEstatus()
|
||||
{
|
||||
|
||||
DdlEstatus.Items.Insert(0, new ListItem("Todos", "-1"));
|
||||
DdlEstatus.Items.Insert(1, new ListItem("Vigente", "1"));
|
||||
DdlEstatus.Items.Insert(2, new ListItem("No Vigente", "2"));
|
||||
DdlEstatus.SelectedValue = "-1";
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region "BOTONES"
|
||||
|
||||
protected void BtnConsultar_Click(object sender, EventArgs e)
|
||||
{
|
||||
FechaInicio = txtFechaI.Text == "" ? "-1" : txtFechaI.Text;
|
||||
FechaFin = txtFechaF.Text == "" ? "-1" : txtFechaF.Text;
|
||||
|
||||
FechaVencimientoInicio = txtFechaVencI.Text == "" ? "-1" : txtFechaVencI.Text;
|
||||
FechaVencimientoFin = txtFechaVencF.Text == "" ? "-1" : txtFechaVencF.Text;
|
||||
|
||||
CveCliente = Convert.ToInt32(DdlCliente.SelectedValue);
|
||||
CveUsuario = Convert.ToInt32(DdlUsuario.SelectedValue);
|
||||
CveEstatus = Convert.ToInt32(DdlEstatus.SelectedValue);
|
||||
|
||||
CargaDatos();
|
||||
}
|
||||
|
||||
protected void linkAgregar_Click(object sender, EventArgs e)
|
||||
{
|
||||
limpiarCamposModal();
|
||||
EsEditar = 0;
|
||||
|
||||
txth4Refrendo.InnerText = "Agregar Refrendo";
|
||||
BtnGuardarRefrendo.Text = "Guardar";
|
||||
|
||||
UPModalRefrendo.Update();
|
||||
|
||||
this.RegistraScript("$('#DvModalRefrendo').modal();");
|
||||
}
|
||||
|
||||
protected void imgE_Click(object sender, EventArgs e)
|
||||
{
|
||||
limpiarCamposModal();
|
||||
|
||||
GridViewRow GvRow = (GridViewRow)(((LinkButton)sender).NamingContainer);
|
||||
CveRefrendo = GvRow.DataKey("CveRefrendo").ToEntero();
|
||||
|
||||
EsEditar = 1;
|
||||
|
||||
String cliente = GvRow.DataKey("CveCliente").ToString();
|
||||
if (cliente == String.Empty)
|
||||
{
|
||||
DdlClientesRef.SelectedValue = "0";
|
||||
TxtClienteEspecifico.Text = GvRow.DataKey("Cliente").ToString();
|
||||
TxtClienteEspecifico.Visible = true;
|
||||
LblClienteEspecifico.Text = "Cliente Específico:";
|
||||
LblClienteEspecifico.Visible = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
DdlClientesRef.SelectedValue = GvRow.DataKey("CveCliente").ToString();
|
||||
}
|
||||
|
||||
String estatus = GvRow.DataKey("CveEstatus").ToString();
|
||||
if (estatus == String.Empty)
|
||||
{
|
||||
DdlEstatusRefrendo.SelectedValue = "-1";
|
||||
}
|
||||
else
|
||||
{
|
||||
DdlEstatusRefrendo.SelectedValue = GvRow.DataKey("CveEstatus").ToString();
|
||||
}
|
||||
|
||||
String tipoDocto = GvRow.DataKey("CveTipoDocto").ToString();
|
||||
if (tipoDocto == String.Empty)
|
||||
{
|
||||
DdlTipoDocto.SelectedValue = "-1";
|
||||
}
|
||||
else
|
||||
{
|
||||
DdlTipoDocto.SelectedValue = GvRow.DataKey("CveTipoDocto").ToString();
|
||||
if (tipoDocto.ToEntero() == 4)
|
||||
{
|
||||
DivLigaDocto.Visible = true;
|
||||
TxtLigaDocumento.Text = GvRow.DataKey("LigaDocto").ToString();
|
||||
}
|
||||
}
|
||||
|
||||
TxtCodigoProveedor.Text = GvRow.DataKey("CodigoProveedor").ToString();
|
||||
TxtDescripcion.Text = GvRow.DataKey("Descripcion").ToString();
|
||||
txtFecha.Text = GvRow.DataKey("Fecha").ToString();
|
||||
txtFechaVenc.Text = GvRow.DataKey("FechaVencimiento").ToString();
|
||||
|
||||
txth4Refrendo.InnerText = "Editar Refrendo";
|
||||
BtnGuardarRefrendo.Text = "Actualizar";
|
||||
|
||||
UPModalRefrendo.Update();
|
||||
|
||||
this.RegistraScript("$('#DvModalRefrendo').modal();");
|
||||
}
|
||||
|
||||
protected void BtnGuardarRefrendo_Click(object sender, EventArgs e)
|
||||
{
|
||||
ClsContratos ObjContrato = new ClsContratos();
|
||||
|
||||
String Descripcion = TxtDescripcion.Text;
|
||||
int CveClienteA = DdlClientesRef.SelectedValue.ToEntero();
|
||||
|
||||
DateTime Fecha = Convert.ToDateTime(txtFecha.Text);
|
||||
DateTime FechaVen = Convert.ToDateTime(txtFechaVenc.Text);
|
||||
|
||||
int UsuarioCreo = UsuarioActual.CveUsuario;
|
||||
|
||||
String ClienteEsp = null;
|
||||
|
||||
if (TxtClienteEspecifico.Text != "" || TxtClienteEspecifico.Text != String.Empty)
|
||||
{
|
||||
ClienteEsp = TxtClienteEspecifico.Text;
|
||||
}
|
||||
|
||||
String CodigoProveedor = TxtCodigoProveedor.Text;
|
||||
int CveEstatus = DdlEstatusRefrendo.SelectedValue.ToEntero();
|
||||
int CveTipoDocto = DdlTipoDocto.SelectedValue.ToEntero();
|
||||
String LigaDocto = TxtLigaDocumento.Text == "" ? "-1" : TxtLigaDocumento.Text;
|
||||
|
||||
ObjContrato.IniciaTransacSQL();
|
||||
|
||||
bool TieneError = false;
|
||||
|
||||
if (EsEditar == 0)
|
||||
{
|
||||
TieneError = !ObjContrato.AddRefrendo(CveClienteA, Descripcion, Fecha, FechaVen, UsuarioCreo, CveEmpresa, ClienteEsp, CodigoProveedor, CveTipoDocto,CveEstatus, LigaDocto);
|
||||
|
||||
if (TieneError)
|
||||
{
|
||||
ObjContrato.RollBack();
|
||||
}
|
||||
else
|
||||
{
|
||||
ObjContrato.Commit();
|
||||
Alert("El Refrendo fue creado correctamente.", ModExtensiones.TipoMensaje.MsgInformacion);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
TieneError = !ObjContrato.UpdateRefrendo(CveRefrendo, CveClienteA, Descripcion, Fecha, FechaVen, ClienteEsp, CodigoProveedor, CveTipoDocto, CveEstatus, LigaDocto);
|
||||
|
||||
if (TieneError)
|
||||
{
|
||||
ObjContrato.RollBack();
|
||||
}
|
||||
else
|
||||
{
|
||||
ObjContrato.Commit();
|
||||
Alert("El Refrendo fue actualizado correctamente.", ModExtensiones.TipoMensaje.MsgInformacion);
|
||||
}
|
||||
}
|
||||
|
||||
ObjContrato.Dispose();
|
||||
limpiarCamposModal();
|
||||
this.RegistraScript("$('#DvModalRefrendo').modal('hide');");
|
||||
CargaDatos();
|
||||
|
||||
}
|
||||
|
||||
protected void GvRefrendos_RowDeleting(object sender, GridViewDeleteEventArgs e)
|
||||
{
|
||||
ClsContratos ObjContrato = new ClsContratos();
|
||||
ObjContrato.IniciaTransacSQL();
|
||||
|
||||
int CveRefrendo = GvRefrendos.Rows[e.RowIndex].DataKey("CveRefrendo").ToEntero();
|
||||
|
||||
bool TieneError = !ObjContrato.RemoveRefrendo(CveRefrendo);
|
||||
|
||||
if (TieneError)
|
||||
{
|
||||
ObjContrato.RollBack();
|
||||
Alert("Error al eliminar el Refrendo.", ModExtensiones.TipoMensaje.MsgError);
|
||||
}
|
||||
else
|
||||
{
|
||||
ObjContrato.Commit();
|
||||
Alert("El Refrendo ha sido eliminado.", ModExtensiones.TipoMensaje.MsgInformacion);
|
||||
}
|
||||
ObjContrato.Dispose();
|
||||
CargaDatos();
|
||||
}
|
||||
|
||||
protected void ImgImprimir_Click(object sender, EventArgs e)
|
||||
{
|
||||
GenerarPDF();
|
||||
}
|
||||
|
||||
protected void ImgExcel_Click(object sender, EventArgs e)
|
||||
{
|
||||
GenerarPDF("Excel");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region "PDF"
|
||||
|
||||
private void GenerarPDF(string Formato = "PDF")
|
||||
{
|
||||
List<ReportParameter> @params = new List<ReportParameter>();
|
||||
|
||||
@params.Add(new ReportParameter("FechaInicio", txtFechaI.Text));
|
||||
@params.Add(new ReportParameter("FechaActual", DateTime.Now.ToShortDateString()));
|
||||
@params.Add(new ReportParameter("FechaFin", txtFechaF.Text));
|
||||
@params.Add(new ReportParameter("UsuarioImprimio", UsuarioActual.Nombre));
|
||||
@params.Add(new ReportParameter("FechaImpresion", DateTime.Now.ToShortDateString()));
|
||||
@params.Add(new ReportParameter("Cliente", DdlCliente.SelectedItem.Text));
|
||||
@params.Add(new ReportParameter("Usuario", DdlUsuario.SelectedItem.Text));
|
||||
@params.Add(new ReportParameter("FechaVencInicio", txtFechaVencI.Text));
|
||||
@params.Add(new ReportParameter("FechaVencFin", txtFechaVencF.Text));
|
||||
@params.Add(new ReportParameter("NombreEmpresa", UsuarioActual.Empresa.Empresa));
|
||||
@params.Add(new ReportParameter("Estatus", DdlEstatus.SelectedItem.Text));
|
||||
|
||||
var logouri = string.Format("{0}://{1}:{2}/Empresas/{3}/Logo.png", Request.Url.Scheme, Request.Url.Host, Request.Url.Port, UsuarioActual.CveEmpresa);
|
||||
System.IO.FileInfo Imagen = new System.IO.FileInfo(string.Format("{0}/Logo.png", UsuarioActual.Empresa.Ruta));
|
||||
|
||||
if (Imagen.Exists)
|
||||
{
|
||||
@params.Add(new ReportParameter("LogoPath", logouri));
|
||||
}
|
||||
else
|
||||
{
|
||||
@params.Add(new ReportParameter("LogoPath", ""));
|
||||
}
|
||||
|
||||
ImprimirPDF("Empresas/Grales/Formatos/FormatoRefrendo.rdlc", TmpDT, @params, "FormatoRefrendo", Formato);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region "MODAL"
|
||||
|
||||
protected void DdlClientesRef_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (DdlClientesRef.SelectedValue.ToString() == "0")
|
||||
{
|
||||
TxtClienteEspecifico.Visible = true;
|
||||
LblClienteEspecifico.Text = "Cliente Específico:";
|
||||
LblClienteEspecifico.Visible = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
TxtClienteEspecifico.Visible = false;
|
||||
TxtClienteEspecifico.Text = "";
|
||||
|
||||
LblClienteEspecifico.Text = "";
|
||||
LblClienteEspecifico.Visible = false;
|
||||
}
|
||||
UPModalRefrendo.Update();
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected void DdlTipoDocto_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (DdlTipoDocto.SelectedValue.ToString() == "4")
|
||||
{
|
||||
DivLigaDocto.Visible = true;
|
||||
TxtLigaDocumento.Text = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
DivLigaDocto.Visible = false;
|
||||
TxtLigaDocumento.Text = "";
|
||||
}
|
||||
UPModalRefrendo.Update();
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user