public void TestDigSensorDataBLL() { DigSensorDataBLL bll = new DigSensorDataBLL(new DigSensorDataDAL()); DigSensorData data1 = new DigSensorData(0, "U2CCV001DM", false, true); bll.Add(data1); DigSensorData data2 = new DigSensorData(); data2.Id = 1; bll.Delete(data2); DigSensorData data3 = new DigSensorData(1, "U2CCV001DM", false, true); DigSensorData data4 = new DigSensorData(1, "U2CCV001DM", false, false); bll.Modify(data3, data4); DigSensorData data5 = (DigSensorData)bll.GetObjById(1.ToString()); int a = bll.ExcuteSqlStr("select * from digSensorData"); List <object> list1 = bll.GetAllObjs(); List <object> list2 = bll.GetObjsBySQL("select * from digSensorData", null); }
public object GetObjById(string id) { long LId; LId = long.Parse(id); DigSensorData digData = new DigSensorData(); string cmdText = "select * from digSensorData where id=@id"; MySqlParameter[] parms = new MySqlParameter[] { new MySqlParameter("@id", id) }; MySqlDataReader reader = this.MySqlHelper.ExecuteReader(cmdText, parms); while (reader.Read()) { digData.Id = long.Parse(id); digData.Name = reader[0].ToString().Trim(); digData.Time = DateTime.Parse(reader[1].ToString().Trim()); digData.Q = bool.Parse(reader[2].ToString().Trim()); digData.Dv = bool.Parse(reader[2].ToString().Trim()); } this.mySqlHelper.CloseConn(); return(digData); }
public List <object> GetObjsBySQL(string strSQL, MySqlParameter[] parms) { List <object> objs = new List <object>(); MySqlDataReader reader = this.MySqlHelper.ExecuteReader(strSQL, parms); while (reader.Read()) { DigSensorData digData = new DigSensorData(); digData.Id = long.Parse(reader[0].ToString().Trim()); digData.Name = reader[1].ToString().Trim(); digData.Time = DateTime.Parse(reader[2].ToString().Trim()); if ("0" == reader[3].ToString().Trim()) { digData.Q = false; } else { digData.Dv = true; } objs.Add(digData); } this.mySqlHelper.CloseConn(); return(objs); }
/// <summary> /// 删除指定传感器数据 /// </summary> /// <param name="obj">传感器</param> /// <returns>受影响的行数</returns> public int Delete(object obj) { DigSensorData data = (DigSensorData)obj; MySqlParameter[] parms = new MySqlParameter[] { new MySqlParameter("id", data.Id) }; string cmdText = "delete from digSensorData where id=@id"; return(base.MySqlHelper.ExecuteNonQuery(cmdText, parms)); }
public int Add(object obj) { DigSensorData data = (DigSensorData)obj; MySqlParameter[] parms = new MySqlParameter[] { new MySqlParameter("@name", data.Name), new MySqlParameter("@q", data.Q), new MySqlParameter("@dv", data.Dv) }; string cmdText = "insert into digSensorData(name,q,dv) values (@name,@q,@dv);"; return(base.MySqlHelper.ExecuteNonQuery(cmdText, parms)); }