Esempio n. 1
0
        /// <summary>
        /// Gets the reportby identifier.
        /// </summary>
        /// <param name="reportID">The report identifier.</param>
        /// <returns></returns>
        public void GetReportbyID(int reportID)
        {
            //this.report = null;
            ClsObject ReportManager = new ClsObject();

            ClsUtility.Init_Hashtable();
            string queryStatement;

            ClsUtility.AddParameters("@ReportID", SqlDbType.Int, reportID.ToString());
            queryStatement = @"Select  IQToolsCaTID ReportID,ReportName , 
                           ReportStylesheet,
                        FileName+'.'+FileExt FullFileName,
                        ContentType,
                        Isnull(FileLength,0)FileLength
                From dbo.IQToolsExcelReports Where IQToolsCaTID=@ReportID;";
            DataRow dr = (DataRow)ReportManager.ReturnObject(ClsUtility.theParams, queryStatement, ClsUtility.ObjectEnum.DataRow);

            ReportManager = null;
            if (dr == null)
            {
                return;
            }

            this.report = new Report();
            if (this.queryParameters != null)
            {
                report.PeriodFrom = this.queryParameters.DateFrom;
                report.PeriodTo   = this.queryParameters.DateTo;
            }
            report.ReportName = dr["ReportName"].ToString();
            report.SetReportID(reportID);
            report.HasReportStyleSheet = false;
            if (dr["ReportStylesheet"] != DBNull.Value)
            {
                int FileSize = Convert.ToInt32(dr["FileLength"]);
                //    byte[] xslStyle;
                byte[] xslData = new byte[FileSize];
                string strOut_XSL;
                ((byte[])dr["ReportStylesheet"]).CopyTo(xslData, 0);

                strOut_XSL = XmlEncodingBOM.GetBOMString(xslData);
                report.ReportStyleSheet = strOut_XSL;

                report.HasReportStyleSheet       = true;
                report.ReportTemplateSize        = FileSize;
                report.ReportTemplateName        = dr["FullFileName"].ToString();
                report.ReportTemplateContentType = dr["ContentType"].ToString();
                report.ReportTemplateBinary      = xslData;
            }
            //return this.report;
        }
