Beispiel #1
0
        private Structs.Shooter GetShooterFromEmbeddedFile(string cardNr)
        {
            var rows =
                (DSStartupResources.ShootersRow[])
                _startup.Shooters.Select(
                    "CardNr='" + cardNr + "'");

            if (rows.Length <= 0)
            {
                throw new CannotFindIdException("Could not find shooter");
            }

            var shooter = new Structs.Shooter
            {
                CardNr     = rows[0].Cardnr,
                ClubId     = rows[0].ClubId,
                Email      = rows[0].Email,
                Givenname  = rows[0].Givenname,
                Surname    = rows[0].Surname,
                Automatic  = true,
                Class      = (Structs.ShootersClass)rows[0].Class,
                LastUpdate = rows[0].LastUpdate
            };

            return(shooter);
        }
        //Override the OnPrintPage to provide the printing logic for the document
        protected override void OnPrintPage(PrintPageEventArgs ev)
        {
            base.OnPrintPage(ev);
            LeftMargin = ev.MarginBounds.Left;

            //Work out the number of lines per page
            //Use the MarginBounds on the event to do this
            //lpp = ev.MarginBounds.Height  / printFont.GetHeight(ev.Graphics) ;
            float topMargin = ev.MarginBounds.Top;

            topMargin = 25;
            float yPos = topMargin;

            //Now print what we want to print
            Structs.Club    club    = CommonCode.GetClub(this.clubIdToPrint);
            Structs.Shooter shooter = CommonCode.GetShooters(club)[this.currentShooter];
            printHeader(ev, shooter, ref yPos);
            printShooter(ev, shooter, ref yPos);

            //If we have more patrols then print another page
            if (this.currentShooter < CommonCode.GetShooters(club).Length)
            {
                ev.HasMorePages = true;
            }
            else
            {
                ev.HasMorePages = false;
            }
        }
Beispiel #3
0
        private string createPatrolHtmlCompetitor(Structs.Competitor comp)
        {
            string tdclass = "";

            if (comp.Lane % 2 == 0)
            {
                tdclass = " class=\"resultevenline\" ";
            }
            else
            {
                tdclass = " class=\"resultoddline\" ";
            }

            StringBuilder html = new StringBuilder();

            Structs.Shooter shooter = myInterface.GetShooter(comp.ShooterId);

            html.Append("<tr>\r\n");
            html.Append("<td " + tdclass + ">" + comp.Lane.ToString() + "</td>\r\n");
            html.Append("<td " + tdclass + ">" + shooter.Givenname + " " + shooter.Surname + "</td>\r\n");
            html.Append("<td " + tdclass + ">" + comp.ShooterClass.ToString() + "</td>\r\n");

            Structs.Weapon weapon = myInterface.GetWeapon(comp.WeaponId);
            html.Append("<td " + tdclass + ">" + weapon.Manufacturer + "</td>\r\n");
            html.Append("<td " + tdclass + ">" + weapon.Model + "</td>\r\n");
            html.Append("<td " + tdclass + ">" + weapon.Caliber + "</td>\r\n");
            html.Append("</tr>\r\n");
            return(html.ToString());
        }
 internal void UpdatedShooter(Structs.Shooter shooter)
 {
     lock (resultHolders)
     {
         resultHolders.Clear();
     }
 }
