コード例 #1
0
        private void InitBillingControls()
        {
            DateTime?_expDate = UserContext.Current.Organization.ExpirationTime;

            ISubscription _custSubscr = ChargifyProvider.GetCustomerSubscription(Chargify, OrganizationId, InstanceId);

            if (_custSubscr != null && _custSubscr.CreditCard != null)
            {
                _expDate = _custSubscr.CurrentPeriodEndsAt;
                if (!IsPostBack)
                {
                    SettingCollection paidSettings = SettingProvider.GetAllPricedSettings(OrganizationId, InstanceId);
                    ChargifyProvider.UpdateSubscriptionAllocations(Chargify, _custSubscr.SubscriptionID, UserContext.Current.Instance, paidSettings, paidSettings);
                }
                TotalAmount    = m_TotalSum;
                SubscriptionId = _custSubscr.SubscriptionID;
                lCCStatus.Text = "Credit Card Registered and " + _custSubscr.State.ToString() + ".";
                TimeSpan _dateDiff = (TimeSpan)(_expDate - DateTime.UtcNow);
                if (_expDate.HasValue)
                {
                    smallNextBillDate.Visible   = true;
                    smallNextBillDate.InnerText = "Next billed on " + _expDate.Value.ToString("dd-MMM-yyyy");
                }
            }
            else
            {
                lCCStatus.Text = "No Credit Card on File.";
                if (!IsPostBack)
                {
                    DisablePurchaseButtons();
                }
            }
            if (_custSubscr != null && _custSubscr.CreditCard != null)
            {
                System.Collections.Generic.List <TransactionType> transTypes = new List <TransactionType>();
                transTypes.Add(TransactionType.Payment);
                System.Collections.Generic.IDictionary <int, ITransaction> trans = Chargify.GetTransactionsForSubscription(_custSubscr.SubscriptionID, 1, 25, transTypes);
                if (trans != null && trans.Count > 0)
                {
                    divPaymentHistoryHeader.Visible = true;
                    cgvTransactList.Visible         = true;
                    cgvTransactList.DataSource      = trans.Values;
                    cgvTransactList.DataBind();
                }
            }
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        protected override void EditForm_ItemUpdated(object sender, DetailsViewUpdatedEventArgs e)
        {
            base.EditForm_ItemUpdated(sender, e);

            if (e == null)
            {
                return;
            }

            if (e.Exception != null)
            {
                return;
            }

            if (m_UserContext.IsFrameworkAdministrator)
            {
                ComboBox cmb = EditForm.FindControl("cmbBillingPlan") as ComboBox;
                int      val = 0;
                if (cmb != null && int.TryParse(cmb.SelectedValue, out val))
                {
                    Guid     instId = (Guid)EditForm.DataKey[0];
                    Instance inst   = m_UserContext.Instance;
                    if (inst == null || inst.InstanceId != instId)
                    {
                        inst = InstanceProvider.GetInstance(instId);
                    }
                    if (inst.BillingPlan != BillingPlan.Custom && val == 1)
                    {
                        InstanceProvider.UpdateInstance(inst, BillingPlan.Custom);
                    }
                    else if (inst.BillingPlan == BillingPlan.Custom && val == 0)
                    {
                        ChargifyNET.ChargifyConnect _chargify   = ChargifyProvider.CreateChargify();
                        ChargifyNET.ISubscription   _custSubscr = ChargifyProvider.GetCustomerSubscription(_chargify, inst.OrganizationId, inst.InstanceId);
                        SettingCollection           settings    = SettingProvider.GetAllPricedSettings(inst.OrganizationId, inst.InstanceId);
                        ChargifyProvider.UpdateSubscriptionAllocations(_chargify, _custSubscr != null ? _custSubscr.SubscriptionID : 0, inst, settings, settings);
                    }
                }
            }

            this.Redirect();
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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();
                }
            }
        }