songjun
2024-09-04 cc908053e0b5075fbfd27350b6da4b39bca9e550
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using PalGain.Core;
using BatchService.Framework.Utility;
using sbcLabSystem.Service.Account;
using sbcLabSystem.Framework;
using sbcLabSystem.Models;
using sbcLabSystem.Data.Domain.Account;
using sbcLabSystem.Models.Home;
using sbcLabSystem.Data.Domain.Backstage;
using sbcLabSystem.Service;
using sbcLabSystem.Service.QC;
using sbcLabSystem.Models.Backstage;
using sbcLabSystem.App_Start.Attribute;
using Newtonsoft.Json;
 
namespace sbcLabSystem.Controllers
{
    public class HomeController : Controller
    {
        //
        // GET: /Home/
 
        private AccountService m_AccountService;
        private QCService _qcService;
 
        public HomeController(AccountService l_AccountService,
            QCService i_qcService)
        {
            _qcService = i_qcService;
            this.m_AccountService = l_AccountService;
        }
 
        public ActionResult Index()
        {
 
            HomePageViewModel viewModel = new HomePageViewModel();
            viewModel.RequestInfo = new UserRequestInfo();
            return View(viewModel);
        }
        public ActionResult GetValidateCode()
        {
            VerifyCode vCode = new VerifyCode();
            string code = vCode.CreateValidateCode(4);
            Session["ValidateCode"] = code;
            byte[] bytes = vCode.CreateValidateGraphic(code);
            return File(bytes, @"image/jpeg");
        }
 
        public ActionResult submitRequest(HomePageViewModel viewModel, string verityCode)
        {
            if (m_AccountService.GetUserRequestInfoQueryable().FirstOrDefault(p => p.OperatorEmail == viewModel.RequestInfo.OperatorEmail ||
            p.ManagerEmail == viewModel.RequestInfo.ManagerEmail) != null)
            {
                return Json("duplicate");
            }
            if (viewModel.RequestInfo != null)
            {
                if (Session["ValidateCode"].ToString() != verityCode)
                {
                    return Json("verifycodeerror");
                }
                viewModel.RequestInfo.RequestTime = DateTime.Now;
                viewModel.RequestInfo.UpdateTime = DateTime.Now;
                m_AccountService.InsertUserRequestInfo(viewModel.RequestInfo);
                _qcService.SendMail(viewModel.RequestInfo.Id, 11);
            }
            else
            {
                return Json("error");
            }
            return Json("ok");
        }
 
        public ActionResult introduce()
        {
            MenuinfoViewModel viewModel = new MenuinfoViewModel();
            viewModel.Menuinfo = m_AccountService.MenusId(1);
            return View(viewModel);
        }
        public ActionResult process()
        {
            MenuinfoViewModel viewModel = new MenuinfoViewModel();
            viewModel.Menuinfo = m_AccountService.MenusId(2);
            return View(viewModel);
        }
        public ActionResult ChargeStandard()
        {
            MenuinfoViewModel viewModel = new MenuinfoViewModel();
            viewModel.ChargeData = new List<ChargedDetile>();
            viewModel.Menuinfo = m_AccountService.MenusId(3);
            string userId = Cookie.GetValue("login_user").ToString();
            var list = _qcService.GetQcDistributionRegisters().Where(p => p.LabId.ToString() == userId).ToList();
            if (list != null && list.Count > 0)
            {
                list.ForEach(info =>
                {
                    ChargedDetile data = new ChargedDetile();
                    data.isCharged = info.IsCharged;
                    data.ChargedRemark = info.ChargeRemark;
                    data.ChargedTime = info.ChargeTime.GetValueOrDefault().ToString("yyyy-MM-dd HH:mm:ss");
                    data.QCDistributionDistNo = info.QCDistributionInfo.DistNo;
                    viewModel.ChargeData.Add(data);
                });
            }
            return View(viewModel);
        }
        public ActionResult Login()
        {
 
            UserRequestInfoModel viewModel = new UserRequestInfoModel()
            {
                LabCode = "",
                LabLoginName = "",
                LabPassword = ""
            };
            return View(viewModel);
        }
        public ActionResult SeveUpdatePwd(UserRequestInfoModel info)
        {
            try
            {
                UserRequestInfo User = m_AccountService.GetUserRequestInfoQueryable()
                       .FirstOrDefault(p => p.LabCode.ToLower() == info.LabCode.ToLower() && p.ManagerEmail == info.ManagerEmail);
                if (User != null)
                {
                    _qcService.SendMail(User.Id, 17);
                    return Json("ok");
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex.ToString());
            }
            return Json("no");
        }
 
