Custom Paper Size Printing in VB.NET
Advance Printing using Ms-Access Database Setting with Schemes
For Custom Paper Size
Vb.net Source Code Part One
Dbf.Open("select * from printlines where schemename='" & PrintingScheme & "'", Conn, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic) If Dbf.RecordCount > 0 Then Dbf.MoveFirst() For i As Integer = 0 To Dbf.RecordCount - 1 If Dbf.Fields("IsVisible").Value = True Then Dim penstyle As New Pen(Color.FromName(Dbf.Fields("LineColor").Value), CSng(Dbf.Fields("BoarderWidth").Value)) If Dbf.Fields("BoarderStyle").Value = "Solid" Then penstyle.DashStyle = Drawing2D.DashStyle.Solid ElseIf Dbf.Fields("BoarderStyle").Value = "Dash" Then penstyle.DashStyle = Drawing2D.DashStyle.Dash ElseIf Dbf.Fields("BoarderStyle").Value = "Dot" Then penstyle.DashStyle = Drawing2D.DashStyle.Dot ElseIf Dbf.Fields("BoarderStyle").Value = "DashDot" Then penstyle.DashStyle = Drawing2D.DashStyle.DashDot Else penstyle.DashStyle = Drawing2D.DashStyle.DashDotDot End If If Dbf.Fields("FieldType").Value = 0 Then e.Graphics.DrawLine(penstyle, CSng(Dbf.Fields("left").Value), CSng(Dbf.Fields("top").Value), CSng(Dbf.Fields("width").Value), CSng(Dbf.Fields("height").Value)) Else e.Graphics.DrawRectangle(penstyle, CSng(Dbf.Fields("left").Value), CSng(Dbf.Fields("top").Value), CSng(Dbf.Fields("width").Value), CSng(Dbf.Fields("height").Value)) End If End If Dbf.MoveNext() Next End If Dbf.Close() If PageNo = PageNos Then Dbf.Open("select * from PrintFieldLabels where schemename='" & PrintingScheme & "' ", Conn, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic) Else Dbf.Open("select * from PrintFieldLabels where schemename='" & PrintingScheme & "' and ltop<" & FooterTop, Conn, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic) End If ' Dbf.Open("select * from PrintFieldLabels where schemename='" & PrintingScheme & "' and ltop<" & FooterTop, Conn, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic) If Dbf.RecordCount > 0 Then Dbf.MoveFirst() For i As Integer = 0 To Dbf.RecordCount - 1 If Dbf.Fields("IsVisible").Value = True Then Dim drawFormat As New StringFormat Dim drawFont As Font = New Font("arial", 10) Dim drawBrush As New SolidBrush(Color.FromName(Dbf.Fields("fontcolor").Value.ToString)) Select Case Dbf.Fields("fontstyle").Value Case 1 drawFont = New Font(Dbf.Fields("Fontname").Value.ToString, CSng(Dbf.Fields("fontsize").Value), FontStyle.Bold) Case 2 drawFont = New Font(Dbf.Fields("Fontname").Value.ToString, CSng(Dbf.Fields("fontsize").Value), FontStyle.Italic) Case 3 drawFont = New Font(Dbf.Fields("Fontname").Value.ToString, CSng(Dbf.Fields("fontsize").Value), FontStyle.Underline) Case 4 drawFont = New Font(Dbf.Fields("Fontname").Value.ToString, CSng(Dbf.Fields("fontsize").Value), FontStyle.Bold Or FontStyle.Italic) Case 5 drawFont = New Font(Dbf.Fields("Fontname").Value.ToString, CSng(Dbf.Fields("fontsize").Value), FontStyle.Bold Or FontStyle.Underline) Case 6 drawFont = New Font(Dbf.Fields("Fontname").Value.ToString, CSng(Dbf.Fields("fontsize").Value), FontStyle.Italic Or FontStyle.Underline) Case 7 drawFont = New Font(Dbf.Fields("Fontname").Value.ToString, CSng(Dbf.Fields("fontsize").Value), FontStyle.Bold Or FontStyle.Italic Or FontStyle.Underline) Case 8 drawFont = New Font(Dbf.Fields("Fontname").Value.ToString, CSng(Dbf.Fields("fontsize").Value), FontStyle.Regular) End Select If Dbf.Fields("align").Value = "Left" Then drawFormat.Alignment = StringAlignment.Near ElseIf Dbf.Fields("align").Value = "Right" Then drawFormat.Alignment = StringAlignment.Far Else drawFormat.Alignment = StringAlignment.Center End If If CSng(Dbf.Fields("width").Value) > 100 Then Dim rect1 As New Rectangle(CSng(Dbf.Fields("left").Value), CSng(Dbf.Fields("top").Value), CSng(Dbf.Fields("width").Value), CSng(Dbf.Fields("height").Value)) If Dbf.Fields("formattype").Value = 0 Then e.Graphics.DrawString(Dbf.Fields("printtext").Value.ToString, drawFont, drawBrush, rect1, drawFormat) Else e.Graphics.DrawString(FormatNumber(Dbf.Fields("printtext").Value, 2).ToString, drawFont, drawBrush, rect1, drawFormat) End If Else If Dbf.Fields("formattype").Value = 0 Then e.Graphics.DrawString(Dbf.Fields("printtext").Value.ToString, drawFont, drawBrush, CSng(Dbf.Fields("left").Value), CSng(Dbf.Fields("top").Value), drawFormat) Else Try e.Graphics.DrawString(FormatNumber(Dbf.Fields("printtext").Value, 2).ToString, drawFont, drawBrush, CSng(Dbf.Fields("left").Value), CSng(Dbf.Fields("top").Value), drawFormat) Catch ex As Exception e.Graphics.DrawString(Dbf.Fields("printtext").Value.ToString, drawFont, drawBrush, CSng(Dbf.Fields("left").Value), CSng(Dbf.Fields("top").Value), drawFormat) End Try End If End If 'If Dbf.Fields("formattype").Value = 0 Then 'e.Graphics.DrawString(Dbf.Fields("printtext").Value.ToString, drawFont, drawBrush, CSng(Dbf.Fields("left").Value), CSng(Dbf.Fields("top").Value), drawFormat) 'Else ' e.Graphics.DrawString(FormatNumber(Dbf.Fields("printtext").Value, 2).ToString, drawFont, drawBrush, CSng(Dbf.Fields("left").Value), CSng(Dbf.Fields("top").Value), drawFormat) 'End If Select Case Dbf.Fields("lfontstyle").Value Case 1 drawFont = New Font(Dbf.Fields("lFontname").Value.ToString, CSng(Dbf.Fields("lfontsize").Value), FontStyle.Bold) Case 2 drawFont = New Font(Dbf.Fields("lFontname").Value.ToString, CSng(Dbf.Fields("lfontsize").Value), FontStyle.Italic) Case 3 drawFont = New Font(Dbf.Fields("lFontname").Value.ToString, CSng(Dbf.Fields("lfontsize").Value), FontStyle.Underline) Case 4 drawFont = New Font(Dbf.Fields("lFontname").Value.ToString, CSng(Dbf.Fields("lfontsize").Value), FontStyle.Bold Or FontStyle.Italic) Case 5 drawFont = New Font(Dbf.Fields("lFontname").Value.ToString, CSng(Dbf.Fields("lfontsize").Value), FontStyle.Bold Or FontStyle.Underline) Case 6 drawFont = New Font(Dbf.Fields("lFontname").Value.ToString, CSng(Dbf.Fields("lfontsize").Value), FontStyle.Italic Or FontStyle.Underline) Case 7 drawFont = New Font(Dbf.Fields("lFontname").Value.ToString, CSng(Dbf.Fields("lfontsize").Value), FontStyle.Bold Or FontStyle.Italic Or FontStyle.Underline) Case 8 drawFont = New Font(Dbf.Fields("lFontname").Value.ToString, CSng(Dbf.Fields("lfontsize").Value), FontStyle.Regular) End Select drawBrush.Color = Color.FromName(Dbf.Fields("lfontcolor").Value.ToString) If Dbf.Fields("lalign").Value = "Left" Then drawFormat.Alignment = StringAlignment.Near ElseIf Dbf.Fields("lalign").Value = "Right" Then drawFormat.Alignment = StringAlignment.Far Else drawFormat.Alignment = StringAlignment.Center End If e.Graphics.DrawString(Dbf.Fields("labletext").Value.ToString, drawFont, drawBrush, CSng(Dbf.Fields("lleft").Value), CSng(Dbf.Fields("ltop").Value), drawFormat) End If Dbf.MoveNext() Next End If Dbf.Close() Dbf.Open("select * from Printrecords where schemename='" & PrintingScheme & "'", Conn, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic) If Dbf.RecordCount > 0 Then Dbf.MoveFirst() For i As Integer = 0 To Dbf.RecordCount - 1 If Dbf.Fields("IsVisible").Value = True Then Dim drawFormat As New StringFormat Dim drawFont As Font = New Font("arial", 10) Dim drawBrush As New SolidBrush(Color.FromName(Dbf.Fields("lfontcolor").Value.ToString)) Select Case Dbf.Fields("lfontstyle").Value Case 1 drawFont = New Font(Dbf.Fields("lFontname").Value.ToString, CSng(Dbf.Fields("lfontsize").Value), FontStyle.Bold) Case 2 drawFont = New Font(Dbf.Fields("lFontname").Value.ToString, CSng(Dbf.Fields("lfontsize").Value), FontStyle.Italic) Case 3 drawFont = New Font(Dbf.Fields("lFontname").Value.ToString, CSng(Dbf.Fields("lfontsize").Value), FontStyle.Underline) Case 4 drawFont = New Font(Dbf.Fields("lFontname").Value.ToString, CSng(Dbf.Fields("lfontsize").Value), FontStyle.Bold Or FontStyle.Italic) Case 5 drawFont = New Font(Dbf.Fields("lFontname").Value.ToString, CSng(Dbf.Fields("lfontsize").Value), FontStyle.Bold Or FontStyle.Underline) Case 6 drawFont = New Font(Dbf.Fields("lFontname").Value.ToString, CSng(Dbf.Fields("lfontsize").Value), FontStyle.Italic Or FontStyle.Underline) Case 7 drawFont = New Font(Dbf.Fields("lFontname").Value.ToString, CSng(Dbf.Fields("lfontsize").Value), FontStyle.Bold Or FontStyle.Italic Or FontStyle.Underline) Case 8 drawFont = New Font(Dbf.Fields("lFontname").Value.ToString, CSng(Dbf.Fields("lfontsize").Value), FontStyle.Regular) End Select If Dbf.Fields("lalign").Value = "Left" Then drawFormat.Alignment = StringAlignment.Near ElseIf Dbf.Fields("lalign").Value = "Right" Then drawFormat.Alignment = StringAlignment.Far Else drawFormat.Alignment = StringAlignment.Center End If e.Graphics.DrawString(Dbf.Fields("labletext").Value.ToString, drawFont, drawBrush, CSng(Dbf.Fields("lleft").Value), CSng(Dbf.Fields("ltop").Value), drawFormat) End If Dbf.MoveNext() Next End If Dbf.Close() For ri As Integer = 1 To pagerecords Try Dim k As String = PrtDbf.Fields("stockname").Value Catch ex As Exception GoTo SSS End Try Dbf.Open("select * from Printrecords where schemename='" & PrintingScheme & "'", Conn, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic) If Dbf.RecordCount > 0 Then Dbf.MoveFirst() For i As Integer = 0 To Dbf.RecordCount - 1 If Dbf.Fields("IsVisible").Value = True Then Dim drawFormat As New StringFormat Dim drawFont As Font = New Font("arial", 10) Dim drawBrush As New SolidBrush(Color.FromName(Dbf.Fields("fontcolor").Value.ToString)) Select Case Dbf.Fields("fontstyle").Value Case 1 drawFont = New Font(Dbf.Fields("Fontname").Value.ToString, CSng(Dbf.Fields("fontsize").Value), FontStyle.Bold) Case 2 drawFont = New Font(Dbf.Fields("Fontname").Value.ToString, CSng(Dbf.Fields("fontsize").Value), FontStyle.Italic) Case 3 drawFont = New Font(Dbf.Fields("Fontname").Value.ToString, CSng(Dbf.Fields("fontsize").Value), FontStyle.Underline) Case 4 drawFont = New Font(Dbf.Fields("Fontname").Value.ToString, CSng(Dbf.Fields("fontsize").Value), FontStyle.Bold Or FontStyle.Italic) Case 5 drawFont = New Font(Dbf.Fields("Fontname").Value.ToString, CSng(Dbf.Fields("fontsize").Value), FontStyle.Bold Or FontStyle.Underline) Case 6 drawFont = New Font(Dbf.Fields("Fontname").Value.ToString, CSng(Dbf.Fields("fontsize").Value), FontStyle.Italic Or FontStyle.Underline) Case 7 drawFont = New Font(Dbf.Fields("Fontname").Value.ToString, CSng(Dbf.Fields("fontsize").Value), FontStyle.Bold Or FontStyle.Italic Or FontStyle.Underline) Case 8 drawFont = New Font(Dbf.Fields("Fontname").Value.ToString, CSng(Dbf.Fields("fontsize").Value), FontStyle.Regular) End Select If Dbf.Fields("align").Value = "Left" Then drawFormat.Alignment = StringAlignment.Near ElseIf Dbf.Fields("align").Value = "Right" Then drawFormat.Alignment = StringAlignment.Far Else drawFormat.Alignment = StringAlignment.Center End If If UCase(Dbf.Fields("DBField").Value.ToString) <> "SNO" Then If Dbf.Fields("formattype").Value = 0 Then e.Graphics.DrawString(PrtDbf.Fields(Dbf.Fields("DBField").Value.ToString).Value.ToString, drawFont, drawBrush, CSng(Dbf.Fields("left").Value), PageTop, drawFormat) Else e.Graphics.DrawString(FormatNumber(PrtDbf.Fields(Dbf.Fields("DBField").Value).Value, 2).ToString, drawFont, drawBrush, CSng(Dbf.Fields("left").Value), PageTop, drawFormat) End If Else e.Graphics.DrawString(PresentRecords, drawFont, drawBrush, CSng(Dbf.Fields("left").Value), PageTop, drawFormat) End If End If Dbf.MoveNext() Next End If Dbf.Close() PageTotal = PageTotal + PrtDbf.Fields("StockAmount").Value Try PageTop = PageTop + RowHeight PresentRecords = PresentRecords + 1 PrtDbf.MoveNext() Catch ex As Exception PresentRecords = PrtDbf.RecordCount GoTo sss End Try Next SSS: Dbf.Open("select * from PrintingSettings where schemename='" & PrintingScheme & "'", Conn, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic) If Dbf.RecordCount > 0 Then If Dbf.Fields("showpageno").Value = True Then If Dbf.Fields("pageformat").Value = 0 Then e.Graphics.DrawString("Page " & PageNo.ToString, New Font("Arial", 10, FontStyle.Bold), Brushes.Black, CSng(Dbf.Fields("pagenoleft").Value), CSng(Dbf.Fields("pagenotop").Value)) Else e.Graphics.DrawString("Page " & PageNo.ToString & " of " & PageNos.ToString, New Font("Arial", 10, FontStyle.Bold), Brushes.Black, CSng(Dbf.Fields("pagenoleft").Value), CSng(Dbf.Fields("pagenotop").Value)) End If End If If PageNo < PageNos Then 'PageTotal e.Graphics.DrawString("Page Total= " & FormatNumber(PageTotal, 2).ToString, New Font("Arial", 10, FontStyle.Bold), Brushes.Black, CSng(Dbf.Fields("pagenoleft").Value), CSng(Dbf.Fields("pagenotop").Value) - 80) e.Graphics.DrawString("Continue........", New Font("Arial", 10, FontStyle.Bold), Brushes.Black, CSng(Dbf.Fields("pagenoleft").Value), CSng(Dbf.Fields("pagenotop").Value) - 50) End If End If Dbf.Close() If PresentRecords >= PrtDbf.RecordCount Then PrtDbf.Close() IsFirstOpen = True PageTop = 0 PageSpace = 0 RowHeight = 0 PresentRecords = 1 pagerecords = 1 PageNo = 1 PageNos = 1 e.HasMorePages = False Else e.HasMorePages = True PageNo = PageNo + 1 PageTop = PageTopConst End If
End Sub
|
For POS System in VB.NET Source Code: Please Contact :Sureshjyothijv@gmail.com |