Example #1
0
 public Config(ConfigSystem cs, string key, object value)
 {
     ConfigSystemInfo = cs;
     ConfigSystem     = cs.ToString();
     ConfigKey        = key;
     ConfigValue      = value?.ToString().Trim();
 }
Example #2
0
        public void Select()
        {
            var dr = DataAccess.Config.GetConfigByID(ConfigSystem.ToString(), ConfigKey);

            if (dr != null)
            {
                InitConfig(dr);
            }
        }
Example #3
0
        public bool Any()
        {
            var sql =
                $"SELECT * FROM {Repository.GetTableAttr<Config>().Name} WHERE ConfigSystem = @configSystem AND ConfigKey = @configKey";

            SqlParameter[] para =
            {
                new SqlParameter("@configSystem", ConfigSystem.ToString()),
                new SqlParameter("@configKey",    ConfigKey)
            };

            var ds = DataAccess.ExecuteDataset(sql, para);

            return(ds.Tables[0].Rows.Count > 0);
        }
Example #4
0
        public void Update(SqlTransaction trans = null)
        {
            Contract.Requires(Any());

            var sql =
                $"UPDATE {Repository.GetTableAttr<Config>().Name} SET ConfigValue = @configValue WHERE ConfigSystem = @configSystem AND ConfigKey = @configKey";

            SqlParameter[] para =
            {
                new SqlParameter("@configSystem", ConfigSystem.ToString()),
                new SqlParameter("@configKey",    ConfigKey),
                new SqlParameter("@configValue",  ConfigValue)
            };

            DataAccess.ExecuteNonQuery(sql, para, trans);
        }
Example #5
0
        private void Insert()
        {
            using (var conn = SQLConn.GetConnection())
            {
                conn.Open();
                var trans = conn.BeginTransaction();
                try
                {
                    DataAccess.Config.InsertConfig(ConfigSystem.ToString(), ConfigKey, ConfigValue, trans);

                    trans.Commit();
                }
                catch
                {
                    trans.Rollback();
                }

                //conn.Close();
            }
        }
Example #6
0
        public void Save(SqlTransaction trans = null)
        {
            if (Any())
            {
                Update();
            }
            else
            {
                var sql =
                    $"INSERT INTO {Repository.GetTableAttr<Config>().Name} (ConfigValue, ConfigSystem, ConfigKey) VALUES (@configValue, @configSystem, @configKey)";

                SqlParameter[] para =
                {
                    new SqlParameter("@configSystem", ConfigSystem.ToString()),
                    new SqlParameter("@configKey",    ConfigKey),
                    new SqlParameter("@configValue",  ConfigValue)
                };

                DataAccess.ExecuteNonQuery(sql, para, trans);
            }
        }
Example #7
0
 private void Delete()
 {
     DataAccess.Config.DeleteConfig(ConfigSystem.ToString(), ConfigKey);
 }