public SuccessAndMsg GetProductReport(int productID) { var product = db.Products.FirstOrDefault(p => p.ProductID == productID); if (product != null) { SuccessAndMsg getUserResult = userDAO.GetUser(product.Username); SuccessAndMsg getImageUrlResult = imageDAO.GetFirstUrlString(productID); // lấy thông tin người dùng thất bại if (!getUserResult.IsSuccess) { return(new SuccessAndMsg(false, getUserResult.Message)); } // lấy đường dẫn hình ảnh thất bại if (!getImageUrlResult.IsSuccess) { return(new SuccessAndMsg(false, getImageUrlResult.Message)); } User user = getUserResult.Value as User; string url = getImageUrlResult.Value as string; ProductReportViewModel result = new ProductReportViewModel(product, user, url); return(new SuccessAndMsg(true, ProductDAOMsg.GetProductReportSuccessful, result)); } return(new SuccessAndMsg(false, ProductDAOMsg.GetProductReportFailed)); }
/// <summary> /// Lấy ra sản phẩm bị báo cáo vi phạm /// </summary> /// <param name="productID">Mã sản phẩm</param> /// <returns></returns> public ActionResult ReportProduct(int productID) { if (Session["Username"] != null) { SuccessAndMsg getReportProductResult = productDAO.GetProductReport(productID); if (getReportProductResult.IsSuccess) { ProductReportViewModel model = getReportProductResult.Value as ProductReportViewModel; return(PartialView("_ProductIsReportedPartial", model)); } TempData["Error"] = new ErrorViewModel(getReportProductResult.Message); return(RedirectToAction("SharedError", "Error")); } return(RedirectToAction("SharedError", "Error")); }
public ProductReportView() { InitializeComponent(); DataContext = new ProductReportViewModel(); }
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")); } }
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")); } }