示例#1
0
        protected UserMedal GetUserMedal(User user)
        {
            UserMedal userMedal = null;

            foreach (UserMedal medal in user.UserMedals)
            {
                if (medal.MedalID == Medal.ID)
                {
                    userMedal = medal;
                }
            }
            if (userMedal == null)
            {
                MedalLevel level = Medal.GetMedalLevel(user, true);
                if (level != null)
                {
                    userMedal             = new UserMedal();
                    userMedal.MedalID     = Medal.ID;
                    userMedal.MedalLeveID = level.ID;
                    userMedal.Url         = level.IconSrc;
                    userMedal.UserID      = user.UserID;
                }
            }

            return(userMedal);
        }
示例#2
0
 protected string GetMedalLevelName(User user)
 {
     if (MedalLevelID == null)
     {
         MedalLevel level = Medal.GetMedalLevel(user, false);
         if (level == null)
         {
             return("--");
         }
         return(level.Name);
     }
     else if (MedalLevel != null)
     {
         return(MedalLevel.Name);
     }
     else
     {
         return("--");
     }
 }
示例#3
0
        /// <summary>
        /// 是否是自动获取的
        /// </summary>
        /// <param name="userMedal"></param>
        /// <returns></returns>
        protected bool IsAutoGet(UserMedal userMedal)
        {
            Medal medal = GetMedal(userMedal.MedalID);

            if (medal.IsCustom)
            {
                return(false);
            }

            bool isAuto;

            if (isAutoGets.TryGetValue(userMedal.MedalID, out isAuto))
            {
                return(isAuto);
            }

            MedalLevel level = medal.GetMedalLevel(user, true);

            if (level == null)
            {
                isAuto = false;
            }
            else
            {
                if (medal.GetMedalLevel(user, false).Value > level.Value)
                {
                    isAuto = false;
                }
                else
                {
                    isAuto = true;
                }
            }

            isAutoGets.Add(userMedal.MedalID, isAuto);

            return(isAuto);
        }
示例#4
0
        protected string GetMedalName(UserMedal userMedal)
        {
            Medal      medal      = GetMedal(userMedal.MedalID);
            MedalLevel medalLevel = null;

            foreach (MedalLevel level in medal.Levels)
            {
                if (level.ID == userMedal.MedalLeveID)
                {
                    medalLevel = level;
                    break;
                }
            }

            if (medalLevel != null && string.IsNullOrEmpty(medalLevel.Name) == false)
            {
                return(string.Concat(medal.Name, " - ", medalLevel.Name));
            }
            else
            {
                return(medal.Name);
            }
        }
