コード例 #1
0
        public void StartRunning(string eventName, string distance)
        {
            try
            {
                var now = DateTime.Now;
                List <RunnerInfo> runners = new List <RunnerInfo>();
                using (RunnerDataContext db = new RunnerDataContext())
                {
                    runners = db.RunnerInfos.Where(x => x.Event == eventName && x.Distance == distance).ToList();

                    List <RunnerScanDateTime> insertingList = new List <RunnerScanDateTime>();
                    foreach (var runner in runners)
                    {
                        RunnerScanDateTime record = new RunnerScanDateTime()
                        {
                            RunnerIdentification = runner.RunnerBIB,
                            ScannedDateTime      = now
                        };
                        insertingList.Add(record);
                    }

                    db.RunnerScanDateTimes.InsertAllOnSubmit(insertingList);
                    db.SubmitChanges();
                }
                MessageBox.Show($"Start {eventName} {distance} successfully");
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
コード例 #2
0
        public void ClearRunningRecord(string eventName, string distance)
        {
            MessageBoxResult messageBoxResult = MessageBox.Show($"Confirm clearing {eventName} {distance} runner record?", "Delete Confirmation", MessageBoxButton.YesNo);

            if (messageBoxResult == MessageBoxResult.Yes)
            {
                try
                {
                    using (RunnerDataContext db = new RunnerDataContext())
                    {
                        var runnerInfos = db.RunnerInfos.Where(x => x.Event == eventName && x.Distance == distance);
                        var runnerScans = db.RunnerScanDateTimes.Where(x => runnerInfos.Select(y => y.RunnerBIB).Contains(x.RunnerIdentification));

                        if (runnerScans.Any())
                        {
                            db.RunnerScanDateTimes.DeleteAllOnSubmit(runnerScans);
                            db.SubmitChanges();

                            MessageBox.Show($"Remove {eventName} {distance} successfully");
                        }
                        else
                        {
                            MessageBox.Show($"{eventName} {distance} found no record");
                        }
                    }
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message);
                }
            }
        }
コード例 #3
0
        private void ClearDBRecords_Click(object sender, RoutedEventArgs e)
        {
            MessageBoxResult messageBoxResult = MessageBox.Show("Confirm clearing WHOLE runner record?", "Delete Confirmation", MessageBoxButton.YesNo);

            if (messageBoxResult == MessageBoxResult.Yes)
            {
                try
                {
                    using (RunnerDataContext db = new RunnerDataContext())
                    {
                        if (db.RunnerScanDateTimes.Any())
                        {
                            db.RunnerScanDateTimes.DeleteAllOnSubmit(db.RunnerScanDateTimes);
                            db.SubmitChanges();
                        }
                    }
                    MessageBox.Show("Clear Whole record successfully");
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }