تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
[VB.NET] مساعدة في الشرح + التطوير ان امكن
#1
السلام عليكم

لدي كود اريد فهمة + ان كان هناك كود افضل منه للفهم اسرع ونفس الوظيفة


كود :
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
       Try
           If DataGridView2.Rows.Count <= 0 Then
               MsgBox("Please add some items to print", MsgBoxStyle.Exclamation)
               Exit Sub
           End If
           Dim con As New OleDb.OleDbConnection(My.Settings.POSConnectionString)
           con.Open()
           Dim sql As String = "Insert into Recipts (ReciptDate,ReciptTotal) Values(:0,:1)"
           Dim cmd As New OleDb.OleDbCommand
           cmd.Parameters.AddWithValue(":0", Date.Now)
           cmd.Parameters.AddWithValue(":1", TextBox4.Text)
           With cmd
               .Connection = con
               .CommandText = sql
           End With
           cmd.ExecuteNonQuery()
           cmd.Dispose()
           Dim cmd1 As New OleDb.OleDbCommand
           sql = "Select max(ReciptID) as MAXID from Recipts"
           With cmd1
               .CommandText = sql
               .Connection = con
           End With
           Dim ReciptID As Long = cmd1.ExecuteScalar
           cmd1.Dispose()
           Dim i As Integer
           For i = 0 To DataGridView2.Rows.Count - 1
               Dim Barcode As String = DataGridView2.Rows(i).Cells(0).Value
               Dim BuyPrice As String = DataGridView2.Rows(i).Cells(2).Value
               Dim SellPrice As String = DataGridView2.Rows(i).Cells(3).Value
               Dim ItemCount As Integer = DataGridView2.Rows(i).Cells(4).Value
               Dim cmd2 As New OleDb.OleDbCommand
               sql = "Insert into ReciptDetails values(:0,:1,:2,:3,:4)"
               With cmd2
                   .CommandText = sql
                   .Connection = con
               End With
               cmd2.Parameters.AddWithValue(":0", ReciptID)
               cmd2.Parameters.AddWithValue(":1", Barcode)
               cmd2.Parameters.AddWithValue(":2", ItemCount)
               cmd2.Parameters.AddWithValue(":3", BuyPrice)
               cmd2.Parameters.AddWithValue(":4", SellPrice)
               cmd2.ExecuteNonQuery()
               cmd2.Dispose()
           Next
           con.Close()
           con.Dispose()
           If Not IsNothing(TextBox6.Text) Then
               ReciptImage = DrawRecipt(DataGridView2.Rows, ReciptID, Format(Now.Date, "dd-mm-yyyy"), TextBox4.Text, TextBox5.Text, TextBox8.Text, TextBox7.Text)
               If PrintDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
                   PrintDoc.PrinterSettings = PrintDialog1.PrinterSettings
                   PrintDoc.Print()
                   DataGridView2.Rows.Clear()
                   TextBox4.Clear()
               End If
           ElseIf PictureBox1.Image Is Nothing Then
               MsgBox("Can't Print receipt please check the settings", MsgBoxStyle.Critical)
           Else
               MsgBox("You did not setup the printer", MsgBoxStyle.Exclamation)
           End If
       Catch ex As Exception
           MsgBox(ex.ToString, MsgBoxStyle.Critical)
       End Try
   End Sub

الكود هو طباعة الرصيد + تعديل على بيانات المنتج مع الكمية المتوفرة
الكود شغال بدون مشاكل ولكن الكود طويل وصعب الفهم بالنسبة لي احب الاكواد المبسطة والمفهومة بنفس قوة والوظيفة .

شكرا لكم اخواني على المشاهدة و القراءة واشكر كل من حاول المساعدة وطبعا اشكر كل عضو ساعدني سابقا ومازال يساعدني
الرد }}}
تم الشكر بواسطة:
#2
الكود يتكون من اربعة جزئيات

الجزء الاول حفظ تاريخ الرصيد المجموع

كود :
Dim con As New OleDb.OleDbConnection(My.Settings.POSConnectionString)
          con.Open()
          Dim sql As String = "Insert into Recipts (ReciptDate,ReciptTotal) Values(:0,:1)"
          Dim cmd As New OleDb.OleDbCommand
          cmd.Parameters.AddWithValue(":0", Date.Now)
          cmd.Parameters.AddWithValue(":1", TextBox4.Text)
          With cmd
              .Connection = con
              .CommandText = sql
          End With
          cmd.ExecuteNonQuery()
          cmd.Dispose()