示例#5
0
        protected string GetMedals(string urlFormat, string imgFormat, bool isHave)
        {
            StringBuilder imgs = new StringBuilder();

            if (isHave)
            {
                foreach (Medal medal in AllSettings.Current.MedalSettings.Medals)
                {
                    MedalLevel medalLevel = medal.GetMedalLevel(My);
                    if (medalLevel != null)
                    {
                        MedalLevel nextLevel = null;
                        int        i         = 0;
                        foreach (MedalLevel level in medal.Levels)
                        {
                            if (level.ID == medalLevel.ID)
                            {
                                if (medal.Levels.Count > i + 1)
                                {
                                    nextLevel = medal.Levels[i + 1];
                                }
                            }
                            i++;
                        }

                        string title;
                        if (medalLevel.Name != string.Empty)
                        {
                            title = medal.Name + "(" + medalLevel.Name + ")";
                        }
                        else
                        {
                            title = medal.Name;
                        }

                        if (nextLevel != null)
                        {
                            if (medal.IsCustom)
                            {
                                title = title + ";点亮下一级图标条件:" + nextLevel.Condition;
                            }
                            else
                            {
                                title = title + ";点亮下一级图标条件:" + GetConditionName(medal.Condition) + "达到" + nextLevel.Value;
                            }
                        }


                        UserMedal userMedal = My.UserMedals.GetValue(medal.ID, medalLevel.ID);
                        if (userMedal != null && string.IsNullOrEmpty(userMedal.ShowUrl) == false)
                        {
                            string url = userMedal.ShowUrl;
                            if (string.IsNullOrEmpty(userMedal.UrlTitle) == false)
                            {
                                title = userMedal.UrlTitle;
                            }

                            imgs.Append(string.Format(urlFormat, url, string.Format(imgFormat, medalLevel.LogoUrl, title)));
                        }
                        else
                        {
                            imgs.Append(string.Format(imgFormat, medalLevel.LogoUrl, title));
                        }
                    }
                }
            }
            else
            {
                foreach (Medal medal in AllSettings.Current.MedalSettings.Medals)
                {
                    if (medal.IsHidden)
                    {
                        continue;
                    }

                    MedalLevel medalLevel = medal.GetMedalLevel(My);
                    if (medalLevel == null)
                    {
                        if (medal.Levels.Count == 0)
                        {
                            continue;
                        }
                        medalLevel = medal.Levels[0];

                        string title;

                        if (medalLevel.Name != string.Empty)
                        {
                            title = medal.Name + "(" + medalLevel.Name + ")";
                        }
                        else
                        {
                            title = medal.Name;
                        }

                        if (medal.IsCustom)
                        {
                            title = title + ";点亮该图标条件:" + medalLevel.Condition;
                        }
                        else
                        {
                            title = title + ";点亮该图标条件:" + GetConditionName(medal.Condition) + "达到" + medalLevel.Value;
                        }

                        imgs.Append(string.Format(imgFormat, medalLevel.LogoUrl, title));
                    }
                }
            }

            return(imgs.ToString());
        }
        private void SaveSetting()
        {
            MessageDisplay msgDisplay = CreateMessageDisplay("medalname", "sortorder", "medallevel");

            Medal medal = new Medal();

            if (IsEdit)
            {
                medal.ID = MedalID;
            }
            else
            {
                medal.ID = AllSettings.Current.MedalSettings.MaxMedalID + 1;
            }

            medal.Name = _Request.Get("medalname", Method.Post, string.Empty);

            if (medal.Name == string.Empty)
            {
                msgDisplay.AddError("medalname", "图标名称不能为空");
            }

            medal.SortOrder = _Request.Get <int>("sortorder", Method.Post, 0);
            medal.Enable    = _Request.Get <bool>("enable", Method.Post, false);
            medal.IsHidden  = _Request.Get <bool>("IsHidden", Method.Post, false);

            medal.IsCustom = _Request.Get <bool>("isAuto", Method.Post, false) == false;
            if (medal.IsCustom)
            {
                medal.Condition = string.Empty;
            }
            else
            {
                medal.Condition = _Request.Get("condition", Method.Post, string.Empty);
            }

            m_MedalCondition = medal.Condition;

            bool hasMedallevelError = false;

            if (medal.Condition == string.Empty && medal.IsCustom == false)
            {
                msgDisplay.AddError("medallevel", "请选择规则");
                hasMedallevelError = true;
            }

            medal.Levels = new MedalLevelCollection();

            int[] ids = _Request.GetList <int>("ids", Method.Post, new int[0] {
            });

            if (IsEdit)
            {
                medal.MaxLevelID = Medal.MaxLevelID;
            }

            List <int> values = new List <int>();

            m_MedalLevels = new MedalLevelCollection();
            foreach (int id in ids)
            {
                MedalLevel level = new MedalLevel();

                if (IsEdit)
                {
                    foreach (MedalLevel tempMedalLevel in Medal.Levels)
                    {
                        if (id == tempMedalLevel.ID)
                        {
                            level.ID = id;
                            break;
                        }
                    }
                }
                if (level.ID == 0)
                {
                    medal.MaxLevelID = medal.MaxLevelID + 1;
                    level.ID         = medal.MaxLevelID;
                }

                if (_Request.Get("levelName_" + id, Method.Post) == null)
                {
                    continue;
                }

                level.Name    = _Request.Get("levelName_" + id, Method.Post, string.Empty).Trim();
                level.IconSrc = _Request.Get("IconSrc_" + id, Method.Post, string.Empty).Trim();

                if (medal.IsCustom)
                {
                    level.Condition = _Request.Get("conditionDescription_" + id, Method.Post, string.Empty).Trim();
                }
                else
                {
                    level.Condition = string.Empty;
                    level.Value     = _Request.Get <int>("levelValue_" + id, Method.Post, 0);
                }

                if (hasMedallevelError == false)
                {
                    //if (level.Name == string.Empty)
                    //{
                    //    msgDisplay.AddError("medallevel", "等级名称不能为空");
                    //}
                    if (level.IconSrc == string.Empty)
                    {
                        msgDisplay.AddError("medallevel", "等级图标不能为空");
                    }
                    //else if (medal.IsCustom && level.Condition == string.Empty)
                    //{
                    //    msgDisplay.AddError("medallevel", "点亮图标说明不能为空");
                    //}
                    else if (medal.IsCustom == false && values.Contains(level.Value))
                    {
                        msgDisplay.AddError("medallevel", "点亮图标需达到的值不能相同");
                    }
                }
                if (medal.IsCustom == false)
                {
                    values.Add(level.Value);
                }

                medal.Levels.Add(level, medal.IsCustom == false);
                m_MedalLevels.Add(level, false);
            }

            m_IsCustom = medal.IsCustom;

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

            MedalSettings medalSetting = new MedalSettings();

            medalSetting.Medals = new MedalCollection();
            foreach (Medal tempMedal in AllSettings.Current.MedalSettings.Medals)
            {
                if (IsEdit && medal.ID == tempMedal.ID)
                {
                    medalSetting.Medals.Add(medal);
                }
                else
                {
                    medalSetting.Medals.Add(tempMedal);
                }
            }

            if (IsEdit)
            {
                medalSetting.MaxMedalID = AllSettings.Current.MedalSettings.MaxMedalID;
            }
            else
            {
                medalSetting.Medals.Add(medal);
                medalSetting.MaxMedalID = medal.ID;
            }

            bool success = false;

            try
            {
                using (new ErrorScope())
                {
                    if (SettingManager.SaveSettings(medalSetting) == false)
                    {
                        CatchError <ErrorInfo>(delegate(ErrorInfo error)
                        {
                            msgDisplay.AddError(error);
                        });
                    }
                    else
                    {
                        if (IsEdit)
                        {
                            UserBO.Instance.RemoveAllUserCache();
                        }
                        success = true;
                    }
                }
            }
            catch (Exception ex)
            {
                msgDisplay.AddError(ex.Message);
            }

            if (success)
            {
                JumpTo("interactive/setting-medals.aspx");
            }
        }
