Пример #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var filePath = HttpContext.Current.Server.MapPath("~/Xtrareport1.repx");

            ASPxWebDocumentViewer1.OpenReport(XtraReport.FromFile(filePath, true));
        }
 public void GenerateReport()
 {
     this.Report            = XtraReport.FromFile(Application.StartupPath + "/Laporan/" + this.ReportName + ".repx", true);
     this.Report.DataSource = this.DataSource;
     this.Report.DataMember = Report.DataMember;
 }
Пример #3
0
        XtraReport IReportResolver.Resolve(string reportName, bool getParameters)
        {
            string layoutFile = GetReportPath(reportName);

            return(XtraReport.FromFile(layoutFile, true));
        }
Пример #4
0
        public override byte[] GetData(string url)
        {
            string[] urlParts   = url.Split('?');
            string   reportName = urlParts[0];

            var path = Path.Combine(reportDirectory, reportName + FileExtension);

            if (File.Exists(path))
            {      //url = "Rep\\XtraReport.repx";
                XtraReport report = XtraReport.FromFile(path);
                if (urlParts.Length > 1)
                {
                    string[] parameterDefinitions = urlParts[1].Split('&');
                    foreach (string parameterDefinition in parameterDefinitions)
                    {
                        string[] keyValue = parameterDefinition.Split('=');
                        DevExpress.XtraReports.Parameters.Parameter parameter = report.Parameters[keyValue[0]];
                        parameter.Value = Convert.ChangeType(keyValue[1], parameter.Type);
                    }
                }

                //read your REPX file to a MemoryStream and return MemoryStream.ToArray();
                var memoryStream = new MemoryStream();
                report.CreateDocument();
                report.SaveLayoutToXml(memoryStream);
                memoryStream.Position = 0;
                return(memoryStream.ToArray());
            }
            return(new byte[0]);



            //try
            //{
            //    // return File.ReadAllBytes(Path.Combine(reportDirectory, url + FileExtension));
            //    string ReportDirectory = "";
            //    var path = Path.Combine(ReportDirectory, url + FileExtension);

            //    //string url= XtraReport


            //    Type objType = Type.GetType(Path.Combine(reportDirectory, url + FileExtension));


            //      //  string.Format("Reports/{0}", url));
            //    object obj = Activator.CreateInstance(objType);

            //    XtraReport xtraReport = (XtraReport)obj;

            //    xtraReport.Parameters["id"].Value = 1;

            //    using (MemoryStream stream = new MemoryStream())
            //    {
            //        xtraReport.SaveLayoutToXml(stream);
            //        return stream.ToArray();
            //    }
            //}
            //catch (Exception)
            //{
            //    throw new FaultException(new FaultReason(string.Format("Could not find report '{0}'.", url)), new FaultCode("Server"), "GetData");
            //}
        }
