华恒Mes鼎捷代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

380 lines
14 KiB

5 months ago
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Net;
  5. using System.Net.Http;
  6. using System.Web.Http;
  7. using ICSSoft.Frame.Data.BLL;
  8. using ICSSoft.Frame.Data.Entity;
  9. using Newtonsoft.Json;
  10. using System.Text;
  11. using ICSSoft.Base.Config.AppConfig;
  12. using ICSSoft.Entity;
  13. using ICSSoft.Entity.mom_order;
  14. using ICSSoft.Frame.Data.DAL;
  15. using WebApplication1.Models;
  16. using WebApplication1.Attributes;
  17. namespace WebApplication1.Controllers
  18. {
  19. public class ValuesController : ApiController
  20. {
  21. private static log4net.ILog log = log4net.LogManager.GetLogger("单据");
  22. public static string conn = System.Configuration.ConfigurationManager.ConnectionStrings["SysConnectionString"].ToString();
  23. public static string connGT = System.Configuration.ConfigurationManager.ConnectionStrings["SysConnectionStringGT"].ToString();
  24. [Route("api/UpdateLotnoStatus")]
  25. [HttpPost]
  26. public HttpResponseMessage UpdateLotnoStatus(string lotno,string muser,string type,decimal transqty) {
  27. HttpResponseMessage repose = new HttpResponseMessage();
  28. string str = "";
  29. Result res = new Result();
  30. try {
  31. string connection = "";
  32. if (type == "888")
  33. connection = conn;
  34. else if (type == "808")
  35. connection = connGT;
  36. if (string.IsNullOrEmpty(connection))
  37. {
  38. throw new Exception("请传入正确的type参数!");
  39. }
  40. DateTime mtime = DateTime.Now;
  41. ICSITEMLOTBLL.UpdateLotnoStatus(lotno,muser,mtime,transqty,connection);
  42. res.code = "200";
  43. res.msg = "更改条码:" + lotno + "入库状态成功!";
  44. str = JsonConvert.SerializeObject(res);
  45. repose.Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json");
  46. return repose;
  47. }
  48. catch (Exception ex) {
  49. res.code = "400";
  50. res.msg = ex.Message+" 更改条码:"+lotno+"入库状态失败!";
  51. str = JsonConvert.SerializeObject(res);
  52. repose.Content = new StringContent(str, Encoding.GetEncoding("UTF-8"),"application/json");
  53. return repose;
  54. }
  55. }
  56. [Route("api/GetMesinfo")]
  57. [HttpPost]
  58. public HttpResponseMessage GetMesinfo(string lotno,string type)
  59. {
  60. HttpResponseMessage repose = new HttpResponseMessage();
  61. string str = "";
  62. Result res = new Result();
  63. try
  64. {
  65. var mes = new { Lotno = "", LOTQTY = "", MDeptCode = "", MODID = "", MOID = "", ITEMCODE = "", INVNAME = "", INVSTD = "", cDepCode = "", cDepName = "", INVUOM = "", CompanyCode = "",Mocode="" };
  66. string connection = "";
  67. if (type == "888")
  68. connection = conn;
  69. else if (type == "808")
  70. connection = connGT;
  71. if (string.IsNullOrEmpty(connection)) {
  72. throw new Exception("请传入正确的type参数!");
  73. }
  74. ICSITEMLOTBLL.GetLotnoMes(lotno, connection, mes);
  75. string json = JsonConvert.SerializeObject(mes);
  76. res.code = "200";
  77. res.msg = "获取信息成功";
  78. res.data = json;
  79. str = JsonConvert.SerializeObject(res);
  80. repose.Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json");
  81. return repose;
  82. }
  83. catch (Exception ex)
  84. {
  85. res.code = "400";
  86. res.msg = ex.Message + " 获取条码:" + lotno + "信息失败!";
  87. str = JsonConvert.SerializeObject(res);
  88. repose.Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json");
  89. return repose;
  90. }
  91. }
  92. [Route("api/GetMesinfo2")]
  93. [HttpPost]
  94. public HttpResponseMessage GetMesinfo2(string lotno, string type)
  95. {
  96. HttpResponseMessage repose = new HttpResponseMessage();
  97. string str = "";
  98. Result res = new Result();
  99. try
  100. {
  101. string connection = "";
  102. if (type == "888")
  103. connection = conn;
  104. else if (type == "808")
  105. connection = connGT;
  106. if (string.IsNullOrEmpty(connection))
  107. {
  108. throw new Exception("请传入正确的type参数!");
  109. }
  110. LOTMES mes = new LOTMES();
  111. ICSITEMLOTBLL.GetLotnoMes2(lotno, connection, mes);
  112. string json = JsonConvert.SerializeObject(mes);
  113. res.code = "200";
  114. res.msg = "获取信息成功";
  115. res.data = json;
  116. str = JsonConvert.SerializeObject(res);
  117. repose.Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json");
  118. return repose;
  119. }
  120. catch (Exception ex)
  121. {
  122. res.code = "400";
  123. res.msg = ex.Message + " 获取条码:" + lotno + "信息失败!";
  124. str = JsonConvert.SerializeObject(res);
  125. repose.Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json");
  126. return repose;
  127. }
  128. }
  129. [Route("api/UpdateOAMes")]
  130. [HttpPost]
  131. public HttpResponseMessage UpdateOAMes([FromBody]ICSOAMES mes) {
  132. HttpResponseMessage repose = new HttpResponseMessage();
  133. string str = "";
  134. Result res = new Result();
  135. try
  136. {
  137. if (mes == null)
  138. throw new Exception("请传入正确的参数!");
  139. string connection = "";
  140. if (mes.type == "888")
  141. connection = conn;
  142. else if (mes.type == "808")
  143. connection = connGT;
  144. if (string.IsNullOrEmpty(connection))
  145. {
  146. throw new Exception("请传入正确的type参数!");
  147. }
  148. ICSITEMLOTBLL.UpdateOAMes(mes, connection);
  149. res.code = "200";
  150. res.msg = "更新ncr单号:" + mes.NCRCODE + "信息成功!";
  151. str = JsonConvert.SerializeObject(res);
  152. repose.Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json");
  153. return repose;
  154. }
  155. catch (Exception ex)
  156. {
  157. res.code = "400";
  158. res.msg = ex.Message + " 更新ncr单号:" + mes.NCRCODE + "信息失败!";
  159. str = JsonConvert.SerializeObject(res);
  160. repose.Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json");
  161. return repose;
  162. }
  163. }
  164. [Route("api/mo/create")]
  165. [HttpPost]
  166. //[ApiAuthorize]
  167. public HttpResponseMessage MoCreate([FromBody]MoInsertModel Model)
  168. {
  169. HttpResponseMessage repose = new HttpResponseMessage();
  170. string str = "";
  171. Result res = new Result();
  172. try
  173. {
  174. //if (Model == null)
  175. // throw new Exception("请传入正确的参数!");
  176. ParamsValidateHelper.CheckNull<MoInsertModel, MoInsertData>(Model);//参数非空验证
  177. string connection = "";
  178. if (Model.Type == "HH")
  179. connection = conn;
  180. else if (Model.Type == "HG")
  181. connection = connGT;
  182. if (string.IsNullOrEmpty(connection))
  183. {
  184. throw new Exception("请传入正确的Type参数!");
  185. }
  186. if (Model.datas.Count <= 0)
  187. throw new Exception("NullOrEmptyParam:datas");
  188. ICSMOBLL.Add(Model.datas, connection);
  189. res.code = "200";
  190. res.msg = "新增成功!";
  191. str = JsonConvert.SerializeObject(res);
  192. repose.Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json");
  193. return repose;
  194. }
  195. catch (Exception ex)
  196. {
  197. res.code = "400";
  198. res.msg = ex.Message + " 新增失败!";
  199. str = JsonConvert.SerializeObject(res);
  200. repose.Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json");
  201. return repose;
  202. }
  203. }
  204. [Route("api/mo/modifity")]
  205. [HttpPost]
  206. //[ApiAuthorize]
  207. public HttpResponseMessage MoModifity([FromBody]MoModifityModel Model)
  208. {
  209. HttpResponseMessage repose = new HttpResponseMessage();
  210. string str = "";
  211. Result res = new Result();
  212. try
  213. {
  214. //if (Model == null)
  215. // throw new Exception("请传入正确的参数!");
  216. ParamsValidateHelper.CheckNull<MoModifityModel, MoModifityData>(Model);//参数非空验证
  217. string connection = "";
  218. if (Model.Type == "HH")
  219. connection = conn;
  220. else if (Model.Type == "HG")
  221. connection = connGT;
  222. if (string.IsNullOrEmpty(connection))
  223. {
  224. throw new Exception("请传入正确的Type参数!");
  225. }
  226. if (Model.datas.Count <= 0)
  227. throw new Exception("NullOrEmptyParam:datas");
  228. ICSMOBLL.Update(Model.datas, connection);
  229. res.code = "200";
  230. res.msg = "更新成功!";
  231. str = JsonConvert.SerializeObject(res);
  232. repose.Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json");
  233. return repose;
  234. }
  235. catch (Exception ex)
  236. {
  237. res.code = "400";
  238. res.msg = ex.Message + " 更新失败!";
  239. str = JsonConvert.SerializeObject(res);
  240. repose.Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json");
  241. return repose;
  242. }
  243. }
  244. [Route("api/mo/delete")]
  245. [HttpPost]
  246. //[ApiAuthorize]
  247. public HttpResponseMessage MoDelete([FromBody]MoModifityModel Model)
  248. {
  249. HttpResponseMessage repose = new HttpResponseMessage();
  250. string str = "";
  251. Result res = new Result();
  252. try
  253. {
  254. //if (Model == null)
  255. // throw new Exception("请传入正确的参数!");
  256. ParamsValidateHelper.CheckNull<MoModifityModel, MoModifityData>(Model);//参数非空验证
  257. string connection = "";
  258. if (Model.Type == "HH")
  259. connection = conn;
  260. else if (Model.Type == "HG")
  261. connection = connGT;
  262. if (string.IsNullOrEmpty(connection))
  263. {
  264. throw new Exception("请传入正确的Type参数!");
  265. }
  266. if (Model.datas.Count <= 0)
  267. throw new Exception("NullOrEmptyParam:datas");
  268. var list = Model.datas.Select(a => new Tuple<string, string>(a.Mocode, a.MOSEQ.ToString())).ToList();
  269. ICSMOBLL.delete(list, connection);
  270. res.code = "200";
  271. res.msg = "删除成功!";
  272. str = JsonConvert.SerializeObject(res);
  273. repose.Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json");
  274. return repose;
  275. }
  276. catch (Exception ex)
  277. {
  278. res.code = "400";
  279. res.msg = ex.Message + " 删除失败!";
  280. str = JsonConvert.SerializeObject(res);
  281. repose.Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json");
  282. return repose;
  283. }
  284. }
  285. [HttpGet]
  286. [Route("api/login")]
  287. public HttpResponseMessage Login(string Username, string Password, string Type)
  288. {
  289. HttpResponseMessage repose = new HttpResponseMessage();
  290. string str = "";
  291. Result res = new Result();
  292. try
  293. {
  294. if (string.IsNullOrEmpty(Username))
  295. throw new Exception("NullOrEmptyParam:Username");
  296. if (string.IsNullOrEmpty(Password))
  297. throw new Exception("NullOrEmptyParam:Password");
  298. if (string.IsNullOrEmpty(Type))
  299. throw new Exception("NullOrEmptyParam:Type");
  300. string connection = "";
  301. if (Type == "HH")
  302. connection = conn;
  303. else if (Type == "HG")
  304. connection = connGT;
  305. if (string.IsNullOrEmpty(connection))
  306. {
  307. throw new Exception("请传入正确的WorkPoint参数!");
  308. }
  309. var user = ICSMOBLL.Login(Username, Password, connection);
  310. var tocken = JwtHelper.CreateTocken(user.UserName);
  311. res.code = "200";
  312. res.msg = "登入成功!";
  313. res.data = tocken;
  314. str = JsonConvert.SerializeObject(res);
  315. repose.Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json");
  316. return repose;
  317. }
  318. catch (Exception ex)
  319. {
  320. res.code = "400";
  321. res.msg = ex.Message;
  322. str = JsonConvert.SerializeObject(res);
  323. repose.Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json");
  324. return repose;
  325. }
  326. }
  327. }
  328. }