Example #1
0
        /*
         * /// <summary>
         * ///
         * /// </summary>
         * /// <param name="throwOverMaxValueError"></param>
         * /// <param name="throwOverMinValueError"></param>
         * /// <param name="userID"></param>
         * /// <param name="points">正数加分 负数减分</param>
         * /// <param name="userPoints"></param>
         * /// <returns></returns>
         * public static bool CheckPoints(bool throwOverMaxValueError, bool throwOverMinValueError, int userID, int[] points, out int[] userPoints)
         * {
         *  return CheckPoints(throwOverMaxValueError, throwOverMinValueError, userID, points, true, out userPoints);
         * }
         * /// <summary>
         * /// 检查积分 上下限
         * /// </summary>
         * /// <param name="userID"></param>
         * /// <param name="points">要更新的积分值  8个</param>
         * /// <param name="isAdd">如果为false 则points就是最终的积分 而不是增加或减少的积分 </param>
         * /// <param name="resultPoints">如果检查成功 则返回用户更新后的积分</param>
         * /// <returns></returns>
         * public static bool CheckPoints(bool throwOverMaxValueError, bool throwOverMinValueError, int userID, int[] points, bool isAdd, out int[] userPoints)
         * {
         *
         *  User user = UserBO.Instance.GetUser(userID);
         *  userPoints = null;
         *  foreach (UserPoint userPoint in AllSettings.Current.PointSettings.UserPoints)
         *  {
         *      int pointID = (int)userPoint.Type;
         *
         *      if (userPoint.Enable)
         *      {
         *          int resultPoint;
         *          if (isAdd)
         *              resultPoint = user.ExtendedPoints[pointID] + points[pointID];
         *          else
         *              resultPoint = points[pointID];
         *          if (points[pointID] > 0)
         *          {
         *
         *              if (resultPoint > userPoint.MaxValue)
         *              {
         *                  if (throwOverMaxValueError)
         *                  {
         *                      Context.ThrowError<UserPointOverMaxValueError>(new UserPointOverMaxValueError("UserPointOverMaxValueError", userPoint.Type, userPoint.MaxValue - user.ExtendedPoints[pointID], user.ExtendedPoints[pointID] + points[pointID], userPoint.MaxValue));
         *                      return false;
         *                  }
         *                  if (isAdd)
         *                  {
         *                      if (user.ExtendedPoints[pointID] > userPoint.MaxValue)//原来已经大于上限  保留原值
         *                          points[pointID] = user.ExtendedPoints[pointID];
         *                      else
         *                          points[pointID] = userPoint.MaxValue;
         *                  }
         *                  else
         *                      points[pointID] = userPoint.MaxValue;
         *              }
         *              else
         *                  points[pointID] = resultPoint;
         *          }
         *          else if (points[pointID] < 0)
         *          {
         *              if (resultPoint < userPoint.MinValue)
         *              {
         *                  if (throwOverMinValueError)
         *                  {
         *                      Context.ThrowError<UserPointOverMinValueError>(new UserPointOverMinValueError("UserPointOverMinValueError", userPoint.Type, user.ExtendedPoints[pointID] - userPoint.MinValue, user.ExtendedPoints[pointID] + points[pointID], userPoint.MinValue));
         *                      return false;
         *                  }
         *                  if (isAdd)
         *                  {
         *                      if (user.ExtendedPoints[pointID] < userPoint.MinValue)//原来已经小于下限  保留原值
         *                          points[pointID] = user.ExtendedPoints[pointID];
         *                      else
         *                          points[pointID] = userPoint.MinValue;
         *                  }
         *                  else
         *                      points[pointID] = userPoint.MinValue;
         *              }
         *              else
         *                  points[pointID] = resultPoint;
         *          }
         *          else
         *          {
         *              if(isAdd)
         *                  points[pointID] = user.ExtendedPoints[pointID];
         *          }
         *      }
         *      else
         *      {
         *          if (isAdd)
         *              points[pointID] = user.ExtendedPoints[pointID];
         *      }
         *  }
         *  userPoints = points;
         *
         *  return true;
         * }
         */

        #region  积分相关设置
        public static bool AddPointExchangeRule(UserPointType pointType, UserPointType targetPointType)
        {
            PointExchangeRule rule = new PointExchangeRule();

            rule.PointType       = pointType;
            rule.TargetPointType = targetPointType;

            if (pointType == targetPointType)
            {
                Context.ThrowError <UserPointCannotExchangeError>(new UserPointCannotExchangeError("UserPointCannotExchangeError", rule.UserPoint.Name, rule.TargetUserPoint.Name));
                return(false);
            }

            if (rule.UserPoint.Enable == false)
            {
                Context.ThrowError <UserPointExchangeUnenabledPointError>(new UserPointExchangeUnenabledPointError("UserPointExchangeUnenabledPointError", rule.UserPoint.Name, rule.TargetUserPoint.Name, rule.UserPoint.Name));
                return(false);
            }

            if (rule.TargetUserPoint.Enable == false)
            {
                Context.ThrowError <UserPointExchangeUnenabledPointError>(new UserPointExchangeUnenabledPointError("UserPointExchangeUnenabledPointError", rule.UserPoint.Name, rule.TargetUserPoint.Name, rule.TargetUserPoint.Name));
                return(false);
            }


            PointExchangeRuleCollection rules = AllSettings.Current.PointSettings.PointExchangeRules;


            PointExchangeRuleCollection tempRules = new PointExchangeRuleCollection();

            foreach (PointExchangeRule tempRule in rules)
            {
                if (rule.Key == tempRule.Key)
                {
                    Context.ThrowError <UserPointIsExistsExchangeRuleError>(new UserPointIsExistsExchangeRuleError("UserPointIsExistsExchangeRuleError", rule.UserPoint.Name, rule.TargetUserPoint.Name));
                    return(false);
                }
                tempRules.Add(tempRule);
            }

            tempRules.Add(rule);

            if (HasUnCatchedError)
            {
                return(false);
            }

            PointSettings setting = SettingManager.CloneSetttings <PointSettings>(AllSettings.Current.PointSettings);

            setting.PointExchangeRules = tempRules;
            if (!SettingManager.SaveSettings(setting))
            {
                return(false);
            }
            //AllSettings.Current.PointSettings = setting;
            return(true);
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="pointType"></param>
        /// <returns></returns>
        protected PointExchangeRuleCollection GetPointExchangeRules(UserPointType pointType)
        {
            PointExchangeRuleCollection rules = new PointExchangeRuleCollection();

            foreach (PointExchangeRule rule in AllSettings.Current.PointSettings.PointExchangeRules)
            {
                if (rule.PointType == pointType)
                {
                    rules.Add(rule);
                }
            }
            return(rules);
        }
Example #3
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);
        }
