private void button1_Click(object sender, EventArgs e) { DataAcquisitionResult result = new DataAcquisitionResult(); List <DataAcquisitionEntity> dtos = new List <DataAcquisitionEntity>(); DataAcquisitionEntity dto = new DataAcquisitionEntity(); dto.DeviceName = "CNC1发那科"; dto.DeviceRunStatus = "运行中"; dto.DeviceUrl = ""; dto.DeviceLndicatorLight = "yellow"; dto.TodayOutput = 10; dto.TodayJiadong = 10; dto.SpindleSpeed = 10; dto.FeedSpeed = 10; dto.SpindleRatio = 10; dto.FeedRatio = 10; dto.LoadRatio = 10; dtos.Add(dto); dto = new DataAcquisitionEntity(); dto.DeviceName = "CNC2发那科"; dto.DeviceRunStatus = "宕机"; dto.DeviceUrl = ""; dto.DeviceLndicatorLight = "red"; dto.TodayOutput = 0; dto.TodayJiadong = 0; dto.SpindleSpeed = 0; dto.FeedSpeed = 0; dto.SpindleRatio = 0; dto.FeedRatio = 0; dto.LoadRatio = 0; dtos.Add(dto); string server = "http://localhost:15988/api/AutomationLine/SaveDataAcquisition"; DataAcquisitionAPIParameter param = new DataAcquisitionAPIParameter(); param.operator_name = "WebApi"; param.operator_time = GenerateTimeStamp(DateTime.Now); param.sign = GenSign(param.operator_name, param.operator_time); param.data = dtos; Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("operator_name", param.operator_name); dic.Add("operator_time", param.operator_time); dic.Add("sign", param.sign); dic.Add("strdata", Serialize(param.data)); try { HttpWebResponse response = CreatePostHttpResponse(server, dic, null, null, Encoding.UTF8, null); System.IO.StreamReader sr = new System.IO.StreamReader(response.GetResponseStream()); string responseContent = sr.ReadToEnd(); sr.Close(); DataAcquisitionResult rtn = Deserialize <DataAcquisitionResult>(responseContent); if (rtn.code != "1000") { return; } } catch (Exception ex) { return; } }
public DataAcquisitionResult SaveDataAcquisition([FromBody] DataAcquisitionAPIParameter param) { DataAcquisitionResult result = new DataAcquisitionResult(); result.code = "1000"; result.msg = "success"; if (param == null) { param = new DataAcquisitionAPIParameter(); this.Request.GetQueryNameValuePairs(); HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"]; //获取传统context HttpRequestBase request = context.Request; //定义传统request对象 param.operator_name = request.Form["operator_name"]; param.operator_time = request.Form["operator_time"]; param.sign = request.Form["sign"]; param.strdata = request.Form["strdata"]; LogHelper.Info("WebApi-SaveDataAcquisition param from forms"); } //else LogHelper.Info(string.Format("WebApi-SaveDataAcquisition param from body{0}", Serialize(param))); if (!VerifyMiddleSign(param.operator_name, param.operator_time, param.sign)) { LogHelper.Info(string.Format("operator_name{0},operation_time{1},sign{2}", param.operator_name, param.operator_time, param.sign)); result.msg = "签名错误"; result.code = "1040"; return(result); } List <DataAcquisitionEntity> dto = new List <DataAcquisitionEntity>(); try { string o1 = ""; string o2 = ""; string o3 = ""; string o4 = ""; string o5 = ""; string o6 = ""; string c1 = ""; string c2 = ""; string c3 = ""; string c4 = ""; string c5 = ""; string c6 = ""; dto = Deserialize <List <DataAcquisitionEntity> >(param.strdata); foreach (var item in dto) { bool fla = InsertDataAcquisition(item); if (!fla) { LogHelper.Error(string.Format("新增失败-SaveDataAcquisition:{0}", Serialize(item))); //result.msg = "数据插入失败"; //result.code = "1050"; //return result; } if (item.DeviceName == "CNC1发那科") { o1 = item.DeviceName + "<br>" + item.DeviceRunStatus; c1 = Colour(item.DeviceRunStatus); } else if (item.DeviceName == "CNC2发那科") { o2 = item.DeviceName + "<br>" + item.DeviceRunStatus; c2 = Colour(item.DeviceRunStatus); } else if (item.DeviceName == "CNC3发那科") { o3 = item.DeviceName + "<br>" + item.DeviceRunStatus; c3 = Colour(item.DeviceRunStatus); } else if (item.DeviceName == "Robot") { o4 = item.DeviceName + "<br>" + item.DeviceRunStatus; c4 = Colour(item.DeviceRunStatus); } else if (item.DeviceName == "清洗机") { o5 = item.DeviceName + "<br>" + item.DeviceRunStatus; c5 = Colour(item.DeviceRunStatus); } else if (item.DeviceName == "CMM2海克斯康") { o6 = item.DeviceName + "<br>" + item.DeviceRunStatus; c6 = Colour(item.DeviceRunStatus); } } #region Sys_RunningState 运行状态 if (!string.IsNullOrEmpty(o1)) { try { int re = 0; DbService ds = new DbService(dbnfin, "MySQL"); string str = string.Format(@"SELECT * from Sys_RunningState WHERE IsEffective=1;"); bool sult = ds.IsExistRecord(str); if (sult) { string str1 = string.Format(@"UPDATE Sys_RunningState SET Describe1='{0}',DescribeColor1='{1}',Describe2='{2}',DescribeColor2='{3}',Describe3='{4}',DescribeColor3='{5}', Describe4='{6}',DescribeColor4='{7}',Describe5='{8}',DescribeColor5='{9}',Describe6='{10}',DescribeColor6='{11}' Where IsEffective=1", o1, c1, o2, c2, o3, c3, o4, c4, o5, c5, o6, c6); int sult1 = ds.InsertSql(str1, out re); if (sult1 <= 0) { LogHelper.Error(string.Format("修改语句错误-Sys_RunningState:{0}", str1)); } } else { string str1 = string.Format(@"INSERT INTO Sys_RunningState(Picture_Url,Describe1,DescribeColor1,Describe2,DescribeColor2,Describe3,DescribeColor3,Describe4,DescribeColor4,Describe5,DescribeColor5,Describe6,DescribeColor6,CreationTime) VALUES( '{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}',NOW())", "/Content/img/product/runningstate/01.png", o1, c1, o2, c2, o3, c3, o4, c4, o5, c5, o6, c6); int sult1 = ds.InsertSql(str1, out re); if (sult1 <= 0) { LogHelper.Error(string.Format("新增语句错误-Sys_RunningState:{0}", str1)); } } } catch (Exception ex) { LogHelper.Error(ex.Message); } } #endregion } catch (Exception ex) { LogHelper.Error(ex.Message); result.msg = ex.Message; result.code = "1060"; return(result); } return(result); }