private void Exit_Clicked(object sender, RoutedEventArgs e) { UserInfo.UserName = ""; UserInfo.Password = ""; UserInfo.IsLogged = false; UserName.Text = ""; Password.Password = ""; Login_Button.Visibility = Visibility.Visible; UserInfoState.Hide(); errorMessage.Text = ""; ContentFrame.Navigate(typeof(Home)); BattleVM.GetBattleVM().AllBattles.Clear(); AthleteVM.GetAthleteVM().AllAthletes.Clear(); MatchesVM.GetMatchesVM().AllMatches.Clear(); ResultVM.GetResultVM().AllResults.Clear(); NavMenuPrimaryListView.IsItemClickEnabled = false; NavMenuBottomListView.IsItemClickEnabled = false; NavMenuMatchListView.Visibility = Visibility.Collapsed; NavMenuMatchInfoListView.Visibility = Visibility.Collapsed; API.GetAPI().SignOut(); }
private async void listView_ItemClick(object sender, ItemClickEventArgs e) { string name = (e.ClickedItem as Matches).name; foreach (Matches match in matchesVM.AllMatches) { if (match.name == name) { MainPage.Curr.NavMenuMatchListView.Visibility = Visibility.Visible; MainPage.Curr.NavMenuMatchInfoListView.Visibility = Visibility.Visible; navMenuItemVM.NavMenuMatchItem[0].text = name; if (navMenuItemVM.PrimarySelectedItem != null) { navMenuItemVM.PrimarySelectedItem.Selected = Visibility.Collapsed; } navMenuItemVM.PrimarySelectedItem = navMenuItemVM.NavMenuMatchItem[0]; navMenuItemVM.PrimarySelectedItem.Selected = Visibility.Visible; if (navMenuItemVM.SecondarySelectedItem != null) { navMenuItemVM.SecondarySelectedItem.Selected = Visibility.Collapsed; } navMenuItemVM.SecondarySelectedItem = navMenuItemVM.NavMenuMatchInfoItem[1]; navMenuItemVM.SecondarySelectedItem.Selected = Visibility.Visible; matchesVM.SelectedMatch = match; // 请求数据库刷新更具当前选中的比赛更新VM(包括Athlete、Battle、Result) // matchesVM.SelectedMatch即为当前选中的比赛,包括了name,startTime和matchEvent JObject result = await Internet.API.GetAPI().GetMatchInfo(matchesVM.SelectedMatch.matchEvent, name); //Debug.WriteLine(result); AthleteVM.GetAthleteVM().AllAthletes.Clear(); AthleteVM.GetAthleteVM().AllAthletes.Add(new Athlete("序号", "姓名", "性别", "身份证", "联系方式", "积分", "种子序号")); JToken athletes = result["data"]["athletes"]; Debug.WriteLine(athletes); foreach (JToken athlete in athletes) { string athleteId = athlete["_id"].ToString(); JToken athleteInfo = athlete["athlete"]; AthleteVM.GetAthleteVM().AllAthletes.Add(new Athlete(athleteId, athleteInfo["姓名"].ToString(), athleteInfo["性别"].ToString(), athleteInfo["身份证"].ToString(), athleteInfo["手机号"].ToString(), athleteInfo["积分"].ToString(), "0")); } string round = result["data"]["round"].ToString(); JToken groups = result["data"]["groups"]; //Battle BattleTableTitle = battleVM.AllBattles[0]; battleVM.AllBattles.Clear(); //battleVM.AllBattles.Add(BattleTableTitle); //Result ResultTableTitle = resultVM.AllResults[0]; resultVM.AllResults.Clear(); //resultVM.AllResults.Add(ResultTableTitle); foreach (JToken group in groups) { string groupId = group["group"].ToString(); JToken battles = group["battles"]; foreach (JToken battle in battles) { //battle id string _id = battle["_id"].ToString(); // winnerName string winnerName = ""; int winnerNum = 0; if (battle["winner"].ToString() != "") { winnerNum = battle["winner"].ToString()[0] - '0'; if (winnerNum == 1) { winnerName = battle["athleteA"]["athlete"]["姓名"].ToString(); } else if (winnerNum == 2) { winnerName = battle["athleteB"]["athlete"]["姓名"].ToString(); } } Athlete A = null, B = null; //Athlete(string _id, string _name, string _sex, string _idNum, string _phoneNum, string _score, string _seedNum) //athleteA JToken athleteA = battle["athleteA"]; //轮空选手为空 if (athleteA.ToString() != null) { string athleteAId = athleteA["_id"].ToString(); //Debug.WriteLine(athleteAId); JToken infoA = athleteA["athlete"]; //Debug.WriteLine(infoA); A = new Athlete(athleteAId, infoA["姓名"].ToString(), infoA["性别"].ToString(), infoA["身份证"].ToString(), infoA["手机号"].ToString(), infoA["积分"].ToString(), "0"); } //athleteB JToken athleteB = battle["athleteB"]; //轮空选手为空 if (athleteB.ToString() != "") { string athleteBId = athleteB["_id"].ToString(); JToken infoB = athleteB["athlete"]; Debug.WriteLine(infoB); B = new Athlete(athleteBId, infoB["姓名"].ToString(), infoB["性别"].ToString(), infoB["身份证"].ToString(), infoB["手机号"].ToString(), infoB["积分"].ToString(), "0"); } Battle newbattle = new Battle(_id, groupId, A, B); battleVM.AllBattles.Add(newbattle); resultVM.AllResults.Add(new Result(newbattle, winnerName, winnerNum)); } } MainPage.Curr.ContentFrame.Navigate(typeof(Battles)); break; } } }
private async void CreateBattles_Click(object sender, RoutedEventArgs e) { if (matchLastTime.Text == "" || place.Text == "" || placeContain.Text == "" || sectionPerDay.Text == "") { await new MessageDialog("请确认信息再进行提交!").ShowAsync(); return; } if (MatchSystem.SelectedIndex == 0) { matchType = "SingleElimination"; } else if (MatchSystem.SelectedIndex == 1) { matchType = "SingleCycle"; } else { matchType = "GroupLoop"; } Debug.WriteLine(StartTimePicker.Date.ToString()); JObject result = await Internet.API.GetAPI().createMatch(athleteDataSet, matchEvent, matchType, NameBox.Text, StartTimePicker.Date.ToString().Split(" ")[0], SeedNumber.Text, matchLastTime.Text, place.Text, placeContain.Text, sectionPerDay.Text); Matches newMatch = new Matches(matchEvent, NameBox.Text, StartTimePicker.Date.ToString().Split(" ")[0], matchType, matchLastTime.Text, place.Text, placeContain.Text, sectionPerDay.Text, SeedNumber.Text); matchesVM.SelectedMatch = newMatch; matchesVM.AllMatches.Add(newMatch); TileService.UpdateTileItem(); Athlete AthleteTableTitle = AthleteVM.GetAthleteVM().AllAthletes[0]; AthleteVM.GetAthleteVM().AllAthletes.Clear(); AthleteVM.GetAthleteVM().AllAthletes.Add(AthleteTableTitle); JToken athletes = result["data"]["athletes"]; // Debug.WriteLine(athletes); foreach (JToken athlete in athletes) { string athleteId = athlete["_id"].ToString(); JToken athleteInfo = athlete["athlete"]; AthleteVM.GetAthleteVM().AllAthletes.Add(new Athlete(athleteId, athleteInfo["姓名"].ToString(), athleteInfo["性别"].ToString(), athleteInfo["身份证"].ToString(), athleteInfo["手机号"].ToString(), athleteInfo["积分"].ToString(), "0")); } JToken groups = result["data"]["groups"]; string round = result["data"]["round"].ToString(); //Battle BattleTableTitle = battleVM.AllBattles[0]; battleVM.AllBattles.Clear(); //battleVM.AllBattles.Add(BattleTableTitle); battleVM.round = int.Parse(round); //Result ResultTableTitle = resultVM.AllResults[0]; resultVM.AllResults.Clear(); //resultVM.AllResults.Add(ResultTableTitle); foreach (JToken group in groups) { string groupId = group["group"].ToString(); JToken battles = group["battles"]; foreach (JToken battle in battles) { //battle id string _id = battle["_id"].ToString(); // winnerName string winnerName = ""; int winnerNum = 0; if (battle["winner"].ToString() != "") { winnerNum = battle["winner"].ToString()[0] - '0'; if (winnerNum == 1) { winnerName = battle["athleteA"]["athlete"]["姓名"].ToString(); } else if (winnerNum == 2) { winnerName = battle["athleteB"]["athlete"]["姓名"].ToString(); } } Athlete A = null, B = null; //Athlete(string _id, string _name, string _sex, string _idNum, string _phoneNum, string _score, string _seedNum) //athleteA JToken athleteA = battle["athleteA"]; //轮空选手为空 if (athleteA.ToString() != null) { string athleteAId = athleteA["_id"].ToString(); //Debug.WriteLine(athleteAId); JToken infoA = athleteA["athlete"]; //Debug.WriteLine(infoA); A = new Athlete(athleteAId, infoA["姓名"].ToString(), infoA["性别"].ToString(), infoA["身份证"].ToString(), infoA["手机号"].ToString(), infoA["积分"].ToString(), "0"); } //athleteB JToken athleteB = battle["athleteB"]; //轮空选手为空 if (athleteB.ToString() != "") { string athleteBId = athleteB["_id"].ToString(); JToken infoB = athleteB["athlete"]; Debug.WriteLine(infoB); B = new Athlete(athleteBId, infoB["姓名"].ToString(), infoB["性别"].ToString(), infoB["身份证"].ToString(), infoB["手机号"].ToString(), infoB["积分"].ToString(), "0"); } Battle newbattle = new Battle(_id, groupId, A, B); battleVM.AllBattles.Add(newbattle); resultVM.AllResults.Add(new Result(newbattle, winnerName, winnerNum)); } } MainPage.Curr.NavMenuMatchListView.Visibility = Visibility.Visible; navMenuItemVM.NavMenuMatchItem[0].text = NameBox.Text; navMenuItemVM.PrimarySelectedItem.Selected = Visibility.Collapsed; navMenuItemVM.PrimarySelectedItem = navMenuItemVM.NavMenuMatchItem[0]; navMenuItemVM.PrimarySelectedItem.Selected = Visibility.Visible; MainPage.Curr.ContentFrame.Navigate(typeof(Battles)); MainPage.Curr.NavMenuMatchInfoListView.Visibility = Visibility.Visible; if (navMenuItemVM.SecondarySelectedItem != null) { navMenuItemVM.SecondarySelectedItem.Selected = Visibility.Collapsed; } navMenuItemVM.SecondarySelectedItem = navMenuItemVM.NavMenuMatchInfoItem[1]; navMenuItemVM.SecondarySelectedItem.Selected = Visibility.Visible; await new MessageDialog("成功创建比赛").ShowAsync(); }