Example #1
0
        private void SetSettingValue(string key, string val)
        {
            var cacheKey = String.Format("{0}||||{1}||||{2}||||{3}", _tableName, _addonName, _userName, key);

            _cache.Remove(cacheKey);

            var nextTableCode = SboUserDefinedDataManager.GetNextTableCode(_tableName);

            using (var factory = new SboDisposableBusinessObjectFactory())
            {
                var recordSet = factory.Create <Recordset>(BoObjectTypes.BoRecordset);

                try
                {
                    if (HasSetting(key))
                    {
                        Log.Debug("Updating setting key " + key);
                        recordSet.DoQuery(_userName == null
                                              ? string.Format(
                                              @"UPDATE ""@{0}"" SET ""U_BigValue"" = '{3}' WHERE ""U_Addon"" = '{1}' AND RTRIM(COALESCE(""U_User"", '')) = '' AND ""U_BigKey"" = '{2}'",
                                              _tableName, _addonName, key,
                                              val
                                              )
                                              : string.Format(
                                              @"UPDATE ""@{0}"" SET ""U_BigValue"" = '{4}' WHERE ""U_Addon"" = '{1}' AND ""U_User"" = '{2}' AND ""U_BigKey"" = '{3}'",
                                              _tableName, _addonName, _userName, key,
                                              val
                                              )
                                          );
                    }
                    else
                    {
                        Log.Debug("Inserting setting key " + key);
                        recordSet.DoQuery(_userName == null
                                              ? string.Format(
                                              @"INSERT INTO ""@{0}"" (""Code"", ""Name"", ""U_Addon"", ""U_BigKey"", ""U_BigValue"") VALUES ('{1}', '{1}', '{2}', '{3}', '{4}')",
                                              _tableName,
                                              nextTableCode,
                                              _addonName, key, val
                                              )
                                              : string.Format(
                                              @"INSERT INTO ""@{0}"" (""Code"", ""Name"", ""U_Addon"", ""U_User"", ""U_BigKey"", ""U_BigValue"") VALUES ('{1}', '{1}', '{2}', '{3}', '{4}', '{5}')",
                                              _tableName,
                                              nextTableCode,
                                              _addonName, _userName, key, val
                                              )
                                          );
                    }
                }
                catch (Exception e)
                {
                    Log.Error(e, "Recordset error");
                }
            }
        }
Example #2
0
 private void Initialize()
 {
     SboUserDefinedDataManager.AddUserTableIfNotExist(_tableName, "Global Settings");
     SboUserDefinedDataManager.AddUserFieldIfNotExist("@" + _tableName, "Addon", "Addon", BoFieldTypes.db_Alpha,
                                                      BoFldSubTypes.st_None, 100);
     SboUserDefinedDataManager.AddUserFieldIfNotExist("@" + _tableName, "User", "User", BoFieldTypes.db_Alpha,
                                                      BoFldSubTypes.st_None, 50);
     SboUserDefinedDataManager.AddUserFieldIfNotExist("@" + _tableName, "BigKey", "Setting key",
                                                      BoFieldTypes.db_Alpha, BoFldSubTypes.st_None, 254);
     SboUserDefinedDataManager.AddUserFieldIfNotExist("@" + _tableName, "BigValue", "Setting value",
                                                      BoFieldTypes.db_Alpha, BoFldSubTypes.st_None, 254);
 }
Example #3
0
        public static void Insert(this Recordset recordset, SboUserDefinedTableDefinition record)
        {
            var tableName = record.GetType().GetCustomAttributes(typeof(SboUserDefinedTableAttribute), true).Select(a => ((SboUserDefinedTableAttribute)a).Name).FirstOrDefault();

            if (String.IsNullOrEmpty(record.Code))
            {
                record.Code = SboUserDefinedDataManager.GetNextTableCode(tableName);
            }
            if (String.IsNullOrEmpty(record.Name))
            {
                record.Name = record.Code;
            }

            var fieldValues = GetUserDefinedTableDefinitionSqlValues(record);

            var query = String.Format(@"INSERT INTO ""@{0}"" ({1}) VALUES ({2})", tableName, String.Join(",", fieldValues.Keys.Select(k => $"\"{k}\"")), String.Join(",", fieldValues.Values));

            Logger.Trace("Inserting into UDT: {0}", query);

            recordset.DoQuery(query);
        }