Solved

CheckBox Always Print Current Date

Posted on 2009-05-18
7
492 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Give Your Engineering Team a Productivity Boost

Learn why container technology is so powerful and how it can provide your team with productivity gains and other benefits.

 

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

Enroll in July's Course of the Month

July's Course of the Month is now available! Enroll to learn HTML5 and prepare for certification. It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

624 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