RepLienasAdicionales

This commit is contained in:
Oscar Irigoyen
2022-09-20 18:33:53 -07:00
parent f6240d7adc
commit dcbff66a3b
6 changed files with 529 additions and 45 deletions

View File

@@ -0,0 +1,254 @@
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;
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 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();
}
}
private void InicializaValores()
{
if (Request["OP"] != null && Request["OP"].ToString() == "PO")
{
DVProveedor1.Visible = true;
DVProveedor2.Visible = true;
GvLineasAdicionales.Columns[9].Visible = true;
}
//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.ToShortDateString();
}
protected void BtnConsultar_Click(object sender, EventArgs e)
{
CargaDatos();
}
private void CargaDatos()
{
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,-1,-1,txtFechaI.Text.ToDate(), txtFechaF.Text.ToDate(), -1, UsuarioActual.CveEmpresa)){
GvLineasAdicionales.DataSource = objVentas.DtResultados;
if( objVentas.DtResultados.Rows.Count > 0)
{
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)
{
GvLineasAdicionales.ExportToExcel2("RepLineas");