Example #4
0
        public void PointExchangeRuleList(
            PointExchangeRuleListHeadFootItemTemplate head
            , PointExchangeRuleListHeadFootItemTemplate foot
            , PointExchangeRuleListItemTemplate item
            )
        {
            PointExchangeRuleCollection pointExchangeRules = AllSettings.Current.PointSettings.PointExchangeRules;
            int i          = 0;
            int totalCount = pointExchangeRules.Count;

            head(totalCount > 0, totalCount);
            foreach (PointExchangeRule rule in pointExchangeRules)
            {
                if (rule.UserPoint.Enable == false || rule.TargetUserPoint.Enable == false)
                {
                    continue;
                }

                PointExchangeRuleListParams param = new PointExchangeRuleListParams(rule);
                item(param, i++);
            }
            foot(totalCount > 0, totalCount);
        }
        private void SavePointExchangeRules()
        {
            MessageDisplay msgDisplay = CreateMessageDisplay("taxRate", "minRemaining");

            int[] ids = StringUtil.Split <int>(_Request.Get("ids", Method.Post, string.Empty));
            PointExchangeRuleCollection rules = AllSettings.Current.PointSettings.PointExchangeRules;

            int i = 0;
            PointExchangeRuleCollection tempRules = new PointExchangeRuleCollection();

            foreach (int id in ids)
            {
                string            key  = _Request.Get("key." + id, Method.Post, string.Empty);
                PointExchangeRule rule = (PointExchangeRule)rules.GetRule(key).Clone();
                if (rule == null)
                {
                    continue;
                }

                string valueString = _Request.Get("taxRate." + id, Method.Post, string.Empty);
                int    value;

                if (!int.TryParse(valueString, out value))
                {
                    msgDisplay.AddError("taxRate", i, Lang_Error.User_UserPointExchangeTaxRateFormatError);
                }
                else
                {
                    rule.TaxRate = value;
                }

                valueString = _Request.Get("minRemaining." + id, Method.Post, string.Empty);
                if (!int.TryParse(valueString, out value))
                {
                    msgDisplay.AddError("minRemaining", i, Lang_Error.User_UserPointExchangeRemainingValueFormatError);
                }
                else if (value < rule.UserPoint.MinValue)
                {
                    msgDisplay.AddError("minRemaining", i, Lang_Error.User_UserPointInvalidTradeMaxValueError);
                    rule.MinRemainingValue = value;
                }
                else
                {
                    rule.MinRemainingValue = value;
                }

                tempRules.Add(rule);

                i++;
            }

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

            try
            {
                PointSettings setting = SettingManager.CloneSetttings <PointSettings>(AllSettings.Current.PointSettings);
                setting.PointExchangeRules = tempRules;
                if (!SettingManager.SaveSettings(setting))
                {
                    CatchError <ErrorInfo>(delegate(ErrorInfo error)
                    {
                        msgDisplay.AddError(error.TatgetName, error.TargetLine, error.Message);
                    });
                }
                else
                {
                    AllSettings.Current.PointSettings = setting;
                }
            }
            catch (Exception ex)
            {
                msgDisplay.AddError(ex.Message);
            }
        }
        private void SavePointExchangeRules()
        {
            MessageDisplay msgDisplay = CreateMessageDisplay("taxRate", "minRemaining");

            int[] ids = StringUtil.Split<int>(_Request.Get("ids",Method.Post,string.Empty));
            PointExchangeRuleCollection rules = AllSettings.Current.PointSettings.PointExchangeRules;

            int i = 0;
            PointExchangeRuleCollection tempRules = new PointExchangeRuleCollection();
            foreach(int id in ids)
            {
                string key = _Request.Get("key."+id,Method.Post,string.Empty);
                PointExchangeRule rule = (PointExchangeRule)rules.GetRule(key).Clone();
                if(rule == null)
                    continue;

                string valueString = _Request.Get("taxRate."+id,Method.Post,string.Empty);
                int value;

                if(!int.TryParse(valueString,out value))
                {
                    msgDisplay.AddError("taxRate",i,Lang_Error.User_UserPointExchangeTaxRateFormatError);
                }
                else
                    rule.TaxRate = value;

                valueString = _Request.Get("minRemaining."+id,Method.Post,string.Empty);
                if(!int.TryParse(valueString,out value))
                {
                    msgDisplay.AddError("minRemaining",i,Lang_Error.User_UserPointExchangeRemainingValueFormatError);
                }
                else if (value < rule.UserPoint.MinValue)
                {
                    msgDisplay.AddError("minRemaining", i, Lang_Error.User_UserPointInvalidTradeMaxValueError);
                    rule.MinRemainingValue = value;
                }
                else
                    rule.MinRemainingValue = value;

                tempRules.Add(rule);

                i++;
            }

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

            try
            {
                PointSettings setting = SettingManager.CloneSetttings<PointSettings>(AllSettings.Current.PointSettings);
                setting.PointExchangeRules = tempRules;
                if (!SettingManager.SaveSettings(setting))
                {
                    CatchError<ErrorInfo>(delegate(ErrorInfo error)
                    {
                        msgDisplay.AddError(error.TatgetName, error.TargetLine, error.Message);
                    });
                }
                else
                    AllSettings.Current.PointSettings = setting;
            }
            catch (Exception ex)
            {
                msgDisplay.AddError(ex.Message);
            }
        }
