13-10-18, 10:09 AM
هذا هو كود التعديل
Private Sub butedit_Click(sender As System.Object, e As System.EventArgs) Handles butedit.Click
If combosupplier_name.SelectedIndex = -1 Then
MessageBox.Show("برجاء اختيار اسم المورد من القائمة", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
End If
If combosupplierinvoice_type.SelectedIndex = -1 Then
MessageBox.Show("برجاء اختيار نوع فاتورة المورد من القائمة", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
End If
If Format(supplierinvoice_date.Value) > Format(txtstock_date.Value) Then
MsgBox("تاريخ إذن استلام البضاعة اكبر من تاريخ الفاتورة", MsgBoxStyle.Critical, "خطأ")
Exit Sub
End If
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
If dgvdata.Rows.Count = 0 Then
MessageBox.Show("يجب إضافة صنف واحد على الأقل لتتم عملية الحفظ", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
Exit Sub
End If
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
If Len(Trim(txttotalpayment.Text)) = 0 Then
MessageBox.Show("برجاء إدخال قيمة المبلغ المسدد", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
txttotalpayment.Focus()
Exit Sub
End If
'**************************************************************************************************
If Val(txttotalpayment.Text) > Val(txtgrandtotal.Text) Then
MessageBox.Show("لا يمكن أن يكون المبلغ المسدد أكبر من قيمة الفاتورة", "خطأ", MessageBoxButtons.OK, MessageBoxIcon.Error)
txttotalpayment.Focus()
Exit Sub
End If
'****************************************التاكد من الكميات فى الداتا جريد********************************
For k = 0 To dgvdata.Rows.Count - 1
If Val(dgvdata.Rows(k).Cells(5).Value) = 0 Then
MsgBox("يرجى التاكد من جميع كميات الاصناف المستلمة", MsgBoxStyle.Critical, "تنبيه")
Exit Sub
End If
Next
'***************************************الغاء الصفوف الفارغة من الداتا جريد*********************************
For k = 0 To dgvdata.Rows.Count - 1
If dgvdata.Rows(k).Cells(1).Value = Nothing Then
dgvdata.Rows.Remove(dgvdata.Rows(k))
End If
Next
'*************************************اثبات الكمية فى جدول الكميات**************************
Try
For Each row As DataGridViewRow In dgvdata.Rows
If Not row.IsNewRow Then
conn = New SqlClient.SqlConnection(ss)
conn.Open()
Dim ct As String = "select item_code from tblItemsTemp_stock where item_code=@d1"
Dim cmd2 As New SqlClient.SqlCommand(ct)
cmd2.Connection = conn
cmd2.Parameters.AddWithValue("@d1", row.Cells(0).Value.ToString())
rdr = cmd2.ExecuteReader()
If (rdr.Read()) Then
conn = New SqlClient.SqlConnection(ss)
conn.Open()
Dim cb2 As String = "Update tblItemsTemp_stock set quantity = quantity + " & row.Cells(5).Value & " where item_code=@d1"
cmd2 = New SqlClient.SqlCommand(cb2)
cmd2.Connection = conn
cmd2.Parameters.AddWithValue("@d1", row.Cells(0).Value.ToString())
cmd2.ExecuteReader()
conn.Close()
Else
conn = New SqlClient.SqlConnection(ss)
conn.Open()
Dim cb3 As String = "insert into tblItemsTemp_stock(item_code,item_name,quantity) VALUES (@d1,@d2,@d3)"
cmd2 = New SqlClient.SqlCommand(cb3)
cmd2.Connection = conn
cmd2.Parameters.AddWithValue("@d1", row.Cells(0).Value.ToString())
cmd2.Parameters.AddWithValue("@d2", row.Cells(1).Value)
cmd2.Parameters.AddWithValue("@d3", row.Cells(5).Value)
cmd2.ExecuteReader()
conn.Close()
End If
End If
Next
'''''''''''''''''''''''''''''حفظ راس الفاتورة''''''''''''''''''''''''''''''''''''
adp = New SqlClient.SqlDataAdapter("select * from tblstock where stock_code = N'" & txtstock_code.Text & "'", conn)
ds = New DataSet
adp.Fill(ds)
dt = New DataTable
dt = ds.Tables(0)
If dt.Rows.Count = 0 Then
MsgBox("لم يتم العثور على البيان المطلوب", MsgBoxStyle.Exclamation, "تنبيه")
Else
Dim dr1 = dt.Rows(0)
dr1!stock_code = txtstock_code.Text
dr1!stock_date = txtstock_date.Value.Date
dr1!supplier_code = txtsupplier_code.Text
dr1!supplier_name = combosupplier_name.Text
dr1!supplierinvoice_type = combosupplierinvoice_type.Text
dr1!supplierinvoice_no = txtsupplierinvoice_no.Text
dr1!supplierinvoice_date = supplierinvoice_date.Value.Date
dr1!notes = txtnotes.Text
dr1!grandtotal = txtgrandtotal.Text
dr1!payment = txttotalpayment.Text
dr1!paymentdue = txtpaymentdue.Text
dr1!status = True
cmd = New SqlClient.SqlCommandBuilder(adp)
adp.Update(dt)
End If
adp.Dispose()
ds.Dispose()
dt.Dispose()
'''''''''''''''''''''''''''''''''''''''''''' حذف تفاصيل السند السابقة'''''''''''''''''''''''''
Dim cmdd As New SqlClient.SqlCommand
cmdd.Connection = conn
cmdd.CommandText = "delete tblstock_details where stock_code = N'" & txtstock_code.Text & "'"
cmdd.ExecuteNonQuery()
' '=======================================حفظ تفاصيل الفاتورة=============================================
adp = New SqlClient.SqlDataAdapter("select * from tblstock_details ", conn)
ds = New DataSet
adp.Fill(ds)
dt = New DataTable
dt = ds.Tables(0)
For i = 0 To dgvdata.Rows.Count - 1
Dim Dr2 = dt.NewRow
Dr2!stock_code = txtstock_code.Text
Dr2!item_code = dgvdata.Rows(i).Cells(0).Value
Dr2!item_name = dgvdata.Rows(i).Cells(1).Value
Dr2!item_unit = dgvdata.Rows(i).Cells(2).Value
Dr2!category = dgvdata.Rows(i).Cells(3).Value
Dr2!unitprice = dgvdata.Rows(i).Cells(4).Value
Dr2!quantity = dgvdata.Rows(i).Cells(5).Value
Dr2!amount = dgvdata.Rows(i).Cells(6).Value
Dr2!discountper = dgvdata.Rows(i).Cells(7).Value
Dr2!discount = dgvdata.Rows(i).Cells(8).Value
Dr2!totalamount = dgvdata.Rows(i).Cells(9).Value
dt.Rows.Add(Dr2)
cmd = New SqlClient.SqlCommandBuilder(adp)
adp.Update(dt)
Next
' '********************************************اضافة السجل الى جدول اذن الدفع*********************
adp = New SqlClient.SqlDataAdapter("select * from tblPaymentvouchers", conn)
ds = New DataSet
adp.Fill(ds)
dt = New DataTable
dt = ds.Tables(0)
Dim dr = dt.Rows(0)
dr!voucher_code = txtstock_code.Text
dr!voucher_date = txtstock_date.Text
dr!amount = Val(txttotalpayment.Text)
dr!supplier_name = combosupplier_name.Text
Dim str As String = ""
If Val(txttotalpayment.Text) > 0 Then
txttotalpaymentarabic.Text = NumToTxtArabic(txttotalpayment.Text)
Else
txttotalpaymentarabic.Text = ""
End If
str = txttotalpaymentarabic.Text
dr!amount_byarabic = str
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim str1 As String = ""
If combosupplierinvoice_type.SelectedIndex = 0 Then
str1 = "سداد الفاتورة النقدية رقم" & txtsupplierinvoice_no.Text
End If
If combosupplierinvoice_type.SelectedIndex = 1 Then
str1 = "سداد دفعة من الفاتورة الآجلة رقم" & txtsupplierinvoice_no.Text
End If
dr!statement = str1
Dim cmd1 As New SqlClient.SqlCommandBuilder(adp)
adp.Update(dt)
adp.Dispose()
ds.Dispose()
dt.Dispose()
' '********************************************اضافة السجل الى جدول حركات الموردين*******************
adp = New SqlClient.SqlDataAdapter("select * from tblSuppliertrans", conn)
ds = New DataSet
adp.Fill(ds)
dt = New DataTable
dt = ds.Tables(0)
Dim dr3 = dt.Rows(0)
dr3!supplier_name = combosupplier_name.Text
dr3!supplier_code = txtsupplier_code.Text
dr3!voucher_date = txtstock_date.Value.Date
dr3!voucher_code = txtstock_code.Text
dr3!debit = Val(txttotalpayment.Text)
dr3!credit = Val(txtgrandtotal.Text)
Dim str2 As String = ""
If combosupplierinvoice_type.SelectedIndex = 0 Then
str2 = "إذن استلام أصناف للفاتورة النقدية رقم" & txtsupplierinvoice_no.Text
End If
If combosupplierinvoice_type.SelectedIndex = 1 Then
str2 = "إذن استلام أصناف للفاتورة الآجلة رقم" & txtsupplierinvoice_no.Text
End If
dr3!discription = str2
dr3!voucher_type = "إذن استلام أصناف"
Dim cmd3 As New SqlClient.SqlCommandBuilder(adp)
adp.Update(dt)
adp.Dispose()
ds.Dispose()
dt.Dispose()
butnew_Click(Nothing, Nothing)
MsgBox("تمت عملية التعديل بنجاح")
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub butedit_Click(sender As System.Object, e As System.EventArgs) Handles butedit.Click
If combosupplier_name.SelectedIndex = -1 Then
MessageBox.Show("برجاء اختيار اسم المورد من القائمة", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
End If
If combosupplierinvoice_type.SelectedIndex = -1 Then
MessageBox.Show("برجاء اختيار نوع فاتورة المورد من القائمة", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
End If
If Format(supplierinvoice_date.Value) > Format(txtstock_date.Value) Then
MsgBox("تاريخ إذن استلام البضاعة اكبر من تاريخ الفاتورة", MsgBoxStyle.Critical, "خطأ")
Exit Sub
End If
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
If dgvdata.Rows.Count = 0 Then
MessageBox.Show("يجب إضافة صنف واحد على الأقل لتتم عملية الحفظ", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
Exit Sub
End If
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
If Len(Trim(txttotalpayment.Text)) = 0 Then
MessageBox.Show("برجاء إدخال قيمة المبلغ المسدد", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
txttotalpayment.Focus()
Exit Sub
End If
'**************************************************************************************************
If Val(txttotalpayment.Text) > Val(txtgrandtotal.Text) Then
MessageBox.Show("لا يمكن أن يكون المبلغ المسدد أكبر من قيمة الفاتورة", "خطأ", MessageBoxButtons.OK, MessageBoxIcon.Error)
txttotalpayment.Focus()
Exit Sub
End If
'****************************************التاكد من الكميات فى الداتا جريد********************************
For k = 0 To dgvdata.Rows.Count - 1
If Val(dgvdata.Rows(k).Cells(5).Value) = 0 Then
MsgBox("يرجى التاكد من جميع كميات الاصناف المستلمة", MsgBoxStyle.Critical, "تنبيه")
Exit Sub
End If
Next
'***************************************الغاء الصفوف الفارغة من الداتا جريد*********************************
For k = 0 To dgvdata.Rows.Count - 1
If dgvdata.Rows(k).Cells(1).Value = Nothing Then
dgvdata.Rows.Remove(dgvdata.Rows(k))
End If
Next
'*************************************اثبات الكمية فى جدول الكميات**************************
Try
For Each row As DataGridViewRow In dgvdata.Rows
If Not row.IsNewRow Then
conn = New SqlClient.SqlConnection(ss)
conn.Open()
Dim ct As String = "select item_code from tblItemsTemp_stock where item_code=@d1"
Dim cmd2 As New SqlClient.SqlCommand(ct)
cmd2.Connection = conn
cmd2.Parameters.AddWithValue("@d1", row.Cells(0).Value.ToString())
rdr = cmd2.ExecuteReader()
If (rdr.Read()) Then
conn = New SqlClient.SqlConnection(ss)
conn.Open()
Dim cb2 As String = "Update tblItemsTemp_stock set quantity = quantity + " & row.Cells(5).Value & " where item_code=@d1"
cmd2 = New SqlClient.SqlCommand(cb2)
cmd2.Connection = conn
cmd2.Parameters.AddWithValue("@d1", row.Cells(0).Value.ToString())
cmd2.ExecuteReader()
conn.Close()
Else
conn = New SqlClient.SqlConnection(ss)
conn.Open()
Dim cb3 As String = "insert into tblItemsTemp_stock(item_code,item_name,quantity) VALUES (@d1,@d2,@d3)"
cmd2 = New SqlClient.SqlCommand(cb3)
cmd2.Connection = conn
cmd2.Parameters.AddWithValue("@d1", row.Cells(0).Value.ToString())
cmd2.Parameters.AddWithValue("@d2", row.Cells(1).Value)
cmd2.Parameters.AddWithValue("@d3", row.Cells(5).Value)
cmd2.ExecuteReader()
conn.Close()
End If
End If
Next
'''''''''''''''''''''''''''''حفظ راس الفاتورة''''''''''''''''''''''''''''''''''''
adp = New SqlClient.SqlDataAdapter("select * from tblstock where stock_code = N'" & txtstock_code.Text & "'", conn)
ds = New DataSet
adp.Fill(ds)
dt = New DataTable
dt = ds.Tables(0)
If dt.Rows.Count = 0 Then
MsgBox("لم يتم العثور على البيان المطلوب", MsgBoxStyle.Exclamation, "تنبيه")
Else
Dim dr1 = dt.Rows(0)
dr1!stock_code = txtstock_code.Text
dr1!stock_date = txtstock_date.Value.Date
dr1!supplier_code = txtsupplier_code.Text
dr1!supplier_name = combosupplier_name.Text
dr1!supplierinvoice_type = combosupplierinvoice_type.Text
dr1!supplierinvoice_no = txtsupplierinvoice_no.Text
dr1!supplierinvoice_date = supplierinvoice_date.Value.Date
dr1!notes = txtnotes.Text
dr1!grandtotal = txtgrandtotal.Text
dr1!payment = txttotalpayment.Text
dr1!paymentdue = txtpaymentdue.Text
dr1!status = True
cmd = New SqlClient.SqlCommandBuilder(adp)
adp.Update(dt)
End If
adp.Dispose()
ds.Dispose()
dt.Dispose()
'''''''''''''''''''''''''''''''''''''''''''' حذف تفاصيل السند السابقة'''''''''''''''''''''''''
Dim cmdd As New SqlClient.SqlCommand
cmdd.Connection = conn
cmdd.CommandText = "delete tblstock_details where stock_code = N'" & txtstock_code.Text & "'"
cmdd.ExecuteNonQuery()
' '=======================================حفظ تفاصيل الفاتورة=============================================
adp = New SqlClient.SqlDataAdapter("select * from tblstock_details ", conn)
ds = New DataSet
adp.Fill(ds)
dt = New DataTable
dt = ds.Tables(0)
For i = 0 To dgvdata.Rows.Count - 1
Dim Dr2 = dt.NewRow
Dr2!stock_code = txtstock_code.Text
Dr2!item_code = dgvdata.Rows(i).Cells(0).Value
Dr2!item_name = dgvdata.Rows(i).Cells(1).Value
Dr2!item_unit = dgvdata.Rows(i).Cells(2).Value
Dr2!category = dgvdata.Rows(i).Cells(3).Value
Dr2!unitprice = dgvdata.Rows(i).Cells(4).Value
Dr2!quantity = dgvdata.Rows(i).Cells(5).Value
Dr2!amount = dgvdata.Rows(i).Cells(6).Value
Dr2!discountper = dgvdata.Rows(i).Cells(7).Value
Dr2!discount = dgvdata.Rows(i).Cells(8).Value
Dr2!totalamount = dgvdata.Rows(i).Cells(9).Value
dt.Rows.Add(Dr2)
cmd = New SqlClient.SqlCommandBuilder(adp)
adp.Update(dt)
Next
' '********************************************اضافة السجل الى جدول اذن الدفع*********************
adp = New SqlClient.SqlDataAdapter("select * from tblPaymentvouchers", conn)
ds = New DataSet
adp.Fill(ds)
dt = New DataTable
dt = ds.Tables(0)
Dim dr = dt.Rows(0)
dr!voucher_code = txtstock_code.Text
dr!voucher_date = txtstock_date.Text
dr!amount = Val(txttotalpayment.Text)
dr!supplier_name = combosupplier_name.Text
Dim str As String = ""
If Val(txttotalpayment.Text) > 0 Then
txttotalpaymentarabic.Text = NumToTxtArabic(txttotalpayment.Text)
Else
txttotalpaymentarabic.Text = ""
End If
str = txttotalpaymentarabic.Text
dr!amount_byarabic = str
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim str1 As String = ""
If combosupplierinvoice_type.SelectedIndex = 0 Then
str1 = "سداد الفاتورة النقدية رقم" & txtsupplierinvoice_no.Text
End If
If combosupplierinvoice_type.SelectedIndex = 1 Then
str1 = "سداد دفعة من الفاتورة الآجلة رقم" & txtsupplierinvoice_no.Text
End If
dr!statement = str1
Dim cmd1 As New SqlClient.SqlCommandBuilder(adp)
adp.Update(dt)
adp.Dispose()
ds.Dispose()
dt.Dispose()
' '********************************************اضافة السجل الى جدول حركات الموردين*******************
adp = New SqlClient.SqlDataAdapter("select * from tblSuppliertrans", conn)
ds = New DataSet
adp.Fill(ds)
dt = New DataTable
dt = ds.Tables(0)
Dim dr3 = dt.Rows(0)
dr3!supplier_name = combosupplier_name.Text
dr3!supplier_code = txtsupplier_code.Text
dr3!voucher_date = txtstock_date.Value.Date
dr3!voucher_code = txtstock_code.Text
dr3!debit = Val(txttotalpayment.Text)
dr3!credit = Val(txtgrandtotal.Text)
Dim str2 As String = ""
If combosupplierinvoice_type.SelectedIndex = 0 Then
str2 = "إذن استلام أصناف للفاتورة النقدية رقم" & txtsupplierinvoice_no.Text
End If
If combosupplierinvoice_type.SelectedIndex = 1 Then
str2 = "إذن استلام أصناف للفاتورة الآجلة رقم" & txtsupplierinvoice_no.Text
End If
dr3!discription = str2
dr3!voucher_type = "إذن استلام أصناف"
Dim cmd3 As New SqlClient.SqlCommandBuilder(adp)
adp.Update(dt)
adp.Dispose()
ds.Dispose()
dt.Dispose()
butnew_Click(Nothing, Nothing)
MsgBox("تمت عملية التعديل بنجاح")
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
