Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Javascript printing question? Urgent Need a real Expert this Time.

Posted on 2004-10-29
7
Medium Priority
?
246 Views
Last Modified: 2010-04-15
I am trying to call a print function to print a string from a database using javascript.
Which is RC_DATA of Varchar2(2500).
This is  a javascript is not being used. I have a thing that needs to be modified:
if(e.CommandName =="Print")
{
                          string parsedreceipt = null;
      parsedreceipt = DecodeReceipt (e.Item.Cells[3].Text);
      Session["parsedreceipt"] = parsedreceipt;
               ///   Response.Write("<script language=\"JavaScript\">window.OpenNewWin('print.aspx', null, 'height=200,width=400');");
      Response.Write("<script language=\"JavaScript\">window.open('print.aspx', null, 'height=200,width=400');</script>");
}

I am confused on what to do? I just want to print the string.

<script language="javascript">
      function OpenNewWin(Receipt)
      {
     winNew = window.open("print.aspx?","printwindow","toolbar=no,scrollbar=no,height=200,width=300,resizable=no,top=200,left=200");
     var PrintHtml ="<Table cellpadding=5 cellspacing=5 broder=0>";
           PrintHtml = PrintHtml + "<TR><TD>Receipt</TD><TD width=5>:</TD><TD>" + Receipt + "</TD></TR>";
           PrintHtml = PrintHtml + " </TABLE>";
           PrintHtml = PrintHtml + " <DIV id=butPanel align=center> <input Type=button value='   Print  ' onclick=Javascript:document.getElementById('butPanel').style.display='none';window.print();document.getElementById('butPanel').style.display='';>";
           PrintHtml = PrintHtml + " <input type=button value=cancel onclick=javascript:window.close();></Div>";
           winNew.document.body.innerHTML=PrintHtml;
           winNew.focus();
      }
      </script>




===================================
.aspx

<%@ Register TagPrefix="cc1" Namespace="ActiveUp.WebControls" Assembly="ActiveDateTime" %>
<%@ Page Language="c#" Codebehind="Receipts.aspx.cs" AutoEventWireup="false" Inherits="MSPOS.Receipt" %>
<%@ Register TagPrefix="uc1" TagName="logout" Src="Engine/Controls/logout.ascx" %>
<%@ Register TagPrefix="mspos" TagName="header" Src="Engine/Controls/header.ascx" %>
<%@ Register TagPrefix="mspos" TagName="footer" Src="~/Engine/Controls/footer.ascx" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<script language="javascript">
      function OpenNewWin(Receipt)
      {
     winNew = window.open("print.aspx?","printwindow","toolbar=no,scrollbar=no,height=200,width=300,resizable=no,top=200,left=200");
     var PrintHtml ="<Table cellpadding=5 cellspacing=5 broder=0>";
           PrintHtml = PrintHtml + "<TR><TD>Receipt</TD><TD width=5>:</TD><TD>" + Receipt + "</TD></TR>";
           PrintHtml = PrintHtml + " </TABLE>";
           PrintHtml = PrintHtml + " <DIV id=butPanel align=center> <input Type=button value='   Print  ' onclick=Javascript:document.getElementById('butPanel').style.display='none';window.print();document.getElementById('butPanel').style.display='';>";
           PrintHtml = PrintHtml + " <input type=button value=cancel onclick=javascript:window.close();></Div>";
           winNew.document.body.innerHTML=PrintHtml;
           winNew.focus();
      }
      </script>
</HEAD>
<BODY leftMargin="0" background="images/bg.gif" topMargin="0">
<form id="Form1" action="database.aspx" method="post" runat="server">
<strong>
<P><mspos:header id="Header1" runat="server"></mspos:header><BR>
<FONT face="Verdana" size="2"></FONT>
</P>
<FONT face="Verdana" size="2">
<P align="center">
<asp:ImageButton id="MainMenu" runat="server" ImageUrl="images/mainmenu.jpg"></asp:ImageButton></P>
</FONT><FONT face="Verdana" size="2">
<DIV align="center">
<TABLE id="Table2" height="118" cellSpacing="1" cellPadding="1" width="355" border="0">
<TR>
<TD vAlign="top" width="147" colSpan="1" rowSpan="4">
<P><asp:radiobuttonlist id="Group_RadioButtonList" runat="server" BorderWidth="0px" CellSpacing="1" CellPadding="1"
                                                                  Height="111px" Font-Bold="True" Font-Size="12px" Font-Names="Verdana"
                                                                  Width="35px" BackColor="#FEF9E9">
<asp:ListItem Value="PayNumber">1</asp:ListItem>
<asp:ListItem Value="Cashier">2</asp:ListItem>
<asp:ListItem Value="StartDate">3</asp:ListItem>
</asp:radiobuttonlist></P>
&nbsp;&nbsp;
</TD>
<TD noWrap colSpan="1" rowSpan="1">Payment Number:</TD>
<TD vAlign="middle" noWrap width="200" colSpan="1" rowSpan="1"><asp:textbox id="txtPayment" runat="server" MaxLength="10"></asp:textbox></TD>
</TR>
<TR>
<TD width="240">Cashier Number:</TD>
<TD><asp:textbox id="txtCashier" runat="server" MaxLength="8"></asp:textbox></TD>
</TR>
<TR>
<TD width="240" height="10">Start Date:</TD>
<TD height="10"><cc1:activedatetime id="ActiveDateTime3" runat="server" AllowNull="False" MonthNamesDisabled="True"
                                                            Format="DAY;-;MONTH;-;YEAR"></cc1:activedatetime></TD>
</TR>
<TR>
<TD width="240">End Date:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</TD>
<TD><cc1:activedatetime id="ActiveDateTime4" runat="server" AllowNull="False" MonthNamesDisabled="True"
                                                            Format="DAY;-;MONTH;-;YEAR"></cc1:activedatetime></TD>
</TR>
<TR>
<TD width="240"></TD>
<TD><asp:button id="btnRunQuery" onclick="btnRunQuery_Click" runat="server" text="Run Query" type="submit"></asp:button></TD>
</TR>
</TABLE>
</DIV>
</FONT></strong>
<DIV>
<br>
<strong>Results of:<BR>
</strong>
</DIV>
<DIV align="center">
<asp:datagrid id="ReceiptsDataGrid" runat="server" BorderWidth="3" CellSpacing="1" CellPadding="1"
                              Height="144px" Width="500px" OnItemDataBound="ReceiptsDataGrid_ItemDataBound"
                              OnItemCommand="ReceiptsDataGrid_ItemCommand" HeaderStyle-Font-Bold="True"
                              maintainviewstate="false" GridLines="None" BorderStyle="Outset" font-size="XX-Small"
                              font-names="Verdana" BorderColor="#CCCC99" AutoGenerateColumns="False">
<AlternatingItemStyle Wrap="False" BackColor="PaleGoldenrod"></AlternatingItemStyle>
<ItemStyle Wrap="False" BackColor="Beige"></ItemStyle>
<HeaderStyle Font-Size="14px" Font-Bold="True" ForeColor="White" BackColor="#954896"></HeaderStyle>
<Columns>
<asp:BoundColumn DataField="RC_PAYMNB" HeaderText="Payment Number "></asp:BoundColumn>
<asp:BoundColumn DataField="RC_CASHNB" HeaderText="Cash Number"></asp:BoundColumn>
<asp:BoundColumn DataField="RC_DATE" HeaderText="Date"></asp:BoundColumn>
<asp:BoundColumn DataField="RC_DATA" Visible="False" HeaderText="Data"></asp:BoundColumn>
<asp:TemplateColumn>
<ItemTemplate>
<asp:Button CommandName="View" Text="View" Runat="server" ID="Button1"></asp:Button>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
<ItemTemplate>
<asp:Button CommandName="Print" Text="Print" Runat="server" ID="Button2"></asp:Button>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
<P align="center">
<uc1:logout id="Logout1" runat="server"></uc1:logout></P>
</form>
</DIV></FORM>
</BODY>
</HTML>


