コード例 #1
0
        /// <summary>
        /// Handles the Click event of the btnPrint control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void btnPrint_Click(object sender, EventArgs e)
        {
            XmlDocument xmlDoc = new XmlDocument();
            /// <summary>
            /// The XSL document
            /// </summary>
            XmlDocument xslDoc;

            try
            {
                if (CurrentSession.Current.HasBilling && CurrentSession.Current.HasFeaturePermission("BILLING_CONFIGURATION"))
                {
                    xmlDoc = new XmlDocument();
                    string strfile = Server.MapPath("~/Billing/PriceList_1_0.xsl");

                    byte[] fileData = File.ReadAllBytes(strfile);

                    string strOut_XSL;

                    strOut_XSL = XmlEncodingBOM.GetBOMString(fileData);

                    xslDoc = new XmlDocument();

                    xslDoc.LoadXml(strOut_XSL);

                    // xmlDoc.LoadXml(docX.ToString());
                    DateTime?printPriceDate;

                    printPriceDate = textPriceListDate.Text.Trim() == "" ? DateTime.Now : DateTime.Parse(textPriceListDate.Text);
                    xmlDoc.LoadXml(BillingManager.GetPriceListXML(Session["AppLocation"].ToString(), Session["AppUserName"].ToString(), printPriceDate));
                    //Create an XML declaration.
                    XmlDeclaration xmldecl;
                    xmldecl = xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", null);
                    //Add the new node to the document.
                    XmlElement root = xmlDoc.DocumentElement;
                    xmlDoc.InsertBefore(xmldecl, root);

                    Hashtable ht = new Hashtable()
                    {
                        { "data", xmlDoc.InnerXml }, { "style", strOut_XSL }
                    };

                    Session["ReportData"] = ht;
                    string strScript = @"<script language=""javascript"" type=""text/javascript"">
                        var w = screen.width - 60; var h = screen.height - 60; var winprops = ""location=no,scrollbars=yes,resizable=yes,status=no"";
                        var frmwin = window.open(""PrintPriceList.aspx?print=true"", ""PrintPriceList"", winprops);
                        if (parseInt(navigator.appVersion) >= 4) {
                            frmwin.window.focus();
                        }   </script>";
                    //mpePrintPriceList.Hide();
                    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "PrintReport", strScript, false);
                }
                else
                {
                    CurrentSession.Logout();
                    Response.Redirect("~/frmLogin.aspx?error=true");
                }
            }
            catch (Exception ex)
            {
                showErrorMessage(ref ex);
            }
        }