Solved

CheckBox Always Print Current Date

Posted on 2009-05-18
7
436 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

912 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

17 Experts available now in Live!

Get 1:1 Help Now