예제 #1
0
        public ActionResult PrintLPO(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 <Web.Models.LPOInvoiceModel>();
                List <IT.Web.Models.LPOInvoiceDetailsModel> lPOInvoiceDetails = new List <LPOInvoiceDetailsModel>();
                List <VenderModel> venderModels = new List <VenderModel>();

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

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

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

                lPOInvoiceModels.Insert(0, LPOInvoiceModel);
                compnayModels     = LPOInvoiceModel.compnays;
                lPOInvoiceDetails = LPOInvoiceModel.lPOInvoiceDetailsList;
                venderModels      = LPOInvoiceModel.venders;

                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/" + compnayModels[0].LogoUrl);
                Report.SetParameterValue("Heading", "LPO");

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

                string companyName;

                if (lPOInvoiceModels.Count > 0)
                {
                    companyName = Id + "-" + lPOInvoiceModels[0].PONumber;
                }
                else
                {
                    companyName = "Data Not Found";
                }
                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;
            }
        }
예제 #2
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 <Web.Models.LPOInvoiceModel>();
                List <IT.Web.Models.LPOInvoiceDetailsModel> lPOInvoiceDetails = new List <LPOInvoiceDetailsModel>();
                List <VenderModel> venderModels = new List <VenderModel>();

                var lPOInvoice = new LPOInvoiceModel
                {
                    Id = Id
                };
                var LPOInvoice = webServices.Post(lPOInvoice, "LPO/EditReport/" + Id);

                var LPOInvoiceModel = new IT.Web.Models.LPOInvoiceModel();
                if (LPOInvoice.Data != "[]")
                {
                    LPOInvoiceModel = (new JavaScriptSerializer()).Deserialize <IT.Web.Models.LPOInvoiceModel>(LPOInvoice.Data.ToString());
                }
                int CompanyId = Convert.ToInt32(Session["CompanyId"]);

                lPOInvoiceModels.Insert(0, LPOInvoiceModel);
                compnayModels     = LPOInvoiceModel.compnays;
                lPOInvoiceDetails = LPOInvoiceModel.lPOInvoiceDetailsList;
                venderModels      = LPOInvoiceModel.venders;

                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", "LPO");

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

                string companyName;
                if (lPOInvoiceModels.Count > 0)
                {
                    companyName = Id + "-" + lPOInvoiceModels[0].PONumber;
                }
                else
                {
                    companyName = "Data Not Found";
                }
                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;
            }
        }