Beispiel #5
0
        private void printShooter(PrintPageEventArgs ev,
                                  Structs.Shooter shooter, ref float yPos)
        {
            Structs.Competitor[] competitors =
                CommonCode.GetCompetitors(shooter.ShooterId, "PatrolId");

            foreach (Structs.Competitor comp in competitors)
            {
                if (comp.PatrolId > 0)
                {
                    Structs.Patrol patrol = CommonCode.GetPatrol(comp.PatrolId);
                    ev.Graphics.DrawString(patrol.StartDateTimeDisplay.ToShortTimeString(),
                                           printCompetitorFont, Brushes.Black, LeftMargin + tab1, yPos,
                                           new StringFormat());

                    ev.Graphics.DrawString(patrol.PatrolId.ToString(),
                                           printCompetitorFont, Brushes.Black, LeftMargin + tab2, yPos,
                                           new StringFormat());
                }
                Structs.Weapon weapon = CommonCode.GetWeapon(comp.WeaponId);
                ev.Graphics.DrawString(weapon.Manufacturer + ", " +
                                       weapon.Model + "(" + comp.WeaponId + ")",
                                       printCompetitorFont, Brushes.Black, LeftMargin + tab3, yPos,
                                       new StringFormat());
                yPos += printHeaderFont.GetHeight();
            }

            currentShooter++;
        }
        private void printTeamMemberResults(PrintPageEventArgs ev, ref float yPos, Structs.Competitor competitor)
        {
            try
            {
                Structs.Shooter shooter = CommonCode.GetShooter(competitor.ShooterId);
                printString(ev, shooter.Surname + " " + shooter.Givenname,
                            printCompetitorFont, this.colTeamResult, yPos, this.colTeamResultTot - this.colTeamResult);

                int hits       = 0;
                int figurehits = 0;
                foreach (Structs.CompetitorResult res in CommonCode.GetCompetitorResults(competitor.CompetitorId))
                {
                    hits       += res.Hits;
                    figurehits += res.FigureHits;
                }

                switch (CompetitionType)
                {
                case Structs.CompetitionTypeEnum.Field:
                {
                    if (competition.NorwegianCount)
                    {
                        printString(ev, (hits + figurehits).ToString(),
                                    printCompetitorFont, this.colTeamResultTot, yPos, this.colTeamPoints - this.colTeamResultTot);
                    }
                    else
                    {
                        printString(ev, hits.ToString() + "/" + figurehits.ToString(),
                                    printCompetitorFont, this.colTeamResultTot, yPos, this.colTeamPoints - this.colTeamResultTot);
                    }
                    break;
                }

                case Structs.CompetitionTypeEnum.MagnumField:
                {
                    printString(ev, hits.ToString() + "/" + figurehits.ToString(),
                                printCompetitorFont, this.colTeamResultTot, yPos, this.colTeamPoints - this.colTeamResultTot);
                    break;
                }

                case Structs.CompetitionTypeEnum.Precision:
                {
                    printString(ev, hits.ToString(),
                                printCompetitorFont, this.colTeamResultTot, yPos, this.colTeamPoints - this.colTeamResultTot);
                    break;
                }

                default:
                    throw new ApplicationException("Unknown CompetitionType");
                }
            }
            catch (Exception exc)
            {
                Trace.WriteLine("CPrintResultlist.printTeamMemberResults Exception: " + exc.ToString());
            }
        }
Beispiel #7
0
 private void createShooter(int cardnr)
 {
     Structs.Shooter shooter = new Structs.Shooter();
     shooter.CardNr    = cardnr.ToString();
     shooter.Class     = Structs.ShootersClass.Klass1;
     shooter.ClubId    = "01-001";
     shooter.Givenname = cardnr.ToString();
     shooter.Surname   = cardnr.ToString();
     intf.NewShooter(shooter);
 }
        private double writeResultsTeam(pdfPage page, double yPos, double xPos1, double xPos2, int competitorId)
        {
            double newYPos = yPos;

            Structs.Competitor competitor = myInterface.GetCompetitor(competitorId);
            Structs.Shooter    shooter    = myInterface.GetShooter(competitor.ShooterId);

            newYPos = addText(page, shooter.Surname + " " + shooter.Givenname, xPos1, yPos, font, fontResultSize);

            int hits       = 0;
            int figurehits = 0;

            foreach (Structs.CompetitorResult res in myInterface.GetCompetitorResults(competitor.CompetitorId))
            {
                hits       += res.Hits;
                figurehits += res.FigureHits;
            }

            switch (competition.Type)
            {
            case Structs.CompetitionTypeEnum.Field:
            {
                if (competition.NorwegianCount)
                {
                    addText(page, (hits + figurehits).ToString(),
                            xPos2, yPos, font, fontResultSize);
                }
                else
                {
                    addText(page, hits.ToString() + "/" + figurehits.ToString(),
                            xPos2, yPos, font, fontResultSize);
                }
                break;
            }

            case Structs.CompetitionTypeEnum.MagnumField:
            {
                addText(page, hits.ToString() + "/" + figurehits.ToString(),
                        xPos2, yPos, font, fontResultSize);
                break;
            }

            case Structs.CompetitionTypeEnum.Precision:
            {
                addText(page, hits.ToString(),
                        xPos2, yPos, font, fontResultSize);
                break;
            }

            default:
                throw new ApplicationException("Unknown CompetitionType");
            }

            return(newYPos);
        }
        private void printPatrol(ref PrintPageEventArgs ev, ref float yPos, int tab)
        {
            printPatrolHeader(ref ev, ref yPos, tab);
            Structs.Competitor[] comps = CommonCode.GetCompetitors(this.patrol, "Lane");

            foreach (Structs.Competitor comp in comps)
            {
                Structs.Shooter shooter = CommonCode.GetShooter(comp.ShooterId);
                Structs.Club    club    = CommonCode.GetClub(shooter.ClubId);

                ev.Graphics.DrawString(comp.Lane.ToString(),
                                       printCompetitorFont, Brushes.Black, this.colLane, yPos, new StringFormat());


                string name = shooter.Givenname + ", " + shooter.Surname;
                while (ev.Graphics.MeasureString(name, printCompetitorFont).Width > (colClub - colName))
                {
                    name = name.Substring(0, name.Length - 1);
                }
                ev.Graphics.DrawString(name,
                                       printCompetitorFont, Brushes.Black, this.colName, yPos, new StringFormat());


                string clubString = club.Name;
                while (ev.Graphics.MeasureString(clubString, printCompetitorFont).Width > (colResult - colClub))
                {
                    clubString = clubString.Substring(0, clubString.Length - 1);
                }
                ev.Graphics.DrawString(clubString,
                                       printCompetitorFont, Brushes.Black, colClub, yPos, new StringFormat());

                switch (CompetitionType)
                {
                case Structs.CompetitionTypeEnum.Field:
                    printCompetitorField(comp, ref ev, ref yPos);
                    break;

                case Structs.CompetitionTypeEnum.MagnumField:
                    printCompetitorMagnumField(comp, ref ev, ref yPos);
                    break;

                case Structs.CompetitionTypeEnum.Precision:
                    printCompetitorPrecision(comp, ref ev, ref yPos);
                    break;

                default:
                    throw new ApplicationException("Unknown CompetitionType");
                }
            }
        }