示例#7
0
        public static void ConvertMedals()
        {

            MedalSettings medalSetting = new MedalSettings();
            MedalCollection medals = new MedalCollection();

            string sql = @"
IF EXISTS(SELECT * FROM sysobjects WHERE [type]=N'TR' AND [name]=N'bx_UserMedals_AfterUpdate')
	DROP TRIGGER bx_UserMedals_AfterUpdate;

--GO
";
            using (SqlConnection connection = new SqlConnection(Settings.Current.IConnectionString))
            {
                connection.Open();
                SqlCommand command = new SqlCommand(sql, connection);
                command.CommandTimeout = 60;
                try
                {
                    command.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    CreateLog(ex);
                    throw new Exception("ɾ��������bx_UserMedals_AfterUpdateʧ��" + ex.Message + sql);
                }
                finally
                {
                    connection.Close();
                }
            }



            sql = @"

IF EXISTS (SELECT * FROM sysobjects WHERE [type] = N'U' AND [name] = N'Max_Medals') AND EXISTS (SELECT * FROM [sysobjects] WHERE [type]='U' AND [name]='Max_UserMedals') BEGIN
    SELECT * FROM Max_Medals;
END
ELSE
    SELECT -9999 AS MedalID;
";
            using (SqlConnection connection = new SqlConnection(Settings.Current.IConnectionString))
            {
                connection.Open();
                SqlCommand command = new SqlCommand(sql, connection);
                command.CommandTimeout = 60;
                try
                {
                    bool hasCreateErrorLog = false;
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            int medalID = reader.GetInt32(reader.GetOrdinal("MedalID"));

                            if (medalID == -9999)
                                return;

                            Medal tempMedal = new Medal();
                            tempMedal.Condition = string.Empty;
                            tempMedal.Enable = reader.GetBoolean(reader.GetOrdinal("IsEnabled"));
                            tempMedal.IsCustom = true;
                            tempMedal.ID = medalID;
                            tempMedal.MaxLevelID = 1;
                            tempMedal.Name = reader.GetString(reader.GetOrdinal("MedalName"));
                            tempMedal.SortOrder = 0;

                            tempMedal.Levels = new MedalLevelCollection();
                            MedalLevel tempLevel = new MedalLevel();
                            tempLevel.Condition = string.Empty;

                            string iconUrl = reader.GetString(reader.GetOrdinal("LogoUrl")).Replace("\\", "/");

                            int i = iconUrl.LastIndexOf("/") + 1;

                            string iconName = string.Empty;
                            if (iconUrl.Length > i)
                                iconName = iconUrl.Substring(i, iconUrl.Length - i);
                            else
                                continue;

                            string targetDir = MaxLabs.bbsMax.UrlUtil.JoinUrl(MaxLabs.bbsMax.Globals.ApplicationPath, "/max-assets/icon-medal/");
                            string targetIconUrl = targetDir + iconName;

                            iconUrl = MaxLabs.bbsMax.UrlUtil.JoinUrl(MaxLabs.bbsMax.Globals.ApplicationPath, iconUrl);
                            if (File.Exists(iconUrl))
                            {
                                if (File.Exists(targetIconUrl))
                                {
                                }
                                else
                                {
                                    try
                                    {
                                        if (Directory.Exists(targetDir) == false)
                                            Directory.CreateDirectory(targetDir);
                                        File.Move(iconUrl, targetIconUrl);
                                    }
                                    catch
                                    {
                                        if (hasCreateErrorLog == false)
                                        {
                                            hasCreateErrorLog = true;
                                            ErrorMessages.Add("�ƶ�ѫ��ͼ��ʧ��,���ֶ��ѡ�/Images/Medals/��Ŀ¼�µ�����ͼ�긴�Ƶ���/max-assets/icon-medal/��Ŀ¼��");
                                        }
                                    }
                                }
                            }

                            tempLevel.IconSrc = "~/max-assets/icon-medal/" + iconName;

                            tempLevel.Name = string.Empty;
                            tempLevel.ID = 1;
                            tempMedal.Levels.Add(tempLevel);

                            medals.Add(tempMedal);

                            if (medalSetting.MaxMedalID < tempMedal.ID)
                                medalSetting.MaxMedalID = tempMedal.ID;
                        }
                    }

                    foreach (Medal medal in new MedalSettings().Medals)
                    {
                        medal.ID = medalSetting.MaxMedalID + 1;
                        medals.Add(medal);
                        medalSetting.MaxMedalID += 1;
                    }

                    medalSetting.Medals = medals;


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

IF EXISTS (SELECT * FROM [sysobjects] WHERE [type]='U' AND [name]='Max_UserMedals') BEGIN
	truncate table [bx_UserMedals];
	INSERT INTO [bx_UserMedals]
           ([UserID]
           ,[MedalID]
           ,[MedalLevelID]
           ,[EndDate]
           ,[CreateDate])
     SELECT 
           UserID
           ,MedalID
           ,1
           ,ExpiresDate
           ,CreateDate
		FROM Max_UserMedals WITH (NOLOCK);

	DROP TABLE Max_UserMedals;
END

DROP TABLE Max_Medals;
";

                    command.CommandText = sql;
                    command.CommandTimeout = 3600;
                    //command.Parameters.AddWithValue("@MedalString", medalSetting.ToString());


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

                    command.ExecuteNonQuery();
                    //AllSettings.Current.MedalSettings = medalSetting;

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


            }
        }
        private void SaveSetting()
        {
            MessageDisplay msgDisplay = CreateMessageDisplay("medalname", "sortorder", "medallevel");

            Medal medal = new Medal();

            if (IsEdit)
            {
                medal.ID = MedalID;
            }
            else
            {
                medal.ID = AllSettings.Current.MedalSettings.MaxMedalID + 1;
            }

            medal.Name = _Request.Get("medalname", Method.Post, string.Empty);

            if (medal.Name == string.Empty)
                msgDisplay.AddError("medalname", "图标名称不能为空");

            medal.SortOrder = _Request.Get<int>("sortorder", Method.Post, 0);
            medal.Enable = _Request.Get<bool>("enable", Method.Post, false);
            medal.IsHidden = _Request.Get<bool>("IsHidden", Method.Post, false);

            medal.IsCustom = _Request.Get<bool>("isAuto", Method.Post, false) == false;
            if (medal.IsCustom)
                medal.Condition = string.Empty;
            else
                medal.Condition = _Request.Get("condition", Method.Post, string.Empty);

            m_MedalCondition = medal.Condition;

            bool hasMedallevelError = false;
            if (medal.Condition == string.Empty && medal.IsCustom == false)
            {
                msgDisplay.AddError("medallevel", "请选择规则");
                hasMedallevelError = true;
            }

            medal.Levels = new MedalLevelCollection();

            int[] ids = _Request.GetList<int>("ids", Method.Post, new int[0] { });

            if (IsEdit)
                medal.MaxLevelID = Medal.MaxLevelID;

            List<int> values = new List<int>();

            m_MedalLevels = new MedalLevelCollection();
            foreach (int id in ids)
            {
                MedalLevel level = new MedalLevel();

                if (IsEdit)
                {
                    foreach (MedalLevel tempMedalLevel in Medal.Levels)
                    {
                        if (id == tempMedalLevel.ID)
                        {
                            level.ID = id;
                            break;
                        }
                    }
                }
                if (level.ID == 0)
                {
                    medal.MaxLevelID = medal.MaxLevelID + 1;
                    level.ID = medal.MaxLevelID;
                }

                if (_Request.Get("levelName_" + id, Method.Post) == null)
                    continue;

                level.Name = _Request.Get("levelName_" + id, Method.Post, string.Empty).Trim();
                level.IconSrc = _Request.Get("IconSrc_" + id, Method.Post, string.Empty).Trim();

                if (medal.IsCustom)
                    level.Condition = _Request.Get("conditionDescription_" + id, Method.Post, string.Empty).Trim();
                else
                {
                    level.Condition = string.Empty;
                    level.Value = _Request.Get<int>("levelValue_" + id, Method.Post, 0);
                }

                if (hasMedallevelError == false)
                {
                    //if (level.Name == string.Empty)
                    //{
                    //    msgDisplay.AddError("medallevel", "等级名称不能为空");
                    //}
                    if (level.IconSrc == string.Empty)
                    {
                        msgDisplay.AddError("medallevel", "等级图标不能为空");
                    }
                    //else if (medal.IsCustom && level.Condition == string.Empty)
                    //{
                    //    msgDisplay.AddError("medallevel", "点亮图标说明不能为空");
                    //}
                    else if (medal.IsCustom == false && values.Contains(level.Value))
                    {
                        msgDisplay.AddError("medallevel", "点亮图标需达到的值不能相同");
                    }
                }
                if (medal.IsCustom == false)
                    values.Add(level.Value);

                medal.Levels.Add(level,medal.IsCustom == false);
                m_MedalLevels.Add(level, false);
            }

            m_IsCustom = medal.IsCustom;

            if (msgDisplay.HasAnyError())
                return;

            MedalSettings medalSetting = new MedalSettings();

            medalSetting.Medals = new MedalCollection();
            foreach (Medal tempMedal in AllSettings.Current.MedalSettings.Medals)
            {
                if (IsEdit && medal.ID == tempMedal.ID)
                {
                    medalSetting.Medals.Add(medal);
                }
                else
                    medalSetting.Medals.Add(tempMedal);
            }

            if (IsEdit)
                medalSetting.MaxMedalID = AllSettings.Current.MedalSettings.MaxMedalID;
            else
            {
                medalSetting.Medals.Add(medal);
                medalSetting.MaxMedalID = medal.ID;
            }

            bool success = false;
            try
            {
                using (new ErrorScope())
                {

                    if (SettingManager.SaveSettings(medalSetting) == false)
                    {
                        CatchError<ErrorInfo>(delegate(ErrorInfo error)
                        {
                            msgDisplay.AddError(error);
                        });
                    }
                    else
                    {
                        if(IsEdit)
                            UserBO.Instance.RemoveAllUserCache();
                        success = true;
                    }
                }
            }
            catch (Exception ex)
            {
                msgDisplay.AddError(ex.Message);
            }

            if (success)
                JumpTo("interactive/setting-medals.aspx");
        }
