برنامج إدارة المبيعات: الدرس - 13: صفحة المبيعات النقدية - الجزء 4: طباعة الفاتورة المبيعات النقدية


في الدرس الثالث عشر من برنامج ادارة المبيعات سنقوم بطباعة معلومات وصل البيع النقدي إضافةً الى جدول المواد المضافة للوصل عن طريق طفحة المبيعات النقدية




متطلبات هذا الدرس 

  • زر الطباعة btnPrint

  • مديول  الطباعة DataGridViewPrinter1

  • داتاكردفيو dtgTotal (زر الطباعة )


أولا:زر الطباعة btnPrint


يتم ارسال امر الطباعة عن طريق الزر btnPrint الى مديول DataGridViewPrinter1 الخاص بطباعة الداتاكردفيو   ومعلومات الوصل عن طريق الكود التالي:- 

  Private Sub btnPrint_Click(sender As Object, e As EventArgs) Handles btnPrint.Click

        If dgvBillInfo.Rows.Count <> 0 Then

            frm = "Bill"

            DataGridViewPrinter1.StartPrint(dgvBillInfo, False, True, " ", " ")

        Else

            MsgBox("لاتوجد فاتورة معروضة لطباعتها", vbMsgBoxRight + MsgBoxStyle.Exclamation, "جاري الطباعة")

 

        End If

    End Sub

 

ثانياً: مديول  الطباعة DataGridViewPrinter1

داخل  مديول  DataGridViewPrinter1. يتم تحديد معلومات الوصل من الادوات الموجودة في فورم المبيعات النقدية كما في الكود التالي:-

Imports System.Drawing.Printing
Module DataGridViewPrinter1
    Public DataGridViewToPrint As New DataGridView
 
    Public DefaultPageSettings As PageSettings = New PageSettings()
 
    Public WithEvents DocToPrint As New PrintDocument
 
    Private lPageNo As String = ""
    Private sPageNo As String = ""
    Private oStringFormat As StringFormat
    Private oStringFormatComboBox As StringFormat
    Private oButton As Button
    Private oCheckbox As CheckBox
    Private oComboBox As ComboBox
    Private nTotalWidth As Int16
    Private nRowPos As Int16
    Private NewPage As Boolean
    Private nPageNo As Int16
    Private Header As String
    Private FooterComment As String = ""
    Public PrintType As String
 
Public Sub StartPrint(ByVal GridToPrint As DataGridView, ByVal PrintAsLandscape As BooleanByVal ShowPrintPreview As BooleanByVal HeaderToPrint As StringByVal CommentToPrint As String)
 
        DataGridViewToPrint = GridToPrint
        Header = HeaderToPrint
        FooterComment = CommentToPrint
 
        'DataGridViewToPrint.Columns(6).Visible = False ' Use to hide a col. (index no.)
 
 
        ' Set up Default Page Settings
        DocToPrint.DefaultPageSettings.Landscape = PrintAsLandscape
 
        DocToPrint.DefaultPageSettings.Margins.Left = 25
        DocToPrint.DefaultPageSettings.Margins.Right = 75
        DocToPrint.DefaultPageSettings.Margins.Top = 25
        DocToPrint.DefaultPageSettings.Margins.Bottom = 75
 
        DocToPrint.OriginAtMargins = True ' takes margins into account
 
        If ShowPrintPreview = True Then
 
            Dim dlgPrintPreview As New EnhancedPrintPreviewDialog1
 
            dlgPrintPreview.ClientSize = New System.Drawing.Size(600, 600)
            dlgPrintPreview.Document = DocToPrint ' Previews print
            dlgPrintPreview.ShowDialog()
 
        Else
 
            '  Allow the user to choose a printer and specify other settings.
            Dim dlgPrint As New PrintDialog
 
            With dlgPrint
                .AllowSelection = False
                .ShowNetwork = False
                .AllowCurrentPage = True
                .AllowSomePages = True
                .Document = DocToPrint
            End With
 
            '  If the user clicked OK, print the document.
            If dlgPrint.ShowDialog = DialogResult.OK Then
                DocToPrint.Print()
            End If
 
        End If
 

 End Sub
 
 
 
    Public Sub DocToPrint_BeginPrint(ByVal sender As ObjectByVal e As System.Drawing.Printing.PrintEventArgs) Handles DocToPrint.BeginPrint
 
        oStringFormat = New StringFormat
        oStringFormat.Alignment = StringAlignment.Center
        oStringFormat.LineAlignment = StringAlignment.Center
        oStringFormat.Trimming = StringTrimming.EllipsisCharacter
 
        oStringFormatComboBox = New StringFormat
        oStringFormatComboBox.LineAlignment = StringAlignment.Center
 
        oStringFormatComboBox.FormatFlags = StringFormatFlags.DirectionRightToLeft
        oStringFormatComboBox.Trimming = StringTrimming.EllipsisCharacter
 
 
        oButton = New Button
        oCheckbox = New CheckBox
        oComboBox = New ComboBox
 
        nTotalWidth = 0
 
        For Each oColumn As DataGridViewColumn In DataGridViewToPrint.Columns
            If oColumn.Visible = True Then ' Prints only Visible columns
                nTotalWidth += oColumn.Width
            End If
        Next
 
        nPageNo = 1
        NewPage = True
        nRowPos = 0
 
    End Sub
 