Beispiel #10
0
        private void populatePatrol(Structs.Patrol thisPatrol)
        {
            Trace.WriteLine("FPatrol: populatePatrol started on thread \"" +
                            Thread.CurrentThread.Name + "\" ( " +
                            Thread.CurrentThread.ManagedThreadId.ToString() + " )");

            this.datasetPatrol.shooters.Clear();

            // Populate list with competitors from this patrol
            Structs.Competitor[] competitors =
                CommonCode.GetCompetitors(thisPatrol, "Lane");

            foreach (Structs.Competitor competitor in competitors)
            {
                DatasetPatrol.shootersRow patrolRow =
                    this.datasetPatrol.shooters.NewshootersRow();

                // Fetch data for row
                Structs.Shooter shooter =
                    CommonCode.GetShooter(competitor.ShooterId);
                Structs.Club club =
                    CommonCode.GetClub(shooter.ClubId);
                Structs.Weapon weapon =
                    CommonCode.GetWeapon(competitor.WeaponId);

                // Populate row
                patrolRow.Move         = false;
                patrolRow.competitorId = competitor.CompetitorId;
                patrolRow.Name         = shooter.Givenname + " " + shooter.Surname;
                patrolRow.Club         = club.Name;
                patrolRow.Weapon       = weapon.Manufacturer + "," +
                                         weapon.Model + "," +
                                         weapon.Caliber;
                patrolRow.Lane        = competitor.Lane;
                patrolRow.WeaponClass = weapon.WClass.ToString().Substring(0, 1);

                this.datasetPatrol.shooters.AddshootersRow(patrolRow);
            }
            Trace.WriteLine("FPatrol: populatePatrol ended.");
        }
Beispiel #11
0
        internal ResultsReturn ResultsGetCompetitor(
            Structs.Competitor competitor)
        {
            Structs.Competition competition = myInterface.CompetitionCurrent;
            ResultsReturn       toReturn    =
                new ResultsReturn(
                    competition.Type,
                    competition.NorwegianCount,
                    competition.Championship);

            Structs.Shooter shooter = myInterface.GetShooter(competitor.ShooterId);

            Structs.CompetitorResult[] results =
                myInterface.GetCompetitorResults(competitor.CompetitorId);

            int figureHits = 0;
            int hits       = 0;
            int points     = 0;

            foreach (Structs.CompetitorResult result in results)
            {
                figureHits += result.FigureHits;
                hits       += result.Hits;
                points     += result.Points;

                toReturn.AddHitsPerStn(result.Hits);
                toReturn.AddFigureHitsPerStn(result.FigureHits);
                toReturn.AddPointsPerStn(result.Points);
            }

            toReturn.ClubId             = shooter.ClubId;
            toReturn.CompetitorId       = competitor.CompetitorId;
            toReturn.FigureHitsTotal    = figureHits;
            toReturn.HitsTotal          = hits;
            toReturn.PointsTotal        = points;
            toReturn.ShooterName        = shooter.Surname + " " + shooter.Givenname;
            toReturn.FinalShootingPlace = competitor.FinalShootingPlace;
            return(toReturn);
        }
