Exemple #1
0
        private DateTime?GetUpdateTime(SettingsKeyEnum settingsKey)
        {
            string querySql = " SELECT * FROM  NY_Settings WHERE UserAccount=@UserAccount AND [Key]=@Key ";
            var    parmers  = new SqlParameter[] {
                new SqlParameter("UserAccount", userAccount),
                new SqlParameter("Key", settingsKey.ToString())
            };

            var updateTime = String.Empty;

            using (var reader = dbhelp.ExecuteReader(CommandType.Text, querySql, parmers))
            {
                if (reader.Read())
                {
                    updateTime = reader["UpdateTime"].ToString();
                }
            }

            if (String.IsNullOrEmpty(updateTime))
            {
                return(null);
            }
            else
            {
                return(DateTime.Parse(updateTime));
            }
        }
Exemple #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="settingsKey"></param>
        /// <param name="valueJson"></param>
        /// <param name="count"></param>
        /// <param name="IntervalUpdateMilliseconds">更新的间隔时间(毫秒)</param>
        public void AddOrUpdate(SettingsKeyEnum settingsKey, string valueJson, int count)
        {
            string querySql = " SELECT * FROM  NY_Settings WHERE UserAccount=@UserAccount AND [Key]=@Key ";
            var    parmers  = new SqlParameter[] {
                new SqlParameter("UserAccount", userAccount),
                new SqlParameter("Key", settingsKey.ToString())
            };

            var isExsists = false;

            using (var reader = dbhelp.ExecuteReader(CommandType.Text, querySql, parmers))
            {
                if (reader.Read())
                {
                    isExsists = true;
                }
            }

            //表示存在,则更新数据
            if (isExsists)
            {
                var updateSql = String.Format(" UPDATE NY_Settings SET [Value]='{0}',Count={1},UpdateTime='{2}'  WHERE UserAccount=@UserAccount AND [Key]=@Key", valueJson, count, DateTime.Now.ToString());
                dbhelp.ExecuteNonQuery(CommandType.Text, updateSql, parmers);
            }
            else
            {
                var insertSql = String.Format(" INSERT INTO NY_Settings VALUES(@UserAccount,@Key,'{0}',{1},'{2}' ) ", valueJson, count, DateTime.Now.ToString());
                dbhelp.ExecuteNonQuery(CommandType.Text, insertSql, parmers);
            }
        }
Exemple #3
0
        public string GetSettingsValue(SettingsKeyEnum settingsKey, out int count)
        {
            string value = String.Empty;

            count = 0;

            string querySql = " SELECT * FROM  NY_Settings WHERE UserAccount=@UserAccount AND [Key]=@Key ";
            var    parmers  = new SqlParameter[] {
                new SqlParameter("UserAccount", userAccount),
                new SqlParameter("Key", settingsKey.ToString())
            };

            var reader = dbhelp.ExecuteReader(CommandType.Text, querySql, parmers);

            if (reader.Read())
            {
                count = int.Parse(reader["Count"].ToString());
                value = reader["Value"].ToString();
            }

            return(value);
        }