322 lines
11 KiB
C#
322 lines
11 KiB
C#
using System;
|
|
using System.Web.UI.WebControls;
|
|
using Extensiones;
|
|
using System.Data;
|
|
using static Extensiones.ModExtensiones;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using ListItem = System.Web.UI.WebControls.ListItem;
|
|
using DocumentFormat.OpenXml.Spreadsheet;
|
|
using System.Web.UI;
|
|
|
|
public partial class Ventas_RepLineasAdicionales : ClsPaginas
|
|
{
|
|
#region PROPIEDADES
|
|
|
|
private int CveLineaAdicional
|
|
{
|
|
get { return (ViewState["CveLineaAdicional"] == null) ? 0 : int.Parse(ViewState["CveLineaAdicional"].ToString()); }
|
|
set { ViewState["CveLineaAdicional"] =(int) value; }
|
|
}
|
|
|
|
private int TipoLinea
|
|
{
|
|
get { return (ViewState["TipoLinea"] == null) ? 1: int.Parse(ViewState["TipoLinea"].ToString()); }
|
|
set { ViewState["TipoLinea"] = (int)value; }
|
|
}
|
|
|
|
private DataTable DTDatosGvLineasAdicionales
|
|
{
|
|
get
|
|
{
|
|
if (ViewState["DTDatosGvLineasAdicionales"] == null)
|
|
{
|
|
ViewState["DTDatosGvLineasAdicionales"] = new DataTable();
|
|
}
|
|
return (DataTable)ViewState["DTDatosGvLineasAdicionales"];
|
|
}
|
|
set { ViewState["DTDatosGvLineasAdicionales"] = (DataTable)value; }
|
|
}
|
|
|
|
private string Comprobante
|
|
{
|
|
get {
|
|
|
|
if(ViewState["Comprobante"] == null)
|
|
{
|
|
ViewState["Comprobante"] = "";
|
|
}
|
|
|
|
return ViewState["Comprobante"].ToString();
|
|
}
|
|
set { ViewState["Comprobante"] = value; }
|
|
}
|
|
|
|
#endregion
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
if (!IsPostBack)
|
|
{
|
|
InicializaValores();
|
|
CargaDatos();
|
|
}
|
|
}
|
|
|
|
private void InicializaValores()
|
|
{
|
|
|
|
if (Request["OP"] != null && Request["OP"].ToString() == "PO")
|
|
{
|
|
DVProveedor1.Visible = true;
|
|
DVProveedor2.Visible = true;
|
|
GvLineasAdicionales.Columns[8].Visible = true;
|
|
TipoLinea = 2;
|
|
LtlEncabezado.Text = "Reporte PO";
|
|
}
|
|
|
|
//Carga Clientes
|
|
DdlClientes.DataSource = get_GlobalDTCliente(UsuarioActual.CveEmpresa, -1);
|
|
DdlClientes.DataBind();
|
|
|
|
if(UsuarioActual.Empresa.Funcionalidad(105) == "1") {
|
|
DdlProveedor.setEsWebService(true);
|
|
DdlProveedor.Attributes.Add("data-metodo", "getproveedores");
|
|
DdlProveedor.SelectedText = "Todos";
|
|
DdlProveedor.SelectedValue = "-1";
|
|
}else {
|
|
DdlProveedor.setEsWebService(false);
|
|
DdlProveedor.ddl.DataSource = get_GlobalDTCompProveedores(UsuarioActual.CveEmpresa);
|
|
DdlProveedor.ddl.DataBind();
|
|
DdlProveedor.ddl.Items.Insert(0, new ListItem("-", "-1"));
|
|
}
|
|
|
|
DdlClientes.setEsWebService(true);
|
|
DdlClientes.Attributes.Add("data-metodo", "getcliente");
|
|
DdlClientes.SelectedText = "Todos";
|
|
DdlClientes.SelectedValue = "-1";
|
|
|
|
txtFechaI.Text = DateTime.Now.FirstDayOfMonth().ToShortDateString();
|
|
txtFechaF.Text = DateTime.Now.AddMonths(3).ToString("dd/MM/yyyy");
|
|
|
|
}
|
|
|
|
|
|
protected void BtnConsultar_Click(object sender, EventArgs e)
|
|
{
|
|
CargaDatos();
|
|
}
|
|
|
|
private void CargaDatos()
|
|
{
|
|
DTDatosGvLineasAdicionales = new DataTable();
|
|
LnkDescargaExcel.Visible = false;
|
|
|
|
ClsVentas objVentas = new ClsVentas();
|
|
|
|
int CveProveedor = DdlProveedor.SelectedValue.ToEntero() > 0 ? DdlProveedor.SelectedValue.ToEntero() : -1;
|
|
|
|
if(objVentas.GetLineasAdicionales(-1,DdlClientes.SelectedValue.ToEntero(),CveProveedor, TipoLinea, -1,txtFechaI.Text.ToDate(), txtFechaF.Text.ToDate(), DdlEstatus.SelectedValue.ToEntero(), UsuarioActual.CveEmpresa)){
|
|
GvLineasAdicionales.DataSource = objVentas.DtResultados;
|
|
|
|
if( objVentas.DtResultados.Rows.Count > 0)
|
|
{
|
|
DTDatosGvLineasAdicionales = objVentas.DtResultados;
|
|
LnkDescargaExcel.Visible = true;
|
|
UpAcciones.Update();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
GvLineasAdicionales.DataSource = null;
|
|
}
|
|
|
|
objVentas.Dispose();
|
|
|
|
GvLineasAdicionales.DataBind();
|
|
UpLineasAdicionales.Update();
|
|
}
|
|
|
|
|
|
protected void LnkCargarComprobante_Click(object sender, EventArgs e)
|
|
{
|
|
GridViewRow GvRow = (GridViewRow) ((LinkButton) sender).NamingContainer;
|
|
|
|
CveLineaAdicional = GvRow.DataKey("CveLineaAdicional").ToString().ToEntero();
|
|
Comprobante = GvRow.DataKey("Comprobante").ToString();
|
|
|
|
RegistraScript("$('#ModalComprobante').modal('show');","");
|
|
}
|
|
|
|
protected void BtnAddComprobante_Click(object sender, EventArgs e)
|
|
{
|
|
bool errorCargaComprobante = false;
|
|
string FileExtension = "-1";
|
|
List<Archivo> filesgral = Anexo.getfiles().Archivos;
|
|
string filemove = "";
|
|
FileInfo fiNuevo;
|
|
|
|
DirectoryInfo df = new DirectoryInfo($@"{UsuarioActual.Empresa.Ruta}\LineasAdicionales\");
|
|
|
|
|
|
//Crea directorio si no existe
|
|
if (!df.Exists)
|
|
{
|
|
try
|
|
{
|
|
Directory.CreateDirectory(df.FullName);
|
|
}
|
|
catch
|
|
{
|
|
errorCargaComprobante = true;
|
|
}
|
|
}
|
|
|
|
//borrar archivo anterior
|
|
if((!errorCargaComprobante) && Comprobante.Length > 0)
|
|
{
|
|
FileInfo fiAnterior = new FileInfo($@"{df.FullName}{Comprobante}");
|
|
if (fiAnterior.Exists)
|
|
{
|
|
try
|
|
{
|
|
File.Delete(fiAnterior.FullName);
|
|
}
|
|
catch
|
|
{
|
|
errorCargaComprobante = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
if(!errorCargaComprobante){
|
|
|
|
string RutaArchivoTemp = "";
|
|
foreach (Archivo fileItem in filesgral)
|
|
{
|
|
FileExtension = System.IO.Path.GetExtension(string.Format(@"{0}Temp\{1}", AppDomain.CurrentDomain.BaseDirectory, fileItem.filename)).Replace(".", "");
|
|
filemove = fileItem.filename;
|
|
RutaArchivoTemp = $@"{AppDomain.CurrentDomain.BaseDirectory}\Temp\{fileItem.filename}";
|
|
|
|
break;
|
|
}
|
|
|
|
if((!errorCargaComprobante) && RutaArchivoTemp.Length > 0)
|
|
{
|
|
fiNuevo = new FileInfo(RutaArchivoTemp);
|
|
|
|
if (fiNuevo.Exists)
|
|
{
|
|
try
|
|
{
|
|
|
|
if (File.Exists($@"{df.FullName}\{CveLineaAdicional}{fiNuevo.Extension}"))
|
|
{
|
|
File.Delete($@"{df.FullName}\{CveLineaAdicional}{fiNuevo.Extension}");
|
|
}
|
|
|
|
File.Move(fiNuevo.FullName, $@"{df.FullName}\{CveLineaAdicional}{fiNuevo.Extension}");
|
|
errorCargaComprobante = false;
|
|
}
|
|
catch
|
|
{
|
|
errorCargaComprobante = true;
|
|
}
|
|
|
|
if (!errorCargaComprobante)
|
|
{
|
|
ClsVentas objVentas = new ClsVentas();
|
|
if (!objVentas.UpdateLineasAdicionales(CveLineaAdicional, "-1", -1, -1, -1, -1, -1, MinFecha, 100, -1, -1, UsuarioActual.CveEmpresa, Comprobante: $@"{CveLineaAdicional}{fiNuevo.Extension}"))
|
|
{
|
|
errorCargaComprobante = true;
|
|
}
|
|
objVentas.Dispose();
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
if (!errorCargaComprobante)
|
|
{
|
|
CargaDatos();
|
|
Anexo.Text = "[]";
|
|
RegistraScript("$('#ModalComprobante').modal('hide');", "");
|
|
Alert("Comprbante actualizado correctamente.");
|
|
}
|
|
|
|
UpAddComprobancte.Update();
|
|
}
|
|
|
|
protected void LnkCambiarEstatus_Click(object sender, EventArgs e)
|
|
{
|
|
GridViewRow GvRow = (GridViewRow)((LinkButton)sender).NamingContainer;
|
|
int CveLineaAdicionalActualzarEstatus = GvRow.DataKey("CveLineaAdicional").ToString().ToEntero();
|
|
bool errorCambioEstatus = false;
|
|
|
|
ClsVentas objVentas = new ClsVentas();
|
|
|
|
if (!objVentas.UpdateLineasAdicionales(CveLineaAdicionalActualzarEstatus, "-1", -1, -1, -1, -1, -1, MinFecha, 100, -1, 3, UsuarioActual.CveEmpresa))
|
|
{
|
|
errorCambioEstatus = true;
|
|
}
|
|
|
|
if (!errorCambioEstatus)
|
|
{
|
|
CargaDatos();
|
|
}
|
|
objVentas.Dispose();
|
|
}
|
|
|
|
|
|
protected void LnkDescargaExcel_Click(object sender, EventArgs e)
|
|
{
|
|
GridView gvTemp = GvLineasAdicionales;
|
|
gvTemp.Columns[8].Visible = false;
|
|
gvTemp.ExportToExcelx( TipoLinea == 1 ? "RepLienasAdicionales":"RepPO");
|
|
}
|
|
|
|
|
|
|
|
protected void GvLineasAdicionales_RowDataBound(object sender, GridViewRowEventArgs e)
|
|
{
|
|
if(e.Row.RowType == DataControlRowType.DataRow)
|
|
{
|
|
if(e.Row.DataKey("CveEstatus").ToEntero().Contiene(2))
|
|
{
|
|
e.Row.FCLinkButton("LnkCambiarEstatus").Visible = true;
|
|
}
|
|
|
|
if (e.Row.DataKey("CveEstatus").ToEntero() == 3)
|
|
{
|
|
e.Row.FCLinkButton("LnkCargarComprobante").Visible = false;
|
|
}
|
|
|
|
if (e.Row.DataKey("Comprobante").Length > 0)
|
|
{
|
|
FileInfo fi = new FileInfo($@"{UsuarioActual.Empresa.Ruta}\LineasAdicionales\{e.Row.DataKey("Comprobante")}");
|
|
LinkButton LnkDescargaComprobante = e.Row.FCLinkButton("LnkDescargaComprobante");
|
|
|
|
if (fi.Exists)
|
|
{
|
|
LnkDescargaComprobante.Visible = true;
|
|
ScriptManager.GetCurrent(this).RegisterPostBackControl(LnkDescargaComprobante);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
protected void LnkDescargaComprobante_Click(object sender, EventArgs e)
|
|
{
|
|
GridViewRow GvRow = (GridViewRow)((LinkButton)sender).NamingContainer;
|
|
string Comprobante = GvRow.DataKey("Comprobante");
|
|
FileInfo fi = new FileInfo($@"{UsuarioActual.Empresa.Ruta}\LineasAdicionales\{Comprobante}");
|
|
|
|
if (fi.Exists)
|
|
{
|
|
Response.Clear();
|
|
Response.AddHeader("Content-Disposition", "attachment; filename=" + fi.Name);
|
|
Response.AddHeader("Content-Length", fi.Length.ToString());
|
|
Response.ContentType = "text/octet-stream";
|
|
Response.Flush();
|
|
Response.TransmitFile(fi.FullName);
|
|
Response.End();
|
|
}
|
|
}
|
|
} |