private void InitializeSettings() { m_CounterSettings = new SettingCollection(); m_PaidSettings = new SettingCollection(); ConfigurationDataSet.SettingDataTable table = ConfigurationDataSet.Current.Setting; string filter = string.Format(CultureInfo.InvariantCulture, "{0} = {1}", table.SettingTypeIdColumn.ColumnName, (int)SettingType.Counter); foreach (ConfigurationDataSet.SettingRow row in table.Select(filter)) { m_CounterSettings.Add(SettingProvider.CreateSetting(row)); } filter = string.Format(CultureInfo.InvariantCulture, "{0} > 0", table.PriceColumn.ColumnName); foreach (ConfigurationDataSet.SettingRow row in table.Select(filter)) { if ((row.ShortName == "PhoneSupport") || (row.ShortName == "Training1Hour") || (row.ShortName == "Training3Hours") || (row.ShortName == "Training8Hours")) { continue; } m_PaidSettings.Add(SettingProvider.CreateSetting(row)); } }
protected void Edit(T item) { if (item == null) { item = new T(); } selectedItem = item; var vm = CreateViewModel(item); var window = CreateWindow(vm); window.ShowDialog(); if (vm.IsCancelled || item.Equals(vm.Setting)) { return; } var index = SettingCollection.IndexOf(item); if (index >= 0) { Remove(item); SettingCollection.Insert(index, vm.Setting); } else { SettingCollection.Add(vm.Setting); } IsDirty = true; }
static void Main() { var settings = new SettingCollection(); settings.Add("MembershipEnabled", "true"); settings.Add("OrderProductsEnabled", "true"); settings.Add("ConnectionTimeOut", "5"); settings.Add("DefaultTheme", "green"); settings.Add("MailPassword", "mailpass", true); Console.WriteLine("\tName\t\tValue\tEncrypted"); Console.WriteLine(new String('-', 40)); foreach (var setting in settings) { Console.WriteLine("{0,-25}{1,-10}{2,-5}", setting.Name, setting.Value, setting.IsEncrypted); } //Console.WriteLine("{0,20}", "hi"); Console.ReadKey(); }
private static SettingCollection DBMapping(DBSettingCollection dbCollection) { if (dbCollection == null) return null; SettingCollection collection = new SettingCollection(); foreach (DBSetting dbItem in dbCollection) { Setting item = DBMapping(dbItem); collection.Add(item); } return collection; }
public static SettingCollection Search(SearchFilter SearchKey) { SettingCollection collection = new SettingCollection(); using (var reader = SqlHelper.ExecuteReader("Setting_Search", SearchFilterManager.SqlSearchParam(SearchKey))) { while (reader.Read()) { Setting obj = new Setting(); obj = GetItemFromReader(reader); collection.Add(obj); } } return(collection); }
private static SettingCollection DBMapping(DBSettingCollection dbCollection) { if (dbCollection == null) { return(null); } SettingCollection collection = new SettingCollection(); foreach (DBSetting dbItem in dbCollection) { Setting item = DBMapping(dbItem); collection.Add(item); } return(collection); }
public static SettingCollection GetCalculatedPaidSettings(Guid OrgId, Guid InstId) { string cnnString = GetSettingsValuesHistoryDbConnectionString(); if (string.IsNullOrEmpty(cnnString)) { return(SettingProvider.GetAllPricedSettings(OrgId, InstId)); } DataTable dtLastValues = SelectSettingsLastValues(OrgId, InstId); if (dtLastValues.Rows.Count == 0) { return(SettingProvider.GetAllPricedSettings(OrgId, InstId)); } dtLastValues.PrimaryKey = new DataColumn[] { dtLastValues.Columns["SettingId"] }; SettingCollection resCol = new SettingCollection(); ConfigurationDataSet.SettingDataTable table = ConfigurationDataSet.Current.Setting; string filter = string.Format(CultureInfo.InvariantCulture, "{0} > 0", table.PriceColumn.ColumnName); Micajah.Common.Bll.Handlers.SettingHandler handler = Micajah.Common.Bll.Handlers.SettingHandler.Current; foreach (ConfigurationDataSet.SettingRow _srow in table.Select(filter)) { Setting s = SettingProvider.CreateSetting(_srow); DataRow rowS = dtLastValues.Rows.Find(_srow[table.SettingIdColumn.ColumnName]); if (rowS != null) { s.Value = rowS["SettingValue"].ToString(); } else { int settingVal = handler.GetUsedItemsCount(s, OrgId, InstId); s.Value = settingVal.ToString(CultureInfo.InvariantCulture); } resCol.Add(s); } return(resCol); }
public static SettingCollection GetLastModifiedPaidSettings(Guid OrgId, Guid InstId, DateTime?FromDate) { if (!FromDate.HasValue) { return(SettingProvider.GetAllPricedSettings(OrgId, InstId)); } string cnnString = GetSettingsValuesHistoryDbConnectionString(); if (string.IsNullOrEmpty(cnnString)) { return(SettingProvider.GetAllPricedSettings(OrgId, InstId)); } DataTable dtS = SelectLastModifiedSettings(OrgId, InstId, FromDate.Value); SettingCollection resCol = new SettingCollection(); if (dtS.Rows.Count == 0) { return(resCol); } dtS.PrimaryKey = new DataColumn[] { dtS.Columns["SettingId"] }; ConfigurationDataSet.SettingDataTable table = ConfigurationDataSet.Current.Setting; string filter = string.Format(CultureInfo.InvariantCulture, "{0} > 0", table.PriceColumn.ColumnName); foreach (ConfigurationDataSet.SettingRow _srow in table.Select(filter)) { DataRow rowS = dtS.Rows.Find(_srow[table.SettingIdColumn.ColumnName]); if (rowS == null) { continue; } Setting s = SettingProvider.CreateSetting(_srow); s.Value = rowS["SettingValue"].ToString(); resCol.Add(s); } return(resCol); }
public static SettingCollection GetbyUser(string CreatedUser, int CompanyID) { SettingCollection collection = new SettingCollection(); Setting obj; var sqlParams = new SqlParameter[] { new SqlParameter("@CreatedUser", CreatedUser), new SqlParameter("@CompanyID", CompanyID), }; using (var reader = SqlHelper.ExecuteReader("Setting_GetAll_byUser", sqlParams)) { while (reader.Read()) { obj = GetItemFromReader(reader); collection.Add(obj); } } return(collection); }
public static SettingCollection GetAllItem(int CompanyID) { SettingCollection collection = new SettingCollection(); var sqlParams = new SqlParameter[] { new SqlParameter("@CompanyID", CompanyID), }; using (var reader = SqlHelper.ExecuteReader("Setting_GetAll", sqlParams)) { while (reader.Read()) { Setting obj = new Setting(); obj = GetItemFromReader(reader); collection.Add(obj); } } return(collection); }
public static void CalculateCounterSettingsValues() { string cnnString = GetSettingsValuesHistoryDbConnectionString(); if (string.IsNullOrEmpty(cnnString)) { return; } ConfigurationDataSet.SettingDataTable table = ConfigurationDataSet.Current.Setting; string filter = string.Format(CultureInfo.InvariantCulture, "{0} = " + ((int)SettingType.Counter).ToString(), table.SettingTypeIdColumn.ColumnName); SettingCollection counterSettings = new SettingCollection(); foreach (ConfigurationDataSet.SettingRow _srow in table.Select(filter)) { counterSettings.Add(SettingProvider.CreateSetting(_srow)); } filter = string.Format(CultureInfo.InvariantCulture, "{0} > 0", table.PriceColumn.ColumnName); SettingCollection paidSettings = new SettingCollection(); foreach (ConfigurationDataSet.SettingRow _srow in table.Select(filter)) { paidSettings.Add(SettingProvider.CreateSetting(_srow)); } if (counterSettings.Count == 0 && paidSettings.Count == 0) { return; } OrganizationCollection orgs = OrganizationProvider.GetOrganizations(false, false); DataTable dtModifiedSettings = new DataTable(); dtModifiedSettings.Columns.Add(new DataColumn("OrganizationId", typeof(Guid))); dtModifiedSettings.Columns.Add(new DataColumn("InstanceId", typeof(Guid))); dtModifiedSettings.Columns.Add(new DataColumn("SettingId", typeof(Guid))); dtModifiedSettings.Columns.Add(new DataColumn("SettingValue", typeof(string))); Micajah.Common.Bll.Handlers.SettingHandler handler = Micajah.Common.Bll.Handlers.SettingHandler.Current; foreach (Organization org in orgs) { InstanceCollection insts = InstanceProvider.GetInstances(org.OrganizationId, false); if (insts.Count == 0) { continue; } foreach (Instance inst in insts) { DataTable dtLastValues = SelectSettingsLastValues(org.OrganizationId, inst.InstanceId); dtLastValues.PrimaryKey = new DataColumn[] { dtLastValues.Columns["SettingId"] }; foreach (Setting setting in counterSettings) { int settingVal = handler.GetUsedItemsCount(setting, org.OrganizationId, inst.InstanceId); DataRow rowLastVal = dtLastValues.Rows.Find(setting.SettingId); if (rowLastVal == null || rowLastVal["SettingValue"].ToString() != settingVal.ToString()) { DataRow rowNewVal = dtModifiedSettings.NewRow(); rowNewVal["OrganizationId"] = org.OrganizationId; rowNewVal["InstanceId"] = inst.InstanceId; rowNewVal["SettingId"] = setting.SettingId; rowNewVal["SettingValue"] = settingVal.ToString(CultureInfo.InvariantCulture); dtModifiedSettings.Rows.Add(rowNewVal); } } SettingCollection settings = SettingProvider.GetAllPricedSettings(org.OrganizationId, inst.InstanceId); foreach (Setting setting in settings) { string settingVal = string.Empty; if (setting.Paid) { if (string.IsNullOrEmpty(setting.Value)) { settingVal = setting.DefaultValue; } else { settingVal = setting.Value; } } else { settingVal = handler.GetUsedItemsCount(setting, org.OrganizationId, inst.InstanceId).ToString(); } DataRow rowLastVal = dtLastValues.Rows.Find(setting.SettingId); if (rowLastVal == null || rowLastVal["SettingValue"].ToString() != settingVal) { DataRow rowNewVal = dtModifiedSettings.NewRow(); rowNewVal["OrganizationId"] = org.OrganizationId; rowNewVal["InstanceId"] = inst.InstanceId; rowNewVal["SettingId"] = setting.SettingId; rowNewVal["SettingValue"] = settingVal.ToString(CultureInfo.InvariantCulture); dtModifiedSettings.Rows.Add(rowNewVal); } } } } if (dtModifiedSettings.Rows.Count == 0) { return; } using (SqlConnection connection = new SqlConnection(cnnString)) { using (var cmd = GetInsertHistoryRecordCommand(connection)) { SqlParameter pOrgId = cmd.Parameters["@OrganizationId"]; SqlParameter pInstId = cmd.Parameters["@InstanceId"]; SqlParameter pSettingId = cmd.Parameters["@SettingId"]; SqlParameter pSettingValue = cmd.Parameters["@SettingValue"]; cmd.Connection.Open(); foreach (DataRow rowS in dtModifiedSettings.Rows) { pOrgId.Value = rowS["OrganizationId"]; pInstId.Value = rowS["InstanceId"]; pSettingId.Value = rowS["SettingId"]; pSettingValue.Value = rowS["SettingValue"]; cmd.ExecuteNonQuery(); } pOrgId.Value = Guid.Empty; pInstId.Value = Guid.Empty; pSettingId.Value = Guid.Empty; pSettingValue.Value = DBNull.Value; cmd.ExecuteNonQuery(); cmd.Connection.Close(); } } }