كود :
Public Class Frm_Goled
Dim myconn As New DBconn
Private Sub AutoNumber()
myconn.tblGroup.Clear()
myconn.tblGroup = myconn.readData("Select * from Goled", "")
Dim coluname() As String = {"الرقم", "رقم المرجع", "المبلغ المدفوع", "تاريخ الوصل", "ملاحظات", "الباقي"}
myconn.formatgrd(coluname, DgvGoled)
myconn.cur = CType(Me.BindingContext(myconn.tblGroup), CurrencyManager)
myconn.showposition(lbl:=LbAdd)
myconn.NewRecAutoNumber("ID", "Goled", txtID, Me)
TexCompany.Clear()
DtbDate.Text = DateTime.Now.ToShortDateString()
'SummDgvGoled()
SumDgv()
TxtNotes.Clear()
TxtHouer.Clear()
btnAdd.Enabled = True
BtnNew.Enabled = True
btnDelete.Enabled = False
btnSave.Enabled = False
DgvGoled_Config()
End Sub
Private Sub DgvGoled_Config()
With DgvGoled
.Columns(0).FillWeight = 50
.Columns(0).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
.Columns(0).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
.Columns(1).FillWeight = 60
.Columns(1).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
.Columns(1).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
.Columns(2).FillWeight = 80
.Columns(2).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
.Columns(2).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
.Columns(3).FillWeight = 80
.Columns(3).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
.Columns(3).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
.Columns(3).DefaultCellStyle.Format = "yyyy/MM/dd"
.Columns(4).FillWeight = 170
.Columns(4).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
.Columns(4).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
.Columns(5).FillWeight = 170
.Columns(5).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
.Columns(5).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
.Columns(5).Visible = False
End With
End Sub
Private row As Integer
Private Sub Showe()
Try
myconn.tbl.Clear()
myconn.tbl = myconn.readData("select * from Goled", "")
If myconn.tbl.Rows.Count <= 0 Then
MessageBox.Show("لا يوجد بيانات فى هذه الشاشه")
Else
Try
txtID.Text = myconn.tbl.Rows(row)(0).ToString()
TexCompany.Text = myconn.tbl.Rows(row)(1).ToString()
TxtHouer.Text = myconn.tbl.Rows(row)(2).ToString()
DtbDate.Value = myconn.tbl.Rows(row)(3).ToString()
TxtNotes.Text = myconn.tbl.Rows(row)(4).ToString()
TxtSafy.Text = myconn.tbl.Rows(row)(5).ToString()
'TxtSafy.Text = False
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End If
btnAdd.Enabled = False
BtnNew.Enabled = True
btnDelete.Enabled = True
btnSave.Enabled = True
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
'Private Sub SummDgvGoled()
' Dim summ As Integer = 0
' For i As Integer = 0 To DgvGoled.RowCount - 1
' summ += DgvGoled.Rows(i).Cells(2).Value
' Next
' TexTotal2.Text = Format(summ, "00.00")
' TexTotal2.ForeColor = Color.Red
'End Sub
Private Sub SumDgv()
Dim x, y, z As Integer
For i As Integer = 0 To DgvGoled.RowCount - 1
x += DgvGoled.Rows(i).Cells(2).Value
y += DgvGoled.Rows(i).Cells(5).Value
Next
TexTotal2.Text = x.ToString
TextBox1.Text = y.ToString
z = y - x
TexTotal1.Text = z.ToString
End Sub
Private Sub Frm_Goled_Load(sender As Object, e As EventArgs) Handles MyBase.Load
AutoNumber()
End Sub
Private Sub BtnNew_Click(sender As Object, e As EventArgs) Handles BtnNew.Click
AutoNumber()
End Sub
Private Sub btnFirst_Click(sender As Object, e As EventArgs) Handles btnFirst.Click
Showe()
myconn.cur.Position = 0
Dim pos As Integer = Me.DgvGoled.CurrentRow.Index
txtID.Text = DgvGoled.Rows(pos).Cells(0).Value
TexCompany.Text = DgvGoled.Rows(pos).Cells(1).Value
TxtHouer.Text = DgvGoled.Rows(pos).Cells(2).Value
DtbDate.Value = DgvGoled.Rows(pos).Cells(3).Value
TxtNotes.Text = DgvGoled.Rows(pos).Cells(4).Value
TxtSafy.Text = DgvGoled.Rows(pos).Cells(5).Value
myconn.showposition(lbl:=LbAdd)
End Sub
Private Sub btnPrev_Click(sender As Object, e As EventArgs) Handles btnPrev.Click
Showe()
myconn.cur.Position -= 1
Dim pos As Integer = Me.DgvGoled.CurrentRow.Index
txtID.Text = DgvGoled.Rows(pos).Cells(0).Value
TexCompany.Text = DgvGoled.Rows(pos).Cells(1).Value
TxtHouer.Text = DgvGoled.Rows(pos).Cells(2).Value
DtbDate.Value = DgvGoled.Rows(pos).Cells(3).Value
TxtNotes.Text = DgvGoled.Rows(pos).Cells(4).Value
TxtSafy.Text = DgvGoled.Rows(pos).Cells(5).Value
myconn.showposition(lbl:=LbAdd)
End Sub
Private Sub btnNext_Click(sender As Object, e As EventArgs) Handles btnNext.Click
Showe()
myconn.cur.Position += 1
Dim pos As Integer = Me.DgvGoled.CurrentRow.Index
txtID.Text = DgvGoled.Rows(pos).Cells(0).Value
TexCompany.Text = DgvGoled.Rows(pos).Cells(1).Value
TxtHouer.Text = DgvGoled.Rows(pos).Cells(2).Value
DtbDate.Value = DgvGoled.Rows(pos).Cells(3).Value
TxtNotes.Text = DgvGoled.Rows(pos).Cells(4).Value
TxtSafy.Text = DgvGoled.Rows(pos).Cells(5).Value
myconn.showposition(lbl:=LbAdd)
End Sub
Private Sub btnLast_Click(sender As Object, e As EventArgs) Handles btnLast.Click
Showe()
myconn.cur.Position = myconn.cur.Count - 1
Dim pos As Integer = Me.DgvGoled.CurrentRow.Index
txtID.Text = DgvGoled.Rows(pos).Cells(0).Value
TexCompany.Text = DgvGoled.Rows(pos).Cells(1).Value
TxtHouer.Text = DgvGoled.Rows(pos).Cells(2).Value
DtbDate.Value = DgvGoled.Rows(pos).Cells(3).Value
TxtNotes.Text = DgvGoled.Rows(pos).Cells(4).Value
TxtSafy.Text = DgvGoled.Rows(pos).Cells(5).Value
myconn.showposition(lbl:=LbAdd)
End Sub
Private Sub DgvGoled_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles DgvGoled.CellClick
Dim pos As Integer = Me.DgvGoled.CurrentRow.Index
txtID.Text = DgvGoled.Rows(pos).Cells(0).Value
TexCompany.Text = DgvGoled.Rows(pos).Cells(1).Value
TxtHouer.Text = DgvGoled.Rows(pos).Cells(2).Value
DtbDate.Value = DgvGoled.Rows(pos).Cells(3).Value
TxtNotes.Text = DgvGoled.Rows(pos).Cells(4).Value
TxtSafy.Text = DgvGoled.Rows(pos).Cells(5).Value
myconn.showposition(lbl:=LbAdd)
btnAdd.Enabled = False
BtnNew.Enabled = True
End Sub
Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
If TexCompany.Text = "" Then MessageBox.Show(" يجب تعبئة كافة الحقول قبل الحفظ", "تنبية", MessageBoxButtons.OK, MessageBoxIcon.Warning) : TexCompany.Focus() : Exit Sub
If TxtHouer.Text = "" Then MessageBox.Show(" يجب تعبئة كافة الحقول قبل الحفظ", "تنبية", MessageBoxButtons.OK, MessageBoxIcon.Warning) : TxtHouer.Focus() : Exit Sub
Dim d As String = DtbDate.Value.ToString("yyyy/MM/dd")
myconn.exceuteData("insert into Goled Values (" & txtID.Text & " ,N'" + TexCompany.Text & "' ,N'" + TxtHouer.Text & "', N'" & d & "', N'" + TxtNotes.Text & "',N'" + TxtSafy.Text & "' )", "تم الادخال بنجاح")
AutoNumber()
End Sub
Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
If TexCompany.Text = "" Then MessageBox.Show(" يجب تعبئة كافة الحقول قبل الحفظ", "تنبية", MessageBoxButtons.OK, MessageBoxIcon.Warning) : TexCompany.Focus() : Exit Sub
If TxtHouer.Text = "" Then MessageBox.Show(" يجب تعبئة كافة الحقول قبل الحفظ", "تنبية", MessageBoxButtons.OK, MessageBoxIcon.Warning) : TxtHouer.Focus() : Exit Sub
myconn.exceuteData("update Goled set Number_Goled= '" & TexCompany.Text & "', Mony_Goled= '" & TxtHouer.Text & "', Date_Goled= '" & DtbDate.Text & "', Note_Goled= '" & TxtNotes.Text & "',Safy_Goled= '" & TxtSafy.Text & "' where ID=" + txtID.Text + " ", "تم التعديل بنجاح")
AutoNumber()
End Sub
Private Sub btnDelete_Click(sender As Object, e As EventArgs) Handles btnDelete.Click
If MessageBox.Show("هل انتا متاكد من مسح البيانات", "تاكيد", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = DialogResult.Yes Then
myconn.tblSearch = myconn.readData("delete from Goled where ID=" + txtID.Text + "", "تم مسح البيانات بنجاح")
AutoNumber()
End If
End Sub
Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
Close()
End Sub
Private Sub TexCompany_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TexCompany.KeyPress
Select Case e.KeyChar
Case "0"c To "9"c, Chr(Keys.Back)
Case "."
'لن نفعل أي شيء.. هذا معناه قبول كتابة هذا الحرف
Case Else
Beep()
e.Handled = True
End Select
End Sub
Private Sub TxtHouer_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TxtHouer.KeyPress
Select Case e.KeyChar
Case "0"c To "9"c, Chr(Keys.Back)
Case "."
'لن نفعل أي شيء.. هذا معناه قبول كتابة هذا الحرف
Case Else
Beep()
e.Handled = True
End Select
End Sub
End Class