Пример #5
0
        public IActionResult GetdataReport(string user, string date1, string date2, string site, int type)
        {
            /*Check Session */
            var page            = "268";
            var typeofuser      = "";
            var PermisionAction = "";

            // CheckSession
            if (string.IsNullOrEmpty(HttpContext.Session.GetString("Username")))
            {
                Alert("คุณไม่มีสิทธิ์ใช้งานหน้าดังกล่าว", NotificationType.error);
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                typeofuser      = HttpContext.Session.GetString("TypeOfUserId");
                PermisionAction = HttpContext.Session.GetString("PermisionAction");
                if (PermisionHelper.CheckPermision(typeofuser, PermisionAction, page) == false)
                {
                    Alert("คุณไม่มีสิทธิ์ใช้งานหน้าดังกล่าว", NotificationType.error);
                    return(RedirectToAction("Index", "Home"));
                }
            }
            /*Check Session */


            IActionResult response   = Unauthorized();
            var           StartDate  = date1.Substring(6, 4) + "-" + date1.Substring(3, 2) + "-" + date1.Substring(0, 2) + " 00:00:00";
            var           EndDate    = date2.Substring(6, 4) + "-" + date2.Substring(3, 2) + "-" + date2.Substring(0, 2) + " 23:59:59";
            var           SStartDate = date1.Substring(0, 2) + "/" + date1.Substring(3, 2) + "/" + date1.Substring(6, 4);

            var EEndDate = date2.Substring(0, 2) + "/" + date2.Substring(3, 2) + "/" + date2.Substring(6, 4);


            List <F03> F03DATA = new List <F03>();
            var        user1   = "";

            if (user == null)
            {
                user1 = "";
            }
            else
            {
                user1 = "dbo." + Environment.GetEnvironmentVariable("Company") + "Purch_ Rcpt_ Header].[User ID] = '" + user + "' AND ";
            }



            if (type == 3)
            {
                var query = "SELECT ROW_NUMBER() OVER (ORDER BY c.NoGR) AS ID,c.ReceiptDate AS ReceiptDate,c.VendorName AS VendorName,c.Des AS Des,c.NoGR AS NoGR,c.DocNo AS DocNo,c.Ref AS Ref,c.Qty AS Qty,c.Uom As Uom,c.Disc AS Disc,c.UnitCost AS UnitCost,c.Amount As Amount,(c.Disc/100)*c.Amount AS DiscPrice,c.ShipmentNo AS ShipmentNo,c.AmountBase As AmountBase " +
                            " FROM " +
                            " (SELECT *, b.AmountBase  AS Amount " +
                            " From" +
                            " (SELECT * FROM(SELECT convert(varchar,dbo." + Environment.GetEnvironmentVariable("Company") + "Purch_ Rcpt_ Line].[Posting Date],23) AS ReceiptDate," +
                            " dbo." + Environment.GetEnvironmentVariable("Company") + "Purch_ Rcpt_ Header].[Buy-from Vendor Name] AS VendorName," +
                            " CONCAT(dbo." + Environment.GetEnvironmentVariable("Company") + "Purch_ Rcpt_ Line].Description," +
                            " dbo." + Environment.GetEnvironmentVariable("Company") + "Purch_ Rcpt_ Line].[Description 2]) AS Des," +
                            " dbo." + Environment.GetEnvironmentVariable("Company") + "Purch_ Rcpt_ Line].[Document No_] AS NoGR," +
                            " dbo." + Environment.GetEnvironmentVariable("Company") + "Purch_ Rcpt_ Line].[Order No_] AS DocNo," +
                            " dbo." + Environment.GetEnvironmentVariable("Company") + "Purch_ Rcpt_ Line].[Ref_ PR No_] AS Ref," +
                            " dbo." + Environment.GetEnvironmentVariable("Company") + "Purch_ Rcpt_ Line].[Unit of Measure] AS Uom," +
                            " dbo." + Environment.GetEnvironmentVariable("Company") + "Purch_ Rcpt_ Line].[Direct Unit Cost] As UnitCost," +
                            " dbo." + Environment.GetEnvironmentVariable("Company") + "Purch_ Rcpt_ Line].[Line Discount _] AS Disc," +
                            " SUM(dbo." + Environment.GetEnvironmentVariable("Company") + "Purch_ Rcpt_ Line].Quantity) AS Qty," +
                            " dbo." + Environment.GetEnvironmentVariable("Company") + "Purch_ Rcpt_ Line].[Vendor Shipment No_] AS ShipmentNo," +
                            " dbo." + Environment.GetEnvironmentVariable("Company") + "Purch_ Rcpt_ Line].[Item Charge Base Amount] AS AmountBase" +
                            " FROM dbo." + Environment.GetEnvironmentVariable("Company") + "Purch_ Rcpt_ Header] INNER JOIN dbo." + Environment.GetEnvironmentVariable("Company") + "Purch_ Rcpt_ Line] ON dbo." + Environment.GetEnvironmentVariable("Company") + "Purch_ Rcpt_ Header].No_ = dbo." + Environment.GetEnvironmentVariable("Company") + "Purch_ Rcpt_ Line].[Document No_] " +
                            " WHERE " + user1 + " dbo." + Environment.GetEnvironmentVariable("Company") + "Purch_ Rcpt_ Line].[Posting Date] BETWEEN {0} AND {1} AND dbo." + Environment.GetEnvironmentVariable("Company") + "Purch_ Rcpt_ Header].[Shortcut Dimension 1 Code] = {2}" +
                            " GROUP BY dbo." + Environment.GetEnvironmentVariable("Company") + "Purch_ Rcpt_ Line].[Posting Date]," +
                            " dbo." + Environment.GetEnvironmentVariable("Company") + "Purch_ Rcpt_ Header].[Buy-from Vendor Name]," +
                            " dbo." + Environment.GetEnvironmentVariable("Company") + "Purch_ Rcpt_ Line].Description," +
                            " dbo." + Environment.GetEnvironmentVariable("Company") + "Purch_ Rcpt_ Line].[Document No_], " +
                            " dbo." + Environment.GetEnvironmentVariable("Company") + "Purch_ Rcpt_ Line].[Order No_]," +
                            " dbo." + Environment.GetEnvironmentVariable("Company") + "Purch_ Rcpt_ Line].[Ref_ PR No_]," +
                            " dbo." + Environment.GetEnvironmentVariable("Company") + "Purch_ Rcpt_ Line].[Unit of Measure]," +
                            " dbo." + Environment.GetEnvironmentVariable("Company") + "Purch_ Rcpt_ Line].[Direct Unit Cost]," +
                            " dbo." + Environment.GetEnvironmentVariable("Company") + "Purch_ Rcpt_ Line].[Line Discount _]," +
                            " dbo." + Environment.GetEnvironmentVariable("Company") + "Purch_ Rcpt_ Line].[Description 2]," +
                            "dbo." + Environment.GetEnvironmentVariable("Company") + "Purch_ Rcpt_ Line].[Vendor Shipment No_]," +
                            " dbo." + Environment.GetEnvironmentVariable("Company") + "Purch_ Rcpt_ Line].[Item Charge Base Amount]) as a" +
                            ") as b) as c WHERE c.Qty != 0 ORDER BY c.NoGR";

                F03DATA = _navcontext.F03s.FromSqlRaw(query, StartDate, EndDate, site).ToList();
            }
            else
            {
                var query = "SELECT ROW_NUMBER() OVER (ORDER BY c.NoGR) AS ID,c.ReceiptDate AS ReceiptDate,c.VendorName AS VendorName,c.Des AS Des,c.NoGR AS NoGR,c.DocNo AS DocNo,c.Ref AS Ref,c.Qty AS Qty,c.Uom As Uom,c.Disc AS Disc,c.UnitCost AS UnitCost,c.Amount As Amount,(c.Disc/100)*c.Amount AS DiscPrice,c.ShipmentNo AS ShipmentNo,c.AmountBase As AmountBase " +
                            " FROM " +
                            " (SELECT *, b.AmountBase AS Amount " +
                            " From" +
                            " (SELECT * FROM(SELECT convert(varchar,dbo." + Environment.GetEnvironmentVariable("Company") + "Purch_ Rcpt_ Line].[Posting Date],23) AS ReceiptDate," +
                            " dbo." + Environment.GetEnvironmentVariable("Company") + "Purch_ Rcpt_ Header].[Buy-from Vendor Name] AS VendorName," +
                            " CONCAT(dbo." + Environment.GetEnvironmentVariable("Company") + "Purch_ Rcpt_ Line].Description," +
                            " dbo." + Environment.GetEnvironmentVariable("Company") + "Purch_ Rcpt_ Line].[Description 2]) AS Des," +
                            " dbo." + Environment.GetEnvironmentVariable("Company") + "Purch_ Rcpt_ Line].[Document No_] AS NoGR," +
                            " dbo." + Environment.GetEnvironmentVariable("Company") + "Purch_ Rcpt_ Line].[Order No_] AS DocNo," +
                            " dbo." + Environment.GetEnvironmentVariable("Company") + "Purch_ Rcpt_ Line].[Ref_ PR No_] AS Ref," +
                            " dbo." + Environment.GetEnvironmentVariable("Company") + "Purch_ Rcpt_ Line].[Unit of Measure] AS Uom," +
                            " dbo." + Environment.GetEnvironmentVariable("Company") + "Purch_ Rcpt_ Line].[Direct Unit Cost] As UnitCost," +
                            " dbo." + Environment.GetEnvironmentVariable("Company") + "Purch_ Rcpt_ Line].[Line Discount _] AS Disc," +
                            " SUM(dbo." + Environment.GetEnvironmentVariable("Company") + "Purch_ Rcpt_ Line].Quantity) AS Qty," +
                            " dbo." + Environment.GetEnvironmentVariable("Company") + "Purch_ Rcpt_ Line].[Vendor Shipment No_] AS ShipmentNo," +
                            " dbo." + Environment.GetEnvironmentVariable("Company") + "Purch_ Rcpt_ Line].[Item Charge Base Amount] AS AmountBase" +
                            " FROM dbo." + Environment.GetEnvironmentVariable("Company") + "Purch_ Rcpt_ Header] INNER JOIN dbo." + Environment.GetEnvironmentVariable("Company") + "Purch_ Rcpt_ Line] ON dbo." + Environment.GetEnvironmentVariable("Company") + "Purch_ Rcpt_ Header].No_ = dbo." + Environment.GetEnvironmentVariable("Company") + "Purch_ Rcpt_ Line].[Document No_] " +
                            " WHERE " + user1 + " dbo." + Environment.GetEnvironmentVariable("Company") + "Purch_ Rcpt_ Line].[Posting Date] BETWEEN {0} AND {1} AND dbo." + Environment.GetEnvironmentVariable("Company") + "Purch_ Rcpt_ Header].[Shortcut Dimension 1 Code] = {2} AND dbo." + Environment.GetEnvironmentVariable("Company") + "Purch_ Rcpt_ Line].[Job Document Type] = {3}" +
                            " GROUP BY dbo." + Environment.GetEnvironmentVariable("Company") + "Purch_ Rcpt_ Line].[Posting Date]," +
                            " dbo." + Environment.GetEnvironmentVariable("Company") + "Purch_ Rcpt_ Header].[Buy-from Vendor Name]," +
                            " dbo." + Environment.GetEnvironmentVariable("Company") + "Purch_ Rcpt_ Line].Description," +
                            " dbo." + Environment.GetEnvironmentVariable("Company") + "Purch_ Rcpt_ Line].[Document No_], " +
                            " dbo." + Environment.GetEnvironmentVariable("Company") + "Purch_ Rcpt_ Line].[Order No_]," +
                            " dbo." + Environment.GetEnvironmentVariable("Company") + "Purch_ Rcpt_ Line].[Ref_ PR No_]," +
                            " dbo." + Environment.GetEnvironmentVariable("Company") + "Purch_ Rcpt_ Line].[Unit of Measure]," +
                            " dbo." + Environment.GetEnvironmentVariable("Company") + "Purch_ Rcpt_ Line].[Direct Unit Cost]," +
                            " dbo." + Environment.GetEnvironmentVariable("Company") + "Purch_ Rcpt_ Line].[Line Discount _]," +
                            " dbo." + Environment.GetEnvironmentVariable("Company") + "Purch_ Rcpt_ Line].[Description 2]," +
                            "dbo." + Environment.GetEnvironmentVariable("Company") + "Purch_ Rcpt_ Line].[Vendor Shipment No_]," +
                            " dbo." + Environment.GetEnvironmentVariable("Company") + "Purch_ Rcpt_ Line].[Item Charge Base Amount]) as a" +
                            ") as b) as c WHERE c.Qty != 0 ORDER BY c.NoGR";

                F03DATA = _navcontext.F03s.FromSqlRaw(query, StartDate, EndDate, site, type).ToList();
            }

            //response = Ok(new { data = F03DATA });
            List <F03DATAReport> f03DATAReports = new List <F03DATAReport>();
            F03DATAReport        fdataReport;

            foreach (var std in F03DATA)
            {
                fdataReport             = new F03DATAReport();
                fdataReport.ID          = std.ID;
                fdataReport.DocNo       = std.DocNo;
                fdataReport.NoGR        = std.NoGR;
                fdataReport.Des         = std.Des;
                fdataReport.ReceiptDate = std.ReceiptDate.Substring(8, 2) + "/" + std.ReceiptDate.Substring(5, 2) + "/" + std.ReceiptDate.Substring(0, 4);
                fdataReport.VendorName  = std.VendorName;
                fdataReport.Ref         = std.Ref;
                fdataReport.Uom         = std.Uom;
                fdataReport.UnitCost    = std.UnitCost;
                fdataReport.Disc        = std.Disc;
                fdataReport.Qty         = std.Qty;
                fdataReport.Amount      = std.Amount;
                fdataReport.DiscPrice   = std.DiscPrice;
                fdataReport.ShipmentNo  = std.ShipmentNo;
                fdataReport.Filter      = "Filter : PostingDate :" + SStartDate + ".." + EEndDate + ", Assigned User ID : " + user + " ,Stie : " + site;
                f03DATAReports.Add(fdataReport);
            }

            XtraReport report = XtraReport.FromFile("reports\\ReportF03.repx");

            report.DataSource = f03DATAReports;



            report.CreateDocument(true);
            var @out = new MemoryStream();

            report.ExportToPdf(@out);
            @out.Position = 0;



            response = Ok(new { data = f03DATAReports });


            //return response;
            return(new FileStreamResult(@out, "application/pdf"));
        }
