1
duan
2024-08-21 f71a02229c1ba00fbecaead19256593ffb052753
提交 | 用户 | age
6ac346 1 using DIXWeb.Business.DIX;
A 2 using DIXWeb.Business.Workflow;
3 using DIXWeb.Entity.Statement;
7b1d78 4 using DIXWeb.Entity.Workflow;
A 5 using DIXWeb.Web;
6 using Newtonsoft.Json;
7 using System;
8 using System.Collections.Generic;
6ac346 9 using System.Configuration;
7b1d78 10 using System.Drawing;
A 11 using System.IO;
12 using System.Linq;
13 using System.Web;
14 using System.Web.Mvc;
15 using ZXing;
16 using ZXing.QrCode;
17
18 namespace DIXWeb.Web
19 {
20     public class DownloadController : BaseMvcController
21     {
22         DownloadBusiness _dBusiness = new DownloadBusiness();
23         // GET: GlobalM/Download
24         public ActionResult Index()
25         {
26             return View();
27         }
28
970dd6 29
c8f614 30         public ActionResult TwoDCodeView()
970dd6 31         {
A 32             try
33             {
c8f614 34                 if (Util.SessionHelper.Session["InspectObjectJson"] == null)
A 35                 {
36                     ViewData["Message"] = "";
37                 }
38                 else
39                 {
40                     ViewData["Message"] = Util.SessionHelper.Session["InspectObjectJson"].ToString();
41                 }
42                 ViewData["Code"] = 200;
43                 Util.SessionHelper.Session["InspectObjectJson"] = null;
44             }
45             catch (Exception ex)
46             {
47                 ViewData["Code"] = 500;
48                 ViewData["Message"] = ex.Message;
49             }
50             return View();
51         }
970dd6 52
c8f614 53
A 54         public ActionResult UploadInspectObjectTwoD(string[] InspectObjectIdArr)
55         {
56             Receive receive = new Receive();
57             try
58             {
59                 List<TwoDCode> list = new List<TwoDCode>();
6ac346 60                 string dir = Server.MapPath("~/Images/InspectObject/");
A 61                 if (!Directory.Exists(dir)) Directory.CreateDirectory(dir);
62                 int InspectObjectId = 0;
63                 for (int i = 0; i < InspectObjectIdArr.Length; i++)
970dd6 64                 {
6ac346 65                     InspectObjectId = int.Parse(InspectObjectIdArr[i]);
A 66                     string InspectObjectCode = _dBusiness.GetInspectObjectById(InspectObjectId).InspectObjectCode;
67                     string fullName = dir + InspectObjectCode + ".jpg";
68                     if (System.IO.File.Exists(fullName))
69                     {
70                         System.IO.File.Delete(fullName);
71                     }
72                     KeepJpg(fullName, InspectObjectCode);
73
74                     list.Add(new TwoDCode()
75                     {
76                         Code = InspectObjectCode,
77                         Url = "/Images/InspectObject/" + InspectObjectCode + ".jpg"
78                     });
970dd6 79                 }
c8f614 80                 Util.SessionHelper.Session["InspectObjectJson"] = Newtonsoft.Json.JsonConvert.SerializeObject(list);
A 81                 receive.Code = 200;
82                 receive.Message = "SUCCESS";
970dd6 83             }
A 84             catch (Exception ex)
85             {
c8f614 86                 receive.Code = 500;
A 87                 receive.Message = ex.Message;
970dd6 88             }
c8f614 89             return Json(receive);
970dd6 90         }
A 91
7b1d78 92         public ActionResult Get2DCode(int InspectObjectId)
A 93         {
94             Receive receive = new Receive();
95             try
96             {
97                 ReceiveTwoDCode record = _dBusiness.GetInspectObjectById(InspectObjectId);
98                 string InspectObjectStr = JsonConvert.SerializeObject(record);
99                 string dir = Server.MapPath("~/Images/InspectObject/");
29abd3 100                 string fileName = record.InspectObjectCode + ".jpg";
7b1d78 101                 receive.Message = "/Images/InspectObject/" + fileName;
6ac346 102                 receive.rows = record.InspectObjectCode;
7b1d78 103                 if (!Directory.Exists(dir)) Directory.CreateDirectory(dir);
A 104
105                 if (!System.IO.File.Exists(dir+fileName))
106                 {
9cbcff 107                     KeepJpg(dir + fileName, record.InspectObjectCode);
7b1d78 108                 }
A 109                 receive.Code = 200;
110             }
111             catch (Exception ex)
112             {
113                 receive.Code = 500;
114                 receive.Message = ex.Message;
115             }
116             return Json(receive);
117         }
118
119         private string KeepJpg(string fullName,string content) {
6ac346 120             int size = int.Parse(ConfigurationManager.AppSettings["TwoDCodeSize"].ToString());
A 121             int width = size;
122             int height = size;
7b1d78 123             BarcodeWriter bw = new BarcodeWriter();
A 124             bw.Format = BarcodeFormat.QR_CODE;
125             QrCodeEncodingOptions options = new QrCodeEncodingOptions();
126             options.DisableECI = true;
127             options.CharacterSet = "UTF-8";
128             options.Width = width;
129             options.Height = height;
130             options.Margin = 1;
131             bw.Options = options;
132             Bitmap bm = bw.Write(content);
133             bm.Save(fullName);
134             return fullName;
135         }
6ac346 136
A 137         public ActionResult InspectObjectTemplate() {
138             string dir = Server.MapPath("~/Template/");
139             if (!System.IO.Directory.Exists(dir)) System.IO.Directory.CreateDirectory(dir);
140             string fileName = "InspectObjectTemplate.xls";
141             string fullName = dir + fileName;
142             if (System.IO.File.Exists(fullName)) System.IO.File.Delete(fullName);
1bf8ef 143             //ExcelHelper.CreateExcel(fullName, "Sheet1");
A 144             new ExcelHelper().Create(fullName, "Sheet1", false);
6ac346 145             return File(fullName, "application/ms-excel", fileName);
A 146         }
147
7d6280 148         public ActionResult ImgSNView(string ImgSN,string FilterType)
16ff9a 149         {
A 150             ViewData["ImgSN"] = ImgSN;
7d6280 151             ViewData["FilterType"] = FilterType;
16ff9a 152             return View();
A 153         }
6ac346 154
7d6280 155         public ActionResult GetImgBySN(string ImgSN, string FilterType)
16ff9a 156         {
7d6280 157             Receive receive = _dBusiness.GetImgBySN(ImgSN, FilterType);
238f73 158             string jsonStr = Newtonsoft.Json.JsonConvert.SerializeObject(receive);
A 159             return Content(jsonStr);
16ff9a 160         }
7b1d78 161     }
A 162 }