Beispiel #12
0
        private void populateUnassigned(Structs.PatrolClass thisClass)
        {
            Trace.WriteLine("FPatrol: populateCompetitorList started on thread \"" +
                            Thread.CurrentThread.Name + "\" ( " +
                            Thread.CurrentThread.ManagedThreadId.ToString() + " )");

            this.datasetPatrol.unassigned.Clear();

            // Populate list with competitors, not yet assigned to a patrol
            Structs.Competitor[] competitors =
                CommonCode.GetCompetitorsWithNoPatrol(thisClass);

            foreach (Structs.Competitor competitor in competitors)
            {
                DatasetPatrol.unassignedRow patrolRow =
                    this.datasetPatrol.unassigned.NewunassignedRow();

                // Fetch data for row
                Structs.Shooter shooter =
                    CommonCode.GetShooter(competitor.ShooterId);
                Structs.Club club =
                    CommonCode.GetClub(shooter.ClubId);
                Structs.Weapon weapon =
                    CommonCode.GetWeapon(competitor.WeaponId);

                // Populate row
                patrolRow.Move         = false;
                patrolRow.competitorId = competitor.CompetitorId;
                patrolRow.Name         = shooter.Givenname + " " + shooter.Surname;
                patrolRow.Club         = club.Name;
                patrolRow.Weapon       = weapon.Manufacturer + "," +
                                         weapon.Model;
                patrolRow.WeaponClass = weapon.WClass.ToString();

                this.datasetPatrol.unassigned.AddunassignedRow(patrolRow);
            }

            Trace.WriteLine("FPatrol: populateCompetitorList ended.");
        }
        private double writePatrol(ref pdfPage page, Structs.Patrol patrol, ref double yPos)
        {
            if (yPos + conversionPixelsToMM * fontSize > bottomMargin)
            {
                page = getNewPage(ref yPos);
                yPos = writePatrolHeader(page, yPos);
            }
            addText(page, patrol.PatrolId.ToString() + " ( " + patrol.StartDateTimeDisplay.ToShortTimeString() + " )",
                    columnPatrolsPatrolPos, yPos, font, fontSize);

            foreach (Structs.Competitor comp in myInterface.GetCompetitors(patrol))
            {
                if (yPos + conversionPixelsToMM * fontSize > bottomMargin)
                {
                    page = getNewPage(ref yPos);
                    yPos = writePatrolHeader(page, yPos);
                }
                Structs.Shooter shooter      = myInterface.GetShooter(comp.ShooterId);
                Structs.Club    club         = myInterface.GetClub(shooter.ClubId);
                Structs.Weapon  weapon       = myInterface.GetWeapon(comp.WeaponId);
                string          weaponString = getWeapon(weapon);

                addText(page, shooter.Givenname + ", " + shooter.Surname,
                        columnPatrolsNamePos, yPos,
                        columnPatrolsClubNamePos - columnPatrolsNamePos,
                        font, fontSize);
                addText(page, club.Name,
                        columnPatrolsClubNamePos, yPos,
                        columnPatrolsWeaponPos - columnPatrolsClubNamePos,
                        font, fontSize);
                yPos = addText(page, weaponString,
                               columnPatrolsWeaponPos, yPos, font, fontSize);

                yPos += 1;
            }
            return(yPos);
        }
        private void timerAddShooters()
        {
            try
            {
                lock (timerAddShootersRunningLock)
                {
                    if (timerAddShootersRunning)
                    {
                        return;
                    }
                    timerAddShootersRunning = true;
                }
                Trace.WriteLine("timerAddShooters_Tick on Thread \" " +
                                Thread.CurrentThread.Name + "\"" +
                                Thread.CurrentThread.ManagedThreadId.ToString());

                Structs.Shooter shooter = new Structs.Shooter();
                shooter.Automatic = false;
                shooter.CardNr    = rnd.Next(100000).ToString();
                int shooterClassInt = -1;
                while (((Structs.ShootersClass)shooterClassInt).ToString() ==
                       shooterClassInt.ToString())
                {
                    shooterClassInt = rnd.Next(2) + 1;
                }
                shooter.Class       = (Structs.ShootersClass)shooterClassInt;
                shooter.ClubId      = "01-417";
                shooter.Email       = "*****@*****.**";
                shooter.Givenname   = shooter.CardNr;
                shooter.Payed       = 0;
                shooter.Surname     = shooter.CardNr;
                shooter.ToAutomatic = false;
                int shooterId = CommonCode.NewShooter(shooter);

                int nrOfCompetitors = 1 + rnd.Next(3);
                for (int i = 0; i < nrOfCompetitors; i++)
                {
                    Structs.Competitor comp = new Structs.Competitor();
                    comp.CompetitionId = CommonCode.GetCompetitions()[0].CompetitionId;
                    while (comp.Lane == 0)
                    {
                        try
                        {
                            comp.PatrolId = 1 + rnd.Next(80);
                            bool retry = true;
                            while (retry)
                            {
                                try
                                {
                                    CommonCode.GetPatrol(comp.PatrolId);
                                    retry = false;
                                }
                                catch (Allberg.Shooter.Common.CannotFindIdException)
                                {
                                    CommonCode.PatrolAddEmpty();
                                }
                            }
                            comp.Lane = CommonCode.PatrolGetNextLane(comp.PatrolId);
                        }
                        catch (Exception)
                        {
                        }
                    }
                    comp.ShooterClass = shooter.Class;
                    comp.ShooterId    = shooterId;
                    comp.WeaponId     = "G9-A1";
                    CommonCode.NewCompetitor(comp);
                }
            }
            catch (Exception exc)
            {
                Trace.WriteLine("Exception while adding competitor:" + exc.ToString());
            }
            finally
            {
                timerAddShootersRunning = false;
            }
        }
        private void printThisCompetitor(PrintPageEventArgs ev,
                                         Structs.Competitor comp, ref float yPos)
        {
            Structs.Shooter shooter = CommonCode.GetShooter(comp.ShooterId);
            Structs.Club    club    = CommonCode.GetClub(shooter.ClubId);
            Structs.Weapon  weapon  = CommonCode.GetWeapon(comp.WeaponId);

            // Print name
            string shooterName = shooter.Surname + " " + shooter.Givenname +
                                 ", " + club.Name;

            ev.Graphics.DrawString(shooterName,
                                   printCompetitorFont, Brushes.Black, placeNameX, yPos,
                                   new StringFormat());

            // Print Club

            /*ev.Graphics.DrawString(club.Name,
             *      printCompetitorFont, Brushes.Black, placeClubX, yPos,
             *      new StringFormat());*/

            // Print weaponsgroup
            ev.Graphics.DrawString(weapon.WClass.ToString(),
                                   printCompetitorFont, Brushes.Black, placeLeftHeaderX, yPos + 2 * printCompetitorFont.Height,
                                   new StringFormat());

            // Print shooterclass
            Structs.ShootersClassShort sclassshort = (Structs.ShootersClassShort)
                                                         (int) comp.ShooterClass;
            ev.Graphics.DrawString(sclassshort.ToString(),
                                   printCompetitorFont, Brushes.Black, placeLeftHeaderX, yPos + 4 * printCompetitorFont.Height,
                                   new StringFormat());

            // Print weapon
            if (comp.WeaponId.ToLower().IndexOf("unknown") == -1)
            {
                ev.Graphics.DrawString(comp.WeaponId.Replace("Unknown", ""),
                                       printCompetitorFont, Brushes.Black, placeLeftHeaderX, yPos + 6 * printCompetitorFont.Height,
                                       new StringFormat());
            }

            // Draw "arrived" checkbox
            float size   = printCompetitorFont.Height;
            float left   = placeNameX + ev.Graphics.MeasureString(shooterName, printCompetitorFont).Width + 10;
            float height = yPos;

            ev.Graphics.DrawString("Ankommit",
                                   printCompetitorFont, Brushes.Black, left + size, height,
                                   new StringFormat());
            Pen pen = new Pen(Brushes.Black, 2);

            ev.Graphics.DrawLine(pen, left, height,
                                 left + size, height);
            ev.Graphics.DrawLine(pen, left, height + size,
                                 left + size, height + size);
            ev.Graphics.DrawLine(pen, left, height,
                                 left, height + size);
            ev.Graphics.DrawLine(pen, left + size, height,
                                 left + size, height + size);
            if (shooter.Arrived)
            {
                ev.Graphics.DrawLine(pen, left, height,
                                     left + size, height + size);
                ev.Graphics.DrawLine(pen, left + size, height,
                                     left, height + size);
            }

            printEmptyCompetitor(ev, ref yPos, comp.Lane);
        }
