public DevExpress.XtraReports.UI.XtraReport CreateReportWithAutoCellWidth(DevExpress.XtraReports.UI.XtraReport xtraReport)
        {
            // I need this for a later excel-export to simulate endless paper (all report pages on one sheet)
            xtraReport.PaperKind  = PaperKind.Custom;
            xtraReport.ReportUnit = ReportUnit.Pixels;
            xtraReport.PageWidth  = 3000;
            xtraReport.RollPaper  = true;

            cellColumnWidthCollection = new Dictionary <XRControl, float>();
            xtraReport.CreateDocument();
            FillColumnCellWidthCollection(xtraReport);
            ApplyNewWidthToReportCells(xtraReport);
            xtraReport.CreateDocument();

            return(xtraReport);
        }
Esempio n. 2
0
        public void getReport()
        {
            string Id = "1";// Session["ReportID"].ToString();

            hndreportId.Value = Id;
            // Dim UId As String = Session["ReportID"].ToString()
            dynamic type = "1";
            //Request.QueryString("type")

            string reportName = "";
            //reportName = "test";
            string param  = Request.QueryString["rp"];
            string export = Request.QueryString["export"];
            //bool mobilemode = Request.QueryString["mobile"].ToString()=="yes"?true:false;
            //ASPxWebDocumentViewer1.MobileMode = mobilemode;
            string fileName = "";
            Guid   requestID;

            try
            {
                requestID = new Guid(Request.QueryString["r"]);
                fileName  = getResponseSQL(requestID.ToString());
            }
            catch
            {
                Response.Redirect("~/index.html");
            }

            /*var data = getResponse(requestID.ToString());
             * log.Info("Page load 4" + data);
             * if (data == "") return;
             * JObject jsonObj = JObject.Parse(data);
             * string fileName = jsonObj["FileName"].Value<string>();*/


            if (fileName == null || fileName == "")
            {
                fileName = "";
            }
            string userid = Request.QueryString["userid"];

            if (userid == null || userid == "")
            {
                userid = "0";
            }

            reportName = fileName;
            int count = 0;

            //// Dim str_Query As String = "select title from l_menu where mnu_id=" & Id
            //string str_Query = "Select a.title,a.defaultreport,a.PublishedReport, b.cnt from (Select title,defaultreport,PublishedReport from l_menu where mnu_id=" + Id + " ) a, (Select  Count(*) Cnt from l_users where user_type = -1 and uid =" + Session["UserId"].ToString() + ") b ";
            //dynamic dt_menu = null; // DbInteract.Get_DataTable(str_Query);
            //if (dt_menu != null)
            //{
            //    if ((dt_menu.Rows.Count > 0))
            //    {
            //        hnddefaultreport.Value = dt_menu.Rows(0)("defaultreport");
            //        hndcustombutton.Value = dt_menu.Rows(0)("PublishedReport");
            //        reportName = dt_menu.Rows(0)("title");
            //        count = Convert.ToInt32(dt_menu.Rows(0)("Cnt"));
            //    }
            //}

            DevExpress.XtraReports.UI.XtraReport objReport = null;

            FilesystemReportStorageWebExtension report = new FilesystemReportStorageWebExtension(System.Web.HttpContext.Current);

            if (chkDesigner.Checked == true && reportName != null)
            {
                type = "2";
            }
            else if (type == null)
            {
                type = "1";
            }

            count = 1;
            //if (count > 0)
            //{
            //    if (Request.QueryString["Designer"] != null && Request.QueryString["Designer"].ToString() == "ON")
            //    {
            //        chkDesigner.Visible = true;
            //    }
            //    else
            //    {
            //        chkDesigner.Visible = false;
            //    }
            //}
            //else
            //{
            //    chkDesigner.Visible = false;
            //}


            string reportPath  = "";
            string storagePath = Server.MapPath("~\\ReportStorage\\");

            // storagePath = "D:\\ReportStore\\";

            if (reportName != null)
            {
                if (reportName == "New")
                {
                    objReport         = new DevExpress.XtraReports.UI.XtraReport();
                    hndreportId.Value = "0";
                    //ElseIf reportName = "Products" Then
                    //    objReport = New Products()
                }
                else
                {
                    //XtraReport1
                    DevExpress.XtraReports.UI.XtraReport rep1 = new DevExpress.XtraReports.UI.XtraReport();
                    reportPath = (storagePath + Convert.ToString(reportName)) + ".resx";

                    //  rep1.LoadLayout(reportPath);
                    objReport = rep1;
                }
            }
            reportDesigner.Visible = false;

            if (!File.Exists(reportPath))
            {
                return;
            }

            if (objReport != null)
            {
                if (reportName == "New")
                {
                    reportDesigner.Visible = true;
                    reportDesigner.OpenReport(reportPath);
                    ASPxWebDocumentViewer1.Visible = false;
                }
                else if ((type == "2"))
                {
                    reportDesigner.Visible = true;
                    reportDesigner.OpenReport(reportPath);
                    ASPxWebDocumentViewer1.Visible = false;
                }
                else
                {
                    ASPxWebDocumentViewer1.Visible = true;
                    ASPxWebDocumentViewer1.OpenReport(reportPath);
                    reportDesigner.Visible = false;
                }

                // Session["export"] = export;

                if (export == "true")
                {
                    //DevExpress.XtraReports.UI.XtraReport reportfile = DevExpress.XtraReports.UI.XtraReport.FromFile(reportPath, true);
                    //MemoryStream stream = new MemoryStream();
                    //reportfile.ExportToPdf(stream);
                    //stream.Seek(0, SeekOrigin.Begin);
                    //byte[] reportByte = stream.ToArray();
                    //Response.Buffer = true;
                    //Response.Clear();
                    //Response.ContentType = "application/msword";
                    //Response.AddHeader("Accept-Header", stream.Length.ToString());
                    //Response.AddHeader("Content-Disposition", "attachment; filename=word.doc");
                    //Response.AddHeader("Content-Length", stream.Length.ToString());
                    //Response.OutputStream.Write(reportByte, 0, reportByte.Length);
                    //// Response.BinaryWrite(stream); // create the file
                    //Response.Flush();
                    //Response.End();


                    DevExpress.XtraReports.UI.XtraReport final = new DevExpress.XtraReports.UI.XtraReport();
                    //Create document first
                    final.CreateDocument();

                    final.Pages.AddRange(objReport.Pages);

                    ExportToDOC(final, "doc", DocumentFormat.Doc);
                }
            }
        }