using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.Http; using System.Web.Http; using ICSSoft.Frame.Data.BLL; using ICSSoft.Frame.Data.Entity; using Newtonsoft.Json; using System.Text; using ICSSoft.Base.Config.AppConfig; using ICSSoft.Entity; using ICSSoft.Entity.mom_order; using ICSSoft.Frame.Data.DAL; using WebApplication1.Models; using WebApplication1.Attributes; namespace WebApplication1.Controllers { public class ValuesController : ApiController { private static log4net.ILog log = log4net.LogManager.GetLogger("单据"); public static string conn = System.Configuration.ConfigurationManager.ConnectionStrings["SysConnectionString"].ToString(); public static string connGT = System.Configuration.ConfigurationManager.ConnectionStrings["SysConnectionStringGT"].ToString(); [Route("api/UpdateLotnoStatus")] [HttpPost] public HttpResponseMessage UpdateLotnoStatus(string lotno,string muser,string type,decimal transqty) { HttpResponseMessage repose = new HttpResponseMessage(); string str = ""; Result res = new Result(); try { string connection = ""; if (type == "888") connection = conn; else if (type == "808") connection = connGT; if (string.IsNullOrEmpty(connection)) { throw new Exception("请传入正确的type参数!"); } DateTime mtime = DateTime.Now; ICSITEMLOTBLL.UpdateLotnoStatus(lotno,muser,mtime,transqty,connection); res.code = "200"; res.msg = "更改条码:" + lotno + "入库状态成功!"; str = JsonConvert.SerializeObject(res); repose.Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json"); return repose; } catch (Exception ex) { res.code = "400"; res.msg = ex.Message+" 更改条码:"+lotno+"入库状态失败!"; str = JsonConvert.SerializeObject(res); repose.Content = new StringContent(str, Encoding.GetEncoding("UTF-8"),"application/json"); return repose; } } [Route("api/GetMesinfo")] [HttpPost] public HttpResponseMessage GetMesinfo(string lotno,string type) { HttpResponseMessage repose = new HttpResponseMessage(); string str = ""; Result res = new Result(); try { var mes = new { Lotno = "", LOTQTY = "", MDeptCode = "", MODID = "", MOID = "", ITEMCODE = "", INVNAME = "", INVSTD = "", cDepCode = "", cDepName = "", INVUOM = "", CompanyCode = "",Mocode="" }; string connection = ""; if (type == "888") connection = conn; else if (type == "808") connection = connGT; if (string.IsNullOrEmpty(connection)) { throw new Exception("请传入正确的type参数!"); } ICSITEMLOTBLL.GetLotnoMes(lotno, connection, mes); string json = JsonConvert.SerializeObject(mes); res.code = "200"; res.msg = "获取信息成功"; res.data = json; str = JsonConvert.SerializeObject(res); repose.Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json"); return repose; } catch (Exception ex) { res.code = "400"; res.msg = ex.Message + " 获取条码:" + lotno + "信息失败!"; str = JsonConvert.SerializeObject(res); repose.Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json"); return repose; } } [Route("api/GetMesinfo2")] [HttpPost] public HttpResponseMessage GetMesinfo2(string lotno, string type) { HttpResponseMessage repose = new HttpResponseMessage(); string str = ""; Result res = new Result(); try { string connection = ""; if (type == "888") connection = conn; else if (type == "808") connection = connGT; if (string.IsNullOrEmpty(connection)) { throw new Exception("请传入正确的type参数!"); } LOTMES mes = new LOTMES(); ICSITEMLOTBLL.GetLotnoMes2(lotno, connection, mes); string json = JsonConvert.SerializeObject(mes); res.code = "200"; res.msg = "获取信息成功"; res.data = json; str = JsonConvert.SerializeObject(res); repose.Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json"); return repose; } catch (Exception ex) { res.code = "400"; res.msg = ex.Message + " 获取条码:" + lotno + "信息失败!"; str = JsonConvert.SerializeObject(res); repose.Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json"); return repose; } } [Route("api/UpdateOAMes")] [HttpPost] public HttpResponseMessage UpdateOAMes([FromBody]ICSOAMES mes) { HttpResponseMessage repose = new HttpResponseMessage(); string str = ""; Result res = new Result(); try { if (mes == null) throw new Exception("请传入正确的参数!"); string connection = ""; if (mes.type == "888") connection = conn; else if (mes.type == "808") connection = connGT; if (string.IsNullOrEmpty(connection)) { throw new Exception("请传入正确的type参数!"); } ICSITEMLOTBLL.UpdateOAMes(mes, connection); res.code = "200"; res.msg = "更新ncr单号:" + mes.NCRCODE + "信息成功!"; str = JsonConvert.SerializeObject(res); repose.Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json"); return repose; } catch (Exception ex) { res.code = "400"; res.msg = ex.Message + " 更新ncr单号:" + mes.NCRCODE + "信息失败!"; str = JsonConvert.SerializeObject(res); repose.Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json"); return repose; } } [Route("api/mo/create")] [HttpPost] //[ApiAuthorize] public HttpResponseMessage MoCreate([FromBody]MoInsertModel Model) { HttpResponseMessage repose = new HttpResponseMessage(); string str = ""; Result res = new Result(); try { //if (Model == null) // throw new Exception("请传入正确的参数!"); ParamsValidateHelper.CheckNull(Model);//参数非空验证 string connection = ""; if (Model.Type == "HH") connection = conn; else if (Model.Type == "HG") connection = connGT; if (string.IsNullOrEmpty(connection)) { throw new Exception("请传入正确的Type参数!"); } if (Model.datas.Count <= 0) throw new Exception("NullOrEmptyParam:datas"); ICSMOBLL.Add(Model.datas, connection); res.code = "200"; res.msg = "新增成功!"; str = JsonConvert.SerializeObject(res); repose.Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json"); return repose; } catch (Exception ex) { res.code = "400"; res.msg = ex.Message + " 新增失败!"; str = JsonConvert.SerializeObject(res); repose.Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json"); return repose; } } [Route("api/mo/modifity")] [HttpPost] //[ApiAuthorize] public HttpResponseMessage MoModifity([FromBody]MoModifityModel Model) { HttpResponseMessage repose = new HttpResponseMessage(); string str = ""; Result res = new Result(); try { //if (Model == null) // throw new Exception("请传入正确的参数!"); ParamsValidateHelper.CheckNull(Model);//参数非空验证 string connection = ""; if (Model.Type == "HH") connection = conn; else if (Model.Type == "HG") connection = connGT; if (string.IsNullOrEmpty(connection)) { throw new Exception("请传入正确的Type参数!"); } if (Model.datas.Count <= 0) throw new Exception("NullOrEmptyParam:datas"); ICSMOBLL.Update(Model.datas, connection); res.code = "200"; res.msg = "更新成功!"; str = JsonConvert.SerializeObject(res); repose.Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json"); return repose; } catch (Exception ex) { res.code = "400"; res.msg = ex.Message + " 更新失败!"; str = JsonConvert.SerializeObject(res); repose.Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json"); return repose; } } [Route("api/mo/delete")] [HttpPost] //[ApiAuthorize] public HttpResponseMessage MoDelete([FromBody]MoModifityModel Model) { HttpResponseMessage repose = new HttpResponseMessage(); string str = ""; Result res = new Result(); try { //if (Model == null) // throw new Exception("请传入正确的参数!"); ParamsValidateHelper.CheckNull(Model);//参数非空验证 string connection = ""; if (Model.Type == "HH") connection = conn; else if (Model.Type == "HG") connection = connGT; if (string.IsNullOrEmpty(connection)) { throw new Exception("请传入正确的Type参数!"); } if (Model.datas.Count <= 0) throw new Exception("NullOrEmptyParam:datas"); var list = Model.datas.Select(a => new Tuple(a.Mocode, a.MOSEQ.ToString())).ToList(); ICSMOBLL.delete(list, connection); res.code = "200"; res.msg = "删除成功!"; str = JsonConvert.SerializeObject(res); repose.Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json"); return repose; } catch (Exception ex) { res.code = "400"; res.msg = ex.Message + " 删除失败!"; str = JsonConvert.SerializeObject(res); repose.Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json"); return repose; } } [HttpGet] [Route("api/login")] public HttpResponseMessage Login(string Username, string Password, string Type) { HttpResponseMessage repose = new HttpResponseMessage(); string str = ""; Result res = new Result(); try { if (string.IsNullOrEmpty(Username)) throw new Exception("NullOrEmptyParam:Username"); if (string.IsNullOrEmpty(Password)) throw new Exception("NullOrEmptyParam:Password"); if (string.IsNullOrEmpty(Type)) throw new Exception("NullOrEmptyParam:Type"); string connection = ""; if (Type == "HH") connection = conn; else if (Type == "HG") connection = connGT; if (string.IsNullOrEmpty(connection)) { throw new Exception("请传入正确的WorkPoint参数!"); } var user = ICSMOBLL.Login(Username, Password, connection); var tocken = JwtHelper.CreateTocken(user.UserName); res.code = "200"; res.msg = "登入成功!"; res.data = tocken; str = JsonConvert.SerializeObject(res); repose.Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json"); return repose; } catch (Exception ex) { res.code = "400"; res.msg = ex.Message; str = JsonConvert.SerializeObject(res); repose.Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json"); return repose; } } } }