/// <summary> /// 更新一条数据 /// </summary> public bool Update(Maticsoft.Model.Config model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update Config set "); strSql.Append("GUID=@GUID,"); strSql.Append("ConfigKey=@ConfigKey,"); strSql.Append("ConfigValue=@ConfigValue"); strSql.Append(" where ID=@ID"); SqlParameter[] parameters = { new SqlParameter("@GUID", SqlDbType.NVarChar, -1), new SqlParameter("@ConfigKey", SqlDbType.NVarChar, -1), new SqlParameter("@ConfigValue", SqlDbType.NVarChar, 50), new SqlParameter("@ID", SqlDbType.Int, 4) }; parameters[0].Value = model.GUID; parameters[1].Value = model.ConfigKey; parameters[2].Value = model.ConfigValue; parameters[3].Value = model.ID; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Maticsoft.Model.Config model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into Config("); strSql.Append("GUID,ConfigKey,ConfigValue)"); strSql.Append(" values ("); strSql.Append("@GUID,@ConfigKey,@ConfigValue)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@GUID", SqlDbType.NVarChar, -1), new SqlParameter("@ConfigKey", SqlDbType.NVarChar, -1), new SqlParameter("@ConfigValue", SqlDbType.NVarChar, 50) }; parameters[0].Value = model.GUID; parameters[1].Value = model.ConfigKey; parameters[2].Value = model.ConfigValue; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.Config GetModel(int ID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 ID,GUID,ConfigKey,ConfigValue from Config "); strSql.Append(" where ID=@ID"); SqlParameter[] parameters = { new SqlParameter("@ID", SqlDbType.Int, 4) }; parameters[0].Value = ID; Maticsoft.Model.Config model = new Maticsoft.Model.Config(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.Config DataRowToModel(DataRow row) { Maticsoft.Model.Config model = new Maticsoft.Model.Config(); if (row != null) { if (row["ID"] != null && row["ID"].ToString() != "") { model.ID = int.Parse(row["ID"].ToString()); } if (row["GUID"] != null) { model.GUID = row["GUID"].ToString(); } if (row["ConfigKey"] != null) { model.ConfigKey = row["ConfigKey"].ToString(); } if (row["ConfigValue"] != null) { model.ConfigValue = row["ConfigValue"].ToString(); } } return(model); }
/// <summary> /// 得到一个对象实体,根据指定的项目名称 /// </summary> public Maticsoft.Model.Config ExGetModel(string ConfigKey) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id,GUID,ConfigKey,ConfigValue from Config "); strSql.Append(" where ConfigKey=@ConfigKey "); SqlParameter[] parameters = { new SqlParameter("@ConfigKey", SqlDbType.VarChar) }; parameters[0].Value = ConfigKey; Maticsoft.Model.Config model = new Maticsoft.Model.Config(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }