المشاركات : 684
المواضيع 248
الإنتساب : Dec 2013
السمعة :
18
الشكر: 379
تم شكره 381 مرات في 232 مشاركات
13-12-18, 08:19 PM
(آخر تعديل لهذه المشاركة : 13-12-18, 08:22 PM {2} بواسطة محمد اسماعيل.)
السلام عليكم
قمت بانشاء وظيفة لاضافة سريال نمبر لكل فاتورة بيع
السريال يعتمد علي قيمة ثابتة مثلا 50 او we مثلا
وبعد ذالك يضاف رقم 1 ويجمع علي اخر رقم لكل فاتورة يتم طباعتها
يبقي اول قيمة لاول فاتورة 501 و 502 و 503 وهكذا مع شرط وجود رقم 50 اول الفاتورة
يبقي اول قيمة لاول فاتورة we1 و we2 و we3 وهكذا مع شرط وجود رقم 50 اول الفاتورة
استخدمت الوظيفة كالاتي ظلت تعمل الي قيمة 5010 وتوقفت عن التزايد عند القيمة 5010 لا اعلم ما سبب وقوف الوظيفة عن العمل اذا كانت تعمل في البدايةبدون مشاكل
كود :
Public Function serial(ByVal ds As DataSet, ByVal tb As String, ByVal tbcode As String) As String
Dim bignum As String = CType(ds.Tables(tb).Compute("Max(" & tbcode & ")", tbcode & " >= 0"), String)
Dim mainval, mainvalB, result As String
mainval = bignum.Substring(0, 2)
mainvalB = bignum.Remove(0, 2)
result = CStr(CLng(mainvalB) + 1)
serial = mainval + result
End Function
المشاركات : 2,324
المواضيع 81
الإنتساب : May 2018
السمعة :
522
الشكر: 13917
تم شكره 5687 مرات في 2270 مشاركات
13-12-18, 10:49 PM
(آخر تعديل لهذه المشاركة : 13-12-18, 10:57 PM {2} بواسطة asemshahen5.)
كود :
Public Function serial(ByVal ds As DataSet, ByVal tb As String, ByVal tbcode As String) As String
Dim cn As New SqlConnection("Server =(local);database=ALASEM2;integrated security=True")
ClearTools()
Dim StrSQL As String = "Select IIF(Max(" & tbcode & ") Is NULL,50,Max(" & tbcode & ")+1) From " & tb & ""
Dim StrTableName As String = "CASTOMER"
Dim da As New SqlDataAdapter(StrSQL, cn)
ds.Clear()
da.Fill(ds, StrTableName)
Dim bignum As String = ds.Tables(StrTableName).Rows(0)(0).ToString()
serial = bignum
End Function
أو
كود :
Dim StrSQL As String = "Select IIF(Max(ID) Is NULL,50,Max(ID)+1) From CASTOMER"
Dim cn As New SqlConnection("Server =(local);database=ALASEM2;integrated security=True")
Dim StrTableName As String = "CASTOMER"
Dim da As New SqlDataAdapter(StrSQL, cn)
Dim dt As New DataSet
da.Fill(dt, StrTableName)
Txt_ID.Text = dt.Tables(StrTableName).Rows(0)(0).ToString()
أو
كود :
Public Function serial1(ByVal dt As DataSet, ByVal tb As String, ByVal tbcode As String) As String
Dim bignum As String = CType(dt.Tables(tb).Compute("Max(" & tbcode & ")+1", tbcode & " >= 0"), String)
serial1 = bignum
End Function
سبحان الله وبحمده سبحان الله العظيم و الحمد لله ولا اله الا الله والله اكبر
المشاركات : 684
المواضيع 248
الإنتساب : Dec 2013
السمعة :
18
الشكر: 379
تم شكره 381 مرات في 232 مشاركات
13-12-18, 11:10 PM
(آخر تعديل لهذه المشاركة : 13-12-18, 11:33 PM {2} بواسطة محمد اسماعيل.)
(13-12-18, 10:49 PM)asemshahen5 كتب :
كود :
Public Function serial(ByVal ds As DataSet, ByVal tb As String, ByVal tbcode As String) As String
Dim cn As New SqlConnection("Server =(local);database=ALASEM2;integrated security=True")
ClearTools()
Dim StrSQL As String = "Select IIF(Max(" & tbcode & ") Is NULL,50,Max(" & tbcode & ")+1) From " & tb & ""
Dim StrTableName As String = "CASTOMER"
Dim da As New SqlDataAdapter(StrSQL, cn)
ds.Clear()
da.Fill(ds, StrTableName)
Dim bignum As String = ds.Tables(StrTableName).Rows(0)(0).ToString()
serial = bignum
End Function
أو
كود :
Dim StrSQL As String = "Select IIF(Max(ID) Is NULL,50,Max(ID)+1) From CASTOMER"
Dim cn As New SqlConnection("Server =(local);database=ALASEM2;integrated security=True")
Dim StrTableName As String = "CASTOMER"
Dim da As New SqlDataAdapter(StrSQL, cn)
Dim dt As New DataSet
da.Fill(dt, StrTableName)
Txt_ID.Text = dt.Tables(StrTableName).Rows(0)(0).ToString()
أو
كود :
Public Function serial1(ByVal dt As DataSet, ByVal tb As String, ByVal tbcode As String) As String
Dim bignum As String = CType(dt.Tables(tb).Compute("Max(" & tbcode & ")+1", tbcode & " >= 0"), String)
serial1 = bignum
End Function
بشكرك علي ردك ومتابعتك الموضوع اسمح لي دقائق
هجرب ورد عليك
(13-12-18, 10:49 PM)asemshahen5 كتب :
كود :
Public Function serial(ByVal ds As DataSet, ByVal tb As String, ByVal tbcode As String) As String
Dim cn As New SqlConnection("Server =(local);database=ALASEM2;integrated security=True")
ClearTools()
Dim StrSQL As String = "Select IIF(Max(" & tbcode & ") Is NULL,50,Max(" & tbcode & ")+1) From " & tb & ""
Dim StrTableName As String = "CASTOMER"
Dim da As New SqlDataAdapter(StrSQL, cn)
ds.Clear()
da.Fill(ds, StrTableName)
Dim bignum As String = ds.Tables(StrTableName).Rows(0)(0).ToString()
serial = bignum
End Function
أو
كود :
Dim StrSQL As String = "Select IIF(Max(ID) Is NULL,50,Max(ID)+1) From CASTOMER"
Dim cn As New SqlConnection("Server =(local);database=ALASEM2;integrated security=True")
Dim StrTableName As String = "CASTOMER"
Dim da As New SqlDataAdapter(StrSQL, cn)
Dim dt As New DataSet
da.Fill(dt, StrTableName)
Txt_ID.Text = dt.Tables(StrTableName).Rows(0)(0).ToString()
أو
كود :
Public Function serial1(ByVal dt As DataSet, ByVal tb As String, ByVal tbcode As String) As String
Dim bignum As String = CType(dt.Tables(tb).Compute("Max(" & tbcode & ")+1", tbcode & " >= 0"), String)
serial1 = bignum
End Function
طيب انا عدلت الوظيفة كالاتي :-
علي اساس جملة الاتصال للبرنامج عامة con
كود :
Public Function code(ByVal ds As DataSet, ByVal tb As String, ByVal tbcode As String) As String
Dim StrSQL As String = "Select IIF(Max(" & tbcode & ") Is NULL,50,Max(" & tbcode & ")+1) From " & tb & ""
Dim da As New OleDbDataAdapter(StrSQL, con)
ds.Clear()
da.Fill(ds, tb)
Dim bignum As String = ds.Tables(tb).Rows(0)(0).ToString()
code = bignum
End Function
الي بيحصل كالاتي
الاكواد عندي زادت من 509 الي 510 وانا اريد تثبيت قيمة الخمسين لعملية البحث عن الفاتورة .
فاصبحت هنا حاجة مختلفة 51 بدلا من 5010
انا عايز 509 تبقي 5010 و 5011 و 5012 وهكذا
بردك عند 5099 تبقي 50100 وهكذا
ما اريدة بدون اطالة الخمسين ثابت لايتغير ويضاف 1 الي مابعدة
المشاركات : 2,324
المواضيع 81
الإنتساب : May 2018
السمعة :
522
الشكر: 13917
تم شكره 5687 مرات في 2270 مشاركات
14-12-18, 03:44 AM
(آخر تعديل لهذه المشاركة : 14-12-18, 03:58 AM {2} بواسطة asemshahen5.)
أبدل ال 50 بـ 1 في الاستعلام و ضع :
كود :
Dim bignum As String =50 & ds.Tables(tb).Rows(0)(0).ToString()
أي بالاستعلام :
كود :
Dim StrSQL As String = "Select IIF(Max(" & tbcode & ") Is NULL,1,Max(" & tbcode & ")+1) From " & tb & ""
سبحان الله وبحمده سبحان الله العظيم و الحمد لله ولا اله الا الله والله اكبر
المشاركات : 684
المواضيع 248
الإنتساب : Dec 2013
السمعة :
18
الشكر: 379
تم شكره 381 مرات في 232 مشاركات
14-12-18, 07:14 PM
(آخر تعديل لهذه المشاركة : 14-12-18, 07:16 PM {2} بواسطة محمد اسماعيل.)
(14-12-18, 03:44 AM)asemshahen5 كتب : أبدل ال 50 بـ 1 في الاستعلام و ضع :
كود :
Dim bignum As String =50 & ds.Tables(tb).Rows(0)(0).ToString()
أي بالاستعلام :
كود :
Dim StrSQL As String = "Select IIF(Max(" & tbcode & ") Is NULL,1,Max(" & tbcode & ")+1) From " & tb & ""
أسال الله العظيم ان يحفظك من كل مكروة او كرب.
تم الحل إنشاء الله .
|