Chapter 3 EIT Forward Problems with IEM
3.4 Case Studies and Discussions
3.4.1 Lumped Model
Código fuente del Formulario de Contraseña
Este c ódigo describe com o valída al usuario si ingresó bien los datos o caso contrario le salen los m ensajes de error.
Public Class frm contraseña Private Sub ingreso() Dim usu As String Dim clave As String Dim x As Integer
usu = M e.TextBox1.Text clave = M e.TextBox2.Text
M e.TusuariosBindingSource.M oveFirst()
x = M e.TusuariosB indingS ource.Find("cnom breusu", usu.Trim ) If x >= 0 Then
M e.TusuariosB indingS ource.Position = x
If M e.TusuariosBindingSource.Current("cpassword") = clave.Trim Then frm m enu.Show()
nivelusu.nivel(M e.TusuariosB indingSource.Current("cnivel").T oString) M e.Hide()
58 Else M sgBox("CONTRASEÑ A INCORRECTA") End If Else M sgBox("USUSARIO NO REGISTRADO") End If End Sub
Private Sub Button1_Click(ByVal sender A s System .Object, ByVal e A s System .EventArgs) Handles Button1.Click
ingreso() End Sub
Private Sub TusuariosBindingNavigatorSaveItem _C lick(ByVa l se nder A s System .Object, ByVal e As System .EventArgs)
M e.Validate()
M e.TusuariosBindingSource.EndEdit()
M e.TableAdapterM anager.UpdateAll(M e.DataSet1) End Sub
Private Sub frm contrase ña_Load(B yVal se nder As S ystem .Object, ByVal e A s System .EventArgs) Handles M yBase.Load
'TODO: esta línea de código carga datos en la tabla 'DataSet1.tus uarios' Puede m overla o quitarla según sea necesario.
M e.TusuariosTableAdapter.Fill(M e.DataSet1.tusuarios) End Sub
Private Sub Button2_Click(ByVal sender A s System .Object, ByVal e A s System .EventArgs) Handles Button2.Click
M e.Close() End Sub
Private Sub Button1_M ouseM ove(ByVal sender A s Object, ByVal e A s System .W indows.Form s.M ouseEventArgs) Handle s Button1.M ouseM ove
ToolTip1.SetToolTip(Button1, "Aceptar") End Sub
Private Sub Button2_M ouseM ove(ByVal sender A s Object, ByVal e A s System .W indows.Form s.M ouseEventArgs) Handle s Button2.M ouseM ove
ToolTip1.SetToolTip(Button2, "Cancelar") End Sub
Private Sub frm contraseña_Activated(ByVa l sender As System .Object, ByVal e A s System .EventArgs) Handles M yBase.Activated
59 TextBox2.Clear()
End Sub
Private Sub TextBox2_KeyPress(ByVal se nder As S ystem .Object, ByVal e A s System .W indows.Form s.KeyPressEve ntArgs) Handles TextBox2.KeyPress
If Asc(e.KeyChar) = 13 Then ingreso()
End If End Sub End Class
Código fuente para ingreso de clientes
Este código describe el ingreso de los clientes para poderlos registrar con toda la inform ación personal de cada uno de e llos, tam bién va lida que no ingrese núm eros o sím bolos en cam pos que no deben hacerlo
Public Class frm clientes
Private Sub Tc lientesBindingNavigatorSaveItem _Click(ByVal sender A s System .Object, ByVal e As System .EventArgs)
Try
M e.Validate()
M e.TclientesBindingSource.EndEdit()
M e.TableAdapterM anager.Update All(M e.DataSet1) Catch ex As Exception
M sgBox(ex.M essage()) End Try
End Sub
Private Sub Form 1_Load(ByVal sender A s System .Object, ByVa l e A s System .EventArgs) Handles M yBase.Load
'TODO: esta línea de código carga datos en la tabla 'DataSet1.tc lientes' Puede m overla o quitarla según sea necesario.
M e.TclientesTableA dapter.Fill(M e.DataSet1.tclientes) End Sub
Private Sub Ccedulac liTextBox_KeyPress(ByVal se nder As Objec t, ByVal e A s System .W indows.Form s.KeyPressEve ntArgs) Handles CcedulacliTextBox.KeyPress Dim caracter As Char = e.KeyChar
If Not Char.IsNum ber(caracter) And (caracter = ChrW (Keys.Back)) = False Then e.KeyChar = Chr(0)
60 End If
End Sub
Private Sub CcedulacliTextBox_Leave(ByVal sender As Object, ByVal e As System .EventArgs) Handles Ccedulac liTextBox. Leave
'Dim a As ClassLibrary1.Class1 'Dim n As Integer
'n = a.validacedula(CcedulacliTe xtBox.Te xt.Trim ) 'If n = CcedulacliTextBox.Text.Substring(9, 1) Then ' MessageBox.Show("Cédula Válida")
'Else
' MessageBox.Show("Cédula Inválida") 'End If
End Sub
Private Sub CapellicliTe xtBox_KeyPress(ByVal sender As Object, ByVal e A s System .W indows.Form s.KeyPressEve ntArgs) Handles Capellic liTe xtBox.Ke yPress
Dim caracter As C har = e.KeyChar
If Char.IsNum ber(caracter) And (caracter = ChrW (Keys.Back)) = False Then e.KeyChar = Chr(0)
End If End Sub
Private Sub Cnom cliTextBox_KeyPress(ByVal sender As O bject, ByVal e A s System .W indows.Form s.KeyPressEve ntArgs) Handles Cnom cliTextBox.KeyPress
Dim caracter As Char = e.KeyChar
If Char.IsNum ber(caracter) And (caracter = ChrW (Keys.Back)) = False Then e.KeyChar = Chr(0)
End If End Sub
Private Sub CtelefcliTextBox_KeyPress(ByVal sender As O bject, ByVal e A s System .W indows.Form s.KeyPressEve ntArgs) Handles CtelefcliTextBox.KeyPress
Dim caracter As Char = e.KeyChar
If Not Char.IsNum ber(caracter) And (caracter = ChrW (Keys.Back)) = False Then e.KeyChar = Chr(0)
End If End Sub
Private Sub Cnum celucliTextBox_KeyPress(ByVa l sender As Object, ByVa l e A s System .W indows.Form s.KeyPressEve ntArgs) Handles Cnum celucliTextBox.KeyPress Dim caracter As Char = e.KeyChar
If Not Char.IsNum ber(caracter) And (caracter = ChrW (Keys.Back)) = False Then e.KeyChar = Chr(0)
End If End Sub
61
Private Sub NcuentacliTe xtBox_KeyPress(B yVal sender As O bject, ByVal e A s System .W indows.Form s.KeyPressEve ntA rgs) Handles Ncuentac liTextBox.KeyPress Dim caracter As Char = e.KeyChar
If Not Char.IsNum ber(caracter) And (caracter = ChrW (Keys.Back)) = False Then e.KeyChar = Chr(0)
End If End Sub
Private Sub txtbuscarcli_K eyPress(ByVa l sender As Object, ByVal e A s System .W indows.Form s.KeyPressEve ntArgs) Handles txtbuscarcli.KeyPress
Dim caracter As Char = e.KeyChar
If Char.IsNum ber(caracter) And (caracter = ChrW (Keys.Back)) = False Then e.KeyChar = Chr(0)
End If End Sub
Private Sub Button1_Click(ByVal sender A s System .Object, ByVal e A s System .EventArgs) Handles Button1.Click
M e.TclientesBindingSource.AddNew() deshabilita()
End Sub
Private Sub Button2_Click(ByVal sender A s System .Object, ByVal e A s System .EventArgs) Handles Button2.Click
M e.TclientesBindingSource.CancelEdit() habilita()
End Sub
Private Sub Button3_Click(ByVal sender A s System .Object, ByVa l e A s System .EventArgs) Handles Button3.Click
habilita() Try
M e.Validate()
M e.TclientesBindingSource.EndEdit()
M e.TableAdapterM anager.Update All(M e.DataSet1) Catch ex As Exception
M sgBox(ex.M essage()) End Try
End Sub
Private Sub Button4_Click(ByVal sender A s System .Object, ByVal e A s System .EventArgs) Handles Button4.Click
deshabilita() End Sub
Private Sub Button5_Click(ByVal sender A s System .Object, ByVal e A s System .EventArgs) Handles Button5.Click
62 Dim buscar As Integer
M e.TclientesBindingSource.M oveFirst()
buscar = M e.TclientesBindingSource.Find("cnom cli", txtbuscarcli.Text.Trim ) If buscar >= 0 Then
M essageBox.Show("Cliente Enc ontrado") M e.TclientesBindingSource.Position = buscar Else
M essageBox.Show("Cliente No E ncontrado") End If
End Sub
Private Sub Button6_Click(ByVal sender A s System .Object, ByVal e A s System .EventArgs) Handles Button6.Click
frm menu.Show() M e.Hide() habilita() End Sub
Private Sub habilita()
M e.Button1.Enable d = True M e.Button4.Enable d = True M e.Button5.Enable d = True M e.Button2.Enable d = False M e.Button3.Enable d = False M e.GroupBox1.Enable d = False End Sub
Private Sub deshabilita() M e.Button1.Enable d = False M e.Button4.Enable d = False M e.Button5.Enable d = False M e.Button2.Enable d = True M e.Button3.Enable d = True M e.GroupBox1.Enable d = True End Sub
Private Sub Button1_M ouseM ove(ByVal sender A s Object, ByVal e A s System .W indows.Form s.M ouseEventArgs) Handle s Button1.M ouseM ove
ToolTip1.SetToolTip(Button1, "Nuevo") End Sub
Private Sub Button2_M ouseM ove(ByVal sender A s Object, ByVal e A s System .W indows.Form s.M ouseEventArgs) Handle s Button2.M ouseM ove
ToolTip1.SetToolTip(Button2, "Cancelar") End Sub
Private Sub Button3_M ouseM ove(ByVal sender A s Object, ByVal e A s System .W indows.Form s.M ouseEventArgs) Handle s Button3.M ouse M ove
ToolTip1.SetToolTip(Button3, "Guardar") End Sub
63
Private Sub Button4_M ouseM ove(ByVal sender A s Object, ByVal e A s System .W indows.Form s.M ouseEventArgs) Handle s Button4.M ouseM ove
ToolTip1.SetToolTip(Button4, "Editar") End Sub
Private Sub Button5_M ouseM ove(ByVal sender A s Object, ByVal e A s System .W indows.Form s.M ouseEventArgs) Handle s Button5.M ouseM ove
ToolTip1.SetToolTip(Button5, "Buscar") End Sub
Private Sub Button6_M ouseM ove(ByVal sender A s Object, ByVal e A s System .W indows.Form s.M ouseEventArgs) Handle s Button6.M ouseM ove
ToolTip1.SetToolTip(Button6, "Salir") End Sub
End Class
Código fuente para el ingreso de factura de ventas
Este código de scribe com o se registra una factura la cual debe tener los datos para ver si e l producto seleccionado tie ne IVA o no, tam bién este perm ite validar los datos que den ser solo núm eros o solo letra para no tener errores en el ingreso de la inform aci ón.
Im ports System .Data
Im ports System .Data.SqlClient Public Class frm factura
Private Sub Button3_Click(ByVal sender A s System .Object, ByVal e A s System .EventArgs) Handles Button3.Click
frm buscarcli.Show() End Sub
Private Sub habilita()
M e.Button3.Enable d = True M e.btngrabar.Enabled = True M e.btncancelar.Enabled = True M e.btnm odificar.Enabled = False M e.btnnuevo.Enabled = False
M e.DfechaDateTim ePicker.Enabled = True End Sub
Private Sub deshabilita() M e.Button3.Enable d = False M e.btngrabar.Enabled = False M e.btncancelar.Enabled = False M e.btnm odificar.Enabled = False M e.btnnuevo.Enabled = False
64 M e.Button13.Enabled = True
M e.Button11.Enabled = True M e.Button8.Enable d = True End Sub
Private Sub habilita1()
M e.Button12.Enabled = True M e.Button9.Enable d = True M e.Button13.Enabled = False M e.Button11.Enabled = False End Sub
Private Sub deshabilita1() M e.Button12.Enabled = False M e.Button9.Enable d = False M e.Button13.Enabled = True M e.Button11.Enabled = True End Sub
Private Sub B utton13_Click(ByVal sender As System .Object, ByVal e A s System .EventArgs) Handles Button13.Clic k
M e.TdetallefacBindingS ource.AddNew() frm buscarproduc.Show()
habilita 1() End Sub
Private Sub grabar() Try
M e.TfacturasBindingSource.Current("ncodcli") = M e.NcodcliTe xtBox.Text
M e.TfacturasBindingSource.Current("dfecha") = M e.DfechaDateTim ePicker.Value M e.TfacturasBindingSource.Current("cusuario") = frm m enu.lblusuario.Te x t
M e.TfacturasBindingSource.EndEdit()
M e.TfacturasTableAdapter.Update(M e.Bdsistem aDataSet.tfacturas) Catch ex As Exception
End Try End Sub
Private Sub btngrabar_Click(ByVal sender A s System .Object, ByVal e A s System .EventArgs) Handles btngrabar.Clic k
grabar() deshabilita() End Sub
Private Sub grabar_detalle()
If M e.NcodfacTextBox.Text.Length > 0 The n
M e.TdetallefacBindingSource.Current("ncodfac") = M e.NcodfacTextBox.Text M e.TdetallefacBindingSource.EndEdit()
M e.TdetallefacTableAda pter.Upda te(M e.Bdsistem aDataSet.tdetallefac)
M e.txtsubtotal.Text = M e.TdetallefacTableAda pter.subtotalfactura(NcodfacTextBox.Te xt) M e.txtiva12.Text = M e.TdetallefacTableAda pter.iva12factura(NcodfacTextBox.Text) deshabilita1() End If
65 End Sub
Private Sub Button9_Click(ByVal sender A s System .Object, ByVal e A s System .EventArgs) Handles Button9.Click
grabar_detalle() End Sub
Private Sub btnnuevo_Click(ByVal sender As System .Object, ByVal e A s System .EventArgs) Handles btnnuevo.Clic k
M e.TfacturasTableA dapter.Fill(M e.Bdsistem aDataSet.tfacturas) M e.TfacturasBindingSource.AddNew()
habilita() End Sub
Private Sub btncancelar_Clic k(ByVal sender As S ystem .Object, ByVal e A s System .EventArgs) Handles b tncancelar.Click
M e.TfacturasBindingSource.CancelEdit() deshabilita()
End Sub
Private Sub btnm odificar_Clic k(ByVal sender As System .Object, ByVal e As System .EventArgs) Handles btnm odificar.Click
habilita() End Sub
Private Sub B utton12_Click(ByVal sender As System .Object, ByVal e A s System .EventArgs) Handles Button12.Clic k
M e.TdetallefacBindingS ource.CancelEdit() deshabilita1()
End Sub
Private Sub B utton11_Click(ByVal sender As System .Object, ByVal e A s System .EventArgs) Handles Button11.Clic k
habilita 1() End Sub
Private Sub NcodfacTe xtBox_TextChanged(ByVal sender As System .Object, ByVal e As System .EventArgs) Handle s NcodfacTextB ox.TextC hanged
If NcodfacTextBox.Text.Length > 0 Then
M e.TdetallefacTableAda pter.Fill(M e.Bdsistem aDataSet.tdetallefac, M e.NcodfacTextBox.Text) M e.txtsubtotal.Text = M e.TdetallefacTableAda pter.subtotalfactura(NcodfacTextBox.Te xt) M e.txtiva12.Text = M e.TdetallefacTableAda pter.iva12factura(NcodfacTextBox.Text) End If End Sub
66
Private Sub Button7_Click(ByVal sender A s System .Object, ByVal e A s System .EventArgs) Handles Button7.Click
Close() End Sub
Private Sub txtsubtotal_TextC hanged(ByVa l sender As System .Object, ByVal e A s System .EventArgs) Handles txtsubtota l.TextChanged
Dim total As Double Try
If txtsubtotal.Text = "" Then txtsubtotal.Text = "0,00" End If
total = Convert.ToDouble(M e.txtsubtotal.Text) +
Convert.ToD ouble(M e.txtiva12.Text) M e.txttotalfac.Text = tota l.ToString Catch ex As Exception
End Try End Sub
Private Sub txtiva12_TextChanged(ByVal sender As System .Object, ByVal e A s System .EventArgs) Handles txtiva12.TextChange d
Dim total As Double Try
If txtiva 12.Text = "" Then txtiva12.Text = "0,00" End If
total = Convert.ToDouble(M e.txtsubtotal.Text) +
Convert.ToD ouble(M e.txtiva12.Text)
M e.txttotalfac.Text = Form at("#,##", total.T oString) Catch ex As Exception
End Try End Sub
Private Sub Button8_Click(ByVal sender A s System .Object, ByVal e A s System .EventArgs) Handles Button8.Click
If M essageBox.Show("Está Seguro de Elim inar el Registr o Actual", "Elim inación",
M essageBoxButtons.YesN o, M essageBoxIcon.Exclam ation,
M essageBoxDefaultButton.Button1) = W indows.Form s.D ialogResult.Yes Then M e.TdetallefacBindingSource.Rem oveCurrent()
M e.TdetallefacBindingSource.EndEdit()
M e.TdetallefacTableAda pter.Upda te(M e.Bdsistem aDataSet.tdetallefac) End If
If NcodfacTextBox.Text.Length > 0 Then
M e.TdetallefacTableAda pter.Fill(M e.Bdsistem aDataSet.tdetallefac, M e.NcodfacTextBox.Text)
67 M e.txtsubtotal.Text = M e.TdetallefacTableAda pter.subtotalfactura(NcodfacTextBox.Te xt) M e.txtiva12.Text = M e.TdetallefacTableAda pter.iva12factura(NcodfacTextBox.Text) End If End Sub
Private Sub Button1_Click(ByVal se nder A s System .Object, ByVal e A s System .EventArgs) Handles Button1.Click
frm listarfactura.Show() End Sub
Private Sub btnborrarfac_Click(ByVa l se nder As System .Object, ByVa l e A s System .EventArgs)
If TdetallefacBindingSource.Count = 0 Then
If MessageBox.Show("E stá Seguro de E lim inar el Registro Ac tual", "Elim inación",
M essageBoxButtons.YesN o, M essageBoxIcon.Exclam ation,
M essageBoxDefaultButton.Button1) = W indows.Form s.D ialogResult.Yes Then M e.TdetallefacB indingSource.Rem oveCurrent()
M e.TdetallefacBindingSource.EndEdit()
M e.TdetallefacTableAdapter.Update(M e.Bdsistem aDataSet.tdeta llefac) End If
If NcodfacTextBox.Text.Length > 0 Then
M e.TdetallefacTableAdapter.Fill(M e.Bdsistem aDataSet.tde tallefac, M e.NcodfacTextBox.Text)
M e.txtsubtota l.Text =
M e.TdetallefacTableAda pter.subtotalfactura(NcodfacTextBox.Te xt)
M e.txtiva12.Text =
M e.TdetallefacTableAda pter.iva12fa ctura(NcodfacTextBox.Text) End If
End If End Sub
Private Sub Button2_Click(ByVal sender A s System .Object, ByVal e A s System .EventArgs) Handles Button2.Click
frm reportfac.idfactura = NcodfacTextBox.Text frm reportfac.Show()
End Sub End Class
68 Código fuente para el búsquedas de clientes
Este código de scribe com o filtra la inform ación de los clientes en caso de te ner varios, para encontrar los da tos rápidam ente.
Public Class frm buscarcli
Private Sub Tc lientesBindingNavigatorSaveItem _Click(ByVal sender A s System .Object, ByVal e As System .EventArgs)
M e.Validate()
M e.TclientesBindingSource.EndE dit()
M e.TableAdapterM anager.UpdateAll(M e.DataSet1) End Sub
Private Sub frm buscarcli_Load(ByVa l se nder As System .Object, ByVa l e A s System .EventArgs) Handles M yBase.Load
'TODO: esta línea de código carga datos en la tabla 'DataSet1.tc lientes' Puede m overla o quitarla según sea necesario.
M e.TclientesTableA dapter.Fill(M e.DataSet1.tclientes) End Sub
Private Sub Button1_Click(ByVal sender A s System .Object, ByVal e A s System .EventArgs) Handles Button1.Click
M e.TclientesTableA dapter.Fill(M e.DataSet1.tclientes) End Sub
Private Sub TextBox1_Te xtChanged(ByVal se nder As System .Object, ByVal e As System .EventArgs) Handles TextBox1.TextChanged
M e.TclientesBindingSource.Filter = "capellicli like '" + TextBox1.Text + "%'" End Sub
Private Sub TclientesData GridV iew_DoubleClic k(ByVal sender As Object, ByVal e As System .EventArgs) Handles Tcliente sDataGridV iew.DoubleClic k
frm factura.Show()
frm factura.NcodcliTextBox.Text = M e.TclientesBindingSource.Current("ncodcli") M e.Hide()
End Sub End Class
69
3.5 Valid ación de la propuesta por la vía de Expertos