コード例 #1
0
ファイル: TagClashForm.cs プロジェクト: crawfis/RaceManager
        public void SetCompetitors(List<CompetitorRace> crs, PassingsInfo pi, List<TagId> tagClashFormList, 
            Race currentRace, DataGridView passingsGrid, Dictionary<TagId, CompetitorRace> disambiuationCRDict)
        {
            this.crs = crs;
            this.tagClashFormList = tagClashFormList;
            this.tagID = pi.ID;
            this.currentRace = currentRace;
            this.passingsGrid = passingsGrid;
            this.disambiuationCRDict = disambiuationCRDict;

            DataTable t = new DataTable();
            t.Columns.Add("First Name");
            t.Columns.Add("Last Name");
            t.Columns.Add("Tag ID");

            foreach (CompetitorRace cr in crs)
            {
                t.Rows.Add(new object[] { cr.firstName, cr.lastName, pi.ID });
                this.dataGridView1.DataSource = t;
            }
            this.dataGridView1.ClearSelection();
        }
コード例 #2
0
        /// <summary>
        /// This method checks whether there exists a competitor with the given id
        /// and loads his/her information to the dialog UI.
        /// </summary>
        public void SetCompetitorData(int competitorID, PassingsInfo pi, BindingList<PassingsInfo> passingsDataList, 
            RaceInformationControl parent)
        {
            this.pi = pi;
            this.passingsDataList = passingsDataList;
            this.raceInformationControl = parent;

            if (parent.GetCurrentRace() != null)
            {
                BindingList<String> validClasses = new BindingList<String>();
                foreach (Class cl in parent.GetCurrentRace().validClasses)
                {
                    validClasses.Add( (cl.name != null ? cl.name : "" ));
                }
                classComboBox.DataSource = validClasses;
            }

            //Console.WriteLine((raceInformationControl.RaceCompetitorsHash[pi.ID] as CompetitorRace).className);
            //String className = (raceInformationControl.RaceCompetitorsHash[pi.ID] as CompetitorRace).className;
            //if (className != null)//now only for existing competitors with event entries
            //    this.eventEntryClassTextBox.Text = className;

            foreach (Competitor c in DataManager.Instance.Competitors)
            {
                if (c.ID == competitorID)
                {
                    competitorDataInput.SetData(c);
                    competitor = c;
                    return;
                }
            }

            //if no competitor found:
            //load tag id only, populate other fields with some default values
            //may need a button that checks whether a person with a given name
            //exists in the list of competitors - to help the admin
            competitorDataInput.SetData("", "", new Address(), new PhoneNumber(),
                DateTime.Now, 30, true, "", "", "3333", pi.ID, new TagId());
        }
コード例 #3
0
        public void UpdatePassingsGrid(TagReadEventArgs e, int addIndex = -1)
        {
            PassingsInfo pi = null;
            bool tagClash = false;
            CompetitorRace cr = null;
            List<CompetitorRace> crs = FindCompetitorRaceByTag(e.TagInfo.ID);
            if (crs.Count == 1)
                cr = crs[0];
            else if(crs.Count > 1)
                tagClash = true;
            
            EventEntry eve = null;
            if (cr == null && !tagClash)
            {
                eve = isCompetitorInEventThreadSafe(e.TagInfo.ID);

                //the following may happen - for example, event entry has IDs of removed competitor;
                //then we should go as if there is not corresponding event entry
                if (eve != null)
                {
                    if (DataManager.Instance.GetCompetitorByID(eve.competitorID) == null)
                        eve = null;
                }
            }

            if (cr != null)
            {
                pi = new PassingsInfo(e.TagInfo, cr.competitorID, cr.firstName, cr.lastName, cr.bikeNumber);
                pi.CompetitorRace = cr;
                if (addIndex == -1 || addIndex >= cr.passings.Count)
                    cr.passings.Add(pi);
                else
                    cr.passings.Insert(addIndex, pi);
            }
            else if (eve != null)
            {                
                CompetitorRace crNew = new CompetitorRace(eve.competitorID);
                //can competitor be null? probably not, as EventEntry is not null
                crNew.competitor = DataManager.Instance.GetCompetitorByID(eve.competitorID);
                crNew.EventEntry = eve;
                crNew.lastName = (crNew.competitor != null) ? crNew.competitor.LastName : "";
                crNew.firstName = (crNew.competitor != null) ? crNew.competitor.FirstName : "";
                crNew.competitorID = eve.competitorID;
                crNew.tagID = eve.tagNumber;
                crNew.tagID2 = eve.tagNumber2;
                crNew.bikeNumber = eve.bikeNumber;
                crNew.raceParent = this.GetCurrentSession();
                if (currentRace != null)//should never happen
                {
                    currentRace.competitorRaceList.Add(crNew);
                    crNew.raceParent = currentRace;
                }
                pi = new PassingsInfo(e.TagInfo, crNew.competitorID, crNew.firstName, crNew.lastName, crNew.bikeNumber);
                pi.CompetitorRace = cr;//crNew???
                if (addIndex == -1 || addIndex >= cr.passings.Count || addIndex >= crNew.passings.Count)//
                    crNew.passings.Add(pi);
                else
                    crNew.passings.Insert(addIndex, pi);
            }
            else
            {
                //have to create a new CompetitorRace:
                cr = new CompetitorRace();
                cr.isNull = true;
                //make its competitor's ID negative:
                //this will prevent possible clash with real
                //competitors' IDs
                cr.competitorID = -1 * DataManager.getNextID();
                cr.tagID = e.TagInfo.ID;
                cr.tagID2 = e.TagInfo.ID;
                cr.firstName = "";
                cr.lastName = "Unassigned";
                if (currentRace != null)//should never happen
                {
                    //currentRace.competitorRaceList is the currentRaceList
                    currentRace.competitorRaceList.Add(cr);
                    cr.raceParent = currentRace;
                }

                pi = new PassingsInfo(e.TagInfo, cr.competitorID, cr.firstName, cr.lastName, cr.bikeNumber);
                pi.CompetitorRace = cr;
                if (addIndex == -1 || addIndex >= cr.passings.Count)
                    cr.passings.Add(pi);
                else
                    cr.passings.Insert(addIndex, pi);
            }


            if (this.InvokeRequired)
            {
                this.Invoke((MethodInvoker)delegate
                {
                    if (addIndex == -1 || addIndex >= cr.passings.Count || addIndex >= (passingsDataGrid.DataSource as BindingList<PassingsInfo>).Count)
                        (passingsDataGrid.DataSource as BindingList<PassingsInfo>).Add(pi);
                    else
                        (passingsDataGrid.DataSource as BindingList<PassingsInfo>).Insert(addIndex, pi);

                    if (passingsDataGrid.RowCount > 0 && !passingsGridScrolled)
                    {
                        passingsDataGrid.Rows[passingsDataGrid.RowCount - 1].Selected = true;
                        passingsDataGrid.CurrentCell = passingsDataGrid.Rows[passingsDataGrid.RowCount - 1].Cells[0];
                    }
                });
            }
            else
            {
                if (addIndex == -1 || addIndex >= cr.passings.Count || addIndex >= (passingsDataGrid.DataSource as BindingList<PassingsInfo>).Count)
                    (passingsDataGrid.DataSource as BindingList<PassingsInfo>).Add(pi);
                else
                    (passingsDataGrid.DataSource as BindingList<PassingsInfo>).Insert(addIndex, pi);

                if (passingsDataGrid.RowCount > 0 && !passingsGridScrolled)
                {
                    passingsDataGrid.Rows[passingsDataGrid.RowCount - 1].Selected = true;
                    passingsDataGrid.CurrentCell = passingsDataGrid.Rows[passingsDataGrid.RowCount - 1].Cells[0];
                }
            }

            if (tagClash)
            {
                //TODO: after the user has selected the Competitor, this should remain for the whole
                //run; need some kind of Dictionary for that; it should be looked up first in
                //the method findCRbyTag;
                //also, don't forget to reset everything for a new run; for instance, tagClashFormList

                if (!tagClashFormList.Contains(pi.ID))
                {
                    List<CompetitorRace> crsNew = new List<CompetitorRace>();
                    foreach (CompetitorRace cRace in crs)
                    {
                        if (cRace.competitorID >= 0)//don't need "Unassigned" CRs
                            crsNew.Add(cRace);
                    }
                    if (crsNew.Count > 1)
                    {
                        tagClashFormList.Add(pi.ID);
                        TagClashForm clashForm = new TagClashForm();
                        clashForm.SetCompetitors(crsNew, pi, tagClashFormList, currentRace, passingsDataGrid, disambiuationCRDict);
                        clashForm.Show(this);
                    }
                }
            }

            //check if pi.lapTime is smaller than min lap time, make it "DELETED" if true
            if (pi != null && pi.CompetitorRace != null)
            {
                if (pi.CompetitorRace.passings != null && pi.CompetitorRace.passings.Count > 1)
                {
                    PassingsInfo piPrevious = null;
                    //look for any previous valid passings
                    for (int i = pi.CompetitorRace.passings.Count - 2; i >= 0; i--)
                    {
                        if (!pi.CompetitorRace.passings[i].Deleted.Equals("DELETED"))
                        {
                            piPrevious = pi.CompetitorRace.passings[i];
                            break;
                        }
                    }
                    if (piPrevious != null)
                    {
                        long latestTime = pi.Time;
                        long nextToLatestTime = piPrevious.Time;
                        double lapTime = (latestTime - nextToLatestTime) / 1000.0;
                        if (lapTime < DataManager.Instance.MinimumLapTime)
                        {
                            pi.Deleted = "DELETED";
                            pi.LapTime = GetTimeString(lapTime);
                        }
                    }
                }
            }
        }