Пример #6
0
        public void PrintReportCustomById(int idReport)
        {
            try
            {
                using (var ctx = new ReportContext())
                {
                    var imageReport = ctx.ReportImageDao.Find(idReport);
                    var path        = FileManagerIts.DeskTopPath + "\\temp.repx";

                    //download do *.repx do banco
                    FileManagerIts.WriteBytesToFile(path, imageReport.ReportImageData);

                    //carregue a estrutura do relatório
                    XtraReport report = XtraReport.FromFile(path, true);

                    //tela personalizado de parametros
                    var parameters = new XFrmReportParams_DEV(report.Parameters);

                    //se o relatorio tem parametros....
                    if (report.Parameters.Count >= 1)
                    {
                        //cancele os parametros nativos
                        report.RequestParameters = false;

                        //chame a tela de parametros
                        parameters.ShowDialog();

                        //limpar os parametros atuais
                        report.Parameters.Clear();

                        //add os novos parametros
                        foreach (var p in parameters.NewParametros)
                        {
                            report.Parameters.Add(p);
                        }
                    }

                    //se a geração nao foi cancelada em
                    if (parameters._isCanceled == false)
                    {
                        //criar o documento
                        ReportPrintTool reportPrintTool = new ReportPrintTool(report);
                        report.CreateDocument();

                        //exibe o relatorio
                        report.ShowPreview();

                        //Remova o relatorio temporario
                        FileManagerIts.DeleteFile(path);
                    }
                    else
                    {
                        XMessageIts.Mensagem("Relatório cancelado.");
                    }
                }
                //se não passar pelo if, a geração foi cancelada, então Task<bool> = false
            }
            catch (Exception ex)
            {
                LoggerUtilIts.ShowExceptionLogs(ex);
                throw ex;
            }
        }
        private void PreviewReport(string fileName)
        {
            XtraReport newReport = XtraReport.FromFile(fileName, true);

            newReport.ShowPreview();
        }