示例#9
0
        private void SaveSetting()
        {
            MessageDisplay msgDisplay = CreateMessageDisplay("name", "levelname", "iconsrc", "condition");

            MedalCollection medals = new MedalCollection();

            int i = 0;

            foreach (Medal medal in MedalList)
            {
                Medal tempMedal = new Medal();
                tempMedal.SortOrder = _Request.Get <int>("sortorder_" + medal.ID, Method.Post, 0);
                tempMedal.Name      = _Request.Get("name_" + medal.ID, Method.Post, string.Empty).Trim();

                if (tempMedal.Name == string.Empty)
                {
                    msgDisplay.AddError("name", i, "勋章名称不能为空");
                }

                tempMedal.Enable   = _Request.Get <bool>("enable_" + medal.ID, Method.Post, false);
                tempMedal.IsHidden = _Request.Get <bool>("isHidden_" + medal.ID, Method.Post, false);

                tempMedal.Levels = new MedalLevelCollection();

                tempMedal.Condition = medal.Condition;
                //if (medal.IsCustom)
                //{
                //    //tempMedal.Condition = _Request.Get("condition_" + medal.ID, Method.Post, string.Empty).Trim();
                //    //msgDisplay.AddError("condition", i, "点亮规则不能为空");
                //}
                //else
                //{
                List <int> values = new List <int>();
                foreach (MedalLevel level in medal.Levels)
                {
                    MedalLevel tempLevel = new MedalLevel();

                    tempLevel.Name      = level.Name;
                    tempLevel.Value     = level.Value;
                    tempLevel.IconSrc   = level.IconSrc;
                    tempLevel.Condition = level.Condition;
                    //tempLevel.Name = _Request.Get("levelName_" + medal.ID + "_" + level.ID, Method.Post, string.Empty).Trim();
                    //if (tempLevel.Name == string.Empty)
                    //{
                    //    msgDisplay.AddError("levelname", i, "等级名称不能为空");
                    //}
                    //tempLevel.Value = _Request.Get<int>("levelValue_" + medal.ID + "_" + level.ID, Method.Post, 0);

                    //if (values.Contains(tempLevel.Value))
                    //{
                    //    msgDisplay.AddError("Condition",i,"不同等级的点亮规则必须不同");
                    //}
                    //values.Add(tempLevel.Value);

                    //tempLevel.IconSrc = _Request.Get("iconSrc_" + medal.ID + "_" + level.ID, Method.Post, string.Empty).Trim();
                    //if (tempLevel.IconSrc == string.Empty)
                    //{
                    //    msgDisplay.AddError("iconSrc", i, "等级图标不能为空");
                    //}

                    tempLevel.ID = level.ID;

                    tempMedal.Levels.Add(tempLevel);
                }
                //}

                tempMedal.ID         = medal.ID;
                tempMedal.IsCustom   = medal.IsCustom;
                tempMedal.MaxLevelID = medal.MaxLevelID;

                medals.Add(tempMedal);

                i++;
            }

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

            MedalSettings setting = new MedalSettings();

            setting.Medals     = medals;
            setting.MaxMedalID = AllSettings.Current.MedalSettings.MaxMedalID;

            try
            {
                if (!SettingManager.SaveSettings(setting))
                {
                    CatchError <ErrorInfo>(delegate(ErrorInfo error)
                    {
                        msgDisplay.AddError(error);
                    });
                }
                else
                {
                    UserBO.Instance.RemoveAllUserCache();
                    m_MedalList = null;
                    _Request.Clear(Method.Post);
                }
            }
            catch (Exception ex)
            {
                msgDisplay.AddError(ex.Message);
            }
        }
