83 lines
3.2 KiB
VB.net
83 lines
3.2 KiB
VB.net
|
|
Imports System.Data.Entity
|
|
Imports DevExpress.Xpf.Core.ServerMode
|
|
Imports DevExpress.Mvvm
|
|
Imports DevExpress.Xpf.Grid
|
|
Imports tsWPFCore
|
|
Imports tsEFCore8.Extensiones
|
|
Imports DevExpress.Xpf.Core
|
|
Imports DevExpress.XtraReports.UI
|
|
Imports System.IO
|
|
Imports DevExpress.Xpf.Printing
|
|
Imports Microsoft.Win32
|
|
Imports System.Data.Objects
|
|
Imports System.Data.Objects.DataClasses
|
|
Imports DevExpress.Xpf.Editors
|
|
Imports bdGrupoSanchoToro.db.tscGrupoSanchoToro
|
|
Imports bdGrupoSanchoToro
|
|
|
|
Public Class dxwAgregarNuevoMunicipio
|
|
' Private _alumno As alumnos
|
|
Friend _CodigoPostal As String
|
|
Friend _CodigoMunicipio As String
|
|
Private bd As tscGrupoSanchoToro
|
|
|
|
Private Sub dxwAgregarNuevoCodigoPostal_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
|
|
Me.teCodigoPostal.Focus()
|
|
End Sub
|
|
|
|
Public Sub New(CodigoPostal As String)
|
|
' Llamada necesaria para el diseñador.
|
|
InitializeComponent()
|
|
' Agregue cualquier inicialización después de la llamada a InitializeComponent().
|
|
bd = tscGrupoSanchoToro.NuevoContexto
|
|
_CodigoPostal = CodigoPostal
|
|
teCodigoPostal.EditValue = CodigoPostal
|
|
End Sub
|
|
|
|
|
|
Private Sub btCancelar_Click(sender As Object, e As RoutedEventArgs)
|
|
Me.DialogResult = False
|
|
Me.Close()
|
|
End Sub
|
|
|
|
Private Sub btAceptar_Click(sender As Object, e As RoutedEventArgs)
|
|
Try
|
|
If teMunicipio.EditValue IsNot Nothing AndAlso teCodigoPostal.EditValue IsNot Nothing Then
|
|
_CodigoPostal = teCodigoPostal.EditValue
|
|
If _CodigoPostal.Length <> 5 Then Throw New Exception("El código postal es erróneo")
|
|
Dim codpro = _CodigoPostal.Substring(0, 2)
|
|
Dim provincia = bd.provincias.FirstOrDefault(Function(x) x.CodigoProvincia = codpro)
|
|
If provincia Is Nothing Then Throw New Exception("El código postal no pertenece a ninguna provincia")
|
|
Dim mun As String = teMunicipio.EditValue
|
|
If mun.NothingAVacio = "" Then Throw New Exception("El municipio es obligatorio")
|
|
_CodigoMunicipio = bdGrupoSanchoToro.db.municipios.ObtieneCodigoMunicipioMasCoincidente(bd, _CodigoPostal, mun)
|
|
Me.DialogResult = True
|
|
Me.Close()
|
|
Else
|
|
DXMessageBox.Show("El codigo postal y el municipio son obligatorios", "Atención")
|
|
End If
|
|
Catch ex As Exception
|
|
FuncionesDinamicas.ErrorNoControladoAp("dxwagregarnuevomunicipio_aceptar_click", ex)
|
|
DXMessageBox.Show(ex.Message, "Error")
|
|
End Try
|
|
End Sub
|
|
|
|
Private Sub teCodigoPostal_EditValueChanged(sender As Object, e As EditValueChangedEventArgs) Handles teCodigoPostal.EditValueChanged
|
|
Dim codpos As String = teCodigoPostal.EditValue
|
|
If codpos IsNot Nothing AndAlso codpos.Length = 5 Then
|
|
Dim codpro = codpos.Substring(0, 2)
|
|
Dim provincia = bd.provincias.FirstOrDefault(Function(x) x.CodigoProvincia = codpro)
|
|
If provincia IsNot Nothing Then
|
|
cbProvincia.EditValue = provincia.Nombre
|
|
Else
|
|
cbProvincia.EditValue = ""
|
|
End If
|
|
Else
|
|
cbProvincia.EditValue = ""
|
|
End If
|
|
End Sub
|
|
End Class
|
|
|
|
|