using DIXWeb.Business.DIX; using DIXWeb.Business.Workflow; using DIXWeb.Entity.Statement; using DIXWeb.Entity.Workflow; using DIXWeb.Web; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Configuration; using System.Drawing; using System.IO; using System.Linq; using System.Web; using System.Web.Mvc; using ZXing; using ZXing.QrCode; namespace DIXWeb.Web { public class DownloadController : BaseMvcController { DownloadBusiness _dBusiness = new DownloadBusiness(); // GET: GlobalM/Download public ActionResult Index() { return View(); } public ActionResult TwoDCodeView() { try { if (Util.SessionHelper.Session["InspectObjectJson"] == null) { ViewData["Message"] = ""; } else { ViewData["Message"] = Util.SessionHelper.Session["InspectObjectJson"].ToString(); } ViewData["Code"] = 200; Util.SessionHelper.Session["InspectObjectJson"] = null; } catch (Exception ex) { ViewData["Code"] = 500; ViewData["Message"] = ex.Message; } return View(); } public ActionResult UploadInspectObjectTwoD(string[] InspectObjectIdArr) { Receive receive = new Receive(); try { List list = new List(); string dir = Server.MapPath("~/Images/InspectObject/"); if (!Directory.Exists(dir)) Directory.CreateDirectory(dir); int InspectObjectId = 0; for (int i = 0; i < InspectObjectIdArr.Length; i++) { InspectObjectId = int.Parse(InspectObjectIdArr[i]); string InspectObjectCode = _dBusiness.GetInspectObjectById(InspectObjectId).InspectObjectCode; string fullName = dir + InspectObjectCode + ".jpg"; if (System.IO.File.Exists(fullName)) { System.IO.File.Delete(fullName); } KeepJpg(fullName, InspectObjectCode); list.Add(new TwoDCode() { Code = InspectObjectCode, Url = "/Images/InspectObject/" + InspectObjectCode + ".jpg" }); } Util.SessionHelper.Session["InspectObjectJson"] = Newtonsoft.Json.JsonConvert.SerializeObject(list); receive.Code = 200; receive.Message = "SUCCESS"; } catch (Exception ex) { receive.Code = 500; receive.Message = ex.Message; } return Json(receive); } public ActionResult Get2DCode(int InspectObjectId) { Receive receive = new Receive(); try { ReceiveTwoDCode record = _dBusiness.GetInspectObjectById(InspectObjectId); string InspectObjectStr = JsonConvert.SerializeObject(record); string dir = Server.MapPath("~/Images/InspectObject/"); string fileName = record.InspectObjectCode + ".jpg"; receive.Message = "/Images/InspectObject/" + fileName; receive.rows = record.InspectObjectCode; if (!Directory.Exists(dir)) Directory.CreateDirectory(dir); if (!System.IO.File.Exists(dir+fileName)) { KeepJpg(dir + fileName, record.InspectObjectCode); } receive.Code = 200; } catch (Exception ex) { receive.Code = 500; receive.Message = ex.Message; } return Json(receive); } private string KeepJpg(string fullName,string content) { int size = int.Parse(ConfigurationManager.AppSettings["TwoDCodeSize"].ToString()); int width = size; int height = size; BarcodeWriter bw = new BarcodeWriter(); bw.Format = BarcodeFormat.QR_CODE; QrCodeEncodingOptions options = new QrCodeEncodingOptions(); options.DisableECI = true; options.CharacterSet = "UTF-8"; options.Width = width; options.Height = height; options.Margin = 1; bw.Options = options; Bitmap bm = bw.Write(content); bm.Save(fullName); return fullName; } public ActionResult InspectObjectTemplate() { string dir = Server.MapPath("~/Template/"); if (!System.IO.Directory.Exists(dir)) System.IO.Directory.CreateDirectory(dir); string fileName = "InspectObjectTemplate.xls"; string fullName = dir + fileName; if (System.IO.File.Exists(fullName)) System.IO.File.Delete(fullName); //ExcelHelper.CreateExcel(fullName, "Sheet1"); new ExcelHelper().Create(fullName, "Sheet1", false); return File(fullName, "application/ms-excel", fileName); } public ActionResult ImgSNView(string ImgSN,string FilterType) { ViewData["ImgSN"] = ImgSN; ViewData["FilterType"] = FilterType; return View(); } public ActionResult GetImgBySN(string ImgSN, string FilterType) { Receive receive = _dBusiness.GetImgBySN(ImgSN, FilterType); string jsonStr = Newtonsoft.Json.JsonConvert.SerializeObject(receive); return Content(jsonStr); } } }