Beispiel #16
0
        //Override the OnPrintPage to provide the printing logic for the document
        protected override void OnPrintPage(PrintPageEventArgs ev)
        {
            Trace.WriteLine("CPrintPatrollistByUser: OnPrintPage started" +
                            " on thread \"" + Thread.CurrentThread.Name + "\" ( " +
                            Thread.CurrentThread.ManagedThreadId.ToString() + " )");

            base.OnPrintPage(ev);

            //Work out the number of lines per page
            //Use the MarginBounds on the event to do this
            //lpp = ev.MarginBounds.Height  / printFont.GetHeight(ev.Graphics) ;
            float topMargin = ev.MarginBounds.Top;

            topMargin = 25;
            float yPos = topMargin;

            //Now print what we want to print
            Structs.Shooter shooter = new Structs.Shooter();
            if (ShooterIdToPrint != -1)
            {
                shooter = CommonCode.GetShooter(ShooterIdToPrint);
            }
            else
            {
                string temp = null;
                while (temp == null & CommonCode.GetShooterHighestId() >= currentShooter)
                {
                    try
                    {
                        shooter = CommonCode.GetShooter(this.currentShooter);
                        temp    = "found shooter";
                    }
                    catch (Common.CannotFindIdException exc)
                    {
                        Trace.WriteLine("CPrintPatrollistByUser: OnPrintPage Exception " +
                                        exc.ToString());
                        temp = null;
                        currentShooter++;
                    }
                }
            }
            printHeader(ev, shooter, ref yPos);
            printShooter(ev, shooter, ref yPos);

            //If we have more patrols then print another page
            if (this.shooterIdToPrint == -1)
            {
                if (CommonCode.GetShooterHighestId() >= this.currentShooter)
                {
                    ev.HasMorePages = true;
                }
                else
                {
                    ev.HasMorePages = false;
                }
            }
            else
            {
                ev.HasMorePages = false;
            }
        }
