Option Explicit On Option Strict On Imports Extensiones Imports System.Data Partial Class ProductosyServicios Inherits ClsPaginas #Region " Propiedades " Private ReadOnly Property CvePS As Integer Get Return ViewState("CvePS").ToString.ToEntero End Get End Property Private Property Ret As String Get Return ViewState("Ret").ToString End Get Set(value As String) ViewState("Ret") = value End Set End Property Public Property dtPaqueteDetalles() As DataTable Get Return CType(ViewState("dtPaqueteDetalles"), DataTable) End Get Set(value As DataTable) ViewState("dtPaqueteDetalles") = value End Set End Property Public Property dtFamily() As DataTable Get Return CType(ViewState("dtFamily"), DataTable) End Get Set(value As DataTable) ViewState("dtFamily") = value End Set End Property #End Region Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load If Not IsPostBack Then ViewState("OrdenO") = "" ViewState("OrdenC") = "" ViewState("DTProductosServiciosCaracteristicas") = Nothing ViewState("DTProductosServiciosCaracteristicasOpciones") = Nothing ViewState("CveSubFamilia") = "-1" Ret = "-1" 'CType(Me.Master, BaseMasterPage).EsPopup = True 'CType(Me.Master, BaseMasterPage).PopupWidth = 700 'RegistraScript("$get('tdContenido').style.height='350px'") CargaClasificaciones() CargaUnidadesMedida() CargarMetodosInv() If UsuarioActual.Empresa.UsaContabilidad Then CargaCuentasContables() End If If Request("CvePS") IsNot Nothing AndAlso IsNumeric(Request("CvePS")) AndAlso Request("CvePS").ToEntero > 0 Then ViewState("CvePS") = Request("CvePS") CargaDatos() 'Configuración de Modalidad Update BtnGuardar.Text = "Guardar Cambios" LoadCaracteristicas() CargarAlias() Else 'Configuración de Modalidad Insert ViewState("CvePS") = -1 ChkEstado.Enabled = False ChkEstado.Checked = True LblFechaCaptura.Text = Now.ToShortDateString() LblUsuarioCapturo.Text = UsuarioActual.Usuario BtnEliminar.Visible = False End If If Request("Ret") IsNot Nothing AndAlso Request("Ret").ToString <> "" Then Ret = Request("Ret") End If CargaFamilia(ViewState("CveSubFamilia").ToString.ToEntero) CargaDefault() CargaSucursaless() If UsuarioActual.TienePermisoProceso(122) Then BtnEliminar.Visible = False BtnGuardar.Visible = False End If End If End Sub #Region "S U C U R S A L E S" Private Sub CargaSucursaless() 'Dim dtSuc As DataTable = GlobalDTSucursales().FiltraParametros("CveEmpresa = " + UsuarioActual.CveEmpresa.ToString) 'dtSuc.AcceptChanges() 'dtSuc.Columns.Add("Importe") 'dtSuc.Columns.Add("Activo") 'For Each row As DataRow In dtSuc.Rows ' row("Activo") = False 'Next 'dtSuc.AcceptChanges() 'If Not ViewState("CvePS") Is Nothing Then ' Dim ObjPS As New ClsProductosServicios ' If ObjPS.GetPSSucursales(CvePS) Then ' Dim dtSucP As DataTable = ObjPS.DtResultados ' For Each Row As DataRow In dtSucP.Rows ' Dim rowsToUpdate = dtSuc.AsEnumerable().Where(Function(r) r.Field(Of Integer)("CveSucursal") = Row("CveSucursal").ToString.ToEntero AndAlso r!CveSucursal.ToString.ToEntero > 0) ' For Each roww As DataRow In rowsToUpdate ' roww.SetField("Importe", Row("Importe")) ' roww.SetField("Activo", True) ' Next ' 'For Each drtt As DataRow In TmpDT.Select(String.Format("PS='{0}' AND CvePS=0", Row("PS"))) ' ' drtt("CvePS") = tCve ' 'Next ' dtSuc.AcceptChanges() ' Next ' End If ' ObjPS.Dispose() 'End If 'gvSucursal.DataSource = dtSuc 'gvSucursal.DataBind() Dim ObjPS As New ClsProductosServicios If ObjPS.GetPSSucursales(CvePS, UsuarioActual.CveEmpresa) Then gvSucursal.DataSource = ObjPS.DtResultados gvSucursal.DataBind() End If ObjPS.Dispose() End Sub Protected Sub gvSucursal_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles gvSucursal.RowDataBound If e.Row.RowType = DataControlRowType.DataRow Then If e.Row.RowIndex = 0 Then e.Row.Cells(0).Width = Unit.Pixel(50) e.Row.Cells(1).Width = Unit.Pixel(100) e.Row.Cells(2).Width = Unit.Pixel(100) End If ' If e.Row.FCCheckBox("chkSucursal").Checked = True Then e.Row.Cells(0).BackColor = Drawing.Color.Yellow End If End Sub #End Region #Region "C A R A C T E R I S T I C A S" Private Sub LoadCaracteristicas() ViewState("OrdenC") = "" CargaDatosC() CargaProductosServiciosCaracteristicas() CargaDatosO() End Sub Public Sub CargaDefault() Dim ObjCaracteristicas As New ClsGralProductosServiciosCaracteristicas If ObjCaracteristicas.GetProductosServiciosCaracteristicas() Then ViewState("DTProductosServiciosCaracteristicas") = ObjCaracteristicas.DtResultados.Clone End If If ObjCaracteristicas.GetProductosServiciosCaracteristicasOpciones() Then ViewState("DTProductosServiciosCaracteristicasOpciones") = ObjCaracteristicas.DtResultados.Clone End If ObjCaracteristicas.Dispose() End Sub Public Sub CargaDatosC() Dim ObjCaracteristicas As New ClsGralProductosServiciosCaracteristicas If ObjCaracteristicas.GetProductosServiciosCaracteristicas() Then ViewState("DTProductosServiciosCaracteristicas") = ObjCaracteristicas.DtResultados.FiltraParametros("CveEmpresa = " & UsuarioActual.CveEmpresa) GlobalDTProductosServiciosCaracteristicas(UsuarioActual.CveEmpresa) = ObjCaracteristicas.DtResultados Else Me.GvDatosCaracteristicas.DataSource = Nothing End If If ViewState("OrdenC").ToString() <> String.Empty Then CargaGrid(ViewState("OrdenC").ToString(), 0) Else CargaGrid("", 0) End If End Sub Public Sub CargaDatosO() Dim ObjOpciones As New ClsGralProductosServiciosCaracteristicas If ObjOpciones.GetProductosServiciosCaracteristicasOpciones() Then ViewState("DTProductosServiciosCaracteristicasOpciones") = ObjOpciones.DtResultados.FiltraParametros("CveEmpresa = " & UsuarioActual.CveEmpresa) GlobalDTProductosServiciosCaracteristicasOpciones(UsuarioActual.CveEmpresa) = ObjOpciones.DtResultados Else GvDatosOpciones.DataSource = Nothing End If If ViewState("OrdenO").ToString() <> String.Empty Then CargaGrid(ViewState("OrdenO").ToString(), 1) Else CargaGrid("", 1) End If End Sub Protected Sub LbAgregarC_Click(sender As Object, e As System.EventArgs) Handles LbAgregarC.Click Dim ObjCaracteristicas As New ClsGralProductosServiciosCaracteristicas If ObjCaracteristicas.AddProductosServiciosCaracteristicas(TxtCaracteristica.Text.Trim, CvePS, ChkEsOpcion.Checked, UsuarioActual.CveUsuario) Then TxtCaracteristica.Text = "" Alert("La nueva Característica de Producto o Servicio se guardó correctamente.", TipoMensaje.MsgInformacion) ViewState("DTProductosServiciosCaracteristicas") = ObjCaracteristicas.DtResultados.FiltraParametros("CveEmpresa = " & UsuarioActual.CveEmpresa) GlobalDTProductosServiciosCaracteristicas(UsuarioActual.CveEmpresa) = ObjCaracteristicas.DtResultados CambioProductosServiciosCaracteristicas() End If ObjCaracteristicas.Dispose() End Sub Protected Sub LbAgregarO_Click(sender As Object, e As System.EventArgs) Handles LbAgregarO.Click Dim ObjOpciones As New ClsGralProductosServiciosCaracteristicas If ObjOpciones.AddProductosServiciosCaracteristicasOpciones(TxtOpcion.Text.Trim, DdlCaracteristica.SelectedValue.ToEntero, UsuarioActual.CveUsuario) Then TxtOpcion.Text = "" Alert("La nueva Opción para Característica de Producto o Servicio se guardó correctamente.", TipoMensaje.MsgInformacion) ViewState("DTProductosServiciosCaracteristicasOpciones") = ObjOpciones.DtResultados.FiltraParametros("CveEmpresa = " & UsuarioActual.CveEmpresa) GlobalDTProductosServiciosCaracteristicasOpciones(UsuarioActual.CveEmpresa) = ObjOpciones.DtResultados CambioProductosServiciosCaracteristicasOpciones() End If ObjOpciones.Dispose() End Sub Private Sub CargaProductosServiciosCaracteristicas() DdlCaracteristica.Items.Clear() DdlCaracteristica.DataSource = GlobalDTProductosServiciosCaracteristicas(UsuarioActual.CveEmpresa).FiltraParametros("EsOpcion = 'Sí' AND CvePS = " + CvePS.ToString) DdlCaracteristica.DataBind() End Sub Protected Sub DdlCaracteristica_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlCaracteristica.SelectedIndexChanged If ViewState("OrdenO").ToString() <> String.Empty Then CargaGrid(ViewState("OrdenO").ToString(), 1) Else CargaGrid("", 1) End If End Sub Protected Sub CambioProductosServiciosCaracteristicas() CargaProductosServiciosCaracteristicas() UpTitulosC.Update() CargaDatosC() CambioProductosServiciosCaracteristicasOpciones() End Sub Protected Sub CambioProductosServiciosCaracteristicasOpciones() UpTitulosO.Update() CargaDatosO() End Sub #End Region #Region "G V C A R A C T E R I S T I C A S" Protected Sub GvDatosCaracteristicas_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GvDatosCaracteristicas.RowDataBound If e.Row.RowType = DataControlRowType.DataRow Then If e.Row.RowIndex = 0 Then e.Row.Cells(0).Width = Unit.Pixel(150) e.Row.Cells(1).Width = Unit.Pixel(100) e.Row.Cells(2).Width = Unit.Pixel(100) e.Row.Cells(3).Width = Unit.Pixel(100) e.Row.Cells(4).Width = Unit.Pixel(50) e.Row.Cells(5).Width = Unit.Pixel(50) End If e.Row.Cells(0).HorizontalAlign = HorizontalAlign.Left If e.Row.RowState = DataControlRowState.Edit OrElse e.Row.RowState = 5 Then 'e.Row.FCDropDownList("DdlPSEdit").DataSource = ViewState("DTPS") 'e.Row.FCDropDownList("DdlPSEdit").DataBind() 'e.Row.FCDropDownList("DdlPSEdit").SelectedValue = e.Row.DBCampo("CvePS") End If End If End Sub Protected Sub GvDatosCaracteristicas_RowDeleting(sender As Object, e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GvDatosCaracteristicas.RowDeleting Dim ObjCaracteristicas As New ClsGralProductosServiciosCaracteristicas If ObjCaracteristicas.RemoveProductosServiciosCaracteristica(GvDatosCaracteristicas.DataKeys(e.RowIndex).Value.ToString.ToEntero) Then GvDatosCaracteristicas.EditIndex = -1 ViewState("DTProductosServiciosCaracteristicas") = ObjCaracteristicas.DtResultados.FiltraParametros("CveEmpresa = " & UsuarioActual.CveEmpresa) GlobalDTProductosServiciosCaracteristicas(UsuarioActual.CveEmpresa) = ObjCaracteristicas.DtResultados Alert("La Característica del Producto o Servicio se eliminó correctamente.", TipoMensaje.MsgInformacion) CambioProductosServiciosCaracteristicas() End If ObjCaracteristicas.Dispose() End Sub Protected Sub GvDatosCaracteristicas_RowCancelingEdit(sender As Object, e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles GvDatosCaracteristicas.RowCancelingEdit GvDatosCaracteristicas.EditIndex = -1 If ViewState("OrdenC").ToString() <> String.Empty Then CargaGrid(ViewState("OrdenC").ToString(), 0) Else CargaGrid("", 0) End If End Sub Protected Sub GvDatosCaracteristicas_RowUpdating(sender As Object, e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GvDatosCaracteristicas.RowUpdating Dim ObjCaracteristicas As New ClsGralProductosServiciosCaracteristicas Dim CveCaracteristica As Integer = GvDatosCaracteristicas.DataKeys(e.RowIndex).Value.ToString.ToEntero Dim Caracteristica As String = DirectCast(GvDatosCaracteristicas.Rows(e.RowIndex).FindControl("TxtCaracteristica"), TextBox).Text.Trim Dim EsOpcion As Boolean = GvDatosCaracteristicas.Rows(e.RowIndex).FCCheckBox("ChkEsOpcion").Checked If ObjCaracteristicas.UpdateProductosServiciosCaracteristica(Caracteristica, CvePS, EsOpcion, CveCaracteristica) Then GvDatosCaracteristicas.EditIndex = -1 ViewState("DTProductosServiciosCaracteristicas") = ObjCaracteristicas.DtResultados.FiltraParametros("CveEmpresa = " & UsuarioActual.CveEmpresa) GlobalDTProductosServiciosCaracteristicas(UsuarioActual.CveEmpresa) = ObjCaracteristicas.DtResultados Alert("Los cambios se guardaron correctamente.", TipoMensaje.MsgInformacion) CambioProductosServiciosCaracteristicas() End If ObjCaracteristicas.Dispose() End Sub Protected Sub GvDatosCaracteristicas_RowEditing(sender As Object, e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GvDatosCaracteristicas.RowEditing GvDatosCaracteristicas.EditIndex = e.NewEditIndex If ViewState("OrdenC").ToString() <> String.Empty Then CargaGrid(ViewState("OrdenC").ToString(), 0) Else CargaGrid("", 0) End If End Sub #End Region #Region "G V O P C I O N E S" Protected Sub GvDatosOpciones_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GvDatosOpciones.RowDataBound If e.Row.RowType = DataControlRowType.DataRow Then If e.Row.RowIndex = 0 Then e.Row.Cells(0).Width = Unit.Pixel(150) e.Row.Cells(1).Width = Unit.Pixel(150) e.Row.Cells(2).Width = Unit.Pixel(100) e.Row.Cells(3).Width = Unit.Pixel(100) e.Row.Cells(4).Width = Unit.Pixel(50) e.Row.Cells(5).Width = Unit.Pixel(50) End If e.Row.Cells(0).HorizontalAlign = HorizontalAlign.Left If e.Row.RowState = DataControlRowState.Edit OrElse e.Row.RowState = 5 Then e.Row.FCDropDownList("DdlCaracteristicaEdit").DataSource = GlobalDTProductosServiciosCaracteristicas(UsuarioActual.CveEmpresa).FiltraParametros("CvePS = " + CvePS.ToString) e.Row.FCDropDownList("DdlCaracteristicaEdit").DataBind() e.Row.FCDropDownList("DdlCaracteristicaEdit").SelectedValue = e.Row.DBCampo("CvePS") End If End If End Sub Protected Sub GvDatosOpciones_RowDeleting(sender As Object, e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GvDatosOpciones.RowDeleting Dim ObjOpciones As New ClsGralProductosServiciosCaracteristicas If ObjOpciones.RemoveProductosServiciosCaracteristicasOpciones(GvDatosOpciones.DataKeys(e.RowIndex).Value.ToString.ToEntero) Then GvDatosOpciones.EditIndex = -1 ViewState("DTProductosServiciosCaracteristicasOpciones") = ObjOpciones.DtResultados.FiltraParametros("CveEmpresa = " & UsuarioActual.CveEmpresa) GlobalDTProductosServiciosCaracteristicasOpciones(UsuarioActual.CveEmpresa) = ObjOpciones.DtResultados Alert("La Opción para Caracteristica del Producto o Servicio se eliminó correctamente.", TipoMensaje.MsgInformacion) CambioProductosServiciosCaracteristicasOpciones() End If ObjOpciones.Dispose() End Sub Protected Sub GvDatosOpciones_RowCancelingEdit(sender As Object, e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles GvDatosOpciones.RowCancelingEdit GvDatosOpciones.EditIndex = -1 If ViewState("OrdenO").ToString() <> String.Empty Then CargaGrid(ViewState("OrdenO").ToString(), 1) Else CargaGrid("", 1) End If End Sub Protected Sub GvDatosOpciones_RowUpdating(sender As Object, e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GvDatosOpciones.RowUpdating Dim ObjOpciones As New ClsGralProductosServiciosCaracteristicas Dim CveCaracteristica As Integer = DirectCast(GvDatosOpciones.Rows(e.RowIndex).FindControl("DdlCaracteristicaEdit"), DropDownList).SelectedValue.ToEntero Dim CveOpcion As Integer = GvDatosOpciones.DataKeys(e.RowIndex).Value.ToString.ToEntero Dim Opcion As String = DirectCast(GvDatosOpciones.Rows(e.RowIndex).FindControl("TxtOpcion"), TextBox).Text.Trim If ObjOpciones.UpdateProductosServiciosCaracteristicasOpciones(Opcion, CveCaracteristica, CveOpcion) Then GvDatosOpciones.EditIndex = -1 ViewState("DTProductosServiciosCaracteristicasOpciones") = ObjOpciones.DtResultados.FiltraParametros("CveEmpresa = " & UsuarioActual.CveEmpresa) GlobalDTProductosServiciosCaracteristicasOpciones(UsuarioActual.CveEmpresa) = ObjOpciones.DtResultados Alert("Los cambios se guardaron correctamente.", TipoMensaje.MsgInformacion) CambioProductosServiciosCaracteristicasOpciones() End If ObjOpciones.Dispose() End Sub Protected Sub GvDatosOpciones_RowEditing(sender As Object, e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GvDatosOpciones.RowEditing GvDatosOpciones.EditIndex = e.NewEditIndex If ViewState("OrdenO").ToString() <> String.Empty Then CargaGrid(ViewState("OrdenO").ToString(), 1) Else CargaGrid("", 1) End If End Sub #End Region #Region "O R D E N A M I E N T O" Protected Sub LbOrden_Click(ByVal sender As Object, ByVal e As EventArgs) Dim Orden As String = "" Dim Campo As String = "" Dim gvi As Integer = 0 Dim Literal As Literal = Nothing Const OrdenInicial As String = "" Dim Arg(2) As String Arg = CType(sender, LinkButton).CommandArgument().ToString.Split(";"c) Campo = Arg(0) gvi = Arg(1).ToEntero Literal = CType(CType(sender, LinkButton).NamingContainer.FindControl("Img" & Campo.Replace(",", "_")), Literal) Campo = Campo.Substring(0, Campo.Length - 1) If ViewState(String.Format("O{0}", Campo, gvi)) IsNot Nothing AndAlso ViewState(String.Format("O{0}", Campo, gvi)).ToString = String.Format("{0} DESC", Campo) Then ViewState(String.Format("O{0}", Campo)) = String.Format("{0} ASC", Campo) Literal.Text = String.Format("") Else ViewState(String.Format("O{0}", Campo, gvi)) = String.Format("{0} DESC", Campo) Literal.Text = String.Format("") End If Orden = OrdenInicial & ViewState(String.Format("O{0}", Campo, gvi)).ToString ViewState("Orden") = Orden CargaGrid(Orden, gvi) End Sub Private Sub CargaGrid(Orden As String, gvi As Integer) Dim Filtro As String = "" If gvi = 0 Then Filtro = "CvePS = " + CvePS.ToString If Orden <> String.Empty Then Dim DV As New DataView(CType(ViewState("DTProductosServiciosCaracteristicas"), DataTable), Filtro, Orden, DataViewRowState.CurrentRows) GvDatosCaracteristicas.DataSource = DV.ToTable() DV.Dispose() Else GvDatosCaracteristicas.DataSource = New DataView(GlobalDTProductosServiciosCaracteristicas(UsuarioActual.CveEmpresa), Filtro, "", DataViewRowState.CurrentRows) End If ViewState("OrdenC") = Orden GvDatosCaracteristicas.DataBind() UpDatosC.Update() ElseIf gvi = 1 Then If Not DdlCaracteristica.SelectedItem Is Nothing Then Filtro = "CvePSCaracteristica = " + DdlCaracteristica.SelectedItem.Value.ToString Else Filtro = "1 = 2" End If If Orden <> String.Empty Then Dim DV As New DataView(CType(ViewState("DTProductosServiciosCaracteristicasOpciones"), DataTable), Filtro, Orden, DataViewRowState.CurrentRows) GvDatosOpciones.DataSource = DV.ToTable() DV.Dispose() Else GvDatosOpciones.DataSource = New DataView(GlobalDTProductosServiciosCaracteristicasOpciones(UsuarioActual.CveEmpresa), Filtro, "", DataViewRowState.CurrentRows) End If ViewState("OrdenO") = Orden GvDatosOpciones.DataBind() UpDatosO.Update() End If End Sub #End Region Private Sub CargaClasificaciones() DdlClasificacion.DataSource = GlobalDTClasificaciones(UsuarioActual.CveEmpresa) DdlClasificacion.DataBind() DdlClasificacion.Items.Insert(1, New ListItem("Sin Clasificacion", "0")) DdlClasificacion.SelectedValueExist("0") 'BLOQUEA DDL CLASIFICACION If UsuarioActual.Empresa.Funcionalidad(121) = "1" Then If Not UsuarioActual.TienePermisoProceso(147) Then DdlClasificacion.Enabled = False End If End If End Sub Private Sub CargarMetodosInv() 'Dim ps As New ClsProductosServicios 'ps.GetMetodosInv() 'ddlMetodos.DataSource = ps.DtResultados ' ps.Dispose() ddlMetodos.DataSource = GlobalDTInvMetodosInventario ddlMetodos.DataBind() ddlMetodos.Items.Insert(0, New ListItem("Seleccione", "-1")) End Sub Private Sub CargaUnidadesMedida() DdlUnidadMedida.DataSource = GlobalDTUnidadesMedida(UsuarioActual.CveEmpresa) DdlUnidadMedida.DataBind() End Sub Private Sub CargaCuentasContables() 'Dim ObjContabilidad As New ClsContPAQi(UsuarioActual.Empresa.ServerContPAQi, UsuarioActual.Empresa.BDContPAQi, UsuarioActual.Empresa.UsrContPAQi, UsuarioActual.Empresa.PwdContPAQi) 'If ObjContabilidad.GetCuentas(-1, "-1", -1) Then ' DdlCtaContableVentas.DataSource = ObjContabilidad.DtResultados ' DdlCtaContableCompras.DataSource = ObjContabilidad.DtResultados ' DdlCtaContableInventarios.DataSource = ObjContabilidad.DtResultados 'Else ' DdlCtaContableVentas.DataSource = Nothing ' DdlCtaContableCompras.DataSource = Nothing ' DdlCtaContableInventarios.DataSource = Nothing 'End If 'DdlCtaContableVentas.DataBind() 'DdlCtaContableCompras.DataBind() 'DdlCtaContableInventarios.DataBind() 'ObjContabilidad.Dispose() End Sub #Region "Familias" Protected Sub DdlFamilia_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles DdlFamilia.SelectedIndexChanged CargaDdlSubFamilia() DdlSubFamilia.SelectedValue = "-1" End Sub Public Sub CargaFamilia(Optional CveSubFamilia As Integer = 0) dtFamily = GlobalDTSubFamilias(UsuarioActual.CveEmpresa) CargaDdlFamilia() If dtFamily.FiltraParametros(String.Format("CveClasificacion={0}", CveSubFamilia)).Rows.Count > 0 Then DdlFamilia.SelectedValue = dtFamily.FiltraParametros(String.Format("CveClasificacion={0}", CveSubFamilia)).Rows(0)("CveCategoria").ToString End If CargaDdlSubFamilia() If CveSubFamilia > 0 Then DdlSubFamilia.SelectedValue = CveSubFamilia.ToString End If End Sub Public Sub CargaDdlFamilia() ' Alert( GlobalDTFamilias(UsuarioActual.CveEmpresa).Rows.Count.ToString()) DdlFamilia.DataSource = GlobalDTFamilias(UsuarioActual.CveEmpresa) DdlFamilia.DataBind() End Sub Public Sub CargaDdlSubFamilia() DdlSubFamilia.DataSource = dtFamily.FiltraParametros(String.Format("CveCategoria={0}", DdlFamilia.SelectedValue), "CveClasificacion") DdlSubFamilia.DataBind() DdlSubFamilia.Items.Insert(0, New ListItem("----", "-1")) End Sub #End Region Private Sub CargaDatos() Dim ObjProductosServicios As New ClsProductosServicios() If ObjProductosServicios.GetPS(CvePS, -1, UsuarioActual.CveEmpresa) Then If ObjProductosServicios.DtResultados.Rows.Count > 0 Then 'SI NO TIENE VALOR Y NO TIENE EL PROCESO MUESTRA SIN CLASIFICACION If ObjProductosServicios.CveClasificacion.ToString.Equals("-1") And Not UsuarioActual.TienePermisoProceso(147) And UsuarioActual.Empresa.Funcionalidad(121) = "1" Then DdlClasificacion.SelectedValueExist("0") Else DdlClasificacion.SelectedValueExist(ObjProductosServicios.CveClasificacion.ToString) End If DdlUnidadMedida.SelectedValue = ObjProductosServicios.CveUnidadMedida.ToString DdlTipoPS.SelectedValue = ObjProductosServicios.CveTipoPS.ToString DdlCtaContableVentas.SelectedValue = ObjProductosServicios.IdCtaContVentas.ToString DdlCtaContableCompras.SelectedValue = ObjProductosServicios.IdCtaContCompras.ToString DdlCtaContableInventarios.SelectedValue = ObjProductosServicios.IdCtaContInventarios.ToString DdlAsientoContVentas.SelectedValue = ObjProductosServicios.AsientoContableVentas.ToString DdlAsientoContCompras.SelectedValue = ObjProductosServicios.AsientoContableCompras.ToString TxtCodigo.Text = ObjProductosServicios.Codigo TxtCodigo2.Text = ObjProductosServicios.Codigo2 TxtCodigoBarras.Text = ObjProductosServicios.CodigoBarras TxtPS.Text = ObjProductosServicios.PS TxtPrecio.Text = ObjProductosServicios.Precio.ToString("F4") 'no usa N4, porque pone comma DdlIVA.SelectedValue = ObjProductosServicios.IVA.ToString TxtRetIVA.Text = (ObjProductosServicios.RetIVA * 100).ToString TxtMG.Text = ObjProductosServicios.MargenGanancia.ToString ChkEstado.Checked = ObjProductosServicios.Estado LblFechaCaptura.Text = ObjProductosServicios.Fecha.ToShortDateString LblUsuarioCapturo.Text = ObjProductosServicios.Usuario ChkAplicaParaConcepto.Checked = ObjProductosServicios.AplicaParaConcepto ChkAplicaParaVenta.Checked = ObjProductosServicios.AplicaParaVenta lbTitulo.Text = lbTitulo.Text & ObjProductosServicios.PS ddlMetodos.SelectedValue = ObjProductosServicios.CveMetodoInventario.ToString If ObjProductosServicios.CveMetodoInventario = 0 Then ddlMetodos.SelectedValue = UsuarioActual.Empresa.CveMetodoInventario.ToString ViewState("CveSubFamilia") = ObjProductosServicios.DtResultados.Rows(0)("CveSubFamilia") Else Alert("El Producto o Servicio Solicitado no existe, por favor revise su búsqueda.", TipoMensaje.MsgAdvertencia) BtnGuardar.Enabled = False End If End If If UsuarioActual.Empresa.Funcionalidad(105) = "" Then ddlProducto.DataSource = GlobalDTProductosServicios(UsuarioActual.CveEmpresa).FiltraParametros("CvePS <>" & CvePS, "PS") ddlProducto.DataBind() DdlProductows.Visible = False Else ddlProducto.Visible = False End If If ObjProductosServicios.GetPaqueteDetalle(CvePS) Then gvPaqueteDetalle.DataSource = ObjProductosServicios.DtResultados dtPaqueteDetalles = ObjProductosServicios.DtResultados gvPaqueteDetalle.DataBind() End If ddlUnidad.DataSource = GlobalDTUnidadesMedida() ddlUnidad.DataBind() ObjProductosServicios.Dispose() End Sub Protected Sub BtnGuardar_Click(sender As Object, e As System.EventArgs) Handles BtnGuardar.Click 'Dim CerrarVentana As String = "opener.location.reload();window.close();" 'If Request("Popup") IsNot Nothing Then CerrarVentana = "self.parent.tb_remove();self.parent.location.reload();window.close();" If (TxtCodigo.Text = TxtCodigo2.Text AndAlso TxtCodigo.Text <> "") Or (TxtCodigo2.Text = TxtCodigoBarras.Text AndAlso TxtCodigo2.Text <> "") Or (TxtCodigo.Text = TxtCodigoBarras.Text AndAlso TxtCodigo.Text <> "") Then Alert("Los codigos no pueden ser iguales. Por favor rectifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia) Return End If If DdlSubFamilia.SelectedValue = "-1" AndAlso UsuarioActual.TienePermisoProceso(138) Then Alert("Se debe especificar Familia y Subfamilia de Costos. Por favor rectifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia) Exit Sub End If Dim ObjProductosServicios As New ClsProductosServicios() Dim EsPaquete As Integer = If(gvPaqueteDetalle.Rows.Count = 0, 0, 1) Dim CveMetodoInv As Integer = If(UsuarioActual.Empresa.UsaInventarios, ddlMetodos.SelectedValue.ToEntero, -1) If CvePS = -1 Then If ObjProductosServicios.AddPS(DdlClasificacion.SelectedValue.ToEntero, DdlSubFamilia.SelectedValue.ToEntero, DdlUnidadMedida.SelectedValue.ToEntero, TxtCodigo.Text.Trim, TxtCodigo2.Text.Trim, TxtCodigoBarras.Text.Trim, TxtPS.Text.Trim, TxtPrecio.Text.Trim.ToDouble, DdlIVA.SelectedValue.ToDouble, (TxtRetIVA.Text.Trim.ToDouble / 100), TxtMG.Text.Trim.ToDouble, DdlCtaContableVentas.SelectedValue.ToEntero, DdlCtaContableCompras.SelectedValue.ToEntero, DdlCtaContableInventarios.SelectedValue.ToEntero, DdlAsientoContVentas.SelectedValue.ToEntero, DdlAsientoContCompras.SelectedValue.ToEntero, ChkAplicaParaConcepto.Checked, ChkAplicaParaVenta.Checked, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveMetodoInv, EsPaquete, CveTipoPS:=DdlTipoPS.SelectedValue.ToEntero, FuePorXML:=False) > 0 Then 'Alert("El Producto o Servicio se guardó correctamente.", TipoMensaje.MsgInformacion, "document.location.href=""/ProductosServicios.aspx?CvePS=" & ObjProductosServcios.CvePS.ToString & """;") Alert("El Producto o Servicio se guardó correctamente.", TipoMensaje.MsgInformacion, "document.location.href=""/Ventas/CatPS.aspx"";") Else Alert("Ocurrió un error al agregar el Producto o Servicio. Por favor vuelva a intentar.", TipoMensaje.MsgError) End If Else If ObjProductosServicios.UpdatePS(DdlClasificacion.SelectedValue.ToEntero, DdlSubFamilia.SelectedValue.ToEntero, DdlUnidadMedida.SelectedValue.ToEntero, TxtCodigo.Text.Trim, TxtCodigo2.Text.Trim, TxtCodigoBarras.Text.Trim, TxtPS.Text.Trim, TxtPrecio.Text.Trim.ToDouble, DdlIVA.SelectedValue.ToDouble, (TxtRetIVA.Text.Trim.ToDouble / 100), TxtMG.Text.Trim.ToDouble, DdlCtaContableVentas.SelectedValue.ToEntero, DdlCtaContableCompras.SelectedValue.ToEntero, DdlCtaContableInventarios.SelectedValue.ToEntero, DdlAsientoContVentas.SelectedValue.ToEntero, DdlAsientoContCompras.SelectedValue.ToEntero, ChkAplicaParaConcepto.Checked, ChkAplicaParaVenta.Checked, ChkEstado.Checked, UsuarioActual.CveUsuario, CvePS, CveMetodoInv, EsPaquete, CveTipoPS:=DdlTipoPS.SelectedValue.ToEntero) Then 'CargaDatos() UpDatos.Update() Dim AccionJS = If(Ret = "Comp", "ircompras();", "document.location.href=""/Ventas/CatPS.aspx"";") Alert("Los cambios se guardaron correctamente.", TipoMensaje.MsgInformacion, AccionJS) Else Alert("Ocurrió un error al actualizar el Producto o Servicio. Por favor vuelva a intentar.", TipoMensaje.MsgError) End If ObjProductosServicios.CvePS = CvePS End If If ObjProductosServicios.CvePS > 0 Then For i As Integer = 0 To gvSucursal.Rows.Count - 1 If gvSucursal.Rows(i).FCCheckBox("chkSucursal").Checked = False Then ObjProductosServicios.RemovePSSucursales(ObjProductosServicios.CvePS, gvSucursal.Rows(i).DataKey("CveSucursal").ToEntero) Else If gvSucursal.Rows(i).FCHiddenField("hdnEnBD").Value.ToEntero = 1 Then 'Actualizarlo ObjProductosServicios.UpdatePSSucursales(ObjProductosServicios.CvePS, gvSucursal.Rows(i).DataKey("CveSucursal").ToEntero, gvSucursal.Rows(i).FCTextBox("txtImporte").Text.ToDouble, UsuarioActual.CveUsuario) 'ObjProductosServicios.UpdatePSSucursales(ObjProductosServicios.CvePS, gvSucursal.Rows(i).FCHiddenField("hdnCveSucursal").Value.ToEntero, gvSucursal.Rows(i).FCTextBox("txtImporte").Text.ToDouble, UsuarioActual.CveUsuario) Else 'Insertarlo 'ObjProductosServicios.AddPSSucursales(ObjProductosServicios.CvePS, gvSucursal.Rows(i).FCHiddenField("hdnCveSucursal").Value.ToEntero, gvSucursal.Rows(i).FCTextBox("txtImporte").Text.ToDouble, UsuarioActual.CveUsuario) ObjProductosServicios.AddPSSucursales(ObjProductosServicios.CvePS, gvSucursal.Rows(i).DataKey("CveSucursal").ToEntero, gvSucursal.Rows(i).FCTextBox("txtImporte").Text.ToDouble, UsuarioActual.CveUsuario) End If End If Next End If ObjProductosServicios.Dispose() RecargaGlobal() End Sub Private Sub RecargaGlobal() Dim Hilo As New System.Threading.Thread(AddressOf GeneraGlobalDT) Hilo.Start() End Sub Private Sub GeneraGlobalDT() Dim ObjPS As New ClsProductosServicios If (ObjPS.GetPS(-1, -1, -1)) Then GlobalDTProductosServicios(-1) = ObjPS.DtResultados End If If ObjPS.GetPSAlias(-1, -1) Then GlobalDTProductosServiciosAlias(-1) = ObjPS.DtResultados End If If ObjPS.GetPSEquivalencias(-1, -1) Then GlobalDTProductosServiciosEquivalencias(-1, -1) = ObjPS.DtResultados End If ObjPS.Dispose() End Sub Protected Sub BtnEliminar_Click(sender As Object, e As System.EventArgs) Handles BtnEliminar.Click 'Dim CerrarVentana As String = "opener.location.reload();window.close();" 'If Request("Popup") IsNot Nothing Then CerrarVentana = "self.parent.tb_remove();self.parent.location.reload();window.close();" Dim ObjProductosServcios As New ClsProductosServicios() If ObjProductosServcios.RemovePS(CvePS) Then RecargaGlobal() Alert("El Producto o Servicio se eliminó correctamente.", TipoMensaje.MsgInformacion, "document.location.href=""/Ventas/CatPS.aspx"";") Else Alert("Ocurrió un error al elimiar el Producto o Servicio. Por favor vuelva a intentar.", TipoMensaje.MsgError) End If ObjProductosServcios.Dispose() End Sub Protected Sub btguardar_Click(sender As Object, e As EventArgs) Handles btguardar.Click Dim ObjProductosServicios As New ClsProductosServicios If ObjProductosServicios.AddPaqueteDetalle(CvePS, HFProducto.Value.ToString.ToEntero, txtCantidad.Text.ToDouble, ddlTipo.SelectedValue.ToEntero, ddlUnidad.SelectedValue.ToEntero) Then If ObjProductosServicios.GetPaqueteDetalle(CvePS) Then gvPaqueteDetalle.EditIndex = -1 gvPaqueteDetalle.DataSource = ObjProductosServicios.DtResultados gvPaqueteDetalle.DataBind() End If End If ObjProductosServicios.Dispose() End Sub Protected Sub HFProducto_ValueChanged(sender As Object, e As EventArgs) Handles HFProducto.ValueChanged ddlUnidad.DataSource = GlobalDTProductosServiciosEquivalencias(HFProducto.Value.ToEntero, -1) ddlUnidad.DataBind() End Sub Protected Sub gvPaqueteDetalle_RowDeleting(sender As Object, e As GridViewDeleteEventArgs) Handles gvPaqueteDetalle.RowDeleting Dim ObjProductosServicios As New ClsProductosServicios Dim tipo As Integer = 0 If dtPaqueteDetalles.Rows.Item(e.RowIndex)("Tipo").ToString = "Paquete" Then tipo = 1 Else tipo = 2 End If If ObjProductosServicios.DeletePaqueteDetalle(dtPaqueteDetalles.Rows.Item(e.RowIndex)("CvePSPaquete").ToString.ToEntero, dtPaqueteDetalles.Rows.Item(e.RowIndex)("CvePS").ToString.ToEntero, dtPaqueteDetalles.Rows.Item(e.RowIndex)("Cantidad").ToString.ToDouble, tipo, dtPaqueteDetalles.Rows.Item(e.RowIndex)("CveUnidadMedida").ToString.ToEntero) Then If ObjProductosServicios.GetPaqueteDetalle(CvePS) Then gvPaqueteDetalle.EditIndex = -1 gvPaqueteDetalle.DataSource = ObjProductosServicios.DtResultados dtPaqueteDetalles = ObjProductosServicios.DtResultados gvPaqueteDetalle.DataBind() End If End If ObjProductosServicios.Dispose() End Sub Protected Sub gvPaqueteDetalle_RowEditing(sender As Object, e As GridViewEditEventArgs) Handles gvPaqueteDetalle.RowEditing gvPaqueteDetalle.EditIndex = e.NewEditIndex gvPaqueteDetalle.DataSource = dtPaqueteDetalles gvPaqueteDetalle.DataBind() End Sub Protected Sub gvPaqueteDetalle_RowCancelingEdit(sender As Object, e As GridViewCancelEditEventArgs) Handles gvPaqueteDetalle.RowCancelingEdit gvPaqueteDetalle.EditIndex = -1 gvPaqueteDetalle.DataSource = dtPaqueteDetalles gvPaqueteDetalle.DataBind() End Sub Protected Sub gvPaqueteDetalle_RowUpdating(sender As Object, e As GridViewUpdateEventArgs) Handles gvPaqueteDetalle.RowUpdating Dim ObjProductosServicios As New ClsProductosServicios If ObjProductosServicios.UpdatePaqueteDetalle(CvePS, dtPaqueteDetalles.Rows.Item(e.RowIndex)("CvePS").ToString.ToEntero, DirectCast(gvPaqueteDetalle.Rows(e.RowIndex).FindControl("txtECantidad"), TextBox).Text.ToDouble, DirectCast(gvPaqueteDetalle.Rows(e.RowIndex).FindControl("ddlETipo"), DropDownList).SelectedValue.ToEntero, DirectCast(gvPaqueteDetalle.Rows(e.RowIndex).FindControl("ddlEUnidad"), DropDownList).SelectedValue.ToEntero) Then If ObjProductosServicios.GetPaqueteDetalle(CvePS) Then gvPaqueteDetalle.EditIndex = -1 gvPaqueteDetalle.DataSource = ObjProductosServicios.DtResultados dtPaqueteDetalles = ObjProductosServicios.DtResultados gvPaqueteDetalle.DataBind() End If End If ObjProductosServicios.Dispose() End Sub Protected Sub gvEquivalencias_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles gvPaqueteDetalle.RowDataBound If e.Row.RowState = DataControlRowState.Edit OrElse e.Row.RowState = 5 Then e.Row.FCDropDownList("ddlEUnidad").DataSource = GlobalDTUnidadesMedida() e.Row.FCDropDownList("ddlEUnidad").SelectedValue = e.Row.DBCampo("CveUnidadMedida") e.Row.FCDropDownList("ddlEUnidad").DataBind() End If End Sub Protected Sub LbAgregar_Click(sender As Object, e As System.EventArgs) Handles LbAgregar.Click Dim ObjAliasAdd As New ClsProductosServicios If ObjAliasAdd.AddPSAlias(TxtAlias.Text.ToString, CvePS) Then GlobalDTProductosServiciosAlias(-1) = ObjAliasAdd.DtResultados CargarAlias() UPGVAlias.Update() Alert("Alias " + TxtAlias.Text + " agregado.", TipoMensaje.MsgInformacion) TxtAlias.Text = "" End If ObjAliasAdd.Dispose() End Sub Protected Sub CargarAlias() Dim ObjAlias As New ClsProductosServicios ObjAlias.GetPSAlias(CvePS, UsuarioActual.CveEmpresa) GVAlias.DataSource = ObjAlias.DtResultados ObjAlias.Dispose() GVAlias.DataBind() End Sub Protected Sub GVAlias_RowDeleting(sender As Object, e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GVAlias.RowDeleting Dim ObjAliasDelete As New ClsProductosServicios If ObjAliasDelete.RemovePSAlias(GVAlias.Rows(e.RowIndex).DataKey("CvePS").ToString.ToEntero, GVAlias.Rows(e.RowIndex).DataKey("PSAlias").ToString) Then GlobalDTProductosServiciosAlias(-1) = ObjAliasDelete.DtResultados GVAlias.EditIndex = -1 CargarAlias() UPGVAlias.Update() Alert("El Alias ha sido Eliminado", TipoMensaje.MsgInformacion) Else Alert("Error al Eliminar", TipoMensaje.MsgError) End If ObjAliasDelete.Dispose() End Sub End Class