Пример #1
0
        public ActionResult ExportFilePrint()
        {
            try
            {
                StiReport report = (StiReport)TempData["dataExportFileTres"];
                var       stream = new MemoryStream();

                var settings = new StiPdfExportSettings();
                settings.AutoPrintMode = StiPdfAutoPrintMode.Dialog;

                var service = new StiPdfExportService();

                service.ExportPdf(report, stream, settings);

                this.Response.Buffer = true;
                this.Response.ClearContent();
                this.Response.ClearHeaders();
                this.Response.ContentType     = "application/pdf";
                this.Response.ContentEncoding = Encoding.UTF8;

                this.Response.AddHeader("Content-Length", stream.Length.ToString());
                this.Response.BinaryWrite(stream.ToArray());
                this.Response.End();

                TempData["dataExportFileTres"] = report;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(View());
        }
Пример #2
0
        public ActionResult ExportFilePdf()
        {
            try
            {
                StiReport report   = (StiReport)TempData["dataExportFileTres"];
                var       stream   = new MemoryStream();
                var       settings = new StiPdfExportSettings();

                var service = new StiPdfExportService();
                service.ExportPdf(report, stream);

                this.Response.ClearContent();
                this.Response.ClearHeaders();
                this.Response.ContentType     = "application/json";
                this.Response.ContentEncoding = Encoding.UTF8;
                this.Response.AddHeader("content-disposition", "attachment; filename=Report.PDF");
                this.Response.BinaryWrite(stream.ToArray());
                this.Response.End();

                TempData["dataExportFileTres"] = report;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(View());
        }
Пример #3
0
        protected void CarregaPdf(byte[] byArquivos)
        {
            try
            {
                StiReport           stiRelatorio = new StiReport();
                StiPdfExportService service      = new StiPdfExportService();
                MemoryStream        stream       = new MemoryStream();
                BinaryWriter        Writer       = null;
                string Name = @"C:\Users\wcfeitosa\Desktop\GetPdfApi\GetPdfApi\Relatorio\R1300130029.mrt";

                DataTable dtRelatorio = new DataTable();
                dtRelatorio.Columns.Add("dado", typeof(System.Byte[]));

                DataRow dtRow = dtRelatorio.NewRow();

                dtRow["dado"] = byArquivos;
                dtRelatorio.Rows.Add(dtRow);

                stiRelatorio.Load(Name);
                stiRelatorio.RegData(dtRelatorio);
                stiRelatorio.Compile();
                stiRelatorio.Render();

                service.ExportPdf(stiRelatorio, stream);
                service.Export(stiRelatorio, "MyReportTEste.pdf");
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Пример #4
0
        public ActionResult Print(int id)
        {
            var hasAccess = AuthorizationManager.HasAccess("InstagramContract.Print");

            if (!hasAccess)
            {
                throw new Exception("شما مجاز به انجام این عملیات نیستید");
            }

            //LogService.Logging($"Print Contract id:{id}", (int)LogType.Info, "print to pdf", "ContractController/PrintAction");
            StiReport report = new StiReport();

            report.Load(System.Web.HttpContext.Current.Server.MapPath("~/Reports/InstagramContract.mrt"));

            var ContractDto = GetReportDTO(id);

            report.RegBusinessObject("Contract", ContractDto);

            report["ContractContext"] = ContractDto.ContractContext;
            report["PlanDescription"] = ContractDto.PlanDescription;
            report.Dictionary.Variables.Add("ContractContext", ContractDto.ContractContext);
            report.Dictionary.Variables.Add("PlanDescription", ContractDto.PlanDescription);
            //Stimulsoft.Base.StiFontCollection.AddFontFile(@"~\Fonts\BNazanin.ttf");
            report.Render(false);
            MemoryStream stream = new MemoryStream();

            StiPdfExportSettings settings = new StiPdfExportSettings();

            settings.AutoPrintMode = StiPdfAutoPrintMode.Dialog;

            StiPdfExportService service = new StiPdfExportService();

            service.ExportPdf(report, stream, settings);

            this.Response.Buffer = true;
            this.Response.ClearContent();
            this.Response.ClearHeaders();
            this.Response.ContentType = "application/pdf";
            //this.Response.AddHeader("Content-Disposition", "attachment; filename=\"report.pdf\"");
            this.Response.ContentEncoding = Encoding.UTF8;
            this.Response.AddHeader("Content-Length", stream.Length.ToString());
            this.Response.BinaryWrite(stream.ToArray());
            this.Response.End();

            return(View());
        }
Пример #5
0
        public ActionResult Print(int id)
        {
            using (var db = new KiaGalleryContext())
            {
                var entity = db.PostItem.Single(x => x.Id == id);

                var sender = db.Settings.SingleOrDefault(x => x.Key == Model.Context.Settings.KeyPostSenderAddress)?.Value;

                StiReport report = new StiReport();
                report.Load(Server.MapPath("~/Report/Post/Report.mrt"));
                report.Dictionary.Databases.Clear();
                report.ScriptLanguage = StiReportLanguageType.CSharp;
                report.Dictionary.Variables["Count"].Value        = entity.Count.ToString();
                report.Dictionary.Variables["Weight"].Value       = entity.Weight.ToString();
                report.Dictionary.Variables["Price"].Value        = Core.ToSeparator(entity.Price);
                report.Dictionary.Variables["Customer"].Value     = entity.Customer;
                report.Dictionary.Variables["Address"].Value      = entity.City.Name + " - " + entity.Address;
                report.Dictionary.Variables["PhoneNumber"].Value  = entity.PhoneNumber;
                report.Dictionary.Variables["MobileNumber"].Value = entity.MobileNumber;
                report.Dictionary.Variables["PostalCode"].Value   = entity.PostalCode;
                report.Dictionary.Variables["Sender"].Value       = sender;

                //report.Dictionary.Synchronize();
                report.Compile();
                report.Render(false);
                MemoryStream stream = new MemoryStream();

                StiPdfExportSettings settings = new StiPdfExportSettings();

                StiPdfExportService service = new StiPdfExportService();
                service.ExportPdf(report, stream, settings);

                this.Response.Buffer = true;
                this.Response.ClearContent();
                this.Response.ClearHeaders();
                this.Response.ContentType = "application/pdf";
                this.Response.AddHeader("Content-Disposition", "attachment; filename=\"Kia-Post-" + entity.Id + ".pdf\"");
                this.Response.ContentEncoding = Encoding.UTF8;
                this.Response.AddHeader("Content-Length", stream.Length.ToString());
                this.Response.BinaryWrite(stream.ToArray());
                this.Response.End();

                return(new FileStreamResult(stream, "application/pdf"));
            }
        }
Пример #6
0
        protected virtual Attachment GetAttachment()
        {
            Assert.IsNotNull(this.reportModel, "Unable to build the report. Report model is not set.");

            this.reportModel.Order = this.Order;

            StiReport report = this.reportFactory.CreateReport(this.reportModel);

            report.Render();

            StiPdfExportService exportService = new StiPdfExportService();
            MemoryStream        stream        = new MemoryStream();

            exportService.ExportPdf(report, stream);

            stream.Seek(0, SeekOrigin.Begin);

            return(new Attachment(stream, "Report.pdf", "application/pdf"));
        }
Пример #7
0
        private void UtbmMain_ToolClick(object sender, ToolClickEventArgs e)
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;
                switch (e.Tool.Key.ToLower())
                {
                case "btprint":
                    //stiReport.Print(true);
                    stiViewerControl1.InvokeClickPrintButton();
                    break;

                case "btexportpdf":
                    //Stimulsoft.Report.SaveLoad.StiDocumentPageSLService serve = new Stimulsoft.Report.SaveLoad.StiDocumentPageSLService();
                    //StiPdfExportService pdfExport = new StiPdfExportService();

                    //StiPdfExportSettings pdfSettings = new StiPdfExportSettings();
                    ////pdfSettings.

                    //stiReport.ExportDocument(StiExportFormat.Pdf, "");

                    StiPdfExportService  service  = new StiPdfExportService();
                    StiPdfExportSettings settings = new StiPdfExportSettings();



                    MemoryStream stream = new MemoryStream();
                    service.ExportPdf(stiReport, stream, settings);
                    service.Export(stiReport, "test.pdf");
                    break;
                }
            }
            catch (Exception ex)
            {
                WfShowErrorMsg(ex.Message);
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }
Пример #8
0
        private static byte[] GetPdfBytes(byte[] reportTemplate, List <ReportDataSource> dataSources)
        {
            using (Stimulsoft.Report.StiReport stiReport = new Stimulsoft.Report.StiReport())
            {
                foreach (var dataSource in dataSources)
                {
                    stiReport.RegBusinessObject(dataSource.DataSourceName, dataSource.DataSource);
                }

                stiReport.Load(reportTemplate);
                stiReport.Render();

                byte[] result = null;
                using (MemoryStream stream = new MemoryStream())
                {
                    StiPdfExportService pdfService = new StiPdfExportService();
                    pdfService.ExportPdf(stiReport, stream);
                    result = stream.ToArray();
                }
                return(result);
            }
        }
Пример #9
0
        public ActionResult Print(string id)
        {
            List <int> idList = id.Split(',').Select(x => int.Parse(x)).ToList();
            List <LoyalityCardViewModel> cardList;

            using (var db = new KiaGalleryContext())
            {
                cardList = db.LoyalityCard.Where(x => idList.Any(y => y == x.Id)).Select(x => new LoyalityCardViewModel
                {
                    id       = x.Id,
                    code     = x.Code,
                    cardType = x.CardType
                }).ToList();
            }
            var data = cardList.GroupBy(x => new { x.id, x.code, x.cardType }).Select(x => new { x.Key.id, x.Key.code, x.Key.cardType });
            List <StiReport> reports = new List <StiReport>();

            foreach (var cards in data.GroupBy(x => new { x.cardType }))
            {
                DataSet   dataset   = new DataSet("DataSource");
                DataTable dataTable = new DataTable();
                dataTable.Columns.Add("Code");
                dataTable.Columns.Add("Image", typeof(byte[]));

                foreach (var item in cards)
                {
                    DataRow row = dataTable.NewRow();
                    row["Image"] = GetProductFileByte("~/upload/loyalityCard/" + item.code + ".jpg");
                    row["Code"]  = item.code;
                    dataTable.Rows.Add(row);
                }
                dataset.Tables.Add(dataTable);
                StiReport report = new StiReport();
                report.Load(Server.MapPath("~/Report/loyalityCard/loyalityCard.mrt"));
                report.Dictionary.Databases.Clear();
                report.ScriptLanguage = StiReportLanguageType.CSharp;
                report.RegData("DataSource", dataset.Tables[0].DefaultView);
                report.Compile();
                report.Render(false);
                reports.Add(report);
            }

            StiReport joinedReport = new StiReport();

            joinedReport.NeedsCompiling = false;
            joinedReport.IsRendered     = true;
            joinedReport.RenderedPages.Clear();

            foreach (var report in reports)
            {
                foreach (StiPage page in report.CompiledReport.RenderedPages)
                {
                    page.Report = joinedReport;
                    page.NewGuid();
                    joinedReport.RenderedPages.Add(page);
                }
            }
            MemoryStream         stream   = new MemoryStream();
            StiPdfExportSettings settings = new StiPdfExportSettings();
            StiPdfExportService  service  = new StiPdfExportService();

            service.ExportPdf(joinedReport, stream, settings);
            this.Response.Buffer = true;
            this.Response.ClearContent();
            this.Response.ClearHeaders();
            this.Response.ContentType = "application/pdf";
            this.Response.AddHeader("Content-Disposition", "attachment; filename=\"KIA-Report.pdf\"");
            this.Response.ContentEncoding = Encoding.UTF8;
            this.Response.AddHeader("Content-Length", stream.Length.ToString());
            this.Response.BinaryWrite(stream.ToArray());
            //this.Response.End();
            return(new FileStreamResult(stream, "application/pdf"));
        }
Пример #10
0
        public ActionResult PrintAll(string id)
        {
            var ids = id.Split(',').Select(x => int.Parse(x)).ToArray();

            using (var db = new KiaGalleryContext())
            {
                var listOrderItem = db.PostItem.Where(x => ids.Any(y => y == x.Id)).ToList();

                foreach (var item in listOrderItem)
                {
                    item.PostDate = DateTime.Now;
                }
                db.SaveChanges();
                DataSet   dataset   = new DataSet("DataSource");
                DataTable dataTable = new DataTable();
                dataTable.Columns.Add("Row");
                dataTable.Columns.Add("Customer");
                dataTable.Columns.Add("Weight");
                dataTable.Columns.Add("Address");
                dataTable.Columns.Add("PostalCode");

                var rowNumber = 1;
                for (int j = 0; j < listOrderItem.Count; j++)
                {
                    DataRow row = dataTable.NewRow();
                    row["Row"]        = rowNumber;
                    row["Customer"]   = listOrderItem[j].Customer;
                    row["Weight"]     = listOrderItem[j].Weight;
                    row["Address"]    = listOrderItem[j].City.Name + "-" + listOrderItem[j].Address + "\nتلفن: " + listOrderItem[j].PhoneNumber + " - " + listOrderItem[j].MobileNumber;
                    row["PostalCode"] = listOrderItem[j].PostalCode;

                    rowNumber++;
                    dataTable.Rows.Add(row);
                }
                dataset.Tables.Add(dataTable);

                StiReport report = new StiReport();
                report.Load(Server.MapPath("~/Report/Post/Details.mrt"));
                report.Dictionary.Databases.Clear();
                report.ScriptLanguage = StiReportLanguageType.CSharp;
                report.RegData("DataSource", dataset.Tables[0].DefaultView);

                report.Dictionary.Variables["ReportDate"].Value = DateUtility.GetPersianDate(DateTime.Now);

                //report.Dictionary.Synchronize();
                report.Compile();
                report.Render(false);
                MemoryStream stream = new MemoryStream();

                StiPdfExportSettings settings = new StiPdfExportSettings();

                StiPdfExportService service = new StiPdfExportService();
                service.ExportPdf(report, stream, settings);

                this.Response.Buffer = true;
                this.Response.ClearContent();
                this.Response.ClearHeaders();
                this.Response.ContentType = "application/pdf";
                this.Response.AddHeader("Content-Disposition", "attachment; filename=\"Report-" + DateUtility.GetPersianDate(DateTime.Now) + ".pdf\"");
                this.Response.ContentEncoding = Encoding.UTF8;
                this.Response.AddHeader("Content-Length", stream.Length.ToString());
                this.Response.BinaryWrite(stream.ToArray());
                this.Response.End();

                return(new FileStreamResult(stream, "application/pdf"));
            }
        }
    protected virtual Attachment GetAttachment()
    {
      Assert.IsNotNull(this.reportModel, "Unable to build the report. Report model is not set.");

      this.reportModel.Order = this.Order;

      StiReport report = this.reportFactory.CreateReport(this.reportModel);
      report.Render();

      StiPdfExportService exportService = new StiPdfExportService();
      MemoryStream stream = new MemoryStream();
      exportService.ExportPdf(report, stream);

      stream.Seek(0, SeekOrigin.Begin);

      return new Attachment(stream, "Report.pdf", "application/pdf");
    }
Пример #12
0
        public ActionResult orderexporttopdf(int orderid)
        {
            //StimulsoftLicenseHelper.Activate();
            //Stimulsoft.Base.StiActivator

            // step 2: set license key
            //var lic = "6vJhGtLLLz2GNviWmUTrhSqnOItdDwjBylQzQcAOiHlNHxonFYHbpjDx+27slnZs5ftj9P0vr+YW2Pss00P90qmOB2PRI4SjLhAufUnckk8d8LLVu4bgMi/81ymyeO7J3xLjnveXaZmAwzelnxcpnNxi4aUQulVJFvwK+qiOxltk2avtYSEE8jmq4WkdUTp9xske7sHZRhrGePQV5sn54z+RtcNe6cUUNgTwUc8dglgPK/WFe8jcs9XjzaRp3RM+l4PfDluVrp1RaQNJsb10wa5XZT2xv3nuWlW9OMBsPLc/63Hsm5zhEfIP3P6J0pV9x/P2lHAiXuDGKMbeKntP0fxrqxRGrhelfT9AV1O5eDpofH8TAi9HvDPn6LHKsddVVcRfXq658kn94eQWyZkEwfPQJWgQUmXhPcZbj5ecea/dnruFjI+1Y1sxLbJA2wzzYtCU2NEj0kAfxId97OiRITg7oQZs2IMiaOFJgvDL1hR5uv69OffNFZk6+h2bm8OB9GF/PZuisO+BzM+HQRlPQP8FWo6jd79o03LiCtH6mVOrQfEAhF8r0qeF7y8TV2OJ8hHnve7mXKTXr4KmGkRzzmDmfAMrpfoPFF4HtglInJTHbKYqiH2z1DDpJVUNa0+kn/Y9RzSZLtIRBVNzgUMubsB+CPJWMal80oD9bTW8/I3O7QFgvSGIUgCaFAs3rYlkJ3Obt7AVXexGQUuTph7Z4auM4/V4DDhhvdy+8+PIj1/kAilviTYXWxqhbLfciZOEMHeGCtepilOvgvY7arGeSqv5tUfIPqoyBh6RSczg+Hf0soFq0t7ysW3FyteYsfsbHppN1htRrfcP3fEn89vddsamdUgUBgZJ8nDKZ+4E0d+g3w+Jdegnu7PAjNjd5YKLt85NfBRwktdWGwp7fKvK2NpidjRVXRHi1CYlcDoxeaCqOqW7/vPv668X6omx6EsYOyWiFskWQxm/E7dpA4ixmNOyMgolUMRbqQK1uVIT1xeavP3r3C9Pm5f4pBkzpUxX54pc6Z+T/psyIXfR77C+kVXEt3+TA9TX+jZ7Zi8oSX1ImDJWn9wPFMCl11Gl3vHTYno2cvK2zeM8vasV/Q+C9GRJkXkDEceDLHaFbDiWQaJi4TJex/1sbYS239UhciSOVizEhpdVA1E7D6vPzSJ9TQjgWtrbANDmjpHzK2YiTnvbUKf9FibYLmtl0iJ3WUhzO1R03jDUJSvF030BPxGWUt5UMTSpaImLTboUbWbCkLnkDXPyxT9xZORjgWTQzVYNUmCXW2qEtzOyVbB+m16KzWvFf69QI1zMEo/N6a1JzT7499RnmqkuqPyBESnVvAaG7Qfz8jff5tK6ml+BTsCRX4MsHV/Sh100Tv4Kt3raiWKyBG6L2UVbKvtaFnGSYPJzNSY6ndlrxWC65VSSbeXxR6AzKVjLw9sgJLh9i6IQ5d5cUfEFzFKNWvCPDiEERKPpG2Vj4yR3HoayBrgpRqgaLAq1/V//hlWT/dcRIevJGjDgbZGv2E1KOiB4Llj/HX0HAO7cCZrtM57hf5jMnqGDvkYSOOHTPqMPv9QbLdBX+5RnHoa8xtXPp1vVPbJXZHJ/f9rVOnGCqjtR6pWAGDYOOZkXZ02y0zjow0go2JuCZnzYZw37U12hcrb2gxPAlmy/SQerFJXaySRLSXu0QW1pfw==";
            //StiLicense.Key = lic;
            var order = db.tbl_order.ToList().Where(a => a.id == orderid).Select(g => new
            {
                id                 = g.id.ToString(),
                username           = g.user.username,
                sodoordate         = g.sodoor_date.ToPersianDate(),
                sodoortime         = g.sodoor_date.ToShortTimeString(),
                fullname           = g.orderfor.Fname + " " + g.orderfor.Lname,
                cellphone          = g.orderfor.cell,
                frombranch         = g.from_branch.branch_name,
                tobranch           = g.to_branch.branch_name,
                sharh              = g.sharh,
                done               = (g.done == false ? "نزد " + g.to_branch.branch_name : "تحویل شده"),
                address            = g.orderfor.address,
                frombranch_address = g.from_branch.Address,
                tobranch_address   = g.to_branch.Address
            });


            var orderitems = db.tbl_orderdetails.Where(a => a.order_id == orderid).ToList().Select(g => new
            {
                productid   = g.product_id.ToString(),
                Catgname    = g.product_.category.categoryname,
                productname = g.product_.category.categoryname + "| " + g.product_.name + "| " + g.product_.codename + "| " + g.product_.dimension,
                weight      = g.product_.weight.ToString() + "kg",
                number      = g.number.ToString(),
                totalweight = (g.product_.weight.HasValue ? (g.product_.weight.Value * g.number).ToString() : ""),
                desc        = g.description
            });

            int branch = db.tbl_order.Where(a => a.id == orderid).SingleOrDefault().from_branchid;

            StiReport report     = new StiReport();
            string    webroot    = _hostingEnvironment.WebRootPath;
            string    myroot     = "/Content/reports/Reportorder.mrt";
            string    targetroot = webroot + myroot;

            //report.Load(Path.Combine(_hostingEnvironment.WebRootPath, "/Content/reports/Reportorder.mrt"));
            report.Load(targetroot);
            //report.Load(Path.Combine(_hostingEnvironment.WebRootPath, "/Content/reports/Reportorder.mrt"));
            report.RegData("orderinfo", order);
            report.RegData("orderitems", orderitems);
            report.Render();
            MemoryStream stream = new MemoryStream();


            StiPdfExportService  pdfexport = new StiPdfExportService();
            StiPdfExportSettings st        = new StiPdfExportSettings();

            pdfexport.ExportPdf(report, stream, st);

            stream.Position = 0;


            byte[]          b = stream.ToArray();
            tbl_filestosend t = new tbl_filestosend();

            t.caption        = "حواله " + order.SingleOrDefault().id;
            t.filecontent    = b;
            t.uploaddatetime = DateTime.Now;
            t.imagename      = "order" + order.SingleOrDefault().id + ".pdf";
            t.user_id        = int.Parse(User.Claims.FirstOrDefault().Value);
            t.filecontent    = b;

            db.tbl_filestosend.Add(t);
            db.SaveChanges();
            //
            //var context = GlobalHost.ConnectionManager.GetHubContext<chatHub>();



            string msgframe = "";

            msgframe += "<p class='msgtext'>حواله " + orderid + " جهت آقای " + order.SingleOrDefault().fullname + "</p>";
            msgframe += "<a target='_blank' class='btn btn-success' href='/admin/DownLoadFile/" + t.id + "'>دانلود فایل</a>";
            string mymsgpure    = $"حواله {orderid} جهت آقای {order.SingleOrDefault().fullname}";
            string thisdatetime = order.SingleOrDefault().sodoordate + "  " + order.SingleOrDefault().sodoortime;

            tbl_signalRmsg msg = new tbl_signalRmsg {
                from_userid = int.Parse(User.Claims.FirstOrDefault().Value), msg_text = msgframe, datetime_send = DateTime.Now, visibleforall = true, visibletofrom = true, visibletoto = true, msg_textpure = mymsgpure
            };

            db.tbl_signalRmsg.Add(msg);
            db.SaveChanges();

            _hub.Clients.All.SendAsync("addNewMessage", msg.id, User.Claims.FirstOrDefault().Value, User.Identity.Name, msgframe, thisdatetime, "public", branch);



            return(Json(true));
        }
        public ActionResult PrintReport(string date)
        {
            using (var db = new KiaGalleryContext())
            {
                if (string.IsNullOrEmpty(date))
                {
                    date = DateUtility.GetPersianDate(DateTime.Now);
                }
                date = date.Replace("-", "/");

                var persianDate = DateUtility.GetDateTime(date);
                var Inventory   = db.InventoryDetail.Where(x => DbFunctions.TruncateTime(x.Date) == persianDate && x.CategoryInventoryReportMember.Active == true).ToList();
                db.SaveChanges();
                DataSet   dataset   = new DataSet("DataSource");
                DataTable dataTable = new DataTable();
                dataTable.Columns.Add("Row");
                dataTable.Columns.Add("Name");
                dataTable.Columns.Add("Category");
                dataTable.Columns.Add("Weight");
                dataTable.Columns.Add("Count");
                var rowNumber = 1;
                for (int j = 0; j < Inventory.Count; j++)
                {
                    DataRow row = dataTable.NewRow();
                    row["Row"]      = rowNumber;
                    row["Name"]     = Inventory[j].Title;
                    row["Category"] = Inventory[j].CategoryInventoryReportMember.Title;
                    row["Weight"]   = Inventory[j].Weight.ToString("N0").ToPersianNumber();
                    row["Count"]    = Inventory[j].Count.ToString("N0").ToPersianNumber();
                    rowNumber++;
                    dataTable.Rows.Add(row);
                }
                dataset.Tables.Add(dataTable);
                StiReport report = new StiReport();
                report.Load(Server.MapPath("~/Report/PrintReportInventory/PrintReport.mrt"));
                var currentUser = GetAuthenticatedUser();
                report.Dictionary.Variables["Date"].Value = DateUtility.GetPersianDate(persianDate).ToPersianNumber();
                var sumCount  = Inventory.Sum(x => x.Count);
                var sumWeight = Inventory.Sum(x => x.Weight);
                var category  = db.CategoryInventoryReportMember.Where(x => x.Active == true).Select(x => x.Title);
                report.Dictionary.Variables["SumCount"].Value  = sumCount.ToString("N0").ToPersianNumber();
                report.Dictionary.Variables["SumWeight"].Value = sumWeight.ToString("#,#,#,#,#.00#").ToPersianNumber();
                report.Dictionary.Databases.Clear();
                report.ScriptLanguage = StiReportLanguageType.CSharp;
                report.RegData("DataSource", dataset.Tables[0].DefaultView);
                report.Dictionary.Synchronize();
                report.Compile();
                report.Render(false);
                MemoryStream         stream   = new MemoryStream();
                StiPdfExportSettings settings = new StiPdfExportSettings();
                StiPdfExportService  service  = new StiPdfExportService();
                service.ExportPdf(report, stream, settings);
                this.Response.Buffer = true;
                this.Response.ClearContent();
                this.Response.ClearHeaders();
                this.Response.ContentType = "application/pdf";
                this.Response.AddHeader("Content-Disposition", "attachment; filename=\"برگه موجودی طلا-" + DateUtility.GetPersianDate(DateTime.Now) + ".pdf\"");
                this.Response.ContentEncoding = Encoding.UTF8;
                this.Response.AddHeader("Content-Length", stream.Length.ToString());
                this.Response.BinaryWrite(stream.ToArray());
                this.Response.End();
                return(new FileStreamResult(stream, "application/pdf"));
            }
        }
Пример #14
0
        public ActionResult MakePersonReport(string model)
        {
            PersonReportViewModel modelData = JsonConvert.DeserializeObject <PersonReportViewModel>(model);

            using (var db = new KiaGalleryContext())
            {
                var query = db.Person.Select(x => x);

                var result = query.Where(x => x.BranchId == modelData.branchId).Select(x => new
                {
                    x.FirstName,
                    x.LastName,
                    x.PersonNumber,
                    x.MobileNumber,
                }).ToList();

                #region Print
                List <StiReport> reports = new List <StiReport>();

                List <PersonReportPrintViewModel> dataPrint = new List <PersonReportPrintViewModel>();
                foreach (var item in result)
                {
                    var itemPrint = new PersonReportPrintViewModel()
                    {
                        firstName    = item.FirstName,
                        lastName     = item.LastName,
                        personNumber = item.PersonNumber,
                        mobileNumber = item.MobileNumber
                    };

                    dataPrint.Add(itemPrint);
                }

                DataSet   dataset   = new DataSet("DataSource");
                DataTable dataTable = new DataTable();

                dataTable.Columns.Add("FirstName");
                dataTable.Columns.Add("LastName");
                dataTable.Columns.Add("PersonNumber");
                dataTable.Columns.Add("MobileNumber");


                for (int j = 0; j < dataPrint.Count; j++)
                {
                    DataRow row = dataTable.NewRow();
                    row["FirstName"]    = dataPrint[j].firstName;
                    row["LastName"]     = dataPrint[j].lastName;
                    row["PersonNumber"] = dataPrint[j].personNumber;
                    row["MobileNumber"] = dataPrint[j].mobileNumber;


                    dataTable.Rows.Add(row);
                }
                dataset.Tables.Add(dataTable);

                StiReport singleReport = new StiReport();
                singleReport.Load(Server.MapPath("~/Report/PersonReport/PersonReportDetail.mrt"));

                singleReport.Dictionary.Databases.Clear();
                singleReport.ScriptLanguage = StiReportLanguageType.CSharp;
                singleReport.Dictionary.Variables["ReportDate"].Value = DateUtility.GetPersianDate(DateTime.Now);


                singleReport.RegData("DataSource", dataset.Tables[0].DefaultView);
                //report.Dictionary.Synchronize();
                singleReport.Compile();
                singleReport.Render(false);

                reports.Add(singleReport);

                MemoryStream stream = new MemoryStream();

                StiPdfExportSettings settings = new StiPdfExportSettings();
                settings.ImageQuality    = 1f;
                settings.ImageResolution = 300;
                StiPdfExportService service = new StiPdfExportService();
                service.ExportPdf(singleReport, stream, settings);

                this.Response.Buffer = true;
                this.Response.ClearContent();
                this.Response.ClearHeaders();
                this.Response.ContentType = "application/pdf";
                this.Response.AddHeader("Content-Disposition", "attachment; filename=\"KIA-Report.pdf\"");
                this.Response.ContentEncoding = Encoding.UTF8;
                this.Response.AddHeader("Content-Length", stream.Length.ToString());
                this.Response.BinaryWrite(stream.ToArray());
                this.Response.End();
                #endregion
                return(new FileStreamResult(stream, "application/pdf"));
            }
        }
Пример #15
0
        public ActionResult PrintReport(int id)
        {
            using (var db = new KiaGalleryContext())
            {
                var data = db.CompanyInvoiceDetails.Where(x => x.CompanyInvoiceId == id).ToList();

                int count = (int)(data.Count() / 4);

                if (data.Count() % 4 != 0)
                {
                    count++;
                }
                List <StiReport> repo = new List <StiReport>();

                for (int i = 0; i < count; i++)
                {
                    var dataForPrint = data.Skip(i * 4).Take(4).ToList();

                    DataSet   dataset   = new DataSet("DataSource");
                    DataTable dataTable = new DataTable();
                    dataTable.Columns.Add("Row");
                    dataTable.Columns.Add("Carat");
                    dataTable.Columns.Add("Wage");
                    dataTable.Columns.Add("Gram");
                    dataTable.Columns.Add("DescriptionProduct");
                    dataTable.Columns.Add("IdentificationCode");
                    dataTable.Columns.Add("StonePrice");
                    dataTable.Columns.Add("StoneWeight");
                    dataTable.Columns.Add("Whistle");
                    dataTable.Columns.Add("GoldPrice");
                    dataTable.Columns.Add("Percent");
                    dataTable.Columns.Add("SumPrice");

                    var           rowNumber  = 1;
                    double        whistle    = 0;
                    int           gram       = 0;
                    double        Percent    = 0.07;
                    int           stonePrice = 0;
                    int           goldPrice  = 0;
                    int           wage       = 0;
                    List <string> sum        = new List <string>();
                    for (int j = 0; j < dataForPrint.Count; j++)
                    {
                        DataRow row = dataTable.NewRow();
                        row["Row"]   = j + 1;
                        row["Carat"] = dataForPrint[j].Carat.ToString().ToPersianNumber();
                        row["Wage"]  = dataForPrint[j].Wage.ToString("N0").ToPersianNumber();
                        row["Gram"]  = dataForPrint[j].Gram.ToString().ToPersianNumber();
                        row["IdentificationCode"] = dataForPrint[j].IdentificationCode.ToPersianNumber();
                        row["StonePrice"]         = dataForPrint[j].StonePrice.ToString("N0").ToPersianNumber();;
                        row["StoneWeight"]        = dataForPrint[j].StoneWeight.ToString().ToPersianNumber();
                        row["Whistle"]            = dataForPrint[j].Whistle.ToString().ToPersianNumber();
                        row["GoldPrice"]          = dataForPrint[j].GoldPrice.ToString("N0").ToPersianNumber();
                        row["Percent"]            = "7%";
                        whistle = data[j].Whistle;
                        whistle = whistle / 1000;

                        gram       = dataForPrint[j].Gram;
                        stonePrice = Convert.ToInt32(dataForPrint[j].StonePrice);
                        goldPrice  = Convert.ToInt32(dataForPrint[j].GoldPrice);
                        wage       = Convert.ToInt32(dataForPrint[j].Wage);
                        var section1 = whistle + gram;
                        var section2 = goldPrice + wage;
                        var section3 = (section1 * section2) + stonePrice;
                        var section  = Convert.ToInt32(section3 * Percent);
                        var phrase2  = section + section3;
                        row["SumPrice"] = phrase2.ToString("N0").ToPersianNumber();
                        sum.Add(phrase2.ToString());
                        rowNumber++;
                        dataTable.Rows.Add(row);
                    }
                    dataset.Tables.Add(dataTable);

                    StiReport report = new StiReport();
                    report.Load(Server.MapPath("~/Report/CompanyInvoice/Factor.mrt"));


                    report.Dictionary.Databases.Clear();
                    report.ScriptLanguage = StiReportLanguageType.CSharp;
                    report.RegData("DataSource", dataset.Tables[0].DefaultView);
                    var branchPhone    = data.Select(x => x.CompanyInvoice.Branch.Phone).FirstOrDefault();
                    var branchName     = data.Select(x => x.CompanyInvoice.Branch.Name).FirstOrDefault();
                    var companyInvoice = data.Select(x => x.CompanyInvoice).FirstOrDefault();
                    var collect        = sum.Sum(x => Convert.ToDecimal(x));
                    report.Dictionary.Variables["Date"].Value                  = DateUtility.GetPersianDate(DateTime.Now);
                    report.Dictionary.Variables["BuyerName"].Value             = companyInvoice.BuyerName;
                    report.Dictionary.Variables["BuyerEconomicalNumber"].Value = companyInvoice.BuyerEconomicalNumber;
                    report.Dictionary.Variables["BuyerNationalId"].Value       = companyInvoice.BuyerNationalId;
                    report.Dictionary.Variables["BuyerPhone"].Value            = companyInvoice.BuyerPhone;
                    report.Dictionary.Variables["BuyerPostalCode"].Value       = companyInvoice.BuyerPostalCode;
                    report.Dictionary.Variables["BuyerAddress"].Value          = companyInvoice.BuyerAddress;
                    report.Dictionary.Variables["Collect"].Value               = collect.ToString("N0").ToPersianNumber();
                    report.Dictionary.Variables["Reduction"].Value             = companyInvoice.Reduction.ToString("N0").ToPersianNumber();
                    var DeductionDiscounts = collect + companyInvoice.Reduction;
                    report.Dictionary.Variables["DeductionDiscounts"].Value = DeductionDiscounts.ToString("N0").ToPersianNumber();
                    decimal value1   = 0.06M;
                    decimal value2   = 0.03M;
                    var     Taxation = Math.Round((DeductionDiscounts * value1) + (DeductionDiscounts * value2));
                    report.Dictionary.Variables["Taxation"].Value = Taxation.ToString("N0").ToPersianNumber();
                    var Result = Math.Round(Taxation + DeductionDiscounts);
                    report.Dictionary.Variables["Result"].Value = Result.ToString("N0").ToPersianNumber();

                    report.Compile();
                    report.Render(false);

                    repo.Add(report);
                    sum = null;
                }
                StiReport joinedReport = new StiReport();
                joinedReport.NeedsCompiling = false;
                joinedReport.IsRendered     = true;
                joinedReport.RenderedPages.Clear();
                foreach (var report in repo)
                {
                    foreach (StiPage page in report.CompiledReport.RenderedPages)
                    {
                        page.Report = joinedReport;
                        page.NewGuid();
                        joinedReport.RenderedPages.Add(page);
                    }
                }
                MemoryStream         stream   = new MemoryStream();
                StiPdfExportSettings settings = new StiPdfExportSettings();
                StiPdfExportService  service  = new StiPdfExportService();
                service.ExportPdf(joinedReport, stream, settings);

                this.Response.Buffer = true;
                this.Response.ClearContent();
                this.Response.ClearHeaders();
                this.Response.ContentType = "application/pdf";
                this.Response.AddHeader("Content-Disposition", "attachment; filename=\"Report.pdf\"");
                this.Response.ContentEncoding = Encoding.UTF8;
                this.Response.AddHeader("Content-Length", stream.Length.ToString());
                this.Response.BinaryWrite(stream.ToArray());
                this.Response.End();
                return(new FileStreamResult(stream, "application/pdf"));
            }
        }
Пример #16
0
        public ActionResult PrintOrder(int id)
        {
            var user = GetAuthenticatedUser();

            using (var db = new KiaGalleryContext())
            {
                var listOrderItem = db.OrderUsableProductDetail.Where(x => x.OrderUsableProductId == id && x.UsableProduct.PrintingHouseId == user.PrintingHouseId).ToList();

                DataSet   dataset   = new DataSet("DataSource");
                DataTable dataTable = new DataTable();
                dataTable.Columns.Add("Row");
                dataTable.Columns.Add("Name");
                dataTable.Columns.Add("Count");
                dataTable.Columns.Add("Unit");

                var rowNumber = 1;
                for (int j = 0; j < listOrderItem.Count; j++)
                {
                    DataRow row = dataTable.NewRow();
                    row["Row"]   = rowNumber;
                    row["Name"]  = listOrderItem[j].UsableProduct.Name;
                    row["Count"] = listOrderItem[j].Remain;
                    row["Unit"]  = listOrderItem[j].UsableProduct.Unit;

                    rowNumber++;
                    dataTable.Rows.Add(row);
                }
                dataset.Tables.Add(dataTable);

                StiReport report = new StiReport();
                report.Load(Server.MapPath("~/Report/PrintingHouse/PrintOrder.mrt"));
                report.Dictionary.Databases.Clear();
                report.ScriptLanguage = StiReportLanguageType.CSharp;
                report.RegData("DataSource", dataset.Tables[0].DefaultView);
                var branchPhone = listOrderItem.Select(x => x.OrderUsableProduct.Branch.Phone).FirstOrDefault();
                var branchName  = listOrderItem.Select(x => x.OrderUsableProduct.Branch.Name).FirstOrDefault();
                var alis        = listOrderItem.Select(x => x.OrderUsableProduct.Branch.Alias).FirstOrDefault();
                var orderNumber = listOrderItem.Select(x => "SPLY-" + alis + "-" + x.OrderUsableProduct.Id).FirstOrDefault();
                report.Dictionary.Variables["Date"].Value        = DateUtility.GetPersianDate(DateTime.Now);
                report.Dictionary.Variables["BranchPhone"].Value = branchPhone;
                report.Dictionary.Variables["BranchName"].Value  = branchName;
                report.Dictionary.Variables["OrderNumber"].Value = orderNumber.ToPersianNumber();

                //report.Dictionary.Synchronize();
                report.Compile();
                report.Render(false);
                MemoryStream stream = new MemoryStream();

                StiPdfExportSettings settings = new StiPdfExportSettings();

                StiPdfExportService service = new StiPdfExportService();
                service.ExportPdf(report, stream, settings);

                this.Response.Buffer = true;
                this.Response.ClearContent();
                this.Response.ClearHeaders();
                this.Response.ContentType = "application/pdf";
                this.Response.AddHeader("Content-Disposition", "attachment; filename=\"Report-" + DateUtility.GetPersianDate(DateTime.Now) + ".pdf\"");
                this.Response.ContentEncoding = Encoding.UTF8;
                this.Response.AddHeader("Content-Length", stream.Length.ToString());
                this.Response.BinaryWrite(stream.ToArray());
                this.Response.End();

                return(new FileStreamResult(stream, "application/pdf"));
            }
        }
Пример #17
0
        public ActionResult MakeProductLicenceReportMin(string model)
        {
            ProductReportViewModel modelData = JsonConvert.DeserializeObject <ProductReportViewModel>(model);
            var id = modelData.id;

            using (var db = new KiaGalleryContext())
            {
                var goldPrice = long.Parse(db.Settings.SingleOrDefault(x => x.Key == Settings.KeyGoldPrice)?.Value);
                var euroPrice = long.Parse(db.Settings.SingleOrDefault(x => x.Key == Settings.KeyEuroPrice)?.Value);
                var result    = db.LicencedProduct.Where(x => id.Any(y => y == x.Id)).Select(x => new
                {
                    x.Id,
                    FileName = x.Product.ProductFileList.FirstOrDefault(y => y.FileType == FileType.WhiteBack).FileName != null ? x.Product.ProductFileList.FirstOrDefault(y => y.FileType == FileType.WhiteBack).FileName : x.FileName,
                    x.Code,
                    x.Weight,
                    x.Color,
                    x.Purity,
                    x.Wage,
                    x.LeatherStonePrice,
                    x.Euro,
                    x.Barcode,
                }).ToList();

                #region Prints

                byte[] defaultImage = System.IO.File.ReadAllBytes(Server.MapPath("~/content/image/kia-gallery-logo-square.png"));

                List <StiReport> reports = new List <StiReport>();

                List <LicencedProductViewModel> dataPrint = new List <LicencedProductViewModel>();
                foreach (var item in result)
                {
                    var itemPrint = new LicencedProductViewModel()
                    {
                        id                = item.Id,
                        image             = string.IsNullOrEmpty(item.FileName) ? defaultImage : GetProductFileByte(item.FileName),
                        code              = item.Code,
                        weight            = item.Weight,
                        color             = item.Color,
                        purity            = item.Purity,
                        wage              = item.Wage,
                        leatherStonePrice = item.LeatherStonePrice,
                        euro              = item.Euro,
                        barcode           = item.Barcode,
                        stringPrice       = Core.ToSeparator(Convert.ToInt32(((((goldPrice + item.Wage) * item.Weight) + ((goldPrice + item.Wage) * item.Weight) * 0.07) + item.LeatherStonePrice.Value) + ((((goldPrice + item.Wage) * item.Weight) + ((goldPrice + item.Wage) * item.Weight) * 0.07) + item.LeatherStonePrice.Value) * 0.09) - (Convert.ToInt32(((((goldPrice + item.Wage) * item.Weight) + ((goldPrice + item.Wage) * item.Weight) * 0.07) + item.LeatherStonePrice.Value) + ((((goldPrice + item.Wage) * item.Weight) + ((goldPrice + item.Wage) * item.Weight) * 0.07) + item.LeatherStonePrice.Value) * 0.09) % 1000)),
                    };
                    dataPrint.Add(itemPrint);
                }

                dataPrint = dataPrint.OrderBy(x => x.id).ToList();

                DataSet   dataset   = new DataSet("DataSource");
                DataTable dataTable = new DataTable();
                dataTable.Columns.Add("Image", typeof(byte[]));
                dataTable.Columns.Add("Code");
                dataTable.Columns.Add("Weight");
                dataTable.Columns.Add("Purity");
                dataTable.Columns.Add("Colour");
                dataTable.Columns.Add("Price");
                dataTable.Columns.Add("Wage");
                dataTable.Columns.Add("LeatherStonePrice");
                dataTable.Columns.Add("Euro");
                dataTable.Columns.Add("StringPrice");
                dataTable.Columns.Add("EuroPrice");
                dataTable.Columns.Add("Index");
                dataTable.Columns.Add("Barcode");


                for (int j = 0; j < dataPrint.Count; j++)
                {
                    DataRow row = dataTable.NewRow();
                    row["Image"]             = dataPrint[j].image;
                    row["Code"]              = dataPrint[j].code;
                    row["Weight"]            = dataPrint[j].weight;
                    row["Purity"]            = dataPrint[j].purity;
                    row["Colour"]            = dataPrint[j].color;
                    row["Wage"]              = dataPrint[j].wage;
                    row["LeatherStonePrice"] = dataPrint[j].leatherStonePrice;
                    row["Euro"]              = dataPrint[j].euro;
                    row["Barcode"]           = dataPrint[j].barcode;
                    if (dataPrint[j].color != "Silver" && dataPrint[j].color != "Silver&Beads" && dataPrint[j].color != "Silver&Leather")
                    {
                        row["StringPrice"] = dataPrint[j].stringPrice;
                        row["EuroPrice"]   = Convert.ToInt32(dataPrint[j].stringPrice.Replace(",", "")) / euroPrice + dataPrint[j].euro;
                    }
                    else
                    {
                        row["StringPrice"] = dataPrint[j].leatherStonePrice;
                        row["EuroPrice"]   = Convert.ToInt32(dataPrint[j].leatherStonePrice.ToString().Replace(",", "")) / euroPrice + dataPrint[j].euro;
                    }
                    row["Index"] = modelData.listRow[j];
                    dataTable.Rows.Add(row);
                }
                dataset.Tables.Add(dataTable);

                StiReport singleReport = new StiReport();

                singleReport.Load(Server.MapPath("~/Report/Report/licenceMin.mrt"));

                singleReport.Dictionary.Databases.Clear();
                singleReport.ScriptLanguage = StiReportLanguageType.CSharp;
                singleReport.RegData("DataSource", dataset.Tables[0].DefaultView);
                //singleReport.Dictionary.Variables["ProductType"].Value = Enums.GetTitle(modelData.productType);
                //report.Dictionary.Synchronize();
                singleReport.Compile();
                singleReport.Render(false);
                reports.Add(singleReport);
                MemoryStream         stream   = new MemoryStream();
                StiPdfExportSettings settings = new StiPdfExportSettings();
                settings.ImageQuality    = 1.0f;
                settings.ImageResolution = 300;
                StiPdfExportService service = new StiPdfExportService();
                service.ExportPdf(singleReport, stream, settings);
                this.Response.Buffer = true;
                this.Response.ClearContent();
                this.Response.ClearHeaders();
                this.Response.ContentType = "application/pdf";
                this.Response.AddHeader("Content-Disposition", "attachment; filename=\"KIA-Report.pdf\"");
                this.Response.ContentEncoding = Encoding.UTF8;
                this.Response.AddHeader("Content-Length", stream.Length.ToString());
                this.Response.BinaryWrite(stream.ToArray());
                this.Response.End();
                #endregion
                return(new FileStreamResult(stream, "application/pdf"));
            }
        }
Пример #18
0
        public ActionResult MakeSingleProductReport(string model)
        {
            ProductReportViewModel modelData = JsonConvert.DeserializeObject <ProductReportViewModel>(model);
            var id = modelData.id;

            using (var db = new KiaGalleryContext())
            {
                var result = db.Product.Where(x => id.Any(y => y == x.Id)).Select(x => new
                {
                    FileName = x.ProductFileList.FirstOrDefault(y => y.FileType == Model.FileType.WhiteBack).FileName,
                    x.BookCode,
                    x.Title
                }).ToList();

                #region Prints

                byte[] defaultImage = System.IO.File.ReadAllBytes(Server.MapPath("~/content/image/kia-gallery-logo-square.png"));

                List <StiReport> reports = new List <StiReport>();

                List <ProductReportPrintViewModel> dataPrint = new List <ProductReportPrintViewModel>();
                foreach (var item in result)
                {
                    var itemPrint = new ProductReportPrintViewModel()
                    {
                        Image    = string.IsNullOrEmpty(item.FileName) ? defaultImage : GetProductFileByte(item.FileName),
                        Title    = item.Title,
                        BookCode = item.BookCode
                    };

                    dataPrint.Add(itemPrint);
                }

                dataPrint = dataPrint.OrderByDescending(x => x.BookCode).ToList();

                DataSet   dataset   = new DataSet("DataSource");
                DataTable dataTable = new DataTable();
                dataTable.Columns.Add("Image", typeof(byte[]));
                dataTable.Columns.Add("Title");
                dataTable.Columns.Add("BookCode");

                for (int j = 0; j < dataPrint.Count; j++)
                {
                    DataRow row = dataTable.NewRow();
                    row["Image"]    = dataPrint[j].Image;
                    row["Title"]    = dataPrint[j].Title;
                    row["BookCode"] = dataPrint[j].BookCode;

                    dataTable.Rows.Add(row);
                }
                dataset.Tables.Add(dataTable);

                StiReport singleReport = new StiReport();
                if (modelData.type == 0)
                {
                    singleReport.Load(Server.MapPath("~/Report/Report/ProductReportDetail.mrt"));
                }
                else
                {
                    singleReport.Load(Server.MapPath("~/Report/Report/ProductReport.mrt"));
                }

                singleReport.Dictionary.Databases.Clear();
                singleReport.ScriptLanguage = StiReportLanguageType.CSharp;
                singleReport.RegData("DataSource", dataset.Tables[0].DefaultView);
                //singleReport.Dictionary.Variables["ProductType"].Value = Enums.GetTitle(modelData.productType);
                //report.Dictionary.Synchronize();
                singleReport.Compile();
                singleReport.Render(false);
                reports.Add(singleReport);
                MemoryStream         stream   = new MemoryStream();
                StiPdfExportSettings settings = new StiPdfExportSettings();
                settings.ImageQuality    = 1f;
                settings.ImageResolution = 300;
                StiPdfExportService service = new StiPdfExportService();
                service.ExportPdf(singleReport, stream, settings);
                this.Response.Buffer = true;
                this.Response.ClearContent();
                this.Response.ClearHeaders();
                this.Response.ContentType = "application/pdf";
                this.Response.AddHeader("Content-Disposition", "attachment; filename=\"KIA-Report.pdf\"");
                this.Response.ContentEncoding = Encoding.UTF8;
                this.Response.AddHeader("Content-Length", stream.Length.ToString());
                this.Response.BinaryWrite(stream.ToArray());
                this.Response.End();
                #endregion
                return(new FileStreamResult(stream, "application/pdf"));
            }
        }
Пример #19
0
        public ActionResult PrintReport(string model)
        {
            string persianDayName         = string.Empty;
            FoodCensusViewModel modelData = JsonConvert.DeserializeObject <FoodCensusViewModel>(model);
            var date = modelData.date;

            var foreignDate = DateUtility.GetDateTime(date);

            var foreignDayOfWeek = foreignDate.Value.DayOfWeek;

            switch (foreignDayOfWeek)
            {
            case DayOfWeek.Saturday:
                persianDayName = "شنبه";
                break;

            case DayOfWeek.Sunday:
                persianDayName = "یکشنبه";
                break;

            case DayOfWeek.Monday:
                persianDayName = "دوشنبه";
                break;

            case DayOfWeek.Tuesday:
                persianDayName = "سه شنبه";
                break;

            case DayOfWeek.Wednesday:
                persianDayName = "چهارشنبه";
                break;

            case DayOfWeek.Thursday:
                persianDayName = "پنج شنبه";
                break;

            default:
                persianDayName = "چنین روزی موجود نیست";
                break;
            }
            using (var db = new KiaGalleryContext())
            {
                var persianDate = DateUtility.GetDateTime(date);
                var userList    = db.User.Where(x => x.RoleList.Any(y => y.Title == "foodRegistration") && x.Active == true).ToList();
                var foodCensus  = db.FoodRegistration.Where(x => DbFunctions.TruncateTime(x.Date) == DbFunctions.TruncateTime(persianDate)).Select(x => new
                {
                    userId = x.UserId,
                    x.Appertizer,
                    food = x.Food,
                    x.FoodWithoutRice,
                }).ToList();

                List <StiReport>           reports   = new List <StiReport>();
                List <FoodCensusViewModel> dataPrint = new List <FoodCensusViewModel>();
                foreach (var item in userList)
                {
                    var itemPrint = new FoodCensusViewModel()
                    {
                        userName        = item.FullName,
                        appertizer      = foodCensus.FirstOrDefault(x => x.userId == item.Id)?.Appertizer ?? false,
                        food            = foodCensus.FirstOrDefault(x => x.userId == item.Id)?.food ?? false,
                        foodWithoutRice = foodCensus.FirstOrDefault(x => x.userId == item.Id)?.FoodWithoutRice ?? false,
                    };
                    dataPrint.Add(itemPrint);
                }
                DataSet   dataset   = new DataSet("DataSource");
                DataTable dataTable = new DataTable();
                dataTable.Columns.Add("Row");
                dataTable.Columns.Add("User");
                dataTable.Columns.Add("Appetizer");
                dataTable.Columns.Add("FoodStatus");
                dataTable.Columns.Add("FoodWithoutRice");
                dataTable.Columns.Add("Row2");
                dataTable.Columns.Add("User2");
                dataTable.Columns.Add("Appetizer2");
                dataTable.Columns.Add("FoodStatus2");
                dataTable.Columns.Add("FoodWithoutRice2");

                var rowNumber = 1;
                for (int j = 0; j < dataPrint.Count; j = j + 2)
                {
                    DataRow row = dataTable.NewRow();
                    row["Row"]             = j + 1;
                    row["" + "User"]       = dataPrint[j].userName;
                    row["Appetizer"]       = dataPrint[j].appertizer;
                    row["FoodStatus"]      = dataPrint[j].food;
                    row["FoodWithoutRice"] = dataPrint[j].foodWithoutRice;
                    if (dataPrint.Count > j + 1)
                    {
                        row["Row2"]             = j + 2;
                        row["User2"]            = dataPrint[j + 1].userName;
                        row["Appetizer2"]       = dataPrint[j + 1].appertizer;
                        row["FoodStatus2"]      = dataPrint[j + 1].food;
                        row["FoodWithoutRice2"] = dataPrint[j + 1].foodWithoutRice;
                    }
                    rowNumber++;
                    dataTable.Rows.Add(row);
                }

                dataset.Tables.Add(dataTable);
                StiReport report = new StiReport();
                report.Load(Server.MapPath("~/Report/FoodCensusReport/FoodCensusReport.mrt"));
                var currentUser          = GetAuthenticatedUser();
                var foodName             = db.FoodCensus.Where(x => x.Date == persianDate).FirstOrDefault();
                var foodCount            = db.FoodRegistration.Where(x => x.Date == persianDate && x.Food == true).Count();
                var appetizerCount       = db.FoodRegistration.Where(x => x.Date == persianDate && x.Appertizer == true).Count();
                var foodWithoutRiceCount = db.FoodRegistration.Where(x => x.Date == persianDate && x.FoodWithoutRice == true).Count();
                report.Dictionary.Variables["Date"].Value                 = date.ToPersianNumber();
                report.Dictionary.Variables["FoodName"].Value             = foodName.FoodName;
                report.Dictionary.Variables["FoodCount"].Value            = foodCount.ToString();
                report.Dictionary.Variables["AppetizerCount"].Value       = appetizerCount.ToString();
                report.Dictionary.Variables["FoodWithoutRiceCount"].Value = foodWithoutRiceCount.ToString();
                report.Dictionary.Variables["Day"].Value = persianDayName;
                report.Dictionary.Databases.Clear();
                report.ScriptLanguage = StiReportLanguageType.CSharp;
                report.RegData("DataSource", dataset.Tables[0].DefaultView);
                report.Dictionary.Synchronize();
                report.Compile();
                report.Render(false);
                MemoryStream         stream   = new MemoryStream();
                StiPdfExportSettings settings = new StiPdfExportSettings();
                StiPdfExportService  service  = new StiPdfExportService();
                service.ExportPdf(report, stream, settings);
                this.Response.Buffer = true;
                this.Response.ClearContent();
                this.Response.ClearHeaders();
                this.Response.ContentType = "application/pdf";
                this.Response.AddHeader("Content-Disposition", "attachment; filename=\"برگه گزارش ثبت غذا-" + DateUtility.GetPersianDate(DateTime.Now) + ".pdf\"");
                this.Response.ContentEncoding = Encoding.UTF8;
                this.Response.AddHeader("Content-Length", stream.Length.ToString());
                this.Response.BinaryWrite(stream.ToArray());
                this.Response.End();
                return(new FileStreamResult(stream, "application/pdf"));
            }
        }