//Delete an Object in database Config public static int Delete(Config_Object DeletingObject) { List<SqlParameter> paralist = new List<SqlParameter>(); string DeleteQuery = @"Delete [Config] Where ConfigName= @ConfigName"; paralist.Add(new SqlParameter("ConfigName", DeletingObject.ConfigName)); return commonDatabase.ExecuteNonQuerySQL(clsConnectionString.GetConnectionString(), DeleteQuery, paralist); }
//Save changes of an Object to database Config public static int SaveChanged(Config_Object UpdatingObject) { List<SqlParameter> paralist = new List<SqlParameter>(); string UpdateQuery = @"Update [systbModules] SET ConfigValue= @ConfigValue Where ConfigName= @ConfigName"; paralist.Add(new SqlParameter("ConfigName", UpdatingObject.ConfigName)); paralist.Add(new SqlParameter("ConfigValue", UpdatingObject.ConfigValue)); return commonDatabase.ExecuteNonQuerySQL(clsConnectionString.GetConnectionString(), UpdateQuery, paralist); }
//Get an Object of Config public static Config_Object GetObject(string _ConfigName) { List<SqlParameter> paralist = new List<SqlParameter>(); Config_Object newObject = new Config_Object(); string SelectQuery = "Select * from [Config] where (1=1) and [ConfigName]= @ConfigName"; paralist.Add(new SqlParameter("ConfigName", _ConfigName)); DataTable tb = commonDatabase.GetSQLDataTable(clsConnectionString.GetConnectionString(), SelectQuery, paralist); if (tb.Rows.Count < 1) return null; DataRow row = tb.Rows[0]; newObject.ConfigName = (string)row["ConfigName"]; if (row["ConfigValue"].ToString() != "") newObject.ConfigValue = (string)row["ConfigValue"]; return newObject; }
//Insert Config public static int Insert(Config_Object newObject) { string InsertQuery = "Insert Into [Config]"; List<SqlParameter> paralist = new List<SqlParameter>(); string _val = "", _para = ""; _val += "ConfigName, "; _para += "@ConfigName, "; paralist.Add(new SqlParameter("ConfigName", newObject.ConfigName)); if (newObject.ConfigValue != null) { _val += "ConfigValue, "; _para += "@ConfigValue, "; paralist.Add(new SqlParameter("ConfigValue", newObject.ConfigValue)); } InsertQuery += "(" + _val + ") Values (" + _para + ")"; InsertQuery = InsertQuery.Replace(", )", ")"); return commonDatabase.ExecuteNonQuerySQL(clsConnectionString.GetConnectionString(), InsertQuery, paralist); }
//Select Config public static List<Config_Object> SelectAll() { string SelectQuery = @"Select * from [Config]"; List<Config_Object> result = new List<Config_Object>(); DataTable tb = commonDatabase.GetSQLDataTable(clsConnectionString.GetConnectionString(), SelectQuery); foreach (DataRow row in tb.Rows) { Config_Object newObject = new Config_Object(); newObject.ConfigName = (string)row["ConfigName"]; if (row["ConfigValue"].ToString() != "") newObject.ConfigValue = (string)row["ConfigValue"]; result.Add(newObject); } return result; }