Esempio n. 1
0
        public static SettingCollection GetCalculatedAllCounterSettings(Guid OrgId, Guid InstId)
        {
            string cnnString = GetSettingsValuesHistoryDbConnectionString();

            ConfigurationDataSet.SettingDataTable table = ConfigurationDataSet.Current.Setting;
            string            filter          = string.Format(CultureInfo.InvariantCulture, "{0} = " + ((int)SettingType.Counter).ToString(), table.SettingTypeIdColumn.ColumnName);
            SettingCollection counterSettings = new SettingCollection();

            Micajah.Common.Bll.Handlers.SettingHandler handler = Micajah.Common.Bll.Handlers.SettingHandler.Current;
            DataTable dtLastValues = null;

            if (!string.IsNullOrEmpty(cnnString))
            {
                dtLastValues = SelectSettingsLastValues(OrgId, InstId);
            }
            if (dtLastValues == null || dtLastValues.Rows.Count == 0)
            {
                foreach (ConfigurationDataSet.SettingRow _srow in table.Select(filter))
                {
                    Setting s = SettingProvider.CreateSetting(_srow);
                    s.Value = handler.GetUsedItemsCount(s, OrgId, InstId).ToString(CultureInfo.InvariantCulture);
                    counterSettings.Add(s);
                }

                filter = string.Format(CultureInfo.InvariantCulture, "{0} > 0", table.PriceColumn.ColumnName);

                foreach (ConfigurationDataSet.SettingRow _srow in table.Select(filter))
                {
                    Setting s = SettingProvider.CreateSetting(_srow);
                    s.Value = handler.GetUsedItemsCount(s, OrgId, InstId).ToString(CultureInfo.InvariantCulture);
                    counterSettings.Add(s);
                }

                return(counterSettings);
            }

            dtLastValues.PrimaryKey = new DataColumn[] { dtLastValues.Columns["SettingId"] };

            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
                {
                    s.Value = handler.GetUsedItemsCount(s, OrgId, InstId).ToString(CultureInfo.InvariantCulture);
                }
                counterSettings.Add(s);
            }

            filter = string.Format(CultureInfo.InvariantCulture, "{0} > 0", table.PriceColumn.ColumnName);

            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
                {
                    s.Value = handler.GetUsedItemsCount(s, OrgId, InstId).ToString(CultureInfo.InvariantCulture);
                }
                counterSettings.Add(s);
            }

            return(counterSettings);
        }