Solved

CheckBox Always Print Current Date

Posted on 2009-05-18
7
419 Views
Last Modified: 2013-11-26
Dear Experts-Exchange,

I have a textbox id=textbox1 that searches information number and checkbox id=CheckBox1 for Always Print Current Date and the button id=BtnPrint Go  (see the attachament)

In Sql Database I have this  :  

InfoNumber                                 DateInfo

12345                                           1/19/2009
12345                                           5/18/2009   (this is the current date)
12345                                           4/22/2009


I would like to know after typing the information number in the text box 12345 and checked the box for printing the current date from the information number, it will printing the information.  How would I do this?

See the below
Protected Sub BtnPrint_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnPrint.Click
 

If Textbox1.Text = "" Then

            LblError.Text = "Please: Enter Information Number value!"

            Textbox1.Focus()

        Else

            LblError.Text = ""

        End If
 

DataFill()

CheckedBox1()
 

End Sub
 

Private Sub DataFill()
 

Dim da As SqlDataAdapter

        Dim ds As Data.DataSet

        Dim strSQL As String

        Dim strCnn As String
 

Try
 

strSQL = "SELECT InfoNum, " & _

"CONVERT (varchar(2), DATEPART(mm, DateInfo, GetDate())) + '/' + CONVERT (varchar(2), DATEPART(dd, DateInfo, GetDate())) + '/' + CONVERT (varchar(4), DATEPART(yyyy, DateInfo, GetDate())) AS [DateInfo]  FROM InfoData  &

WHERE InfoNum =  & Trim(TextBox1.text) &  and CurrentDate =                   
 

strCnn = System.Configuration.ConfigurationManager.AppSettings("ABCStringConn)
 

da = New SqlDataAdapter(strSQL, strCnn)

            ds = New Data.DataSet()

            da.Fill(ds, "infodata")

            Session("DataView") = ds.Tables("InfoData").DefaultView()

End Try

    End Sub
 
 

Protected Sub CheckBox1_CheckedChanged(ByVal sender As Object, ByVal e As 

System.EventArgs) Handles CheckBox1CheckedChanged
 

If CheckBox1.Checked = True Then
 

Print&&. (what is the SQL Statement/VB.NET code for printing the checked current date 5/19/2009 from SQL database)
 

End if

End sub
 

Thanks

Open in new window

Search.jpg
0
Comment
Question by:slb2008
  • 4
  • 3
7 Comments
 
LVL 6

Expert Comment

by:M3mph15
ID: 24417751
Hi,

What you could do is create a new page that you open in a new window, pass those parameters to show in a label and then print it. This can all be done using javascript.

I'm not at a computer to test any code so i'll post some when i can but basically you will need a javascript function that grabs the values of the textbox and the checkbox and sends it to the new page in the quersytring.

e.g. PrintPage.aspx?txt=<textbox value>&chk=<Checkbox value>. So then the new page grabs those values and displays them in a label.

Then you can use window.print() in a javascript function on the page load(in the new page) to bring up the print dialog.

This will allow the user to select what printer they want.

Will post code for the first bit later on

-M3mph15


0
 

Author Comment

by:slb2008
ID: 24418089
Hi M3mhp15,
Thanks for your quick response.
I'll be waiting for the code.
Thanks  slb2008
 
0
 
LVL 6

Accepted Solution

by:
M3mph15 earned 500 total points
ID: 24420118
Hi slb2008, Here is the code:

For this example i'll use the names Home.aspx and PrintPage.aspx for the webpages.

So in the <head> section of Home.aspx insert the following:

function PrintDate()
        {
            var txt =  document.getElementById('<%= <name of textbox>.ClientID %>').innerHTML  ;
            var chk = document.getElementById('<%= <name of checkbox>.ClientID %>').checked;
            var obj_calwindow = window.open(
                    'PrintPage.aspx?txt=' + txt + '&chk=' + chk, 'Print', 'width=600,height='+'650'+
                    ',status=no,resizable=yes,top=200,left=200,dependent=yes,alwaysRaised=yes'
                    );
        }
The above function will grab the data from the textbox and checkbox and send the data to another page (which opens in a seperate window) in the querystring.

Now to make the button call the javascript function:
<asp:Button ID="btnPrint" runat="server" Text="Print" OnClientClick="PrintDate()" />

Now we have to retrieve the data from the querystring and then print the page. So make sure on PrintPage.aspx that there are 2 labels. After a few test prints you can move the labels to suit your formatting.
So in the code behind of PrintPage.aspx within the PageLoad event:
String txt = Request.QueryString("txt")
String chk = Request.QueryString("chk")
Label1.Text = txt
If chk == "True" Then 'Im not 100% sure what the value of chk will be.
     Label2.Text = Date.Today().ToString()
End If

And then in the <head> section of PrintPage.aspx:
    <script type="text/javascript">
        var p = window.print();
        window.close;
    </script>

So when that is all implemented on the click of the button it will open up another window and automatically bring up the print dialog and once it is printed it will close the window.

HTH
-M3mph15

0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:slb2008
ID: 24424126

Hi M3mph15,
I received the code  and I am going to try it.
It's correct the value of chk will be true or false.
I will let you know later.
If you please, I inserted a new question titled "GridView with buttons Print, View and Add".  Maybe you could view my new question.
Thanks, slb2008
0
 

Author Comment

by:slb2008
ID: 24424127
Hi M3mph15,
I received the code  and I am going to try it.
It's correct the value of chk will be true or false.
I will let you know later.
If you please, I publish a new question titled "GridView with buttons Print, View and Add".  Maybe you could view my new question.
Thanks, slb2008
0
 
LVL 6

Expert Comment

by:M3mph15
ID: 24470346
Hey sbl2008,

Any feedback on wether my coding workedor not?

-M3mph15
0
 

Author Comment

by:slb2008
ID: 24478984
Hi M3mph15,
I am sorry I didn't answer you soon.  Your code worked well, but I did different way, which is working now.  Thanks for your help.
I will end here to give 500 points acepting as solution.
Thanks
 
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now