المشاركات : 2
المواضيع 1
الإنتساب : Jun 2022
السمعة :
0
الشكر: 1
تم شكره 0 مرات في 0 مشاركات
كود :
Private Sub BtnSave_Click(sender As System.Object, e As System.EventArgs) Handles BtnSave.Click, BtnClose.Click
Total.Text = Val(Total.Text) + Val(DiscountTotal.Text)
Insert_Buy_Tbl(Buy_ID.Text, Buy_Date.Value, Imp_Inv_No.Text, Inv_Type.Text, SalesMan.Text, Imp_ID.Text, Item_Count.Text, Total.Text, TaxValue.Text, TaxTotal.Text, DiscountValue.Text, DiscountTotal.Text, FinalTotal.Text, Paid.Text, UnPaid.Text)
Insert_Buy_Details_Tbl()
InsertStore()
Update_Imp_Balance()
Insert_Imp_Move(Buy_Date.Value, Imp_ID.Text, "فاتورة شراء", FinalTotal.Text, Paid.Text, UnPaid.Text, SalesMan.Text)
End Sub
كود :
Public Sub Insert_Buy_Tbl(ByVal Buy_ID As Int32, ByVal Buy_Date As Date, ByVal Imp_Inv_No As String, ByVal Inv_Type As String, ByVal SalesMan As String, ByVal Imp_ID As Int32, ByVal Item_Count As Int32, ByVal Total As Double, ByVal Tax_Per As Double, ByVal TaxTotal As Double, ByVal Discount_Per As Double, ByVal DiscountTotal As Double, ByVal FinalTotal As Double, ByVal Paid As Double, ByVal UnPaid As Double)
Dim Cmd As New SqlCommand
With Cmd
.Connection = Con
.CommandType = CommandType.Text
.CommandText = "Insert Into Buy_Tbl ( Buy_ID,Buy_Date,Imp_Inv_No,Inv_Type,SalesMan,Imp_ID,Item_Count,Total,Tax_Per,TaxTotal,Discount_Per,DiscountTotal,FinalTotal,Paid,UnPaid)values(@Buy_ID,@Buy_Date,@Imp_Inv_No,@Inv_Type,@SalesMan,@Imp_ID,@Item_Count,@Total,@Tax_Per,@TaxTotal,@Discount_Per,@DiscountTotal,@FinalTotal,@Paid,@UnPaid)"
.Parameters.Clear()
.Parameters.AddWithValue("@Buy_ID", SqlDbType.Int).Value = Buy_ID
.Parameters.AddWithValue("@Buy_Date", SqlDbType.Date).Value = Buy_Date
.Parameters.AddWithValue("@Imp_Inv_No", SqlDbType.VarChar).Value = Imp_Inv_No
.Parameters.AddWithValue("@Inv_Type", SqlDbType.VarChar).Value = Inv_Type
.Parameters.AddWithValue("@SalesMan", SqlDbType.VarChar).Value = SalesMan
.Parameters.AddWithValue("@Imp_ID", SqlDbType.Int).Value = Imp_ID
.Parameters.AddWithValue("@Item_Count", SqlDbType.Int).Value = Item_Count
.Parameters.AddWithValue("@Total", SqlDbType.Decimal).Value = Total
.Parameters.AddWithValue("@Tax_Per", SqlDbType.Decimal).Value = Tax_Per
.Parameters.AddWithValue("@TaxTotal", SqlDbType.Decimal).Value = TaxTotal
.Parameters.AddWithValue("@Discount_Per", SqlDbType.Decimal).Value = Discount_Per
.Parameters.AddWithValue("@DiscountTotal", SqlDbType.Decimal).Value = DiscountTotal
.Parameters.AddWithValue("@FinalTotal", SqlDbType.Decimal).Value = FinalTotal
.Parameters.AddWithValue("@Paid", SqlDbType.Decimal).Value = Paid
.Parameters.AddWithValue("@UnPaid", SqlDbType.Decimal).Value = UnPaid
End With
If Con.State = 1 Then Con.Close()
Con.Open()
Cmd.ExecuteNonQuery()
Con.Close()
Cmd = Nothing
End Sub
صورة الخطا
المشاركات : 2,061
المواضيع 49
الإنتساب : Oct 2017
السمعة :
538
الشكر: 10647
تم شكره 5323 مرات في 2095 مشاركات
17-06-22, 09:23 PM
(آخر تعديل لهذه المشاركة : 17-06-22, 09:35 PM {2} بواسطة ابراهيم ايبو.)
السلام عليكم ورحمة الله وبركاته
اخي الكريم
في الكود الاول والذي ينادي الصب انت تأخذ القيم من مربعات النصوص بدون ان تحول القيمة
كل قيمة رقمية من نوع Double حولها وكذلك من نوع integer
كود :
Insert_Buy_Tbl(Convert.ToInt32(Buy_ID.Text), Buy_Date.Value, Imp_Inv_No.Text, Inv_Type.Text, SalesMan.Text, ToInt32(Imp_ID.Text), Item_Count.Text, Convert.ToDouble(Total.Text), Convert.ToDouble(TaxValue.Text), Convert.ToDouble(TaxTotal.Text), DiscountValue.Text, Convert.ToDouble(DiscountTotal.Text, FinalTotal.Text), Convert.ToDouble(Paid.Text), Convert.ToDouble(UnPaid.Text))
هذا في حال الاسماء كلها صحيحة
اما الكود الثاني عند العمل مع الباراميترات لديك طريقتين
الاولى WithValue هكذا وليس كما كتبت انت بدمج الطريقتين معا
كود :
Public Sub Insert_Buy_Tbl(ByVal Buy_ID As Int32, ByVal Buy_Date As Date, ByVal Imp_Inv_No As String, ByVal Inv_Type As String, ByVal SalesMan As String, ByVal Imp_ID As Int32, ByVal Item_Count As Int32, ByVal Total As Double, ByVal Tax_Per As Double, ByVal TaxTotal As Double, ByVal Discount_Per As Double, ByVal DiscountTotal As Double, ByVal FinalTotal As Double, ByVal Paid As Double, ByVal UnPaid As Double)
Dim Cmd As New SqlCommand
With Cmd
.Connection = Con
.CommandType = CommandType.Text
.CommandText = "Insert Into Buy_Tbl ( Buy_ID,Buy_Date,Imp_Inv_No,Inv_Type,SalesMan,Imp_ID,Item_Count,Total,Tax_Per,TaxTotal,Discount_Per,DiscountTotal,FinalTotal,Paid,UnPaid)values(@Buy_ID,@Buy_Date,@Imp_Inv_No,@Inv_Type,@SalesMan,@Imp_ID,@Item_Count,@Total,@Tax_Per,@TaxTotal,@Discount_Per,@DiscountTotal,@FinalTotal,@Paid,@UnPaid)"
.Parameters.Clear()
.Parameters.AddWithValue("@Buy_ID", Buy_ID)
.Parameters.AddWithValue("@Buy_Date", Buy_Date)
.Parameters.AddWithValue("@Imp_Inv_No", Imp_Inv_No)
.Parameters.AddWithValue("@Inv_Type", Inv_Type)
.Parameters.AddWithValue("@SalesMan", SalesMan)
.Parameters.AddWithValue("@Imp_ID", Imp_ID)
.Parameters.AddWithValue("@Item_Count", Item_Count)
.Parameters.AddWithValue("@Total", Total)
.Parameters.AddWithValue("@Tax_Per", Tax_Per)
.Parameters.AddWithValue("@TaxTotal", TaxTotal)
.Parameters.AddWithValue("@Discount_Per", Discount_Per)
.Parameters.AddWithValue("@DiscountTotal", DiscountTotal)
.Parameters.AddWithValue("@FinalTotal", FinalTotal)
.Parameters.AddWithValue("@Paid", Paid)
.Parameters.AddWithValue("@UnPaid", UnPaid)
End With
If Con.State = 1 Then Con.Close()
Con.Open()
Cmd.ExecuteNonQuery()
Con.Close()
Cmd = Nothing
End Sub
او الطريقة الاخرى هكذا
كود :
Public Sub Insert_Buy_Tbl(ByVal Buy_ID As Int32, ByVal Buy_Date As Date, ByVal Imp_Inv_No As String, ByVal Inv_Type As String, ByVal SalesMan As String, ByVal Imp_ID As Int32, ByVal Item_Count As Int32, ByVal Total As Double, ByVal Tax_Per As Double, ByVal TaxTotal As Double, ByVal Discount_Per As Double, ByVal DiscountTotal As Double, ByVal FinalTotal As Double, ByVal Paid As Double, ByVal UnPaid As Double)
Dim Cmd As New SqlCommand
With Cmd
.Connection = Con
.CommandType = CommandType.Text
.CommandText = "Insert Into Buy_Tbl ( Buy_ID,Buy_Date,Imp_Inv_No,Inv_Type,SalesMan,Imp_ID,Item_Count,Total,Tax_Per,TaxTotal,Discount_Per,DiscountTotal,FinalTotal,Paid,UnPaid)values(@Buy_ID,@Buy_Date,@Imp_Inv_No,@Inv_Type,@SalesMan,@Imp_ID,@Item_Count,@Total,@Tax_Per,@TaxTotal,@Discount_Per,@DiscountTotal,@FinalTotal,@Paid,@UnPaid)"
.Parameters.Clear()
.Parameters.Add(New SqlParameter("@Buy_ID", SqlDbType.Int)).Value = Buy_ID
.Parameters.Add(New SqlParameter("@Buy_Date", SqlDbType.Date)).Value = Buy_Date
.Parameters.Add(New SqlParameter("@Imp_Inv_No", SqlDbType.VarChar)).Value = Imp_Inv_No
.Parameters.Add(New SqlParameter("@Inv_Type", SqlDbType.VarChar)).Value = Inv_Type
.Parameters.Add(New SqlParameter("@SalesMan", SqlDbType.VarChar)).Value = SalesMan
.Parameters.Add(New SqlParameter("@Imp_ID", SqlDbType.Int)).Value = Imp_ID
.Parameters.Add(New SqlParameter("@Item_Count", SqlDbType.Int)).Value = Item_Count
.Parameters.Add(New SqlParameter("@Total", SqlDbType.Decimal)).Value = Total
.Parameters.Add(New SqlParameter("@Tax_Per", SqlDbType.Decimal)).Value = Tax_Per
.Parameters.Add(New SqlParameter("@TaxTotal", SqlDbType.Decimal)).Value = TaxTotal
.Parameters.Add(New SqlParameter("@Discount_Per", SqlDbType.Decimal)).Value = Discount_Per
.Parameters.Add(New SqlParameter("@DiscountTotal", SqlDbType.Decimal)).Value = DiscountTotal
.Parameters.Add(New SqlParameter("@FinalTotal", SqlDbType.Decimal)).Value = FinalTotal
.Parameters.Add(New SqlParameter("@Paid", SqlDbType.Decimal)).Value = Paid
.Parameters.Add(New SqlParameter("@UnPaid", SqlDbType.Decimal)).Value = UnPaid
End With
If Con.State = 1 Then Con.Close()
Con.Open()
Cmd.ExecuteNonQuery()
Con.Close()
Cmd = Nothing
End Sub
End Class
اعمل الخير وأجرك لا تنتظره فالله خير من إليك يرده
البرمجة ليست مجرد كود بل هي منهج تفكير منطقي لحل المشكلات
المشاركات : 2
المواضيع 1
الإنتساب : Jun 2022
السمعة :
0
الشكر: 1
تم شكره 0 مرات في 0 مشاركات
شكرا اخي الكريم الكود الاول طبقت مثل ما تفضلت ونحلت المشكلة
لكن الان ظهر خطا ثاني
صورة الخطأ
كود :
Public Sub Insert_Imp_Move(ByVal Move_Date As Date, ByVal Imp_ID As Int32, ByVal Move_Type As String, ByVal Move_Total As Double, ByVal Paid As Double, ByVal UnPaid As Double, ByVal SalesMan As String)
Dim Cmd As New SqlCommand
With Cmd
.Connection = Con
.CommandType = CommandType.Text
.CommandText = "Insert Into Imp_Move ( Move_Date,Imp_ID,Move_Type,Move_Total,Paid,UnPaid,SalesMan)values(@Move_Date,@Imp_ID,@Move_Type,@Move_Total,@Paid,@UnPaid,@SalesMan)"
.Parameters.Clear()
.Parameters.AddWithValue("@Move_Date", SqlDbType.Date).Value = Move_Date
.Parameters.AddWithValue("@Imp_ID", SqlDbType.Int).Value = Imp_ID
.Parameters.AddWithValue("@Move_Type", SqlDbType.VarChar).Value = Move_Type
.Parameters.AddWithValue("@Move_Total", SqlDbType.Decimal).Value = Move_Total
.Parameters.AddWithValue("@Paid", SqlDbType.Decimal).Value = Paid
.Parameters.AddWithValue("@UnPaid", SqlDbType.Decimal).Value = UnPaid
.Parameters.AddWithValue("@SalesMan", SqlDbType.VarChar).Value = SalesMan
End With
If Con.State = 1 Then Con.Close()
Con.Open()
Cmd.ExecuteNonQuery()
Con.Close()
MsgBox("تم إضافة السجل بنجاح", MsgBoxStyle.Information, "حفظ")
Cmd = Nothing
End Sub
|