コード例 #1
0
        /// <summary>
        /// 保存信息
        /// </summary>
        /// <param name="key">键</param>
        /// <param name="value">值(中英文用‘|’分隔)</param>
        /// <param name="inEncrypt">是否加密</param>
        public static void SaveValue(string key, string value, bool inEncrypt = false)
        {
            if (String.CompareOrdinal(ReadValue(key, inEncrypt), value) == 0)
                return;

            lock (_lock)
            {
#if PgSQL
                if (Database.ExecuteNonQuery(@"
update PH7_AppSettings set
  AS_Value = @AS_Value,
  AS_ValueEncrypted = @AS_ValueEncrypted
where AS_Key = @AS_Key",
#endif
#if MsSQL
                if (Database.ExecuteNonQuery(@"
update PH7_AppSettings set
  AS_Value = @AS_Value,
  AS_ValueEncrypted = @AS_ValueEncrypted
where AS_Key = @AS_Key",
#endif
#if MySQL
                if (Database.ExecuteNonQuery(@"
update PH7_AppSettings set
  AS_Value = ?AS_Value,
  AS_ValueEncrypted = ?AS_ValueEncrypted
where AS_Key = ?AS_Key",
#endif
#if ORA
                if (Database.ExecuteNonQuery(@"
update PH7_AppSettings set
  AS_Value = :AS_Value,
  AS_ValueEncrypted = :AS_ValueEncrypted
where AS_Key = :AS_Key",
#endif
                    ParamValue.Input("AS_Value", inEncrypt ? Encrypt(value) : value),
                    ParamValue.Input("AS_ValueEncrypted", inEncrypt ? 1 : 0),
                    ParamValue.Input("AS_Key", key)) == 1)
                    return;

#if PgSQL
                Database.ExecuteNonQuery(@"
insert into PH7_AppSettings
  (AS_Key, AS_Value, AS_ValueEncrypted)
values
  (@AS_Key, @AS_Value, @AS_ValueEncrypted)",
#endif
#if MsSQL
                Database.ExecuteNonQuery(@"
insert into PH7_AppSettings
  (AS_Key, AS_Value, AS_ValueEncrypted)
values
  (@AS_Key, @AS_Value, @AS_ValueEncrypted)",
#endif
#if MySQL
                Database.ExecuteNonQuery(@"
insert into PH7_AppSettings
  (AS_Key, AS_Value, AS_ValueEncrypted)
values
  (?AS_Key, ?AS_Value, ?AS_ValueEncrypted)",
#endif
#if ORA
                Database.ExecuteNonQuery(@"
insert into PH7_AppSettings
  (AS_Key, AS_Value, AS_ValueEncrypted)
values
  (:AS_Key, :AS_Value, :AS_ValueEncrypted)",
#endif
                    ParamValue.Input("AS_Key", key),
                    ParamValue.Input("AS_Value", inEncrypt ? Encrypt(value) : value),
                    ParamValue.Input("AS_ValueEncrypted", inEncrypt ? 1 : 0));
            }
        }
コード例 #2
0
        /// <summary>
        /// 读取信息(分离出当前线程语言的中英文文本)
        /// Thread.CurrentThread.CurrentCulture.Name为非'zh-'时返回后半截
        /// </summary>
        /// <param name="key">键</param>
        /// <param name="inEncrypt">是否加密</param>
        public static string ReadValue(string key, bool inEncrypt = false)
        {
            try
            {
                return _cache.GetValue(key, () =>
                {
                    string pendingValue;
#if PgSQL
                    using (DataReader reader = Database.CreateDataReader(@"
select AS_Value, AS_ValueEncrypted
from PH7_AppSettings
where AS_Key = @AS_Key",
#endif
#if MsSQL
                    using (DataReader reader = Database.CreateDataReader(@"
select AS_Value, AS_ValueEncrypted
from PH7_AppSettings
where AS_Key = @AS_Key",
#endif
#if MySQL
                    using (DataReader reader = Database.CreateDataReader(@"
select AS_Value, AS_ValueEncrypted
from PH7_AppSettings
where AS_Key = ?AS_Key",
#endif
#if ORA
                    using (DataReader reader = Database.CreateDataReader(@"
select AS_Value, AS_ValueEncrypted
from PH7_AppSettings
where AS_Key = :AS_Key",
#endif
                        CommandBehavior.SingleRow))
                    {
                        reader.CreateParameter("AS_Key", key);
                        if (reader.Read())
                            if (inEncrypt)
                                if (reader.IsDBNull(1) || reader.GetInt32(1) != 1)
                                    pendingValue = reader.GetString(0);
                                else
                                    try
                                    {
                                        return AppRun.SplitCulture(Decrypt(reader.GetString(0)));
                                    }
                                    catch (SystemException) //FormatException & CryptographicException
                                    {
                                        pendingValue = reader.GetString(0);
                                    }
                            else
                                return AppRun.SplitCulture(reader.GetString(0));
                        else
                            throw new KeyNotFoundException();
                    }

                    if (pendingValue != null)
#if PgSQL
                        Database.ExecuteNonQuery(@"
update PH7_AppSettings set
  AS_Value = @AS_Value,
  AS_ValueEncrypted = 1
where AS_Key = @AS_Key",
#endif
#if MsSQL
                        Database.ExecuteNonQuery(@"
update PH7_AppSettings set
  AS_Value = @AS_Value,
  AS_ValueEncrypted = 1
where AS_Key = @AS_Key",
#endif
#if MySQL
                        Database.ExecuteNonQuery(@"
update PH7_AppSettings set
  AS_Value = ?AS_Value,
  AS_ValueEncrypted = 1
where AS_Key = ?AS_Key",
#endif
#if ORA
                        Database.ExecuteNonQuery(@"
update PH7_AppSettings set
  AS_Value = :AS_Value,
  AS_ValueEncrypted = 1
where AS_Key = :AS_Key",
#endif
                            ParamValue.Input("AS_Value", Encrypt(pendingValue)),
                            ParamValue.Input("AS_Key", key));

                    return AppRun.SplitCulture(pendingValue);
                });
            }