.cs
====================================
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.Odbc;
using System.Text;
using System.Drawing;
using System.Data.Common;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace MSPOS
{
      /// <summary>
      /// Summary description for Receipts.
      /// </summary>
      public class Receipt : System.Web.UI.Page
      {
            protected System.Web.UI.WebControls.RadioButtonList Group_RadioButtonList;
            protected System.Web.UI.WebControls.DataGrid ReceiptsDataGrid;
            private DataSet ddlDataSet = new DataSet();
            private OdbcConnection myConnection =  new OdbcConnection("DSN=MSPOS;UID=system;PWD=system");
            protected System.Web.UI.WebControls.Button btnRunQuery;
            protected System.Web.UI.WebControls.Button Button2;
            
            protected System.Web.UI.WebControls.TextBox txtPayment;
            protected System.Web.UI.WebControls.TextBox txtCashier;
            
            private DataSet ddlDataSet1 = new DataSet();
            private DataSet ddlDataSet2 = new DataSet();
            protected ActiveUp.WebControls.ActiveDateTime ActiveDateTime3;
            protected ActiveUp.WebControls.ActiveDateTime ActiveDateTime4;
            private DataSet ddlDataSet3 = new DataSet();
            protected System.Web.UI.WebControls.ImageButton MainMenu;
            protected System.Web.UI.WebControls.Button Button1;
            protected string AccessLevel = null;

            private void Page_Load(object sender, System.EventArgs e)
            {
                  // Put user code to initialize the page here
                  if (!Page.IsPostBack)
                  {
                        ActiveDateTime3.Date = System.DateTime.Today.Date;
                        ActiveDateTime4.Date = System.DateTime.Today.Date;
                  }
            }

            private void MainMenu_Click(Object sender, ImageClickEventArgs e)
            {
                  AccessLevel = Session["Authenticated"].ToString();
                  if (AccessLevel == "1")
                        Response.Redirect("AdminStart.aspx");        
                  else if (AccessLevel == "2")
                        Response.Redirect("CCManStart.aspx");        
                  else if (AccessLevel == "3")
                        Response.Redirect("CCashierStart.aspx");        
                  else if (AccessLevel == "4")
                        Response.Redirect("CashierStart.aspx");        
                  else Response.Redirect("Error.aspx");
            }


            #region Web Form Designer generated code
            override protected void OnInit(EventArgs e)
            {
                  //
                  // CODEGEN: This call is required by the ASP.NET Web Form Designer.
                  //
                  InitializeComponent();
                  base.OnInit(e);
            }
            
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InitializeComponent()
            {    
                  this.MainMenu.Click += new System.Web.UI.ImageClickEventHandler(this.MainMenu_Click);
                  this.Group_RadioButtonList.SelectedIndexChanged += new System.EventHandler(this.Group_RadioButtonList_SelectedIndexChanged);
                  this.txtCashier.TextChanged += new System.EventHandler(this.txtCashier_TextChanged);
                  this.btnRunQuery.Click += new System.EventHandler(this.btnRunQuery_Click);
                  this.Load += new System.EventHandler(this.Page_Load);

            }
            #endregion

            public string DecodeReceipt (string szBill)
            {
                  string szNewBill="";
                             
                  // Create an ASCII encoding.
                  Encoding ascii = Encoding.ASCII;
                       
                  Byte[] encodedBytes = ascii.GetBytes(szBill);

                  foreach (Byte a in encodedBytes)
                  {
                        if (a ==10 || a ==15 ||a==18 ||a ==27)
                        {}          
                        else if (a == 13)
                              szNewBill = szNewBill + "\\n";
                        else
                              szNewBill = szNewBill +(char) a;

                  }
                  return szNewBill;
            }
         


            private void txtPayment_TextChanged(object sender, System.EventArgs e)
            {
            
            }

            private void txtCashier_TextChanged(object sender, System.EventArgs e)
            {
            
            }

            //***********************************************************************
            // Get RC_PAYMND and populate dataset
            public DataSet BindRC_PAYMND(string searchstring)
            {
                  OdbcConnection myConnection =  new OdbcConnection("DSN=MSPOS;UID=system;PWD=system");

                  // Populate the ddlDataSet1
                  myConnection.Open();
                  string strSQLDDL = @"SELECT RC_PAYMNB FROM TBRECEIPTS WHERE RC_PAYMNB='"+searchstring+"'";
                  OdbcDataAdapter myDataAdapter = new OdbcDataAdapter(strSQLDDL, myConnection);
                  ddlDataSet1.Clear();  
                  myDataAdapter.Fill(ddlDataSet1, "ddlRC_PAYMNB");
                  myDataAdapter.Dispose();
                  myDataAdapter = null;
                  myConnection.Close();
                  strSQLDDL = null;
                  return ddlDataSet1;
            }
            //***********************************************************************

            //***********************************************************************
            // Get RC_CASHND and populate dataset
            public DataSet BindRC_CASHND(string searchstring)
            {
                  OdbcConnection myConnection =  new OdbcConnection("DSN=MSPOS;UID=system;PWD=system");

                  // Populate the ddlDataSet2
                  myConnection.Open();
                  string strSQLDDL = @"SELECT RC_CASHNB FROM TBRECEIPTS WHERE RC_CASHNB='"+searchstring+"'";
                  OdbcDataAdapter myDataAdapter = new OdbcDataAdapter(strSQLDDL, myConnection);
                  ddlDataSet2.Clear();  
                  myDataAdapter.Fill(ddlDataSet2, "ddlRC_CASHNB");
                  myDataAdapter.Dispose();
                  myDataAdapter = null;
                  myConnection.Close();
                  strSQLDDL = null;
                  return ddlDataSet2;
            }
            //***********************************************************************


            //***********************************************************************
            // Get RC_CASHND and populate dataset with RC_CASHND and RC_DATE
            public DataSet BindRC_DATE()
            {
                  OdbcConnection myConnection =  new OdbcConnection("DSN=MSPOS;UID=system;PWD=system");

                  // Populate the ddlDataSet3
                  myConnection.Open();
                  string strSQLDDL = @"SELECT RC_DATE FROM TBRECEIPTS";
                  OdbcDataAdapter myDataAdapter = new OdbcDataAdapter(strSQLDDL, myConnection);
                  ddlDataSet3.Clear();  
                  myDataAdapter.Fill(ddlDataSet3, "ddlRC_DATE");
                  myDataAdapter.Dispose();
                  myDataAdapter = null;
                  myConnection.Close();
                  strSQLDDL = null;
                  return ddlDataSet3;
            }
            //***********************************************************************
       
            public void ReceiptsDataGrid_ItemDataBound(object sender,System.Web.UI.WebControls.DataGridItemEventArgs e)
            {
                  if(e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType==ListItemType.Item )
                  {
                        string parsedreceipt = null;
                        string strValue="Javascript:OpenNewWin('"+ DecodeReceipt(e.Item.Cells[3].Text) + "');";
                        Button btn = ( (Button) e.Item.FindControl("Button2") );
                        Session["parsedreceipt"] = parsedreceipt;  
                        btn.Attributes.Add("Onclick",strValue);
                  
                  }


            }
            //***********************************************************************
       


            public void ReceiptsDataGrid_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
            {
                  ListItemType oType = ((ListItemType)e.Item.ItemType);
                  if(oType == ListItemType.Item || oType == ListItemType.AlternatingItem)
                  {
                        e.Item.Attributes.Add("onmouseover", "this.style.backgroundColor='lightblue'");            
                        e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='Beige'");            
                  }
                  
                  if(e.CommandName =="View")
                  {
                        string parsedreceipt = null;
                        parsedreceipt = DecodeReceipt (e.Item.Cells[3].Text);
                        StringBuilder strAlert = new StringBuilder();
                        strAlert.Append("<script language=javascript> alert('");
                        strAlert.Append("Receipt:                    " + parsedreceipt + "\\n");
                        strAlert.Append("');</script>");
                        this.RegisterStartupScript("startup",strAlert.ToString());
                  }

                  if(e.CommandName =="Print")
                  {
                        string parsedreceipt = null;
                        parsedreceipt = DecodeReceipt (e.Item.Cells[3].Text);
                        Session["parsedreceipt"] = parsedreceipt;
            ///   Response.Write("<script language=\"JavaScript\">window.OpenNewWin('print.aspx', null, 'height=200,width=400');");
                        Response.Write("<script language=\"JavaScript\">window.open('print.aspx', null, 'height=200,width=400');</script>");
            
                  }

                  
                  
                  

            }


            private void Group_RadioButtonList_SelectedIndexChanged(object sender, System.EventArgs e)
            {
            
            }


            public void btnRunQuery_Click(object sender, System.EventArgs e)
            {
                  string select_statement = "SELECT RC_PAYMNB, RC_CASHNB, RC_DATE, RC_DATA FROM TBRECEIPTS";
                  string DateString1 = ActiveDateTime3.Date.Day.ToString() + "-" + ActiveDateTime3.Date.Month.ToString() + "-" + ActiveDateTime3.Date.Year.ToString();
                  string DateString2 = ActiveDateTime4.Date.Day.ToString() + "-" + ActiveDateTime4.Date.Month.ToString() + "-" + ActiveDateTime4.Date.Year.ToString();

                  
                  switch (Group_RadioButtonList.SelectedIndex)
                  {
                        case 0:
                              select_statement += " Where RC_PAYMNB='" + txtPayment.Text + "'";
                              break;
                        case 1:
                              select_statement += " Where RC_CASHNB='" + txtCashier.Text + "'";
                              break;
                        case 2:
                              select_statement += " Where To_Date(RC_DATE, 'dd-mm-yyyy') <= '" + DateString2.ToString() + "' And To_Date(RC_DATE, 'dd-mm-yyyy') >= '" + DateString1.ToString() + "'";
                              break;
                  }

            

                  OdbcConnection myConnection =  new
                  OdbcConnection("DSN=MSPOS;UID=system;PWD=system");

                  // Populate the ddlDataSet1
                  myConnection.Open();
                  string strSQLDDL = select_statement;
                  OdbcDataAdapter myDataAdapter = new OdbcDataAdapter(strSQLDDL,myConnection);
                  ddlDataSet1.Clear();  
                  myDataAdapter.Fill(ddlDataSet1);
                  myDataAdapter.Dispose();
                  myDataAdapter = null;
                  myConnection.Close();
                  ReceiptsDataGrid.DataSource = ddlDataSet1.Tables[0];
                  ReceiptsDataGrid.DataBind();
            
        }

            private void ReceiptsDataGrid_SelectedIndexChanged(object sender, System.EventArgs e)
            {
            
            }
            

      }
}