Пример #8
0
        private void grdRaporList_ArsDoubleClick(object sender, EventArgs e)
        {
            string raporDosyaAdi = grdRaporList.getSelectedRowData("RAPOR_DOSYA_ADI");
            string raporAdi      = grdRaporList.getSelectedRowData("RAPOR_ADI");
            string raporYolu     = Path.GetDirectoryName(Application.ExecutablePath) + "\\Raporlar\\" + grdRaporList.getSelectedRowData("RAPOR_ADI") + ".repx";

            var        filePath = raporYolu;
            XtraReport report   = new XtraReport();

            report = XtraReport.FromFile(filePath, true);
            (report.DataSource as SqlDataSource).ConfigureDataConnection += ConfigureDataConnection;

            if (report.Parameters.Count > 0 && parentForm != null)
            {
                foreach (Parameter parameter in report.Parameters)
                {
                    foreach (ArsPanel arsPanel in parentForm.arsPanelList)
                    {
                        Control ctrlParam = arsPanel.GetControlByName(parameter.Name);
                        if (ctrlParam != null)
                        {
                            switch (ctrlParam)
                            {
                            case ArsEdit _:
                                switch (parameter.Type.ToString())
                                {
                                case "System.String":
                                    parameter.Value = (ctrlParam as ArsEdit).GetDataStr();
                                    break;

                                case "System.Int32":
                                    parameter.Value = Convert.ToInt32((ctrlParam as ArsEdit).GetDataStr());
                                    break;

                                case "System.Double":
                                    parameter.Value = Convert.ToDouble((ctrlParam as ArsEdit).GetDataStr());
                                    break;

                                default:
                                    parameter.Value = (ctrlParam as ArsEdit).GetDataStr();
                                    break;
                                }
                                break;

                            case ArsMaskEdit _:
                                parameter.Value = (ctrlParam as ArsMaskEdit).GetDataStr();
                                break;

                            case ArsComboBox _:
                                parameter.Value = (ctrlParam as ArsComboBox).GetString();
                                break;

                            case ArsCheck _:
                                if (parameter.Type.ToString() == "System.Boolean")
                                {
                                    parameter.Value = (ctrlParam as ArsCheck).Checked;
                                }
                                else
                                {
                                    if ((ctrlParam as ArsCheck).Checked)
                                    {
                                        parameter.Value = (ctrlParam as ArsCheck).CheckedValue;
                                    }
                                    else
                                    {
                                        parameter.Value = (ctrlParam as ArsCheck).UnCheckedValue;
                                    }
                                }
                                break;

                            case ArsDecimalEdit _:
                                parameter.Value = (ctrlParam as ArsDecimalEdit).GetDoubleData();
                                break;

                            case ArsDateTime _:
                                parameter.Value = (ctrlParam as ArsDateTime).Value;
                                break;
                            }
                            parameter.Visible = false;
                        }
                    }
                }

                string folderName = grdRaporList.getSelectedRowData("RAPOR_ADI") + DateTime.Now.Ticks + ".pdf";
                var    pathFolder = Path.GetDirectoryName(Application.ExecutablePath) + "\\Raporlar\\PDF\\" + folderName;
                report.ExportToPdf(pathFolder);

                try
                {
                    var pathPdf = Path.GetDirectoryName(Application.ExecutablePath) + "\\Raporlar\\PDF\\" + folderName;
                    Process.Start(pathPdf);
                }
                catch (Exception ex)
                {
                    report.ShowRibbonPreview();
                }

                this.Close();
            }
            else
            {
                report.ShowRibbonPreview();
                this.Close();
            }
        }
