/// <summary> /// 增加一条数据 /// </summary> public bool Add(Alert model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into Alert("); strSql.Append("AlertID,AlertName,AlertRule,OrganID,Description)"); strSql.Append(" values ("); strSql.Append("@AlertID,@AlertName,@AlertRule,@OrganID,@Description)"); SqlParameter[] parameters = { new SqlParameter("@AlertID", SqlDbType.Int,4), new SqlParameter("@AlertName", SqlDbType.VarChar,30), new SqlParameter("@AlertRule", SqlDbType.VarChar,500), new SqlParameter("@OrganID", SqlDbType.Int,4), new SqlParameter("@Description", SqlDbType.VarChar,500)}; parameters[0].Value = model.AlertID; parameters[1].Value = model.AlertName; parameters[2].Value = model.AlertRule; parameters[3].Value = model.OrganID; parameters[4].Value = model.Description; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return true; } else { return false; } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Alert model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update Alert set "); strSql.Append("AlertName=@AlertName,"); strSql.Append("AlertRule=@AlertRule,"); strSql.Append("OrganID=@OrganID,"); strSql.Append("Description=@Description"); strSql.Append(" where AlertID=@AlertID "); SqlParameter[] parameters = { new SqlParameter("@AlertName", SqlDbType.VarChar,30), new SqlParameter("@AlertRule", SqlDbType.VarChar,500), new SqlParameter("@OrganID", SqlDbType.Int,4), new SqlParameter("@Description", SqlDbType.VarChar,500), new SqlParameter("@AlertID", SqlDbType.Int,4)}; parameters[0].Value = model.AlertName; parameters[1].Value = model.AlertRule; parameters[2].Value = model.OrganID; parameters[3].Value = model.Description; parameters[4].Value = model.AlertID; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return true; } else { return false; } }
/// <summary> /// 得到一个对象实体 /// </summary> public Alert GetModel(int AlertID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 AlertID,AlertName,AlertRule,OrganID,Description from Alert "); strSql.Append(" where AlertID=@AlertID "); SqlParameter[] parameters = { new SqlParameter("@AlertID", SqlDbType.Int,4) }; parameters[0].Value = AlertID; Alert model = new Alert(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["AlertID"] != null && ds.Tables[0].Rows[0]["AlertID"].ToString() != "") { model.AlertID = int.Parse(ds.Tables[0].Rows[0]["AlertID"].ToString()); } if (ds.Tables[0].Rows[0]["AlertName"] != null && ds.Tables[0].Rows[0]["AlertName"].ToString() != "") { model.AlertName = ds.Tables[0].Rows[0]["AlertName"].ToString(); } if (ds.Tables[0].Rows[0]["AlertRule"] != null && ds.Tables[0].Rows[0]["AlertRule"].ToString() != "") { model.AlertRule = ds.Tables[0].Rows[0]["AlertRule"].ToString(); } //if (ds.Tables[0].Rows[0]["MinValue"] != null && ds.Tables[0].Rows[0]["MinValue"].ToString() != "") //{ // model.MinValue = ds.Tables[0].Rows[0]["MinValue"].ToString(); //} //if (ds.Tables[0].Rows[0]["MaxValue"] != null && ds.Tables[0].Rows[0]["MaxValue"].ToString() != "") //{ // model.MaxValue = ds.Tables[0].Rows[0]["MaxValue"].ToString(); //} if (ds.Tables[0].Rows[0]["OrganID"] != null && ds.Tables[0].Rows[0]["OrganID"].ToString() != "") { model.OrganID = int.Parse(ds.Tables[0].Rows[0]["OrganID"].ToString()); } if (ds.Tables[0].Rows[0]["Description"] != null && ds.Tables[0].Rows[0]["Description"].ToString() != "") { model.Description = ds.Tables[0].Rows[0]["Description"].ToString(); } return model; } else { return null; } }
/// <summary> /// 获得数据列表 /// </summary> public List<Alert> DataTableToList(DataTable dt) { List<Alert> modelList = new List<Alert>(); int rowsCount = dt.Rows.Count; if (rowsCount > 0) { Alert model; for (int n = 0; n < rowsCount; n++) { model = new Alert(); if (dt.Rows[n]["AlertID"] != null && dt.Rows[n]["AlertID"].ToString() != "") { model.AlertID = int.Parse(dt.Rows[n]["AlertID"].ToString()); } if (dt.Rows[n]["AlertName"] != null && dt.Rows[n]["AlertName"].ToString() != "") { model.AlertName = dt.Rows[n]["AlertName"].ToString(); } if (dt.Rows[n]["AlertRule"] != null && dt.Rows[n]["AlertRule"].ToString() != "") { model.AlertRule = dt.Rows[n]["AlertRule"].ToString(); } //if (dt.Rows[n]["MinValue"] != null && dt.Rows[n]["MinValue"].ToString() != "") //{ // model.MinValue = dt.Rows[n]["MinValue"].ToString(); //} //if (dt.Rows[n]["MaxValue"] != null && dt.Rows[n]["MaxValue"].ToString() != "") //{ // model.MaxValue = dt.Rows[n]["MaxValue"].ToString(); //} if (dt.Rows[n]["OrganID"] != null && dt.Rows[n]["OrganID"].ToString() != "") { model.OrganID = int.Parse(dt.Rows[n]["OrganID"].ToString()); } if (dt.Rows[n]["Description"] != null && dt.Rows[n]["Description"].ToString() != "") { model.Description = dt.Rows[n]["Description"].ToString(); } modelList.Add(model); } } return modelList; }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Alert model) { return dal.Update(model); }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(Alert model) { return dal.Add(model); }