示例#10
0
        private void SaveSetting()
        {
            MessageDisplay msgDisplay = CreateMessageDisplay("name", "levelname", "iconsrc", "condition");

            MedalCollection medals = new MedalCollection();

            int i = 0;
            foreach (Medal medal in MedalList)
            {
                Medal tempMedal = new Medal();
                tempMedal.SortOrder = _Request.Get<int>("sortorder_" + medal.ID, Method.Post, 0);
                tempMedal.Name = _Request.Get("name_" + medal.ID, Method.Post, string.Empty).Trim();

                if (tempMedal.Name == string.Empty)
                {
                    msgDisplay.AddError("name", i, "勋章名称不能为空");
                }

                tempMedal.Enable = _Request.Get<bool>("enable_" + medal.ID, Method.Post, false);
                tempMedal.IsHidden = _Request.Get<bool>("isHidden_" + medal.ID, Method.Post, false);

                tempMedal.Levels = new MedalLevelCollection();

                tempMedal.Condition = medal.Condition;
                //if (medal.IsCustom)
                //{
                //    //tempMedal.Condition = _Request.Get("condition_" + medal.ID, Method.Post, string.Empty).Trim();
                //    //msgDisplay.AddError("condition", i, "点亮规则不能为空");
                //}
                //else
                //{
                    List<int> values = new List<int>();
                    foreach (MedalLevel level in medal.Levels)
                    {
                        MedalLevel tempLevel = new MedalLevel();

                        tempLevel.Name = level.Name;
                        tempLevel.Value = level.Value;
                        tempLevel.IconSrc = level.IconSrc;
                        tempLevel.Condition = level.Condition;
                        //tempLevel.Name = _Request.Get("levelName_" + medal.ID + "_" + level.ID, Method.Post, string.Empty).Trim();
                        //if (tempLevel.Name == string.Empty)
                        //{
                        //    msgDisplay.AddError("levelname", i, "等级名称不能为空");
                        //}
                        //tempLevel.Value = _Request.Get<int>("levelValue_" + medal.ID + "_" + level.ID, Method.Post, 0);

                        //if (values.Contains(tempLevel.Value))
                        //{
                        //    msgDisplay.AddError("Condition",i,"不同等级的点亮规则必须不同");
                        //}
                        //values.Add(tempLevel.Value);

                        //tempLevel.IconSrc = _Request.Get("iconSrc_" + medal.ID + "_" + level.ID, Method.Post, string.Empty).Trim();
                        //if (tempLevel.IconSrc == string.Empty)
                        //{
                        //    msgDisplay.AddError("iconSrc", i, "等级图标不能为空");
                        //}

                        tempLevel.ID = level.ID;

                        tempMedal.Levels.Add(tempLevel);
                    }
                //}

                tempMedal.ID = medal.ID;
                tempMedal.IsCustom = medal.IsCustom;
                tempMedal.MaxLevelID = medal.MaxLevelID;

                medals.Add(tempMedal);

                i++;
            }

            if (msgDisplay.HasAnyError())
                return;

            MedalSettings setting = new MedalSettings();
            setting.Medals = medals;
            setting.MaxMedalID = AllSettings.Current.MedalSettings.MaxMedalID;

            try
            {
                if (!SettingManager.SaveSettings(setting))
                {
                    CatchError<ErrorInfo>(delegate(ErrorInfo error)
                    {
                        msgDisplay.AddError(error);
                    });
                }
                else
                {
                    UserBO.Instance.RemoveAllUserCache();
                    m_MedalList = null;
                    _Request.Clear(Method.Post);
                }
            }
            catch (Exception ex)
            {
                msgDisplay.AddError(ex.Message);
            }
        }
