Ejemplo n.º 1
0
        public JsonResult Load(int id)
        {
            Response response;

            try
            {
                using (var db = new KiaGalleryContext())
                {
                    var entity = db.LicencedProduct.Single(x => x.Id == id);

                    var data = new LicencedProductViewModel
                    {
                        id                = entity.Id,
                        productId         = entity.ProductId,
                        code              = entity.Code,
                        wage              = entity.Wage,
                        leatherStonePrice = entity.LeatherStonePrice,
                        barcode           = entity.Barcode,
                        euro              = entity.Euro,
                        purity            = entity.Purity,
                        color             = entity.Color,
                        fileName          = entity.FileName,
                        weight            = entity.Weight,
                        productName       = entity.Product?.Title
                    };
                    response = new Response()
                    {
                        status = 200,
                        data   = data
                    };
                }
            }
            catch (Exception ex)
            {
                response = Core.GetExceptionResponse(ex);
            }
            return(Json(response, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 2
0
        public JsonResult Save(LicencedProductViewModel model)
        {
            Response response;
            string   oldFileName = "";

            try
            {
                using (var db = new KiaGalleryContext())
                {
                    if (model.id > 0 && model.id != null)
                    {
                        var entity = db.LicencedProduct.Single(x => x.Id == model.id);
                        entity.ProductId         = model.productId;
                        entity.Weight            = model.weight;
                        entity.Color             = model.color;
                        entity.Purity            = "18K";
                        entity.Code              = model.code;
                        entity.Barcode           = model.barcode;
                        entity.FileName          = model.fileName;
                        entity.Euro              = model.euro;
                        entity.Wage              = model.wage;
                        entity.LeatherStonePrice = model.leatherStonePrice;
                        if (!string.IsNullOrEmpty(entity.FileName) && entity.FileName != model.fileName)
                        {
                            oldFileName = entity.FileName;
                        }
                    }
                    else
                    {
                        var entity = new LicencedProduct()
                        {
                            ProductId         = model.productId,
                            Weight            = model.weight,
                            Color             = model.color,
                            Purity            = "18K",
                            Code              = model.code,
                            Barcode           = model.barcode,
                            FileName          = model.fileName,
                            Euro              = model.euro,
                            Wage              = model.wage,
                            LeatherStonePrice = model.leatherStonePrice,
                        };
                        db.LicencedProduct.Add(entity);
                    }
                    db.SaveChanges();

                    if (!string.IsNullOrEmpty(oldFileName) && System.IO.File.Exists(Server.MapPath("~/Upload/LicencedProduct/" + oldFileName)))
                    {
                        System.IO.File.Delete(Server.MapPath("~/Upload/LicencedProduct/" + oldFileName));
                    }
                };
                response = new Response()
                {
                    status  = 200,
                    message = "محصول با موفقیت اضافه شد."
                };
            }
            catch (Exception ex)
            {
                response = Core.GetExceptionResponse(ex);
            }
            return(Json(response, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 3
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"));
            }
        }