public void SubmitForm(DataAcquisitionEntity daEntity, string keyValue = "") { if (!string.IsNullOrEmpty(keyValue)) { daEntity.Modify(keyValue); service.Update(daEntity); } else { daEntity.Create(); service.Insert(daEntity); } }
public bool InsertDataAcquisition(DataAcquisitionEntity dto) { bool fla = false; try { #region Sys_DataAcquisition 数据采集 int re = 0; DbService ds = new DbService(dbnfin, "MySQL"); string str1 = string.Format(@"SELECT * from Sys_DataAcquisition WHERE DeviceName='{0}' AND IsEffective=1;", dto.DeviceName); bool sult1 = ds.IsExistRecord(str1); if (sult1) { string srt = string.Format(@"UPDATE Sys_DataAcquisition SET DeviceRunStatus='{0}',DeviceUrl='{1}',DeviceLndicatorLight='{2}',TodayOutput={3},TodayJiadong={4},SpindleSpeed={5},FeedSpeed={6},SpindleRatio={7},FeedRatio={8},LoadRatio={9} WHERE DeviceName='{10}' AND IsEffective=1", dto.DeviceRunStatus, dto.DeviceUrl, dto.DeviceLndicatorLight, dto.TodayOutput, dto.TodayJiadong, dto.SpindleSpeed, dto.FeedSpeed, dto.SpindleRatio, dto.FeedRatio, dto.LoadRatio, dto.DeviceName); int sult = ds.InsertSql(srt, out re); if (sult > 0) { fla = true; } } else { string srt = string.Format(@"INSERT INTO Sys_DataAcquisition(DeviceName,DeviceRunStatus,DeviceUrl,DeviceLndicatorLight,TodayOutput,TodayJiadong,SpindleSpeed,FeedSpeed,SpindleRatio,FeedRatio,LoadRatio,CreationTime) VALUES ( '{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}',NOW())", dto.DeviceName, dto.DeviceRunStatus, dto.DeviceUrl, dto.DeviceLndicatorLight, dto.TodayOutput, dto.TodayJiadong, dto.SpindleSpeed, dto.FeedSpeed, dto.SpindleRatio, dto.FeedRatio, dto.LoadRatio); int sult = ds.InsertSql(srt, out re); if (sult > 0) { fla = true; } } #endregion } catch (Exception ex) { LogHelper.Error(ex.Message); } return(fla); }
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; } }