示例#11
0
        public MedalSettings()
        {
            Medals = new MedalCollection();
            MaxMedalID = 3;

            Medal medal = new Medal();

            medal.ID = 1;
            medal.IsCustom = false;
            medal.IsHidden = false;
            medal.Enable = true;
            medal.Condition = "point_1";
            medal.Name = "大富翁";
            medal.MaxLevelID = 5;

            MedalLevel level = new MedalLevel();
            level.IconSrc = "~/max-assets/icon-medal/gold1.gif";
            level.ID = 1;
            level.Name = "万元户";
            level.Value = 10000;

            medal.Levels.Add(level);

            level = new MedalLevel();
            level.IconSrc = "~/max-assets/icon-medal/gold2.gif";
            level.ID = 2;
            level.Name = "暴发户";
            level.Value = 100000;
            medal.Levels.Add(level);


            level = new MedalLevel();
            level.IconSrc = "~/max-assets/icon-medal/gold3.gif";
            level.ID = 3;
            level.Name = "百万富翁";
            level.Value = 1000000;
            medal.Levels.Add(level);


            level = new MedalLevel();
            level.IconSrc = "~/max-assets/icon-medal/gold4.gif";
            level.ID = 4;
            level.Name = "千万富翁";
            level.Value = 10000000;
            medal.Levels.Add(level);

            level = new MedalLevel();
            level.IconSrc = "~/max-assets/icon-medal/gold5.gif";
            level.ID = 5;
            level.Name = "亿万富翁";
            level.Value = 100000000;
            medal.Levels.Add(level);

            Medals.Add(medal);

            medal = new Medal();

            medal.ID = 2;
            medal.IsCustom = true;
            medal.IsHidden = false;
            medal.Enable = true;
            medal.Condition = "";
            medal.Name = "忠实用户";
            medal.MaxLevelID = 1;

            level = new MedalLevel();
            level.IconSrc = "~/max-assets/icon-medal/medal15.gif";
            level.ID = 1;
            level.Name = "一级";
            level.Condition = "参与“领取每日积分大礼包”任务可获得此图标";
            medal.Levels.Add(level);

            Medals.Add(medal);


            medal = new Medal();

            medal.ID = 3;
            medal.IsCustom = true;
            medal.IsHidden = true;
            medal.Enable = true;
            medal.Condition = "";
            medal.Name = "开国元老";
            medal.MaxLevelID = 1;

            level = new MedalLevel();
            level.IconSrc = "~/max-assets/icon-medal/medal11.gif";
            level.ID = 1;
            level.Name = "一级";
            level.Condition = "需要管理员点亮";
            medal.Levels.Add(level);

            Medals.Add(medal);
        }