Exemplo n.º 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);
            }
        }
Exemplo n.º 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);
                }
            }
        }
Exemplo n.º 3
0
        public List <RunnerResult> SearchResult(string eventName, string distance)
        {
            _eventName = eventName;
            _distance  = distance;

            string      dateTimeFormat = "HH : mm : ss.fff";
            CultureInfo thaiCulture    = new CultureInfo("th-TH");

            List <RunnerResult> result = new List <RunnerResult>();

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

                foreach (var group in runnerScans)
                {
                    var runnerMaxScannedTime = group.Max(x => x.ScannedDateTime);
                    var runnerMinScannedTime = group.Min(x => x.ScannedDateTime);

                    if (runnerMaxScannedTime > runnerMinScannedTime)
                    {
                        RunnerResult runnerStatus = new RunnerResult();
                        runnerStatus.RunnerIdentification = group.Key;
                        var runnerInfo = runnerInfos.SingleOrDefault(x => x.RunnerBIB == group.Key);
                        runnerStatus.Name     = string.Concat(runnerInfo.FirstName, " ", runnerInfo.LastName);
                        runnerStatus.Distance = runnerInfo.Distance;

                        runnerStatus.StartTimeString = $"ที่เวลา {runnerMinScannedTime.ToString(dateTimeFormat, thaiCulture)}";
                        runnerStatus.EndTimeString   = $"ที่เวลา {runnerMaxScannedTime.ToString(dateTimeFormat, thaiCulture)}";

                        var diffTime         = (runnerMaxScannedTime - runnerMinScannedTime);
                        var dateTimeTimeDiff = new DateTime(Math.Abs(diffTime.Ticks));
                        runnerStatus.Duration       = dateTimeTimeDiff;
                        runnerStatus.DurationString = $"{dateTimeTimeDiff.Hour} ชั่วโมง {dateTimeTimeDiff.Minute} นาที {dateTimeTimeDiff.Second}.{dateTimeTimeDiff.Millisecond} วินาที";

                        result.Add(runnerStatus);
                    }
                }
            }
            return(result.OrderBy(x => x.Duration).ToList());
        }
Exemplo n.º 4
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);
                }
            }
        }