Пример #9
0
        private void ExportReportToPdf()
        {
            DataContainer container;
            string        pStatementDate = DateTime.Now.ToString();

            try
            {
                using (SAController ctrlSA = new SAController())
                {
                    List <string> Values;
                    GetOracleParameterValues(out Values, ReportInfo.StoreName);

                    var fields = GetModuleFields();
                    foreach (var field in fields)
                    {
                        if (!string.IsNullOrEmpty(field.ParameterName) && field.ParameterName.ToUpper() == CONSTANTS.SAOKE_DAY_PARAM)
                        {
                            pStatementDate = this[field.FieldID].Encode(field);
                        }
                    }
                    //Tao tung bao cao mot va ket xuat ra file PDF
                    List <string> paras = new List <string>(Values[0].ToString().Split(','));
                    #region Create Data
                    foreach (var para in paras)
                    {
                        List <string> value = new List <string>();
                        value.Add(para);
                        value.Add(Values[1].ToString());
                        ctrlSA.ExecuteReport(out container, ModuleInfo.ModuleID, ModuleInfo.SubModule, value);

                        var dsResult = container.DataSet;

                        var dt = new DataTable(CONSTANTS.REPORT_PARAMETER);
                        foreach (var field in CommonFields)
                        {
                            var name = field.FieldName;
                            var col  = new DataColumn(name, FieldUtils.GetType(field.FieldType));
                            dt.Columns.Add(col);
                        }

                        var row = dt.NewRow();
                        dt.Rows.Add(row);
                        dsResult.Tables.Add(dt);

                        foreach (var field in CommonFields)
                        {
                            row[field.FieldName] = this[field.FieldID];
                        }

                        #endregion
                        #region Create Report
                        dsResult.WriteXml(baseRptPath + ".xml", XmlWriteMode.WriteSchema);
                        var report = XtraReport.FromFile(baseRptPath + ".repx", true);
                        report.XmlDataPath = baseRptPath + ".xml";
                        var fileName = para + "_" + Convert.ToDateTime(pStatementDate, CultureInfo.InvariantCulture).ToShortDateString().Replace("/", "") + ".pdf";

                        System.IO.Directory.CreateDirectory(ExportPath);

                        report.ExportToPdf(ExportPath + "\\" + fileName);
                        #endregion
                    }
                }
            }
            catch (FaultException ex)
            {
                ShowError(ex);
            }
            catch (Exception ex)
            {
                ShowError(ex);
            }
        }