Public Sub DocToPrint_PrintPage(ByVal sender As ObjectByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles DocToPrint.PrintPage

 
        Static oColumnLefts As New ArrayList
        Static oColumnWidths As New ArrayList
        Static oColumnTypes As New ArrayList
        Static nHeight As Int16
 
        Dim nWidth, i, nRowsPerPage As Int16
        Dim nTop As Int16 = e.MarginBounds.Top
        Dim nLeft As Int16 = e.MarginBounds.Left
        Dim nRight As Int16 = e.MarginBounds.Right
 
        ' Draw Header
        Dim Rowscount As Integer = DataGridViewToPrint.Rows.Count  ' get rows count for table height
 
        '  Dim rowCount As Integer
        Dim rectC2 As New Rectangle
        If frm = "ForwardSales" Then
            rectC2 = New Rectangle(45, 30, 730, +350 + (Rowscount * 60))  'col1 - border  [ Start from right, Start From top,( Width - end to right),Height - end to down)]
        Else
            rectC2 = New Rectangle(45, 30, 730, +350 + (Rowscount * 35))
        End If
 
        Dim blackPen As New Pen(Color.Navy, 2)
 
 
        Dim fntWSL As New Font("Khalid Art bold", 15, FontStyle.Underline)
 
 
        Dim fnt As New Font("Arial", 13, FontStyle.Bold)
        Dim fntSe As New Font("Hacen Freehand", 14, FontStyle.Regular)
        Dim fntSe2 As New Font("Hacen Freehand", 12, FontStyle.Regular)
        Dim fnt2 As New Font("Hacen Promoter Md", 24, FontStyle.Regular)
        Dim fntRES As New Font("Fanan", 14, FontStyle.Regular)
        Dim fnt4 As New Font("Tahoma", 13, FontStyle.Regular)
 
        Dim stringss As New StringFormat
        stringss.Alignment = StringAlignment.Center
        Dim stringsL As New StringFormat
        stringsL.Alignment = StringAlignment.Far
        Dim stringsN As New StringFormat
        stringsN.Alignment = StringAlignment.Near
 
        If nPageNo = 1 Then
 
            oColumnLefts.Clear()
            oColumnWidths.Clear()
            oColumnTypes.Clear()
 
 For Each oColumn As DataGridViewColumn In DataGridViewToPrint.Columns

                If oColumn.Visible = True Then
                    nWidth = CType(Math.Floor(oColumn.Width / nTotalWidth * nTotalWidth * (e.MarginBounds.Width / nTotalWidth) - 10), Int16) ' -10  decrease table width
 
                    nHeight = e.Graphics.MeasureString(oColumn.HeaderText, oColumn.InheritedStyle.Font, nWidth).Height + 15 'row height
 
                    oColumnLefts.Add(8 + nLeft) 'set table in the center of rectangle
                    oColumnWidths.Add(nWidth)
                    oColumnTypes.Add(oColumn.GetType)
                    nLeft += nWidth
 
                End If
            Next
 
        End If
 
Do While nRowPos < DataGridViewToPrint.Rows.Count
 
            Dim oRow As DataGridViewRow = DataGridViewToPrint.Rows(nRowPos)
 
            If nTop + nHeight >= e.MarginBounds.Height + e.MarginBounds.Top Then
 
                DrawFooter(e, nRowsPerPage)
 
                NewPage = True
                nPageNo += 1
                e.HasMorePages = True
                Exit Sub
 
            Else
 
                If NewPage Then
 
                    Dim point1 As New Point(45, 140)
                    Dim point2 As New Point(775, 140) '
 
                    e.Graphics.DrawRectangle(Pens.Navy, rectC2) ' border column     
                    e.Graphics.DrawLine(blackPen, point1, point2)
 
                    'header
                    e.Graphics.DrawString("اسم الشركة او المكتب", (fnt2), Brushes.Red, e.MarginBounds.Right - 345, e.MarginBounds.Top - e.Graphics.MeasureString(Header, New Font(DataGridViewToPrint.Font, FontStyle.Bold), e.MarginBounds.Width).Height + 30, stringss)
                    e.Graphics.DrawString("نشاط الشركة - وصف الشركة   ", (fntSe), Brushes.Black, e.MarginBounds.Right - 345, e.MarginBounds.Top - e.Graphics.MeasureString(Header, New Font(DataGridViewToPrint.Font, FontStyle.Bold), e.MarginBounds.Width).Height + 70, stringss)
                    e.Graphics.DrawString("  العنوان : المحافظة - المدينة - نقطة دالة " + "     -       " + "هاتف : 07700000000 - 07711111111", (fntSe2), Brushes.Blue, e.MarginBounds.Right - 345, e.MarginBounds.Top - e.Graphics.MeasureString(Header, New Font(DataGridViewToPrint.Font, FontStyle.Bold), e.MarginBounds.Width).Height + 100, stringss)
 
                    'contents
 
    If frm = "Bill" Then

                        e.Graphics.DrawString("وصل بيع نقدي", (fntWSL), Brushes.Black, e.MarginBounds.Right - 345, e.MarginBounds.Top - e.Graphics.MeasureString(Header, New Font(DataGridViewToPrint.Font, FontStyle.Bold), e.MarginBounds.Width).Height + 160, stringss)
 
                        e.Graphics.DrawString("التأريخ :-  " + frmBills.tbDate.Text, (fnt), Brushes.Black, e.MarginBounds.Right - 85, e.MarginBounds.Top - e.Graphics.MeasureString(Header, New Font(DataGridViewToPrint.Font, FontStyle.Bold), e.MarginBounds.Width).Height + 155, stringss)
                        e.Graphics.DrawString("رقم الوصل :-  " + frmBills.tbBillID.Text, (fnt), Brushes.Black, e.MarginBounds.Right - 690, e.MarginBounds.Top - e.Graphics.MeasureString(Header, New Font(DataGridViewToPrint.Font, FontStyle.Bold), e.MarginBounds.Width).Height + 155, stringsN)
                        e.Graphics.DrawString("حضرة السيد / السيدة :- " + frmBills.tbCName.Text, (fntRES), Brushes.Black, e.MarginBounds.Right - 345, e.MarginBounds.Top - e.Graphics.MeasureString(Header, New Font(DataGridViewToPrint.Font, FontStyle.Bold), e.MarginBounds.Width).Height + 210, stringss)
 
                    End If
 
                    If frm = "CashSales" Then
                        e.Graphics.DrawString("وصل بيع نقدي", (fntWSL), Brushes.Black, e.MarginBounds.Right - 345, e.MarginBounds.Top - e.Graphics.MeasureString(Header, New Font(DataGridViewToPrint.Font, FontStyle.Bold), e.MarginBounds.Width).Height + 160, stringss)
 
                        e.Graphics.DrawString("التأريخ :-  " + frmCashSale.BillDate, (fnt), Brushes.Black, e.MarginBounds.Right - 85, e.MarginBounds.Top - e.Graphics.MeasureString(Header, New Font(DataGridViewToPrint.Font, FontStyle.Bold), e.MarginBounds.Width).Height + 155, stringss)
                        e.Graphics.DrawString("رقم الوصل :-  " + frmCashSale.tbBillNo.Text, (fnt), Brushes.Black, e.MarginBounds.Right - 690, e.MarginBounds.Top - e.Graphics.MeasureString(Header, New Font(DataGridViewToPrint.Font, FontStyle.Bold), e.MarginBounds.Width).Height + 155, stringsN)
                        e.Graphics.DrawString("حضرة السيد / السيدة :- " + frmCashSale.tbPurchaserName.Text, (fntRES), Brushes.Black, e.MarginBounds.Right - 345, e.MarginBounds.Top - e.Graphics.MeasureString(Header, New Font(DataGridViewToPrint.Font, FontStyle.Bold), e.MarginBounds.Width).Height + 210, stringss)
 
                    End If
 
                    If frm = "ForwardSales" Then
                        e.Graphics.DrawString("وصل بيع آجل", (fntWSL), Brushes.Black, e.MarginBounds.Right - 345, e.MarginBounds.Top - e.Graphics.MeasureString(Header, New Font(DataGridViewToPrint.Font, FontStyle.Bold), e.MarginBounds.Width).Height + 160, stringss)
 
                        e.Graphics.DrawString("التأريخ :-  " + frmForwardSales.BillDate, (fnt), Brushes.Black, e.MarginBounds.Right - 85, e.MarginBounds.Top - e.Graphics.MeasureString(Header, New Font(DataGridViewToPrint.Font, FontStyle.Bold), e.MarginBounds.Width).Height + 155, stringss)
                        e.Graphics.DrawString("رقم الوصل :-  " + frmForwardSales.tbBillNo.Text, (fnt), Brushes.Black, e.MarginBounds.Right - 690, e.MarginBounds.Top - e.Graphics.MeasureString(Header, New Font(DataGridViewToPrint.Font, FontStyle.Bold), e.MarginBounds.Width).Height + 155, stringsN)
                        e.Graphics.DrawString("حضرة السيد / السيدة :- " + frmForwardSales.tbPurchaserName.Text, (fntRES), Brushes.Black, e.MarginBounds.Right - 345, e.MarginBounds.Top - e.Graphics.MeasureString(Header, New Font(DataGridViewToPrint.Font, FontStyle.Bold), e.MarginBounds.Width).Height + 210, stringss)
 
                    End If
                    If frm = "Forward Bills" Then
                        e.Graphics.DrawString("وصل بيع آجل", (fntWSL), Brushes.Black, e.MarginBounds.Right - 345, e.MarginBounds.Top - e.Graphics.MeasureString(Header, New Font(DataGridViewToPrint.Font, FontStyle.Bold), e.MarginBounds.Width).Height + 160, stringss)
 
 e.Graphics.DrawString("التأريخ :-  " + frmForwardBills.tbDate.Text, (fnt), Brushes.Black, e.MarginBounds.Right - 85, e.MarginBounds.Top - e.Graphics.MeasureString(Header, New Font(DataGridViewToPrint.Font, FontStyle.Bold), e.MarginBounds.Width).Height + 155, stringss)

                        e.Graphics.DrawString("رقم الوصل :-  " + frmForwardBills.tbBillID.Text, (fnt), Brushes.Black, e.MarginBounds.Right - 690, e.MarginBounds.Top - e.Graphics.MeasureString(Header, New Font(DataGridViewToPrint.Font, FontStyle.Bold), e.MarginBounds.Width).Height + 155, stringsN)
                        e.Graphics.DrawString("حضرة السيد / السيدة :- " + frmForwardBills.tbCName.Text, (fntRES), Brushes.Black, e.MarginBounds.Right - 345, e.MarginBounds.Top - e.Graphics.MeasureString(Header, New Font(DataGridViewToPrint.Font, FontStyle.Bold), e.MarginBounds.Width).Height + 210, stringss)
 
                    End If
 
 
 
 
 
                    ' Draw Columns
                    nTop = e.MarginBounds.Top
    i = 0
 
                        For Each oColumn As DataGridViewColumn In DataGridViewToPrint.Columns
                            If oColumn.Visible = True Then
                                e.Graphics.FillRectangle(New SolidBrush(Drawing.Color.LightGray), New Rectangle(oColumnLefts(i) + 23, nTop + 220, oColumnWidths(i), nHeight))
                                e.Graphics.DrawRectangle(Pens.Black, New Rectangle(oColumnLefts(i) + 23, nTop + 220, oColumnWidths(i), nHeight))
                                e.Graphics.DrawString(oColumn.HeaderText, oColumn.InheritedStyle.Font, New SolidBrush(oColumn.InheritedStyle.ForeColor), New RectangleF(oColumnLefts(i) + 23, nTop + 220, oColumnWidths(i), nHeight), oStringFormat)
                                i += 1
                            End If
 
                        Next
 
                        NewPage = False
 
                    End If

 nTop += nHeight
                i = 0
                'draw cells
                For Each oCell As DataGridViewCell In oRow.Cells
                    If oCell.Visible = True Then
                        If oColumnTypes(i) Is GetType(DataGridViewTextBoxColumn) OrElse oColumnTypes(i) Is GetType(DataGridViewLinkColumn) Then
                            If oCell.Value.ToString = Nothing Then
                                e.Graphics.DrawString(" ", oCell.InheritedStyle.Font, New SolidBrush(oCell.InheritedStyle.ForeColor), New RectangleF(oColumnLefts(i) + 23, nTop + 220, oColumnWidths(i), nHeight), oStringFormat)
 
                            Else
                                e.Graphics.DrawString(oCell.Value.ToString, oCell.InheritedStyle.Font, New SolidBrush(oCell.InheritedStyle.ForeColor), New RectangleF(oColumnLefts(i) + 23, nTop + 220, oColumnWidths(i), nHeight), oStringFormat)
 
                            End If
 
                        ElseIf oColumnTypes(i) Is GetType(DataGridViewButtonColumn) Then
 
                            oButton.Text = oCell.Value.ToString
                            oButton.Size = New Size(oColumnWidths(i), nHeight)
                            Dim oBitmap As New Bitmap(oButton.Width, oButton.Height)
                            oButton.DrawToBitmap(oBitmap, New Rectangle(0, 0, oBitmap.Width, oBitmap.Height))
                            e.Graphics.DrawImage(oBitmap, New Point(oColumnLefts(i), nTop))
 
                        ElseIf oColumnTypes(i) Is GetType(DataGridViewCheckBoxColumn) Then
 
                            oCheckbox.Size = New Size(14, 14)
                            oCheckbox.Checked = CType(oCell.Value, Boolean)
                            Dim oBitmap As New Bitmap(oColumnWidths(i), nHeight)
                            Dim oTempGraphics As Graphics = Graphics.FromImage(oBitmap)
                            oTempGraphics.FillRectangle(Brushes.White, New Rectangle(0, 0, oBitmap.Width, oBitmap.Height))
                            oCheckbox.DrawToBitmap(oBitmap, New Rectangle(CType((oBitmap.Width - oCheckbox.Width) / 2, Int32), CType((oBitmap.Height - oCheckbox.Height) / 2, Int32), oCheckbox.Width, oCheckbox.Height))
                            e.Graphics.DrawImage(oBitmap, New Point(oColumnLefts(i), nTop))
 
                        ElseIf oColumnTypes(i) Is GetType(DataGridViewComboBoxColumn) Then
 
                            oComboBox.Size = New Size(oColumnWidths(i), nHeight)
                            Dim oBitmap As New Bitmap(oComboBox.Width, oComboBox.Height)
                            oComboBox.DrawToBitmap(oBitmap, New Rectangle(0, 0, oBitmap.Width, oBitmap.Height))
                            e.Graphics.DrawImage(oBitmap, New Point(oColumnLefts(i), nTop))
                            e.Graphics.DrawString(oCell.Value.ToString, oCell.InheritedStyle.Font, New SolidBrush(oCell.InheritedStyle.ForeColor), New RectangleF(oColumnLefts(i) + 1, nTop, oColumnWidths(i) - 16, nHeight), oStringFormatComboBox)
 
                        ElseIf oColumnTypes(i) Is GetType(DataGridViewImageColumn) Then
 
                            Dim oCellSize As Rectangle = New Rectangle(oColumnLefts(i), nTop, oColumnWidths(i), nHeight)
                            Dim oImageSize As Size = CType(oCell.Value, Image).Size
                            e.Graphics.DrawImage(oCell.Value, New Rectangle(oColumnLefts(i) + CType(((oCellSize.Width - oImageSize.Width) / 2), Int32), nTop + CType(((oCellSize.Height - oImageSize.Height) / 2), Int32), CType(oCell.Value, Image).Width, CType(oCell.Value, Image).Height))
 
                        End If
 
                        e.Graphics.DrawRectangle(Pens.Black, New Rectangle(oColumnLefts(i) + 23, nTop + 220, oColumnWidths(i), nHeight))
 
                        i += 1
 
                    End If
                Next
 
   'bottom
                'e.Graphics.DrawLine(blackPen, point1, point2)
 


                If frm = "ForwardSales" Then
                    e.Graphics.DrawString("المبلغ المسدد بالدينار  ", (fnt), Brushes.Black, e.MarginBounds.Right - 90, e.MarginBounds.Top - e.Graphics.MeasureString(Header, New Font(DataGridViewToPrint.Font, FontStyle.Bold), e.MarginBounds.Width).Height + 302 + Rowscount * 45, stringss)
                    e.Graphics.DrawString(" " + frmForwardSales.tbAmountPaid.Text, (fnt), Brushes.Green, e.MarginBounds.Right - 215, e.MarginBounds.Top - e.Graphics.MeasureString(Header, New Font(DataGridViewToPrint.Font, FontStyle.Bold), e.MarginBounds.Width).Height + 302 + Rowscount * 45, stringss)
                    e.Graphics.DrawString("دينار  ", (fnt), Brushes.Black, e.MarginBounds.Right - 295, e.MarginBounds.Top - e.Graphics.MeasureString(Header, New Font(DataGridViewToPrint.Font, FontStyle.Bold), e.MarginBounds.Width).Height + 303 + Rowscount * 45, stringss)
 
 
                    e.Graphics.DrawString("المبلغ المتبقي بالدينار  ", (fnt), Brushes.Black, e.MarginBounds.Right - 420, e.MarginBounds.Top - e.Graphics.MeasureString(Header, New Font(DataGridViewToPrint.Font, FontStyle.Bold), e.MarginBounds.Width).Height + 302 + Rowscount * 45, stringss)
                    e.Graphics.DrawString(" " + frmForwardSales.lbRemainingAmount.Text, (fnt), Brushes.Red, e.MarginBounds.Right - 550, e.MarginBounds.Top - e.Graphics.MeasureString(Header, New Font(DataGridViewToPrint.Font, FontStyle.Bold), e.MarginBounds.Width).Height + 302 + Rowscount * 45, stringss)
                    e.Graphics.DrawString("دينار  ", (fnt), Brushes.Black, e.MarginBounds.Right - 630, e.MarginBounds.Top - e.Graphics.MeasureString(Header, New Font(DataGridViewToPrint.Font, FontStyle.Bold), e.MarginBounds.Width).Height + 303 + Rowscount * 45, stringss)
 
                    If frmForwardSales.cbNotifications.Checked = True Then
                        e.Graphics.DrawString("على ان يتم السداد في تأريخ : " + frmForwardSales.BillPaymentDate, (fnt), Brushes.Red, e.MarginBounds.Right - 340, e.MarginBounds.Top - e.Graphics.MeasureString(Header, New Font(DataGridViewToPrint.Font, FontStyle.Bold), e.MarginBounds.Width).Height + 342 + Rowscount * 45, stringss)
 
                    End If
                    e.Graphics.DrawString(المشتري", (fntRES), Brushes.Black, e.MarginBounds.Right - 110, e.MarginBounds.Top - e.Graphics.MeasureString(Header, New Font(DataGridViewToPrint.Font, FontStyle.Bold), e.MarginBounds.Width).Height + 345 + Rowscount * 60, stringss)
                    e.Graphics.DrawString(الموظف", (fntRES), Brushes.Black, e.MarginBounds.Right - 345, e.MarginBounds.Top - e.Graphics.MeasureString(Header, New Font(DataGridViewToPrint.Font, FontStyle.Bold), e.MarginBounds.Width).Height + 345 + Rowscount * 60, stringss)
                    e.Graphics.DrawString("الختم", (fntRES), Brushes.Black, e.MarginBounds.Right - 600, e.MarginBounds.Top - e.Graphics.MeasureString(Header, New Font(DataGridViewToPrint.Font, FontStyle.Bold), e.MarginBounds.Width).Height + 345 + Rowscount * 60, stringss)
 
 
                Else
                    e.Graphics.DrawString(المشتري", (fntRES), Brushes.Black, e.MarginBounds.Right - 110, e.MarginBounds.Top - e.Graphics.MeasureString(Header, New Font(DataGridViewToPrint.Font, FontStyle.Bold), e.MarginBounds.Width).Height + 345 + Rowscount * 35, stringss)
                    e.Graphics.DrawString(الموظف", (fntRES), Brushes.Black, e.MarginBounds.Right - 345, e.MarginBounds.Top - e.Graphics.MeasureString(Header, New Font(DataGridViewToPrint.Font, FontStyle.Bold), e.MarginBounds.Width).Height + 345 + Rowscount * 35, stringss)
                    e.Graphics.DrawString("الختم", (fntRES), Brushes.Black, e.MarginBounds.Right - 600, e.MarginBounds.Top - e.Graphics.MeasureString(Header, New Font(DataGridViewToPrint.Font, FontStyle.Bold), e.MarginBounds.Width).Height + 345 + Rowscount * 35, stringss)
 
                End If
 
            End If
 
            nRowPos += 1
            nRowsPerPage += 1
 
        Loop
 
        DrawFooter(e, nRowsPerPage)
 
        e.HasMorePages = False
 
    End Sub
 
 
 
Public Sub DrawFooter(ByVal e As System.Drawing.Printing.PrintPageEventArgs, ByVal RowsPerPage As Int32)
 
        Dim sPageNo As String = nPageNo.ToString + " of "
 
        If nPageNo = "1" Then
 
            lPageNo = Math.Ceiling((DataGridViewToPrint.Rows.Count - 1) / RowsPerPage).ToString()
            sPageNo = nPageNo.ToString + " of " + lPageNo
 
        Else
 
            sPageNo = nPageNo.ToString + " of " + lPageNo
 
        End If
 
    End Sub
 
End Module




ثالثاً: زر الطباعة btnPrint داخل dgvTotal.

يتم اضافة كود الطباعة الى حدث dgvTotal_CellClick اسفل كود عرض معلومات الوصل داخل الادوات وكود الجدذف بالشكل وحسب الكود التالي :- 

Private Sub dgvTotal_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgvTotal.CellClick

        Dim pos As Integer = dgvTotal.CurrentRow.Index

        tbBillID.Text = dgvTotal.Rows(pos).Cells("Bill_ID").Value.ToString

        tbCName.Text = dgvTotal.Rows(pos).Cells("Customer_Name").Value.ToString

        tbDate.Text = dgvTotal.Rows(pos).Cells("Bill_Date").Value

 

        If e.ColumnIndex = 4 Then 'كود الحذف

            If MsgBox("هل تريد حذف الصف الحالي؟", MsgBoxStyle.Question + vbYesNo, Title:="تحذير") = vbYes Then

                Dim cr = dgvTotal.CurrentRow.Index

                Dim IDpos As Integer = dgvTotal.Rows(cr).Cells("Bill_ID").Value

 

                Dim cmd As New OleDbCommand("Delete from tblBills where Bill_ID =" & IDpos, con)

                con.Open()

                cmd.ExecuteNonQuery()

                con.Close()

                MsgBox("تم الحذف بنجاح", vbMsgBoxRight + MsgBoxStyle.Information, "جاري الحذف")

 

                Load_Bills()

            End If

        End If

 

        If e.ColumnIndex = 5 Then 'كود الطباعة

            Dim daBD As New OleDbDataAdapter("SELECT tblBills.Total , tblBills.Unit_Price, tblBills.Units,  tblBills.Item_Name 

FROM tblBills Where Bill_ID=" & tbBillID.Text, con)

            Dim dtBD As New DataTable

            dtBD.Clear()

            daBD.Fill(dtBD)

            dgvBillInfo.DataSource = dtBD

 

            dgvBillInfo.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter

            dgvBillInfo.Columns(3).HeaderText = "اسم المنتح"

            dgvBillInfo.Columns(3).Width = 150

            dgvBillInfo.Columns(3).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter

 

            dgvBillInfo.Columns(2).HeaderText = "الوحدات"

            dgvBillInfo.Columns(2).Width = 80

            dgvBillInfo.Columns(2).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter

 

            dgvBillInfo.Columns(1).Width = 80

            dgvBillInfo.Columns(1).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter

            dgvBillInfo.Columns(1).HeaderText = "سعر الوحد"

 

            dgvBillInfo.Columns(0).HeaderText = "الأجمالي"

            dgvBillInfo.Columns(0).Width = 100

            dgvBillInfo.Columns(0).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter

            frm = "Bill"

            DataGridViewPrinter1.StartPrint(dgvBillInfo, False, True, " ", " ")

        End If

 

    End Sub



لتحميل الأكواد المستخدمة في الدرس إضغط هنا 

يمكنكم متابعة الدرس عن طريق اليوتيوب





دروس قد تهمك

شرح عرض فواتير- برنامج ادارة المطاعم https://youtu.be/pvGbqhxwo5o
عرض الفواتير حسب رقم الفاتورة،تأريخ معين،بين تأريخين - برنامج ادارة المطاعم https://youtu.be/Gnbveum_erI عرض الفواتير الشهر,فواتير الخصم وبدون خصم - برنامج ادارة المطاعم https://youtu.be/8d2_ea8CRgk عرض الفواتير اليوم , الأمس والأسبوع - برنامج ادارة المطاعم https://youtu.be/_GkYftUyJgU

قوائم تشغيل قد تهمك 🎬 برنامج إدارة المطاعم - Vb.net and MS Access https://youtube.com/playlist?list=PLJ_b4a1hzeO_8w9hKbLq_FvhYquVLynqk دورة مايكروسوفت اكسس Microsoft Access https://www.youtube.com/playlist?list=PLJ_b4a1hzeO8kBfZzpjYGVB-i1dgrGyWW دورة ربط الفيجوال بيسك بقواعد البيانات (SQL Server - Access) https://www.youtube.com/playlist?list=PLJ_b4a1hzeO9-R7JTfRFsmHXaWhWaXTVP دورة تعلم الفيحوال بيسك (vb.net) https://www.youtube.com/playlist?list=PLJ_b4a1hzeO_qAeBJbFZlTWwLhqqpIMXk

للتواصل https://www.facebook.com/Info.AliAlhadithy #المبيعات #المدينون #مبيعات_غير_نقدية #مبيعات_آجلة #مبيعات_نقدية #حساب_المبيعات #فاتورة_ييع


تعليقات

المشاركات الشائعة من هذه المدونة

برنامج إدارة المطاعم - الدرس الثالث والعشرون والأخير: برمجة صلاحيات المستخدمين

برنامج إدارة المبيعات - الدرس الأول :- صفحة الموجودات - الجزء 1 - إنشاء جدول الموجوادت وعرضه بالفيجوال بيسك

دورة Microsoft Access - الدرس الثامن: انشاء وتوزيع صلاحيات التحكم للمستخدمين :