Пример #1
0
        public int UploadFileToFolder(int Id)
        {
            string pdfname = "";

            try
            {
                ReportDocument Report = new ReportDocument();
                Report.Load(Server.MapPath("~/Reports/LPO-Invoice/LPOInvoice.rpt"));

                List <IT.Web.Models.CompnayModel>    compnayModels     = new List <Web.Models.CompnayModel>();
                List <IT.Web.Models.LPOInvoiceModel> lPOInvoiceModels  = new List <IT.Web.Models.LPOInvoiceModel>();
                List <LPOInvoiceDetailsModel>        lPOInvoiceDetails = new List <LPOInvoiceDetailsModel>();
                List <VenderModel> venderModels = new List <VenderModel>();

                int CompanyId = Convert.ToInt32(Session["CompanyId"]);

                Web.Models.LPOInvoiceModel lPOInvoiceModel = new Web.Models.LPOInvoiceModel();
                lPOInvoiceModel.Id       = Id;
                lPOInvoiceModel.detailId = CompanyId;

                var LPOInvoice = webServices.Post(lPOInvoiceModel, "Quotation/EditReport/" + Id);

                if (LPOInvoice.Data != "[]")
                {
                    lPOInvoiceModel = (new JavaScriptSerializer()).Deserialize <IT.Web.Models.LPOInvoiceModel>(LPOInvoice.Data.ToString());
                }

                lPOInvoiceModels.Add(lPOInvoiceModel);
                venderModels      = lPOInvoiceModel.venders;
                compnayModels     = lPOInvoiceModel.compnays;
                lPOInvoiceDetails = lPOInvoiceModel.lPOInvoiceDetailsList;

                Report.Database.Tables[0].SetDataSource(compnayModels);
                Report.Database.Tables[1].SetDataSource(venderModels);
                Report.Database.Tables[2].SetDataSource(lPOInvoiceModels);
                Report.Database.Tables[3].SetDataSource(lPOInvoiceDetails);

                Stream stram = Report.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
                stram.Seek(0, SeekOrigin.Begin);

                string companyName = Id + "-" + lPOInvoiceModels[0].PONumber;

                var root = Server.MapPath("/PDF/");
                pdfname = String.Format("{0}.pdf", companyName);
                var path = Path.Combine(root, pdfname);
                path = Path.GetFullPath(path);

                Report.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, path);

                stram.Close();

                return(1);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #2
0
        public ActionResult PrintQuotation(int Id)
        {
            string pdfname = "";

            try
            {
                ReportDocument Report = new ReportDocument();
                Report.Load(Server.MapPath("~/Reports/LPO-Invoice/LPOInvoice.rpt"));

                List <IT.Web.Models.CompnayModel>    compnayModels     = new List <Web.Models.CompnayModel>();
                List <IT.Web.Models.LPOInvoiceModel> lPOInvoiceModels  = new List <IT.Web.Models.LPOInvoiceModel>();
                List <LPOInvoiceDetailsModel>        lPOInvoiceDetails = new List <LPOInvoiceDetailsModel>();
                List <VenderModel> venderModels = new List <VenderModel>();

                int CompanyId = Convert.ToInt32(Session["CompanyId"]);

                Web.Models.LPOInvoiceModel lPOInvoiceModel = new Web.Models.LPOInvoiceModel
                {
                    Id       = Id,
                    detailId = CompanyId,
                };
                var LPOInvoice = webServices.Post(lPOInvoiceModel, "Quotation/EditReport/" + Id);

                if (LPOInvoice.Data != "[]")
                {
                    lPOInvoiceModel = (new JavaScriptSerializer()).Deserialize <IT.Web.Models.LPOInvoiceModel>(LPOInvoice.Data.ToString());
                }

                lPOInvoiceModels.Add(lPOInvoiceModel);
                venderModels      = lPOInvoiceModel.venders;
                compnayModels     = lPOInvoiceModel.compnays;
                lPOInvoiceDetails = lPOInvoiceModel.lPOInvoiceDetailsList;

                venderModels[0].UserName = "******";

                Report.Database.Tables[0].SetDataSource(compnayModels);
                Report.Database.Tables[1].SetDataSource(venderModels);
                Report.Database.Tables[2].SetDataSource(lPOInvoiceModels);
                Report.Database.Tables[3].SetDataSource(lPOInvoiceDetails);

                Report.SetParameterValue("ImageUrl", "http://itmolen-001-site8.htempurl.com/ClientDocument/" + lPOInvoiceModel.compnays[0].LogoUrl);
                Report.SetParameterValue("Heading", "Quotation");

                Stream stram = Report.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
                stram.Seek(0, SeekOrigin.Begin);

                string companyName = Id + "-" + lPOInvoiceModels[0].PONumber;

                var root = Server.MapPath("/PDF/");
                pdfname = String.Format("{0}.pdf", companyName);
                var path = Path.Combine(root, pdfname);
                path = Path.GetFullPath(path);

                Report.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, path);

                //stram.Close();


                byte[] fileBytes = System.IO.File.ReadAllBytes(path);
                string fileName  = companyName + ".PDF";
                //return File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Octet, fileName);

                //Stream stram = Report.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
                //stram.Seek(0, SeekOrigin.Begin);

                return(new FileStreamResult(stram, "application/pdf"));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }