private void spreadList(DSPatrolManagement dblist, bool preserveCompetitorOrder)
        {
            Trace.WriteLine("CPatrolManagement: spreadList() started on thread \"" +
                            Thread.CurrentThread.Name + "\" ( " +
                            System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() +
                            " )");

            try
            {
                // Spread that list
                int i = 0;
                foreach (DSPatrolManagement.PSortRow row in dblist.PSort)
                {
                    // For each shooter, add competitors to patrols,
                    // sorting on weaponsclass
                    int shooterId = row.ShooterId;

                    // First get those competitors, sorted on weaponsclass
                    DSPatrolManagement comps = getCompetitors(shooterId, preserveCompetitorOrder);

                    // Assign competitors to patrols with regards to minimum wait
                    assignPatrolsToCompetitors(comps, preserveCompetitorOrder);
                    i++;
                    this.myInterface.updatedPatrolAddAutomaticCompetitors(
                        2 * database.Shooters.Count + i,
                        3 * database.Shooters.Count);
                }
            }
            finally
            {
                Trace.WriteLine("CPatrolManagement: spreadList() ended.");
            }
        }
示例#2
0
        public override DataSet Clone()
        {
            DSPatrolManagement cln = ((DSPatrolManagement)(base.Clone()));

            cln.InitVars();
            return(cln);
        }
        private DSPatrolManagement sortList(DSPatrolManagement dblist)
        {
            Trace.WriteLine("CPatrolManagement: sortList() started on thread \"" +
                            Thread.CurrentThread.Name + "\" ( " +
                            System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() +
                            " )");

            try
            {
                DSPatrolManagement dblistnew = new DSPatrolManagement();
                int i = 0;
                foreach (DSPatrolManagement.PSortRow row in
                         dblist.PSort.Select("", "NrOfRounds desc, ClubId"))
                {
                    DSPatrolManagement.PSortRow newRow = dblistnew.PSort.NewPSortRow();
                    newRow.ShooterId  = row.ShooterId;
                    newRow.ClubId     = row.ClubId;
                    newRow.NrOfRounds = row.NrOfRounds;
                    dblistnew.PSort.AddPSortRow(newRow);
                    i++;
                    this.myInterface.updatedPatrolAddAutomaticCompetitors(
                        database.Shooters.Count + i,
                        3 * database.Shooters.Count);
                }

                return(dblistnew);
            }
            finally
            {
                Trace.WriteLine("CPatrolManagement: sortList() ended.");
            }
        }
        private DSPatrolManagement createList()
        {
            Trace.WriteLine("CPatrolManagement: createList() started on thread \"" +
                            Thread.CurrentThread.Name + "\" ( " +
                            System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() +
                            " )");

            try
            {
                DSPatrolManagement dblist = new DSPatrolManagement();

                int i = 0;
                foreach (DatabaseDataset.ShootersRow shooter in database.Shooters)
                {
                    DSPatrolManagement.PSortRow newRow = dblist.PSort.NewPSortRow();

                    newRow.ClubId = shooter.ClubId;
                    int rounds = 0;
                    foreach (System.Data.DataRow row in shooter.GetChildRows("ShootersCompetitors"))
                    {
                        if (row.IsNull("PatrolId"))
                        {
                            rounds++;
                        }
                    }
                    if (rounds > 0)
                    {
                        newRow.NrOfRounds = rounds;
                        newRow.ShooterId  = shooter.ShooterId;

                        dblist.PSort.AddPSortRow(newRow);
                    }
                    i++;

                    this.myInterface.updatedPatrolAddAutomaticCompetitors(i, 3 * database.Shooters.Count);
                }

                return(dblist);
            }
            finally
            {
                Trace.WriteLine("CPatrolManagement: createList() ended.");
            }
        }
        internal void PatrolAddAutomaticCompetitors(bool CleanPatrols, bool preserveCompetitorOrder)
        {
            Trace.WriteLine("CPatrolManagement: PatrolAddAutomaticCompetitors(" +
                            CleanPatrols.ToString() + ") started on thread \"" +
                            Thread.CurrentThread.Name + "\" ( " +
                            System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() +
                            " )");

            database = myInterface.databaseClass.Database;

            // First clean patrols if instructed
            if (CleanPatrols)
            {
                cleanPatrols();
                myInterface.updatedPatrol();
            }

            // Check there is any competitors
            if (this.database.Competitors
                .Select("PatrolId is null").Length == 0)
            {
                return;
            }

            this.myInterface.updatedPatrolAddAutomaticCompetitors(
                0, 3 * database.Shooters.Count);

            // Create list
            DSPatrolManagement dblist = createList();

            // Sort list
            dblist = sortList(dblist);

            // Spread list evenly
            spreadList(dblist, preserveCompetitorOrder);

            // Update interface
            this.myInterface.updatedPatrolAddAutomaticCompetitors(
                3 * database.Shooters.Count,
                3 * database.Shooters.Count);

            Trace.WriteLine("CPatrolManagement: PatrolAddAutomaticCompetitors ended.");
        }
        private void assignPatrolsToCompetitors(DSPatrolManagement comps, bool preserveOrder)
        {
            Trace.WriteLine("CPatrolManagement: assignPatrolsToCompetitors() started on thread \"" +
                            Thread.CurrentThread.Name + "\" ( " +
                            System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() +
                            " )");

            try
            {
                int patrolTime  = myInterface.CompetitionCurrent.PatrolTime;
                int patrolRest  = myInterface.CompetitionCurrent.PatrolTimeRest;
                int maxInPatrol = myInterface.CompetitionCurrent.PatrolSize;

                int starttime = 0;

                string sorting = "";
                if (preserveOrder)
                {
                    sorting = "CompetitorId";
                }
                else
                {
                    sorting = "PatrolClass";
                }

                foreach (DSPatrolManagement.CompetitorsRow comp in
                         comps.Competitors.Select("", sorting))
                {
                    Structs.Competitor competitor =
                        myInterface.GetCompetitor(comp.CompetitorId);
                    starttime = assignPatrolToCompetitor(competitor,
                                                         comp.PatrolClass,
                                                         starttime, maxInPatrol);
                    starttime += patrolTime + patrolRest;
                }
            }
            finally
            {
                Trace.WriteLine("CPatrolManagement: assignPatrolsToCompetitors() ended.");
            }
        }
        private DSPatrolManagement getCompetitors(int shooterId, bool preserveShooterOrder)
        {
            Trace.WriteLine("CPatrolManagement: getCompetitors() started on thread \"" +
                            Thread.CurrentThread.Name + "\" ( " +
                            System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() +
                            " )");

            try
            {
                // Get the competitors from the database
                Structs.Competitor[] temp = myInterface.GetCompetitors(shooterId);
                ArrayList            competitorsUnfiltered =
                    new ArrayList(temp);
                for (int i = 0; i < competitorsUnfiltered.Count;)
                {
                    object             obj  = competitorsUnfiltered[i];
                    Structs.Competitor comp = (Structs.Competitor)obj;
                    if (comp.PatrolId != -1)
                    {
                        competitorsUnfiltered.Remove(obj);
                    }
                    i++;
                }
                Structs.Competitor[] competitors = (Structs.Competitor[])
                                                   competitorsUnfiltered.ToArray(
                    typeof(Structs.Competitor));

                // Insert them into a temporary table
                DSPatrolManagement dblistunsorted = new DSPatrolManagement();
                foreach (Structs.Competitor row in competitors)
                {
                    DSPatrolManagement.CompetitorsRow newRow =
                        dblistunsorted.Competitors.NewCompetitorsRow();

                    newRow.CompetitorId = row.CompetitorId;
                    newRow.PatrolClass  =
                        (int)myInterface.ConvertWeaponsClassToPatrolClass(
                            myInterface.GetWeapon(row.WeaponId).WClass);

                    dblistunsorted.Competitors.AddCompetitorsRow(newRow);
                }

                // Sort the table into a new table
                string sorting = "PatrolClass desc";
                if (preserveShooterOrder)
                {
                    sorting = "CompetitorId," + sorting;
                }
                else
                {
                    sorting += ", CompetitorId";
                }

                DSPatrolManagement.CompetitorsRow[] rows = (DSPatrolManagement.CompetitorsRow[])
                                                           dblistunsorted.Competitors.Select("", sorting);

                DSPatrolManagement dblistsorted = new DSPatrolManagement();
                foreach (DSPatrolManagement.CompetitorsRow row in rows)
                {
                    DSPatrolManagement.CompetitorsRow newRow =
                        dblistsorted.Competitors.NewCompetitorsRow();

                    newRow.CompetitorId = row.CompetitorId;
                    newRow.PatrolClass  = row.PatrolClass;

                    dblistsorted.Competitors.AddCompetitorsRow(newRow);
                }

                return(dblistsorted);
            }
            finally
            {
                Trace.WriteLine("CPatrolManagement: getCompetitors() ended.");
            }
        }