Beispiel #17
0
        private void printHeader(PrintPageEventArgs ev,
                                 Structs.Shooter shooter, ref float yPos)
        {
            int tab = 125;

            // Print RegistrationsInfo
            ev.Graphics.DrawString(
                "WinShooter",
                printAllbergFont, Brushes.Black,
                LeftMargin, ev.PageBounds.Size.Height - 2 * printHeaderFont.GetHeight() - 20, new StringFormat());

            /*ev.Graphics.DrawString("©John Allberg",
             *      printHeaderFont, Brushes.Black, ev.PageBounds.Right-180,
             *      ev.PageBounds.Size.Height -2*printHeaderFont.GetHeight()-20,
             *      new StringFormat());*/

            // Print logo
            System.Drawing.Image image = getLogo();

            ev.Graphics.DrawImage(
                image,
                ev.MarginBounds.Right - image.Width / 4,
                20,
                image.Width / 4,
                image.Height / 4);

            // Print patrol header
            ev.Graphics.DrawString("Tävling: ",
                                   printHeaderFont, Brushes.Black, LeftMargin, yPos,
                                   new StringFormat());
            ev.Graphics.DrawString(CommonCode.GetCompetitions()[0].Name,
                                   printHeaderFont, Brushes.Black, LeftMargin + tab, yPos,
                                   new StringFormat());
            yPos += printHeaderFont.GetHeight();

            ev.Graphics.DrawString("Namn: ",
                                   printHeaderFont, Brushes.Black, LeftMargin, yPos,
                                   new StringFormat());
            ev.Graphics.DrawString(shooter.Surname + " " + shooter.Givenname,
                                   printHeaderFont, Brushes.Black, LeftMargin + tab, yPos,
                                   new StringFormat());
            yPos += printHeaderFont.GetHeight();

            ev.Graphics.DrawString("Skyttekort: ",
                                   printHeaderFont, Brushes.Black, LeftMargin, yPos,
                                   new StringFormat());
            ev.Graphics.DrawString(shooter.CardNr,
                                   printHeaderFont, Brushes.Black, LeftMargin + tab, yPos,
                                   new StringFormat());
            yPos += printHeaderFont.GetHeight();

            ev.Graphics.DrawString("Skytteklubb: ",
                                   printHeaderFont, Brushes.Black, LeftMargin, yPos,
                                   new StringFormat());
            Structs.Club club = CommonCode.GetClub(shooter.ClubId);
            ev.Graphics.DrawString(club.Name,
                                   printHeaderFont, Brushes.Black, LeftMargin + tab, yPos,
                                   new StringFormat());
            yPos += printHeaderFont.GetHeight();
            yPos += printHeaderFont.GetHeight();
            yPos += printHeaderFont.GetHeight();

            ev.Graphics.DrawString("Starttid",
                                   printHeaderFont, Brushes.Black, LeftMargin + tab1, yPos,
                                   new StringFormat());
            ev.Graphics.DrawString("Patrull",
                                   printHeaderFont, Brushes.Black, LeftMargin + tab2, yPos,
                                   new StringFormat());
            ev.Graphics.DrawString("Vapen",
                                   printHeaderFont, Brushes.Black, LeftMargin + tab3, yPos,
                                   new StringFormat());
            yPos += printHeaderFont.GetHeight();
        }
