Imports System.Data
Imports System.Data.OleDb
Public Class frmAddNew
Public Sub ClearTextBox(ByVal root As Control)
For Each ctrl As Control In root.Controls
ClearTextBox(ctrl)
If TypeOf ctrl Is TextBox Then
CType(ctrl, TextBox).Text = String.Empty
End If
Next (ctrl)
End Sub
'Private Sub txtcrn_KeyPress(ByVal sender As Object, ByVal e As KeyPressEventArgs) Handles txtCRN.KeyPress
' If e.KeyChar = ControlChars.Cr Then
' e.Handled = True
' End If
' If Not IsNumeric(e.KeyChar) And Not e.KeyChar = Chr(Keys.Enter) Then
' e.Handled = True
' Dim Msg As String = "رقم السجل المدني يجب أن يكون عددا صحيحا"
' MsgBox(Msg, vbCritical + vbMsgBoxRight + vbMsgBoxRtlReading, "نظام مواعيد الأعلاف")
' txtCRN.Text = ""
' Exit Sub
' End If
' If e.KeyChar = Chr(Keys.Enter) And txtCRN.Text = "" Then
' Dim Msg As String = "يجب عليك ادخال السجل المدني"
' MsgBox(Msg, vbCritical + vbMsgBoxRight + vbMsgBoxRtlReading, "نظام مواعيد الأعلاف")
' txtCRN.Focus()
' End If
'End Sub
Private Sub btnSaveInfo_Click(sender As Object, e As EventArgs) Handles btnSaveInfo.Click
ApoSYSconn.Close()
ApoSYSconn.Open()
Dim CMD As New OleDb.OleDbCommand("qNewCustomer", ApoSYSconn)
CMD.CommandType = CommandType.StoredProcedure
CMD.Parameters.Add(New OleDb.OleDbParameter("@CivilRegNum", txtCRN.Text))
CMD.Parameters.Add(New OleDb.OleDbParameter("@Name1", txtName1.Text))
CMD.Parameters.Add(New OleDb.OleDbParameter("@Name2", txtName2.Text))
CMD.Parameters.Add(New OleDb.OleDbParameter("@Name3", txtName3.Text))
CMD.Parameters.Add(New OleDb.OleDbParameter("@Name4", txtName4.Text))
CMD.Parameters.Add(New OleDb.OleDbParameter("@MobileNum", txtMobileNo.Text))
CMD.ExecuteNonQuery()
ApoSYSconn.Close()
Dim Msg2 As String = "تم حفظ السجل بنجاح"
MsgBox(Msg2, vbInformation + vbMsgBoxRight + vbMsgBoxRtlReading, "نظام مواعيد الأعلاف")
ClearTextBox(Me)
txtCRN.Focus()
Exit Sub
ClearTextBox(Me)
End Sub
Private Sub btnCancel_Click(sender As Object, e As EventArgs) Handles btnCancel.Click
Close()
End Sub
Private Sub btnSaveAll_Click(sender As Object, e As EventArgs) Handles btnSaveAll.Click
If txtCRN.Text = "" Then
Dim Msg1 As String = "يجب عليك ادخال رقم السجل المدني"
MsgBox(Msg1, vbCritical + vbMsgBoxRight + vbMsgBoxRtlReading, "نظام مواعيد الأعلاف")
txtCRN.Focus()
Exit Sub
End If
ApoSYSconn.Close()
ApoSYSconn.Open()
Dim CMD As New OleDb.OleDbCommand("qNewCustomer", ApoSYSconn)
CMD.CommandType = CommandType.StoredProcedure
CMD.Parameters.Add(New OleDb.OleDbParameter("@CivilRegNum", txtCRN.Text))
CMD.Parameters.Add(New OleDb.OleDbParameter("@Name1", txtName1.Text))
CMD.Parameters.Add(New OleDb.OleDbParameter("@Name2", txtName2.Text))
CMD.Parameters.Add(New OleDb.OleDbParameter("@Name3", txtName3.Text))
CMD.Parameters.Add(New OleDb.OleDbParameter("@Name4", txtName4.Text))
CMD.Parameters.Add(New OleDb.OleDbParameter("@MobileNum", txtMobileNo.Text))
CMD.ExecuteNonQuery()
Dim CMD1 As New OleDb.OleDbCommand("qNewBarwah", ApoSYSconn)
CMD1.CommandType = CommandType.StoredProcedure
CMD1.Parameters.Add(New OleDb.OleDbParameter("@Customer", txtCRN.Text))
CMD1.Parameters.Add(New OleDb.OleDbParameter("@BarwahNum", txtBarwahNo.Text))
CMD1.Parameters.Add(New OleDb.OleDbParameter("@Notes", txtNotes.Text))
CMD1.ExecuteNonQuery()
Dim CMD2 As New OleDb.OleDbCommand("qNewDate", ApoSYSconn)
CMD2.CommandType = CommandType.StoredProcedure
CMD2.Parameters.Add(New OleDb.OleDbParameter("@BawahNum", txtBarwahNo.Text))
CMD2.Parameters.Add(New OleDb.OleDbParameter("@DateReg", txtDateReg.Text))
CMD2.Parameters.Add(New OleDb.OleDbParameter("@DateReceipt", txtDateRecipt.Text))
CMD2.ExecuteNonQuery()
ApoSYSconn.Close()
Dim Msg As String = "تم حفظ السجل بنجاح"
MsgBox(Msg, vbInformation + vbMsgBoxRight + vbMsgBoxRtlReading, "نظام مواعيد الأعلاف")
Exit Sub
ClearTextBox(Me)
End Sub
Private Sub txtCRN_KeyDown(sender As Object, e As KeyEventArgs) Handles txtCRN.KeyDown
If e.KeyCode = Keys.Enter Then
' SendKeys.Send("{tab}")
'e.SuppressKeyPress = True
txtName1.Focus()
End If
End Sub
Private Sub txtBarwahNo_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtBarwahNo.KeyPress
If e.KeyChar = ControlChars.Cr Then
e.Handled = True
End If
If Not IsNumeric(e.KeyChar) And Not e.KeyChar = Chr(Keys.Enter) Then
e.Handled = True
Dim Msg As String = "رقم البروه يجب أن يكون عددا صحيحا"
MsgBox(Msg, vbCritical + vbMsgBoxRight + vbMsgBoxRtlReading, "نظام مواعيد الأعلاف")
txtBarwahNo.Text = ""
Exit Sub
End If
If e.KeyChar = Chr(Keys.Enter) And txtBarwahNo.Text = "" Then
Dim Msg As String = "يجب عليك ادخال رقم البروه"
MsgBox(Msg, vbCritical + vbMsgBoxRight + vbMsgBoxRtlReading, "نظام مواعيد الأعلاف")
txtBarwahNo.Focus()
End If
End Sub
Private Sub txtBarwahNo_KeyDown(sender As Object, e As KeyEventArgs) Handles txtBarwahNo.KeyDown
If e.KeyCode = Keys.Enter Then
txtDateRecipt.Focus()
End If
End Sub
Private Sub txtName1_KeyDown(sender As Object, e As KeyEventArgs) Handles txtName1.KeyDown
If e.KeyCode = Keys.Enter Then
txtName2.Focus()
End If
End Sub
Private Sub txtName2_KeyDown(sender As Object, e As KeyEventArgs) Handles txtName2.KeyDown
If e.KeyCode = Keys.Enter Then
txtName3.Focus()
End If
End Sub
Private Sub txtName3_KeyDown(sender As Object, e As KeyEventArgs) Handles txtName3.KeyDown
If e.KeyCode = Keys.Enter Then
txtName4.Focus()
End If
End Sub
Private Sub txtName4_KeyDown(sender As Object, e As KeyEventArgs) Handles txtName4.KeyDown
If e.KeyCode = Keys.Enter Then
txtMobileNo.Focus()
End If
End Sub
Private Sub txtMobileNo_KeyDown(sender As Object, e As KeyEventArgs) Handles txtMobileNo.KeyDown
If e.KeyCode = Keys.Enter Then
txtBarwahNo.Focus()
End If
End Sub
Private Sub btnSaveAll_KeyDown(sender As Object, e As KeyEventArgs) Handles btnSaveAll.KeyDown
If e.KeyCode = Keys.Enter Then
btnCancel.Focus()
End If
End Sub
Private Sub frmAddNew_Load(sender As Object, e As EventArgs) Handles MyBase.Load
If txtCRN.Text = "" And txtBarwahNo.Text = "" Then
btnSaveAll.Enabled = False
Else
btnSaveAll.Enabled = True
End If
If txtCRN.Text = "" Then
btnSaveInfo.Enabled = False
Else
btnSaveInfo.Enabled = True
End If
End Sub
Private Sub txtName1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtName1.KeyPress
If e.KeyChar = ControlChars.Cr Then
e.Handled = True
End If
If IsNumeric(e.KeyChar) Then
e.Handled = True
End If
End Sub
Private Sub txtName2_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtName2.KeyPress
If e.KeyChar = ControlChars.Cr Then
e.Handled = True
End If
If IsNumeric(e.KeyChar) Then
e.Handled = True
End If
End Sub
Private Sub txtName3_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtName3.KeyPress
If e.KeyChar = ControlChars.Cr Then
e.Handled = True
End If
If IsNumeric(e.KeyChar) Then
e.Handled = True
End If
End Sub
Private Sub txtName4_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtName4.KeyPress
If e.KeyChar = ControlChars.Cr Then
e.Handled = True
End If
If IsNumeric(e.KeyChar) Then
e.Handled = True
End If
End Sub
Private Sub txtMobileNo_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtMobileNo.KeyPress
If e.KeyChar = ControlChars.Cr Then
e.Handled = True
End If
If Not IsNumeric(e.KeyChar) Then
e.Handled = True
End If
End Sub
Private Sub txtCRN_Validated(sender As Object, e As EventArgs) Handles txtCRN.Validated
If txtCRN.Text = "" Then
Dim Msg As String = "يجب عليك ادخال السجل المدني"
MsgBox(Msg, vbCritical + vbMsgBoxRight + vbMsgBoxRtlReading, "نظام مواعيد الأعلاف")
txtCRN.Focus()
txtCRN.SelectionStart = 0
Return
End If
'كود التحقق من المدخل عدد صحيح
If IsNumeric(txtCRN.Text) Then
Exit Sub
Else
Dim Msg As String = "رقم السجل المدني يجب أن يكون عددا صحيحا"
MsgBox(Msg, vbCritical + vbMsgBoxRight + vbMsgBoxRtlReading, "نظام مواعيد الأعلاف")
txtCRN.Text = ""
txtCRN.Focus()
txtCRN.SelectionStart = 0
Return
Exit Sub
End If
Dim cmd As New OleDbCommand
ApoSYSconn.Close()
cmd.Connection = ApoSYSconn
ApoSYSconn.Open()
cmd.CommandText = "Select * from tblCustomers where CivilRegNum=@n"
cmd.Parameters.Add("@n", OleDbType.VarChar).Value = txtCRN.Text.ToString
Dim dr As OleDbDataReader = cmd.ExecuteReader()
If dr.HasRows = True Then
MessageBox.Show("هذا السجل موجود", "تحذير", MessageBoxButtons.OK, MessageBoxIcon.Warning)
txtCRN.Text = ""
txtCRN.Focus()
txtCRN.SelectionStart = 0
ApoSYSconn.Close()
End If
End Sub
Private Sub txtBarwahNo_Validated(sender As Object, e As EventArgs) Handles txtBarwahNo.Validated
Dim cmd As New OleDbCommand
ApoSYSconn.Close()
cmd.Connection = ApoSYSconn
ApoSYSconn.Open()
cmd.CommandText = "Select * from tblBarwah where BarwahNum=@n"
cmd.Parameters.Add("@n", OleDbType.VarChar).Value = txtBarwahNo.Text.ToString
Dim dr As OleDbDataReader = cmd.ExecuteReader()
If dr.HasRows = True Then
MessageBox.Show("هذا السجل موجود", "تحذير", MessageBoxButtons.OK, MessageBoxIcon.Warning)
txtBarwahNo.Text = ""
txtBarwahNo.Focus()
txtBarwahNo.SelectionStart = 0
ApoSYSconn.Close()
End If
End Sub
Private Sub txtCRN_TextChanged(sender As Object, e As EventArgs) Handles txtCRN.TextChanged
If txtCRN.Text = "" Then
btnSaveInfo.Enabled = False
Else
btnSaveInfo.Enabled = True
End If
End Sub
Private Sub txtBarwahNo_TextChanged(sender As Object, e As EventArgs) Handles txtBarwahNo.TextChanged
If txtBarwahNo.Text = "" Then
btnSaveAll.Enabled = False
Else
btnSaveAll.Enabled = True
End If
End Sub
Private Sub txtDateReg_KeyDown(sender As Object, e As KeyEventArgs)
If e.KeyCode = Keys.Enter Then
txtDateRecipt.Focus()
End If
End Sub
Private Sub txtDateRecipt_KeyDown(sender As Object, e As KeyEventArgs)
If e.KeyCode = Keys.Enter Then
txtNotes.Focus()
End If
End Sub
Private Sub txtDateRecipt_KeyDown_1(sender As Object, e As KeyEventArgs) Handles txtDateRecipt.KeyDown
If e.KeyCode = Keys.Enter Then
txtNotes.Focus()
End If
End Sub
Private Sub btnSaveInfo_KeyPress(sender As Object, e As KeyPressEventArgs) Handles btnSaveInfo.KeyPress
If e.KeyChar = ControlChars.Cr Then
e.Handled = True
End If
End Sub
Private Sub txtDateReg_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtDateReg.KeyPress
If e.KeyChar = ControlChars.Cr Then
e.Handled = True
End If
End Sub
Private Sub txtDateRecipt_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtDateRecipt.KeyPress
If e.KeyChar = ControlChars.Cr Then
e.Handled = True
End If
End Sub
End Class