/// <summary> /// 增加一条数据 /// </summary> public int Add(HighBack model) { DBHelper db = new DBHelper(); DbCommand cmd = db.GetStoredProcCommond("Proc_HighBack_Insert");//返回主键 db.AddInParameter(cmd, "@house_no", DbType.Int32, model.HouseNo); db.AddInParameter(cmd, "@temperatureset", DbType.String, model.Temperatureset); db.AddInParameter(cmd, "@RegionCode", DbType.String, model.RegionCode); db.AddInParameter(cmd, "@regionName", DbType.String, model.RegionName); db.AddInParameter(cmd, "@RegionId", DbType.Guid,Guid.Parse(model.RegionId)); db.AddInParameter(cmd, "@testdatetime", DbType.DateTime, model.Testdatetime); db.AddInParameter(cmd, "@addTime", DbType.DateTime, model.AddTime); db.AddInParameter(cmd, "@state", DbType.String, model.State); object res = db.ExecuteScalar(cmd); return res == null ? -1 : Convert.ToInt32(res); }
private HighBack DataRowToBean(DataRow row) { HighBack highBackBean = new HighBack(); highBackBean.ID = Convert.IsDBNull(row["ID"]) ? 0 : Convert.ToInt32(row["ID"]); highBackBean.HouseNo = Convert.IsDBNull(row["house_no"]) ? 0 : Convert.ToInt32(row["house_no"]); highBackBean.Temperatureset = Convert.IsDBNull(row["temperatureset"]) ? "" : row["temperatureset"].ToString(); highBackBean.RegionCode = Convert.IsDBNull(row["RegionCode"]) ? "" : row["RegionCode"].ToString(); highBackBean.RegionName = Convert.IsDBNull(row["regionName"]) ? "" : row["regionName"].ToString(); highBackBean.RegionId = Convert.IsDBNull(row["RegionId"]) ? "" : row["RegionId"].ToString(); highBackBean.Testdatetime = Convert.IsDBNull(row["testdatetime"]) ? new DateTime(1900, 1, 1) : Convert.ToDateTime(row["testdatetime"]); highBackBean.AddTime = Convert.IsDBNull(row["addTime"]) ? new DateTime(1900, 1, 1) : Convert.ToDateTime(row["addTime"]); highBackBean.State = Convert.IsDBNull(row["state"]) ? "" : row["state"].ToString(); return highBackBean; }
private void CreateHighData() { try { int n = 0; bool flag = false; Dao.testDataDao testData = new testDataDao(); StroeSignHt = testData.GetStoreSign(); string sqlwhere = " and convert(varchar(10),testdatetime,23)='" + DateTime.Now.ToString("yyyy-MM-dd") + "'"; // string sqlwhere = " and convert(varchar(10),testdatetime,23)='2011-09-23'"; IList<TestData> list = testData.GetTestDataList(sqlwhere); foreach (TestData data in list) { StoreHouse storeHouse = testData.GetStoreHouses(data.RegionId.ToString(), data.house_no.ToString()); if (storeHouse == null) { comm.SaveLog("1", DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") + "获取数据出现问题"); return; } char[] temp = data.temperatureset.ToCharArray(); comm.SaveLog("1",DateTime.Now.ToString()+"开始解析数据"); switch (StroeSignHt[data.RegionCode].ToString()) { case "1": comm.SaveLog("1", DateTime.Now.ToString() + StroeSignHt[data.RegionCode].ToString()); flag = GetWD(storeHouse.cable_x.Value, storeHouse.cable_y.Value, storeHouse.node_z.Value, temp); break; case "2": comm.SaveLog("1", DateTime.Now.ToString() + StroeSignHt[data.RegionCode].ToString()); flag = GetWD2(storeHouse.cable_x.Value, storeHouse.cable_y.Value, storeHouse.node_z.Value, temp); comm.SaveLog("1", DateTime.Now.ToString()+"完成" + StroeSignHt[data.RegionCode].ToString()); break; case "3": comm.SaveLog("1", DateTime.Now.ToString() + StroeSignHt[data.RegionCode].ToString()); flag = GetWD3(storeHouse.cable_x.Value, storeHouse.cable_y.Value, storeHouse.node_z.Value, temp); break; } if (!flag) { n++; HighBack highBack = new HighBack(); highBack.AddTime = DateTime.Now; highBack.HouseNo = data.house_no.Value; highBack.RegionCode = data.RegionCode; highBack.RegionId = data.RegionId.ToString(); highBack.RegionName = data.regionName; highBack.Temperatureset = data.temperatureset; highBack.Testdatetime = data.testdatetime.Value; highBack.State = "0"; testData.Add(highBack); } } comm.SaveLog("1", DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") + "任务执行完成:共发现" + n.ToString() + "条高温数据"); } catch (Exception e) { comm.SaveLog("2", DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") + "任务执行失败:" + e.Message); } }