Beispiel #18
0
 private string GetNameForCompetitor(Structs.Competitor comp)
 {
     Structs.Shooter shooter = myInterface.GetShooter(comp.ShooterId);
     return(shooter.Surname + " " + shooter.Givenname);
 }
Beispiel #19
0
        /// <summary>
        /// Updates a shooter in the local cache file
        /// </summary>
        /// <param name="shooter"></param>
        internal void UpdateShooterInCache(Structs.Shooter shooter)
        {
            if (int.Parse(shooter.CardNr) < 0)
            {
                return;
            }

            var rows =
                (DSLocalCache.ShootersRow[])
                _localCache.Shooters.Select(
                    "CardNr='" + shooter.CardNr + "'");

            DSLocalCache.ShootersRow row;
            if (rows.Length > 0)
            {
                row = rows[0];
            }
            else
            {
                row = _localCache.Shooters.NewShootersRow();
                _localCache.Shooters.AddShootersRow(row);
            }

            bool updated = false;

            #region check all attributes
            if (row.IsCardnrNull() ||
                row.Cardnr != shooter.CardNr)
            {
                row.Cardnr = shooter.CardNr;
                updated    = true;
            }
            if (row.IsClassNull() ||
                row.Class != (int)shooter.Class)
            {
                row.Class = (int)shooter.Class;
                updated   = true;
            }
            if (row.IsClubIdNull() ||
                row.ClubId != shooter.ClubId)
            {
                row.ClubId = shooter.ClubId;
                updated    = true;
            }
            if (row.IsEmailNull() ||
                row.Email != shooter.Email)
            {
                row.Email = shooter.Email;
                updated   = true;
            }
            if (row.IsGivennameNull() ||
                row.Givenname != shooter.Givenname)
            {
                row.Givenname = shooter.Givenname;
                updated       = true;
            }
            if (row.IsSurnameNull() ||
                row.Surname != shooter.Surname)
            {
                row.Surname = shooter.Surname;
                updated     = true;
            }
            #endregion

            if (updated)
            {
                row.LastUpdate = DateTime.Now;
                UpdateLocalCache();
            }
        }
