using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Threading.Tasks; using System.Web.Http; using WebAPI.App_Start; using WebAPI.Models; using Newtonsoft.Json.Converters; namespace WebAPI.Controllers { /// /// 泡沫、注塑点检 /// [RoutePrefix("api/MachineClass")] public class MachineClassController : ApiController { /// /// 获取点检项 /// /// /// [HttpGet] public Response> Get(string MachineCode) { var result = new Response>(); var sqlScript = $"select a.*,(select top 1 MValue from T_MD_PutMachineValue where MachineCode = a.PID ORDER BY CreateData ) as 'MValue',(select top 1 PValue from T_MD_PutMachineValue where MachineCode = a.PID ORDER BY CreateData ) as 'PValue' from T_MD_PutMachineClass as a where a.MachineCode = '{MachineCode}' ORDER BY a.SerialNumber "; DataSet dataSet = SqlHelper.ExecuteDataset(Config.maindbConnectionString, CommandType.Text, sqlScript); var sqlValue = $"select * from T_MD_PutMachine where MachineCode ='{MachineCode}' "; DataSet dataSetValue = SqlHelper.ExecuteDataset(Config.maindbConnectionString, CommandType.Text, sqlValue); var list_PutMachine = new List(); foreach (DataRow R in dataSetValue.Tables[0].Rows) { var t = new PutMachine(); t.PID = R["PID"].ToString(); t.MachineCode = R["MachineCode"].ToString(); t.MachinePID = R["MachinePID"].ToString(); t.Limit = R["Limit"].ToString(); t.Floor = R["Floor"].ToString(); t.Name = R["Name"].ToString(); t.SerialNumber = Convert.ToInt32(R["SerialNumber"].ToString()); list_PutMachine.Add(t); } var list_MachineClass = new List(); if (dataSet.Tables[0].Rows.Count > 0) { foreach (DataRow R in dataSet.Tables[0].Rows) { var t = new MachineClass(); t.PID = R["PID"].ToString(); t.MachineCode = R["MachineCode"].ToString(); t.Name = R["Name"].ToString(); t.Position = R["Position"].ToString(); t.Content = R["Content"].ToString(); t.Methond = R["Methond"].ToString(); t.Type = R["Type"].ToString(); t.SerialNumber = R["SerialNumber"].ToString(); var m = list_PutMachine.Where(p => p.MachinePID == t.PID).OrderBy(o=>o.SerialNumber).ToList(); t.putMachine = m; switch (t.Type) { case "1": t.SelectName = R["MValue"].ToString(); if (!string.IsNullOrEmpty(t.SelectName)) { switch (t.SelectName) { case "状态良好": t.SelectValue = "1"; break; case "正在处理": t.SelectValue = "2"; break; case "状态不好或损毁": t.SelectValue = "3"; break; case "停机状态": t.SelectValue = "4"; break; } } else { t.SelectName = ""; t.SelectValue = ""; } break; case "2": t.SelectName = R["MValue"].ToString(); t.SelectValue = R["MValue"].ToString(); break; case "3": t.putMachine[0].SelectName = R["MValue"].ToString(); t.putMachine[1].SelectName = R["PValue"].ToString(); break; } list_MachineClass.Add(t); } result.Result = list_MachineClass; } else { result.Code = 201; result.Message = "设备信息不存在"; } return result; } /// /// 点检录入 /// /// public async Task Insert() { var request = await this.Request.Content.ReadAsStringAsync(); var requeststr = request.Replace("\r", "").Replace("\n", ""); var resObj = JsonHelper.Instance.JsonToObj(requeststr); var group = "";//班次 switch (resObj.groupValue) { case "1": group = "三班"; break; case "2": group = "白班"; break; case "3": group = "二班"; break; } var item = resObj.dataList[resObj.dataList.Count - 1]; for (var i = 0; i < resObj.dataList.Count-1; i++) { var t = new MachineValue(); t.UserName = resObj.id; t.MachineCode = resObj.dataList[i].PID; t.Name = resObj.dataList[i].Content; t.Type = resObj.dataList[i].Type; t.Group = group; t.UserName = resObj.id; if (resObj.dataList[i].Type == "3") { if (resObj.dataList[i].SelectValue == "4") { t.MValue = "停机状态"; t.PValue = "停机状态"; } else { t.MValue = resObj.dataList[i].putMachine[0].SelectName; t.PValue = resObj.dataList[i].putMachine[1].SelectName; } } else { if (resObj.dataList[i].Type == "1") { switch (resObj.dataList[i].SelectValue) { case "1": t.MValue = "状态良好"; break; case "2": t.MValue = "正在处理"; break; case "3": t.MValue = "状态不好或损毁"; break; case "4": t.MValue = "停机状态"; break; } } else { if (resObj.dataList[i].SelectValue == "4") t.MValue = "停机状态"; else t.MValue = resObj.dataList[i].SelectValue; } } SqlData.InsertMachine(t); } var Response = new Response(); return Ok(Response); } /// /// 获取注塑点检项 /// /// /// /// [HttpGet] [Route("GZhuSuItem")] public Response> GZhuSuItem( string Machine, string ProductCode) { var result = new Response>(); var sqlScript = $"select a.* from T_MD_PutMachineClass as a where a.MachineCode = '{Machine}' ORDER BY a.SerialNumber "; DataSet dataSet = SqlHelper.ExecuteDataset(Config.maindbConnectionString, CommandType.Text, sqlScript); var sqlValue = $"select * from T_MD_PutMachine where MachineCode ='{Machine}' "; DataSet dataSetValue = SqlHelper.ExecuteDataset(Config.maindbConnectionString, CommandType.Text, sqlValue); var sql_selectProduct = $"select * from monitordata where QrCodeContent = '{ProductCode}'"; //HoldEndPos DataSet sql_selectSetValue = SqlHelper.ExecuteDataset(Config.maindbConnectionString, CommandType.Text, sql_selectProduct); var list_PutMachine = new List(); foreach (DataRow R in dataSetValue.Tables[0].Rows) { var t = new PutMachine(); t.PID = R["PID"].ToString(); t.MachineCode = R["MachineCode"].ToString(); t.MachinePID = R["MachinePID"].ToString(); t.Limit = R["Limit"].ToString(); t.Floor = R["Floor"].ToString(); t.Name = R["Name"].ToString(); t.SerialNumber = Convert.ToInt32(R["SerialNumber"].ToString()); list_PutMachine.Add(t); } var list_MachineClass = new List(); if (dataSet.Tables[0].Rows.Count > 0) { if (sql_selectSetValue.Tables[0].Rows.Count > 0) { foreach (DataRow R in dataSet.Tables[0].Rows) { var t = new MachineClass(); t.PID = R["PID"].ToString(); t.MachineCode = R["MachineCode"].ToString(); t.Name = R["Name"].ToString(); t.Position = R["Position"].ToString(); t.Content = R["Content"].ToString(); t.Methond = R["Methond"].ToString(); t.Type = R["Type"].ToString(); t.SerialNumber = R["SerialNumber"].ToString(); var m = list_PutMachine.Where(p => p.MachinePID == t.PID).OrderBy(o => o.SerialNumber).ToList(); t.putMachine = m; if (sql_selectSetValue.Tables[0].Rows.Count > 0) { if (R["SerialNumber"].ToString() == "1") { //注塑开始位置 t.SelectName = sql_selectSetValue.Tables[0].Rows[0]["InjectStartPos"].ToString(); t.SelectValue = sql_selectSetValue.Tables[0].Rows[0]["InjectStartPos"].ToString(); } else if (R["SerialNumber"].ToString() == "2") { //保压结束位置 t.SelectName = sql_selectSetValue.Tables[0].Rows[0]["HoldEndPos"].ToString(); t.SelectValue = sql_selectSetValue.Tables[0].Rows[0]["HoldEndPos"].ToString(); } else if (R["SerialNumber"].ToString() == "3") { //储料完成位置 t.SelectName = sql_selectSetValue.Tables[0].Rows[0]["ChargeEndPos"].ToString(); t.SelectValue = sql_selectSetValue.Tables[0].Rows[0]["ChargeEndPos"].ToString(); } } else { t.SelectName = "0"; t.SelectValue = "0"; } list_MachineClass.Add(t); } result.Result = list_MachineClass; } else { result.Code = 202; result.Message = "产品信息不存在"; } } else { } return result; } } }