Пример #10
0
        public override void Execute()
        {
            try
            {
                if (ModuleInfo.SendEmail == CONSTANTS.Yes)
                {
                    ExecuteReportAndSendMail();
                }
                else
                {
                    using (SAController ctrlSA = new SAController())
                    {
                        DataContainer container;
                        #region Create Data
                        List <string> Values;
                        GetOracleParameterValues(out Values, ReportInfo.StoreName);
                        ctrlSA.ExecuteReport(out container, ModuleInfo.ModuleID, ModuleInfo.SubModule, Values);

                        var dsResult = container.DataSet;

                        var dt = new DataTable(CONSTANTS.REPORT_PARAMETER);
                        foreach (var field in CommonFields)
                        {
                            var name = field.FieldName;
                            var col  = new DataColumn(name, FieldUtils.GetType(field.FieldType));
                            dt.Columns.Add(col);
                        }

                        var row = dt.NewRow();
                        dt.Rows.Add(row);
                        dsResult.Tables.Add(dt);

                        foreach (var field in CommonFields)
                        {
                            row[field.FieldName] = this[field.FieldID];
                        }

                        #endregion
                        #region Create Report
                        dsResult.WriteXml(baseRptPath + ".xml", XmlWriteMode.WriteSchema);
                        var report = XtraReport.FromFile(baseRptPath + ".repx", true);
                        report.XmlDataPath = baseRptPath + ".xml";

                        string strProcedureName = ReportInfo.StoreName.ToString();
                        string strReportName    = ReportInfo.ReportName.ToString();

                        #endregion
                        report.RequestParameters = false;
                        report.ShowPreviewDialog();
                    }
                }
                //RequireRefresh = true;
            }
            catch (FaultException ex)
            {
                ShowError(ex);
            }
            catch (Exception ex)
            {
                ShowError(ex);
            }
        }