Beispiel #20
0
        private void ImportDatasetThread()
        {
            Trace.WriteLine("CFileImport: ImportDatasetThread started " +
                            "on thread \"" + Thread.CurrentThread.Name + "\" ( " +
                            System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() + " )");

            int i = -1;

            foreach (DataRow row in this.ViewDatatable.Rows)
            {
                i++;
                string classString = null;

                Trace.WriteLine("CFileImport: ImportDatasetThread calling " +
                                "updatedFileImportCount(" + i.ToString() + ", " +
                                ViewDatatable.Rows.Count.ToString() + ")");
                myInterface.updatedFileImportCount(
                    i, ViewDatatable.Rows.Count);

                // Get shooter
                string shooterCard = (string)row[viewTableColumnNames.Skyttekort.ToString().Trim()];

                // Get shooter from DB
                Structs.Shooter shooter;
                try
                {
                    shooter = myInterface.GetShooter(shooterCard);

                    classString = (string)row[viewTableColumnNames.Klass.ToString()];
                    if (classString.IndexOf("1") >= 0)
                    {
                        shooter.Class = Structs.ShootersClass.Klass1;
                    }
                    if (classString.IndexOf("2") >= 0)
                    {
                        shooter.Class = Structs.ShootersClass.Klass2;
                    }
                    if (classString.IndexOf("3") >= 0)
                    {
                        shooter.Class = Structs.ShootersClass.Klass3;
                    }

                    myInterface.UpdateShooter(shooter);
                }
                catch (CannotFindIdException)
                {
                    // Add user to DB with values from file.
                    shooter = new Structs.Shooter();
                    // What class?
                    classString = (string)row[viewTableColumnNames.Klass.ToString()];
                    Structs.ShootersClass sclass = Structs.ShootersClass.Klass1;
                    if (classString.IndexOf("1") >= 0)
                    {
                        sclass = Structs.ShootersClass.Klass1;
                    }
                    if (classString.IndexOf("2") >= 0)
                    {
                        sclass = Structs.ShootersClass.Klass2;
                    }
                    if (classString.IndexOf("3") >= 0)
                    {
                        sclass = Structs.ShootersClass.Klass3;
                    }

                    if (shooterCard == "")
                    {
                        try
                        {
                            Random rnd = new Random();
                            while (true)
                            {
                                shooterCard = (-rnd.Next(100000)).ToString();
                                myInterface.GetShooter(shooterCard);
                            }
                        }
                        catch (CannotFindIdException)
                        {
                        }
                    }
                    // Create shooter and insert into database
                    shooter.Automatic   = false;
                    shooter.CardNr      = shooterCard.ToString();
                    shooter.Class       = sclass;
                    shooter.ClubId      = ((string)row[viewTableColumnNames.Klubb.ToString()]).Trim();
                    shooter.Email       = ((string)row[viewTableColumnNames.Epost.ToString()]).Trim();
                    shooter.Givenname   = ((string)row[viewTableColumnNames.Efternamn.ToString()]).Trim();
                    shooter.Surname     = ((string)row[viewTableColumnNames.Fornamn.ToString()]).Trim();
                    shooter.Payed       = 0;
                    shooter.ToAutomatic = false;

                    shooter.ShooterId = myInterface.NewShooter(shooter, false);
                    if (shooter.ShooterId < 0)
                    {
                        throw new ApplicationException("ShooterId is " + shooter.ShooterId);
                    }
                }

                // Ok, shooter is done. Create competitor
                classString = (string)row[viewTableColumnNames.Klass.ToString().ToUpper()];
                Structs.ShootersClass cclass = shooter.Class;
                if (classString.IndexOf("D") >= 0)
                {
                    cclass = (Structs.ShootersClass)(
                        (int)Structs.ShootersClass.Damklass1 - 1 +
                        (int)cclass);
                }
                if (classString.IndexOf("J") >= 0)
                {
                    cclass = Structs.ShootersClass.Juniorklass;
                }
                if (classString.IndexOf("VY") >= 0)
                {
                    cclass = Structs.ShootersClass.VeteranklassYngre;
                }
                if (classString.IndexOf("VÄ") >= 0)
                {
                    cclass = Structs.ShootersClass.VeteranklassÄldre;
                }
                if (classString.IndexOf("Ö") >= 0)
                {
                    cclass = Structs.ShootersClass.Öppen;
                }

                // Phu, class is done. Continue with competitor
                Structs.Competitor competitor = new Structs.Competitor();
                competitor.CompetitionId = myInterface.GetCompetitions()[0].CompetitionId;
                competitor.ShooterId     = shooter.ShooterId;
                competitor.WeaponId      = (string)row[viewTableColumnNames.Vapen.ToString()];
                competitor.PatrolId      = -1;
                competitor.Lane          = -1;
                competitor.ShooterClass  = cclass;

                if (!row.IsNull(viewTableColumnNames.Patrull.ToString()) &&
                    ((string)row[viewTableColumnNames.Patrull.ToString()]).Trim() != "")
                {
                    try
                    {
                        // Patrol defined in importfile
                        string patrolString = (string)row[viewTableColumnNames.Patrull.ToString()];
                        int    patrolId     = -1;
                        patrolId = int.Parse(patrolString);
                        while (patrolId > myInterface.GetPatrolsCount())
                        {
                            myInterface.PatrolAddEmpty(false);
                        }
                        competitor.PatrolId = patrolId;
                        string laneString = null;
                        if (!row.IsNull(viewTableColumnNames.Bana.ToString()))
                        {
                            laneString = (string)row[viewTableColumnNames.Bana.ToString()];
                        }

                        if (laneString != null &&
                            laneString.Trim() != "")
                        {
                            competitor.Lane = int.Parse(laneString);
                        }
                        else
                        {
                            competitor.Lane = myInterface.PatrolGetNextLane(patrolId);
                        }
                    }
                    catch (System.FormatException)
                    {
                        // If this occurres, just ignore. It really shouldn't, since
                        // it has already been checked
                    }
                }

                myInterface.NewCompetitor(competitor, false);
            }

            myInterface.updatedFileImportCount(
                ViewDatatable.Rows.Count,
                ViewDatatable.Rows.Count);
            myInterface.updatedShooter(new Structs.Shooter());
            myInterface.updatedCompetitor(new Structs.Competitor());
            myInterface.updatedPatrol();
        }