Imports System.Text
Imports System.Drawing.Printing
Imports System.Windows.Forms
Imports System.Collections.Generic
Imports System.Drawing
Imports FirebirdSql.Data.FirebirdClient
Imports Microsoft.Reporting.WinForms
Imports IO = System.IO
Imports System.Globalization
Public Class Print_Invoice_From_User_Setting
'------------Print Preview Variables--------------
Dim HX As Integer = 0
Dim HY As Integer = 0
Dim lblPageOfTotal As New ToolStripLabel
Dim dicPrevGroupingColumns As New Dictionary(Of String, String)
Dim dicPrevGroupingDetailColumns As New Dictionary(Of String, String)
Dim dicPrevHeaderColumnsValue As New Dictionary(Of String, String)
Dim dicSumOfHeaderColumns As New Dictionary(Of String, Decimal)
Dim dicSumOfDetailColumns As New Dictionary(Of String, Decimal)
Dim dicSumOfGroupColumns As New Dictionary(Of String, Decimal)
Dim dicSumOfOverAllDetailColumns As New Dictionary(Of String, Decimal)
Dim dicSumOfOverAllHeaderColumns As New Dictionary(Of String, Decimal)
Dim nMax_Width As Double = 0
Dim nMax_Height As Double = 0
'Dim dicPrevGroupingDetailColumns As New Dictionary(Of String, String)
Dim nGap As Integer = 1
Dim nLineGap As Integer = 2
Dim strEmail_Ids As String = ""
Private WithEvents PrintDoc As New System.Drawing.Printing.PrintDocument ' PrintDocumnet Object used for printing
Dim Is_Exit_On As Boolean = False
Dim nSheets As Integer = 0
'System.Drawing.Printing.PrintPageEventArgs
Dim objects As System.Drawing.Printing.PrintPageEventArgs
Dim nHeaderHeight As Integer = 0
Dim nFooterHeight As Integer = 0
Dim nFooter_RTF_Height As Integer = 0
Dim dr As DataRow()
Dim nPrinted_Rows As Integer = 0
Dim ppc As New System.Drawing.Printing.PreviewPrintController()
Dim Is_Print_Summary As Boolean = False
Dim Is_Print_Grand_Total As Boolean = False
Private Shared StrFormat As StringFormat
Private Shared StrVariableFormat As StringFormat
Private Shared StrLeftCenterAlignment As StringFormat
Private Shared StrCenterAlignment As StringFormat
Private Shared numFormat As StringFormat
Private Shared numFormatNoDecimal As StringFormat
Private Shared printFont As Font
Private Shared printFontHeaderFooter As Font
Private Shared printFontDetail As Font
Private Shared printFontHeaderFooterDetail As Font
Dim Is_Print_Preview As Boolean = False
Dim Has_Print As Boolean = False
Dim CInfo As CultureInfo
Private strFormName As String = ""
Private ppvw As PrintPreviewDialog
Dim nEdit_Id_Value As Long
Private Shared NewPage As Boolean ' Indicates if a new page reached
Private Shared PageNo As Int16 ' Number of pages to print
Private Shared nPageNo As Int16 = 0
Private Shared nRows As Integer = 0
Private Shared nRowsChild As Integer = 0
Private Shared nChildItems As Integer = 0
Private Shared nCurrent_Copy As Byte = 0
Private Shared Has_Child_Item As Boolean = False
Private Shared Has_More_Child_Item As Boolean = False
Private Shared nResetChildiLoop As Integer = 0
Private Shared nDetailHeaderRepeat_Start As Integer = 0
Private Shared nResetiLoop As Integer = 0
Private Shared Is_Continue_Same_Item As Boolean = False
Private Shared nColCountChild As Integer = 0
Private Shared nColCount As Integer = 0
Private nHeader_Serial_No As Integer = 0
Private nGroup_Serial_No As Integer = 0
Private nDetail_Group_Serial_No As Integer = 0
Private nDetail_Serial_No As Integer = 0
Dim img1 As Bitmap = Nothing
Dim img2 As Bitmap = Nothing
Dim Header_Position As Integer = 0
Dim Footer_Position As Integer = 0
Dim Is_DetailHeader_Caption_To_Repeat As Boolean = False
Dim lPageHeight As Integer = 0
Dim lPageWidth As Integer = 0
Dim Type_Of_Pages As New List(Of String)
Dim leftMargin As Single = 0
Dim topMargin As Single = 0
Dim nPrev_Right_Margin As Single = 0
Dim nPrev_Bottom_Margin As Single = 0
Dim isPageNoFormat_Set As Boolean = True
Dim Is_Closed_From_TextBox As Boolean = False
Dim nPFSLeft_Margin As Integer = 0
Dim nPFSRight_Margin As Integer = 0
Dim nPFSTop_Margin As Integer = 0
Dim nPFSBottom_Margin As Integer = 0
Dim nPFSPage_Width As Integer = 0
Dim nPFSPage_Height As Integer = 0
Dim nPFSCopy_In_One_Page As Integer = 0
Dim nPFSEach_Page_Width As Integer = 0
Dim nPFSEach_Page_Height As Integer = 0
Dim nPFSPage_No_Format As Integer = -1
Dim Is_Horizontal_Grid_Line As Boolean = False
Dim Is_Vertical_Grid_Line As Boolean = False
Dim nPFSPage_No_Alignment As Integer = -1
Dim strContinuation_Caption As String = "Continue..."
Dim strContinuation_Caption_Next_Page As String = "Continue..."
Dim strForm_Caption As String = ""
Dim xColor As New ColorConverter
Dim xFont As New FontConverter
Dim Is_preview As Boolean = False
Dim Is_mdiform_Closing As Boolean = False
Dim Is_Print_Given As Boolean = False
'---------------Data Variables--------------
Dim dicData_Format As Dictionary(Of String, String)
Dim dicHeader_Sum As Dictionary(Of String, Boolean)
Dim dicHeader_Count As Dictionary(Of String, Boolean)
Dim dicHeader_Grouping As Dictionary(Of String, Boolean)
Dim dicHeader_Width As Dictionary(Of String, Integer)
Dim dicPrint_Options As New Dictionary(Of String, Boolean)
Dim strFrom_Date As String = ""
Dim strTo_Date As String = ""
Dim dicData_Type As Dictionary(Of String, String)
Dim dicDetail_Sum As Dictionary(Of String, Boolean)
Dim dicDetail_Count As Dictionary(Of String, Boolean)
Dim dicDetail_Grouping As Dictionary(Of String, Boolean)
Dim dicDetail_Width As Dictionary(Of String, Integer)
Dim dicDecimal_Place As Dictionary(Of String, String)
Dim dicSummary_Captions As New Dictionary(Of String, String)
Dim dicGroup_Serial_No_Reset_Columns As New Dictionary(Of String, String)
Dim dicColumn_Captions As New Dictionary(Of String, String)
Dim dicMerge_Columns As New Dictionary(Of String, String)
Dim strBook_Type_As_Register_Type As String = """"
Dim dsHeader As DataSet
Dim strRegister_Heading As String = ""
Dim strHeader_Detail_Or_Both As String = ""
Dim Is_Detail_Start As Boolean = False
Dim Is_Group_Serial_No_On_Single_Columns As Boolean = False
Dim dtrPrint_Setting As DataRow
Dim dPrint_Setting_Detail As DataSet
Dim dsInvoice_Print_Data As DataSet
Dim Is_Full_Page_Print As Boolean = False
Public Sub New(ByVal drPrint_Setting_Header As DataRow, ByVal dsPrint_Setting_Detail As DataSet, ByVal dsInvoice_Data As DataSet, ByVal Print_Copy As List(Of String), ByVal Register_Heading As String, ByVal Print_Options As Dictionary(Of String, Boolean), ByVal From_Date As String, ByVal To_Date As String, ByVal dsHeader_Data_Set As DataSet, ByVal Header_Detail_Or_Both As String, ByVal dicHeader_Fields_Width As Dictionary(Of String, Integer), ByVal dicDetail_Fields_Width As Dictionary(Of String, Integer), ByVal dicFormat_Fields As Dictionary(Of String, String), ByVal dicData_Field_Type As Dictionary(Of String, String), ByVal dicHeader_Sum_Fields As Dictionary(Of String, Boolean), ByVal dicDetail_Sum_Fields As Dictionary(Of String, Boolean), ByVal dicHeader_Count_Fields As Dictionary(Of String, Boolean), ByVal dicDetail_Count_Fields As Dictionary(Of String, Boolean), ByVal dicHeader_Grouping_Fields As Dictionary(Of String, Boolean), ByVal dicDetail_Grouping_Fields As Dictionary(Of String, Boolean), ByVal Book_Type_As_Register_Type As String, ByVal Mdi_Form As Form, ByVal Edit_id_Value As Long, ByVal nPageWidth As Integer, ByVal dicDecimal_Places As Dictionary(Of String, String), Optional ByVal dicSummary_Caption As Dictionary(Of String, String) = Nothing, Optional ByVal dicGroup_Serial_No_Reset_Column As Dictionary(Of String, String) = Nothing, Optional ByVal dicColumn_Caption As Dictionary(Of String, String) = Nothing, Optional ByVal dicMerge_Column As Dictionary(Of String, String) = Nothing)
dicPrint_Options = Print_Options
dtrPrint_Setting = drPrint_Setting_Header
dPrint_Setting_Detail = dsPrint_Setting_Detail
dsInvoice_Print_Data = dsInvoice_Data
If Not dicSummary_Caption Is Nothing Then
dicSummary_Captions = dicSummary_Caption
End If
If Not dicGroup_Serial_No_Reset_Column Is Nothing Then
dicGroup_Serial_No_Reset_Columns = dicGroup_Serial_No_Reset_Column
End If
If Not dicColumn_Caption Is Nothing Then
dicColumn_Captions = dicColumn_Caption
End If
If Not dicMerge_Column Is Nothing Then
dicMerge_Columns = dicMerge_Column
End If
strFrom_Date = From_Date
strTo_Date = To_Date
strRegister_Heading = Register_Heading
dsHeader = dsHeader_Data_Set
strHeader_Detail_Or_Both = Header_Detail_Or_Both
dicData_Format = dicFormat_Fields
dicHeader_Sum = dicHeader_Sum_Fields
dicHeader_Count = dicHeader_Count_Fields
dicHeader_Grouping = dicHeader_Grouping_Fields
dicHeader_Width = dicHeader_Fields_Width
dicDecimal_Place = dicDecimal_Places
dicData_Type = dicData_Field_Type
dicDetail_Sum = dicDetail_Sum_Fields
dicDetail_Count = dicDetail_Count_Fields
dicDetail_Grouping = dicDetail_Grouping_Fields
dicDetail_Width = dicDetail_Fields_Width
If drPrint_Setting_Header("HEADING_FONT") & "" <> "" Then
printFontHeaderFooter = xFont.ConvertFromString(drPrint_Setting_Header("HEADING_FONT"))
printFontHeaderFooterDetail = New Font(printFontHeaderFooter.Name, printFontHeaderFooter.Size - 1, FontStyle.Bold Or FontStyle.Italic)
Else
printFontHeaderFooter = New Font("Verdana", 9, FontStyle.Bold)
printFontHeaderFooterDetail = New Font("Verdana", 8, FontStyle.Bold Or FontStyle.Italic)
End If
If drPrint_Setting_Header("DATA_FONT") & "" <> "" Then
printFont = xFont.ConvertFromString(drPrint_Setting_Header("DATA_FONT"))
printFontDetail = New Font(printFont.Name, printFont.Size - 1, FontStyle.Italic)
Else
printFont = New Font("Verdana", 9, FontStyle.Regular)
printFontDetail = New Font("Verdana", 8, FontStyle.Italic)
End If
strBook_Type_As_Register_Type = Book_Type_As_Register_Type
CInfo = New CultureInfo("hi-IN")
If strBook_Type_As_Register_Type = "S" Then
Type_Of_Pages = Print_Copy
End If
Header_Position = 1 '0-In All Page,1-First Page Only
Footer_Position = 0 '0-In All Page,1-Last Page Only
Is_DetailHeader_Caption_To_Repeat = False
'PrintDoc.OriginAtMargins = False
ppvw = New PrintPreviewDialog
ppvw.Document = PrintDoc 'PreparePrintDocument()
ppvw.WindowState = FormWindowState.Maximized
ppvw.PrintPreviewControl.Zoom = 1.0
ppvw.KeyPreview = True
ppvw.ControlBox = False
'ppvw.MinimizeBox = False
ppvw.AutoScroll = True
AddHandler ppvw.KeyPress, AddressOf CloseOnEscapeKeyPress
AddHandler ppvw.KeyUp, AddressOf CloseOnEscape
AddHandler ppvw.FormClosed, AddressOf FormClosed
AddHandler ppvw.FormClosing, AddressOf ForClosing
AddHandler ppvw.MdiChildActivate, AddressOf MdiChildActivate
If nPFSPage_Height = 0 Then
lPageHeight = 1169
Else
lPageHeight = nPFSPage_Height
End If
If nPageWidth = 0 Then
lPageWidth = 827
Else
lPageWidth = nPageWidth
End If
lPageHeight = drPrint_Setting_Header("PAGE_HEIGHT") * 100
leftMargin = drPrint_Setting_Header("LEFT_MARGIN") * 100
nPFSRight_Margin = drPrint_Setting_Header("RIGHT_MARGIN") * 100
nPFSBottom_Margin = drPrint_Setting_Header("BOTTOM_MARGIN") * 100
topMargin = drPrint_Setting_Header("TOP_MARGIN") * 100
'nPFSLeft_Margin = leftMargin
nPrev_Right_Margin = nPFSRight_Margin
nPrev_Bottom_Margin = nPFSBottom_Margin
nPFSCopy_In_One_Page = drPrint_Setting_Header("COPY_IN_ONE_PAGE")
nPFSEach_Page_Height = drPrint_Setting_Header("EACH_PAGE_HEIGHT")
nPFSEach_Page_Width = drPrint_Setting_Header("EACH_PAGE_WIDTH")
If nPFSEach_Page_Width = 0 Then
nPFSEach_Page_Width = lPageWidth
End If
nPFSTop_Margin = drPrint_Setting_Header("TOP_MARGIN") * 100
nPFSPage_No_Alignment = drPrint_Setting_Header("PAGE_NO_ALIGNMENT")
nPFSPage_No_Format = drPrint_Setting_Header("PAGE_NO_FORMAT")
If drPrint_Setting_Header("HORIZONTAL_GRID_LINES") & "" = "Y" Then
Is_Horizontal_Grid_Line = True
End If
If drPrint_Setting_Header("VERTICAL_GRID_LINES") & "" = "Y" Then
Is_Vertical_Grid_Line = True
End If
If drPrint_Setting_Header("FULL_PAGE_PRINT") = "Y" Then
Is_Full_Page_Print = True
End If
strContinuation_Caption = drPrint_Setting_Header("CONTINUITY_CAPTION")
strContinuation_Caption_Next_Page = drPrint_Setting_Header("CONTINUITY_CAPTION_NEXT_PAGE")
PrintDoc.DefaultPageSettings.Margins.Left = IIf(nPFSLeft_Margin < 25, 25, nPFSLeft_Margin)
PrintDoc.DefaultPageSettings.Margins.Right = IIf(nPFSRight_Margin < 25, 25, nPFSRight_Margin)
PrintDoc.DefaultPageSettings.Margins.Top = IIf(nPFSTop_Margin < 25, 25, nPFSTop_Margin)
PrintDoc.DefaultPageSettings.Margins.Bottom = IIf(nPFSBottom_Margin < 25, 25, nPFSBottom_Margin)
Get_Footer_Height(nFooterHeight, nFooter_RTF_Height, dsInvoice_Print_Data, dsPrint_Setting_Detail)
HX = 0
HY = 0 'CInt(PrintDoc.DefaultPageSettings.HardMarginY)
'Dim HX As Integer = CInt(PrintDoc.DefaultPageSettings.HardMarginX)
'Dim HY As Integer = CInt(PrintDoc.DefaultPageSettings.HardMarginY)
'Dim margins As New Margins(100, 100, 100, 100)
If lPageWidth > lPageHeight Then
ppvw.Document.DefaultPageSettings.Landscape = True
ppvw.Document.DefaultPageSettings.PaperSize = New PaperSize("Test", lPageHeight , lPageWidth, + ppvw.Document.DefaultPageSettings.Margins.Top)
ppvw.Width = lPageWidth '+ leftMargin + nPFSRight_Margin
Else
ppvw.Document.DefaultPageSettings.PaperSize = New PaperSize("Test", lPageWidth, lPageHeight + ppvw.Document.DefaultPageSettings.Margins.Top + ppvw.Document.DefaultPageSettings.Margins.Bottom)
ppvw.Document.DefaultPageSettings.Landscape = False
ppvw.Height = lPageHeight '+ topMargin + nPFSBottom_Margin
ppvw.Width = lPageWidth
End If
'PrintDoc.OriginAtMargins = True
'ppvw.Document.OriginAtMargins = True
Dim ctlToolStrip As Control()
ctlToolStrip = ppvw.Controls.Find("toolStrip1", True)
If ctlToolStrip.Count > 0 Then
Dim tsp As ToolStrip
tsp = DirectCast(ctlToolStrip(0), ToolStrip)
For Each CTL As Control In ppvw.Controls
CTL.BackColor = Color.PowderBlue
Next
For Each tsi As ToolStripItem In tsp.Items
'Clipboard.SetText(tsi.Name)
'MsgBox(tsi.Name)
If tsi.Name.ToLower Like "*print*" Then
ElseIf tsi.Name = "pageToolStripLabel" Then
lblPageOfTotal = tsi
lblPageOfTotal.ForeColor = Color.Red
lblPageOfTotal.Font = New Font("Verdana", 9, FontStyle.Bold Or FontStyle.Italic Or FontStyle.Underline)
'tsi.Text = "Print To &Default Printer"
'tsi.Font = New Font("Verdana", 9, FontStyle.Bold)
'tsi.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText
'tsi.TextImageRelation = TextImageRelation.ImageBeforeText
'tsi.Height = 18
'tsi.Visible = False
ElseIf tsi.Name.ToLower Like "*separa*" Then
tsi.Visible = False
ElseIf tsi.Name.ToLower Like "*close*" Then
tsi.Visible = False
End If
Next
'--------------Default Print-------
Dim btnDefaultPrint As New ToolStripButton
btnDefaultPrint.Text = "Print To &Default Printer"
btnDefaultPrint.Font = New Font("Verdana", 9, FontStyle.Bold)
btnDefaultPrint.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText
btnDefaultPrint.TextImageRelation = TextImageRelation.ImageBeforeText
btnDefaultPrint.Height = 18
btnDefaultPrint.Name = "btnPrintDefault"
AddHandler btnDefaultPrint.Click, AddressOf PRINT_DEFAULT_DOC
tsp.Items.Add(btnDefaultPrint)
'---------Selected Print---------
Dim btnPrint As New ToolStripButton
btnPrint.Text = "&Print"
btnPrint.Font = New Font("Verdana", 9, FontStyle.Bold)
btnPrint.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText
btnPrint.TextImageRelation = TextImageRelation.ImageBeforeText
btnPrint.Height = 18
btnPrint.Name = "btnPrint"
AddHandler btnPrint.Click, AddressOf PRINT_DOC
'------------Close---------------------
Dim btnClose As New ToolStripButton
btnClose.Text = "&Close"
btnClose.Font = New Font("Verdana", 9, FontStyle.Bold)
btnClose.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText
btnClose.TextImageRelation = TextImageRelation.ImageBeforeText
btnClose.Height = 18
btnClose.Name = "btnClose"
AddHandler btnClose.Click, AddressOf CLOSE_DOC
tsp.BackColor = Color.LightYellow
tsp.Items.Add(btnPrint)
tsp.Items.Add(btnClose)
End If
ppvw.Name = "PRINT_REGISTER_" & strBook_Type_As_Register_Type & "."
ppvw.ShowIcon = True
ppvw.Tag = ppvw.Name
ppvw.Text = ppvw.Name
Is_Print_Preview = True
Try
If Is_Print_Preview = False Then
Is_Print_Given = True
PrintDoc.PrintController = New StandardPrintController()
Set_Hard_Print_Margin(True)
PrintDoc.Print()
Else
Is_Print_Given = False
PrintDoc.PrintController = New StandardPrintController()
Set_Hard_Print_Margin(False)
ppvw.Show()
End If
ppvw.MdiParent = Mdi_Form
Catch ex As Exception
MessageBox.Show(ex.Message, "Print", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Try
End Sub
Private Sub PrintDoc_BeginPrint(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintEventArgs) Handles PrintDoc.BeginPrint
Is_Exit_On = False
Dim InMargins As Margins
PrintDoc.DefaultPageSettings.Margins.Left = IIf(nPFSLeft_Margin < 25, 25, nPFSLeft_Margin)
PrintDoc.DefaultPageSettings.Margins.Right = IIf(nPFSRight_Margin < 25, 25, nPFSRight_Margin)
PrintDoc.DefaultPageSettings.Margins.Top = IIf(nPFSTop_Margin < 25, 25, nPFSTop_Margin)
PrintDoc.DefaultPageSettings.Margins.Bottom = IIf(nPFSBottom_Margin < 25, 25, nPFSBottom_Margin)
'PrintDoc.DefaultPageSettings.Margins.Left = nPFSLeft_Margin
'PrintDoc.DefaultPageSettings.Margins.Right = nPFSRight_Margin
'PrintDoc.DefaultPageSettings.Margins.Top = nPFSTop_Margin
'PrintDoc.DefaultPageSettings.Margins.Bottom = nPFSBottom_Margin
InMargins = PrintDoc.DefaultPageSettings.Margins
If PrintDoc.OriginAtMargins Then
If PrintDoc.PrintController.IsPreview Then
PrintDoc.DefaultPageSettings.Margins = New Margins(InMargins.Left + HX, _
InMargins.Right - HX, _
InMargins.Top + HY, _
InMargins.Bottom - HY)
End If
Else
If Not PrintDoc.PrintController.IsPreview Then
PrintDoc.DefaultPageSettings.Margins = New Margins(InMargins.Left - HX, _
InMargins.Right + HX, _
InMargins.Top - HY, _
InMargins.Bottom + HY)
End If
End If
Reset_Print()
End Sub
Private Sub PrintDoc_EndPrint(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintEventArgs) Handles PrintDoc.EndPrint
Try
If Is_mdiform_Closing = True Then
Is_mdiform_Closing = False
Exit Sub
End If
nRows = 0
Has_Print = True
Is_Print_Given = False
Dim mdiParent As Object
Dim nCount As Integer = 0
Dim strName As String = ppvw.Name
mdiParent = ppvw.MdiParent
ppvw.Name = strName
ppvw.Tag = strName
ppvw.Text = strName
mdiParent.imgFormImage.Images.Add(strName, GetFormImage(ppvw))
lblPageOfTotal.Text = "Out Of " & IIf(nPageNo = 0, 1, nPageNo) & " Current Page No. Is"
'objects.Graphics.DrawString("Hello_End", New Font("Verdana", 10, FontStyle.Bold Or FontStyle.Underline, GraphicsUnit.Point), Brushes.Black, leftMargin, 10, StrCenterAlignment)
Catch ex As Exception
Finally
'PrintDoc.OriginAtMargins = True
'ppvw.Document.OriginAtMargins = True
Is_Exit_On = True
End Try
End Sub
Private Sub PrintDoc_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDoc.PrintPage
Dim Is_Print_Summary_Called As Boolean = False
Dim nPerWidth As Integer
Dim nPerHeight As Integer
Dim Is_Merge_Exist As Boolean = False
Dim nMerge_Start_Postition As Integer = 0
Dim nMerge_Text_Height As Integer = 0
Dim nMerge_Width As Integer = 0
Dim nMerge_Height As Integer = 0
Dim strPrev_Merge_Text As String = ""
Dim actual As SizeF = Nothing
Dim actualMerge As SizeF = Nothing
Dim actual1 As SizeF = Nothing
Dim nHeight As Integer = 0
Dim iLoop As Integer = 0
Dim strColumn As String = ""
Dim strColumn1 As String = ""
Dim strFont As String = "Verdana,9pt ,style=Regular"
Dim strColor As String = "-16776961"
Dim nLeft As Integer = 0
Dim nTop As Integer = 0
Dim nWidth As Integer = 0
Dim nTotalWidth As Integer = 0
Dim nTotalHeight As Integer = 0
Dim nPrev_Top As Integer = 0
Dim nNext_Row_Max_Height As Integer = 0
Dim nHeight_Gap As Integer = nPFSTop_Margin
Dim strData As String = ""
Dim strPrevGroup As String = ""
Dim Has_Negative_Value As Boolean = False
Dim nRTF_Footer_Height As Double = 0
Dim nRTF_Header_Height As Double = 0
Dim nHeader_Height As Double = 0
Dim nCustom_Field_Height As Double = 0
Dim nMisc_Charges_Height As Double = 0
'Dim dicPrevGroupingColumns As New Dictionary(Of String, String)
'Dim dicPrevGroupingDetailColumns As New Dictionary(Of String, String)
Dim Is_Print_Group_Header As Boolean = True
Dim nGroup_Height As Integer = 0
Dim nStart_Top As Integer = 0
Dim nEnd_Top As Integer = 0
Dim strGroup_Data As String = ""
Dim Is_Print_Header_Column_Value As Boolean = True
Dim Is_Merge_Line_Print As Boolean = False
Dim Is_To_Go_To_Print_Group_Header As String = "H"
Dim Is_First_Time As Boolean = False
Dim Is_Header_Printed As Boolean = False
'-----------------------------------------------------------------
If leftMargin = 0 Then
leftMargin = e.MarginBounds.Left / 2
End If
Try
nPerWidth = e.PageBounds.Width
nPerHeight = e.PageBounds.Height
e.Graphics.InterpolationMode = Drawing2D.InterpolationMode.Bicubic
If Not dicPrint_Options Is Nothing Then
Print_Company_Name_And_Address(e, nHeight_Gap)
End If
'e.Graphics.DrawString(strRegister_Heading, New Font("Verdana", 10, FontStyle.Bold Or FontStyle.Underline, GraphicsUnit.Point), Brushes.Black, leftMargin, nHeight_Gap, StrFormat)
'actual1 = e.Graphics.MeasureString("Date Range:", printFontHeaderFooter)
'nHeight_Gap = nHeight_Gap + printFontHeaderFooter.Height
'e.Graphics.DrawString("Date Range:", printFontHeaderFooter, Brushes.Black, leftMargin, nHeight_Gap, StrFormat)
'e.Graphics.DrawString(strFrom_Date & " To " & strTo_Date, printFont, Brushes.Black, leftMargin + actual1.Width + 5, nHeight_Gap, StrFormat)
nHeight_Gap = nHeight_Gap + printFontHeaderFooter.Height
If dtrPrint_Setting("IS_HEADER_FORMAT") = "Y" AndAlso dsInvoice_Print_Data.Tables("T_FORMAT").Rows.Count > 0 Then
Print_Header_Footer_RTF_Part(e, dsInvoice_Print_Data.Tables("T_FORMAT").Rows(0), nRTF_Header_Height, nMax_Width, nMax_Height, nHeight_Gap, "H")
End If
Print_Header_Part(e, dsInvoice_Print_Data.Tables("T_Sale_Purchase").Rows(0), nHeader_Height, nHeight_Gap)
If dsInvoice_Print_Data.Tables("TC_CUSTOM_FIELDS").Rows.Count > 0 Then
Print_Custom_Fields_Part(e, dsInvoice_Print_Data.Tables("TC_CUSTOM_FIELDS"), nCustom_Field_Height, nHeight_Gap)
End If
'nCustom_Field_Height+ nRTF_Header_Height + nHeader_Height
topMargin = nHeight_Gap
If Not dicPrevGroupingColumns Is Nothing AndAlso dicPrevGroupingColumns.Count > 0 Then
Is_Print_Group_Header = False
ElseIf Not dicPrevGroupingDetailColumns Is Nothing AndAlso dicPrevGroupingDetailColumns.Count > 0 Then
Is_Print_Group_Header = False
End If
For iLoop = nPrinted_Rows To dsHeader.Tables(0).Rows.Count - 1
'---------Grouping Print Start------------
nGroup_Height = 0
If Is_Detail_Start = True Then
Is_Print_Header_Column_Value = False
End If
If strHeader_Detail_Or_Both = "H" Then
If Page_Break(e, nNext_Row_Max_Height + printFont.Height, nTop, iLoop, nPrev_Top, True, False, False, iLoop, False) = True Then
Is_Print_Group_Header = False
Exit Sub
End If
Print_Group_Header_Part(e, nTop, nGroup_Height, dicPrevGroupingColumns, Is_Print_Group_Header, iLoop, nHeight, nNext_Row_Max_Height)
If Page_Break(e, nNext_Row_Max_Height + printFont.Height, nTop, iLoop, nPrev_Top, True, False, False, iLoop, False) = True Then
Exit Sub
End If
ElseIf strHeader_Detail_Or_Both = "D" Then
If Page_Break(e, nNext_Row_Max_Height + printFont.Height, nTop, iLoop, nPrev_Top, True, False, False, iLoop, False) = True Then
Is_Print_Group_Header = False
Exit Sub
End If
Print_Group_Detail_Part(e, nTop, nGroup_Height, dicPrevGroupingDetailColumns, Is_Print_Group_Header, iLoop, nHeight, nNext_Row_Max_Height)
If Page_Break(e, nNext_Row_Max_Height + printFont.Height, nTop, iLoop, nPrev_Top, True, False, False, iLoop, False) = True Then
Exit Sub
End If
Else
If Page_Break(e, nNext_Row_Max_Height + printFont.Height, nTop, iLoop, nPrev_Top, True, False, False, iLoop, False) = True Then
Is_Print_Group_Header = False
Exit Sub
End If
If Is_Print_Header_Column_Value = False OrElse Is_Detail_Start = True Then
If Not dicPrevHeaderColumnsValue Is Nothing AndAlso dicPrevHeaderColumnsValue.Count > 0 Then
For iCol = 0 To dsHeader.Tables(0).Columns.Count - 1
strColumn = dsHeader.Tables(0).Columns(iCol).ColumnName
If Not dicHeader_Width Is Nothing AndAlso dicHeader_Width.ContainsKey("""" & strColumn & """") Then
strData = dsHeader.Tables(0).Rows(iLoop)(strColumn).ToString & ""
If strData <> dicPrevHeaderColumnsValue("""" & strColumn & """") Then
dicPrevHeaderColumnsValue("""" & strColumn & """") = strData
Is_Print_Header_Column_Value = True
nDetail_Serial_No = 0
If Is_Print_Summary_Called = False Then
nHeader_Serial_No = nHeader_Serial_No + 1
Is_Print_Summary_Called = True
If dicSummary_Captions.ContainsKey("DT") Then
Print_Summary_Part(e, nTop, nGroup_Height, dicSumOfDetailColumns, iLoop, nHeight, nNext_Row_Max_Height, "D", dicSummary_Captions("DT"))
Else
Print_Summary_Part(e, nTop, nGroup_Height, dicSumOfDetailColumns, iLoop, nHeight, nNext_Row_Max_Height, "D", "Total :")
End If
End If
Is_Detail_Start = False
End If
End If
Next
Is_Print_Summary_Called = False
End If
End If
If Is_To_Go_To_Print_Group_Header = "H" Then
Print_Group_Header_Part(e, nTop, nGroup_Height, dicPrevGroupingColumns, Is_Print_Group_Header, iLoop, nHeight, nNext_Row_Max_Height)
ElseIf Is_To_Go_To_Print_Group_Header = "D" Then
Print_Group_Detail_Part(e, nTop, nGroup_Height, dicPrevGroupingDetailColumns, Is_Print_Group_Header, iLoop, nHeight, nNext_Row_Max_Height)
End If
If Page_Break(e, nNext_Row_Max_Height + printFont.Height, nTop, iLoop, nPrev_Top, True, False, False, iLoop, False) = True Then
Exit Sub
End If
End If
If Is_Print_Group_Header = True AndAlso nHeader_Serial_No = 0 Then
nHeader_Serial_No = 0
End If
Is_Print_Group_Header = False
'---------Grouping Print End------------
'If strHeader_Detail_Or_Both = "B" AndAlso Is_Detail_Start = False Then
' nDetail_Serial_No = 0
'End If
If iLoop = nPrinted_Rows OrElse (Is_Print_Header_Column_Value = True AndAlso strHeader_Detail_Or_Both = "B") Then
Is_First_Time = False
For iCol = 0 To dsHeader.Tables(0).Columns.Count - 1
strColumn = dsHeader.Tables(0).Columns(iCol).ColumnName
If Not dicHeader_Width Is Nothing AndAlso dicHeader_Width.ContainsKey("""" & strColumn & """") Then
If dicPrevHeaderColumnsValue.ContainsKey("""" & strColumn & """") = False AndAlso strHeader_Detail_Or_Both = "B" Then
dicPrevHeaderColumnsValue.Add("""" & strColumn & """", dsHeader.Tables(0).Rows(iLoop)(strColumn).ToString & "")
End If
If Is_Detail_Start = False Then
nWidth = dicHeader_Width("""" & strColumn & """")
Else
Continue For
End If
ElseIf Not dicDetail_Width Is Nothing AndAlso dicDetail_Width.ContainsKey("""" & strColumn & """") AndAlso strHeader_Detail_Or_Both = "D" Then
nWidth = dicDetail_Width("""" & strColumn & """")
ElseIf Is_Detail_Start = True AndAlso Not dicDetail_Width Is Nothing AndAlso dicDetail_Width.ContainsKey("""" & strColumn & """") Then
'nWidth = dicDetail_Width("""" & strColumn & """")
Continue For
Else
Continue For
End If
If dicData_Type.ContainsKey("""" & strColumn & """") AndAlso (dicData_Type("""" & strColumn & """").ToLower Like "*varchar*") Then 'OrElse dicData_Type("""" & strColumn & """").ToLower Like "*date*"
StrVariableFormat = StrFormat
Else
StrVariableFormat = numFormat
End If
If dicMerge_Columns.ContainsKey("""" & strColumn & """") Then
Is_Merge_Exist = True
nMerge_Width = nMerge_Width + nWidth
If strPrev_Merge_Text <> "" AndAlso strPrev_Merge_Text <> dicMerge_Columns("""" & strColumn & """") AndAlso dicMerge_Columns.Last.Key <> """" & strColumn & """" Then
actualMerge = e.Graphics.MeasureString(strPrev_Merge_Text, printFontHeaderFooter)
e.Graphics.DrawString(strPrev_Merge_Text, printFontHeaderFooter, Brushes.Black, New RectangleF(nMerge_Start_Postition + leftMargin + (nMerge_Width - nWidth - actualMerge.Width) / 2, topMargin + nTop, nMerge_Width - nWidth, e.MarginBounds.Size.Height), StrFormat)
e.Graphics.DrawLine(Pens.Red, nMerge_Start_Postition + leftMargin, topMargin + nMerge_Height + nGroup_Height, nMerge_Width + nMerge_Start_Postition + leftMargin - nWidth, topMargin + nMerge_Height + nGroup_Height)
strPrev_Merge_Text = ""
nMerge_Start_Postition = nLeft
nMerge_Width = nWidth
ElseIf dicMerge_Columns.Last.Key = """" & strColumn & """" Then
actualMerge = e.Graphics.MeasureString(strPrev_Merge_Text, printFontHeaderFooter)
e.Graphics.DrawString(strPrev_Merge_Text, printFontHeaderFooter, Brushes.Black, New RectangleF(nMerge_Start_Postition + leftMargin + (nMerge_Width - actualMerge.Width) / 2, topMargin + nTop, nMerge_Width, e.MarginBounds.Size.Height), StrFormat)
e.Graphics.DrawLine(Pens.Red, nMerge_Start_Postition + leftMargin, topMargin + nMerge_Height + nGroup_Height, nMerge_Width + nMerge_Start_Postition + leftMargin, topMargin + nMerge_Height + nGroup_Height)
strPrev_Merge_Text = ""
Else
If strPrev_Merge_Text <> dicMerge_Columns("""" & strColumn & """") AndAlso strPrev_Merge_Text = "" AndAlso nMerge_Start_Postition = 0 Then
nMerge_Start_Postition = nLeft
End If
strPrev_Merge_Text = dicMerge_Columns("""" & strColumn & """")
End If
actualMerge = e.Graphics.MeasureString(dicMerge_Columns("""" & strColumn & """"), printFontHeaderFooter)
If actualMerge.Height > nMerge_Text_Height AndAlso nMerge_Text_Height = 0 Then
nMerge_Text_Height = actualMerge.Height
nMerge_Height = nMerge_Text_Height
End If
End If
If dicColumn_Captions.ContainsKey("""" & strColumn & """") Then
actual = e.Graphics.MeasureString(dicColumn_Captions("""" & strColumn & """"), printFontHeaderFooter, New SizeF(nWidth, e.MarginBounds.Size.Height), StrVariableFormat)
Else
actual = e.Graphics.MeasureString(strColumn, printFontHeaderFooter, New SizeF(nWidth, e.MarginBounds.Size.Height), StrVariableFormat)
End If
If actual.Height + nMerge_Text_Height > nHeight Then
nHeight = Math.Round(actual.Height) + nMerge_Text_Height
End If
If strHeader_Detail_Or_Both = "B" Then
e.Graphics.FillRectangle(Brushes.LightGray, New Rectangle(leftMargin + nLeft, topMargin + nTop + 2, nWidth, actual.Height - 3 + nMerge_Text_Height))
End If
'OrElse dicMerge_Columns.ContainsKey("""" & strColumn & """") = False
If dicMerge_Columns.ContainsKey("""" & strColumn & """") = False Then
nMerge_Text_Height = 0
End If
If dicColumn_Captions.ContainsKey("""" & strColumn & """") Then
e.Graphics.DrawString(dicColumn_Captions("""" & strColumn & """"), printFontHeaderFooter, Brushes.Black, New RectangleF(leftMargin + nLeft, topMargin + nTop + nMerge_Text_Height, nWidth, e.MarginBounds.Size.Height), StrVariableFormat)
Else
e.Graphics.DrawString(strColumn, printFontHeaderFooter, Brushes.Black, New RectangleF(leftMargin + nLeft, topMargin + nTop + nMerge_Text_Height, nWidth, e.MarginBounds.Size.Height), StrVariableFormat)
End If
nLeft = nLeft + nWidth
Is_Header_Printed = True
If dsHeader.Tables(0).Rows.Count - 1 > iLoop Then
strData = Get_Formatted_Data(dsHeader.Tables(0).Rows(iLoop + 1)(iCol).ToString & "", strColumn, dicData_Format, dicData_Type, dicDecimal_Place, StrVariableFormat, Has_Negative_Value)
If Is_Detail_Start = True Then
actual = e.Graphics.MeasureString(strData, printFontDetail, New SizeF(nWidth, e.MarginBounds.Size.Height), StrVariableFormat)
Else
actual = e.Graphics.MeasureString(strData, printFont, New SizeF(nWidth, e.MarginBounds.Size.Height), StrVariableFormat)
End If
If actual.Height + nMerge_Text_Height > nNext_Row_Max_Height Then
nNext_Row_Max_Height = Math.Round(actual.Height) + nMerge_Text_Height
End If
End If
'OrElse dicMerge_Columns.ContainsKey("""" & strColumn & """") = False
If strPrev_Merge_Text = "" Then
nMerge_Text_Height = 0
nMerge_Height = 0
End If
Next
'If nLeft = 0 Then
' nHeight = 0
'End If
If Is_Header_Printed = False Then
nHeight = 0
End If
strPrev_Merge_Text = ""
nPrev_Top = nTop
nGroup_Height = 0
nTop = nTop + nHeight
nLeft = 0
If Is_Header_Printed = True Then
e.Graphics.DrawLine(Pens.Red, leftMargin, topMargin + nTop, nPFSEach_Page_Width - nPFSRight_Margin, topMargin + nTop)
End If
'nNext_Row_Max_Height,nTop,iLoop
If Page_Break(e, nNext_Row_Max_Height, nTop, iLoop, nPrev_Top, True, False, False, iLoop, False) = True Then
Exit Sub
End If
'-----Below column header----
End If
'Is_Print_Header_Column_Value = False
If strHeader_Detail_Or_Both = "H" OrElse nHeader_Serial_No = 0 Then
nHeader_Serial_No = nHeader_Serial_No + 1
End If
If strHeader_Detail_Or_Both <> "H" Then
nDetail_Serial_No = nDetail_Serial_No + 1
End If
If iLoop <> nPrinted_Rows Then
nStart_Top = nEnd_Top + nGroup_Height
End If
For iCol = 0 To dsHeader.Tables(0).Columns.Count - 1
strColumn = dsHeader.Tables(0).Columns(iCol).ColumnName
If Not dicHeader_Width Is Nothing AndAlso dicHeader_Width.ContainsKey("""" & strColumn & """") AndAlso Is_Print_Header_Column_Value = True Then
nWidth = dicHeader_Width("""" & strColumn & """")
Is_Detail_Start = False
ElseIf Not dicDetail_Width Is Nothing AndAlso dicDetail_Width.ContainsKey("""" & strColumn & """") AndAlso strHeader_Detail_Or_Both = "D" Then
nWidth = dicDetail_Width("""" & strColumn & """")
ElseIf Not dicDetail_Width Is Nothing AndAlso dicDetail_Width.ContainsKey("""" & strColumn & """") AndAlso strHeader_Detail_Or_Both = "B" Then
If Is_Detail_Start = False Then
nDetail_Serial_No = 1
Is_Detail_Start = True
If iLoop <> nPrinted_Rows Then
nEnd_Top = nStart_Top + nHeight
End If
nPrev_Top = IIf(nTop = 0, nPrev_Top, nTop)
nTop = nTop + nHeight
nTotalHeight = nTop
nHeight = printFont.Height
nHeight = 0
e.Graphics.DrawLine(Pens.Red, leftMargin, topMargin + nTop, nPFSEach_Page_Width - nPFSRight_Margin, topMargin + nTop)
If Page_Break(e, nNext_Row_Max_Height, nTop, iLoop, nPrev_Top, False, True, False, iLoop, True) = True Then
Exit Sub
End If
nLeft = 0
End If
If Is_First_Time = False Then
nLeft = 0
Is_First_Time = True
For nCol = 0 To dsHeader.Tables(0).Columns.Count - 1
strColumn1 = dsHeader.Tables(0).Columns(nCol).ColumnName
If dicData_Type.ContainsKey("""" & strColumn1 & """") AndAlso (dicData_Type("""" & strColumn1 & """").ToLower Like "*varchar*") Then ' OrElse dicData_Type("""" & strColumn1 & """").ToLower Like "*date*"
StrVariableFormat = StrFormat
Else
StrVariableFormat = numFormat
End If
If Is_Detail_Start = True AndAlso Not dicDetail_Width Is Nothing AndAlso dicDetail_Width.ContainsKey("""" & strColumn1 & """") Then
nWidth = dicDetail_Width("""" & strColumn1 & """")
Else
Continue For
End If
If dicColumn_Captions.ContainsKey("""" & strColumn1 & """") Then
actual = e.Graphics.MeasureString(dicColumn_Captions("""" & strColumn1 & """"), printFontHeaderFooterDetail, New SizeF(nWidth, e.MarginBounds.Size.Height), StrVariableFormat)
Else
actual = e.Graphics.MeasureString(strColumn1, printFontHeaderFooterDetail, New SizeF(nWidth, e.MarginBounds.Size.Height), StrVariableFormat)
End If
If actual.Height > nHeight Then
nHeight = Math.Round(actual.Height)
End If
If strHeader_Detail_Or_Both = "B" Then
'e.Graphics.FillRectangle(Brushes.LightYellow, New Rectangle(leftMargin + nLeft, topMargin + nTop + 2, nWidth, actual.Height - 3))
End If
If dicColumn_Captions.ContainsKey("""" & strColumn1 & """") Then
e.Graphics.DrawString(dicColumn_Captions("""" & strColumn1 & """"), printFontHeaderFooterDetail, Brushes.Black, New RectangleF(leftMargin + nLeft, topMargin + nTop, nWidth, e.MarginBounds.Size.Height), StrVariableFormat)
Else
e.Graphics.DrawString(strColumn1, printFontHeaderFooterDetail, Brushes.Black, New RectangleF(leftMargin + nLeft, topMargin + nTop, nWidth, e.MarginBounds.Size.Height), StrVariableFormat)
End If
nLeft = nLeft + nWidth
If dsHeader.Tables(0).Rows.Count - 1 > iLoop Then
'strData = dsHeader.Tables(0).Rows(iLoop + 1)(iCol).ToString & ""
strData = Get_Formatted_Data(dsHeader.Tables(0).Rows(iLoop + 1)(strColumn1).ToString & "", strColumn1, dicData_Format, dicData_Type, dicDecimal_Place, StrVariableFormat, Has_Negative_Value)
If Is_Detail_Start = True Then
actual = e.Graphics.MeasureString(strData, printFontDetail, New SizeF(nWidth, e.MarginBounds.Size.Height), StrVariableFormat)
Else
actual = e.Graphics.MeasureString(strData, printFont, New SizeF(nWidth, e.MarginBounds.Size.Height), StrVariableFormat)
End If
If actual.Height > nNext_Row_Max_Height Then
nNext_Row_Max_Height = Math.Round(actual.Height)
End If
End If
Next
nLeft = 0
If iLoop <> nPrinted_Rows Then
nEnd_Top = nStart_Top + nHeight
End If
nPrev_Top = IIf(nTop = 0, nPrev_Top, nTop)
nTop = nTop + nHeight
nTotalHeight = nTop
nHeight = 0
'-----Below column header----
e.Graphics.DrawLine(Pens.Red, leftMargin, topMargin + nTop, nPFSEach_Page_Width - nPFSRight_Margin, topMargin + nTop)
End If
If Page_Break(e, nNext_Row_Max_Height, nTop, iLoop, nPrev_Top, False, True, False, iLoop, False) = True Then
Exit Sub
End If
nWidth = dicDetail_Width("""" & strColumn & """")
Else
Continue For
End If
If Is_Detail_Start = False Then
If strHeader_Detail_Or_Both = "D" OrElse strHeader_Detail_Or_Both = "H" Then
'----------For Columns Separation Lines----------------
nMerge_Height = 0
If iLoop = nPrinted_Rows Then
If dicMerge_Columns.ContainsKey("""" & strColumn & """") Then
If strPrev_Merge_Text = dicMerge_Columns("""" & strColumn & """") Then
actualMerge = e.Graphics.MeasureString(dicMerge_Columns.ContainsKey("""" & strColumn & """"), printFontHeaderFooter)
nMerge_Height = actualMerge.Height
Else
strPrev_Merge_Text = dicMerge_Columns("""" & strColumn & """")
End If
End If
End If
e.Graphics.DrawLine(Pens.Red, leftMargin + nLeft, topMargin + nPrev_Top + nMerge_Height, leftMargin + nLeft, topMargin + nTop - nGroup_Height)
End If
End If
strData = dsHeader.Tables(0).Rows(iLoop)(iCol).ToString & ""
If strData = "SL#" OrElse strColumn = "SL#" Then
If Is_Detail_Start = True Then
If Not dicDetail_Width Is Nothing AndAlso dicDetail_Width.ContainsKey("""" & strColumn & """") Then
strData = Get_Formatted_Data(nDetail_Serial_No, strColumn, dicData_Format, dicData_Type, dicDecimal_Place, StrVariableFormat, Has_Negative_Value)
If Is_Detail_Start = True Then
actual = e.Graphics.MeasureString(strData, printFontDetail, New SizeF(nWidth, e.MarginBounds.Size.Height), StrVariableFormat)
Else
actual = e.Graphics.MeasureString(strData, printFont, New SizeF(nWidth, e.MarginBounds.Size.Height), StrVariableFormat)
End If
If actual.Height > nHeight Then
nHeight = Math.Round(actual.Height)
End If
e.Graphics.DrawString(strData, printFontDetail, Brushes.Black, New RectangleF(leftMargin + nLeft, topMargin + nTop, nWidth, e.MarginBounds.Size.Height), StrVariableFormat)
End If
Else
If Not dicHeader_Width Is Nothing AndAlso dicHeader_Width.ContainsKey("""" & strColumn & """") Then
strData = Get_Formatted_Data(nHeader_Serial_No, strColumn, dicData_Format, dicData_Type, dicDecimal_Place, StrVariableFormat, Has_Negative_Value)
If Is_Detail_Start = True Then
actual = e.Graphics.MeasureString(strData, printFontDetail, New SizeF(nWidth, e.MarginBounds.Size.Height), StrVariableFormat)
Else
actual = e.Graphics.MeasureString(strData, printFont, New SizeF(nWidth, e.MarginBounds.Size.Height), StrVariableFormat)
End If
If actual.Height > nHeight Then
nHeight = Math.Round(actual.Height)
End If
e.Graphics.DrawString(strData, printFont, Brushes.Black, New RectangleF(leftMargin + nLeft, topMargin + nTop, nWidth, e.MarginBounds.Size.Height), StrVariableFormat)
ElseIf Not dicDetail_Width Is Nothing AndAlso dicDetail_Width.ContainsKey("""" & strColumn & """") Then
strData = Get_Formatted_Data(nDetail_Serial_No, strColumn, dicData_Format, dicData_Type, dicDecimal_Place, StrVariableFormat, Has_Negative_Value)
If Is_Detail_Start = True Then
actual = e.Graphics.MeasureString(strData, printFontDetail, New SizeF(nWidth, e.MarginBounds.Size.Height), StrVariableFormat)
Else
actual = e.Graphics.MeasureString(strData, printFont, New SizeF(nWidth, e.MarginBounds.Size.Height), StrVariableFormat)
End If
If actual.Height > nHeight Then
nHeight = Math.Round(actual.Height)
End If
e.Graphics.DrawString(strData, printFont, Brushes.Black, New RectangleF(leftMargin + nLeft, topMargin + nTop, nWidth, e.MarginBounds.Size.Height), StrVariableFormat)
End If
End If
Else
strData = Get_Formatted_Data(dsHeader.Tables(0).Rows(iLoop)(iCol).ToString & "", strColumn, dicData_Format, dicData_Type, dicDecimal_Place, StrVariableFormat, Has_Negative_Value)
If Is_Detail_Start = True Then
actual = e.Graphics.MeasureString(strData, printFontDetail, New SizeF(nWidth, e.MarginBounds.Size.Height), StrVariableFormat)
Else
actual = e.Graphics.MeasureString(strData, printFont, New SizeF(nWidth, e.MarginBounds.Size.Height), StrVariableFormat)
End If
If actual.Height > nHeight Then
nHeight = Math.Round(actual.Height)
End If
If Is_Detail_Start = True Then
e.Graphics.DrawString(strData, printFontDetail, Brushes.Black, New RectangleF(leftMargin + nLeft, topMargin + nTop, nWidth, e.MarginBounds.Size.Height), StrVariableFormat)
If Not dicDetail_Sum Is Nothing Then
If dicDetail_Sum.ContainsKey("""" & strColumn & """") AndAlso dicDetail_Sum("""" & strColumn & """").ToString = "True" Then
If Has_Negative_Value = True Then
strData = -Convert_Rs_Format_To_Value(strData)
Else
strData = Convert_Rs_Format_To_Value(strData)
End If
If dicSumOfDetailColumns.ContainsKey("""" & strColumn & """") Then
dicSumOfDetailColumns("""" & strColumn & """") = Val(dicSumOfDetailColumns("""" & strColumn & """")) + Val(strData)
dicSumOfOverAllDetailColumns("""" & strColumn & """") = Val(dicSumOfOverAllDetailColumns("""" & strColumn & """")) + Val(strData)
Else
dicSumOfDetailColumns.Add("""" & strColumn & """", Val(strData))
If Not dicSumOfOverAllDetailColumns.ContainsKey("""" & strColumn & """") Then
dicSumOfOverAllDetailColumns.Add("""" & strColumn & """", Val(strData))
Else
dicSumOfOverAllDetailColumns("""" & strColumn & """") = Val(dicSumOfOverAllDetailColumns("""" & strColumn & """")) + Val(strData)
End If
End If
End If
End If
Else
e.Graphics.DrawString(strData, printFont, Brushes.Black, New RectangleF(leftMargin + nLeft, topMargin + nTop, nWidth, e.MarginBounds.Size.Height), StrVariableFormat)
If strHeader_Detail_Or_Both = "D" Then
If dicDetail_Sum.ContainsKey("""" & strColumn & """") AndAlso dicDetail_Sum("""" & strColumn & """").ToString = "True" Then
If Has_Negative_Value = True Then
strData = -Convert_Rs_Format_To_Value(strData)
Else
strData = Convert_Rs_Format_To_Value(strData)
End If
If dicSumOfDetailColumns.ContainsKey("""" & strColumn & """") Then
dicSumOfDetailColumns("""" & strColumn & """") = Val(dicSumOfDetailColumns("""" & strColumn & """")) + Val(strData)
dicSumOfOverAllDetailColumns("""" & strColumn & """") = Val(dicSumOfOverAllDetailColumns("""" & strColumn & """")) + Val(strData)
Else
dicSumOfDetailColumns.Add("""" & strColumn & """", Val(strData))
If Not dicSumOfOverAllDetailColumns.ContainsKey("""" & strColumn & """") Then
dicSumOfOverAllDetailColumns.Add("""" & strColumn & """", Val(strData))
Else
dicSumOfOverAllDetailColumns("""" & strColumn & """") = Val(dicSumOfOverAllDetailColumns("""" & strColumn & """")) + Val(strData)
End If
End If
End If
ElseIf strHeader_Detail_Or_Both = "H" Then
If dicHeader_Sum.ContainsKey("""" & strColumn & """") AndAlso dicHeader_Sum("""" & strColumn & """").ToString = "True" Then
If Has_Negative_Value = True Then
strData = -Convert_Rs_Format_To_Value(strData)
Else
strData = Convert_Rs_Format_To_Value(strData)
End If
If dicSumOfHeaderColumns.ContainsKey("""" & strColumn & """") Then
dicSumOfHeaderColumns("""" & strColumn & """") = Val(dicSumOfHeaderColumns("""" & strColumn & """")) + Val(strData)
dicSumOfOverAllHeaderColumns("""" & strColumn & """") = Val(dicSumOfOverAllHeaderColumns("""" & strColumn & """")) + Val(strData)
Else
dicSumOfHeaderColumns.Add("""" & strColumn & """", Val(strData))
If Not dicSumOfOverAllHeaderColumns.ContainsKey("""" & strColumn & """") Then
dicSumOfOverAllHeaderColumns.Add("""" & strColumn & """", Val(strData))
Else
dicSumOfOverAllHeaderColumns("""" & strColumn & """") = Val(dicSumOfOverAllHeaderColumns("""" & strColumn & """")) + Val(strData)
End If
End If
End If
ElseIf strHeader_Detail_Or_Both = "B" Then
If Not dicHeader_Sum Is Nothing Then
If dicHeader_Sum.ContainsKey("""" & strColumn & """") AndAlso dicHeader_Sum("""" & strColumn & """").ToString = "True" Then
If Has_Negative_Value = True Then
strData = -Convert_Rs_Format_To_Value(strData)
Else
strData = Convert_Rs_Format_To_Value(strData)
End If
If dicSumOfOverAllHeaderColumns.ContainsKey("""" & strColumn & """") Then
dicSumOfOverAllHeaderColumns("""" & strColumn & """") = Val(dicSumOfOverAllHeaderColumns("""" & strColumn & """")) + Val(strData)
Else
dicSumOfOverAllHeaderColumns.Add("""" & strColumn & """", Val(strData))
End If
End If
End If
End If
End If
End If
nLeft = nLeft + nWidth
If dsHeader.Tables(0).Rows.Count - 1 > iLoop Then
'strData = dsHeader.Tables(0).Rows(iLoop + 1)(iCol).ToString & ""
strData = Get_Formatted_Data(dsHeader.Tables(0).Rows(iLoop + 1)(iCol).ToString & "", strColumn, dicData_Format, dicData_Type, dicDecimal_Place, StrVariableFormat, Has_Negative_Value)
If Is_Detail_Start = True Then
actual = e.Graphics.MeasureString(strData, printFontDetail, New SizeF(nWidth, e.MarginBounds.Size.Height), StrVariableFormat)
Else
actual = e.Graphics.MeasureString(strData, printFont, New SizeF(nWidth, e.MarginBounds.Size.Height), StrVariableFormat)
End If
If actual.Height > nNext_Row_Max_Height Then
nNext_Row_Max_Height = Math.Round(actual.Height)
End If
End If
Next
If strHeader_Detail_Or_Both = "B" Then
Is_Print_Header_Column_Value = False
End If
If iLoop <> nPrinted_Rows Then
nEnd_Top = nStart_Top + nHeight
End If
nPrev_Top = IIf(nTop = 0, nPrev_Top, nTop)
nTop = nTop + nHeight
nTotalWidth = nLeft
nTotalHeight = nTop
nHeight = printFont.Height
nLeft = 0
If Page_Break(e, nNext_Row_Max_Height, nTop, iLoop, nPrev_Top, True, False, IIf(iLoop = dsHeader.Tables(0).Rows.Count - 1, True, False), iLoop + 1, False) = True Then
Exit Sub
End If
e.Graphics.DrawLine(Pens.Red, leftMargin + CInt(nMax_Width), topMargin + nTop, nPFSEach_Page_Width - nPFSRight_Margin, topMargin + nTop)
Next
'If topMargin + nTop < lPageHeight - nFooterHeight - nFooter_RTF_Height - nPFSBottom_Margin Then
' 'nTotalHeight = nTotalHeight + (lPageHeight - nFooterHeight - nFooter_RTF_Height - nPFSBottom_Margin - nTotalHeight)
' nTop = topMargin + nTop + (lPageHeight - (nFooterHeight + nFooter_RTF_Height + nPFSBottom_Margin + topMargin + nTop))
' '(nNext_Row_Max_Height + nTop > lPageHeight - topMargin - nFooterHeight - nFooter_RTF_Height - nPFSBottom_Margin)
'End If
If nNext_Row_Max_Height + nTop < lPageHeight - topMargin - nFooterHeight - nFooter_RTF_Height - nPFSBottom_Margin Then
nTop = lPageHeight - topMargin - nFooterHeight - nFooter_RTF_Height - nPFSBottom_Margin - printFontHeaderFooter.Height * 2
nTotalHeight = nTop
End If
If Is_Print_Summary = False AndAlso ((Not dicSumOfDetailColumns Is Nothing AndAlso dicSumOfDetailColumns.Count > 0) OrElse (Not dicSumOfHeaderColumns Is Nothing AndAlso dicSumOfHeaderColumns.Count > 0)) Then
If Page_Break(e, nNext_Row_Max_Height + printFont.Height, nTop, iLoop, nPrev_Top, True, True, False, iLoop, False) = False Then
e.Graphics.DrawLine(Pens.Red, leftMargin, topMargin + nTop, nPFSEach_Page_Width - nPFSRight_Margin, topMargin + nTop)
If strHeader_Detail_Or_Both = "B" OrElse strHeader_Detail_Or_Both = "D" Then
If dicSummary_Captions.ContainsKey("DT") Then
Print_Summary_Part(e, nTop, nTotalHeight, dicSumOfDetailColumns, iLoop, nHeight, nNext_Row_Max_Height, "D", dicSummary_Captions("DT"))
Else
Print_Summary_Part(e, nTop, nTotalHeight, dicSumOfDetailColumns, iLoop, nHeight, nNext_Row_Max_Height, "D", "Total :")
End If
Else
If dicSummary_Captions.ContainsKey("HT") Then
Print_Summary_Part(e, nTop, nTotalHeight, dicSumOfHeaderColumns, iLoop, nHeight, nNext_Row_Max_Height, "H", dicSummary_Captions("HT"))
Else
Print_Summary_Part(e, nTop, nTotalHeight, dicSumOfHeaderColumns, iLoop, nHeight, nNext_Row_Max_Height, "H", "Total :")
End If
End If
e.Graphics.DrawRectangle(Pens.Red, New Rectangle(leftMargin, topMargin, nPFSEach_Page_Width - nPFSRight_Margin - leftMargin, nTotalHeight))
Is_Print_Summary = True
Else
Exit Sub
End If
End If
If Is_Print_Grand_Total = False AndAlso ((Not dicSumOfOverAllDetailColumns Is Nothing AndAlso dicSumOfOverAllDetailColumns.Count > 0) OrElse (Not dicSumOfOverAllHeaderColumns Is Nothing AndAlso dicSumOfOverAllHeaderColumns.Count > 0)) Then
If Page_Break(e, nNext_Row_Max_Height + printFont.Height, nTop, iLoop, nPrev_Top, True, True, False, iLoop, False) = False Then
If strHeader_Detail_Or_Both = "B" Then
If dicSummary_Captions.ContainsKey("GTD") Then
Print_Summary_Part(e, nTop, nTotalHeight, dicSumOfOverAllDetailColumns, iLoop, nHeight, nNext_Row_Max_Height, "GT", dicSummary_Captions("GTD"))
Else
Print_Summary_Part(e, nTop, nTotalHeight, dicSumOfOverAllDetailColumns, iLoop, nHeight, nNext_Row_Max_Height, "GT", "Grand Total(Detail) :")
End If
Is_Print_Grand_Total = True
ElseIf strHeader_Detail_Or_Both = "H" AndAlso Not dicHeader_Grouping Is Nothing AndAlso dicHeader_Grouping.Count > 0 Then
If dicSummary_Captions.ContainsKey("GTH") Then
Print_Summary_Part(e, nTop, nTotalHeight, dicSumOfOverAllHeaderColumns, iLoop, nHeight, nNext_Row_Max_Height, "GT", dicSummary_Captions("GTH"))
Else
Print_Summary_Part(e, nTop, nTotalHeight, dicSumOfOverAllHeaderColumns, iLoop, nHeight, nNext_Row_Max_Height, "GT", "Grand Total :")
End If
ElseIf strHeader_Detail_Or_Both = "D" AndAlso Not dicDetail_Grouping Is Nothing AndAlso dicDetail_Grouping.Count > 0 Then
If dicSummary_Captions.ContainsKey("GDT") Then
Print_Summary_Part(e, nTop, nTotalHeight, dicSumOfOverAllDetailColumns, iLoop, nHeight, nNext_Row_Max_Height, "GT", dicSummary_Captions("GDT"))
Else
Print_Summary_Part(e, nTop, nTotalHeight, dicSumOfOverAllDetailColumns, iLoop, nHeight, nNext_Row_Max_Height, "GT", "Grand Total :")
End If
End If
e.Graphics.DrawRectangle(Pens.Red, New Rectangle(leftMargin, topMargin, nPFSEach_Page_Width - nPFSRight_Margin - leftMargin, nTotalHeight))
Else
'nPrinted_Rows = iLoop
If (Not dicSumOfOverAllDetailColumns Is Nothing AndAlso dicSumOfOverAllDetailColumns.Count > 0) OrElse (Not dicSumOfOverAllHeaderColumns Is Nothing AndAlso dicSumOfOverAllHeaderColumns.Count > 0) Then
Exit Sub
Else
e.HasMorePages = False
End If
End If
End If
If strHeader_Detail_Or_Both = "B" AndAlso (Not dicSumOfOverAllHeaderColumns Is Nothing AndAlso dicSumOfOverAllHeaderColumns.Count > 0) Then
If Page_Break(e, nNext_Row_Max_Height + printFont.Height, nTop, iLoop, nPrev_Top, True, True, False, iLoop, False) = False Then
If dicSummary_Captions.ContainsKey("GHT") Then
Print_Summary_Part(e, nTop, nTotalHeight, dicSumOfOverAllHeaderColumns, iLoop, nHeight, nNext_Row_Max_Height, "GTH", dicSummary_Captions("GHT"))
Else
Print_Summary_Part(e, nTop, nTotalHeight, dicSumOfOverAllHeaderColumns, iLoop, nHeight, nNext_Row_Max_Height, "GTH", "Grand Total(Header) :")
End If
e.Graphics.DrawRectangle(Pens.Red, New Rectangle(leftMargin, topMargin, nPFSEach_Page_Width - nPFSRight_Margin - leftMargin, nTotalHeight))
Else
Exit Sub
End If
End If
nTotalHeight = nTotalHeight + topMargin
If dsInvoice_Print_Data.Tables("TC_CHARGES").Rows.Count > 0 Then
Print_Misc_Charges_Part(e, dsInvoice_Print_Data, nMisc_Charges_Height, nTotalHeight, dtrPrint_Setting)
End If
If dtrPrint_Setting("IS_FOOTER_FORMAT") = "Y" AndAlso dsInvoice_Print_Data.Tables("T_FORMAT").Rows.Count > 0 Then
Print_Header_Footer_RTF_Part(e, dsInvoice_Print_Data.Tables("T_FORMAT").Rows(0), nRTF_Footer_Height, nMax_Width + leftMargin, nMax_Height, nTotalHeight, "F")
End If
Print_Options(e, nTotalHeight - topMargin)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
Private Sub CloseOnEscapeKeyPress(ByVal sender As Object, ByVal e As KeyPressEventArgs)
If Is_Exit_On = True Then
If e.KeyChar = Chr(Keys.Escape) AndAlso Not ppvw Is Nothing Then
If MessageBox.Show("Are you sure to close the print privew window...???", "Print Preview Closing Prompt...!!!", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then
Try
Dim mdiParent As Object
mdiParent = ppvw.MdiParent
ppvw.Close()
If mdiParent.imgFormImage.Images.ContainsKey(ppvw.Name) Then
mdiParent.imgFormImage.Images.RemoveByKey(ppvw.Name)
End If
Catch ex As Exception
End Try
End If
End If
End If
End Sub
Sub CloseOnEscape(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)
If Is_Exit_On = True Then
If e.KeyCode = Keys.Escape And e.Control = False AndAlso e.Alt = False AndAlso e.Shift = False AndAlso Not ppvw Is Nothing Then
If MessageBox.Show("Are you sure to close the print privew window...???", "Print Preview Closing Prompt...!!!", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then
Try
Dim mdiParent As Object
mdiParent = ppvw.MdiParent
ppvw.Close()
If mdiParent.imgFormImage.Images.ContainsKey(ppvw.Name) Then
mdiParent.imgFormImage.Images.RemoveByKey(ppvw.Name)
End If
Catch ex As Exception
End Try
End If
End If
End If
End Sub
Private Sub FormClosed(ByVal sender As Object, ByVal e As FormClosedEventArgs)
Try
Dim mdiParent As Object
mdiParent = ppvw.MdiParent
If mdiParent.imgFormImage.Images.ContainsKey(ppvw.Name) Then
mdiParent.imgFormImage.Images.RemoveByKey(ppvw.Name)
End If
Catch ex As Exception
End Try
End Sub
Private Sub ForClosing(ByVal sender As Object, ByVal e As FormClosingEventArgs)
If e.CloseReason = CloseReason.MdiFormClosing Then
Is_mdiform_Closing = True
Else
Is_mdiform_Closing = False
End If
End Sub
Private Sub MdiChildActivate(ByVal sender As Object, ByVal e As EventArgs)
Try
Dim mdiParent As Object
mdiParent = ppvw.MdiParent
If mdiParent.Images.ContainsKey(ppvw.Name) Then
mdiParent.Images.RemoveByKey(ppvw.Name)
End If
mdiParent.Images.Add(ppvw.Name, GetFormImage(ppvw))
Catch ex As Exception
End Try
If Has_Print = True Then
Exit Sub
End If
End Sub
Private Sub PRINT_DEFAULT_DOC(ByVal sender As Object, ByVal e As EventArgs)
Try
ppvw.Enabled = False
Is_Print_Given = False
PrintDoc.PrintController = New StandardPrintController()
Set_Hard_Print_Margin(True)
PrintDoc.Print()
Catch ex As Exception
Finally
ppvw.Enabled = True
End Try
End Sub
Sub Set_Hard_Print_Margin(ByVal Is_Direct_Print As Boolean)
If Is_Direct_Print = True Then
'leftMargin = nPFSLeft_Margin - 10
'topMargin = nPFSTop_Margin - 10
'nPFSRight_Margin = nPrev_Right_Margin - 10
'nPFSBottom_Margin = nPrev_Bottom_Margin - 10
PrintDoc.OriginAtMargins = False
'ppvw.Document.OriginAtMargins = True
Else
PrintDoc.OriginAtMargins = True
'ppvw.Document.OriginAtMargins = True
'leftMargin = nPFSLeft_Margin + 20
'topMargin = nPFSTop_Margin
'nPFSRight_Margin = nPrev_Right_Margin + 20
'nPFSBottom_Margin = nPrev_Bottom_Margin + 10
End If
End Sub
Private Sub PRINT_DOC(ByVal sender As Object, ByVal e As EventArgs)
Dim xPrintDlg As New PrintDialog
Try
ppvw.Enabled = False
If xPrintDlg.ShowDialog() = DialogResult.OK Then
PrintDoc.PrinterSettings.PrinterName = xPrintDlg.PrinterSettings.PrinterName
Is_Print_Given = False
PrintDoc.PrintController = New StandardPrintController()
Set_Hard_Print_Margin(True)
PrintDoc.Print()
End If
Catch ex As Exception
Finally
ppvw.Enabled = True
End Try
End Sub
Private Sub CLOSE_DOC(ByVal sender As Object, ByVal e As EventArgs)
If Is_Exit_On = True Then
If MsgBox("Are you sure to close the print preview window...???", vbQuestion + vbYesNo, "Print Preview Closing Prompt...!!!") = MsgBoxResult.Yes Then
Try
Dim mdiParent As Object
mdiParent = ppvw.MdiParent
ppvw.Close()
If mdiParent.imgFormImage.Images.ContainsKey(ppvw.Name) Then
mdiParent.imgFormImage.Images.RemoveByKey(ppvw.Name)
End If
Catch ex As Exception
End Try
End If
End If
End Sub
Private Sub Print_Company_Name_And_Address(ByVal e As PrintPageEventArgs, ByRef nHeight_Gap As Integer)
If dicPrint_Options("IS_COMPANY_NAME_PRINT") = True Then
Dim actual1 As SizeF = Nothing
Dim nWidth_Gap As Integer = 50
Dim nPrev_Width As Integer = 0
actual1 = e.Graphics.MeasureString(strCompany_Name, New Font(printFontHeaderFooter.Name, printFontHeaderFooter.Size, FontStyle.Bold Or FontStyle.Underline, GraphicsUnit.Point))
e.Graphics.DrawString(strCompany_Name, New Font(printFontHeaderFooter.Name, printFontHeaderFooter.Size, FontStyle.Bold Or FontStyle.Underline, GraphicsUnit.Point), Brushes.Black, nMax_Width + (nPFSEach_Page_Width - actual1.Width) / 2, nHeight_Gap, StrFormat)
nHeight_Gap = nHeight_Gap + printFontHeaderFooter.Height
If dicPrint_Options("IS_COMPANY_ADDRESS_PRINT") = True Then
If Trim(strCompany_Address1) & Trim(strCompany_Address2) & Trim(strCompany_Address3) <> "" Then
actual1 = e.Graphics.MeasureString(strCompany_Address1 & IIf(strCompany_Address2 = "", "", "," & strCompany_Address2) & IIf(strCompany_Address3 = "", "", "," & strCompany_Address3), printFont)
e.Graphics.DrawString(strCompany_Address1 & IIf(strCompany_Address2 = "", "", "," & strCompany_Address2) & IIf(strCompany_Address3 = "", "", "," & strCompany_Address3), printFont, Brushes.Black, nMax_Width + (nPFSEach_Page_Width - actual1.Width) / 2, nHeight_Gap, StrFormat)
nHeight_Gap = nHeight_Gap + printFont.Height
actual1 = e.Graphics.MeasureString(Trim(strCompany_City) & IIf(Trim(strCompany_State) <> "", IIf(Trim(strCompany_City) = "", "", ",") & Trim(strCompany_State) & IIf(strCompany_Pin_Code <> "", " - " & strCompany_Pin_Code, ""), ""), printFont)
e.Graphics.DrawString(Trim(strCompany_City) & IIf(Trim(strCompany_State) <> "", IIf(Trim(strCompany_City) = "", "", ",") & Trim(strCompany_State) & IIf(strCompany_Pin_Code <> "", " - " & strCompany_Pin_Code, ""), ""), printFont, Brushes.Black, nMax_Width + (nPFSEach_Page_Width - actual1.Width) / 2, nHeight_Gap, StrFormat)
nHeight_Gap = nHeight_Gap + printFont.Height
End If
If Trim(strCompany_Phone) <> "" AndAlso Trim(strCOMPANY_FAX) <> "" Then
actual1 = e.Graphics.MeasureString("Phone:", printFontHeaderFooter)
nWidth_Gap = actual1.Width
actual1 = e.Graphics.MeasureString("Fax:", printFontHeaderFooter)
nWidth_Gap = nWidth_Gap + actual1.Width
actual1 = e.Graphics.MeasureString(strCompany_Phone, printFont)
nWidth_Gap = nWidth_Gap + actual1.Width
actual1 = e.Graphics.MeasureString(strCOMPANY_FAX, printFont)
nWidth_Gap = nWidth_Gap + actual1.Width
nPrev_Width = nWidth_Gap
e.Graphics.DrawString("Phone:", printFontHeaderFooter, Brushes.Black, nMax_Width + lPageWidth / 2 - nPrev_Width / 2, nHeight_Gap, StrFormat)
actual1 = e.Graphics.MeasureString("Phone:", printFontHeaderFooter)
nWidth_Gap = actual1.Width
e.Graphics.DrawString(strCompany_Phone, printFont, Brushes.Black, nMax_Width + lPageWidth / 2 - nPrev_Width / 2 + nWidth_Gap, nHeight_Gap, StrFormat)
actual1 = e.Graphics.MeasureString("Phone:", printFontHeaderFooter)
nWidth_Gap = actual1.Width
actual1 = e.Graphics.MeasureString(strCompany_Phone, printFont)
nWidth_Gap = nWidth_Gap + actual1.Width
e.Graphics.DrawString("Fax:", printFontHeaderFooter, Brushes.Black, nMax_Width + lPageWidth / 2 - nPrev_Width / 2 + nWidth_Gap, nHeight_Gap, StrFormat)
actual1 = e.Graphics.MeasureString("Fax:", printFontHeaderFooter)
nWidth_Gap = nWidth_Gap + actual1.Width
e.Graphics.DrawString(strCOMPANY_FAX, printFont, Brushes.Black, nMax_Width + lPageWidth / 2 - nPrev_Width / 2 + nWidth_Gap, nHeight_Gap, StrFormat)
nHeight_Gap = nHeight_Gap + printFontHeaderFooter.Height
ElseIf Trim(strCOMPANY_FAX) <> "" Then
actual1 = e.Graphics.MeasureString("Fax: ", printFontHeaderFooter)
e.Graphics.DrawString("Fax: ", printFontHeaderFooter, Brushes.Black, nMax_Width + lPageWidth / 2, nHeight_Gap, StrFormat)
e.Graphics.DrawString(strCOMPANY_FAX, printFont, Brushes.Black, nMax_Width + lPageWidth / 2 + actual1.Width + 5, nHeight_Gap, StrFormat)
nHeight_Gap = nHeight_Gap + printFontHeaderFooter.Height
ElseIf Trim(strCompany_Phone) <> "" Then
actual1 = e.Graphics.MeasureString("Phone: ", printFontHeaderFooter)
nWidth_Gap = actual1.Width
e.Graphics.DrawString("Phone: ", printFontHeaderFooter, Brushes.Black, nMax_Width + lPageWidth / 2, nHeight_Gap, StrFormat)
e.Graphics.DrawString(strCompany_Phone, printFont, Brushes.Black, nMax_Width + lPageWidth / 2 + nWidth_Gap + 5, nHeight_Gap, StrFormat)
nHeight_Gap = nHeight_Gap + printFontHeaderFooter.Height
End If
If Trim(strCompany_Email) <> "" AndAlso Trim(strCompany_Website) <> "" Then
actual1 = e.Graphics.MeasureString("e-mail:", printFontHeaderFooter)
nWidth_Gap = actual1.Width
actual1 = e.Graphics.MeasureString("website:", printFontHeaderFooter)
nWidth_Gap = nWidth_Gap + actual1.Width
actual1 = e.Graphics.MeasureString(strCompany_Email, printFont)
nWidth_Gap = nWidth_Gap + actual1.Width
actual1 = e.Graphics.MeasureString(strCompany_Website, printFont)
nWidth_Gap = nWidth_Gap + actual1.Width
nPrev_Width = nWidth_Gap
e.Graphics.DrawString("e-mail:", printFontHeaderFooter, Brushes.Black, nMax_Width + lPageWidth / 2 - nPrev_Width / 2, nHeight_Gap, StrFormat)
actual1 = e.Graphics.MeasureString("e-mail:", printFontHeaderFooter)
nWidth_Gap = actual1.Width
e.Graphics.DrawString(strCompany_Email, printFont, Brushes.Black, nMax_Width + lPageWidth / 2 - nPrev_Width / 2 + nWidth_Gap, nHeight_Gap, StrFormat)
actual1 = e.Graphics.MeasureString("e-mail:", printFontHeaderFooter)
nWidth_Gap = actual1.Width
actual1 = e.Graphics.MeasureString(strCompany_Email, printFont)
nWidth_Gap = nWidth_Gap + actual1.Width
e.Graphics.DrawString("website:", printFontHeaderFooter, Brushes.Black, nMax_Width + lPageWidth / 2 - nPrev_Width / 2 + nWidth_Gap, nHeight_Gap, StrFormat)
actual1 = e.Graphics.MeasureString("website:", printFontHeaderFooter)
nWidth_Gap = nWidth_Gap + actual1.Width
e.Graphics.DrawString(strCompany_Website, printFont, Brushes.Black, nMax_Width + lPageWidth / 2 - nPrev_Width / 2 + nWidth_Gap, nHeight_Gap, StrFormat)
nHeight_Gap = nHeight_Gap + printFontHeaderFooter.Height
ElseIf Trim(strCompany_Email) <> "" Then
actual1 = e.Graphics.MeasureString("e-mail: ", printFontHeaderFooter)
e.Graphics.DrawString("e-mail: ", printFontHeaderFooter, Brushes.Black, nMax_Width + lPageWidth / 2, nHeight_Gap, StrFormat)
e.Graphics.DrawString(strCompany_Email, printFont, Brushes.Black, nMax_Width + lPageWidth / 2 + actual1.Width + 5, nHeight_Gap, StrFormat)
nHeight_Gap = nHeight_Gap + printFontHeaderFooter.Height
ElseIf Trim(strCompany_Website) <> "" Then
actual1 = e.Graphics.MeasureString(", website: ", printFontHeaderFooter)
nWidth_Gap = actual1.Width
e.Graphics.DrawString(", website: ", printFontHeaderFooter, Brushes.Black, nMax_Width + lPageWidth / 2, nHeight_Gap, StrFormat)
e.Graphics.DrawString(strCompany_Website, printFont, Brushes.Black, nMax_Width + lPageWidth / 2 + nWidth_Gap + 5, nHeight_Gap, StrFormat)
nHeight_Gap = nHeight_Gap + printFontHeaderFooter.Height
End If
If Trim(strCOMPANY_TIN) <> "" AndAlso Trim(strCOMPANY_PAN) <> "" Then
actual1 = e.Graphics.MeasureString("TIN:", printFontHeaderFooter)
nWidth_Gap = actual1.Width
actual1 = e.Graphics.MeasureString("PAN:", printFontHeaderFooter)
nWidth_Gap = nWidth_Gap + actual1.Width
actual1 = e.Graphics.MeasureString(strCOMPANY_TIN, printFont)
nWidth_Gap = nWidth_Gap + actual1.Width
actual1 = e.Graphics.MeasureString(strCOMPANY_PAN, printFont)
nWidth_Gap = nWidth_Gap + actual1.Width
nPrev_Width = nWidth_Gap
e.Graphics.DrawString("TIN:", printFontHeaderFooter, Brushes.Black, nMax_Width + lPageWidth / 2 - nPrev_Width / 2, nHeight_Gap, StrFormat)
actual1 = e.Graphics.MeasureString("TIN:", printFontHeaderFooter)
nWidth_Gap = actual1.Width
e.Graphics.DrawString(strCOMPANY_TIN, printFont, Brushes.Black, nMax_Width + lPageWidth / 2 - nPrev_Width / 2 + nWidth_Gap, nHeight_Gap, StrFormat)
actual1 = e.Graphics.MeasureString("TIN:", printFontHeaderFooter)
nWidth_Gap = actual1.Width
actual1 = e.Graphics.MeasureString(strCOMPANY_TIN, printFont)
nWidth_Gap = nWidth_Gap + actual1.Width
e.Graphics.DrawString("PAN:", printFontHeaderFooter, Brushes.Black, nMax_Width + lPageWidth / 2 - nPrev_Width / 2 + nWidth_Gap, nHeight_Gap, StrFormat)
actual1 = e.Graphics.MeasureString("PAN:", printFontHeaderFooter)
nWidth_Gap = nWidth_Gap + actual1.Width
e.Graphics.DrawString(strCOMPANY_PAN, printFont, Brushes.Black, nMax_Width + lPageWidth / 2 - nPrev_Width / 2 + nWidth_Gap, nHeight_Gap, StrFormat)
nHeight_Gap = nHeight_Gap + printFontHeaderFooter.Height
ElseIf Trim(strCOMPANY_TIN) <> "" Then
actual1 = e.Graphics.MeasureString("TIN: ", printFontHeaderFooter)
e.Graphics.DrawString("TIN: ", printFontHeaderFooter, Brushes.Black, nMax_Width + lPageWidth / 2, nHeight_Gap, StrFormat)
e.Graphics.DrawString(strCOMPANY_TIN, printFont, Brushes.Black, nMax_Width + lPageWidth / 2 + actual1.Width + 5, nHeight_Gap, StrFormat)
nHeight_Gap = nHeight_Gap + printFontHeaderFooter.Height
ElseIf Trim(strCOMPANY_PAN) <> "" Then
actual1 = e.Graphics.MeasureString("PAN: ", printFontHeaderFooter)
nWidth_Gap = actual1.Width
e.Graphics.DrawString("PAN: ", printFontHeaderFooter, Brushes.Black, nMax_Width + lPageWidth / 2, nHeight_Gap, StrFormat)
e.Graphics.DrawString(strCOMPANY_PAN, printFont, Brushes.Black, nMax_Width + lPageWidth / 2 + nWidth_Gap + 5, nHeight_Gap, StrFormat)
nHeight_Gap = nHeight_Gap + printFontHeaderFooter.Height
End If
If Trim(strCOMPANY_CST) <> "" AndAlso Trim(strCOMPANY_ECC) <> "" Then
actual1 = e.Graphics.MeasureString("CST:", printFontHeaderFooter)
nWidth_Gap = actual1.Width
actual1 = e.Graphics.MeasureString("ECC:", printFontHeaderFooter)
nWidth_Gap = nWidth_Gap + actual1.Width
actual1 = e.Graphics.MeasureString(strCOMPANY_CST, printFont)
nWidth_Gap = nWidth_Gap + actual1.Width
actual1 = e.Graphics.MeasureString(strCOMPANY_ECC, printFont)
nWidth_Gap = nWidth_Gap + actual1.Width
nPrev_Width = nWidth_Gap
e.Graphics.DrawString("CST:", printFontHeaderFooter, Brushes.Black, nMax_Width + lPageWidth / 2 - nPrev_Width / 2, nHeight_Gap, StrFormat)
actual1 = e.Graphics.MeasureString("ECC:", printFontHeaderFooter)
nWidth_Gap = actual1.Width
e.Graphics.DrawString(strCOMPANY_CST, printFont, Brushes.Black, nMax_Width + lPageWidth / 2 - nPrev_Width / 2 + nWidth_Gap, nHeight_Gap, StrFormat)
actual1 = e.Graphics.MeasureString("ECC:", printFontHeaderFooter)
nWidth_Gap = actual1.Width
actual1 = e.Graphics.MeasureString(strCOMPANY_ECC, printFont)
nWidth_Gap = nWidth_Gap + actual1.Width
e.Graphics.DrawString("ECC:", printFontHeaderFooter, Brushes.Black, nMax_Width + lPageWidth / 2 - nPrev_Width / 2 + nWidth_Gap, nHeight_Gap, StrFormat)
actual1 = e.Graphics.MeasureString("ECC:", printFontHeaderFooter)
nWidth_Gap = nWidth_Gap + actual1.Width
e.Graphics.DrawString(strCOMPANY_ECC, printFont, Brushes.Black, nMax_Width + lPageWidth / 2 - nPrev_Width / 2 + nWidth_Gap, nHeight_Gap, StrFormat)
nHeight_Gap = nHeight_Gap + printFontHeaderFooter.Height
ElseIf Trim(strCOMPANY_CST) <> "" Then
actual1 = e.Graphics.MeasureString("CST: ", printFontHeaderFooter)
e.Graphics.DrawString("CST: ", printFontHeaderFooter, Brushes.Black, nMax_Width + lPageWidth / 2, nHeight_Gap, StrFormat)
e.Graphics.DrawString(strCOMPANY_CST, printFont, Brushes.Black, nMax_Width + lPageWidth / 2 + actual1.Width + 5, nHeight_Gap, StrFormat)
nHeight_Gap = nHeight_Gap + printFontHeaderFooter.Height
ElseIf Trim(strCOMPANY_ECC) <> "" Then
actual1 = e.Graphics.MeasureString("ECC: ", printFontHeaderFooter)
nWidth_Gap = actual1.Width
e.Graphics.DrawString("ECC: ", printFontHeaderFooter, Brushes.Black, nMax_Width + lPageWidth / 2, nHeight_Gap, StrFormat)
e.Graphics.DrawString(strCOMPANY_ECC, printFont, Brushes.Black, nMax_Width + lPageWidth / 2 + nWidth_Gap + 5, nHeight_Gap, StrFormat)
nHeight_Gap = nHeight_Gap + printFontHeaderFooter.Height
End If
End If
End If
End Sub
Private Sub Print_Options(ByVal e As PrintPageEventArgs, ByVal nTotalHeight As Integer)
Dim actual1 As SizeF = Nothing
Dim nPrev_Width As Integer = 0
If dicPrint_Options("IS_USER_ID_PRINT") = True Then
e.Graphics.DrawString("User Id:", printFontHeaderFooter, Brushes.Black, leftMargin, topMargin + nTotalHeight, StrFormat)
actual1 = e.Graphics.MeasureString("User Id:", printFontHeaderFooter)
nPrev_Width = actual1.Width
e.Graphics.DrawString(strUser_ID, printFont, Brushes.Black, leftMargin + actual1.Width, topMargin + nTotalHeight, StrFormat)
nPrev_Width = nPrev_Width + leftMargin
End If
If dicPrint_Options("IS_DATE_PRINT") = True AndAlso dicPrint_Options("IS_TIME_PRINT") = True Then
e.Graphics.DrawString("Print Date/Time:", printFontHeaderFooter, Brushes.Black, leftMargin + nPrev_Width + 5, topMargin + nTotalHeight, StrFormat)
actual1 = e.Graphics.MeasureString("Print Date/Time:", printFontHeaderFooter)
nPrev_Width = nPrev_Width + actual1.Width
e.Graphics.DrawString(Now.ToString("dd-MMM-yy HH:mm:ss"), printFont, Brushes.Black, leftMargin + nPrev_Width, topMargin + nTotalHeight, StrFormat)
actual1 = e.Graphics.MeasureString(Now.ToString("dd-MMM-yy HH:mm:ss"), printFont)
nPrev_Width = nPrev_Width + leftMargin + actual1.Width
Else
If dicPrint_Options("IS_DATE_PRINT") = True Then
e.Graphics.DrawString("Print Date:", printFontHeaderFooter, Brushes.Black, leftMargin + nPrev_Width + 5, topMargin + nTotalHeight, StrFormat)
actual1 = e.Graphics.MeasureString("Print Date:", printFontHeaderFooter)
nPrev_Width = nPrev_Width + actual1.Width
e.Graphics.DrawString(Now.ToString("dd-MMM-yy"), printFont, Brushes.Black, leftMargin + nPrev_Width, topMargin + nTotalHeight, StrFormat)
actual1 = e.Graphics.MeasureString(Now.ToString("dd-MMM-yy"), printFont)
nPrev_Width = nPrev_Width + leftMargin + actual1.Width
End If
If dicPrint_Options("IS_TIME_PRINT") = True Then
e.Graphics.DrawString("Print Time:", printFontHeaderFooter, Brushes.Black, leftMargin + nPrev_Width + 5, topMargin + nTotalHeight, StrFormat)
actual1 = e.Graphics.MeasureString("Print Time:", printFontHeaderFooter)
nPrev_Width = nPrev_Width + actual1.Width
e.Graphics.DrawString(Now.ToString("HH:mm:ss"), printFont, Brushes.Black, leftMargin + nPrev_Width, topMargin + nTotalHeight, StrFormat)
actual1 = e.Graphics.MeasureString(Now.ToString("HH:mm:ss"), printFont)
nPrev_Width = nPrev_Width + leftMargin + actual1.Width
End If
End If
If dicPrint_Options("IS_PAGE_NO_PRINT") = True Then
nPageNo = nPageNo + 1
e.Graphics.DrawString("Page# " & nPageNo.ToString, printFont, Brushes.Black, leftMargin, 10, StrFormat)
End If
End Sub
Private Sub Print_Group_Header_Part(ByVal e As PrintPageEventArgs, ByRef nTop As Integer, ByRef nGroup_Height As Integer, ByRef dicPrevGroupingColumns As Dictionary(Of String, String), ByVal Is_Print_Group_Header As Boolean, ByVal iLoop As Integer, ByRef nHeight As Integer, ByRef nNext_Row_Max_Height As Integer)
Dim strGroup_Data As String = ""
Dim nLeft As Integer = 0
Dim nWidth As Integer = 0
Dim strData As String = ""
Dim actual As SizeF = Nothing
Dim Dont_Draw_Line As Boolean = False
Dim Is_Prev_Print_Group_Header As Boolean = Is_Print_Group_Header
Dim Is_Print_Summary_Called As Boolean = False
Dim Is_Group_Serial_No_Reset As Boolean = False
nNext_Row_Max_Height = 0
'If iLoop > 0 Then
' Is_Prev_Print_Group_Header = True
'End If
If Not dicHeader_Grouping Is Nothing AndAlso dicHeader_Grouping.Count > 0 Then
If Is_Print_Group_Header = False OrElse iLoop > 0 Then
If Not dicPrevGroupingColumns Is Nothing AndAlso dicPrevGroupingColumns.Count > 0 Then
For Each strColumn In dicHeader_Grouping.Keys
strColumn = Replace(strColumn, """", "")
strData = dsHeader.Tables(0).Rows(iLoop)(strColumn).ToString & ""
If dicGroup_Serial_No_Reset_Columns.Count > 0 AndAlso dicGroup_Serial_No_Reset_Columns.ContainsKey("""" & strColumn & """") Then
If strData <> dicGroup_Serial_No_Reset_Columns("""" & strColumn & """") AndAlso Is_Group_Serial_No_Reset = False Then
Is_Group_Serial_No_Reset = True
dicGroup_Serial_No_Reset_Columns("""" & strColumn & """") = strData
End If
End If
If strData <> dicPrevGroupingColumns("""" & strColumn & """") Then
dicPrevGroupingColumns("""" & strColumn & """") = strData
Is_Print_Group_Header = True
If Is_Print_Summary_Called = False Then
If Is_Group_Serial_No_Reset = True OrElse dicGroup_Serial_No_Reset_Columns.Count = 0 Then
nGroup_Serial_No = nGroup_Serial_No + 1
End If
If dicSummary_Captions.ContainsKey("HT") Then
Print_Summary_Part(e, nTop, nGroup_Height, dicSumOfHeaderColumns, iLoop, nHeight, nNext_Row_Max_Height, "H", dicSummary_Captions("HT"))
Else
Print_Summary_Part(e, nTop, nGroup_Height, dicSumOfHeaderColumns, iLoop, nHeight, nNext_Row_Max_Height, "H", "Total :")
End If
Is_Print_Summary_Called = True
If nHeight > 0 Then
Dont_Draw_Line = True
Else
Dont_Draw_Line = False
End If
End If
End If
Next
End If
End If
strGroup_Data = ""
If Is_Print_Group_Header = True OrElse (iLoop > 0 AndAlso iLoop = nPrinted_Rows) Then
If iLoop = nPrinted_Rows Then
For Each strColumn In dicHeader_Grouping.Keys
strColumn = Replace(strColumn, """", "")
If dicPrevGroupingColumns.ContainsKey("""" & strColumn & """") = False Then
dicPrevGroupingColumns.Add("""" & strColumn & """", dsHeader.Tables(0).Rows(iLoop)(strColumn).ToString & "")
End If
If Not dicHeader_Width Is Nothing AndAlso dicHeader_Width.ContainsKey("""" & strColumn & """") Then
nWidth = dicHeader_Width("""" & strColumn & """")
Else
Continue For
End If
If Trim(strGroup_Data) = "" Then
strGroup_Data = strColumn
Else
strGroup_Data = strGroup_Data & "->" & strColumn
End If
nLeft = nLeft + nWidth
Next
If strGroup_Data <> "" Then
e.Graphics.DrawString("Grouping On:- " & strGroup_Data, printFontHeaderFooter, Brushes.Black, New RectangleF(leftMargin, topMargin + nTop, lPageWidth, e.MarginBounds.Size.Height), StrFormat)
actual = e.Graphics.MeasureString(strGroup_Data, printFontHeaderFooter, New SizeF(lPageWidth, e.MarginBounds.Size.Height), StrFormat)
If actual.Height > nHeight Then
nHeight = Math.Round(actual.Height)
nNext_Row_Max_Height = nHeight
End If
nTop = nTop + nHeight
nGroup_Height = nGroup_Height + nHeight
nLeft = 0
End If
'e.Graphics.DrawLine(Pens.Red, leftMargin, topMargin + nTop, lPageWidth + leftMargin, topMargin + nTop)
End If
'----Above Group Header---
If Dont_Draw_Line = False OrElse iLoop = nPrinted_Rows Then
e.Graphics.DrawLine(Pens.Red, leftMargin, topMargin + nTop, lPageWidth + leftMargin, topMargin + nTop)
End If
strGroup_Data = ""
If iLoop = 0 Then
nGroup_Serial_No = 1
End If
For Each strColumn In dicHeader_Grouping.Keys
strColumn = Replace(strColumn, """", "")
'strData = dsHeader.Tables(0).Rows(iLoop)(strColumn).ToString & ""
strData = Get_Formatted_Data(dsHeader.Tables(0).Rows(iLoop)(strColumn).ToString & "", strColumn, dicData_Format, dicData_Type, dicDecimal_Place, StrVariableFormat)
'actual = e.Graphics.MeasureString(strData, printFontHeaderFooter, New SizeF(nWidth, e.MarginBounds.Size.Height), StrFormat)
'If actual.Height > nHeight Then
' nHeight = Math.Round(actual.Height)
'End If
If strData = "SL#" OrElse strColumn = "SL#" Then
strData = nGroup_Serial_No
End If
'strData = Get_Formatted_Data(dsHeader.Tables(0).Rows(iLoop + 1)(iCol).ToString & "", strColumn, dicData_Format, dicData_Type, dicDecimal_Place, StrVariableFormat)
If Trim(strGroup_Data) = "" Then
If Is_Print_Group_Header = False AndAlso iLoop > 0 AndAlso iLoop = nPrinted_Rows Then
strGroup_Data = "Continue..." & nGroup_Serial_No & ". " & strData
Else
strGroup_Data = nGroup_Serial_No & ". " & strData
End If
Else
strGroup_Data = strGroup_Data & "->" & strData
End If
nLeft = nLeft + nWidth
'actual = e.Graphics.MeasureString(strColumn, printFontHeaderFooter, New SizeF(nWidth, e.MarginBounds.Size.Height), StrFormat)
'If actual.Height > nHeight Then
' nHeight = Math.Round(actual.Height)
'End If
Next
If strGroup_Data <> "" Then
actual = e.Graphics.MeasureString(strGroup_Data, printFontHeaderFooter, New SizeF(lPageWidth, e.MarginBounds.Size.Height), StrFormat)
e.Graphics.DrawString(strGroup_Data, printFontHeaderFooter, Brushes.Black, New RectangleF(leftMargin, topMargin + nTop, lPageWidth, e.MarginBounds.Size.Height), StrFormat)
If actual.Height > nHeight Then
nHeight = Math.Round(actual.Height)
nNext_Row_Max_Height = nHeight + nNext_Row_Max_Height
End If
nGroup_Height = nGroup_Height + nHeight
nTop = nTop + nHeight
nLeft = 0
End If
'----Below Group Header---
'If Dont_Draw_Line = False Then
e.Graphics.DrawLine(Pens.Red, leftMargin, topMargin + nTop, lPageWidth + leftMargin, topMargin + nTop)
'End If
End If
End If
End Sub
Private Sub Print_Group_Detail_Part(ByVal e As System.Drawing.Printing.PrintPageEventArgs, ByRef nTop As Integer, ByRef nGroup_Height As Integer, ByRef dicPrevGroupingColumns As Dictionary(Of String, String), ByVal Is_Print_Group_Header As Boolean, ByVal iLoop As Integer, ByRef nHeight As Integer, ByRef nNext_Row_Max_Height As Integer)
Dim strGroup_Data As String = ""
Dim nLeft As Integer = 0
Dim nWidth As Integer = 0
Dim strData As String = ""
Dim actual As SizeF = Nothing
Dim Dont_Draw_Line As Boolean = False
Dim Is_Prev_Print_Group_Header As Boolean = Is_Print_Group_Header
Dim Is_Print_Summary_Called As Boolean = False
'If iLoop > 0 Then
' Is_Prev_Print_Group_Header = True
'End If
If Not dicDetail_Grouping Is Nothing AndAlso dicDetail_Grouping.Count > 0 Then
If Is_Print_Group_Header = False OrElse iLoop > 0 Then
If Not dicPrevGroupingColumns Is Nothing AndAlso dicPrevGroupingColumns.Count > 0 Then
For Each strColumn In dicDetail_Grouping.Keys
strColumn = Replace(strColumn, """", "")
strData = dsHeader.Tables(0).Rows(iLoop)(strColumn).ToString & ""
If strData <> dicPrevGroupingColumns("""" & strColumn & """") Then
dicPrevGroupingColumns("""" & strColumn & """") = strData
Is_Print_Group_Header = True
If Is_Print_Summary_Called = False Then
nDetail_Group_Serial_No = nDetail_Group_Serial_No + 1
Is_Print_Summary_Called = True
If dicSummary_Captions.ContainsKey("DT") Then
Print_Summary_Part(e, nTop, nGroup_Height, dicSumOfDetailColumns, iLoop, nHeight, nNext_Row_Max_Height, "D", dicSummary_Captions("DT"))
Else
Print_Summary_Part(e, nTop, nGroup_Height, dicSumOfDetailColumns, iLoop, nHeight, nNext_Row_Max_Height, "D", "Total :")
End If
If nHeight > 0 Then
Dont_Draw_Line = True
Else
Dont_Draw_Line = False
End If
End If
End If
Next
End If
End If
strGroup_Data = ""
If Is_Print_Group_Header = True OrElse (iLoop > 0 AndAlso iLoop = nPrinted_Rows) Then
If iLoop = nPrinted_Rows Then
For Each strColumn In dicDetail_Grouping.Keys
strColumn = Replace(strColumn, """", "")
If dicPrevGroupingColumns.ContainsKey("""" & strColumn & """") = False Then
dicPrevGroupingColumns.Add("""" & strColumn & """", dsHeader.Tables(0).Rows(iLoop)(strColumn).ToString & "")
End If
If Not dicDetail_Width Is Nothing AndAlso dicDetail_Width.ContainsKey("""" & strColumn & """") Then
nWidth = dicDetail_Width("""" & strColumn & """")
Else
Continue For
End If
If Trim(strGroup_Data) = "" Then
strGroup_Data = strColumn
Else
strGroup_Data = strGroup_Data & "->" & strColumn
End If
nLeft = nLeft + nWidth
Next
If strGroup_Data <> "" Then
e.Graphics.DrawString("Grouping On:-" & strGroup_Data, printFontHeaderFooter, Brushes.Black, New RectangleF(leftMargin, topMargin + nTop, lPageWidth, e.MarginBounds.Size.Height), StrFormat)
actual = e.Graphics.MeasureString(strGroup_Data, printFontHeaderFooter, New SizeF(lPageWidth, e.MarginBounds.Size.Height), StrFormat)
If actual.Height > nHeight Then
nHeight = Math.Round(actual.Height)
End If
nTop = nTop + nHeight
nGroup_Height = nGroup_Height + nHeight
nLeft = 0
End If
End If
'----Above Group Header---
If Dont_Draw_Line = False OrElse iLoop = nPrinted_Rows Then
e.Graphics.DrawLine(Pens.Red, leftMargin, topMargin + nTop, lPageWidth + leftMargin, topMargin + nTop)
End If
'If Dont_Draw_Line = False Then
' e.Graphics.DrawLine(Pens.Red, leftMargin, topMargin + nTop, lPageWidth + leftMargin, topMargin + nTop)
'End If
strGroup_Data = ""
'nGroup_Serial_No = nGroup_Serial_No + 1
'If Is_Prev_Print_Group_Header = True AndAlso iLoop > 0 Then
If iLoop = 0 Then
nDetail_Group_Serial_No = 1 'nDetail_Group_Serial_No + 1
End If
For Each strColumn In dicDetail_Grouping.Keys
strColumn = Replace(strColumn, """", "")
strData = dsHeader.Tables(0).Rows(iLoop)(strColumn).ToString & ""
If strData = "SL#" OrElse strColumn = "SL#" Then
strData = nDetail_Group_Serial_No
End If
If Trim(strGroup_Data) = "" Then
If Is_Print_Group_Header = False AndAlso iLoop > 0 AndAlso iLoop = nPrinted_Rows Then
strGroup_Data = "Continue..." & nDetail_Group_Serial_No & ". " & strData
Else
strGroup_Data = nDetail_Group_Serial_No & ". " & strData
End If
Else
strGroup_Data = strGroup_Data & "->" & strData
End If
nLeft = nLeft + nWidth
Next
If strGroup_Data <> "" Then
actual = e.Graphics.MeasureString(strGroup_Data, printFontHeaderFooter, New SizeF(lPageWidth, e.MarginBounds.Size.Height), StrFormat)
e.Graphics.DrawString(strGroup_Data, printFontHeaderFooter, Brushes.Black, New RectangleF(leftMargin, topMargin + nTop, lPageWidth, e.MarginBounds.Size.Height), StrFormat)
If actual.Height > nHeight Then
nHeight = Math.Round(actual.Height)
End If
nGroup_Height = nGroup_Height + nHeight
nTop = nTop + nHeight
nLeft = 0
End If
'----Below Group Header---
'If Dont_Draw_Line = False Then
e.Graphics.DrawLine(Pens.Red, leftMargin, topMargin + nTop, lPageWidth + leftMargin, topMargin + nTop)
'End If
End If
End If
End Sub
Private Function Page_Break(ByVal e As PrintPageEventArgs, ByVal nNext_Row_Max_Height As Integer, ByVal nTop As Integer, ByVal iLoop As Integer, ByVal nPrev_Top As Integer, ByVal Draw_Line As Boolean, ByVal Reset_Detail_Serial_No As Boolean, ByVal Is_Last_Row As Boolean, ByVal Next_Print_Row As Integer, ByVal Detail_Start As Boolean) As Boolean
Dim nTotalHeight As Integer = 0
Dim nLeft As Integer = 0
Dim nWidth As Integer = 0
Dim strColumn As String = ""
If nNext_Row_Max_Height + nTop > lPageHeight - topMargin - nPFSBottom_Margin OrElse Is_Last_Row = True Then
nTotalHeight = nTop
e.Graphics.DrawRectangle(Pens.Red, New Rectangle(leftMargin + nMax_Width, topMargin, nPFSEach_Page_Width - nPFSRight_Margin - leftMargin, nTotalHeight))
nLeft = 0
nWidth = 0
For iCol = 0 To dsHeader.Tables(0).Columns.Count - 1
strColumn = dsHeader.Tables(0).Columns(iCol).ColumnName
If Not dicHeader_Width Is Nothing AndAlso dicHeader_Width.ContainsKey("""" & strColumn & """") Then
nWidth = dicHeader_Width("""" & strColumn & """")
ElseIf Not dicDetail_Width Is Nothing AndAlso dicDetail_Width.ContainsKey("""" & strColumn & """") Then
nWidth = dicDetail_Width("""" & strColumn & """")
Else
Continue For
End If
If strHeader_Detail_Or_Both <> "B" Then
e.Graphics.DrawLine(Pens.Red, leftMargin + nLeft, topMargin + nPrev_Top, leftMargin + nLeft, topMargin + nTotalHeight)
'ElseIf Draw_Line = True Then
' e.Graphics.DrawLine(Pens.Red, leftMargin + nLeft, topMargin + nPrev_Top, leftMargin + nLeft, topMargin + nTotalHeight)
End If
nLeft = nLeft + nWidth
Next
If iLoop <> dsHeader.Tables(0).Rows.Count - 1 OrElse (iLoop = dsHeader.Tables(0).Rows.Count - 1 AndAlso Is_Last_Row = False) Then
nPrinted_Rows = Next_Print_Row
Print_Options(e, nTotalHeight)
e.Graphics.DrawString("Continue...", printFontHeaderFooter, Brushes.Black, nPFSEach_Page_Width - e.Graphics.MeasureString("Continue...", printFontHeaderFooter).Width, topMargin + nTotalHeight, StrFormat)
e.HasMorePages = True
If Reset_Detail_Serial_No = True Then
nDetail_Serial_No = 0
End If
If Detail_Start = True Then
Is_Detail_Start = True
End If
Return True
End If
ElseIf (nNext_Row_Max_Height + nTop > lPageHeight - topMargin - nFooterHeight - nFooter_RTF_Height - nPFSBottom_Margin) Then
If iLoop = dsHeader.Tables(0).Rows.Count - 1 Then
nTotalHeight = nTop
e.Graphics.DrawRectangle(Pens.Red, New Rectangle(leftMargin, topMargin, nPFSEach_Page_Width - nPFSRight_Margin - leftMargin, nTotalHeight))
nLeft = 0
nWidth = 0
For iCol = 0 To dsHeader.Tables(0).Columns.Count - 1
strColumn = dsHeader.Tables(0).Columns(iCol).ColumnName
If Not dicHeader_Width Is Nothing AndAlso dicHeader_Width.ContainsKey("""" & strColumn & """") Then
nWidth = dicHeader_Width("""" & strColumn & """")
ElseIf Not dicDetail_Width Is Nothing AndAlso dicDetail_Width.ContainsKey("""" & strColumn & """") Then
nWidth = dicDetail_Width("""" & strColumn & """")
Else
Continue For
End If
If strHeader_Detail_Or_Both <> "B" Then
e.Graphics.DrawLine(Pens.Red, leftMargin + nLeft, topMargin + nPrev_Top, leftMargin + nLeft, topMargin + nTotalHeight)
'ElseIf Draw_Line = True Then
' e.Graphics.DrawLine(Pens.Red, leftMargin + nLeft, topMargin + nPrev_Top, leftMargin + nLeft, topMargin + nTotalHeight)
End If
nLeft = nLeft + nWidth
Next
'If iLoop <> dsHeader.Tables(0).Rows.Count - 1 OrElse (iLoop = dsHeader.Tables(0).Rows.Count - 1 AndAlso Is_Last_Row = False) Then
nPrinted_Rows = Next_Print_Row - 1
Print_Options(e, nTotalHeight)
e.Graphics.DrawString("Continue...", printFontHeaderFooter, Brushes.Black, nPFSEach_Page_Width - e.Graphics.MeasureString("Continue...", printFontHeaderFooter).Width, topMargin + nTotalHeight, StrFormat)
e.HasMorePages = True
If Reset_Detail_Serial_No = True Then
nDetail_Serial_No = 0
End If
If Detail_Start = True Then
Is_Detail_Start = True
End If
Return True
'End If
End If
End If
Return False
End Function
Private Sub Print_Summary_Part(ByVal e As PrintPageEventArgs, ByRef nTop As Integer, ByRef nTotal_Height As Integer, ByRef dicSumOfColumns As Dictionary(Of String, Decimal), ByVal iLoop As Integer, ByRef nHeight As Integer, ByRef nNext_Row_Max_Height As Integer, ByVal Sum_Of_Which_Part As String, ByVal strSummary_Caption As String)
Dim strGroup_Data As String = ""
Dim nLeft As Integer = 0
Dim nWidth As Integer = 0
Dim strData As String = ""
Dim actual As SizeF = Nothing
Dim strColumn As String = ""
Dim strTotal_Caption As String = strSummary_Caption
Dim Has_Negative_Value As Boolean = False
Dim Is_Grand_Total As Boolean = False
nNext_Row_Max_Height = 0
nHeight = 0
If Not dicSumOfColumns Is Nothing AndAlso dicSumOfColumns.Count > 0 Then
For iCol = 0 To dsHeader.Tables(0).Columns.Count - 1
strColumn = dsHeader.Tables(0).Columns(iCol).ColumnName
If Not dicHeader_Width Is Nothing AndAlso dicHeader_Width.ContainsKey("""" & strColumn & """") AndAlso Sum_Of_Which_Part = "H" Then
nWidth = dicHeader_Width("""" & strColumn & """")
ElseIf Not dicDetail_Width Is Nothing AndAlso dicDetail_Width.ContainsKey("""" & strColumn & """") AndAlso Sum_Of_Which_Part = "D" Then
nWidth = dicDetail_Width("""" & strColumn & """")
ElseIf Not dicHeader_Width Is Nothing AndAlso dicHeader_Width.ContainsKey("""" & strColumn & """") AndAlso Sum_Of_Which_Part = "GT" AndAlso strHeader_Detail_Or_Both = "H" Then 'Group Header Grand Total
Is_Grand_Total = True
nWidth = dicHeader_Width("""" & strColumn & """")
ElseIf Not dicDetail_Width Is Nothing AndAlso dicDetail_Width.ContainsKey("""" & strColumn & """") AndAlso Sum_Of_Which_Part = "GT" AndAlso strHeader_Detail_Or_Both = "D" Then 'Group Detail Grand Total
Is_Grand_Total = True
nWidth = dicDetail_Width("""" & strColumn & """")
ElseIf Not dicDetail_Width Is Nothing AndAlso dicDetail_Width.ContainsKey("""" & strColumn & """") AndAlso Sum_Of_Which_Part = "GT" AndAlso strHeader_Detail_Or_Both = "B" Then 'Detail Part Grand Total
Is_Grand_Total = True
nWidth = dicDetail_Width("""" & strColumn & """")
ElseIf Not dicHeader_Width Is Nothing AndAlso dicHeader_Width.ContainsKey("""" & strColumn & """") AndAlso Sum_Of_Which_Part = "GTH" Then 'Header Part Grand Total
Is_Grand_Total = True
nWidth = dicHeader_Width("""" & strColumn & """")
Else
Continue For
End If
If Not dicSumOfColumns Is Nothing AndAlso dicSumOfColumns.Count > 0 Then
If dicSumOfColumns.ContainsKey("""" & strColumn & """") Then
strData = Get_Formatted_Data(dicSumOfColumns("""" & strColumn & """").ToString(), strColumn, dicData_Format, dicData_Type, dicDecimal_Place, StrVariableFormat, Has_Negative_Value)
If Has_Negative_Value = True Then
If Is_Grand_Total = True Then
If dicData_Format.ContainsKey("""" & strColumn & "_" & "Grand_Total""") AndAlso dicData_Format("""" & strColumn & "_" & "Grand_Total""").ToLower() = "nabs" Then
strData = "-" & strData
End If
Else
If dicData_Format.ContainsKey("""" & strColumn & "_" & "Total""") AndAlso dicData_Format("""" & strColumn & "_" & "Total""").ToLower() = "nabs" Then
strData = "-" & strData
End If
End If
End If
If Is_Detail_Start = True Then
actual = e.Graphics.MeasureString(strData, printFontHeaderFooterDetail, New SizeF(nWidth, e.MarginBounds.Size.Height), StrVariableFormat)
If actual.Height > nHeight Then
nHeight = Math.Round(actual.Height)
End If
e.Graphics.DrawString(strData, printFontHeaderFooterDetail, Brushes.Black, New RectangleF(leftMargin + nLeft, topMargin + nTop - IIf(Sum_Of_Which_Part = "GT" Or Sum_Of_Which_Part = "GTH", 0, 1), nWidth, e.MarginBounds.Size.Height), StrVariableFormat)
If nHeight > 0 Then
e.Graphics.DrawString(strTotal_Caption, printFontHeaderFooterDetail, Brushes.Black, leftMargin + 5, topMargin + nTop - IIf(Sum_Of_Which_Part = "GT" Or Sum_Of_Which_Part = "GTH", 0, 1), StrFormat)
End If
Else
actual = e.Graphics.MeasureString(strData, printFontHeaderFooter, New SizeF(nWidth, e.MarginBounds.Size.Height), StrVariableFormat)
If actual.Height > nHeight Then
nHeight = Math.Round(actual.Height)
End If
e.Graphics.DrawString(strData, printFontHeaderFooter, Brushes.Black, New RectangleF(leftMargin + nLeft, topMargin + nTop - IIf(Sum_Of_Which_Part = "GT" Or Sum_Of_Which_Part = "GTH", 0, 1), nWidth, e.MarginBounds.Size.Height), StrVariableFormat)
If nHeight > 0 Then
e.Graphics.DrawString(strTotal_Caption, printFontHeaderFooter, Brushes.Black, leftMargin + 5, topMargin + nTop - IIf(Sum_Of_Which_Part = "GT" Or Sum_Of_Which_Part = "GTH", 0, 1), StrFormat)
End If
End If
If Sum_Of_Which_Part <> "GT" AndAlso Sum_Of_Which_Part <> "GTH" Then
e.Graphics.DrawLine(Pens.Black, leftMargin + nLeft, topMargin + nTop + nHeight - 2, leftMargin + nLeft + nWidth - nLineGap, topMargin + nTop + nHeight - 2)
'e.Graphics.DrawLine(Pens.Red, leftMargin + nLeft, topMargin + nTop + nHeight - 2, leftMargin + nLeft + nWidth, topMargin + nTop + nHeight - 2)
End If
End If
nLeft = nLeft + nWidth
If dsHeader.Tables(0).Rows.Count - 1 > iLoop Then
strData = Get_Formatted_Data(dsHeader.Tables(0).Rows(iLoop + 1)(iCol).ToString & "", strColumn, dicData_Format, dicData_Type, dicDecimal_Place, StrVariableFormat, Has_Negative_Value)
'If Has_Negative_Value = True Then
' strData = -Convert_Rs_Format_To_Value(strData)
'Else
' strData = Convert_Rs_Format_To_Value(strData)
'End If
If Is_Detail_Start = True Then
actual = e.Graphics.MeasureString(strData, printFontHeaderFooterDetail, New SizeF(nWidth, e.MarginBounds.Size.Height), StrVariableFormat)
Else
actual = e.Graphics.MeasureString(strData, printFontHeaderFooter, New SizeF(nWidth, e.MarginBounds.Size.Height), StrVariableFormat)
End If
'actual = e.Graphics.MeasureString(strData, printFontHeaderFooterDetail, New SizeF(nWidth, e.MarginBounds.Size.Height), StrFormat)
If actual.Height > nNext_Row_Max_Height Then
nNext_Row_Max_Height = Math.Round(actual.Height)
End If
End If
End If
Next
If nHeight > 0 Then
If iLoop <= dsHeader.Tables(0).Rows.Count Then
If Sum_Of_Which_Part <> "GT" AndAlso Sum_Of_Which_Part <> "GTH" Then
e.Graphics.DrawLine(Pens.Red, leftMargin + CInt(nMax_Width), topMargin + nTop + nHeight, nPFSEach_Page_Width - nPFSRight_Margin, topMargin + nTop + nHeight)
End If
nTop = nTop + nHeight
nTotal_Height = nTotal_Height + nHeight
End If
End If
nLeft = 0
nWidth = 0
End If
dicSumOfColumns.Clear()
End Sub
Private Function Get_Formatted_Data_From_Direct(ByVal Data As String, ByVal dData_Format As String, ByVal dData_Type As String, ByVal dDecimal_Place As String, ByRef sVariableFormat As StringFormat, Optional ByRef Has_Negative_Value As Boolean = False) As String
Has_Negative_Value = False
If Not dData_Type.ToLower Like "*varchar*" AndAlso Not dData_Type.ToLower Like "*date*" Then
If dData_Format.ToLower() = "abs" Then
If Val(Data) < 0 Then
Has_Negative_Value = True
End If
Data = Convert_Value_Format_To_Rs(Math.Abs(Val(Data)), Val(dDecimal_Place), False, False)
Else
Data = Convert_Value_Format_To_Rs(Data, Val(dDecimal_Place), False, False)
End If
sVariableFormat = numFormat
ElseIf dData_Type.ToLower Like "*date*" Then
If Val(Data) > 0 Then
If dData_Format <> "" Then
Data = DateTime.FromOADate(Val(Data)).ToString(dData_Format) '"dd-MMM-yy"
Else
If Val(Data) - Int(Val(Data)) > 0 AndAlso Int(Val(Data)) > 0 Then
Data = DateTime.FromOADate(Val(Data)).ToString("dd-MMM-yy HH:mm:ss") '"dd-MMM-yy"
ElseIf Val(Data) - Int(Val(Data)) > 0 AndAlso Int(Val(Data)) = 0 Then
Data = DateTime.FromOADate(Val(Data)).ToString("HH:mm:ss") '"dd-MMM-yy"
ElseIf Val(Data) > 0 AndAlso Int(Val(Data)) > 0 Then
Data = DateTime.FromOADate(Val(Data)).ToString("dd-MMM-yy") '"dd-MMM-yy"
Else
Data = ""
End If
End If
Else
Data = ""
End If
'sVariableFormat = numFormat
sVariableFormat = StrFormat
Else
sVariableFormat = StrFormat
End If
Return Data
End Function
Private Function Get_Formatted_Data(ByVal Data As String, ByVal strColumn As String, ByVal dData_Format As Dictionary(Of String, String), ByVal dData_Type As Dictionary(Of String, String), ByVal dDecimal_Place As Dictionary(Of String, String), ByRef sVariableFormat As StringFormat, Optional ByRef Has_Negative_Value As Boolean = False) As String
Has_Negative_Value = False
If dData_Type.ContainsKey("""" & strColumn & """") AndAlso Not dData_Type.Item("""" & strColumn & """").ToLower Like "*varchar*" AndAlso Not dData_Type.Item("""" & strColumn & """").ToLower Like "*date*" Then
If dData_Format.ContainsKey("""" & strColumn & """") Then
If dDecimal_Place.ContainsKey("""" & strColumn & """") Then
If dData_Format("""" & strColumn & """").ToLower() = "abs" Then
If Val(Data) < 0 Then
Has_Negative_Value = True
End If
Data = Convert_Value_Format_To_Rs(Math.Abs(Val(Data)), Val(dDecimal_Place("""" & strColumn & """")), False, False)
Else
Data = Convert_Value_Format_To_Rs(Data, Val(dDecimal_Place("""" & strColumn & """")), False, False)
End If
Else
Data = Convert_Value_Format_To_Rs(Data, 0, False, False)
End If
Else
If dicDecimal_Place.ContainsKey("""" & strColumn & """") Then
Data = Convert_Value_Format_To_Rs(Data, Val(dDecimal_Place("""" & strColumn & """")), False, False)
Else
Data = Convert_Value_Format_To_Rs(Data, 0, False, False)
End If
End If
sVariableFormat = numFormat
ElseIf dData_Type.Item("""" & strColumn & """").ToLower Like "*date*" Then
If dData_Format.ContainsKey("""" & strColumn & """") Then
If Val(Data) > 0 Then
If dData_Format("""" & strColumn & """").ToString <> "" Then
Data = DateTime.FromOADate(Val(Data)).ToString(dData_Format("""" & strColumn & """")) '"dd-MMM-yy"
Else
If Val(Data) - Int(Val(Data)) > 0 AndAlso Int(Val(Data)) > 0 Then
Data = DateTime.FromOADate(Val(Data)).ToString("dd-MMM-yy HH:mm:ss") '"dd-MMM-yy"
ElseIf Val(Data) - Int(Val(Data)) > 0 AndAlso Int(Val(Data)) = 0 Then
Data = DateTime.FromOADate(Val(Data)).ToString("HH:mm:ss") '"dd-MMM-yy"
ElseIf Val(Data) > 0 AndAlso Int(Val(Data)) > 0 Then
Data = DateTime.FromOADate(Val(Data)).ToString("dd-MMM-yy") '"dd-MMM-yy"
Else
Data = ""
End If
End If
Else
Data = ""
End If
Else
If Val(Data) - Int(Val(Data)) > 0 AndAlso Int(Val(Data)) > 0 Then
Data = DateTime.FromOADate(Val(Data)).ToString("dd-MMM-yy HH:mm:ss") '"dd-MMM-yy"
ElseIf Val(Data) - Int(Val(Data)) > 0 AndAlso Int(Val(Data)) = 0 Then
Data = DateTime.FromOADate(Val(Data)).ToString("HH:mm:ss") '"dd-MMM-yy"
ElseIf Val(Data) > 0 AndAlso Int(Val(Data)) > 0 Then
Data = DateTime.FromOADate(Val(Data)).ToString("dd-MMM-yy") '"dd-MMM-yy"
Else
Data = ""
End If
End If
sVariableFormat = numFormat
Else
sVariableFormat = StrFormat
End If
Return Data
End Function
Private Sub Reset_Print()
StrFormat = New StringFormat
StrFormat.Alignment = StringAlignment.Near 'text horizontal alignment
StrFormat.LineAlignment = StringAlignment.Near 'Text vetical alignment
StrFormat.Trimming = StringTrimming.EllipsisCharacter
StrLeftCenterAlignment = New StringFormat
StrLeftCenterAlignment.Alignment = StringAlignment.Near 'text horizontal alignment
StrLeftCenterAlignment.LineAlignment = StringAlignment.Center 'Text vetical alignment
StrLeftCenterAlignment.Trimming = StringTrimming.EllipsisCharacter
StrCenterAlignment = New StringFormat
StrCenterAlignment.Alignment = StringAlignment.Center 'text horizontal alignment
StrCenterAlignment.LineAlignment = StringAlignment.Center 'Text vetical alignment
StrCenterAlignment.Trimming = StringTrimming.EllipsisCharacter
numFormat = New StringFormat
numFormat.Alignment = StringAlignment.Far
numFormat.LineAlignment = StringAlignment.Near
nCurrent_Col = 2
nCurrent_Row = 0
nRows = 0
nRowsChild = 0
nChildItems = 0
nCurrent_Copy = 0
Has_Child_Item = False
Has_More_Child_Item = False
nResetChildiLoop = 0
Is_Continue_Same_Item = False
nColCountChild = 0
nColCount = 0
nResetiLoop = 0
nDetailHeaderRepeat_Start = 0
PageNo = 0
NewPage = True
nPageNo = 0
nPrinted_Rows = 0
nHeader_Serial_No = 0
nDetail_Serial_No = 0
nGroup_Serial_No = 0
Is_Detail_Start = False
Is_Print_Summary = False
Is_Print_Grand_Total = False
dicPrevGroupingColumns.Clear()
dicPrevGroupingDetailColumns.Clear()
dicPrevHeaderColumnsValue.Clear()
dicSumOfHeaderColumns.Clear()
dicSumOfDetailColumns.Clear()
dicSumOfGroupColumns.Clear()
dicSumOfOverAllDetailColumns.Clear()
End Sub
Private Sub Print_Header_Footer_RTF_Part(ByVal e As PrintPageEventArgs, ByVal dataRow As DataRow, ByRef nHeader_RTF_Height As Integer, ByVal nMax_Width As Double, ByVal nMax_Height As Double, ByRef nHeight_Gap As Double, ByVal Header_Or_Footer As String)
Dim strHeader_Or_Footer As String = IIf(Header_Or_Footer = "H", "INVOICE_HEADER_FORMAT", "INVOICE_FOOTER_FORMAT")
Dim RTF_Height As Double = 0
If dataRow.Item(strHeader_Or_Footer) <> "" AndAlso dataRow.Item(strHeader_Or_Footer) <> "0" Then
Dim rtfHeader As New RichTextBox
Dim xRtfImage As New DrawRichTextBoxToBitmap
rtfHeader.Width = nPFSEach_Page_Width - leftMargin - nPFSRight_Margin
rtfHeader.WordWrap = True
rtfHeader.Rtf = dataRow.Item(strHeader_Or_Footer)
rtfHeader.Height = Get_RTF_Text_Height(rtfHeader)
RTF_Height = rtfHeader.Height
If RTF_Height > 0 Then
e.Graphics.DrawImage(xRtfImage.DrawRTB(rtfHeader), New Point(nMax_Width + leftMargin, nMax_Height + nHeight_Gap + 1))
End If
If Header_Or_Footer = "H" Then
If RTF_Height > (dataRow.Item("TOP_IMAGE_HEIGHT")) * 100 Then
'RTF_Height = (rtfHeader.Height - (dataRow.Item("TOP_IMAGE_HEIGHT")) * 100) + 1
ElseIf RTF_Height <= (dataRow.Item("TOP_IMAGE_HEIGHT")) * 100 Then
RTF_Height = (dataRow.Item("TOP_IMAGE_HEIGHT")) * 100 + 1
End If
Else
If RTF_Height > (dataRow.Item("BOTTOM_IMAGE_HEIGHT")) * 100 Then
'RTF_Height = (rtfHeader.Height - (dataRow.Item("BOTTOM_IMAGE_HEIGHT")) * 100) + 1
ElseIf RTF_Height <= (dataRow.Item("BOTTOM_IMAGE_HEIGHT")) * 100 Then
RTF_Height = (dataRow.Item("BOTTOM_IMAGE_HEIGHT")) * 100 + 1
End If
End If
'If nMax_Top < topMargin + nEnd + nEndMiscChargeTop + nCustomFieldEndTop + nHeader_RTF_Height + nFooter_RTF_Height Then '+ nMax_Height
' nMax_Top = topMargin + nEnd + nEndMiscChargeTop + nCustomFieldEndTop + nHeader_RTF_Height + nFooter_RTF_Height '+ nMax_Height
'End If
If Header_Or_Footer = "H" Then
If dataRow.Item("IMAGE_PATH_TOP").ToString() <> "" Then
Try
If IO.File.Exists(strFinnecalImagePath & "\User_Images\" & dataRow.Item("IMAGE_PATH_TOP").ToString()) Then
If Val(dataRow.Item("IMAGE_TOP_ALIGNMENT").ToString()) = 3 Then 'Right
e.Graphics.DrawImage(New Bitmap(strFinnecalImagePath & "\User_Images\" & dataRow.Item("IMAGE_PATH_TOP").ToString(), False), CInt(nMax_Width + nPFSEach_Page_Width - leftMargin - nPFSRight_Margin - dataRow.Item("TOP_IMAGE_WIDTH") * 100), CInt(nMax_Height + nHeight_Gap), dataRow.Item("TOP_IMAGE_WIDTH") * 100, dataRow.Item("TOP_IMAGE_HEIGHT") * 100)
ElseIf Val(dataRow.Item("IMAGE_TOP_ALIGNMENT").ToString()) = 2 Then 'Center
e.Graphics.DrawImage(New Bitmap(strFinnecalImagePath & "\User_Images\" & dataRow.Item("IMAGE_PATH_TOP").ToString(), False), CInt(nMax_Width + (nPFSEach_Page_Width - leftMargin - nPFSRight_Margin) / 2), CInt(nMax_Height + nHeight_Gap), (dataRow.Item("TOP_IMAGE_WIDTH")) * 100, (dataRow.Item("TOP_IMAGE_HEIGHT")) * 100)
Else 'LEFT
e.Graphics.DrawImage(New Bitmap(strFinnecalImagePath & "\User_Images\" & dataRow.Item("IMAGE_PATH_TOP").ToString(), False), CInt(nMax_Width + leftMargin), CInt(nMax_Height + nHeight_Gap), (dataRow.Item("TOP_IMAGE_WIDTH")) * 100, (dataRow.Item("TOP_IMAGE_HEIGHT")) * 100)
End If
End If
Catch ex As Exception
End Try
End If
Else
If dataRow.Item("IMAGE_PATH_BOTTOM").ToString() <> "" Then
Try
If IO.File.Exists(strFinnecalImagePath & "\User_Images\" & dataRow.Item("IMAGE_PATH_BOTTOM").ToString()) Then
If Val(dataRow.Item("IMAGE_BOTTOM_ALIGNMENT").ToString()) = 3 Then 'Right
e.Graphics.DrawImage(New Bitmap(strFinnecalImagePath & "\User_Images\" & dataRow.Item("IMAGE_PATH_BOTTOM").ToString(), False), CInt(nMax_Width + nPFSEach_Page_Width - leftMargin - nPFSRight_Margin - dataRow.Item("BOTTOM_IMAGE_WIDTH") * 100), CInt(nMax_Height + nHeight_Gap + 1), dataRow.Item("BOTTOM_IMAGE_WIDTH") * 100, dataRow.Item("BOTTOM_IMAGE_HEIGHT") * 100)
ElseIf Val(dataRow.Item("IMAGE_BOTTOM_ALIGNMENT").ToString()) = 2 Then 'Center
e.Graphics.DrawImage(New Bitmap(strFinnecalImagePath & "\User_Images\" & dataRow.Item("IMAGE_PATH_BOTTOM").ToString(), False), CInt(nMax_Width + (nPFSEach_Page_Width - leftMargin - nPFSRight_Margin) / 2), CInt(nMax_Height + nHeight_Gap + 1), (dataRow.Item("BOTTOM_IMAGE_WIDTH")) * 100, (dataRow.Item("BOTTOM_IMAGE_HEIGHT")) * 100)
Else 'LEFT
e.Graphics.DrawImage(New Bitmap(strFinnecalImagePath & "\User_Images\" & dataRow.Item("IMAGE_PATH_BOTTOM").ToString(), False), CInt(nMax_Width + leftMargin), CInt(nMax_Height + nHeight_Gap + 1), (dataRow.Item("BOTTOM_IMAGE_WIDTH")) * 100, (dataRow.Item("BOTTOM_IMAGE_HEIGHT")) * 100)
End If
End If
Catch ex As Exception
End Try
End If
End If
nHeader_RTF_Height = RTF_Height
nHeight_Gap = nHeight_Gap + nHeader_RTF_Height + 1
End If
End Sub
Private Sub Print_Header_Part(ByVal e As PrintPageEventArgs, ByVal dataRow As DataRow, ByRef nHeader_Height As Double, ByRef nHeight_Gap As Double)
Dim dvAddress_Fields As DataView = dPrint_Setting_Detail.Tables(0).AsDataView
Dim dvOther_Main_Fields As DataView = dPrint_Setting_Detail.Tables(0).AsDataView
Dim nInital_Top As Integer = 0
Dim nAddress_Height As Double = 0
Dim nAddress_Width As Double = 0
Dim nMain_Fields_Height As Integer = 0
Dim actualHeight As SizeF = Nothing
Dim actualHeight1 As SizeF = Nothing
Dim strData As String = ""
Dim Has_Negative_Value As Boolean = False
Dim nStart_Top As Integer = 0
Dim nEnd_Top As Integer = 0
Dim nStart_Left As Integer = 0
Dim nAddress_Left As Integer = 0
Dim nAddress_Top As Integer = 0
dvAddress_Fields.RowFilter = "Field_Type='ADDRESS'"
dvOther_Main_Fields.RowFilter = "Field_Type='MAIN'"
For iLoop = 0 To dvAddress_Fields.Count - 1
If iLoop = 0 Then
nAddress_Top = nHeight_Gap + nAddress_Height
nAddress_Left = leftMargin
End If
strData = dataRow(dvAddress_Fields.Item(iLoop).Item("FIELD_NAME")) & ""
actualHeight = e.Graphics.MeasureString(strData, printFontHeaderFooter, dvAddress_Fields.Item(iLoop).Item("WIDTH") * 100)
e.Graphics.DrawString(dataRow(dvAddress_Fields.Item(iLoop).Item("FIELD_NAME")) & "", printFontHeaderFooter, Brushes.Black, New RectangleF(leftMargin + 1 + nMax_Width, nHeight_Gap + nAddress_Height, dvAddress_Fields.Item(iLoop).Item("WIDTH") * 100, e.MarginBounds.Size.Height), StrFormat)
nAddress_Height = nAddress_Height + actualHeight.Height
nAddress_Width = dvAddress_Fields.Item(iLoop).Item("WIDTH") * 100
Next
If nAddress_Top > 0 Then
e.Graphics.DrawLine(Pens.Red, leftMargin, nAddress_Top, nPFSEach_Page_Width - nPFSRight_Margin, nAddress_Top)
End If
For iLoop = 0 To dvOther_Main_Fields.Count - 1
If iLoop = 0 Then
nStart_Top = nHeight_Gap + nMain_Fields_Height
nStart_Left = leftMargin + 1 + nAddress_Width
End If
strData = dvOther_Main_Fields.Item(iLoop).Item("FIELD_CAPTION")
actualHeight = e.Graphics.MeasureString(strData, printFontHeaderFooter, dvOther_Main_Fields.Item(iLoop).Item("WIDTH") * 100)
e.Graphics.DrawString(dvOther_Main_Fields.Item(iLoop).Item("FIELD_CAPTION"), printFontHeaderFooter, Brushes.Black, New RectangleF(leftMargin + 1 + nAddress_Width + nMax_Width, nHeight_Gap + nMain_Fields_Height, dvOther_Main_Fields.Item(iLoop).Item("WIDTH") * 100, e.MarginBounds.Size.Height), StrFormat)
strData = Get_Formatted_Data_From_Direct(dataRow(dvOther_Main_Fields.Item(iLoop).Item("FIELD_NAME")) & "", "", dvOther_Main_Fields.Item(iLoop).Item("DATA_TYPE") & "", Val(dvOther_Main_Fields.Item(iLoop).Item("DECIMAL_PLACES") & ""), StrVariableFormat, Has_Negative_Value)
actualHeight1 = e.Graphics.MeasureString(strData, printFont, dvOther_Main_Fields.Item(iLoop).Item("WIDTH") * 100)
e.Graphics.DrawString(strData, printFont, Brushes.Black, New RectangleF(leftMargin + 1 + nAddress_Width + dvOther_Main_Fields.Item(iLoop).Item("WIDTH") * 100 + nMax_Width, nHeight_Gap + nMain_Fields_Height, dvOther_Main_Fields.Item(iLoop).Item("WIDTH") * 100, e.MarginBounds.Size.Height), StrVariableFormat)
If actualHeight.Height > actualHeight1.Height Then
nMain_Fields_Height = nMain_Fields_Height + actualHeight.Height
Else
nMain_Fields_Height = nMain_Fields_Height + actualHeight1.Height
End If
Next
If nStart_Top > 0 Then
e.Graphics.DrawLine(Pens.Red, CInt(nMax_Width) + nStart_Left, nStart_Top, nStart_Left, nStart_Top + CInt(nMain_Fields_Height))
e.Graphics.DrawLine(Pens.Red, CInt(nMax_Width) + leftMargin, nStart_Top, leftMargin, nStart_Top + CInt(nMain_Fields_Height))
e.Graphics.DrawLine(Pens.Red, CInt(nMax_Width) + nPFSEach_Page_Width - nPFSRight_Margin, nStart_Top, nPFSEach_Page_Width - nPFSRight_Margin, nStart_Top + CInt(nMain_Fields_Height))
e.Graphics.DrawLine(Pens.Red, CInt(nMax_Width) + leftMargin, nStart_Top + CInt(nMain_Fields_Height), nPFSEach_Page_Width - nPFSRight_Margin, nStart_Top + CInt(nMain_Fields_Height))
nStart_Top = 0
nStart_Left = 0
nAddress_Top = 0
nAddress_Left = 0
End If
If nAddress_Height > nMain_Fields_Height Then
nHeight_Gap = nHeight_Gap + nAddress_Height
Else
nHeight_Gap = nHeight_Gap + nMain_Fields_Height
End If
End Sub
Private Sub Print_Custom_Fields_Part(ByVal e As PrintPageEventArgs, ByVal dataRow As DataTable, ByRef nCustom_Field_Height As Double, ByRef nHeight_Gap As Double)
Dim dvCustom As DataView = dPrint_Setting_Detail.Tables(0).AsDataView
Dim nInital_Top As Integer = 0
Dim nCustom_Height As Double = 0
Dim nCustom_Width As Double = 0
Dim nCustom_Field_Start_Top As Integer = 0
Dim nCustom_Field_Start_Left As Integer = 0
Dim nCustom_Field_Second_Start_Left As Integer = 0
Dim actualHeight As SizeF = Nothing
Dim actualHeight1 As SizeF = Nothing
Dim strData As String = ""
Dim Has_Negative_Value As Boolean = False
Dim nFirst_Custom_Field_Height As Double = 0
Dim nSecond_Custom_Field_Height As Double = 0
dvCustom.RowFilter = "Field_Type='CUSTOM'"
For iLoop = 0 To dvCustom.Count - 1
If iLoop = 0 Then
nCustom_Field_Start_Left = leftMargin
nCustom_Field_Start_Top = nHeight_Gap + nCustom_Field_Height
End If
For nCustom = 0 To dataRow.Rows.Count - 1
If dvCustom.Item(iLoop).Item("MISC_CHARGE_OR_CUSTOM_FIELD_ID") = dataRow.Rows(nCustom)("CUSTOM_FIELD_IDS") Then
strData = dataRow.Rows(nCustom)("CUSTOM_FIELD_VALUE") & ""
Exit For
End If
Next
If iLoop Mod 2 = 0 Then
actualHeight = e.Graphics.MeasureString(dvCustom.Item(iLoop).Item("FIELD_CAPTION"), printFontHeaderFooter, dvCustom.Item(iLoop).Item("WIDTH") * 100)
e.Graphics.DrawString(dvCustom.Item(iLoop).Item("FIELD_CAPTION"), printFontHeaderFooter, Brushes.Black, New RectangleF(leftMargin + 1 + nCustom_Width + nMax_Width, nHeight_Gap + nCustom_Field_Height, dvCustom.Item(iLoop).Item("WIDTH") * 100, e.MarginBounds.Size.Height), StrFormat)
nCustom_Width = dvCustom.Item(iLoop).Item("WIDTH") * 100
strData = Get_Formatted_Data_From_Direct(strData, "", dvCustom.Item(iLoop).Item("DATA_TYPE") & "", Val(dvCustom.Item(iLoop).Item("DECIMAL_PLACES") & ""), StrVariableFormat, Has_Negative_Value)
actualHeight1 = e.Graphics.MeasureString(strData, printFont, dvCustom.Item(iLoop).Item("WIDTH") * 100)
e.Graphics.DrawString(strData, printFont, Brushes.Black, New RectangleF(leftMargin + 1 + nCustom_Width + nMax_Width, nHeight_Gap + nCustom_Field_Height, dvCustom.Item(iLoop).Item("WIDTH") * 100, e.MarginBounds.Size.Height), StrVariableFormat)
nCustom_Width = nCustom_Width + dvCustom.Item(iLoop).Item("WIDTH") * 100
If actualHeight.Height > actualHeight1.Height Then
nFirst_Custom_Field_Height = actualHeight.Height
Else
nFirst_Custom_Field_Height = actualHeight1.Height
End If
If iLoop = dvCustom.Count - 1 Then
nCustom_Field_Height = nCustom_Field_Height + nFirst_Custom_Field_Height
End If
Else
If iLoop = 1 Then
nCustom_Field_Second_Start_Left = leftMargin + 1 + nCustom_Width
End If
actualHeight = e.Graphics.MeasureString(dvCustom.Item(iLoop).Item("FIELD_CAPTION"), printFontHeaderFooter, dvCustom.Item(iLoop).Item("WIDTH") * 100)
e.Graphics.DrawString(dvCustom.Item(iLoop).Item("FIELD_CAPTION"), printFontHeaderFooter, Brushes.Black, New RectangleF(leftMargin + 1 + nCustom_Width + nMax_Width, nHeight_Gap + nCustom_Field_Height, dvCustom.Item(iLoop).Item("WIDTH") * 100, e.MarginBounds.Size.Height), StrFormat)
nCustom_Width = dvCustom.Item(iLoop).Item("WIDTH") * 100
strData = Get_Formatted_Data_From_Direct(strData, "", dvCustom.Item(iLoop).Item("DATA_TYPE") & "", Val(dvCustom.Item(iLoop).Item("DECIMAL_PLACES") & ""), StrVariableFormat, Has_Negative_Value)
actualHeight1 = e.Graphics.MeasureString(strData, printFont, dvCustom.Item(iLoop).Item("WIDTH") * 100)
e.Graphics.DrawString(strData, printFont, Brushes.Black, New RectangleF(leftMargin + 1 + nCustom_Width + nMax_Width, nHeight_Gap + nCustom_Field_Height, dvCustom.Item(iLoop).Item("WIDTH") * 100, e.MarginBounds.Size.Height), StrVariableFormat)
If actualHeight.Height > actualHeight1.Height Then
nSecond_Custom_Field_Height = actualHeight.Height
Else
nSecond_Custom_Field_Height = actualHeight1.Height
End If
If nFirst_Custom_Field_Height > nSecond_Custom_Field_Height Then
nCustom_Field_Height = nCustom_Field_Height + nFirst_Custom_Field_Height
Else
nCustom_Field_Height = nCustom_Field_Height + nSecond_Custom_Field_Height
End If
nFirst_Custom_Field_Height = 0
nSecond_Custom_Field_Height = 0
nCustom_Width = 0
End If
Next
If nCustom_Field_Start_Top > 0 Then
e.Graphics.DrawLine(Pens.Red, CInt(nMax_Width) + leftMargin, nCustom_Field_Start_Top, leftMargin, nCustom_Field_Start_Top + CInt(nCustom_Field_Height))
e.Graphics.DrawLine(Pens.Red, CInt(nMax_Width) + nCustom_Field_Second_Start_Left, nCustom_Field_Start_Top, nCustom_Field_Second_Start_Left, nCustom_Field_Start_Top + CInt(nCustom_Field_Height))
e.Graphics.DrawLine(Pens.Red, CInt(nMax_Width) + nPFSEach_Page_Width - nPFSRight_Margin, nCustom_Field_Start_Top, nPFSEach_Page_Width - nPFSRight_Margin, nCustom_Field_Start_Top + CInt(nCustom_Field_Height))
End If
nHeight_Gap = nHeight_Gap + nCustom_Field_Height
End Sub
Private Sub Print_Misc_Charges_Part(ByVal e As PrintPageEventArgs, ByVal dataDetail As DataSet, ByRef nMisc_Charge_Height As Double, ByRef nHeight_Gap As Double, ByVal settingDataRow As DataRow)
Dim dvCustom As DataView = dPrint_Setting_Detail.Tables(0).AsDataView
Dim nInital_Top As Integer = 0
Dim nCharge_Width As Double = 100
Dim nCharge_Caption_Width As Double = 0
Dim nMisc_Charge_Start_Top As Integer = 0
Dim nMisc_Charge_Start_Left As Integer = 0
Dim actualHeight As SizeF = Nothing
Dim actualHeight1 As SizeF = Nothing
Dim strData As String = ""
Dim Has_Negative_Value As Boolean = False
Dim nFirst_Custom_Field_Height As Double = 0
Dim nSecond_Custom_Field_Height As Double = 0
Dim nMisc_Charge_Caption_End_Left As Integer = 0
'eachpagewidth-field width*2
dvCustom.RowFilter = "Field_Type='CAL'"
'dataRow.Rows(iLoop)(dvCustom.Item(iLoop).Item("FIELD_NAME"))
For iLoop = 0 To dvCustom.Count - 1
nCharge_Caption_Width = nPFSEach_Page_Width - dvCustom.Item(iLoop).Item("WIDTH") * 100 - leftMargin - nPFSRight_Margin - nCharge_Width
If iLoop = 0 Then
nMisc_Charge_Start_Top = nHeight_Gap
nMisc_Charge_Start_Left = nCharge_Caption_Width + nMax_Width
nMisc_Charge_Caption_End_Left = dvCustom.Item(iLoop).Item("WIDTH") * 100
e.Graphics.DrawString("Grand Total In Words", printFontHeaderFooter, Brushes.Black, New RectangleF(leftMargin + nMax_Width, nHeight_Gap, nCharge_Caption_Width - leftMargin, e.MarginBounds.Size.Height), StrFormat)
actualHeight = e.Graphics.MeasureString("Grand Total In Words", printFontHeaderFooter, nCharge_Caption_Width - leftMargin)
e.Graphics.DrawString(Number_To_Word(Val(dataDetail.Tables("T_SALE_PURCHASE").Rows(0)(dtrPrint_Setting.Item("NUMBER_TO_WORD_FIELD")) & "")), printFontDetail, Brushes.Black, New RectangleF(leftMargin + 1 + nMax_Width, nHeight_Gap + actualHeight.Height, nCharge_Caption_Width, e.MarginBounds.Size.Height), StrFormat)
End If
If dvCustom.Item(iLoop).Item("HAS_LINE") = "Y" Then
e.Graphics.DrawLine(Pens.Red, CInt(nMax_Width + nCharge_Caption_Width), CInt(nHeight_Gap + nMisc_Charge_Height), nPFSEach_Page_Width - nPFSRight_Margin, CInt(nHeight_Gap + nMisc_Charge_Height))
End If
strData = dvCustom.Item(iLoop).Item("FIELD_CAPTION")
actualHeight = e.Graphics.MeasureString(strData, printFontHeaderFooter, dvCustom.Item(iLoop).Item("WIDTH") * 100)
e.Graphics.DrawString(dvCustom.Item(iLoop).Item("FIELD_CAPTION"), printFontHeaderFooter, Brushes.Black, New RectangleF(nCharge_Caption_Width + nMax_Width, nHeight_Gap + nMisc_Charge_Height, dvCustom.Item(iLoop).Item("WIDTH") * 100, e.MarginBounds.Size.Height), StrFormat)
If dvCustom.Item(iLoop).Item("TABLE_NAME") = "TC_CHARGES" Then
For iCharges = 0 To dataDetail.Tables("TC_CHARGES").Rows.Count - 1
If dataDetail.Tables("TC_CHARGES").Rows(iCharges)("MISC_CHARGE_IDS") = dvCustom.Item(iLoop).Item("MISC_CHARGE_OR_CUSTOM_FIELD_ID") Then
strData = Get_Formatted_Data_From_Direct(dataDetail.Tables("TC_CHARGES").Rows(iCharges)("PERCENTAGE_VALUE") & "", "", dvCustom.Item(iLoop).Item("DATA_TYPE") & "", Val(dvCustom.Item(iLoop).Item("DECIMAL_PLACES") & ""), StrVariableFormat, Has_Negative_Value)
e.Graphics.DrawString(strData, printFont, Brushes.Black, New RectangleF(nMax_Width + nCharge_Caption_Width + 10, nHeight_Gap + nMisc_Charge_Height, nCharge_Width + 10, e.MarginBounds.Size.Height), StrVariableFormat)
strData = Get_Formatted_Data_From_Direct(dataDetail.Tables("TC_CHARGES").Rows(iCharges)("CHARGE_VALUE") & "", "", dvCustom.Item(iLoop).Item("DATA_TYPE") & "", Val(dvCustom.Item(iLoop).Item("DECIMAL_PLACES") & ""), StrVariableFormat, Has_Negative_Value)
Exit For
End If
Next
Else
strData = Get_Formatted_Data_From_Direct(dataDetail.Tables(dvCustom.Item(iLoop).Item("TABLE_NAME")).Rows(0).Item(dvCustom.Item(iLoop).Item("FIELD_NAME")) & "", "", dvCustom.Item(iLoop).Item("DATA_TYPE") & "", Val(dvCustom.Item(iLoop).Item("DECIMAL_PLACES") & ""), StrVariableFormat, Has_Negative_Value)
End If
'nPFSEach_Page_Width - leftMargin - nPFSRight_Margin
actualHeight1 = e.Graphics.MeasureString(strData, printFont, nCharge_Width)
e.Graphics.DrawString(strData, printFont, Brushes.Black, New RectangleF(nMax_Width + nPFSEach_Page_Width - nCharge_Width - nPFSRight_Margin, nHeight_Gap + nMisc_Charge_Height, nCharge_Width, e.MarginBounds.Size.Height), StrVariableFormat)
If actualHeight.Height > actualHeight1.Height Then
nMisc_Charge_Height = nMisc_Charge_Height + actualHeight.Height
Else
nMisc_Charge_Height = nMisc_Charge_Height + actualHeight1.Height
End If
Next
If nMisc_Charge_Start_Top > 0 Then
e.Graphics.DrawLine(Pens.Red, leftMargin + CInt(nMax_Width), nMisc_Charge_Start_Top, leftMargin + CInt(nMax_Width), nMisc_Charge_Start_Top + CInt(nMisc_Charge_Height))
e.Graphics.DrawLine(Pens.Red, nMisc_Charge_Start_Left + CInt(nMax_Width), nMisc_Charge_Start_Top, nMisc_Charge_Start_Left + CInt(nMax_Width), nMisc_Charge_Start_Top + CInt(nMisc_Charge_Height))
e.Graphics.DrawLine(Pens.Red, nPFSEach_Page_Width - nPFSRight_Margin + CInt(nMax_Width), nMisc_Charge_Start_Top, nPFSEach_Page_Width - nPFSRight_Margin + CInt(nMax_Width), nMisc_Charge_Start_Top + CInt(nMisc_Charge_Height))
e.Graphics.DrawLine(Pens.Red, nMisc_Charge_Start_Left + nMisc_Charge_Caption_End_Left + CInt(nMax_Width), nMisc_Charge_Start_Top, nMisc_Charge_Start_Left + nMisc_Charge_Caption_End_Left + CInt(nMax_Width), nMisc_Charge_Start_Top + CInt(nMisc_Charge_Height))
e.Graphics.DrawLine(Pens.Red, leftMargin + CInt(nMax_Width), nMisc_Charge_Start_Top + CInt(nMisc_Charge_Height), nPFSEach_Page_Width - nPFSRight_Margin, nMisc_Charge_Start_Top + CInt(nMisc_Charge_Height))
End If
nHeight_Gap = nHeight_Gap + nMisc_Charge_Height
End Sub
Private Sub Get_Footer_Height(ByRef nFooterHeight As Integer, ByRef nFooter_RTF_Height As Integer, ByVal dataDetail As DataSet, ByVal dsPrint_Setting_Detail As DataSet)
Dim dvCustom As DataView = dPrint_Setting_Detail.Tables(0).AsDataView
Dim nInital_Top As Integer = 0
Dim nCharge_Width As Double = 100
Dim nCharge_Caption_Width As Double = 0
Dim nMisc_Charge_Start_Top As Integer = 0
Dim nMisc_Charge_Start_Left As Integer = 0
Dim nMisc_Charge_Height As Double = 0
Dim actualHeight As SizeF = Nothing
Dim actualHeight1 As SizeF = Nothing
Dim strData As String = ""
Dim Has_Negative_Value As Boolean = False
Dim nFirst_Custom_Field_Height As Double = 0
Dim nSecond_Custom_Field_Height As Double = 0
Dim nMisc_Charge_Caption_End_Left As Integer = 0
Dim strHeader_Or_Footer As String = "INVOICE_FOOTER_FORMAT"
Dim datarow As DataRow = dataDetail.Tables("T_FORMAT").Rows(0)
Dim RTF_Height As Double = 0
If DataRow.Item(strHeader_Or_Footer) <> "" AndAlso DataRow.Item(strHeader_Or_Footer) <> "0" Then
Dim rtfHeader As New RichTextBox
Dim xRtfImage As New DrawRichTextBoxToBitmap
rtfHeader.Width = nPFSEach_Page_Width
rtfHeader.WordWrap = True
rtfHeader.Rtf = DataRow.Item(strHeader_Or_Footer)
rtfHeader.Height = Get_RTF_Text_Height(rtfHeader)
RTF_Height = rtfHeader.Height
If RTF_Height > (DataRow.Item("BOTTOM_IMAGE_HEIGHT")) * 100 Then
RTF_Height = (rtfHeader.Height - (datarow.Item("BOTTOM_IMAGE_HEIGHT")) * 100) + 1
ElseIf RTF_Height <= (datarow.Item("BOTTOM_IMAGE_HEIGHT")) * 100 Then
RTF_Height = (datarow.Item("BOTTOM_IMAGE_HEIGHT")) * 100 + 1
End If
End If
nFooter_RTF_Height = RTF_Height
dvCustom.RowFilter = "Field_Type='CAL'"
For iLoop = 0 To dvCustom.Count - 1
If dvCustom.Item(iLoop).Item("TABLE_NAME") = "TC_CHARGES" Then
For iCharges = 0 To dataDetail.Tables("TC_CHARGES").Rows.Count - 1
If dataDetail.Tables("TC_CHARGES").Rows(iCharges)("MISC_CHARGE_IDS") = dvCustom.Item(iLoop).Item("MISC_CHARGE_OR_CUSTOM_FIELD_ID") Then
nMisc_Charge_Height = nMisc_Charge_Height + printFontHeaderFooter.Height
Exit For
End If
Next
Else
nMisc_Charge_Height = nMisc_Charge_Height + printFontHeaderFooter.Height
End If
Next
nFooterHeight = nMisc_Charge_Height
End Sub
Private Sub PrintDoc_QueryPageSettings(ByVal sender As Object, ByVal e As System.Drawing.Printing.QueryPageSettingsEventArgs) Handles PrintDoc.QueryPageSettings
'Dim prn As PrintDocument = DirectCast(sender, PrintDocument)
'Dim xHard As Integer = CType(e.PageSettings.HardMarginX, Integer)
'Dim yHard As Integer = CType(e.PageSettings.HardMarginY, Integer)
'If prn.PrintController.IsPreview Then
' PrintDoc.DefaultPageSettings.Margins.Left = xHard 'nPFSLeft_Margin
' 'PrintDoc.DefaultPageSettings.Margins.Right = nPFSRight_Margin
' PrintDoc.DefaultPageSettings.Margins.Top = yHard 'nPFSTop_Margin
' 'PrintDoc.DefaultPageSettings.Margins.Bottom = nPFSBottom_Margin
' 'mMarginLeft = xHard
' 'mMarginTop = yHard
'Else
' PrintDoc.DefaultPageSettings.Margins.Left = 0
' PrintDoc.DefaultPageSettings.Margins.Right = 0
' PrintDoc.DefaultPageSettings.Margins.Top = 0
' PrintDoc.DefaultPageSettings.Margins.Bottom = 0
' 'mMarginLeft = 0
' 'mMarginTop = 0
'End If
End Sub
End Class