الجزء الثاني لجلب اكبر قيمة من حقل ReceiptID واستخدام هذه القيمة في رقم رصيد جديد

كود :
Dim cmd1 As New OleDb.OleDbCommand
          sql = "Select max(ReciptID) as MAXID from Recipts"
          With cmd1
              .CommandText = sql
              .Connection = con
          End With
          Dim ReciptID As Long = cmd1.ExecuteScalar
          cmd1.Dispose()

الجزء الثالث لحفظ تفاصيل الرصيد والتفاصيل هنا هو عدد غير محدود من الصفوف الموجودة في الــ DataGridView
كود :
Dim i As Integer
          For i = 0 To DataGridView2.Rows.Count - 1
              Dim Barcode As String = DataGridView2.Rows(i).Cells(0).Value
              Dim BuyPrice As String = DataGridView2.Rows(i).Cells(2).Value
              Dim SellPrice As String = DataGridView2.Rows(i).Cells(3).Value
              Dim ItemCount As Integer = DataGridView2.Rows(i).Cells(4).Value
              Dim cmd2 As New OleDb.OleDbCommand
              sql = "Insert into ReciptDetails values(:0,:1,:2,:3,:4)"
              With cmd2
                  .CommandText = sql
                  .Connection = con
              End With
              cmd2.Parameters.AddWithValue(":0", ReciptID)
              cmd2.Parameters.AddWithValue(":1", Barcode)
              cmd2.Parameters.AddWithValue(":2", ItemCount)
              cmd2.Parameters.AddWithValue(":3", BuyPrice)
              cmd2.Parameters.AddWithValue(":4", SellPrice)
              cmd2.ExecuteNonQuery()
              cmd2.Dispose()
          Next
          con.Close()
          con.Dispose()

الجزء الرابع لطباعة الرصيد 
كود :
If Not IsNothing(TextBox6.Text) Then
              ReciptImage = DrawRecipt(DataGridView2.Rows, ReciptID, Format(Now.Date, "dd-mm-yyyy"), TextBox4.Text, TextBox5.Text, TextBox8.Text, TextBox7.Text)
              If PrintDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
                  PrintDoc.PrinterSettings = PrintDialog1.PrinterSettings
                  PrintDoc.Print()
                  DataGridView2.Rows.Clear()
                  TextBox4.Clear()
              End If
          ElseIf PictureBox1.Image Is Nothing Then
              MsgBox("Can't Print receipt please check the settings", MsgBoxStyle.Critical)
          Else
              MsgBox("You did not setup the printer", MsgBoxStyle.Exclamation)
          End If

اخي هذا شرح حسب فهمي المتواضع.
الرد }}}
تم الشكر بواسطة: بادئ


المواضيع المحتمل أن تكون متشابهة .
الموضوع : الكاتب الردود : المشاهدات : آخر رد
  [VB.NET] مساعدة في تقرير mrfenix93 1 41 24-03-24, 10:29 PM
آخر رد: mrfenix93
  مساعدة jalaltech 1 96 07-03-24, 07:38 PM
آخر رد: قناص المدينة
  [VB.NET] مساعدة فى كود فاتورة اللكترونية asdfar1977 2 194 02-03-24, 02:00 AM
آخر رد: asdfar1977
  مساعدة فى كود فاتورة الكترونية asdfar1977 0 80 29-02-24, 07:14 PM
آخر رد: asdfar1977
  مساعدة jalaltech 0 133 17-02-24, 02:15 AM
آخر رد: jalaltech
  طلب مساعدة AHMED213 3 324 06-02-24, 09:39 PM
آخر رد: AHMED213
  [VB.NET] طلب مساعدة AHMED213 0 221 31-01-24, 12:56 AM
آخر رد: AHMED213
  طلب مساعدة بخصوص كود الطباعة paveldida 2 461 19-01-24, 12:00 AM
آخر رد: العتيق
  [VB.NET] مساعدة في استدعاء البيانات معينه من form الأول إلى form 2 بدون التعديل loay775 2 275 18-01-24, 05:04 PM
آخر رد: loay775
  اريد مساعدة في العملية الحسابية melad2002 3 406 29-12-23, 09:10 PM
آخر رد: melad2002

التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم