Imports DevExpress.Xpf.Editors Imports DevExpress.Xpf.LayoutControl Imports tsWPFCore Imports System.ComponentModel Imports System.Data Imports DevExpress.Xpf.Editors.Validation Imports DevExpress.Xpf.Editors.Helpers Imports DevExpress.Xpf.Core Imports tsWPFCore.modExtensiones Imports System.Data.Common Imports System.Data.Entity Imports bdGrupoSanchoToro.db Imports tsUtilidades.Datos Imports DevExpress.Xpf.Bars Imports DevExpress.Xpf.Grid Imports System.Collections Imports tsUtilidades.Extensiones Imports tsUtilidades.Enumeraciones Imports bdGrupoSanchoToro.db.Utilidades Imports bdGrupoSanchoToro.db.tscGrupoSanchoToro Imports System.Drawing Imports bdGrupoSanchoToro.db.albaranes Public Class ucAlbaran Private bd As tscGrupoSanchoToro Friend _idAlbaran As Nullable(Of Integer) Private lProductos As List(Of productos) Private lArticulos As List(Of articulos) Friend idLog As Integer? Public Overrides Sub Cargado() Me.Tipo_ucControlBusqueda = GetType(ucAlbaranes) End Sub Dim ra As albaranes Public Overrides Sub EstableceDataContextSecundarios(Optional Background As Boolean = False) Try lProductos = bd.productos.OrderBy(Function(x) x.Descripcion).ToList Dim lProductosAlb = ra.detallesalbaranes.Select(Function(x) x.idProducto).ToArray lProductos = lProductos.Where(Function(x) x.FechaBaja Is Nothing OrElse lProductosAlb.Contains(x.idProducto)).ToList cbProducto.ItemsSource = lProductos cbRazonSocial.ItemsSource = bd.entidades.Where(Function(X) X.FechaBaja.HasValue = False OrElse X.idEntidad = ra.idEntidad).ToList.Select(Function(x) New With {x.idEntidad, x.RazonSocial}).OrderBy(Function(x) x.RazonSocial).ToList Dim plantillas As List(Of tsWPFCore.Plantilla) = Comun.ObtienePlantillas(bd, {"GRUPLA.ALBENT"}, False) Me.ContenedorAplicacion.cbPlantillaAImprimir.ItemsSource = plantillas If plantillas.Count > 0 Then Me.ContenedorAplicacion.bePlantilla.EditValue = plantillas.First.idPlantilla End If Dim Acciones As New List(Of tsWPFCore.Accion) Acciones.Add(New Accion With { .idAccion = 1, .Descripcion = "GENERA ALBARÁN DE RECOGIDA Y FACTURA RÁPIDA (F10)"}) Acciones.Add(New Accion With { .idAccion = 3, .Descripcion = "GENERA ALBARÁN DE RECOGIDA DE PRODUCTOS PENDIENTES (F11)"}) Acciones.Add(New Accion With { .idAccion = 2, .Descripcion = "ENVIAR ALBARÁN POR CORREO ELECTRÓNICO (F12)"}) Me.ContenedorAplicacion.cbAcciones.ItemsSource = Acciones Me.ContenedorAplicacion.beAcciones.EditValue = Acciones.First.idAccion Catch ex As Exception Throw New Exception(ex.Message, ex) End Try End Sub Public Overrides Function EstablecedcPrincipal(Optional Background As Boolean = False, Optional FuerzaNuevo As Boolean = False, Optional Refrescar As Boolean = False) As tsUtilidades.EstadosAplicacion Try Dim NuevoEstado As tsUtilidades.EstadosAplicacion If idLog.HasValue Then 'Try ' Dim log = bd.logs.First(Function(x) x.idLog = idLog) ' ra = tsUtilidades.Utilidades.DeserializarSinErrores(log.LogXML, GetType(albaranes)) ' If ra.idUsuario.HasValue Then ra.idUsuarioNavigation = bd.usuarios.FirstOrDefault(Function(x) x.idUsuario = ra.idUsuario.Value) ' Dim df = bd.logs.FirstOrDefault(Function(x) x.idRelacionado = log.idLog AndAlso x.Aplicacion = "detallesalbaranes_AE") ' If df IsNot Nothing Then ' Dim ld As List(Of detallesalbaranes) = tsUtilidades.Utilidades.DeserializarSinErrores(df.LogXML, GetType(List(Of detallesalbaranes))) ' For Each d In ld ' Dim pr = bd.productos.FirstOrDefault(Function(x) x.idProducto = d.idProducto) ' d.productos = pr ' If d.idArticulo.HasValue Then ' Dim art = bd.articulos.FirstOrDefault(Function(x) x.idArticulo = d.idArticulo) ' d.articulos = art ' End If ' ra.detallesalbaranes.Add(d) ' Next ' End If ' Dim mv = bd.logs.FirstOrDefault(Function(x) x.idRelacionado = log.idLog AndAlso x.Aplicacion = "MOVIMIENTOSCAJA_AE") ' If mv IsNot Nothing Then ' Dim ld = tsUtilidades.Utilidades.DeserializarSinErrores(mv.LogXML, GetType(List(Of movimientoscaja))) ' For Each d In ld ' ra.movimientoscaja.Add(d) ' Next ' End If ' Dim lent = bd.logs.FirstOrDefault(Function(x) x.idRelacionado = log.idLog AndAlso x.Aplicacion = "ENTIDADES") ' If lent IsNot Nothing Then ' Dim ent = tsUtilidades.Utilidades.DeserializarSinErrores(lent.LogXML, GetType(entidades)) ' ra.entidades = ent ' ' lgDatosCliente.DataContext = ra.entidades ' End If ' Dim lobr = bd.logs.FirstOrDefault(Function(x) x.idRelacionado = log.idLog AndAlso x.Aplicacion = "OBRAS") ' If lobr IsNot Nothing Then ' Dim obr = tsUtilidades.Utilidades.DeserializarSinErrores(lobr.LogXML, GetType(destinomontajes)) ' ra.destinomontajes = obr ' ' lgDatosObra.DataContext = ra.destinomontajes ' End If ' NuevoEstado = tsUtilidades.EstadosAplicacion.ModificandoRegistro 'Catch EX As Exception ' Throw New Exception("No ha sido posible mostrar el registro del cambio (id " & idLog.Value.ToString & ").", EX) 'End Try Else If FuerzaNuevo OrElse _idAlbaran Is Nothing Then ra = New albaranes _idAlbaran = Nothing ra.Fecha = DateOnly.FromDateTime(Today) ra.NumeroBultos = 1 NuevoEstado = tsUtilidades.EstadosAplicacion.Nuevo Else ra = bd.albaranes.First(Function(x) x.idAlbaran = _idAlbaran) NuevoEstado = tsUtilidades.EstadosAplicacion.ModificandoRegistro End If End If If Me.cbTipo.ItemsSource Is Nothing Then cbTipo.ItemsSource = tsUtilidades.DescripcionValor.EnumADescripcionValor(GetType(bdGrupoSanchoToro.db.albaranes.TipoAlbaranEnum)) cbAlmacenOrigen.ItemsSource = Comun.ObtieneListaAlmacenes(bd) cbAlmacenDestino.ItemsSource = Comun.ObtieneListaAlmacenes(bd) End If Me.gcLogs.ItemsSource = bd.logs.Where(Function(x) x.id = ra.idAlbaran AndAlso x.Aplicacion = "albaranes").ToList gcProductos.ItemsSource = ra.detallesalbaranes Me.DataContext = ra Return NuevoEstado Catch ex As Exception Throw New Exception(ex.Message, ex) End Try End Function Public Overrides Function ObtieneBD() As tsUtilidades.ItsContexto bd = tscGrupoSanchoToro.NuevoContexto Return bd End Function Public Overrides ReadOnly Property NombreTablaBase As String Get Return "albaranes" End Get End Property Private ReadOnly Property IAplicacion_CampoIndice As String Get Return "idAlbaran" End Get End Property Public Overrides ReadOnly Property idRegistroAplicacionActual As String Get If idLog.HasValue Then Return "Albarán R.C.:" & idLog.ToString Else If Me.Estado = tsUtilidades.EstadosAplicacion.Nuevo Then Return "Albarán.Nuevo" Else Return "Albarán." & DirectCast(Me.DataContext, albaranes).idAlbaran.ToString End If End If End Get End Property Public Overrides ReadOnly Property DescripcionRegistro As String Get Return "Albarán" End Get End Property 'Public Overrides ReadOnly Property CampoIndice As String ' Get ' Return "idAlbaranEntrega" ' End Get 'End Property Public Sub New(Optional idAlbaran As Integer? = Nothing) ' Llamada necesaria para el diseñador. InitializeComponent() _idAlbaran = idAlbaran ' Agregue cualquier inicialización después de la llamada a InitializeComponent(). End Sub Public Overrides Sub EstableceTitulo() If idLog.HasValue Then Me.docpanel.Caption = "R.C. Albarán " & ra.idAlbaran Me.docpanel.Tag = "R.C. Albarán." & ra.idAlbaran Else If Me.Estado = tsUtilidades.EstadosAplicacion.ModificandoRegistro Then Me.docpanel.Caption = "Albarán " & ra.idAlbaran Me.docpanel.Tag = "Albarán." & ra.idAlbaran.ToString Else Me.docpanel.Caption = "Albarán Nuevo" Me.docpanel.Tag = "Albaran.Nuevo" End If End If End Sub Public Overrides Function obtienePermisos() As tsUtilidades.Permisos Return Comun.ObtienePermisos(Me.bd, "AP.ADMINISTRATIVOS", bdGrupoSanchoToro.db.Utilidades.idUsuario) End Function Private Sub ap_ValidarControl(sender As Object, e As ValidationEventArgs, ByRef ev As ErrorValidacion, ByRef ValorOriginalCambiado As Object) Handles Me.ValidarControl Dim pts As PropiedadesTS = sender.parent.propiedadests Try If Not pts Is Nothing Then Me.ErroresValidacion.EliminaError("validando-" & pts.NombreCampo) Select Case pts.NombreCampo.ToLower Case "codigopostalcarga" If Not e.Value Is Nothing AndAlso e.Value.ToString <> "" AndAlso e.Value.ToString <> ra.CodigoMunicipioCarga Then Dim sCpo As String = e.Value.ToString If sCpo.Length <> 5 Then Throw New Exception("El código postal no es correcto") Dim sCodigoprovincia As String = sCpo.Substring(0, 2) If Not bd.provincias.Any(Function(x) x.CodigoProvincia = sCodigoprovincia) Then If sCpo.Length <> 5 Then Throw New Exception("El código postal del Cliente no es correcto") Select Case bd.codigospostales.Where(Function(x) x.CodigoPostal = sCpo).Count Case 0 Dim vncp As New dxwAgregarNuevoCodigoPostal(sCpo, bd) If vncp.ShowDialog Then Dim pob = bd.codigospostales.First(Function(x) x.CodigoPostal = sCpo) ra.CodigoMunicipioCarga = pob.CodigoMunicipio Else Throw New Exception("El código postal de la carga no es correcto") End If Case 1 Dim pob = bd.codigospostales.First(Function(x) x.CodigoPostal = sCpo) ra.CodigoMunicipioCarga = pob.CodigoMunicipio Case Else Dim wMunicipios As New dxwCodigosPostales(bd, sCpo) If wMunicipios.ShowDialog Then ra.CodigoMunicipioCarga = wMunicipios.CodigoMunicipio Else Throw New Exception("El código postal de la carga no es correcto") End If End Select ra.CodigoMunicipioCargaNavigation = bd.municipios.First(Function(x) x.CodigoMunicipio = ra.CodigoMunicipioCarga) ' ra.CodigoPostalCarga = sCpo ra.RefrescaCamposSoloLectura() End If Case "codigopostaldescarga" If Not e.Value Is Nothing AndAlso e.Value.ToString <> "" AndAlso e.Value.ToString <> ra.CodigoMunicipioDescarga Then Dim sCpo As String = e.Value.ToString If sCpo.Length <> 5 Then Throw New Exception("El código postal no es correcto") Dim sCodigoprovincia As String = sCpo.Substring(0, 2) If Not bd.provincias.Any(Function(x) x.CodigoProvincia = sCodigoprovincia) Then If sCpo.Length <> 5 Then Throw New Exception("El código postal del Cliente no es correcto") Select Case bd.codigospostales.Where(Function(x) x.CodigoPostal = sCpo).Count Case 0 Dim vncp As New dxwAgregarNuevoCodigoPostal(sCpo, bd) If vncp.ShowDialog Then Dim pob = bd.codigospostales.First(Function(x) x.CodigoPostal = sCpo) ra.CodigoMunicipioDescarga = pob.CodigoMunicipio Else Throw New Exception("El código postal de la descarga no es correcto") End If Case 1 Dim pob = bd.codigospostales.First(Function(x) x.CodigoPostal = sCpo) ra.CodigoMunicipioDescarga = pob.CodigoMunicipio Case Else Dim wMunicipios As New dxwCodigosPostales(bd, sCpo) If wMunicipios.ShowDialog Then ra.CodigoMunicipioDescarga = wMunicipios.CodigoMunicipio Else Throw New Exception("El código postal de la descarga no es correcto") End If End Select ra.CodigoMunicipioDescargaNavigation = bd.municipios.First(Function(x) x.CodigoMunicipio = ra.CodigoMunicipioCarga) ' ra.CodigoPostalDescarga = sCpo ra.RefrescaCamposSoloLectura() End If Case "emailcarga" If e.Value IsNot Nothing AndAlso e.Value.ToString <> "" Then If Not e.Value.ToString.Trim.ToLower.EsEmailValido Then Throw New Exception("El email es incorrecto") End If Case "emaildescarga" If e.Value IsNot Nothing AndAlso e.Value.ToString <> "" Then If Not e.Value.ToString.Trim.ToLower.EsEmailValido Then Throw New Exception("El email es incorrecto") End If End Select End If Catch ex As Exception Dim sCodigoError As String = "validando-" If pts IsNot Nothing Then sCodigoError &= pts.NombreCampo End If ev = New ErrorValidacion(sCodigoError, sender, ex.Message, ex, DevExpress.XtraEditors.DXErrorProvider.ErrorType.Critical) e.IsValid = False End Try End Sub Private Sub BtAñadirCodigoPostalCarga_Click(sender As Object, e As RoutedEventArgs) If ContenedorAplicacion.btGuardar.IsEnabled Then Dim vncp As New dxwAgregarNuevoMunicipio("") If vncp.ShowDialog Then Dim pob = bd.codigospostales.AsNoTracking.First(Function(x) x.CodigoPostal = vncp._CodigoPostal) ra.CodigoMunicipioCarga = pob.CodigoMunicipio ra.CodigoPostalCarga = vncp._CodigoPostal ra.CodigoMunicipioCargaNavigation = bd.municipios.AsNoTracking.First(Function(x) x.CodigoMunicipio = ra.CodigoMunicipioCarga) ra.RefrescaCamposSoloLectura() End If End If End Sub Private Sub BtAñadirCodigoPostalDesCarga_Click(sender As Object, e As RoutedEventArgs) If ContenedorAplicacion.btGuardar.IsEnabled Then Dim vncp As New dxwAgregarNuevoMunicipio("") If vncp.ShowDialog Then Dim pob = bd.codigospostales.First(Function(x) x.CodigoPostal = vncp._CodigoPostal) ra.CodigoMunicipioDescarga = pob.CodigoMunicipio ra.CodigoPostalDescarga = vncp._CodigoPostal ra.CodigoMunicipioDescargaNavigation = bd.municipios.AsNoTracking.First(Function(x) x.CodigoMunicipio = ra.CodigoMunicipioDescarga) ra.RefrescaCamposSoloLectura() End If End If End Sub Private Sub BtCancelarCodigoPostalCarga_Click(sender As Object, e As RoutedEventArgs) If ContenedorAplicacion.btGuardar.IsEnabled Then ra.CodigoPostalCarga = "" ra.CodigoMunicipioCarga = "" ra.CodigoMunicipioCarga = Nothing ra.RefrescaCamposSoloLectura() End If End Sub Private Sub BtCancelarCodigoPostalDescarga_Click(sender As Object, e As RoutedEventArgs) If ContenedorAplicacion.btGuardar.IsEnabled Then ra.CodigoPostalDescarga = "" ra.CodigoMunicipioDescarga = "" ra.CodigoMunicipioDescargaNavigation = Nothing ra.RefrescaCamposSoloLectura() End If End Sub Private Sub ap_DespuesGuardar(sender As Object, e As ItemClickEventArgs, OpcionGuardado As Integer) Handles Me.DespuesGuardar Dim ae As albaranes = Me.DataContext _idAlbaran = DirectCast(Me.DataContext, albaranes).idAlbaran Me.gcLogs.ItemsSource = bd.logs.Where(Function(x) x.id = ae.idAlbaran AndAlso x.Aplicacion = "albaranes").ToList End Sub Private Sub ap_Enlazar(Celda As EditGridCellData, Defecto As Boolean) Handles Me.Enlazar Select Case Celda.Column.FieldName.ToLower Case "idlog" Dim log As logs = gcLogs.CurrentItem Dim id As Integer = log.idLog Dim uc As New ucAlbaran uc.idLog = log.idLog FuncionesDinamicas.AbrirAP(uc, OtrosParametros) End Select End Sub Private Sub ap_EstadoCambiado(EstadoAnterior As tsUtilidades.EstadosAplicacion, EstadoNuevo As tsUtilidades.EstadosAplicacion) Handles Me.EstadoCambiado If idLog.HasValue Then EstableceSoloLectura() Select Case EstadoNuevo Case tsUtilidades.EstadosAplicacion.ModificandoRegistro If ra.Tipo = TipoAlbaranEnum.COMPRA Then gcEsventa.ReadOnly = True Else gcEsventa.ReadOnly = False End If End Select End Sub Private Sub BiBuscarProducto_Click(sender As Object, e As RoutedEventArgs) If tvProductos.ActiveEditor Is Nothing Then Dispatcher.BeginInvoke(New Action(Sub() tvProductos.ShowEditor()), System.Windows.Threading.DispatcherPriority.Render) End If Dim dxw As New dxwProductos(lProductos) If dxw.ShowDialog Then Dim dea As detallesalbaranes = gcProductos.CurrentItem Dim prod = lProductos.First(Function(x) x.idProducto = dxw.idProducto) If tvProductos.ActiveEditor IsNot Nothing Then tvProductos.ActiveEditor.EditValue = prod.idProducto Else Debug.Write("no") End If tvProductos.PostEditor() tvProductos.CloseEditor() gcProductos.RefreshRow(tvProductos.FocusedRowHandle) End If End Sub Private Sub BiBuscarCliente_Click(sender As Object, e As RoutedEventArgs) 'If Me.Estado = EstadosAplicacion.Nuevo Then Dim dxw As New dxwEntidades(bd, True, False) If dxw.ShowDialog Then Dim ent = bd.entidades.First(Function(x) x.idEntidad = dxw.Entidad.idEntidad) ra.idEntidadNavigation = ent ra.idEntidad = ent.idEntidad End If ' End If End Sub Private Sub RellenaDatosProducto(dea As detallesalbaranes) If dea IsNot Nothing AndAlso dea.idProducto <> 0 Then Dim ae As albaranes = Me.DataContext Dim pr = lProductos.First(Function(x) x.idProducto = dea.idProducto) If dea.Cantidad = 0 Then dea.Cantidad = 1 dea.EsVenta = False End If End Sub Private Sub tvProductos_PreviewKeyDown(sender As Object, e As KeyEventArgs) Handles tvProductos.PreviewKeyDown If e.Key = Key.F6 Then Select Case gcProductos.CurrentColumn.FieldName.ToLower Case "idproducto" BiBuscarProducto_Click(Nothing, Nothing) End Select End If End Sub Private Sub BeCodigoPostalCarga_DefaultButtonClick(sender As Object, e As RoutedEventArgs) Dim dxw As New dxwCodigosPostales(bd, "") If dxw.ShowDialog Then ra.CodigoMunicipioCarga = dxw.CodigoMunicipio ra.CodigoMunicipioCargaNavigation = bd.municipios.First(Function(x) x.CodigoMunicipio = ra.CodigoMunicipioCarga) ra.CodigoPostalCarga = dxw.CodigoPostal ra.RefrescaCamposSoloLectura() End If End Sub Private Sub BeCodigoPostalDescarga_DefaultButtonClick(sender As Object, e As RoutedEventArgs) Dim dxw As New dxwCodigosPostales(bd, "") If dxw.ShowDialog Then ra.CodigoMunicipioDescarga = dxw.CodigoMunicipio ra.CodigoPostalDescarga = dxw.CodigoPostal ra.CodigoMunicipioDescargaNavigation = bd.municipios.First(Function(x) x.CodigoMunicipio = ra.CodigoMunicipioDescarga) ra.RefrescaCamposSoloLectura() End If End Sub Private Sub uc_ImprimirPlantilla(sender As Object, e As ItemClickEventArgs, idPlantilla As Integer, Previsualizar As Boolean) Handles Me.ImprimirPlantilla If Me.Estado = tsUtilidades.EstadosAplicacion.ModificandoRegistro Then Dim bdtmp = tscGrupoSanchoToro.NuevoContexto Dim ae = bdtmp.albaranes.First(Function(x) x.idAlbaran = ra.idAlbaran) Imprimir(ra, idPlantilla, 1, False) Else DXMessageBox.Show("Antes debe almacenar", "Atención") End If End Sub Private Sub Imprimir(ra As albaranes, idPlantilla As Integer, Copias As Integer, ImpresoraDefecto As Boolean) Dim ds As List(Of albaranes) ' Dim pl As plantillas = (From p In bd.plantillas Where p.idPlantilla = idPlantilla).First Dim pl = bd.plantillas.AsNoTracking.Where(Function(x) x.idPlantilla = idPlantilla).Select(Function(x) New With {.Fichero = x.idFicheroNavigation.Fichero, .Tipo = x.idGrupoNavigation.Codigo}).FirstOrDefault ds = New List(Of albaranes) ds.Add(ra) Select Case pl.Tipo Case Else ' "GRUPLA.ALBENT" tsWPFCore.tsXtraReport.ImprimirPlantilla(pl.Fichero, ImpresoraDefecto, Copias, ds) End Select End Sub Private Sub tvProductos_ShowingEditor(sender As Object, e As ShowingEditorEventArgs) Handles tvProductos.ShowingEditor 'If ra.detallesalbaranes.ToList.Any(Function(x) x.idAlbaranRecogida.HasValue OrElse (x.idUltimaFactura.HasValue AndAlso (x.facturas.Fecha > ra.Fecha.Date))) Then ' If e.RowHandle <> DataControlBase.NewItemRowHandle Then ' Dim da As detallesalbaranes = gcProductos.GetRow(e.RowHandle) ' If e.Column.FieldName.ToLower <> "observaciones" AndAlso e.Column.FieldName.ToLower <> "fechacancelacion" AndAlso e.Column.FieldName.ToLower <> "motivocancelacion" AndAlso e.Column.FieldName.ToLower <> "precio" AndAlso e.Column.FieldName.ToLower <> "cantidad" Then ' If da.idAlbaranRecogida.HasValue OrElse da.idUltimaFactura.HasValue Then ' e.Cancel = True ' e.Handled = True ' End If ' End If ' End If 'End If End Sub Private Sub beCodigoPostalCarga_PreviewKeyDown(sender As Object, e As KeyEventArgs) Handles beCodigoPostalCarga.PreviewKeyDown If e.Key = Key.F6 Then BeCodigoPostalCarga_DefaultButtonClick(Nothing, Nothing) End If End Sub Private Sub beCodigoPostalDescarga_PreviewKeyDown(sender As Object, e As KeyEventArgs) Handles beCodigoPostalDescarga.PreviewKeyDown If e.Key = Key.F6 Then BeCodigoPostalDescarga_DefaultButtonClick(Nothing, Nothing) End If End Sub Private Sub tvProductos_ValidateRow(sender As Object, e As GridRowValidationEventArgs) Handles tvProductos.ValidateRow 'Dim da As detallesalbaranes = e.Row 'Dim Errores As String = "" 'If da.Cantidad <> 1 AndAlso da.idArticulo.HasValue Then ' Errores &= "Si es un artículo en concreto la cantidad tiene que ser 1" & vbCrLf 'End If 'If Errores <> "" Then ' DXMessageBox.Show(Errores, "Error") ' e.SetError(Errores) ' e.IsValid = False 'End If Try Dim htErrores = New Hashtable ErroresValidacion.LimpiarErrores("TSGC-" & gcProductos.PropiedadesTS.NumeroObjeto.ToString & ":" & e.RowHandle.ToString & ":") Dim da As detallesalbaranes = e.Row If da.Cantidad <> 1 AndAlso da.idArticulo.HasValue Then htErrores.Add("Cantidad1", "Si es un artículo en concreto la cantidad tiene que ser 1") End If If htErrores.Count > 0 Then Me.AgregaErroresTSGC(gcProductos, htErrores, e) End If Catch ex As Exception FuncionesDinamicas.ErrorNoControladoAp(Me, ex) DXMessageBox.Show(ex.Message, "Error") End Try End Sub Private Sub tvProductos_InitNewRow(sender As Object, e As InitNewRowEventArgs) Handles tvProductos.InitNewRow gcProductos.SetCellValue(e.RowHandle, "Cantidad", 1) End Sub Private Sub ucAlbaranEntrega_EjecutarAccion(sender As Object, e As ItemClickEventArgs, idAccion As Integer) Handles Me.EjecutarAccion 'Select Case idAccion ' Case 1 ' GENERA ALBARÁN DE RECOGIDA Y FACTURA RAPIDA ' Try ' If Not Guardar(Nothing, Nothing,,, 3) Then ' Dim ae As albaranes = Me.DataContext ' ' If ae.detallesalbaranes.Any(Function(x) x.idAlbaranRecogida.HasValue) Then ' ' DXMessageBox.Show("Sólo se puede generar una factura rápida si no se ha recogido ningún producto del albarán", "Atención") ' ' Else ' Dim ar As albaranesrecogida = New albaranesrecogida ' With ar ' .Fecha = Now ' .idCliente = ae.idCliente ' .idUsuario = idUsuario ' .EstableceNumeroAlbaran(bd) ' End With ' bd.albaranesrecogida.Add(ar) ' For Each d In ae.detallesalbaranes.Where(Function(x) x.EsVenta = False AndAlso x.idAlbaranRecogida.HasValue = False) ' d.albaranesrecogida = ar ' Next ' bd.GuardarCambios() ' Dim id As Integer = ae.idAlbaranEntrega ' Dim uc As New ucFacturaEmitida(,, id) ' FuncionesDinamicas.AbrirAP(uc, OtrosParametros) ' tsWPFCore.Comun.dm.DockController.RemovePanel(docpanel) ' End If ' Catch ex As Exception ' FuncionesDinamicas.ErrorNoControladoAp(Me, ex) ' DXMessageBox.Show(ex.Message, "Error") ' End Try ' Case 2 ' ENVIA ALBARÁN DE ENTREGA POR EMAIL ' Dim bCancelar As Boolean = False ' If Me.ContenedorAplicacion.btGuardar.IsEnabled Then ' bCancelar = Me.Guardar(Nothing, Nothing,, True, 5) ' End If ' If Not bCancelar Then ' Dim dxnc = New dxwEnvioCorreo(ra.entidades.Email, ra.entidades.Email2, "", "Producciones Romian, S.L. - Adjunto le remitimos albarán de entrega nº " & ra.NumeroAlbaran, "Distinguidos Sres., " & vbCrLf & "Adjunto le remitimos albarán entrega nº " & ra.NumeroAlbaran, "AlbaranEntrega_" & ra.NumeroAlbaran.Replace("/", "-") & ".pdf") ' If dxnc.ShowDialog Then ' Dim cta = bd.cuentascorreo.First(Function(x) x.Codigo = "DEFECTO") ' Dim bAlbaran = GeneraPdfAlbaran(bd, ra) ' bdGrupoSanchoToro.db.correos.GeneraRegistroCorreon(bd, dxnc._Asunto, dxnc._Cuerpo, cta, dxnc._Destinatarios, dxnc._CC, dxnc._BCC, bAlbaran, dxnc._Adjunto, ra.idAlbaranEntrega, "albaranes", ra.idCliente) ' End If ' End If 'Case 3 ' GENERA ALBARÁN DE RECOGIDA RÁPIDO ' Try ' If Not Guardar(Nothing, Nothing,,, 3) Then ' Dim ae As albaranes = Me.DataContext ' Dim uc As New ucAlbaranRecogida(, ae.idAlbaranEntrega) ' FuncionesDinamicas.AbrirAP(uc, OtrosParametros) ' tsWPFCore.Comun.dm.DockController.RemovePanel(docpanel) ' End If ' Catch ex As Exception ' FuncionesDinamicas.ErrorNoControladoAp(Me, ex) ' DXMessageBox.Show(ex.Message, "Error") ' End Try ' End Select End Sub Friend Shared Function GeneraPdfAlbaran(bd As tscGrupoSanchoToro, Albaran As albaranes) As Byte() Dim albes As New List(Of albaranes) albes.Add(Albaran) Dim idplae = bd.plantillas.First(Function(x) x.Codigo = "ALBENTV").idPlantilla If Albaran.entidades.TipoImpresionAlbaranEntrega = db.albaranes.TipoImpresionAlbaranEntregaEnum.IMPRIMIR_CONTRATO Then idplae = bd.plantillas.First(Function(x) x.Codigo = "CONTAE").idPlantilla Dim bAes = Informes.GuardaInformeEnPdf(bd, idplae, albes) Return bAes End Function Private Sub ucAlbaranEntrega_TeclaFuncionPulsada(sender As Object, e As KeyEventArgs) Handles Me.TeclaFuncionPulsada Select Case e.Key Case Key.F12 ValidaControlObjetoActual() ucAlbaranEntrega_EjecutarAccion(Nothing, Nothing, 2) Case Key.F11 ValidaControlObjetoActual() ucAlbaranEntrega_EjecutarAccion(Nothing, Nothing, 3) Case Key.System Select Case e.SystemKey Case Key.F10 ValidaControlObjetoActual() ucAlbaranEntrega_EjecutarAccion(Nothing, Nothing, 1) e.Handled = True End Select End Select End Sub Private Sub gcProductos_AntesEliminar(gc As tsGridControl, ByRef Cancelar As Boolean) Handles gcProductos.AntesEliminar End Sub Private Sub ucAlbaranEntrega_CampoActualizado(sender As Object, e As DataTransferEventArgs) Handles Me.CampoActualizado Dim pts As PropiedadesTS = sender.parent.propiedadests If Not pts Is Nothing Then Select Case pts.NombreCampo.ToLower Case "tipo" gcEsventa.ReadOnly = False Select Case DirectCast(ra.Tipo, bdGrupoSanchoToro.db.albaranes.TipoAlbaranEnum) Case bdGrupoSanchoToro.db.albaranes.TipoAlbaranEnum.COMPRA For Each d In ra.detallesalbaranes.Where(Function(x) x.EsVenta) d.EsVenta = False Next gcEsventa.ReadOnly = True ra.idAlmacenOrigen = Nothing EstableceSoloLectura(cbAlmacenOrigen, True) EstableceSoloLectura(cbAlmacenDestino, False) Case bdGrupoSanchoToro.db.albaranes.TipoAlbaranEnum.CAMBIO_ALMACEN EstableceSoloLectura(cbAlmacenOrigen, False) EstableceSoloLectura(cbAlmacenDestino, False) Case bdGrupoSanchoToro.db.albaranes.TipoAlbaranEnum.SUBALQUILER ra.idAlmacenOrigen = Nothing EstableceSoloLectura(cbAlmacenOrigen, True) EstableceSoloLectura(cbAlmacenDestino, False) Case bdGrupoSanchoToro.db.albaranes.TipoAlbaranEnum.DEVOLUCION_SUBALQUILER EstableceSoloLectura(cbAlmacenOrigen, False) ra.idAlmacenDestino = Nothing EstableceSoloLectura(cbAlmacenDestino, True) Case bdGrupoSanchoToro.db.albaranes.TipoAlbaranEnum.ENTREGA EstableceSoloLectura(cbAlmacenOrigen, False) ra.idAlmacenDestino = Nothing EstableceSoloLectura(cbAlmacenDestino, True) Case bdGrupoSanchoToro.db.albaranes.TipoAlbaranEnum.RECOGIDA ra.idAlmacenOrigen = Nothing EstableceSoloLectura(cbAlmacenOrigen, True) EstableceSoloLectura(cbAlmacenDestino, False) Case bdGrupoSanchoToro.db.albaranes.TipoAlbaranEnum.STOCK_INICIAL_O_FABRICACION ra.idAlmacenOrigen = Nothing EstableceSoloLectura(cbAlmacenOrigen, True) EstableceSoloLectura(cbAlmacenDestino, False) End Select End Select End If End Sub Private Sub hlVale_Click(sender As Object, e As RoutedEventArgs) 'Dim uc As New ucPresupuesto(ra.idPresupuesto) 'FuncionesDinamicas.AbrirAP(uc, OtrosParametros) End Sub 'Private Sub hlPresupuesto_Click(sender As Object, e As RoutedEventArgs) ' If ra.idPresupuesto.HasValue Then ' Dim uc As New ucPresupuesto(ra.idPresupuesto) ' FuncionesDinamicas.AbrirAP(uc, OtrosParametros) ' End If 'End Sub Private Sub beContrato_DefaultButtonClick(sender As Object, e As RoutedEventArgs) 'Dim dxw As New dxwAsignarContrato(bd, ra.idEntidad) 'If dxw.ShowDialog Then ' Dim ctr = bd.presupuestos.First(Function(x) x.idPresupuesto = dxw.idPresupuesto) ' ra.idPresupuestoNavigation = ctr ' If ra.idEntidad.HasValue = False Then ' ra.idEntidadNavigation = ctr.idClienteNavigation ' ra.idEntidad = ctr.idCliente ' End If 'End If End Sub Private Sub ucAlbaran_AntesGuardar(sender As Object, e As ItemClickEventArgs, ByRef Cancelar As Boolean, ByRef MensajesError As Hashtable, EliminacionManual As Integer) Handles Me.AntesGuardar Dim hte As New Hashtable Select Case DirectCast(ra.Tipo, bdGrupoSanchoToro.db.albaranes.TipoAlbaranEnum) Case bdGrupoSanchoToro.db.albaranes.TipoAlbaranEnum.COMPRA For Each d In ra.detallesalbaranes.Where(Function(x) x.EsVenta) d.EsVenta = False Next If ra.idAlmacenDestino.HasValue = False Then hte.Add("ALMACENAR-ALMACEN_DESTINO_OBLIGATORIO", "El almacén destino es obligatorio") Case bdGrupoSanchoToro.db.albaranes.TipoAlbaranEnum.CAMBIO_ALMACEN If ra.idAlmacenOrigen.HasValue = False Then hte.Add("ALMACENAR-ALMACEN_ORIGEN_OBLIGATORIO", "El almacén origen es obligatorio") If ra.idAlmacenDestino.HasValue = False Then hte.Add("ALMACENAR-ALMACEN_DESTINO_OBLIGATORIO", "El almacén destino es obligatorio") Case bdGrupoSanchoToro.db.albaranes.TipoAlbaranEnum.SUBALQUILER If ra.idAlmacenDestino.HasValue = False Then hte.Add("ALMACENAR-ALMACEN_DESTINO_OBLIGATORIO", "El almacén destino es obligatorio") Case bdGrupoSanchoToro.db.albaranes.TipoAlbaranEnum.DEVOLUCION_SUBALQUILER If ra.idAlmacenOrigen.HasValue = False Then hte.Add("ALMACENAR-ALMACEN_ORIGEN_OBLIGATORIO", "El almacén origen es obligatorio") Case bdGrupoSanchoToro.db.albaranes.TipoAlbaranEnum.ENTREGA If ra.idAlmacenOrigen.HasValue = False Then hte.Add("ALMACENAR-ALMACEN_ORIGEN_OBLIGATORIO", "El almacén origen es obligatorio") Case bdGrupoSanchoToro.db.albaranes.TipoAlbaranEnum.RECOGIDA If ra.idAlmacenDestino.HasValue = False Then hte.Add("ALMACENAR-ALMACEN_DESTINO_OBLIGATORIO", "El almacén destino es obligatorio") Case bdGrupoSanchoToro.db.albaranes.TipoAlbaranEnum.STOCK_INICIAL_O_FABRICACION If ra.idAlmacenDestino.HasValue = False Then hte.Add("ALMACENAR-ALMACEN_DESTINO_OBLIGATORIO", "El almacén destino es obligatorio") End Select If hte.Count > 0 Then MensajesError = hte Cancelar = True Else ra.idUsuario = bdGrupoSanchoToro.db.Utilidades.idUsuario Dim bdtmp = tscGrupoSanchoToro.NuevoContexto Select Case Estado Case tsUtilidades.EstadosAplicacion.Nuevo For Each d In ra.detallesalbaranes d.idAlbaranNavigation = ra d.ActualizaProducto(bdtmp, 1) Next Case tsUtilidades.EstadosAplicacion.ModificandoRegistro Dim das = bdtmp.detallesalbaranes.Where(Function(x) x.idAlbaran = ra.idAlbaran).ToList For Each d In das d.ActualizaProducto(bdtmp, -1) Next For Each d In ra.detallesalbaranes d.ActualizaProducto(bdtmp, 1) Next End Select End If End Sub Private Sub ucAlbaran_AntesEliminar(sender As Object, e As ItemClickEventArgs, ByRef Cancelar As Boolean, ByRef MensajesError As Hashtable, ByRef OmitirPreguntaContinuar As Boolean) Handles Me.AntesEliminar Dim bdtmp = tscGrupoSanchoToro.NuevoContexto Dim das = bdtmp.detallesalbaranes.Where(Function(x) x.idAlbaran = ra.idAlbaran).ToList For Each d In das d.ActualizaProducto(bdtmp, -1) Next End Sub Private Sub btIrAContrato_Click(sender As Object, e As RoutedEventArgs) If ra.idPresupuesto.HasValue Then 'Dim uc As New ucPresupuesto(ra.idPresupuesto) 'FuncionesDinamicas.AbrirAP(uc, OtrosParametros) End If End Sub Private Sub btQuitarContrato_Click(sender As Object, e As RoutedEventArgs) ra.idPresupuesto = Nothing ra.idPresupuestoNavigation = Nothing End Sub End Class