public DataAcquisitionResult SaveRunningStateStockBin([FromBody] RunningStateAPIParameterB param) { DataAcquisitionResult result = new DataAcquisitionResult(); result.code = "1000"; result.msg = "success"; if (param == null) { param = new RunningStateAPIParameterB(); 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-SaveRunningStateStockBin 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); } RunningStateDTOB dto = new RunningStateDTOB(); try { dto = Deserialize <RunningStateDTOB>(param.strdata); bool fla = UpdateRunningStateStockBin(dto); if (!fla) { LogHelper.Error(string.Format("新增失败-SaveRunningStateStockBin:{0}", Serialize(dto))); //result.msg = "数据插入失败"; //result.code = "1050"; //return result; } } catch (Exception ex) { LogHelper.Error(ex.Message); result.msg = ex.Message; result.code = "1060"; return(result); } return(result); }
private void button8_Click(object sender, EventArgs e) { DataAcquisitionResult result = new DataAcquisitionResult(); RunningStateDTOB dto = new RunningStateDTOB(); dto.Describe7 = "38;2;3;0;0;10"; dto.DescribeColor7 = "#D24D57;#26A65B;#EB7347;#84AF9B;#FC9D99;#00CCFF"; dto.Describe8 = "39;0;29;0;0;20"; dto.DescribeColor8 = "#D24D57;#26A65B;#EB7347;#84AF9B;#FC9D99;#00CCFF"; string server = "http://localhost:15988/api/AutomationLine/SaveRunningStateStockBin"; RunningStateAPIParameterB param = new RunningStateAPIParameterB(); param.operator_name = "WebApi"; param.operator_time = GenerateTimeStamp(DateTime.Now); param.sign = GenSign(param.operator_name, param.operator_time); param.data = dto; 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 bool UpdateRunningStateStockBin(RunningStateDTOB dto) { bool fla = false; try { int re = 0; DbService ds = new DbService(dbnfin, "MySQL"); string srt = string.Format(@"UPDATE Sys_RunningState set Describe7='{0}',DescribeColor7='{1}',Describe8='{2}',DescribeColor8='{3}'", dto.Describe7, dto.DescribeColor7, dto.Describe8, dto.DescribeColor8); int sult = ds.InsertSql(srt, out re); if (sult > 0) { fla = true; } } catch (Exception ex) { LogHelper.Error(ex.Message); } return(fla); }