Click here to Skip to main content
15,886,795 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Everyone,

In the below code, I want user to enter full job number i.e J000001. The below code allows the user to enter just number and appends letter 'J' when user hits print. I want to get rid of that. The user will enter the full job number. I've a jobnumber column in the database. When the user enters the jobnumber (J000001), the crystal report will show up with all the details of that job. Any help is greatly appreciated.

Below is the code:

VB
Imports System.Globalization
Imports System.Drawing.Printing
Imports System.Drawing

Class MainWindow
    
    Public Sub New()

        ' This call is required by the designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        AddHandler printDocument1.PrintPage, AddressOf printDocument1_PrintPage
    End Sub

    'Declaration  the  global  variables 
    Private paperSize As New PaperSize("papersize", 300, 500)
    'set the paper size 
    Private totalnumber As Integer = 0
    'this is for total number of items of the list or array
    Private itemperpage As Integer = 0
    'this is for no of item per page 
    Private printDocument1 As New PrintDocument()
    Private printDialog1 As New System.Windows.Forms.PrintDialog()
    Private DefaultFont As New Font("Calibri", 20)

    Private Sub Button_Click(sender As Object, e As RoutedEventArgs)
        If txtStart.Text Then
            itemperpage = 1
            totalnumber = txtStart.Text
            printDialog1.Document = printDocument1
            printDocument1.DefaultPageSettings.PaperSize = paperSize
            printDialog1.ShowDialog()

            'printDocument1.PrinterSettings.PrinterName = "";
            printDocument1.Print()
        Else
            MessageBox.Show("Invalid number")
        End If
    End Sub

    Private Function CheckNumber(str As String) As Boolean
        Dim Num As Double
        Return Double.TryParse(str, Num)
    End Function

    'Define the  Printpage event of the printdocument 
    Private Sub printDocument1_PrintPage(sender As Object, e As System.Drawing.Printing.PrintPageEventArgs)
        Dim currentY As Single = 10
        While totalnumber <= txtStart.Text
            ' check the number of items 
            e.Graphics.DrawString("J" + totalnumber.ToString("000000", CultureInfo.InvariantCulture), DefaultFont, System.Drawing.Brushes.Black, 50, currentY)
            'print each item
            currentY += 20
            ' set a gap between every item
            totalnumber += 1
            'increment count by 1
            If itemperpage < 1 Then
                ' check whether  the number of item(per page) is more than 1 or not
                itemperpage += 1
                ' increment itemperpage by 1
                ' set the HasMorePages property to false , so that no other page will not be added 
                e.HasMorePages = False
            Else

                ' if the number of item(per page) is more than 1 then add one page 
                itemperpage = 1
                'initiate itemperpage to 0 . 
                If totalnumber <= C>

XAML Code
<pre lang="HTML"><Window x:Class="MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="175" Width="303">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition />
            <RowDefinition />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="1.5*" />
        </Grid.ColumnDefinitions>
        <Label C/>
        <TextBox x:Name="txtStart" Grid.Column="1" />
        <Button Grid.Row="2" Grid.ColumnSpan="2" C/>
    </Grid>
</Window>
Posted
Comments
Sergey Alexandrovich Kryukov 23-Sep-14 11:14am    
What is the problem with your code?
—SA
Member 11075637 23-Sep-14 11:22am    
Sergey,

I want the user to enter the Jobnumber (J000001) instead of me appending the number with 'J'. How can I achieve this with above code? I'm having hard time with it. Thank you for your response.

Regards
Sergey Alexandrovich Kryukov 23-Sep-14 11:31am    
Then do exactly that... I don't understand the problem, sorry.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900