You are on page 1of 4

Imports System.Data.

SqlClient Module Module1 Public su As Integer Public cn As New SqlConnection("Data Source=MAQ4-PC;Initial Catalog=notas2013;Integrated Security=True")

Imports System.Data.SqlClient Public Class Form1 Private Sub TB2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TB2.KeyPress If (Asc(e.KeyChar) >= 65 And Asc(e.KeyChar) <= 90) Or (Asc(e.KeyChar) >= 61 And Asc(e.KeyChar) >= 122) Or Asc(e.KeyChar) = 8 Or Asc(e.KeyChar) = 32 Or (Asc(e.KeyChar) >= 160 And Asc(e.KeyChar) <= 165) Or Asc(e.KeyChar) = 130 Then e.Handled = False Else e.Handled = True End If If e.KeyChar = ChrW(Keys.Enter) Then If TB2.Text <> "" Then cn.Open() Dim comando As New SqlCommand("select * from dbo.materia where ma = '" & Trim(TB2.Text) & "'", cn) Dim lectura As SqlDataReader lectura = comando.ExecuteReader If lectura.Read() Then MsgBox("materia ya existe ") TB2.Text = " " TB2.Focus() Else MDIParent1.gu.Enabled = True MDIParent1.nu.Enabled = False End If cn.Close() End If End If End Sub End Class

Imports System.Data.SqlClient Public Class Form2 Private Sub TB2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TB2.KeyPress If (Asc(e.KeyChar) >= 65 And Asc(e.KeyChar) <= 90) Or (Asc(e.KeyChar) >= 61 And Asc(e.KeyChar) >= 122) Or Asc(e.KeyChar) = 8 Or Asc(e.KeyChar) = 32 Or (Asc(e.KeyChar) >= 160 And Asc(e.KeyChar) <= 165) Or Asc(e.KeyChar) = 130 Then e.Handled = False Else e.Handled = True End If If e.KeyChar = ChrW(Keys.Enter) Then If TB2.Text <> "" Then cn.Open() Dim comando As New SqlCommand("select * from dbo.curso where curso = '" & Trim(TB2.Text) & "'", cn) Dim lectura As SqlDataReader lectura = comando.ExecuteReader If lectura.Read() Then MsgBox("curso ya existe ") TB2.Text = " " TB2.Focus() Else MDIParent1.gu.Enabled = True MDIParent1.nu.Enabled = False End If cn.Close() End If End If End Sub End Class

Imports System.Windows.Forms Imports System.Data.SqlClient Public Class MDIParent1 Private Sub ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem.Click su = 1 TS1.Enabled = True MS.Enabled = False gu.Enabled = False End Sub

Private Sub ToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem1.Click su = 2 TS1.Enabled = True MS.Enabled = False gu.Enabled = False End Sub Private Sub nu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles nu.Click cn.Open() If su = 1 Then Form1.MdiParent = Me Form1.Show() Dim comando As New SqlCommand("select count (*) as ultimo from dbo.materia ", cn) Dim ultimo As Integer = Convert.ToInt32(comando.ExecuteScalar()) + 1 Form1.TB1.Text = ultimo Form1.TB2.Text = "" Form1.TB1.Focus() End If If su = 2 Then Form2.MdiParent = Me Form2.Show() Dim comando As New SqlCommand("select count (*) as ultimo from dbo.curso ", cn) Dim ultimo As Integer = Convert.ToInt32(comando.ExecuteScalar()) + 1 Form2.TB1.Text = ultimo Form2.TB2.Text = "" Form2.TB1.Focus() End If

cn.Close() End Sub Private Sub gu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles gu.Click cn.Open() If su = 1 Then Dim cmd1 As New SqlCommand("insert into dbo.materia(codigo,ma) values ('" & Val(Form1.TB1.Text) & "','" & Trim(Form1.TB1.Text) & "')", cn) cmd1.ExecuteNonQuery() End If If su = 2 Then Dim cmd1 As New SqlCommand("insert into dbo.curso(codigo,curso) values ('" & Val(Form1.TB1.Text) & "','" & Trim(Form1.TB1.Text) & "')", cn)

cmd1.ExecuteNonQuery() End If gu.Enabled = False nu.Enabled = True cn.Close() End Sub Private Sub ca_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ca.Click If su = 1 Then Form1.Close() End If If su = 2 Then Form2.Close() End If End Sub Private Sub sa_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles sa.Click If su = 1 Then Form1.Close() End If If su = 2 Then Form2.Close() End If TS1.Enabled = False MS.Enabled = True End Sub End Class

You might also like