1
duan
2024-08-21 f71a02229c1ba00fbecaead19256593ffb052753
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
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<TwoDCode> list = new List<TwoDCode>();
                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);
        }
    }
}