Imports System.Data.OleDb
Public Class Form1
Dim InfoAdapter As New OleDbDataAdapter("SELECT * FROM EmpInfo ORDER BY LastName", con)
Dim InfoTable As New DataTable
Dim WithEvents myBindingSource As New BindingSource
Dim InfoState As String
Private Sub frmAddEmp_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
myBindingSource.DataSource = InfoTable
InfoAdapter.Fill(InfoTable)
txtEmpNo.DataBindings.Add("Text", myBindingSource, "ID")
txtFirstName.DataBindings.Add("Text", myBindingSource, "FirstName")
txtLastName.DataBindings.Add("Text", myBindingSource, "LastName")
DateTimePicker1.DataBindings.Add("Text", myBindingSource, "BirthDate")
ComboBox1.DataBindings.Add("Text", myBindingSource, "ScCart")
txtjop.DataBindings.Add("Text", myBindingSource, "Grade")
txtHomePhone.DataBindings.Add("Text", myBindingSource, "HomePhone")
txtStep.DataBindings.Add("Text", myBindingSource, "step")
txtDep.DataBindings.Add("Text", myBindingSource, "department")
txtadress.DataBindings.Add("Text", myBindingSource, "adress")
lblPhotoFile.DataBindings.Add("Text", myBindingSource, "PictureFile")
DataGridView1.DataSource = myBindingSource
End Sub
Private Sub lblPhotoFile_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lblPhotoFile.TextChanged
Try
PictureBox1.Image = Nothing
PictureBox1.Image = Image.FromFile(lblPhotoFile.Text)
Catch ex As Exception
End Try
End Sub
Sub txtFirstName_KeyPress(ByVal sender As Object, ByVal e As KeyPressEventArgs) Handles txtFirstName.KeyPress
If e.KeyChar = ControlChars.Cr Then
txtLastName.Focus()
End If
End Sub
Private Sub btnFirst_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnFirst.Click
myBindingSource.MoveFirst()
End Sub
Private Sub btnPrevious_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnPrevious.Click
myBindingSource.MovePrevious()
End Sub
Private Sub btnNext_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnNext.Click
myBindingSource.MoveNext()
End Sub
Private Sub btnLast_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnLast.Click
myBindingSource.MoveLast()
End Sub
Private Sub myBindingSource_PositionChanged(ByVal sender As Object, ByVal e As EventArgs) Handles myBindingSource.PositionChanged
TextBox1.Text = myBindingSource.Position + 1 & " / " & myBindingSource.Count
End Sub
Private Sub btnAdd_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnAdd.Click
myBindingSource.AddNew()
ComboBox1.SelectedIndex = -1
lblGrade.Text = "1"
End Sub
Private Sub btnCancel_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnCancel.Click
myBindingSource.CancelEdit()
End Sub
Private Sub btnSave_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSave.Click
If txtEmpNo.Text.Trim = "" Or txtFirstName.Text.Trim = "" Or txtLastName.Text.Trim = "" Or ComboBox1.SelectedIndex = -1 Or txtjop.Text.Trim = "" Or txtStep.Text.Trim = "" Or txtDep.Text.Trim = "" Or txtadress.Text.Trim = "" Or txtHomePhone.Text.Trim = "" Then
MessageBox.Show("من فضلك يرجى عدم ترك حقل فارغ", "إدخال خاطىء", MessageBoxButtons.OK, MessageBoxIcon.Information)
Exit Sub
End If
Dim SavedItem As String = txtLastName.Text
Dim SavedRow As Integer
myBindingSource.EndEdit()
InfoTable.DefaultView.Sort = "LastName"
SavedRow = InfoTable.DefaultView.Find(SavedItem)
MsgBox("تمت عملية الأضافة بنجاح", MsgBoxStyle.Information, "حفظ")
End Sub
Private Sub btnDelete_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnDelete.Click
If MessageBox.Show("هل أنت متأكد من أنك تريد حذف هذا السجل" _
, "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question, _
MessageBoxDefaultButton.Button2) = Windows.Forms.DialogResult.Yes Then
myBindingSource.RemoveCurrent()
End If
MsgBox("تمت عملية ألحذف بنجاح", MsgBoxStyle.Information, "حفظ")
End Sub
Private Sub btnExit_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnExit.Click
Close()
End Sub
Private Sub frmInfo_FormClosing(ByVal sender As Object, ByVal e As FormClosingEventArgs) Handles Me.FormClosing
If InfoState = "Edit" Or InfoState = "Add" Then
MessageBox.Show("!!! لايمكنك الخروج هكذا لانك لم تكمل ألأضافة أو إضغط زر تراجع ", "", MessageBoxButtons.OK, MessageBoxIcon.Information)
e.Cancel = True
Else
'Try
Dim InfoAdapterCommands As New OleDbCommandBuilder(InfoAdapter)
InfoAdapter.Update(InfoTable)
InfoTable = New DataTable()
InfoAdapter.Fill(InfoTable)
DataGridView1.DataSource = InfoTable
End If
End Sub
Private Sub btnLoadPhoto_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoadPhoto.Click
OpenFileDialog1.Filter = "Images (*.jpg,*.png,*.gif)|*.jpg;*.jpeg;*.png;*.gif"
If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
Try
PictureBox1.Image = Image.FromFile(OpenFileDialog1.FileName)
lblPhotoFile.Text = OpenFileDialog1.FileName
Catch ex As Exception
lblPhotoFile.Text = ""
End Try
End If
End Sub
End Class