Пример #1
0
        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            if (!(ListView.SelectedItem is Competition t))
            {
                return;
            }
            t.CompetitionName = ComName.Text;
            var tmpSdate = StartDate.SelectedDate ?? DateTime.Now;
            var tmpEdate = EndDate.SelectedDate ?? DateTime.Now;

            t.StartTime = Convert.ToDateTime(
                $"{tmpSdate:yyyy/MM/dd} {(StartHour.Text.Length == 1 ? $"0{StartHour.Text}" : StartHour.Text)}:{(StartMinute.Text.Length == 1 ? $"0{StartMinute.Text}" : StartMinute.Text)}:{(StartSecond.Text.Length == 1 ? $"0{StartSecond.Text}" : StartSecond.Text)}");
            t.EndTime = Convert.ToDateTime(
                $"{tmpEdate:yyyy/MM/dd} {(EndHour.Text.Length == 1 ? $"0{EndHour.Text}" : EndHour.Text)}:{(EndMinute.Text.Length == 1 ? $"0{EndMinute.Text}" : EndMinute.Text)}:{(EndSecond.Text.Length == 1 ? $"0{EndSecond.Text}" : EndSecond.Text)}");
            t.Option = 0;
            if (LimitedSubmit.IsChecked ?? false)
            {
                t.Option |= 1;
            }
            if (LastSubmit.IsChecked ?? false)
            {
                t.Option |= 2;
            }
            if (TimeCount.IsChecked ?? false)
            {
                t.Option |= 4;
            }
            if (IntimeNotify.IsChecked ?? false)
            {
                t.Option |= 8;
            }
            if (HideRank.IsChecked ?? false)
            {
                t.Option |= 16;
            }
            if (HideScore.IsChecked ?? false)
            {
                t.Option |= 32;
            }
            if (StopRank.IsChecked ?? false)
            {
                t.Option |= 64;
            }
            if (SummaryResult.IsChecked ?? false)
            {
                t.Option |= 128;
            }
            if (ToPrivate.IsChecked ?? false)
            {
                t.Option |= 256;
            }
            t.Password    = ComPassword.Text;
            t.SubmitLimit = Convert.ToInt32(LimitedSubmitTime.Text);
            var tmpProId = new List <int>();

            foreach (var i in ComProblems.Text.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries))
            {
                try
                {
                    var x = Convert.ToInt32(i);
                    if (Connection.GetProblem(x).ProblemId == 0)
                    {
                        MessageBox.Show("输入的题目 ID 不合法,无法保存", "提示", MessageBoxButton.OK, MessageBoxImage.Error);
                        return;
                    }
                    tmpProId.Add(x);
                }
                catch
                {
                    MessageBox.Show("输入的题目 ID 不合法,无法保存", "提示", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            t.ProblemSet  = tmpProId.ToArray();
            t.Description = ComNote.Text;
            Connection.UpdateCompetition(t);
        }