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("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); } }
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"); }
private void DeleteMedals(List<int> medalIDs) { MessageDisplay msgDisplay = CreateMessageDisplay(); MedalCollection medals = new MedalCollection(); int i = 0; foreach (Medal medal in MedalList) { if (medalIDs.Contains(medal.ID) == false) medals.Add(medal); } 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); Logs.LogManager.LogOperation( new Medal_DeleteMedalByIDs(MyUserID, My.Name, _Request.IpAddress, medalIDs) ); } } catch (Exception ex) { msgDisplay.AddError(ex.Message); } }