        public ActionResult unionPassword()
        {
            try
            {
                var userList = m_AccountService.GetUserRequestInfoQueryable().ToList();
                userList.ForEach(x =>
                {
                    if (string.IsNullOrEmpty(x.LabPassword))
                    {
                        return;
                    } 
                    var md5 = MD5Helper.MD5Encrypt3(x.LabPassword);
                    x.LabPassword = md5;
                    LogHelper.Info(md5);
                    m_AccountService.UpdateUserRequestInfo(x);
                });
            }
            catch(Exception ex)
            {
                LogHelper.Error(ex.ToString());
            }
            return Json("ok"); 
        }
 
 
        public ActionResult SeveLogin(UserRequestInfoModel info)
        {
            try
            {
                if (info.LabLoginName != Session["ValidateCode"].ToString())
                {
                    return Json("yzm");
                }
                //if (!string.IsNullOrEmpty(Cookie.GetValue("userLogin_num")) && int.Parse(Cookie.GetValue("userLogin_num")) > 3)
                //{
                //    return Json("3");
                //}
                //if (string.IsNullOrEmpty(Cookie.GetValue("userLogin_num")) || Cookie.GetValue("userLogin_num") == "")
                //{
                //    Cookie.Save("userLogin_num", "1", 1);
                //}  
                //else
                //{
                //    string number = (int.Parse(Cookie.GetValue("userLogin_num")) + 1).ToString();
                //    Cookie.Save("userLogin_num", number, 1);
                //}
                if (info != null)
                {
                    UserRequestInfo User = null;
                    try
                    { 
                        string md5_password = MD5Helper.MD5Encrypt3(info.LabPassword);
                        User = m_AccountService.GetUserRequestInfoQueryable()
                            .FirstOrDefault(p => p.LabCode.ToLower() == info.LabCode.ToLower()
                                && (p.LabPassword == info.LabPassword)
                                || p.LabPassword == md5_password);
                    }
                    catch (Exception ex)
                    {
                        LogHelper.Error(ex.ToString());
                    }
                    if (User != null)
                    {
                        Cookie.Save("login_user", User.Id.ToString(), 120);
                        Cookie.isValidUser(User.Id.ToString(), true);
                        LogHelper.Debug(User.LabCode + "用户请求登录成功");
                        Cookie.Save("userLogin_num", "1", 1);
                        return Json("ok");
                    }
                }
                else
                {
                    LogHelper.Info("未查到用户信息:" + JsonConvert.SerializeObject(info));
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex.ToString());
            }
            LogHelper.Debug(info.LabCode + "用户请求登录失败");
            return Json("no");
        }
        public ActionResult Contact()
        {
            EmeilInfoModel viewModel = new EmeilInfoModel();
            return View(viewModel);
        }
        public ActionResult SeveContact(EmeilInfoModel info)
        {
            info.SendOutDatetime = DateTime.Now;
            EmileInfo entity = EmeilInfoModel.FormEntity(info);
            entity.EmileName = "eqas@sbc.org.cn ";
            m_AccountService.InserEmilinfo(entity);
            return Json("ok");
        }
 
    }
}