Пример #11
0
        /// <summary>
        /// Gera um relatório para o Spool de relatórios
        /// </summary>
        /// <param name="id">ID do relatório</param>
        /// <returns></returns>
        public void PrintReportSpool(int id, bool visualizar = true)
        {
            try
            {
                var ctx         = new ReportContext();
                var imageReport = ctx.ReportImageDao.Find(id);
                var path        = Application.StartupPath + "\\temp.repx";
                var pathPrnx    = Application.StartupPath + "\\tempPrnx.prnx";
                var isCanceled  = false;

                //download do *.repx do banco
                FileManagerIts.WriteBytesToFile(path, imageReport.ReportImageData);

                //carregue a estrutura do relatório
                XtraReport report = XtraReport.FromFile(path, true);

                //tela personalizado de parametros
                var parameters = new XFrmReportParams_DEV(report.Parameters);

                //se o relatorio tem parametros....
                if (report.Parameters.Count >= 1)
                {
                    report.RequestParameters = false;

                    //chame a tela de paramentros
                    parameters.ShowDialog();

                    report.Parameters.Clear();

                    foreach (var item in parameters.NewParametros)
                    {
                        report.Parameters.Add(item);
                    }

                    isCanceled = parameters._isCanceled;
                }

                #region Processamento do relatório
                //se a geração nao foi cancelada em
                //XFrmReportParams, continue com a geração
                if (isCanceled == false)
                {
                    //criar o documento
                    ReportPrintTool reportPrintTool = new ReportPrintTool(report);
                    report.CreateDocument();

                    //salva o documento gerado em prnx
                    report.PrintingSystem.SaveDocument(pathPrnx);

                    //carrega o relatório gerado para bytes[]
                    var image = FileManagerIts.ReadBytesFromFile(pathPrnx);

                    //zipar a imagem
                    var imageZipped = ZipUtil.ZipFromBytes(image);

                    //criaçao do relatorio
                    var imgSave = new ReportSpool(DateTime.Now, report.DisplayName, imageZipped);
                    var result  = ctx.ReportSpoolDao.Save(imgSave);


                    if (result && visualizar)
                    {
                        GerarRelatorioFromSpool(imgSave.IdSpool, TypeGeracaoSpool.PreVisualizar);
                    }
                    else if (result && !visualizar)
                    {
                        XMessageIts.Mensagem("Relatório gerado com sucesso!", "Sucesso");
                    }
                    else
                    {
                        XMessageIts.Advertencia("Falha ao gerar relatório.\n\n" +
                                                "Contate o adminstrador do sistema", "Atenção");
                    }

                    //Remova o relatorio temporario
                    FileManagerIts.DeleteFile(path);
                    FileManagerIts.DeleteFile(pathPrnx);
                }

                #endregion

                //se não passar pelo if, a geração foi cancelada, então Task<bool> = false
            }
            catch (Exception ex)
            {
                LoggerUtilIts.ShowExceptionLogs(ex);
                throw ex;
            }
        }
