01-04-17, 01:39 PM
(آخر تعديل لهذه المشاركة : 01-04-17, 01:50 PM {2} بواسطة نبيل كونكت.)
كود :
Imports System.Data.OleDb
Imports System.Data
Public Class folderadd
Dim da As OleDbDataAdapter
Dim sqlstr As String
Public a As Integer
Sub amount()
txtamount.Text = Val(txtqty.Text) * Val(txtprice.Text)
End Sub
Dim dt As New DataTable
Sub sorse()
dt.Columns.Add("رقم الصنف")
dt.Columns.Add("اسم الصنف")
dt.Columns.Add("الكميه")
dt.Columns.Add("سعر الشراء")
dt.Columns.Add("الاجمالى")
dgvprodac.DataSource = dt
dgvprodac.Columns(0).Width = txtid.Width
dgvprodac.Columns(1).Width = txtlabel.Width
dgvprodac.Columns(2).Width = txtprice.Width
dgvprodac.Columns(3).Width = txtqty.Width
dgvprodac.Columns(4).Width = txtamount.Width
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim frm As New frlko
frm.ShowDialog()
txtcusid.Text = frm.dgvcust.CurrentRow.Cells(0).Value
txtfullname.Text = frm.dgvcust.CurrentRow.Cells(1).Value
txttell.Text = frm.dgvcust.CurrentRow.Cells(2).Value
End Sub
Private Sub folderadd_Load(sender As Object, e As EventArgs) Handles MyBase.Load
txtsailman.Text = fullname
sorse()
Try
a = 0
a = txtnamper.Text
Catch ex As Exception
MsgBox(ex.Message)
End Try
Try
con.Open()
sqlstr = "Select IIF(MAX(Id) IS NULL,0,MAX(Id)) + 1 AS maxId from TAB_OLDER"
cmd = New OleDbCommand(sqlstr, con)
txtnamper.Text = cmd.ExecuteScalar()
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Sub clear()
txtid.Clear()
txtlabel.Clear()
txtprice.Clear()
txtqty.Clear()
txtamount.Clear()
txtid.Focus()
End Sub
Private Sub txtid_KeyDown(sender As Object, e As KeyEventArgs) Handles txtid.KeyDown
Try
If e.KeyCode = Keys.Enter Then
'get product infos
cmd = New OleDb.OleDbCommand("select label, PRICE from tab_pro where id = " & txtid.Text, con)
con.Open()
Dim dr As OleDb.OleDbDataReader = cmd.ExecuteReader
dr.Read()
If dr.HasRows Then
txtlabel.Text = dr(0)
txtprice.Text = dr(1)
txtqty.Focus()
Else
MsgBox("تحقق من المنتج", MsgBoxStyle.Exclamation, "تنبيه")
clear()
End If
dr.Close()
End If
Catch ex As Exception
Exit Sub
Finally
con.Close()
End Try
End Sub
Private Sub txtprice_TextChanged(sender As Object, e As EventArgs) Handles txtqty.TextChanged, txtprice.TextChanged
Try
amount()
Catch ex As Exception
Exit Sub
End Try
End Sub
Private Sub txtqty_KeyDown(sender As Object, e As KeyEventArgs) Handles txtqty.KeyDown
If e.KeyCode = Keys.Enter Then
Dim raw As DataRow = dt.NewRow
raw(0) = txtid.Text
raw(1) = txtlabel.Text
raw(2) = txtqty.Text
raw(3) = txtprice.Text
raw(4) = txtamount.Text
dt.Rows.Add(raw)
Me.dgvprodac.DataSource = dt
clear()
End If
End Sub
Private Sub btndelet_Click(sender As Object, e As EventArgs) Handles btndelet.Click
Try
dgvprodac.Rows.RemoveAt(dgvprodac.CurrentRow.Index)
Catch ex As Exception
End Try
End Sub
Private Sub btndeletall_Click(sender As Object, e As EventArgs) Handles btndeletall.Click
dt.Rows.Clear()
Me.dgvprodac.DataSource = dt
End Sub
Private Sub dgvprodac_DoubleClick(sender As Object, e As EventArgs) Handles dgvprodac.DoubleClick
Try
txtid.Text = Me.dgvprodac.CurrentRow.Cells(0).Value
txtlabel.Text = Me.dgvprodac.CurrentRow.Cells(1).Value
txtqty.Text = Me.dgvprodac.CurrentRow.Cells(2).Value
txtprice.Text = Me.dgvprodac.CurrentRow.Cells(3).Value
txtamount.Text = Me.dgvprodac.CurrentRow.Cells(4).Value
dgvprodac.Rows.RemoveAt(dgvprodac.CurrentRow.Index)
Catch ex As Exception
Exit Sub
End Try
End Sub
Sub MySub()
Dim f As New folder
sqlstr = "Select IIF(MAX(Id) IS NULL,0,MAX(Id)) + 1 AS maxId from TAB_OLDER"
End Sub
Private Sub btnsave_Click(sender As Object, e As EventArgs) Handles btnsave.Click
Dim cmd As New OleDbCommand(String.Empty, con)
Dim ss As String
con.Open()
For Each r As DataGridViewRow In dgvprodac.Rows
Dim ad As Integer = Val(r.Cells(0).Value)
Dim txt As Integer = Val(r.Cells(2).Value)
cmd.CommandText = String.Format(" UPDATE [tab_pro] SET [qty] = qty +{0} WHERE [id] = {1} ", txt, ad)
cmd.ExecuteNonQuery()
Next
Try
'cmd = New OleDbCommand(sqlstr, con)
ss = "INSERT INTO [tab_older] ([date], [sailman],[ID]) VALUES (@date, @sailman, @ID)"
Dim md As New OleDbCommand(ss, con)
cmd.Parameters.AddWithValue("@date", dtolder.Value.Date)
cmd.Parameters.AddWithValue("@sailman", txtsailman.Text)
cmd.Parameters.AddWithValue("@ID", txtnamper.Text)
'con.Open()
cmd.ExecuteNonQuery()
'con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
con.Close()
MsgBox("تم حفظ الفاتوره")
dt.Rows.Clear()
MySub()
End Sub