//[ValidateAntiForgeryToken] private void SaveToDatabase(tblChalanReport report) { unitOfWork.ChalanReport.Insert(report); unitOfWork.Save(); }
private void SupplierProductToStoreReport(int SupplierId, int StoreId, List <VM_ProductToStore> productList) { var newProductList = new List <VM_ProductToStore>(); foreach (var product in productList) { VM_ProductToStore newProduct = new VM_ProductToStore(); newProduct.StoreId = StoreId; newProduct.StoreName = unitOfWork.StoreRepository.GetByID(StoreId).store_name; newProduct.SupplierId = SupplierId; newProduct.SupplierName = product.SupplierName; newProduct.ProductName = product.ProductName; newProduct.Quantity = product.Quantity; newProduct.Unit = product.Unit; newProduct.UnitPrice = product.UnitPrice; newProductList.Add(newProduct); } int restaurantId = Int32.Parse(SessionManger.RestaurantOfLoggedInUser(Session).ToString());; string restaurantName = unitOfWork.RestaurantRepository.GetByID(restaurantId).Name; string restaurantAddress = unitOfWork.RestaurantRepository.GetByID(restaurantId).Address; LocalReport localReport = new LocalReport(); localReport.ReportPath = Server.MapPath("~/Reports/SupplierProductToStoreReport.rdlc"); localReport.SetParameters(new ReportParameter("RestaurantName", restaurantName)); localReport.SetParameters(new ReportParameter("RestaurantAddress", restaurantAddress)); ReportDataSource reportDataSource = new ReportDataSource("SupplierProductToStoreDataSet", newProductList); localReport.DataSources.Add(reportDataSource); string reportType = "pdf"; string mimeType; string encoding; string fileNameExtension; //The DeviceInfo settings should be changed based on the reportType //http://msdn.microsoft.com/en-us/library/ms155397.aspx string deviceInfo = "<DeviceInfo>" + " <OutputFormat>PDF</OutputFormat>" + " <PageWidth>8.5in</PageWidth>" + " <PageHeight>11in</PageHeight>" + " <MarginTop>0.5in</MarginTop>" + " <MarginLeft>0in</MarginLeft>" + " <MarginRight>0in</MarginRight>" + " <MarginBottom>0.5in</MarginBottom>" + "</DeviceInfo>"; Warning[] warnings; string[] streams; byte[] renderedBytes; //Render the report renderedBytes = localReport.Render( reportType, deviceInfo, out mimeType, out encoding, out fileNameExtension, out streams, out warnings); var fileName = RenameReportFile(SupplierId, StoreId, DateTime.Now, "Sup", "Main"); var path = System.IO.Path.Combine(Server.MapPath("~/pdfReport")); //var saveAs = string.Format("{0}.pdf", Path.Combine(path, "myfilename")); var saveAs = path + "\\" + fileName + ".pdf"; var idx = 0; while (System.IO.File.Exists(saveAs)) { idx++; saveAs = string.Format("{0}.{1}.pdf", Path.Combine(path, "myfilename"), idx); } using (var stream = new FileStream(saveAs, FileMode.Create, FileAccess.Write)) { stream.Write(renderedBytes, 0, renderedBytes.Length); stream.Close(); } tblChalanReport report = new tblChalanReport() { ToStore = Convert.ToString(StoreId), Supplier = Convert.ToString(SupplierId), Date = DateTime.Now, ReportName = fileName }; SaveToDatabase(report); localReport.Dispose(); }