Example #1
0
        public PointSettings()
        {
            UserPoints = new UserPointCollection();
            ExchangeProportions = new PointExchangeProportionCollection();

            ExchangeProportions.Add(UserPointType.Point1, 10);
            ExchangeProportions.Add(UserPointType.Point2, 1);
            ExchangeProportions.Add(UserPointType.Point3, 1);
            ExchangeProportions.Add(UserPointType.Point4, 1);
            ExchangeProportions.Add(UserPointType.Point5, 1);
            ExchangeProportions.Add(UserPointType.Point6, 1);
            ExchangeProportions.Add(UserPointType.Point7, 1);
            ExchangeProportions.Add(UserPointType.Point8, 1);

            EnablePointExchange = false;
            
            EnablePointTransfer = false;

            PointRechargeRules = new PointRechargeRuleCollection();

            PointExchangeRules = new PointExchangeRuleCollection();
            PointExchangeRule rule = new PointExchangeRule();
            rule.PointType = UserPointType.Point2;
            rule.TargetPointType = UserPointType.Point1;
            rule.TaxRate = 2;
            PointExchangeRules.Add(rule);

            GeneralPointName = "总积分";
            GeneralPointExpression = "p1+p2*10";
            DisplayGeneralPoint = true;
            TradeRate = 2;

            PointTransferRules = new PointTransferRuleCollection();
            PointTransferRule tRule = new PointTransferRule();
            tRule.CanTransfer = true;
            tRule.PointType = UserPointType.Point1;
            tRule.TaxRate = 2;
            PointTransferRules.Add(tRule);

            PointIcons = new PointIconCollection();
            PointIcon icon = new PointIcon();
            icon.IconCount = 4;
            icon.IconsString = "fortune_3.gif|fortune_2.gif|fortune_1.gif";
            icon.PointType = UserPointType.Point1;
            icon.PointValue = 1000;
            PointIcons.Add(icon);
        }
        private void Save()
        {
            MessageDisplay msgDisplay = CreateMessageDisplay("money", "point", "minvalue");
            PointRechargeRuleCollection rules = new PointRechargeRuleCollection();
            int i = 0;
            foreach (UserPoint point in AllSettings.Current.PointSettings.EnabledUserPoints)
            {
                int pointID = (int)point.Type;
                PointRechargeRule rule = new PointRechargeRule();
                rule.UserPointType = point.Type;
                rule.Enable = _Request.IsChecked("canRecharge." + pointID, Method.Post, false);
                rule.Money = _Request.Get<int>("money." + pointID, Method.Post, 0);
                rule.Point = _Request.Get<int>("point." + pointID, Method.Post, 0);
                rule.MinValue = _Request.Get<int>("minvalue." + pointID, Method.Post, 0);

                if (rule.Enable)
                {
                    if (rule.Money < 1)
                    {
                        msgDisplay.AddError("money", i, "人民币必须为大于0的整数");
                    }

                    if (rule.Point < 1)
                    {
                        msgDisplay.AddError("point", i, "积分数量必须为大于0的整数");
                    }

                    if (rule.Point < 1)
                    {
                        msgDisplay.AddError("minvalue", i, "一次至少需要充值的积分数量必须大于0");
                    }
                }
                rules.Add(rule);
                i++;
            }

            if (msgDisplay.HasAnyError())
                return;


            PointSettings pointSetting = SettingManager.CloneSetttings<PointSettings>(PointSettings);
            PaySettings paySettings = SettingManager.CloneSetttings<PaySettings>(PaySettings);


            pointSetting.PointRechargeRules = rules;
            paySettings.EnablePointRecharge = _Request.Get<bool>("enable", Method.Post, false);
            if (paySettings.EnablePointRecharge)
            {
                paySettings.ProductName = _Request.Get("ProductName", Method.Post, string.Empty);
                paySettings.EnableAlipay = _Request.Get<bool>("enableAlipay", Method.Post, false);
                paySettings.EnableTenpay = _Request.Get<bool>("EnableTenpay", Method.Post, false);
                paySettings.Enable99Bill = _Request.Get<bool>("Enable99Bill", Method.Post, false);

                if (paySettings.EnableAlipay)
                {
                    paySettings.Alipay_SellerEmail = _Request.Get("Alipay_SellerEmail", Method.Post, string.Empty);
                    paySettings.Alipay_PartnerID = _Request.Get("Alipay_PartnerID", Method.Post, string.Empty);
                    paySettings.Alipay_Key = _Request.Get("Alipay_Key", Method.Post, string.Empty);
                }

                if (paySettings.EnableTenpay)
                {
                    paySettings.Tenpay_BargainorID = _Request.Get("Tenpay_BargainorID", Method.Post, string.Empty);
                    paySettings.Tenpay_Key = _Request.Get("Tenpay_Key", Method.Post, string.Empty);
                }

                if (paySettings.Enable99Bill)
                {
                    paySettings._99Bill_MerchantAcctID = _Request.Get("_99Bill_MerchantAcctID", Method.Post, string.Empty);
                    paySettings._99Bill_Key = _Request.Get("_99Bill_Key", Method.Post, string.Empty);
                }
            }
            else
            {
                paySettings.EnableAlipay = false;
                paySettings.EnableTenpay = false;
                paySettings.Enable99Bill = false;
            }

            if (paySettings.EnablePointRecharge)
            {
                foreach (PointRechargeRule rule in rules)
                {
                    if (rule.Enable)
                    {
                        pointSetting.UserPoints.GetUserPoint(rule.UserPointType).MaxValue = int.MaxValue;
                    }
                }
            }

            try
            {
                SettingManager.SaveSettings(pointSetting);
                SettingManager.SaveSettings(paySettings);

                PostBOV5.Instance.ClearShowChargePointLinks();
            }
            catch (Exception ex)
            {
                msgDisplay.AddError(ex.Message);
            }
        }
        private void Save()
        {
            MessageDisplay msgDisplay         = CreateMessageDisplay("money", "point", "minvalue");
            PointRechargeRuleCollection rules = new PointRechargeRuleCollection();
            int i = 0;

            foreach (UserPoint point in AllSettings.Current.PointSettings.EnabledUserPoints)
            {
                int pointID            = (int)point.Type;
                PointRechargeRule rule = new PointRechargeRule();
                rule.UserPointType = point.Type;
                rule.Enable        = _Request.IsChecked("canRecharge." + pointID, Method.Post, false);
                rule.Money         = _Request.Get <int>("money." + pointID, Method.Post, 0);
                rule.Point         = _Request.Get <int>("point." + pointID, Method.Post, 0);
                rule.MinValue      = _Request.Get <int>("minvalue." + pointID, Method.Post, 0);

                if (rule.Enable)
                {
                    if (rule.Money < 1)
                    {
                        msgDisplay.AddError("money", i, "人民币必须为大于0的整数");
                    }

                    if (rule.Point < 1)
                    {
                        msgDisplay.AddError("point", i, "积分数量必须为大于0的整数");
                    }

                    if (rule.Point < 1)
                    {
                        msgDisplay.AddError("minvalue", i, "一次至少需要充值的积分数量必须大于0");
                    }
                }
                rules.Add(rule);
                i++;
            }

            if (msgDisplay.HasAnyError())
            {
                return;
            }


            PointSettings pointSetting = SettingManager.CloneSetttings <PointSettings>(PointSettings);
            PaySettings   paySettings  = SettingManager.CloneSetttings <PaySettings>(PaySettings);


            pointSetting.PointRechargeRules = rules;
            paySettings.EnablePointRecharge = _Request.Get <bool>("enable", Method.Post, false);
            if (paySettings.EnablePointRecharge)
            {
                paySettings.ProductName  = _Request.Get("ProductName", Method.Post, string.Empty);
                paySettings.EnableAlipay = _Request.Get <bool>("enableAlipay", Method.Post, false);
                paySettings.EnableTenpay = _Request.Get <bool>("EnableTenpay", Method.Post, false);
                paySettings.Enable99Bill = _Request.Get <bool>("Enable99Bill", Method.Post, false);

                if (paySettings.EnableAlipay)
                {
                    paySettings.Alipay_SellerEmail = _Request.Get("Alipay_SellerEmail", Method.Post, string.Empty);
                    paySettings.Alipay_PartnerID   = _Request.Get("Alipay_PartnerID", Method.Post, string.Empty);
                    paySettings.Alipay_Key         = _Request.Get("Alipay_Key", Method.Post, string.Empty);
                }

                if (paySettings.EnableTenpay)
                {
                    paySettings.Tenpay_BargainorID = _Request.Get("Tenpay_BargainorID", Method.Post, string.Empty);
                    paySettings.Tenpay_Key         = _Request.Get("Tenpay_Key", Method.Post, string.Empty);
                }

                if (paySettings.Enable99Bill)
                {
                    paySettings._99Bill_MerchantAcctID = _Request.Get("_99Bill_MerchantAcctID", Method.Post, string.Empty);
                    paySettings._99Bill_Key            = _Request.Get("_99Bill_Key", Method.Post, string.Empty);
                }
            }
            else
            {
                paySettings.EnableAlipay = false;
                paySettings.EnableTenpay = false;
                paySettings.Enable99Bill = false;
            }

            if (paySettings.EnablePointRecharge)
            {
                foreach (PointRechargeRule rule in rules)
                {
                    if (rule.Enable)
                    {
                        pointSetting.UserPoints.GetUserPoint(rule.UserPointType).MaxValue = int.MaxValue;
                    }
                }
            }

            try
            {
                SettingManager.SaveSettings(pointSetting);
                SettingManager.SaveSettings(paySettings);

                PostBOV5.Instance.ClearShowChargePointLinks();
            }
            catch (Exception ex)
            {
                msgDisplay.AddError(ex.Message);
            }
        }