/// <summary> /// Данная функция не заполняет поля result_grade и result_place /// </summary> /// <param name="MemberId"></param> /// <param name="GroupId"></param> /// <param name="SecondColNameType"></param> /// <returns></returns> public participations ToParticipation(long MemberId, long GroupId, enSecondColNameType SecondColNameType) { participations result = new participations() { member = MemberId, Group = GroupId, }; if (GradeInEnum != enGrade.None) { result.init_grade = (byte)GradeInEnum; } switch (SecondColNameType) { case enSecondColNameType.Coach: result.coach = GlobalDefines.GetCoachId(SecondCol, true); break; case enSecondColNameType.Team: default: // по умолчанию будет "команда" result.team = GlobalDefines.GetTeamId(SecondCol, true); break; } return(result); }
/// <summary> /// /// </summary> /// <param name="PartInDB"></param> /// <returns></returns> public void CopyPartToDB(participations PartInDB, enSecondColNameType SecondColNameType) { PartInDB.init_grade = GradeInEnum == enGrade.None ? null : (byte?)GradeInEnum; switch (SecondColNameType) { case enSecondColNameType.Coach: PartInDB.team = null; PartInDB.coach = GlobalDefines.GetCoachId(SecondCol, true); break; case enSecondColNameType.Team: default: // по умолчанию будет "команда" PartInDB.coach = null; PartInDB.team = GlobalDefines.GetTeamId(SecondCol, true); break; } }
public static bool operator ==(CFullMemberInfo lhs, CMember rhs) { switch (GlobalDefines.ObjectBaseEquals(lhs, rhs)) { case enObjectBaseEqualsResult.True: return(true); case enObjectBaseEqualsResult.False: return(false); default: { bool result = lhs.Name == rhs.Name && lhs.Surname == rhs.Surname && lhs.YearOfBirth == (rhs.YearOfBirthInShort < 0 ? (short)0 : rhs.YearOfBirthInShort); if (result) { result = ((lhs.InitGrade == null && rhs.GradeInEnum == enGrade.None) || (lhs.InitGrade.Value == (byte)rhs.GradeInEnum)); } if (result) { // Т.к. тип второй колонки здесь поменяться не может, то делаем так if (lhs.Coach == null) { result = ((lhs.Team == null && string.IsNullOrEmpty(rhs.SecondCol)) || (lhs.Team == GlobalDefines.GetTeamId(rhs.SecondCol, false))); } else { result = ((lhs.Coach == null && string.IsNullOrEmpty(rhs.SecondCol)) || (lhs.Coach == GlobalDefines.GetCoachId(rhs.SecondCol, false))); } } return(result); } } }
/// <summary> /// Метод, который производит сохранение настроек /// </summary> /// <returns></returns> protected override bool SaveSettings() { if (Modified) { if (!CheckSettings()) { return(false); } string curMemberInfo = MemberData.MemberInDB.ToInfoString(); if (MemberData.PartInDB.init_grade.HasValue) { curMemberInfo += " " + GlobalDefines.GRADE_NAMES[(enGrade)MemberData.PartInDB.init_grade.Value]; } curMemberInfo += " " + (MemberData.SecondColNameType == enSecondColNameType.Coach ? MemberData.PartInDB.coaches.name : MemberData.PartInDB.teams.name); string newMemberInfo = MemberData.ToString(); if (MessageBox.Show(this, string.Format(Properties.Resources.resfmtChangeMemberQuestion, curMemberInfo, newMemberInfo), Title, MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.Yes) == MessageBoxResult.No) { return(false); } try { var ChangedMembersInDB = (from member in DBManagerApp.m_Entities.members where member.surname == MemberData.Surname && member.name == MemberData.Name select member).FirstOrDefault(); if (ChangedMembersInDB == null || ChangedMembersInDB.id_member == MemberData.MemberInDB.id_member) { // Участника с такими данными нет в БД => просто меняем данные текущего участника MemberData.MemberInDB.name = MemberData.Name; MemberData.MemberInDB.surname = MemberData.Surname; } else { // Такой спортсмен уже есть в БД => используем его MemberData.MemberInDB = ChangedMembersInDB; MemberData.PartInDB.member = MemberData.MemberInDB.id_member; } MemberData.MemberInDB.year_of_birth = MemberData.YearOfBirth; MemberData.PartInDB.init_grade = MemberData.Grade == enGrade.None ? null : (byte?)MemberData.Grade; if (MemberData.SecondColNameType == enSecondColNameType.Coach) { MemberData.PartInDB.coach = GlobalDefines.GetCoachId(MemberData.SecondColumn, true); MemberData.PartInDB.team = null; } else { MemberData.PartInDB.team = GlobalDefines.GetTeamId(MemberData.SecondColumn, true); MemberData.PartInDB.coach = null; } DBManagerApp.m_Entities.SaveChanges(); Modified = false; } catch (Exception ex) { MessageBox.Show(this, $"{Properties.Resources.resExceptionDuringSaveMember}: {ex.ToString()}", Title, MessageBoxButton.OK, MessageBoxImage.Error); return(false); } } return(true); }