1201 lines
50 KiB
Plaintext
1201 lines
50 KiB
Plaintext
|
|
Option Explicit On
|
|
Option Strict On
|
|
|
|
Imports System.Data
|
|
Imports System.IO
|
|
Imports Extensiones
|
|
Imports GemBox.Spreadsheet
|
|
Imports Microsoft.Reporting.WebForms
|
|
Imports ZXing
|
|
|
|
Partial Class Ventas_ActualizarPrecios
|
|
Inherits ClsPaginas
|
|
|
|
Private Property DtListasPrecios As DataTable
|
|
Get
|
|
Return If(IsNothing(ViewState("DtListasPrecios")), Nothing, CType(ViewState("DtListasPrecios"), DataTable))
|
|
End Get
|
|
Set(value As DataTable)
|
|
ViewState("DtListasPrecios") = value
|
|
End Set
|
|
End Property
|
|
|
|
Private Property DtSubProyectos As DataTable
|
|
Get
|
|
Return If(IsNothing(ViewState("DtSubProyectos")), Nothing, CType(ViewState("DtSubProyectos"), DataTable))
|
|
End Get
|
|
Set(value As DataTable)
|
|
ViewState("DtSubProyectos") = value
|
|
End Set
|
|
End Property
|
|
|
|
Private Property DtDatosPrecios As DataTable
|
|
Get
|
|
Return If(IsNothing(ViewState("DtDatosPrecios")), Nothing, CType(ViewState("DtDatosPrecios"), DataTable))
|
|
End Get
|
|
Set(value As DataTable)
|
|
ViewState("DtDatosPrecios") = value
|
|
End Set
|
|
End Property
|
|
|
|
Private Property DtPreciosMultiple As DataTable
|
|
Get
|
|
Return If(IsNothing(ViewState("DtPreciosMultiple")), Nothing, CType(ViewState("DtPreciosMultiple"), DataTable))
|
|
End Get
|
|
Set(value As DataTable)
|
|
ViewState("DtPreciosMultiple") = value
|
|
End Set
|
|
End Property
|
|
|
|
Private Property CveSucursal As Integer
|
|
Get
|
|
If ViewState("CveSucursal") Is Nothing Then
|
|
Return -1
|
|
Else
|
|
Return ViewState("CveSucursal").ToString.ToEntero
|
|
End If
|
|
End Get
|
|
Set(value As Integer)
|
|
ViewState("CveSucursal") = value
|
|
End Set
|
|
End Property
|
|
|
|
Private Property CvePS As Integer
|
|
Get
|
|
If ViewState("CvePS") Is Nothing Then
|
|
Return -1
|
|
Else
|
|
Return ViewState("CvePS").ToString.ToEntero
|
|
End If
|
|
End Get
|
|
Set(value As Integer)
|
|
ViewState("CvePS") = value
|
|
End Set
|
|
End Property
|
|
|
|
Private Property PS As String
|
|
Get
|
|
If ViewState("PS") Is Nothing Then
|
|
Return ""
|
|
Else
|
|
Return ViewState("PS").ToString
|
|
End If
|
|
End Get
|
|
Set(value As String)
|
|
ViewState("PS") = value
|
|
End Set
|
|
End Property
|
|
|
|
Private Property PermisoEdicionLista As Boolean
|
|
Get
|
|
If ViewState("BloquearEdicionListas") Is Nothing Then
|
|
ViewState("BloquearEdicionListas") = True
|
|
End If
|
|
Return Boolean.Parse(ViewState("BloquearEdicionListas").ToString)
|
|
End Get
|
|
Set(value As Boolean)
|
|
ViewState("BloquearEdicionListas") = value
|
|
End Set
|
|
End Property
|
|
|
|
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
|
|
If Not Page.IsPostBack Then
|
|
If UsuarioActual.Empresa.Funcionalidad(578) = "1" Then
|
|
LblModalidad.Visible = True
|
|
DivModalidad.Visible = True
|
|
End If
|
|
If UsuarioActual.CveEmpresa.Contiene(189, 190, 192, 193) Then
|
|
LblModalidad.Visible = True
|
|
DivModalidad.Visible = True
|
|
End If
|
|
|
|
If UsuarioActual.TienePermisoProceso(282) Then
|
|
PermisoEdicionLista = False
|
|
DivActualizarPrecio.Visible = False
|
|
HlAgregarExcel.Visible = False
|
|
End If
|
|
|
|
CargaCombos()
|
|
|
|
End If
|
|
End Sub
|
|
Public Sub CargaCombos()
|
|
CargaDDlClasif()
|
|
CargaPS()
|
|
CargaPreciosLista()
|
|
CargaProveedores()
|
|
CargarMarcas()
|
|
CargarModelos()
|
|
End Sub
|
|
Public Sub CargaDDlClasif()
|
|
DDlClasificacion.DataSource = GlobalDTClasificaciones(UsuarioActual.CveEmpresa)
|
|
DDlClasificacion.DataBind()
|
|
DDlClasificacion.Items.Insert(0, New ListItem("Todos", "-1"))
|
|
End Sub
|
|
|
|
Public Sub CargaPreciosLista()
|
|
|
|
DdlPrecioLista.Items.Clear()
|
|
|
|
If UsuarioActual.Empresa.Funcionalidad(404).ToEntero > 0 Then 'si maneja precios de lista
|
|
|
|
Dim primerItem As String = ""
|
|
|
|
DtListasPrecios = GlobalDTPrecioListas(UsuarioActual.CveEmpresa).Copy()
|
|
DdlPrecioLista.DataSource = DtListasPrecios
|
|
DdlPrecioListaCarga.DataSource = DtListasPrecios
|
|
DdlMultiplePrecioLista.DataSource = DtListasPrecios
|
|
primerItem = DtListasPrecios.FiltroPrimeroValor("CvePrecioLista")
|
|
|
|
DdlPrecioLista.DataBind()
|
|
DdlPrecioListaCarga.DataBind()
|
|
DdlMultiplePrecioLista.DataBind()
|
|
|
|
Dim SeleccionMaxima As Integer = 14
|
|
If DtListasPrecios IsNot Nothing Then
|
|
If (DtListasPrecios.Rows.Count - 1) < 14 Then
|
|
SeleccionMaxima = DtListasPrecios.Rows.Count - 1
|
|
End If
|
|
|
|
Dim sbMultiple As New StringBuilder
|
|
For Each Row As DataRow In DtListasPrecios.FiltraPorIndices(0, SeleccionMaxima).Rows
|
|
sbMultiple.AppendFormat("{0},", Row("CvePrecioLista"))
|
|
Next
|
|
DdlMultiplePrecioLista.SelectedValuesIfExistM(sbMultiple.ToString(), True)
|
|
|
|
If (DdlPrecioLista.Items.Count = 1) Then
|
|
DdlPrecioLista.Items.FindByValue(primerItem).Selected = True
|
|
End If
|
|
End If
|
|
|
|
Else
|
|
DdlPrecioLista.Items.Insert(0, New ListItem("Sin Precio Lista", "-2"))
|
|
DdlPrecioListaCarga.Items.Insert(0, New ListItem("Sin Precio Lista", "-2"))
|
|
End If
|
|
|
|
End Sub
|
|
|
|
Public Sub CargaPS()
|
|
'FUNCIONALIDAD 105
|
|
If UsuarioActual.Empresa.Funcionalidad(105) = "1" Then
|
|
DDlPs.setEsWebService(True)
|
|
Else
|
|
DDlPs.setEsWebService(False)
|
|
|
|
'FUNCIONALIDAD DE COMPUESTO
|
|
If UsuarioActual.Empresa.Funcionalidad(143) = "1" Then
|
|
DDlPs.ddl.DataTextField = "PSCodigoCompuesto"
|
|
End If
|
|
|
|
DDlPs.DataSource = GlobalDTPSSimplificado(UsuarioActual.CveEmpresa)
|
|
DDlPs.DataBind()
|
|
|
|
DDlPs.ddl.Items.Insert(0, New ListItem("Todos", "-1"))
|
|
End If
|
|
End Sub
|
|
Private Sub CargaProveedores()
|
|
If UsuarioActual.Empresa.Funcionalidad(524) <> "" Then
|
|
DdlProveedor.setEsWebService(True)
|
|
DivProveedorCompra.Visible = True
|
|
LblProveedorCompra.Visible = True
|
|
End If
|
|
End Sub
|
|
Protected Sub CargarMarcas()
|
|
If UsuarioActual.Empresa.Funcionalidad(130) = "1" Then
|
|
Dim ObjMarcas As New ClsProductosServicios
|
|
If ObjMarcas.GetMarcas(UsuarioActual.CveEmpresa) Then
|
|
DdlMarca.DataSource = ObjMarcas.DtResultados.Copy
|
|
End If
|
|
ObjMarcas.Dispose()
|
|
DdlMarca.DataBind()
|
|
|
|
LblMarca.Visible = True
|
|
DivMarca.Visible = True
|
|
End If
|
|
|
|
DdlMarca.Items.Insert(0, New ListItem("Todos", "-1"))
|
|
End Sub
|
|
Private Sub CargarModelos()
|
|
If UsuarioActual.Empresa.Funcionalidad(558).ToString = "1" Then
|
|
lblModelo.Visible = True
|
|
DivModelo.Visible = True
|
|
Dim ObjGeneral As New ClsGenerales
|
|
If ObjGeneral.GetModelos(UsuarioActual.CveEmpresa) Then
|
|
DdlModelo.DataSource = ObjGeneral.DtResultados
|
|
End If
|
|
ObjGeneral.Dispose()
|
|
DdlModelo.DataBind()
|
|
End If
|
|
DdlModelo.Items.Insert(0, New ListItem("Seleccione", "-1"))
|
|
|
|
End Sub
|
|
Protected Sub BtnConsultar_Click(sender As Object, e As EventArgs)
|
|
|
|
Dim CveProveedor As Integer = -1
|
|
Dim CvePS As Integer = -1
|
|
Dim Marcas As String = If(DdlMarca.GetSelectedValuesM = "", "-1", DdlMarca.GetSelectedValuesM)
|
|
|
|
If DDlPs.SelectedValue.ToEntero > 0 Then
|
|
CvePS = DDlPs.SelectedValue.ToEntero
|
|
End If
|
|
|
|
If DdlProveedor.txtValue.Value.ToEntero > 0 Then
|
|
CveProveedor = DdlProveedor.txtValue.Value.ToEntero
|
|
End If
|
|
|
|
'POR LISTA DE PRECIO
|
|
If DdlModalidad.SelectedValue = "1" Then
|
|
Dim objPS As New ClsProductosServicios
|
|
If objPS.GetPSPreciosLista(UsuarioActual.CveEmpresa, DdlPrecioLista.SelectedValue.ToEntero, DDlClasificacion.SelectedValue.ToEntero, CvePS,
|
|
CveProveedor:=CveProveedor, Estado:=DdlEstado.SelectedValue.ToEntero, Marcas:=Marcas, CveModelo:=DdlModelo.SelectedValue.ToEntero) Then
|
|
DtDatosPrecios = objPS.DtResultados
|
|
GVPrecios.DataSource = DtDatosPrecios
|
|
End If
|
|
objPS.Dispose()
|
|
|
|
If UsuarioActual.Empresa.Funcionalidad(531) = "1" Then 'Empresa Acumuladores
|
|
GVPrecios.Columns(2).Visible = True
|
|
End If
|
|
|
|
If UsuarioActual.CveEmpresa = 153 Then 'Empresa servec
|
|
GVPrecios.Columns(11).Visible = True
|
|
End If
|
|
|
|
dvDatos.Visible = True
|
|
dvMultiple.Visible = False
|
|
|
|
DivActualizarPrecio.Visible = True
|
|
|
|
If UsuarioActual.TienePermisoProceso(282) Then
|
|
DivActualizarPrecio.Visible = False
|
|
End If
|
|
|
|
GVPrecios.DataBind()
|
|
End If
|
|
|
|
'MULTIPLE LISTAS DE PRECIO
|
|
If DdlModalidad.SelectedValue = "2" Then
|
|
|
|
Dim ListasPrecios As String = If(DdlMultiplePrecioLista.GetSelectedValuesM = "", "-1", DdlMultiplePrecioLista.GetSelectedValuesM)
|
|
|
|
Dim objPS As New ClsProductosServicios
|
|
If objPS.GetPSMultiplesPreciosLista(UsuarioActual.CveEmpresa, ListasPrecios:=ListasPrecios, CveClasificacion:=DDlClasificacion.SelectedValue.ToEntero, CvePS:=CvePS,
|
|
CveProveedor:=CveProveedor, Estado:=DdlEstado.SelectedValue.ToEntero, Marcas:=Marcas, CveModelo:=DdlModelo.SelectedValue.ToEntero) Then
|
|
DtPreciosMultiple = objPS.DtResultados.Copy()
|
|
GvMultiple.DataSource = DtPreciosMultiple
|
|
End If
|
|
objPS.Dispose()
|
|
|
|
dvDatos.Visible = False
|
|
dvMultiple.Visible = True
|
|
DivActualizarPrecio.Visible = False
|
|
|
|
For colIndex As Integer = 2 To GvMultiple.Columns.Count - 1
|
|
If colIndex <= DtPreciosMultiple.Columns.Count - 1 Then
|
|
GvMultiple.Columns(colIndex).Visible = True
|
|
Else
|
|
GvMultiple.Columns(colIndex).Visible = False
|
|
End If
|
|
Next
|
|
|
|
GvMultiple.DataBind()
|
|
End If
|
|
|
|
|
|
UpDescargar.Update()
|
|
UpDatos.Update()
|
|
UPPrecioLista.Update()
|
|
End Sub
|
|
Protected Sub DDlClasificacion_SelectedIndexChanged(sender As Object, e As EventArgs)
|
|
CargaPS()
|
|
UpEncabezado.Update()
|
|
End Sub
|
|
Protected Sub RblTipo_SelectedIndexChanged(sender As Object, e As EventArgs)
|
|
If RblTipo.SelectedValue = "Imp" Then
|
|
ImporteFijo.Visible = True
|
|
Else
|
|
ImporteFijo.Visible = False
|
|
End If
|
|
UPPrecioLista.Update()
|
|
End Sub
|
|
Protected Sub BtnGuardar_Click(sender As Object, e As EventArgs) Handles BtnGuardar.Click
|
|
If RblTipo.SelectedIndex = 1 And TxtPorcentaje.Text.ToDecimal = 0 Then
|
|
Alert("Se debe de especificar un porcentaje.", TipoMensaje.MsgAdvertencia)
|
|
Exit Sub
|
|
End If
|
|
|
|
Dim TieneError As Boolean = False
|
|
'Dim Importe As Decimal = If(TxtImporte.Text = "", -1, TxtImporte.Text.ToDecimal)
|
|
Dim Porcentaje As Decimal = If(TxtPorcentaje.Text = "", -1, TxtPorcentaje.Text.ToDecimal)
|
|
Dim MensajeAlert As New StringBuilder
|
|
Dim sbProductos As New StringBuilder
|
|
|
|
Dim ObjPS As New ClsProductosServicios
|
|
ObjPS.IniciaTransacSQL()
|
|
Try
|
|
For Each row As GridViewRow In GVPrecios.Rows
|
|
If row.FCCheckBox("chkPS").Checked Then
|
|
TieneError = Not ObjPS.UpdatePSPreciosLista(row.FCTextBox("TxtPrecio").Text.ToDecimal, DdlPrecioLista.SelectedValue.ToEntero, Porcentaje, row.DataKey("CvePS").ToEntero, UsuarioActual.CveUsuario, NowADS(), If(RblTipo.SelectedValue = "Imp", True, False), PrecioMinimo:=row.FCTextBox("TxtPrecioMinimo").Text.ToDecimal)
|
|
If CBool(row.DataKey("ProductoExhibicion")) Then
|
|
sbProductos.AppendFormat("{0},", row.DataKey("CvePS").ToEntero)
|
|
End If
|
|
|
|
|
|
If Not TieneError Then
|
|
TieneError = ActualizarPreciosFranquicia(ObjPS, row.DataKey("Codigo"), row.FCTextBox("TxtPrecio").Text.ToDecimal, row.FCTextBox("TxtPrecioMinimo").Text.ToDecimal, DdlPrecioLista.SelectedItem.Text)
|
|
Else
|
|
Exit For
|
|
End If
|
|
End If
|
|
Next
|
|
|
|
If Not TieneError Then
|
|
If UsuarioActual.Empresa.Funcionalidad(109) = "1" AndAlso sbProductos.Length > 0 Then
|
|
MensajeAlert.AppendFormat("Los precios de lista de los productos/servicios se actualizaron correctamente. <br/> <b><a target='_blank' class='Texto' href=""/Compras/PopUpVerFactura.aspx?P={0}"">Descargar Etiquetas</a></b>", Encripta(String.Format("OP=ETIQUETA&CVEPRECIOLISTA={0}&PRODUCTOS={1}", DdlPrecioLista.SelectedValue.ToEntero, sbProductos.ToString())))
|
|
ImprimirEtiquetas(sbProductos.ToString())
|
|
Else
|
|
MensajeAlert.Append("Los precios de lista de los productos/servicios se actualizaron correctamente.")
|
|
End If
|
|
|
|
Alert(MensajeAlert.ToString())
|
|
End If
|
|
Catch ex As Exception
|
|
TieneError = True
|
|
GuardaLog(ex.ToString())
|
|
End Try
|
|
|
|
If TieneError Then
|
|
ObjPS.RollBack()
|
|
Alert("Ocurrió un error al actualizar precios", TipoMensaje.MsgError)
|
|
Else
|
|
ObjPS.Commit()
|
|
End If
|
|
|
|
ObjPS.Dispose()
|
|
BtnConsultar_Click(Nothing, Nothing)
|
|
RegistraScript("$('#divAgregar').modal('hide')")
|
|
TxtImporte.Text = ""
|
|
TxtPrecio.Text = ""
|
|
TxtPorcentaje.Text = ""
|
|
End Sub
|
|
|
|
#Region "MODAL PRECIOS MINIMOS"
|
|
Public Sub LnkPrecioMinActual_Click(sender As Object, e As EventArgs)
|
|
|
|
Dim GvRow As GridViewRow = DirectCast(DirectCast(sender, LinkButton).NamingContainer, GridViewRow)
|
|
|
|
CvePS = GvRow.DataKey("CvePS").ToEntero
|
|
PS = GvRow.DataKey("PS").ToString
|
|
|
|
TxtAplicarPrecio.Text = ""
|
|
|
|
CargaDatosModalPreciosMinimos()
|
|
|
|
RegistraScript("$('#ModalActualizaPrecios').modal({ backdrop: 'static', keyboard: false}); $('#ChkSeleccionarTodos').find('input[type=checkbox]').prop('checked', false);")
|
|
|
|
End Sub
|
|
|
|
|
|
Protected Sub LnkModalGuardarPreciosMinimos_Click(sender As Object, e As EventArgs)
|
|
ProcesaPreciosSucursales()
|
|
CargaDatosModalPreciosMinimos()
|
|
End Sub
|
|
|
|
Private Sub CargaDatosModalPreciosMinimos()
|
|
|
|
|
|
Dim ObjPS As New ClsProductosServicios
|
|
If ObjPS.GetPSSucursales(CvePS, UsuarioActual.CveEmpresa) Then
|
|
gvSucursal.DataSource = ObjPS.DtResultados
|
|
End If
|
|
|
|
ObjPS.Dispose()
|
|
gvSucursal.DataBind()
|
|
LtlModalTitleUpModalTitulo.Text = PS
|
|
UpModalActualizaPrecios.Update()
|
|
UpModalTitulo.Update()
|
|
|
|
End Sub
|
|
|
|
Private Sub ProcesaPreciosSucursales()
|
|
|
|
Dim ObjProductosServicios As New ClsProductosServicios()
|
|
|
|
For i As Integer = 0 To gvSucursal.Rows.Count - 1
|
|
|
|
If gvSucursal.Rows(i).FCCheckBox("chkSucursal").Checked Then
|
|
|
|
If gvSucursal.Rows(i).FCHiddenField("hdnEnBD").Value.ToEntero = 1 Then
|
|
ObjProductosServicios.UpdatePSSucursales(CvePS, -1, gvSucursal.Rows(i).FCTextBox("TxtMinimo").Text.ToDouble, -1, UsuarioActual.CveUsuario, gvSucursal.Rows(i).DataKey("CveSubProyecto").ToEntero, PrecioMinimo:=gvSucursal.Rows(i).FCTextBox("TxtPrecioMinimo").Text.ToDecimal)
|
|
Else
|
|
ObjProductosServicios.AddPSSucursales(CvePS, Nothing, gvSucursal.Rows(i).FCTextBox("TxtMinimo").Text.ToDouble, -1, UsuarioActual.CveUsuario, gvSucursal.Rows(i).DataKey("CveSubProyecto").ToEntero, PrecioMinimo:=gvSucursal.Rows(i).FCTextBox("TxtPrecioMinimo").Text.ToDecimal)
|
|
End If
|
|
|
|
End If
|
|
Next
|
|
|
|
ObjProductosServicios.Dispose()
|
|
|
|
End Sub
|
|
|
|
#End Region
|
|
|
|
#Region "C A R G A R E X C E L "
|
|
Private Sub BtnDescargarFormato_Click(sender As Object, e As EventArgs) Handles BtnDescargarFormato.Click
|
|
|
|
Dim DtExcel As DataTable = (From row As GridViewRow In GVPrecios.Rows.Cast(Of GridViewRow)
|
|
Where row.RowType = DataControlRowType.DataRow
|
|
Select New With
|
|
{
|
|
.Codigo = row.DataKey("Codigo"),
|
|
.NumeroParte = row.DataKey("NumeroParte"),
|
|
.PS = row.DataKey("PS"),
|
|
.Precio = row.FCTextBox("TxtPrecio").Text.ToDecimal()
|
|
}).QueryToDataTable(True)
|
|
If DtExcel.Rows.Count < 1 Then
|
|
Alert("No hay resultados en la busqueda.", TipoMensaje.MsgAdvertencia)
|
|
Exit Sub
|
|
End If
|
|
|
|
|
|
If DdlPrecioLista.SelectedItem IsNot Nothing Then
|
|
Dim worksheetName As String = DdlPrecioLista.SelectedItem.Text
|
|
|
|
Const invalidCharsRegex As String = "[/\\*'?[\]:]+"
|
|
Const maxLength As Integer = 31
|
|
Dim safeName As String = Regex.Replace(worksheetName, invalidCharsRegex, " ").Replace(" ", " ").Trim()
|
|
|
|
If String.IsNullOrEmpty(safeName) Then
|
|
safeName = "Precios" ' cannot be empty
|
|
ElseIf safeName.Length > maxLength Then
|
|
safeName = safeName.Substring(0, maxLength)
|
|
End If
|
|
|
|
DtExcel.TableName = safeName
|
|
Else
|
|
DtExcel.TableName = "Precios"
|
|
End If
|
|
|
|
|
|
DtExcel.Columns("Codigo").ColumnName = "Código"
|
|
DtExcel.Columns("PS").ColumnName = "Producto / Servicio"
|
|
DtExcel.Columns("NumeroParte").ColumnName = "Número de parte"
|
|
|
|
If UsuarioActual.Empresa.Funcionalidad(531) = "1" OrElse UsuarioActual.Empresa.Funcionalidad(578) = "1" Then 'Empresa Acumuladores
|
|
If UsuarioActual.Empresa.Funcionalidad(531) = "1" Then
|
|
DtExcel.Columns("Número de parte").ColumnName = "Código CPK"
|
|
End If
|
|
Else
|
|
DtExcel.Columns.Remove("Número de parte")
|
|
End If
|
|
|
|
SpreadsheetInfo.SetLicense(ModExtensiones.SerialGemBoxSpreadsheet)
|
|
|
|
Dim FileExcel As New ExcelFile()
|
|
|
|
Dim worksheet As ExcelWorksheet = FileExcel.Worksheets.Add(DtExcel.TableName)
|
|
worksheet.InsertDataTable(DtExcel, New InsertDataTableOptions() With
|
|
{
|
|
.ColumnHeaders = True,
|
|
.StartRow = 0,
|
|
.StartColumn = 0
|
|
})
|
|
worksheet.Rows(0).Style.FillPattern.SetPattern(FillPatternStyle.Solid, SpreadsheetColor.FromArgb(75, 119, 190), SpreadsheetColor.FromArgb(255, 255, 255))
|
|
worksheet.Rows(0).Style.Font.Color = SpreadsheetColor.FromArgb(255, 255, 255)
|
|
|
|
Dim columnCount As Integer = worksheet.CalculateMaxUsedColumns()
|
|
For i As Integer = 0 To columnCount
|
|
worksheet.Columns(i).AutoFit(1, worksheet.Rows(0), worksheet.Rows(worksheet.Rows.Count - 1))
|
|
Next
|
|
|
|
FileExcel.Save(Response, "Precios.xlsx", SaveOptions.XlsxDefault)
|
|
|
|
End Sub
|
|
Private Sub BtnCargaExcel_Click(sender As Object, e As EventArgs) Handles BtnCargaExcel.Click
|
|
|
|
If TxtExcel.getfiles().Archivos.Count > 0 Then
|
|
Dim file As Archivo = TxtExcel.getfiles().Archivos(0)
|
|
Dim Directorio As String = AppDomain.CurrentDomain.BaseDirectory & file.path
|
|
CargarArchivo(Directorio, file.filename)
|
|
Else
|
|
Alert("No existe el archivo. Favor de subir un archivo excel a la plataforma.", TipoMensaje.MsgError)
|
|
End If
|
|
End Sub
|
|
Private Sub CargarArchivo(Ruta As String, FileName As String)
|
|
SpreadsheetInfo.SetLicense(ModExtensiones.SerialGemBoxSpreadsheet)
|
|
Dim Tipo As String = "EXCEL"
|
|
Dim dt As DataTable = Nothing
|
|
Dim ErrorArchivo As Boolean = False
|
|
|
|
Try
|
|
dt = ReadExcelFile(Ruta + FileName, True)
|
|
Catch ex As Exception
|
|
ErrorArchivo = True
|
|
OnError("Ocurrio un error al leer el archivo <br/>" & ex.Message, ex)
|
|
End Try
|
|
If Not ErrorArchivo AndAlso dt IsNot Nothing Then
|
|
|
|
If DdlPrecioListaCarga.SelectedValue.ToEntero() = -1 Then
|
|
Alert("Debe Seleccionar la lista de precios a cargar. Favor de corregirlo", TipoMensaje.MsgError)
|
|
Exit Sub
|
|
End If
|
|
|
|
'LA PRIMERA COLUMNA SIEMRPE ES CODIGO
|
|
If Not dt.Columns(0).ColumnName = "Código" Then
|
|
Alert("El nombre de la primera columna debe ser 'Codigo'. Favor de corregirlo", TipoMensaje.MsgError)
|
|
Exit Sub
|
|
End If
|
|
|
|
Dim IndiceActualColExcel As Integer = 1
|
|
Dim StrColPos As String() = {"primera", "segunda", "tecera", "cuarta"}
|
|
|
|
'SI ES EMPRESA DE ACUMULADORES SE AGREGA LA COLUMNA "Código CPK"
|
|
If UsuarioActual.Empresa.Funcionalidad(531) = "1" Then
|
|
If Not dt.Columns(IndiceActualColExcel).ColumnName = "Código CPK" Then
|
|
Alert("El nombre de la segunda columna debe ser 'Código CPK'. Favor de corregirlo", TipoMensaje.MsgError)
|
|
Exit Sub
|
|
End If
|
|
|
|
IndiceActualColExcel += 1
|
|
End If
|
|
|
|
If UsuarioActual.Empresa.Funcionalidad(578) = "1" Then
|
|
If Not dt.Columns(IndiceActualColExcel).ColumnName = "Número de parte" Then
|
|
Alert("El nombre de la segunda columna debe ser 'Número de parte'. Favor de corregirlo", TipoMensaje.MsgError)
|
|
Exit Sub
|
|
End If
|
|
|
|
IndiceActualColExcel += 1
|
|
End If
|
|
|
|
If Not dt.Columns(IndiceActualColExcel).ColumnName = "Producto / Servicio" Then
|
|
Alert($"El nombre de la {StrColPos(IndiceActualColExcel)} columna debe ser 'Producto / Servicio'. Favor de corregirlo", TipoMensaje.MsgError)
|
|
Exit Sub
|
|
End If
|
|
|
|
IndiceActualColExcel += 1
|
|
|
|
If Not dt.Columns(IndiceActualColExcel).ColumnName = "Precio" Then
|
|
Alert($"El nombre de la {StrColPos(IndiceActualColExcel)} columna debe ser 'Precio'. Favor de corregirlo", TipoMensaje.MsgError)
|
|
Exit Sub
|
|
End If
|
|
|
|
|
|
dt.TableName = "Datos"
|
|
Dim ProductosNoCargados As New StringBuilder()
|
|
Dim RowsCargados As Integer = 0
|
|
Dim RowsNoCargados As Integer = 0
|
|
Dim ObjPS As New ClsProductosServicios
|
|
'ObjPS.IniciaTransacSQL()
|
|
Try
|
|
Dim DtPS As DataTable = GlobalDTPSSimplificado(UsuarioActual.CveEmpresa)
|
|
For Each row As DataRow In dt.FiltraParametros("Código <> ''").Rows
|
|
Dim Correcto As Boolean = False
|
|
Dim TieneError As Boolean = False
|
|
Dim CvePS As Integer = DtPS.FiltroPrimeroValor("CvePS", String.Format("Codigo='{0}'", row(0).ToString())).ToEntero
|
|
Dim CvePrecioLista As Integer = DdlPrecioListaCarga.SelectedValue.ToEntero()
|
|
Dim PrecioNuevo As Decimal = row("Precio").ToString().ToDecimal()
|
|
Dim Porcentaje As Decimal = -1
|
|
|
|
If CvePS > 0 AndAlso CvePrecioLista > 0 Then
|
|
|
|
Correcto = ObjPS.UpdatePSPreciosLista(PrecioNuevo, CvePrecioLista, Porcentaje, CvePS, UsuarioActual.CveUsuario, NowADS(), True)
|
|
If Correcto Then
|
|
RowsCargados += 1
|
|
TieneError = ActualizarPreciosFranquicia(ObjPS, row(0).ToString(), PrecioNuevo, 0, DdlPrecioListaCarga.SelectedItem.Text)
|
|
End If
|
|
Else
|
|
If CvePS > 0 AndAlso CvePrecioLista = -2 Then
|
|
Correcto = ObjPS.UpdatePSPrecios(PrecioNuevo, CvePrecioLista, Porcentaje, CvePS, UsuarioActual.CveUsuario, NowADS(), True)
|
|
If Correcto Then
|
|
RowsCargados += 1
|
|
End If
|
|
Else
|
|
Correcto = False
|
|
End If
|
|
|
|
End If
|
|
If Not Correcto Then
|
|
ProductosNoCargados.AppendFormat("{0}-{1},", row(0).ToString(), row("Producto / Servicio").ToString())
|
|
RowsNoCargados += 1
|
|
End If
|
|
Next
|
|
Catch ex As Exception
|
|
OnError("Ocurrió un error al cargar los precios.", ex)
|
|
Finally
|
|
|
|
Dim MensajeFinal As New StringBuilder()
|
|
If RowsNoCargados = 0 AndAlso RowsCargados > 0 Then
|
|
MensajeFinal.Append("Los precios de los Productos/Servicios se cargaron correctamente. <br/><br/>")
|
|
End If
|
|
If RowsCargados > 0 Then
|
|
MensajeFinal.Append("Se actualizaron <b>" & RowsCargados & "</b> Productos o Servicios correctamente.")
|
|
End If
|
|
If RowsNoCargados > 0 Then
|
|
MensajeFinal.Append("No se pudieron actualizar <b>" & RowsNoCargados & "</b> Productos/Servicios. <br/>Los siguientes Productos o Servicios no se pudieron actualizar: " & ProductosNoCargados.ToString())
|
|
End If
|
|
|
|
Alert(MensajeFinal.ToString())
|
|
ObjPS.Dispose()
|
|
End Try
|
|
|
|
|
|
End If
|
|
End Sub
|
|
|
|
#End Region
|
|
|
|
Protected Sub gvSucursal_RowDataBound(sender As Object, e As GridViewRowEventArgs)
|
|
If e.Row.RowType = DataControlRowType.DataRow Then
|
|
e.Row.FCTextBox("TxtPrecioMinimo").Attributes.Add("onKeyUp", String.Format("FncSeleccionaChk({0});", e.Row.FCCheckBox("chkSucursal").ClientID))
|
|
End If
|
|
End Sub
|
|
|
|
Private Function ActualizarPreciosFranquicia(ObjPS As ClsProductosServicios, Codigo As String, Precio As Decimal, PrecioMinimo As Decimal, PrecioLista As String, Optional UpdatePrecioMinimo As Boolean = True) As Boolean
|
|
Dim FranquiciasStr As String = UsuarioActual.Empresa.Funcionalidad(563)
|
|
Dim StrMsg As New StringBuilder
|
|
Dim StrMsgError As New StringBuilder
|
|
If FranquiciasStr <> "" Then
|
|
Dim Franquicias As String() = FranquiciasStr.Split(","c)
|
|
Dim Porcentaje As Decimal = If(TxtPorcentaje.Text = "", -1, TxtPorcentaje.Text.ToDecimal)
|
|
|
|
For Each Franquicia As String In Franquicias
|
|
Dim CveFranquicia As Integer = Franquicia.ToEntero
|
|
Dim CvePS As Integer = GlobalDTPSSimplificado(CveFranquicia, Codigo:=Codigo).FiltroPrimeroValor("CvePS", "").ToEntero
|
|
Dim CvePrecioLisa As Integer = GlobalDTPrecioListas(CveFranquicia).FiltroPrimeroValor("CvePrecioLista", String.Format("PrecioLista = '{0}'", PrecioLista)).ToEntero
|
|
|
|
If CvePS <= 0 Then
|
|
Dim EmpresaFranquicia As String = GlobalDTEmpresas(CveEmpresa:=CveFranquicia).FiltroPrimeroValor("Empresa")
|
|
StrMsg.AppendFormat("El producto '{0}' no se encuentra en la Franquicia '{1}' <br/>", PS, EmpresaFranquicia)
|
|
|
|
End If
|
|
'If CvePrecioLisa <= 0 Then
|
|
' Dim EmpresaFranquicia As String = GlobalDTEmpresas(CveEmpresa:=CveFranquicia).FiltroPrimeroValor("Empresa")
|
|
' StrMsg.AppendFormat("El precio lista '{0}' no existe en la Franquicia '{1}'<br/>", DdlPrecioLista.SelectedItem.Text, EmpresaFranquicia)
|
|
'End If
|
|
If CvePrecioLisa > 0 AndAlso CvePS > 0 AndAlso Not ObjPS.UpdatePSPreciosLista(Precio, CvePrecioLisa, Porcentaje, CvePS, UsuarioActual.CveUsuario, NowADS(), If(RblTipo.SelectedValue = "Imp", True, False), PrecioMinimo:=If(UpdatePrecioMinimo, PrecioMinimo, 0)) Then
|
|
StrMsgError.AppendFormat("No se pudo actualizar el producto")
|
|
End If
|
|
Next
|
|
|
|
End If
|
|
|
|
If StrMsgError.ToString = "" Then
|
|
If StrMsg.ToString <> "" Then
|
|
Alert(StrMsg.ToString, TipoMensaje.MsgAdvertencia)
|
|
End If
|
|
Return False
|
|
Else
|
|
Return True
|
|
End If
|
|
|
|
End Function
|
|
Protected Sub LnkExportarExcel_Click(sender As Object, e As EventArgs)
|
|
Dim DtExcel As New DataTable("Precios")
|
|
DtExcel.Columns.Add(New DataColumn("Código", GetType(String)))
|
|
|
|
If UsuarioActual.Empresa.Funcionalidad(531) = "1" Then 'Empresa Acumuladores
|
|
DtExcel.Columns.Add(New DataColumn("Código CPK", GetType(String)))
|
|
End If
|
|
|
|
If UsuarioActual.Empresa.Funcionalidad(578) = "1" Then 'Empresa Acumuladores
|
|
DtExcel.Columns.Add(New DataColumn("Número de parte", GetType(String)))
|
|
End If
|
|
|
|
DtExcel.Columns.Add(New DataColumn("Producto/Servicio", GetType(String)))
|
|
DtExcel.Columns.Add(New DataColumn("Clasificación", GetType(String)))
|
|
DtExcel.Columns.Add(New DataColumn("Importe", GetType(Decimal)))
|
|
DtExcel.Columns.Add(New DataColumn("Precio Mínimo", GetType(Decimal)))
|
|
DtExcel.Columns.Add(New DataColumn("U.M.", GetType(String)))
|
|
DtExcel.Columns.Add(New DataColumn("Moneda", GetType(String)))
|
|
|
|
If UsuarioActual.CveEmpresa = 153 Then 'Empresa servec
|
|
DtExcel.Columns.Add(New DataColumn("C. Promedio", GetType(Decimal)))
|
|
End If
|
|
|
|
DtExcel.Columns.Add(New DataColumn("E. Mínimo", GetType(Decimal)))
|
|
DtExcel.Columns.Add(New DataColumn("Importe Anterior", GetType(Decimal)))
|
|
DtExcel.Columns.Add(New DataColumn("Precio Mínimo Anterior", GetType(Decimal)))
|
|
DtExcel.Columns.Add(New DataColumn("Fecha Modificación", GetType(DateTime)))
|
|
DtExcel.Columns.Add(New DataColumn("Usuario Modificó", GetType(String)))
|
|
DtExcel.Columns.Add(New DataColumn("Porcentaje", GetType(Decimal)))
|
|
DtExcel.Columns.Add(New DataColumn("Fecha Ingreso", GetType(DateTime)))
|
|
DtExcel.Columns.Add(New DataColumn("Usuario Ingresó", GetType(String)))
|
|
|
|
|
|
If DtDatosPrecios IsNot Nothing Then
|
|
For Each Row As DataRow In DtDatosPrecios.Rows
|
|
Dim NewRow As DataRow = DtExcel.NewRow()
|
|
|
|
NewRow("Código") = Row("Codigo")
|
|
|
|
If UsuarioActual.Empresa.Funcionalidad(531) = "1" Then 'Empresa Acumuladores
|
|
NewRow("Código CPK") = Row("NumeroParte")
|
|
End If
|
|
|
|
NewRow("Producto/Servicio") = Row("PS")
|
|
NewRow("Clasificación") = Row("Clasificacion")
|
|
NewRow("Importe") = Row("PrecioLista")
|
|
NewRow("Precio Mínimo") = Row("PrecioMinimo")
|
|
NewRow("U.M.") = Row("UnidadMedida")
|
|
NewRow("Moneda") = Row("Moneda")
|
|
|
|
If UsuarioActual.CveEmpresa = 153 Then 'Empresa servec
|
|
NewRow("C. Promedio") = Row("CostoPromedio")
|
|
End If
|
|
|
|
NewRow("E. Mínimo") = Row("VentaMinima")
|
|
NewRow("Importe Anterior") = Row("ImporteAnterior")
|
|
NewRow("Precio Mínimo Anterior") = Row("PrecioMinimoAnterior")
|
|
NewRow("Fecha Modificación") = Row("FechaModificacion")
|
|
NewRow("Usuario Modificó") = Row("UsuarioModifico")
|
|
NewRow("Porcentaje") = Row("Porcentaje")
|
|
NewRow("Fecha Ingreso") = Row("FechaIng")
|
|
NewRow("Usuario Ingresó") = Row("Usuario")
|
|
|
|
DtExcel.Rows.Add(NewRow)
|
|
Next
|
|
End If
|
|
|
|
SpreadsheetInfo.SetLicense(ModExtensiones.SerialGemBoxSpreadsheet)
|
|
|
|
Dim FileExcel As New ExcelFile()
|
|
|
|
Dim worksheet As ExcelWorksheet = FileExcel.Worksheets.Add(DtExcel.TableName)
|
|
worksheet.InsertDataTable(DtExcel, New InsertDataTableOptions() With
|
|
{
|
|
.ColumnHeaders = True,
|
|
.StartRow = 0,
|
|
.StartColumn = 0
|
|
})
|
|
worksheet.Rows(0).Style.FillPattern.SetPattern(FillPatternStyle.Solid, SpreadsheetColor.FromArgb(75, 119, 190), SpreadsheetColor.FromArgb(255, 255, 255))
|
|
worksheet.Rows(0).Style.Font.Color = SpreadsheetColor.FromArgb(255, 255, 255)
|
|
|
|
Dim columnCount As Integer = worksheet.CalculateMaxUsedColumns()
|
|
For i As Integer = 0 To columnCount
|
|
worksheet.Columns(i).AutoFit(1, worksheet.Rows(0), worksheet.Rows(worksheet.Rows.Count - 1))
|
|
Next
|
|
|
|
Dim FechaIMes As String = "", FechaFMes As String = "", Titulo As String = "LISTADO DE PRECIOS", ListaPrecios As String = DdlPrecioLista.SelectedItem.Text, Divisor As Integer = 1, AlturaImagen As Double = 100, AnchoImagen As Double = 100, DatoTituloExtra As String = ""
|
|
|
|
|
|
Dim TotalRowHeader As Integer = 8
|
|
Dim TotalRowFooter As Integer = 2
|
|
|
|
|
|
worksheet.Rows.InsertEmpty(0, TotalRowHeader)
|
|
Dim celdasConTexto As CellRange = worksheet.GetUsedCellRange(True)
|
|
celdasConTexto.Style.Font.Name = "Calibri Light"
|
|
|
|
Dim RangoNombreEmpresa As CellRange = worksheet.Cells.GetSubrangeAbsolute(1, celdasConTexto.FirstColumnIndex, 1, celdasConTexto.LastColumnIndex)
|
|
RangoNombreEmpresa.Merged = True
|
|
RangoNombreEmpresa.Value = UsuarioActual.Empresa.Empresa
|
|
RangoNombreEmpresa.Style.Font.Size = 20 * 20
|
|
RangoNombreEmpresa.Style.Font.Name = "Calibri Light"
|
|
RangoNombreEmpresa.Style.HorizontalAlignment = GemBox.Spreadsheet.HorizontalAlignmentStyle.Center
|
|
RangoNombreEmpresa.Style.VerticalAlignment = GemBox.Spreadsheet.VerticalAlignmentStyle.Center
|
|
|
|
|
|
Dim RangoTitulo As CellRange = worksheet.Cells.GetSubrangeAbsolute(3, celdasConTexto.FirstColumnIndex, 3, celdasConTexto.LastColumnIndex)
|
|
RangoTitulo.Merged = True
|
|
RangoTitulo.Value = Titulo
|
|
RangoTitulo.Style.Font.Size = 17 * 20
|
|
RangoTitulo.Style.Font.Name = "Calibri Light"
|
|
RangoTitulo.Style.HorizontalAlignment = GemBox.Spreadsheet.HorizontalAlignmentStyle.Center
|
|
RangoTitulo.Style.VerticalAlignment = GemBox.Spreadsheet.VerticalAlignmentStyle.Center
|
|
|
|
|
|
'If FechaIMes.Trim.Length > 0 And FechaFMes.Trim.Length > 0 Then
|
|
' Dim RangoFechas = worksheet.Cells.GetSubrangeAbsolute(4, celdasConTexto.FirstColumnIndex, 4, celdasConTexto.LastColumnIndex)
|
|
' RangoFechas.Merged = True
|
|
' RangoFechas.Value = $"Fechas: {FechaIMes} a {FechaFMes}"
|
|
' RangoFechas.Style.Font.Size = 15 * 20
|
|
' RangoFechas.Style.Font.Name = "Calibri Light"
|
|
' RangoFechas.Style.HorizontalAlignment = GemBox.Spreadsheet.HorizontalAlignmentStyle.Center
|
|
' RangoFechas.Style.VerticalAlignment = GemBox.Spreadsheet.VerticalAlignmentStyle.Center
|
|
'End If
|
|
|
|
|
|
If ListaPrecios.Length > 0 Then
|
|
Dim RangoSubProyecto As CellRange = worksheet.Cells.GetSubrangeAbsolute(5, celdasConTexto.FirstColumnIndex, 5, celdasConTexto.LastColumnIndex)
|
|
RangoSubProyecto.Merged = True
|
|
RangoSubProyecto.Value = $"Lista de precio: {ListaPrecios}"
|
|
RangoSubProyecto.Style.Font.Size = 14 * 20
|
|
RangoSubProyecto.Style.Font.Name = "Calibri Light"
|
|
RangoSubProyecto.Style.HorizontalAlignment = GemBox.Spreadsheet.HorizontalAlignmentStyle.Center
|
|
RangoSubProyecto.Style.VerticalAlignment = GemBox.Spreadsheet.VerticalAlignmentStyle.Center
|
|
End If
|
|
|
|
For i As Integer = celdasConTexto.FirstColumnIndex To celdasConTexto.LastColumnIndex
|
|
|
|
worksheet.Rows(8).Cells(i).Style.Font.Size = 12 * 20
|
|
worksheet.Rows(8).Cells(i).Style.HorizontalAlignment = GemBox.Spreadsheet.HorizontalAlignmentStyle.Center
|
|
worksheet.Rows(8).Cells(i).Style.VerticalAlignment = GemBox.Spreadsheet.VerticalAlignmentStyle.Center
|
|
|
|
worksheet.Rows(8).Cells(i).Style.FillPattern.SetPattern(GemBox.Spreadsheet.FillPatternStyle.Solid, GemBox.Spreadsheet.SpreadsheetColor.FromArgb(75, 119, 190), GemBox.Spreadsheet.SpreadsheetColor.FromArgb(255, 255, 255))
|
|
worksheet.Rows(8).Cells(i).Style.Font.Color = GemBox.Spreadsheet.SpreadsheetColor.FromArgb(255, 255, 255)
|
|
If i > 0 Then
|
|
Try
|
|
worksheet.Columns(i).AutoFit(1)
|
|
Catch ex As Exception
|
|
End Try
|
|
End If
|
|
Next
|
|
Dim IndexEndTable As Integer = DtExcel.Rows.Count + TotalRowHeader + TotalRowFooter
|
|
|
|
worksheet.Rows(IndexEndTable).Cells(0).Value = "Usuario Imprimió"
|
|
worksheet.Rows(IndexEndTable + 1).Cells(0).Value = UsuarioActual.Nombre
|
|
worksheet.Rows(IndexEndTable).Cells(2).Value = "Fecha Impresión"
|
|
worksheet.Rows(IndexEndTable + 1).Cells(2).Value = NowADS().ToString("dd/MM/yyyy")
|
|
|
|
Dim Imagen As New System.IO.FileInfo($"{UsuarioActual.Empresa.Ruta}/Logo.png")
|
|
|
|
If Imagen.Exists Then
|
|
Dim Ruta As String = String.Format("{0}/Logo.png", UsuarioActual.Empresa.Ruta)
|
|
Using sr As New StreamReader(Ruta)
|
|
Dim ms As New MemoryStream()
|
|
sr.BaseStream.CopyTo(ms)
|
|
worksheet.Pictures.Add(ms, ExcelPictureFormat.Png, "A1", AnchoImagen, AlturaImagen, LengthUnit.Pixel)
|
|
End Using
|
|
End If
|
|
|
|
For I As Integer = celdasConTexto.FirstColumnIndex To celdasConTexto.LastColumnIndex
|
|
|
|
If I > 0 Then
|
|
|
|
If Divisor = 1 Then
|
|
worksheet.Columns(I + 1).Style.NumberFormat = "#,##0.00"
|
|
Else
|
|
worksheet.Columns(I + 1).Style.NumberFormat = "#,##"
|
|
End If
|
|
|
|
Try
|
|
worksheet.Columns(I).AutoFit(1)
|
|
Catch ex As Exception
|
|
End Try
|
|
|
|
End If
|
|
Next
|
|
|
|
FileExcel.Save(Response, "Precios.xlsx", SaveOptions.XlsxDefault)
|
|
|
|
End Sub
|
|
Protected Sub GvMultiple_RowCreated(sender As Object, e As GridViewRowEventArgs)
|
|
'QUITAR COLUMNA "CvePS"
|
|
'e.Row.Cells(1).Visible = False
|
|
|
|
'If e.Row.RowType = DataControlRowType.Header Then
|
|
' For colIndex = 2 To e.Row.Cells.Count - 1
|
|
|
|
' Dim indiceColumna As Integer = (colIndex)
|
|
' Dim LtlId = "LtlLista" + (colIndex - 1).ToString()
|
|
' Dim Dr = DtPreciosMultiple.Rows(e.Row.RowIndex)
|
|
' If Dr IsNot Nothing Then
|
|
' 'VERIFICA QUE EL INDICE DE LA COLUMNA DEL DT NO SEA MAYOR A LA DEL GRIDVIEW
|
|
' If indiceColumna <= DtPreciosMultiple.Columns.Count - 1 Then
|
|
' Dim cell = e.Row.Cells(colIndex)
|
|
|
|
' Dim text = cell.Text
|
|
' Dim splitValues = text.Split("|"c)
|
|
|
|
' If splitValues.Length > 1 Then
|
|
' Dim CvePrecioLista = splitValues(0)
|
|
' Dim PrecioLista = splitValues(1)
|
|
' e.Row.FCLiteral(LtlId).Text = PrecioLista
|
|
' cell.Attributes.Add("cvepreciolista", CvePrecioLista)
|
|
' End If
|
|
|
|
' End If
|
|
|
|
' End If
|
|
|
|
' Next
|
|
'End If
|
|
End Sub
|
|
Protected Sub GvMultiple_RowDataBound(sender As Object, e As GridViewRowEventArgs)
|
|
If e.Row.RowType = DataControlRowType.Header Then
|
|
For colIndex As Integer = 2 To e.Row.Cells.Count - 1
|
|
|
|
Dim indiceColumna As Integer = (colIndex)
|
|
Dim LtlId As String = "LtlLista_" + (colIndex - 1).ToString()
|
|
|
|
If indiceColumna <= DtPreciosMultiple.Columns.Count - 1 Then
|
|
|
|
Dim text As String = DtPreciosMultiple.Columns(indiceColumna).ColumnName
|
|
Dim splitValues As String() = text.Split("|"c)
|
|
|
|
If splitValues.Length > 1 Then
|
|
Dim CvePrecioLista As String = splitValues(0)
|
|
Dim PrecioLista As String = splitValues(1)
|
|
e.Row.FCLabel(LtlId).Text = PrecioLista
|
|
e.Row.FCLabel(LtlId).Attributes.Add("cvepreciolista", CvePrecioLista)
|
|
End If
|
|
|
|
End If
|
|
|
|
Next
|
|
End If
|
|
|
|
If e.Row.RowType = DataControlRowType.DataRow Then
|
|
For colIndex As Integer = 2 To e.Row.Cells.Count - 1
|
|
|
|
Dim indiceColumna As Integer = (colIndex)
|
|
Dim TxtId As String = "TxtPrecio_" + (colIndex - 1).ToString()
|
|
|
|
|
|
Dim Dr As DataRow = DtPreciosMultiple.Rows(e.Row.RowIndex)
|
|
If Dr IsNot Nothing Then
|
|
|
|
'VERIFICA QUE EL INDICE DE LA COLUMNA DEL DT NO SEA MAYOR A LA DEL GRIDVIEW
|
|
If indiceColumna <= DtPreciosMultiple.Columns.Count - 1 Then
|
|
Dim Valor As Decimal = DtPreciosMultiple.Rows(e.Row.RowIndex)(indiceColumna).ToString().ToDecimal()
|
|
|
|
e.Row.FCTextBox(TxtId).Text = Valor.FormatoNumero(2)
|
|
e.Row.FCTextBox(TxtId).Enabled = PermisoEdicionLista
|
|
End If
|
|
|
|
End If
|
|
Next
|
|
End If
|
|
End Sub
|
|
Protected Sub LnkGuardarMultiple_Click(sender As Object, e As EventArgs)
|
|
Dim TieneError As Boolean = False
|
|
|
|
Dim DtPS As DataTable = GlobalDTPSSimplificado(UsuarioActual.CveEmpresa)
|
|
|
|
Dim ObjPS As New ClsProductosServicios
|
|
ObjPS.IniciaTransacSQL()
|
|
Try
|
|
For Each GvRow As GridViewRow In GvMultiple.Rows
|
|
|
|
If GvRow.FCCheckBox("chkPS").Checked Then
|
|
For colIndex As Integer = 2 To GvRow.Cells.Count - 1
|
|
|
|
Dim indiceColumna As Integer = (colIndex)
|
|
|
|
Dim LtlId As String = "LtlLista_" + (colIndex - 1).ToString()
|
|
Dim TxtId As String = "TxtPrecio_" + (colIndex - 1).ToString()
|
|
|
|
If indiceColumna <= DtPreciosMultiple.Columns.Count - 1 Then
|
|
|
|
Dim CvePrecioLista As Integer = GvMultiple.HeaderRow.FCLabel(LtlId).Attributes().Item("cvepreciolista").ToEntero()
|
|
Dim CvePS As Integer = DtPreciosMultiple.Rows(GvRow.RowIndex)("CvePS").ToString().ToEntero()
|
|
|
|
Dim Precio As Decimal = GvRow.FCTextBox(TxtId).Text.ToDecimal()
|
|
|
|
TieneError = Not ObjPS.UpdatePSPreciosLista(Precio, CvePrecioLista, 0, CvePS, UsuarioActual.CveUsuario, NowADS(), True)
|
|
|
|
If Not TieneError Then
|
|
|
|
Dim text As String = DtPreciosMultiple.Columns(indiceColumna).ColumnName
|
|
Dim splitValues As String() = text.Split("|"c)
|
|
|
|
If splitValues.Length > 1 Then
|
|
|
|
Dim PrecioLista As String = splitValues(1)
|
|
|
|
Dim DrPS = DtPS.FiltroPrimero($"CvePS = {CvePS}")
|
|
If DrPS IsNot Nothing Then
|
|
TieneError = ActualizarPreciosFranquicia(ObjPS, DrPS("Codigo").ToString(), Precio, 0, PrecioLista, UpdatePrecioMinimo:=False)
|
|
Else
|
|
TieneError = True
|
|
End If
|
|
|
|
End If
|
|
|
|
Else
|
|
Exit For
|
|
End If
|
|
|
|
If TieneError Then
|
|
Exit For
|
|
End If
|
|
End If
|
|
|
|
Next
|
|
End If
|
|
|
|
Next
|
|
Catch ex As Exception
|
|
OnError("Ocurrió un error al actualizar precios", ex)
|
|
TieneError = True
|
|
End Try
|
|
|
|
|
|
If Not TieneError Then
|
|
Alert("Los Precios de lista de los Productos/Servicios se actualizaron correctamente")
|
|
Else
|
|
Alert("Ocurrió un error al actualizar precios", TipoMensaje.MsgError)
|
|
End If
|
|
|
|
If TieneError Then
|
|
ObjPS.RollBack()
|
|
Else
|
|
ObjPS.Commit()
|
|
End If
|
|
|
|
ObjPS.Dispose()
|
|
|
|
If Not TieneError Then
|
|
BtnConsultar_Click(Nothing, Nothing)
|
|
End If
|
|
|
|
End Sub
|
|
Protected Sub DdlModalidad_SelectedIndexChanged(sender As Object, e As EventArgs)
|
|
DivPrecioLista.Visible = DdlModalidad.SelectedValue = "1"
|
|
DivMultiplePrecioLista.Visible = DdlModalidad.SelectedValue = "2"
|
|
|
|
dvDatos.Visible = DdlModalidad.SelectedValue = "1"
|
|
DivActualizarPrecio.Visible = DdlModalidad.SelectedValue = "1"
|
|
If UsuarioActual.TienePermisoProceso(282) Then
|
|
DivActualizarPrecio.Visible = False
|
|
End If
|
|
dvMultiple.Visible = DdlModalidad.SelectedValue = "2"
|
|
|
|
UPPrecioLista.Update()
|
|
UpEncabezado.Update()
|
|
UpDatos.Update()
|
|
End Sub
|
|
|
|
Protected Sub ImprimirEtiquetas(StrClavesPS As String)
|
|
Dim CvePrecioListaPredeterminada = GlobalDTPrecioListas(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CvePrecioLista", "Predeterminada = True").ToEntero()
|
|
Dim DtPrecios As DataTable = Nothing
|
|
|
|
Dim ObjVentas As New ClsProductosServicios
|
|
If ObjVentas.GetPSPrecios(CvePrecioListaPredeterminada, StrClavesPS) AndAlso ObjVentas.DtResultados IsNot Nothing AndAlso ObjVentas.DtResultados.Rows.Count > 0 Then
|
|
DtPrecios = ObjVentas.DtResultados.Copy()
|
|
End If
|
|
ObjVentas.Dispose()
|
|
|
|
If DtPrecios IsNot Nothing Then
|
|
|
|
DtPrecios.Columns.Add(New DataColumn("CBBase64", GetType(String)))
|
|
|
|
For Each Row As DataRow In DtPrecios.Rows
|
|
Row("CBBase64") = Convert.ToBase64String(GeneraCodigoQR(Row("CodigoBarras").ToString(), 40, 150, 0, "CODE_39", True))
|
|
Next
|
|
|
|
Dim DirectorioArchivo As String = "Empresas/Grales/Formatos/Etiqueta.mrt"
|
|
If System.IO.File.Exists(UsuarioActual.Empresa.Ruta + "Formatos/Etiqueta.mrt") Then
|
|
DirectorioArchivo = UsuarioActual.Empresa.Ruta + "Formatos/Etiqueta.mrt"
|
|
End If
|
|
Dim params As New List(Of ReportParameter)
|
|
|
|
Dim lrds As New List(Of ReportDataSource)
|
|
Dim rds As New ReportDataSource
|
|
rds.Name = "Datos"
|
|
rds.Value = DtPrecios
|
|
lrds.Add(rds)
|
|
|
|
Dim bytesPDF = StreamBytesStimul("Facturas", DirectorioArchivo, lrds, params, NombreArchivo:="Precios", Formato:="PDF")
|
|
Dim pdf64 = Convert.ToBase64String(bytesPDF)
|
|
|
|
RegistraScript($"impresionBase64('{pdf64}');", "Imprimir")
|
|
'ImprimirPDFStimul(DirectorioArchivo, DtPrecios, params, "Precios")
|
|
End If
|
|
|
|
End Sub
|
|
|
|
Private Function GeneraCodigoQR(CodigoBarras As String, Alto As Integer, Largo As Integer, Margen As Integer, Formato As String, Optional PureBacode As Boolean = False) As Byte()
|
|
|
|
Dim barcodeWriter As New BarcodeWriter
|
|
Dim opciones As New ZXing.Common.EncodingOptions
|
|
Dim FormatoBar As New BarcodeFormat
|
|
'Dim Respuesta As Byte()
|
|
|
|
opciones.Height = Alto
|
|
opciones.Width = Largo
|
|
opciones.Margin = Margen
|
|
opciones.PureBarcode = PureBacode
|
|
barcodeWriter.Options = opciones
|
|
|
|
Select Case Formato
|
|
Case "All_1D"
|
|
barcodeWriter.Format = BarcodeFormat.All_1D
|
|
Exit Select
|
|
Case "AZTEC"
|
|
barcodeWriter.Format = BarcodeFormat.AZTEC
|
|
Exit Select
|
|
Case "CODABAR"
|
|
barcodeWriter.Format = BarcodeFormat.CODABAR
|
|
Exit Select
|
|
Case "CODE_128"
|
|
barcodeWriter.Format = BarcodeFormat.CODE_128
|
|
Exit Select
|
|
Case "CODE_39"
|
|
barcodeWriter.Format = BarcodeFormat.CODE_39
|
|
Exit Select
|
|
Case "CODE_93"
|
|
barcodeWriter.Format = BarcodeFormat.CODE_93
|
|
Exit Select
|
|
Case "DATA_MATRIX"
|
|
barcodeWriter.Format = BarcodeFormat.DATA_MATRIX
|
|
Exit Select
|
|
Case "EAN_13"
|
|
barcodeWriter.Format = BarcodeFormat.EAN_13
|
|
Exit Select
|
|
Case "EAN_8"
|
|
barcodeWriter.Format = BarcodeFormat.EAN_8
|
|
Exit Select
|
|
Case "IMB"
|
|
barcodeWriter.Format = BarcodeFormat.IMB
|
|
Exit Select
|
|
Case "ITF"
|
|
barcodeWriter.Format = BarcodeFormat.ITF
|
|
Exit Select
|
|
Case "MAXICODE"
|
|
barcodeWriter.Format = BarcodeFormat.MAXICODE
|
|
Exit Select
|
|
Case "MSI"
|
|
barcodeWriter.Format = BarcodeFormat.MSI
|
|
Exit Select
|
|
Case "PDF_417"
|
|
barcodeWriter.Format = BarcodeFormat.PDF_417
|
|
Exit Select
|
|
Case "PLESSEY"
|
|
barcodeWriter.Format = BarcodeFormat.PLESSEY
|
|
Exit Select
|
|
Case "QR_CODE"
|
|
barcodeWriter.Format = BarcodeFormat.QR_CODE
|
|
Exit Select
|
|
Case "RSS_14"
|
|
barcodeWriter.Format = BarcodeFormat.RSS_14
|
|
Exit Select
|
|
Case "RSS_EXPANDED"
|
|
barcodeWriter.Format = BarcodeFormat.RSS_EXPANDED
|
|
Exit Select
|
|
Case "UPC_A"
|
|
barcodeWriter.Format = BarcodeFormat.UPC_A
|
|
Exit Select
|
|
Case "UPC_E"
|
|
barcodeWriter.Format = BarcodeFormat.UPC_E
|
|
Exit Select
|
|
Case "UPC_EAN_EXTENSION"
|
|
barcodeWriter.Format = BarcodeFormat.UPC_EAN_EXTENSION
|
|
Exit Select
|
|
|
|
End Select
|
|
|
|
Dim imgCod As Drawing.Bitmap = barcodeWriter.Write(CodigoBarras)
|
|
Dim memoriStream As New System.IO.MemoryStream
|
|
imgCod.Save(memoriStream, Drawing.Imaging.ImageFormat.Bmp)
|
|
|
|
'Respuesta = Convert.ToBase64String(memoriStream.ToArray())
|
|
|
|
Return memoriStream.ToArray()
|
|
|
|
End Function
|
|
|
|
|
|
Protected Sub GVPrecios_RowDataBound(sender As Object, e As GridViewRowEventArgs)
|
|
|
|
If e.Row.RowType = DataControlRowType.DataRow Then
|
|
|
|
e.Row.FCTextBox("TxtPrecio").Enabled = PermisoEdicionLista
|
|
e.Row.FCTextBox("TxtPrecioMinimo").Enabled = PermisoEdicionLista
|
|
|
|
End If
|
|
|
|
End Sub
|
|
End Class |