Esempio n. 2
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 (Authentication.HasFeatureRight(ApplicationAccess.BillingConfiguration, (DataTable)Session["UserRight"]) == true)
                {
                    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() == "1900-01-01" ? DateTime.Now : DateTime.Parse(textPriceListDate.Text);
                    xmlDoc.LoadXml(BillingManager.GetPriceListXML(Session["AppLocation"].ToString(), Session["AppUserName"].ToString(), printPriceDate));

                    //DateTime dateFromStringGlob = DateTime.Parse(printPriceDate.ToString(), System.Globalization.CultureInfo.InvariantCulture);
                    //DateTime dateFromStringGlob = new DateTime(printPriceDate.Value.Year, printPriceDate.Value.Month, printPriceDate.Value.Day, 0, 0, 0, 0);
                    //xmlDoc.LoadXml(BillingManager.GetPriceListXML(Session["AppLocation"].ToString(), Session["AppUserName"].ToString(), dateFromStringGlob));

                    //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>";

                    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "PrintReport", strScript, false);
                    // Page.ClientScript.RegisterClientScriptBlock(this.btnPrint.GetType(), "PrintReport", strScript, false);

                    //XmlNamespaceManager nsmgr = new XmlNamespaceManager(xslDoc.NameTable);
                    //nsmgr.AddNamespace("xsl", "http://www.w3.org/1999/XSL/Transform");

                    //XPathNavigator xslNav = xslDoc.CreateNavigator();

                    //XslCompiledTransform trans = new XslCompiledTransform();

                    //Response.Clear();
                    //Response.ContentType = "text/html; charset=UTF-8";

                    //XsltSettings xslSessings = new XsltSettings();
                    //xslSessings.EnableScript = true;

                    //trans.Load(xslNav, xslSessings, new XmlUrlResolver());

                    //trans.Transform(xmlDoc.CreateNavigator(), null, Response.OutputStream);

                    //Response.Flush();
                }
                else
                {
                    Response.Redirect("~/frmLogin.aspx?error=true");
                }
            }
            catch (Exception ex)
            {
                showErrorMessage(ref ex);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Gets the encoding bom.
        /// </summary>
        /// <param name="ByteArray">The byte array.</param>
        /// <returns></returns>
        private XmlEncodingBOM GetEncodingBOM(byte[] ByteArray)
        {
            int bomIndex  = -1;
            int bomLength = 0;

            XmlEncodingBOM[] XmlEncodings = new XmlEncodingBOM[10] {
                new XmlEncodingBOM("UTF-8", Encoding.UTF8, 3, new byte[3] {
                    0xEF, 0xBB, 0xBF
                }),
                new XmlEncodingBOM("UTF-16", Encoding.BigEndianUnicode, 2, new byte[2] {
                    0xFE, 0xFF
                }),
                new XmlEncodingBOM("UTF-16", Encoding.Unicode, 2, new byte[2] {
                    0xFF, 0xFE
                }),
                new XmlEncodingBOM("UTF-32", Encoding.UTF32, 4, new byte[4] {
                    0x00, 0x00, 0xFE, 0xFF
                }),
                new XmlEncodingBOM("UTF-32", Encoding.UTF32, 4, new byte[4] {
                    0xFF, 0xFE, 0x00, 0x00
                }),
                new XmlEncodingBOM("UTF-7", Encoding.UTF7, 4, new byte[4] {
                    0x2B, 0x2F, 0x76, 0x38
                }),
                new XmlEncodingBOM("UTF-7", Encoding.UTF7, 4, new byte[4] {
                    0x2B, 0x2F, 0x76, 0x39
                }),
                new XmlEncodingBOM("UTF-7", Encoding.UTF7, 4, new byte[4] {
                    0x2B, 0x2F, 0x76, 0x2B
                }),
                new XmlEncodingBOM("UTF-7", Encoding.UTF7, 4, new byte[4] {
                    0x2B, 0x2F, 0x76, 0x2F
                }),
                new XmlEncodingBOM("ASCII", Encoding.ASCII, 0, null)
            };


            for (int i = 0; i < XmlEncodings.Length; i++)
            {
                if (ByteArray.Length < XmlEncodings[i].BOMLength)
                {
                    break;
                }
                bool isTheOne = true;
                for (int x = 0; x < XmlEncodings[i].BOMLength; x++)
                {
                    if (XmlEncodings[i].ByteSequnce[x] != ByteArray[x])
                    {
                        isTheOne = false;
                    }
                }
                if (isTheOne)
                {
                    if (XmlEncodings[i].BOMLength >= bomLength)
                    {
                        bomLength = XmlEncodings[i].BOMLength;
                        bomIndex  = i;
                    }
                }
            }

            if (bomIndex < 0)
            {
                return(new XmlEncodingBOM("UTF-8", Encoding.UTF8, 0, null));
            }
            else
            {
                return(XmlEncodings[bomIndex]);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Gets the reportby identifier.
        /// </summary>
        /// <param name="reportID">The report identifier.</param>
        /// <returns></returns>
        public void GetReportbyID(int reportID)
        {
            try
            {
                //this.report = null;
                ClsObject ReportManager = new ClsObject();
                ClsUtility.Init_Hashtable();
                string queryStatement;

                ClsUtility.AddParameters("@ReportID", SqlDbType.Int, reportID.ToString());
                queryStatement = @"Select  IQToolsCaTID ReportID,ReportName , 
                           ReportStylesheet,
                        FileName+'.'+FileExt FullFileName,
                        ContentType,
                        Isnull(FileLength,0)FileLength
                From dbo.IQToolsExcelReports Where IQToolsCaTID=@ReportID;";
                DataRow dr = (DataRow)ReportManager.ReturnObject(ClsUtility.theParams, queryStatement, ClsDBUtility.ObjectEnum.DataRow);
                ReportManager = null;
                if (dr == null)
                {
                    return;
                }

                this.report = new Report();
                if (this.queryParameters != null)
                {
                    report.PeriodFrom = this.queryParameters.DateFrom;
                    report.PeriodTo   = this.queryParameters.DateTo;
                }
                report.ReportName = dr["ReportName"].ToString();
                report.SetReportID(reportID);
                report.HasReportStyleSheet = false;
                if (dr["ReportStylesheet"] != DBNull.Value)
                {
                    int    FileSize = Convert.ToInt32(dr["FileLength"]);
                    byte[] xslStyle;
                    byte[] xslData = new byte[FileSize];
                    string strOut_XSL;
                    ((byte[])dr["ReportStylesheet"]).CopyTo(xslData, 0);


                    XmlEncodingBOM encBOM = GetEncodingBOM(xslData);

                    if (encBOM.BOMLength > 0)
                    {
                        xslStyle = new byte[FileSize - encBOM.BOMLength];
                        Array.Copy(xslData, encBOM.BOMLength, xslStyle, 0, FileSize - encBOM.BOMLength);
                    }
                    else
                    {
                        xslStyle = xslData;
                    }

                    //ignore EncodingByteOrderMark assume utf8
                    // xslStyle = xslData;
                    strOut_XSL = encBOM.TextEncoding.GetString(xslStyle);


                    report.ReportStyleSheet = strOut_XSL;

                    report.HasReportStyleSheet       = true;
                    report.ReportTemplateSize        = FileSize;
                    report.ReportTemplateName        = dr["FullFileName"].ToString();
                    report.ReportTemplateContentType = dr["ContentType"].ToString();
                    report.ReportTemplateBinary      = xslData;
                }
            }

            catch (Exception e)
            {
                throw e;
            }
            //return this.report;
        }
Esempio n. 5
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);
            }
        }