public Model.MonitorChannel GetModelByTD(int appId, int monitorType) { StringBuilder strSql = new StringBuilder(); strSql.Append("select a_id, ChannelId, Threshold, a_minute, a_state, a_datetime,a_type "); strSql.Append(" from MonitorChannel "); strSql.Append(" where "); strSql.Append(" ChannelId = @ChannelId"); strSql.Append(" AND a_type=@a_type"); SqlParameter[] parameters = { new SqlParameter("@ChannelId", SqlDbType.Int, 4), new SqlParameter("@a_type", SqlDbType.Int, 4) }; parameters[0].Value = appId; parameters[1].Value = monitorType; Model.MonitorChannel model = new Model.MonitorChannel(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["a_id"].ToString() != "") { model.a_id = int.Parse(ds.Tables[0].Rows[0]["a_id"].ToString()); } if (ds.Tables[0].Rows[0]["ChannelId"].ToString() != "") { model.ChannelId = int.Parse(ds.Tables[0].Rows[0]["ChannelId"].ToString()); } if (ds.Tables[0].Rows[0]["Threshold"].ToString() != "") { model.Threshold = decimal.Parse(ds.Tables[0].Rows[0]["Threshold"].ToString()); } if (ds.Tables[0].Rows[0]["a_minute"].ToString() != "") { model.a_minute = int.Parse(ds.Tables[0].Rows[0]["a_minute"].ToString()); } if (ds.Tables[0].Rows[0]["a_state"].ToString() != "") { model.a_state = int.Parse(ds.Tables[0].Rows[0]["a_state"].ToString()); } if (ds.Tables[0].Rows[0]["a_datetime"].ToString() != "") { model.a_datetime = DateTime.Parse(ds.Tables[0].Rows[0]["a_datetime"].ToString()); } if (ds.Tables[0].Rows[0]["a_type"].ToString() != "") { model.a_type = int.Parse(ds.Tables[0].Rows[0]["a_type"].ToString()); } return(model); } else { return(null); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Model.MonitorChannel model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update MonitorChannel set "); strSql.Append(" ChannelId = @ChannelId , "); strSql.Append(" Threshold = @Threshold , "); strSql.Append(" a_minute = @a_minute , "); strSql.Append(" a_state = @a_state , "); strSql.Append(" a_datetime = @a_datetime , "); strSql.Append(" a_time_range = @a_time_range,"); strSql.Append(" a_type = @a_type"); strSql.Append(" where a_id=@a_id "); SqlParameter[] parameters = { new SqlParameter("@a_id", SqlDbType.Int, 4), new SqlParameter("@ChannelId", SqlDbType.Int, 4), new SqlParameter("@Threshold", SqlDbType.Decimal, 9), new SqlParameter("@a_minute", SqlDbType.Int, 4), new SqlParameter("@a_state", SqlDbType.Int, 4), new SqlParameter("@a_datetime", SqlDbType.DateTime), new SqlParameter("@a_time_range", SqlDbType.NVarChar, -1), new SqlParameter("@a_type", SqlDbType.Int, 4) }; parameters[0].Value = model.a_id; parameters[1].Value = model.ChannelId; parameters[2].Value = model.Threshold; parameters[3].Value = model.a_minute; parameters[4].Value = model.a_state; parameters[5].Value = model.a_datetime; parameters[6].Value = model.a_time_range; parameters[7].Value = model.a_type; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 获得数据列表 /// </summary> public List <Model.MonitorChannel> DataTableToList(DataTable dt) { var modelList = new List <Model.MonitorChannel>(); int rowsCount = dt.Rows.Count; if (rowsCount > 0) { Model.MonitorChannel model; for (int n = 0; n < rowsCount; n++) { model = new Model.MonitorChannel(); if (dt.Rows[n]["a_id"].ToString() != "") { model.a_id = int.Parse(dt.Rows[n]["a_id"].ToString()); } if (dt.Rows[n]["ChannelId"].ToString() != "") { model.ChannelId = int.Parse(dt.Rows[n]["ChannelId"].ToString()); } if (dt.Rows[n]["Threshold"].ToString() != "") { model.Threshold = decimal.Parse(dt.Rows[n]["Threshold"].ToString()); } if (dt.Rows[n]["a_minute"].ToString() != "") { model.a_minute = int.Parse(dt.Rows[n]["a_minute"].ToString()); } if (dt.Rows[n]["a_state"].ToString() != "") { model.a_state = int.Parse(dt.Rows[n]["a_state"].ToString()); } if (dt.Rows[n]["a_datetime"].ToString() != "") { model.a_datetime = DateTime.Parse(dt.Rows[n]["a_datetime"].ToString()); } //a_type if (dt.Rows[n]["a_type"].ToString() != "") { model.a_type = int.Parse(dt.Rows[n]["a_type"].ToString()); } model.a_time_range = dt.Rows[n]["a_time_range"].ToString(); modelList.Add(model); } } return(modelList); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Model.MonitorChannel model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into MonitorChannel("); strSql.Append("ChannelId,Threshold,a_minute,a_state,a_datetime,a_time_range,a_type"); strSql.Append(") values ("); strSql.Append("@ChannelId,@Threshold,@a_minute,@a_state,@a_datetime,@a_time_range,@a_type"); strSql.Append(") "); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@ChannelId", SqlDbType.Int, 4), new SqlParameter("@Threshold", SqlDbType.Decimal, 9), new SqlParameter("@a_minute", SqlDbType.Int, 4), new SqlParameter("@a_state", SqlDbType.Int, 4), new SqlParameter("@a_datetime", SqlDbType.DateTime), new SqlParameter("@a_time_range", SqlDbType.NVarChar, -1), new SqlParameter("@a_type", SqlDbType.Int, 4) }; parameters[0].Value = model.ChannelId; parameters[1].Value = model.Threshold; parameters[2].Value = model.a_minute; parameters[3].Value = model.a_state; parameters[4].Value = model.a_datetime; parameters[5].Value = model.a_time_range; parameters[6].Value = model.a_type; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Model.MonitorChannel model) { return(_dal.Update(model)); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Model.MonitorChannel model) { return(_dal.Add(model)); }