Example #7
0
        public static void ConvertPoints()
        {

            string sql = @"

IF EXISTS (SELECT * FROM sysobjects WHERE [type] = N'U' AND [name] = N'bbsMax_ExtendedPoints') AND EXISTS (SELECT * FROM [sysobjects] WHERE [type]='U' AND [name]='bbsMax_ExtendedPoints') BEGIN
    SELECT * FROM bbsMax_ExtendedPoints;
END
ELSE
    SELECT -9999 AS PointID;

IF EXISTS (SELECT * FROM sysobjects WHERE [type] = N'U' AND [name] = N'System_bbsMax_Settings') AND EXISTS (SELECT * FROM [sysobjects] WHERE [type]='U' AND [name]='System_bbsMax_Settings') BEGIN
    SELECT * FROM System_bbsMax_Settings;
END
ELSE
    SELECT '-9999' AS Catalog;

";
            PointSettings pointSetting = new PointSettings();

            UserPointCollection points = new UserPointCollection();

            Dictionary<int, bool> allowImports = new Dictionary<int, bool>();
            Dictionary<int, bool> allowExports = new Dictionary<int, bool>();
            Dictionary<int, int> ratios = new Dictionary<int, int>();

            int exchangeMinBalance = 0;
            double exchangeTax = 0.2;
            int tradePointID = 0;
            double tradingTax = 0.2;
            int transferMinBalance = 0;
            using (SqlConnection connection = new SqlConnection(Settings.Current.IConnectionString))
            {
                connection.Open();
                SqlCommand command = new SqlCommand(sql, connection);
                command.CommandTimeout = 60;
                try
                {
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            int pointID = reader.GetInt32(reader.GetOrdinal("PointID"));

                            if (pointID == -9999)
                                return;

                            if (pointID > 0 && pointID < 9)
                            {
                                pointID = pointID - 1;

                                if (allowExports.ContainsKey(pointID))
                                    continue;

                                UserPoint userPoint = new UserPoint();

                                allowExports.Add(pointID, reader.GetBoolean(reader.GetOrdinal("AllowExport")));
                                allowImports.Add(pointID, reader.GetBoolean(reader.GetOrdinal("AllowImport")));
                                ratios.Add(pointID, reader.GetInt32(reader.GetOrdinal("Ratio")));

                                userPoint.Type = (MaxLabs.bbsMax.Enums.UserPointType)pointID;
                                userPoint.Name = reader.GetString(reader.GetOrdinal("PointName"));
                                userPoint.UnitName = reader.GetString(reader.GetOrdinal("PointUnit"));
                                userPoint.InitialValue = reader.GetInt32(reader.GetOrdinal("DefaultPoint"));
                                userPoint.Display = reader.GetBoolean(reader.GetOrdinal("IsPublic"));
                                userPoint.Enable = reader.GetBoolean(reader.GetOrdinal("IsEnabled"));
                                userPoint.MaxValue = reader.GetInt32(reader.GetOrdinal("MaxValue"));
                                userPoint.MinValue = reader.GetInt32(reader.GetOrdinal("MinValue"));

                                points.Add(userPoint);
                            }
                        }

                        if (reader.NextResult())
                        {
                            string pointformula = string.Empty;
                            while (reader.Read())
                            {
                                string catalog = reader.GetString(reader.GetOrdinal("Catalog"));
                                if (catalog == "-9999")
                                    break;

                                if (string.Compare(catalog, "PointSetting", true) == 0)
                                {
                                    string key = reader.GetString(reader.GetOrdinal("SettingKey"));
                                    string value = reader.GetString(reader.GetOrdinal("SettingValue"));
                                    try
                                    {
                                        switch (key.ToLower())
                                        {
                                            case "exchangeminbalance": exchangeMinBalance = int.Parse(value); break;
                                            case "exchangetax": exchangeTax = double.Parse(value); break;
                                            case "tradepointid": tradePointID = int.Parse(value) - 1; break;
                                            case "tradingtax": tradingTax = double.Parse(value); break;
                                            case "transferminbalance": transferMinBalance = int.Parse(value); break;
                                            case "pointname": pointSetting.GeneralPointName = value; break;
                                            case "pointformula": pointformula = value; break;
                                            default: break;
                                        }
                                    }
                                    catch { }
                                }
                            }
                            if (string.IsNullOrEmpty(pointformula) == false)
                                pointSetting.GeneralPointExpression = GetGeneralPointExpression(pointformula);

                        }
                    }

                    pointSetting.UserPoints = points;


                    if (allowImports.Count > 0)
                    {
                        //�һ�����
                        PointExchangeProportionCollection ExchangeProportions = new PointExchangeProportionCollection();

                        for (int i = 0; i < 8; i++)
                        {
                            if (ratios.ContainsKey(i))
                            {
                                ExchangeProportions.Add((UserPointType)i, ratios[i] == 0 ? 1 : ratios[i]);
                            }
                            else
                                ExchangeProportions.Add((UserPointType)i, 1);
                        }

                        pointSetting.ExchangeProportions = ExchangeProportions;

                        //�һ�����
                        PointExchangeRuleCollection PointExchangeRules = new PointExchangeRuleCollection();

                        foreach (KeyValuePair<int, bool> pair in allowImports)
                        {
                            if (pair.Value)//�������
                            {
                                foreach (KeyValuePair<int, bool> tempPair in allowExports)
                                {
                                    if (tempPair.Key == pair.Key)
                                        continue;

                                    if (tempPair.Value)//����ҳ�
                                    {
                                        PointExchangeRule rule = new PointExchangeRule();
                                        rule.PointType = (UserPointType)tempPair.Key;
                                        rule.TargetPointType = (UserPointType)pair.Key;
                                        try
                                        {
                                            rule.TaxRate = (int)(exchangeTax * 100);
                                        }
                                        catch { }

                                        PointExchangeRules.Add(rule);
                                    }
                                }
                            }
                        }

                        pointSetting.PointExchangeRules = PointExchangeRules;
                        try
                        {
                            pointSetting.TradeRate = (int)(tradingTax * 100);
                        }
                        catch { }

                        //PointTransferRuleCollection PointTransferRules = new PointTransferRuleCollection();
                        //PointTransferRule tRule = new PointTransferRule();
                        //tRule.CanTransfer = true;
                        //try
                        //{
                        //    tRule.PointType = (UserPointType)tradePointID;
                        //}
                        //catch
                        //{
                        //}
                        //tRule.TaxRate = pointSetting.TradeRate;

                        //PointTransferRules.Add(tRule);
                        //pointSetting.PointTransferRules = PointTransferRules;

                        pointSetting.PointTransferRules = new PointTransferRuleCollection();
                        pointSetting.PointIcons = new PointIconCollection();
                    }

                    sql = @"
UPDATE bx_Settings SET [Value] = @PointString WHERE TypeName = 'MaxLabs.bbsMax.Settings.PointSettings' AND [Key] = '*';
IF @@ROWCOUNT = 0
    INSERT INTO bx_Settings ([Key], [Value], [TypeName]) VALUES ('*', @PointString, 'MaxLabs.bbsMax.Settings.PointSettings');


DROP TABLE bbsMax_ExtendedPoints;
";
                    command.CommandText = sql;

                    SqlParameter param = new SqlParameter("@PointString", SqlDbType.NText);
                    param.Value = pointSetting.ToString();
                    command.Parameters.Add(param);

                    command.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    CreateLog(ex);
                    throw new Exception("������չ��������ʧ��" + ex.Message + sql);
                }
                finally
                {
                    connection.Close();
                }
            }


        }
Example #8
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="pointType"></param>
 /// <returns></returns>
 protected PointExchangeRuleCollection GetPointExchangeRules(UserPointType pointType)
 {
     PointExchangeRuleCollection rules = new PointExchangeRuleCollection();
     foreach (PointExchangeRule rule in AllSettings.Current.PointSettings.PointExchangeRules)
     {
         if (rule.PointType == pointType)
             rules.Add(rule);
     }
     return rules;
 }