Пример #12
0
        public IActionResult GetDataPDF(string Startdate, string EndDate, string type, string Job)
        {
            /*Check Session */
            var page            = "274";
            var typeofuser      = "";
            var PermisionAction = "";

            // CheckSession
            if (string.IsNullOrEmpty(HttpContext.Session.GetString("Username")))
            {
                Alert("กรุณา Login เข้าสู่ระบบ", NotificationType.error);
                return(RedirectToAction("Login", "Accounts"));
            }
            else
            {
                typeofuser      = HttpContext.Session.GetString("TypeOfUserId");
                PermisionAction = HttpContext.Session.GetString("PermisionAction");
                if (PermisionHelper.CheckPermision(typeofuser, PermisionAction, page) == false)
                {
                    Alert("คุณไม่มีสิทธิ์ใช้งานหน้าดังกล่าว", NotificationType.error);
                    return(RedirectToAction("Index", "Home"));
                }
            }
            /*Check Session */



            var date1 = Startdate.Substring(6, 4) + "-" + Startdate.Substring(3, 2) + "-" + Startdate.Substring(0, 2) + " 00:00:00";
            var date2 = EndDate.Substring(6, 4) + "-" + EndDate.Substring(3, 2) + "-" + EndDate.Substring(0, 2) + " 23:59:59";

            var date11 = Startdate.Substring(6, 4) + "-" + Startdate.Substring(3, 2) + "-" + Startdate.Substring(0, 2);
            var date22 = EndDate.Substring(6, 4) + "-" + EndDate.Substring(3, 2) + "-" + EndDate.Substring(0, 2);

            var queryData = "";
            var jobFilter = "";
            List <Outstanding> Outstandings = new List <Outstanding>();
            IActionResult      response     = Unauthorized();
            var filter = "";
            var Site   = "";

            if (Job == null)
            {
                Site = "";
            }
            else
            {
                jobFilter = Job.Replace("\'", "");
                Site      = " AND dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Line].[Location Code] IN (" + Job + ")";
            }

            if (type == "3")
            {
                filter    = "'PostingDate :" + date11 + ".." + date22 + ",Type: All,User : "******"Username") + " Job : " + jobFilter + "' as Filter ";
                queryData = "SELECT ROW_NUMBER() OVER (ORDER BY dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Header].No_) as ID, " +
                            "dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Header].No_ as OrderNo, " +
                            "dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Header].[Order Date] as OrderDate, " +
                            "dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Header].[Buy-from Vendor No_] as VendorNo, " +
                            "dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Header].[Pay-to Name] as VendorName, " +
                            "dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Line].No_ as ItemInLine, " +
                            "dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Line].Description as Description, " +
                            "dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Line].[Direct Unit Cost] as DirectUnitCost, " +
                            "dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Line].[Outstanding Quantity] as OutstandingQuantity, " +
                            "dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Line].[Unit of Measure] as UOM, " +
                            "dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Line].[Location Code] as JobNo, " +
                            "dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Line].Quantity, " +
                            "[Outstanding Quantity]*dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Line].[Direct Unit Cost] as Total," +
                            "case when dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Header].[Job Document Type]=0 THEN 'Purchase Order' ELSE 'Job Order' END as TypeOrder," + filter +

                            " FROM " +
                            "dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Header] " +
                            "INNER JOIN dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Line] ON dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Header].No_ = dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Line].[Document No_] " +
                            "WHERE " +
                            "dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Header].Status = 1 AND   dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Header].[Document Type] =1 and " +
                            "dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Line].[Outstanding Quantity] >0 " +
                            "and dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Header].[Order Date]>={0} and dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Header].[Order Date]<={1}  " + Site;
                Outstandings = _navcontext.Outstandings.FromSqlRaw(queryData, date1, date2).ToList();
            }
            else if (type == "1")
            {
                filter    = "'PostingDate :" + date11 + ".." + date22 + ",Type: Job Order,User : "******"Username") + " Job : " + jobFilter + "' as Filter ";
                queryData = "SELECT ROW_NUMBER() OVER (ORDER BY dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Header].No_) as ID, " +
                            "dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Header].No_ as OrderNo, " +
                            "dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Header].[Order Date] as OrderDate, " +
                            "dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Header].[Buy-from Vendor No_] as VendorNo, " +
                            "dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Header].[Pay-to Name] as VendorName, " +
                            "dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Line].No_ as ItemInLine, " +
                            "dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Line].Description as Description, " +
                            "dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Line].[Direct Unit Cost] as DirectUnitCost, " +
                            "dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Line].[Outstanding Quantity] as OutstandingQuantity, " +
                            "dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Line].[Unit of Measure] as UOM, " +
                            "dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Line].[Location Code] as JobNo, " +
                            "dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Line].Quantity, " +
                            "[Outstanding Quantity]*dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Line].[Direct Unit Cost] as Total," +
                            "case when dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Header].[Job Document Type]=0 THEN 'Purchase Order' ELSE 'Job Order' END as TypeOrder," + filter +
                            " FROM " +
                            "dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Header] " +
                            "INNER JOIN dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Line] ON dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Header].No_ = dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Line].[Document No_] " +
                            "WHERE " +
                            "dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Header].Status = 1 AND   dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Header].[Document Type] =1 and " +
                            "dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Line].[Outstanding Quantity] >0 and dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Header].[Job Document Type]=1 " +
                            "and dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Header].[Order Date]>={0} and dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Header].[Order Date]<={1}  " + Site;
                Outstandings = _navcontext.Outstandings.FromSqlRaw(queryData, date1, date2).ToList();
            }
            else if (type == "0")
            {
                filter    = "'PostingDate :" + date11 + ".." + date22 + ",Type: Purchase Order,User : "******"Username") + " Job : " + jobFilter + "' as Filter ";
                queryData = "SELECT ROW_NUMBER() OVER (ORDER BY dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Header].No_) as ID, " +
                            "dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Header].No_ as OrderNo, " +
                            "dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Header].[Order Date] as OrderDate, " +
                            "dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Header].[Buy-from Vendor No_] as VendorNo, " +
                            "dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Header].[Pay-to Name] as VendorName, " +
                            "dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Line].No_ as ItemInLine, " +
                            "dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Line].Description as Description, " +
                            "dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Line].[Direct Unit Cost] as DirectUnitCost, " +
                            "dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Line].[Outstanding Quantity] as OutstandingQuantity, " +
                            "dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Line].[Unit of Measure] as UOM, " +
                            "dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Line].[Location Code] as JobNo, " +
                            "dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Line].Quantity, " +
                            "[Outstanding Quantity]*dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Line].[Direct Unit Cost] as Total," +
                            "case when dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Header].[Job Document Type]=0 THEN 'Purchase Order' ELSE 'Job Order' END as TypeOrder," + filter +

                            " FROM " +
                            "dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Header] " +
                            "INNER JOIN dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Line] ON dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Header].No_ = dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Line].[Document No_] " +
                            "WHERE " +
                            "dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Header].Status = 1 AND   dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Header].[Document Type] =1 and " +
                            "dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Line].[Outstanding Quantity] >0 and dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Header].[Job Document Type]=0 " +
                            "and dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Header].[Order Date]>={0} and dbo." + Environment.GetEnvironmentVariable("Company") + "Purchase Header].[Order Date]<={1}  " + Site;
                Outstandings = _navcontext.Outstandings.FromSqlRaw(queryData, date1, date2).ToList();
            }



            XtraReport report = XtraReport.FromFile("reports\\Outstanding.repx");

            report.DataSource = Outstandings;


            report.CreateDocument(true);
            var @out = new MemoryStream();

            report.ExportToPdf(@out);
            @out.Position = 0;



            return(new FileStreamResult(@out, "application/pdf"));
        }