تقييم الموضوع :
  • 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

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

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


الردود في هذا الموضوع
مساعدة في الشرح + التطوير ان امكن - بواسطة 0theghost0 - 09-09-16, 10:48 AM


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


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