0
Comment
Question by:mathieu_cupryk
[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
  • 2
7 Comments
 

Author Comment

by:mathieu_cupryk
ID: 12450740
Hi Sukumur, I look at this link and is there someway you can help me.
I have be sick for a few weeks. I have to finish this.
I would really appreciate your help.
0
 

Author Comment

by:mathieu_cupryk
ID: 12450742
I don't mind the popup print dialog coming up just that if that I can click on the button and the selection printer comes on ready to print.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 7

Expert Comment

by:sukumar_diya
ID: 12450793
Hi mathieu,
I am going for lunch i will be back in an hour. Please explain me little bit what is hapening and what do u want??
 I will try my best to help you...

Cheers
Sukumar
0
 

Author Comment

by:mathieu_cupryk
ID: 12453763
When I press the print button on the datagrid I would like to have the same fuctionality as the view button, except that now the information will prompt me
a printer to print to.
0
 

Author Comment

by:mathieu_cupryk
ID: 12457483
I just need a simple Javascript to print a receipt.
That's it.

0
 
LVL 6

Accepted Solution

by:
der_jth earned 1500 total points
ID: 12458318
mathieu_cupryk: You seem to be repeating similar questions all the time. Instead of just pasting huge lumps of code into more and more new questions, please tell us which part of this previous solution <http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/ASP_DOT_NET/Q_21172769.html> doesn't work for this case?
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

604 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