//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;
            }
        }
        private double writePatrolByClub(ref pdfPage page, Structs.Shooter[] shooters, ref double yPos)
        {
            Structs.Club club = myInterface.GetClub(shooters[0].ClubId);

            if (yPos + conversionPixelsToMM * (2 * fontSize + fontHeaderSize) > bottomMargin)
            {
                // Paging
                page = getNewPage(ref yPos);
                yPos = writePatrolByClubHeader(page, yPos);
            }
            addText(page, club.ClubId,
                    columnPatrolsByClubClubIdPos, yPos, fontHeader, fontHeaderSize);
            yPos = addText(page, club.Name,
                           columnPatrolsByClubNamePos, yPos, fontHeader, fontHeaderSize);

            foreach (Structs.Shooter shooter in shooters)
            {
                if (yPos + 2 * conversionPixelsToMM * fontSize > bottomMargin)
                {
                    // Paging
                    page = getNewPage(ref yPos);
                    yPos = writePatrolByClubHeader(page, yPos);
                }
                foreach (Structs.Competitor comp in myInterface.GetCompetitors(shooter.ShooterId, "PatrolId"))
                {
                    if (yPos + 2 * conversionPixelsToMM * fontSize > bottomMargin)
                    {
                        // Paging
                        page = getNewPage(ref yPos);
                        yPos = writePatrolByClubHeader(page, yPos);
                    }

                    if (comp.PatrolId >= 1)
                    {
                        Structs.Patrol patrol     = myInterface.GetPatrol(comp.PatrolId);
                        string         weaponText = getWeapon(myInterface.GetWeapon(comp.WeaponId));

                        addText(page, shooter.Givenname + ", " + shooter.Surname,
                                columnPatrolsByClubNamePos, yPos, font, fontSize);
                        addText(page, patrol.PatrolId.ToString() + " (" +
                                patrol.StartDateTimeDisplay.ToShortTimeString() + ")",
                                columnPatrolsByClubPatrolPos, yPos, font, fontSize);
                        addText(page, weaponText,
                                columnPatrolsByClubWeaponPos, yPos, font, fontSize);

                        Structs.ShootersClassShort sc = (Structs.ShootersClassShort)(int) comp.ShooterClass;
                        string classText = sc.ToString().Replace("Klass", "").Replace("Damklass", "D");
                        classText += myInterface.GetWeapon(comp.WeaponId).WClass.ToString().Substring(0, 1);

                        yPos = addText(page, classText,
                                       columnPatrolsByClubClassPos, yPos, font, fontSize);

                        yPos += 1;
                    }
                }
            }

            return(yPos + 5);
        }
Example #3
0
 private void createClub()
 {
     Structs.Club club = new Structs.Club();
     club.Country = "SE";
     club.Name    = "Club1";
     club.ClubId  = "01-001";
     intf.NewClub(club);
 }
        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");
                }
            }
        }
Example #5
0
        private void populateCompetitors()
        {
            Trace.WriteLine("FCompetitors: DdClubs_SelectedIndexChanged() " +
                            "started on thread \"" +
                            Thread.CurrentThread.Name +
                            "\" ( " +
                            Thread.CurrentThread.ManagedThreadId.ToString() +
                            " )");

            Structs.Club club =
                CommonCode.GetClub(
                    (string)this.DdClubs.SelectedValue);
            Structs.ResultWeaponsClass wclass =
                (Structs.ResultWeaponsClass)
                    (int) this.ddWeaponClass.SelectedValue;

            // Get all shooters that belong to the current club and
            // have a competitor with the current class
            //Structs.Shooter[] shooters = CommonCode.GetShooters(club, wclass);
            Structs.Competitor[] comps = CommonCode.GetCompetitors(club, wclass, "Surname, Givenname");

            DatasetTeams ds1 = new DatasetTeams();
            DatasetTeams ds2 = new DatasetTeams();
            DatasetTeams ds3 = new DatasetTeams();
            DatasetTeams ds4 = new DatasetTeams();
            DatasetTeams ds5 = new DatasetTeams();

            shooters = new Hashtable();
            addShootersToDS(ds1, comps);
            addShootersToDS(ds2, comps);
            addShootersToDS(ds3, comps);
            addShootersToDS(ds4, comps);
            addShootersToDS(ds5, comps);

            // Bind the dropdowns to the datatable
            this.ddCompetitor1.DataSource = ds1.Competitors;
            this.ddCompetitor2.DataSource = ds2.Competitors;
            this.ddCompetitor3.DataSource = ds3.Competitors;
            this.ddCompetitor4.DataSource = ds4.Competitors;
            this.ddCompetitor5.DataSource = ds5.Competitors;

            Trace.WriteLine("FCompetitors: DdClubs_SelectedIndexChanged() ended.");
        }
Example #6
0
 private void DdClubsSelectedIndexChanged(object sender, EventArgs e)
 {
     if ((string)_ddClubs.SelectedValue == NewClubValue)
     {
         // Clean up
         RestoreWindow();
     }
     else
     {
         Structs.Club club =
             _commonCode.GetClub((string)_ddClubs.SelectedValue);
         _txtName.Text            = club.Name;
         _txtOfficialName.Text    = club.ClubId;
         _txtOfficialName.Enabled = false;
         _txtPgInfo.Text          = FormatGiro.FormatPlusgiro(club.Plusgiro);
         _txtBgInfo.Text          = FormatGiro.FormatBankgiro(club.Bankgiro);
         _ddCountry.SelectedValue = club.Country;
         _btnDelete.Enabled       = true;
     }
     _btnSave.Enabled = false;
 }
Example #7
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.");
        }
Example #8
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);
        }
Example #10
0
        private void BtnSaveClick(object sender, EventArgs e)
        {
            // Validation
            if (_txtOfficialName.Text.Length == 0 |
                _txtName.Text.Length == 0)
            {
                MessageBox.Show("Varken den officiella beteckning eller " +
                                "namnet får vara blankt.",
                                "Inmatningsfel",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return;
            }

            try
            {
                int.Parse(_txtOfficialName.Text.Replace("-", ""));
            }
            catch (Exception)
            {
                MessageBox.Show("Den officella beteckningen består endast av tal" +
                                " och 1 minustecken.",
                                "Inmatningsfel",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return;
            }

            try
            {
                if (!PostgiroIsValid(_txtPgInfo.Text.Replace("-", "").Replace(" ", "")))
                {
                    MessageBox.Show("Postgiroinformationen verkar vara felaktig.",
                                    "Inmatningsfel",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                    return;
                }

                if (!BankgiroIsValid(_txtBgInfo.Text.Replace("-", "").Replace(" ", "")))
                {
                    MessageBox.Show("Bankgiroinformationen verkar vara felaktig.",
                                    "Inmatningsfel",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                    return;
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Postgiro- och/eller Bankgiroinformationen verkar vara felaktig.",
                                "Inmatningsfel",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return;
            }


            // Save
            if ((string)_ddClubs.SelectedValue == NewClubValue)
            {
                // New club
                // Check if club exists
                try
                {
                    var temp = _commonCode.GetClub(_txtOfficialName.Text);
                    MessageBox.Show("Det finns redan en klubb med det officiella namnet \"" +
                                    _txtOfficialName.Text +
                                    "\". Den heter \"" +
                                    temp.Name +
                                    "\"", "Felmeddelande", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }
                catch (Common.CannotFindIdException)
                {
                    // Do nothing, continue
                }

                var club = new Structs.Club
                {
                    ClubId      = _txtOfficialName.Text,
                    Name        = _txtName.Text,
                    Country     = (string)_ddCountry.SelectedValue,
                    Automatic   = false,
                    ToAutomatic = false,
                    Plusgiro    = _txtPgInfo.Text.Replace(" ", ""),
                    Bankgiro    = _txtBgInfo.Text.Replace(" ", "")
                };
                if (_commonCode.EnableInternetConnections)
                {
                    DialogResult res =
                        MessageBox.Show("Vill du lägga till klubben \"" +
                                        _txtName.Text + "\" till Internet-databasen?",
                                        "Internet-databasen", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (DialogResult.Yes == res)
                    {
                        club.ToAutomatic = true;
                    }
                }
                _commonCode.NewClub(club);
            }
            else
            {
                // Edit existing club
                var club = _commonCode.GetClub((string)_ddClubs.SelectedValue);
                club.Country     = (string)_ddCountry.SelectedValue;
                club.Name        = _txtName.Text;
                club.ToAutomatic = false;
                club.Plusgiro    = _txtPgInfo.Text.Replace(" ", "");
                club.Bankgiro    = _txtBgInfo.Text.Replace(" ", "");
                if (_commonCode.EnableInternetConnections)
                {
                    var res =
                        MessageBox.Show("Vill du uppdatera klubben \"" +
                                        _txtName.Text + "\" i Internet-databasen?",
                                        "Internet-databasen", MessageBoxButtons.YesNo,
                                        MessageBoxIcon.Question);
                    if (DialogResult.Yes == res)
                    {
                        club.ToAutomatic = true;
                    }
                }
                _commonCode.UpdateClub(club);
            }

            RestoreWindow();
        }
        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);
        }
Example #12
0
        private void printCompetitor(PrintPageEventArgs ev,
                                     Structs.Competitor competitor,
                                     PrintLabel label)
        {
            Trace.WriteLine("Competitor: " + competitor.CompetitorId);

            ResultsReturn result = CommonCode.ResultsGetCompetitor(competitor);

            float y = label.Y + label.MarginalTop;
            float x = label.X + label.MarginalLeft;

            string shooterClass = getShooterClassString(
                CommonCode.GetCompetitor(result.CompetitorId));

            ev.Graphics.DrawString(
                shooterClass,
                printFont, Brushes.Black,
                x, y, new StringFormat());

            float indent = ev.Graphics.MeasureString("RES", printFont).Width;

            x = x + indent;

            ev.Graphics.DrawString(
                result.ShooterName,
                printFont, Brushes.Black,
                x, y, new StringFormat());
            y += printFont.Height;

            Structs.Club club = CommonCode.GetClub(
                result.ClubId);

            ev.Graphics.DrawString(
                club.Name,
                printFont, Brushes.Black,
                x, y, new StringFormat());
            y += printFont.Height;

            string resultString = "";

            switch (CommonCode.CompetitionCurrent.Type)
            {
            case Structs.CompetitionTypeEnum.Field:
                resultString = getResultStringField(result);
                break;

            case Structs.CompetitionTypeEnum.MagnumField:
                resultString = getResultStringField(result);
                break;

            case Structs.CompetitionTypeEnum.Precision:
                resultString = result.HitsTotal.ToString() + " p";
                break;
            }

            ev.Graphics.DrawString(
                resultString,
                printFont, Brushes.Black,
                x, y, new StringFormat());

            y += printFont.Height;
        }
Example #13
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();
        }
Example #14
0
        /// <summary>
        /// Updates a club in cache
        /// </summary>
        /// <param name="club"></param>
        internal void UpdateClubInCache(Structs.Club club)
        {
            var rows =
                (DSLocalCache.ClubsRow[])
                _localCache.Clubs.Select(
                    "ClubId='" + club.ClubId + "'");

            DSLocalCache.ClubsRow row;
            if (rows.Length > 0)
            {
                row = rows[0];
            }
            else
            {
                row = _localCache.Clubs.NewClubsRow();
                _localCache.Clubs.AddClubsRow(row);
            }

            bool updated = false;

            #region check all attributes
            if (row.IsClubIdNull() ||
                row.ClubId != club.ClubId)
            {
                row.ClubId = club.ClubId;
                updated    = true;
            }
            if (row.IsCountryNull() ||
                row.Country != club.Country)
            {
                row.Country = club.Country;
                updated     = true;
            }
            if (row.IsEmailNull() ||
                row.Email != club.Email)
            {
                row.Email = club.Email;
                updated   = true;
            }
            if (row.IsNameNull() ||
                row.Name != club.Name)
            {
                row.Name = club.Name;
                updated  = true;
            }
            if (row.IsPlusgiroNull() ||
                row.Plusgiro != club.Plusgiro)
            {
                row.Plusgiro = club.Plusgiro;
                updated      = true;
            }
            if (row.IsBankgiroNull() ||
                row.Bankgiro != club.Bankgiro)
            {
                row.Bankgiro = club.Bankgiro;
                updated      = true;
            }
            #endregion

            if (updated)
            {
                row.LastUpdate = DateTime.Now;
                UpdateLocalCache();
            }
        }
        private void printHeader(PrintPageEventArgs ev, ref float yPos, int tab)
        {
            float leftMargin = 50;

            // Print watermark "Preliminär"
            if (printPrelResults)
            {
                ev.Graphics.RotateTransform(45);

                Font prelFont = new Font("Arial", 90,
                                         System.Drawing.FontStyle.Regular);

                ev.Graphics.DrawString("Preliminärresultat",
                                       prelFont,
                                       Brushes.LightGray,
                                       ev.MarginBounds.Left,
                                       0,
                                       new StringFormat());

                ev.Graphics.RotateTransform(-45);
            }

            // 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 page 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("Vapengrupp: ",
                                   printHeaderFont, Brushes.Black, leftMargin, yPos,
                                   new StringFormat());
            ev.Graphics.DrawString(wclass.ToString(),
                                   printHeaderFont, Brushes.Black, leftMargin + tab, yPos,
                                   new StringFormat());
            yPos += printHeaderFont.GetHeight();

            if (this.clubId != null)
            {
                Structs.Club club = CommonCode.GetClub(clubId);
                ev.Graphics.DrawString("Skytteklubb: ",
                                       printHeaderFont, Brushes.Black, leftMargin, yPos,
                                       new StringFormat());

                ev.Graphics.DrawString(club.Name,
                                       printHeaderFont, Brushes.Black, leftMargin + tab, yPos,
                                       new StringFormat());
                yPos += printHeaderFont.GetHeight();
            }
            //

            // Print allberg on bottom
            ev.Graphics.DrawString("Utskriven " + DateTime.Now.ToShortDateString() + " " +
                                   DateTime.Now.ToShortTimeString(),
                                   printAllbergFont, Brushes.Black, ev.PageBounds.Right - 250,
                                   ev.PageBounds.Size.Height - 2 * printHeaderFont.GetHeight() - 20,
                                   new StringFormat());
        }
        private double writeResultsTeam(pdfPage page, double yPos, ResultsReturnTeam result, int place)
        {
            double newYPos = yPos;

            Structs.Club club = myInterface.GetClub(result.ClubId);
            if (competition.CompetitionId == 0)
            {
                competition = myInterface.GetCompetitions()[0];
            }

            addText(page, place.ToString(), this.leftMargin, yPos, font, fontResultSize);
            addText(page, result.TeamName, this.colResultNamePos, yPos, colResultClubPos - colResultNamePos, font, fontResultSize);
            addText(page, club.Name, this.colResultClubPos, yPos, colResultResultPos - colResultClubPos, font, fontResultSize);
            switch (competition.Type)
            {
            case Structs.CompetitionTypeEnum.Field:
            {
                if (competition.NorwegianCount)
                {
                    addText(page, (result.Hits + result.FigureHits).ToString(),
                            colResultTotPos, yPos, font, fontResultSize);
                }
                else
                {
                    addText(page, result.Hits.ToString() + "/" + result.FigureHits.ToString(),
                            colResultTotPos, yPos, font, fontResultSize);
                }
                addText(page, result.Points.ToString(),
                        this.colResultPointsPos, yPos, font, fontResultSize);
                break;
            }

            case Structs.CompetitionTypeEnum.Precision:
            {
                addText(page, result.Hits.ToString(),
                        this.colResultPointsPos, yPos, font, fontResultSize);
                break;
            }

            default:
                throw new ApplicationException("Not implemented yet");
            }

            /*if (competition.UsePriceMoney &&
             *      result.PriceMoney != 0)
             * {
             *      newYPos = addText(page, result.PriceMoney.ToString() + ":-",
             *              this.colResultPricePos, yPos, font, fontResultSize);
             * }*/

            string[] HitsPerStn = result.HitsPerStn.Split(';');
            double   xPos       = colResultResultPos;
            double   xMaxPos    = colResultTotPos;

            foreach (string thisStn in HitsPerStn)
            {
                int maxXSizeInPoints = (int)((xMaxPos - xPos) / conversionPixelsToMM);
                if (font.getWordWidth(thisStn, fontSize) > maxXSizeInPoints)
                {
                    xPos = colResultResultPos;
                    yPos = newYPos;
                }
                newYPos = addText(page, thisStn, xPos, yPos, font, fontResultSize);
                xPos   += conversionPixelsToMM * font.getWordWidth(thisStn, fontSize);
            }

            Structs.Team team = myInterface.GetTeam(result.TeamId);

            foreach (int compid in (int[])team.CompetitorIds.ToArray(typeof(int)))
            {
                newYPos = writeResultsTeam(page, newYPos, colResultResultPos, colResultTotPos, compid);
            }
            return(newYPos);
        }
        private double writeResultsUser(pdfPage page, double yPos, ResultsReturn result, int place)
        {
            double newYPos = yPos;

            Structs.Club club = myInterface.GetClub(result.ClubId);
            if (competition.CompetitionId == 0)
            {
                competition = myInterface.GetCompetitions()[0];
            }

            addText(page, place.ToString(), this.leftMargin, yPos, font, fontResultSize);
            addText(page, result.ShooterName, this.colResultNamePos, yPos, colResultClubPos - colResultNamePos, font, fontResultSize);
            addText(page, club.Name, this.colResultClubPos, yPos, colResultResultPos - colResultClubPos, font, fontResultSize);
            switch (competition.Type)
            {
            case Structs.CompetitionTypeEnum.Field:
            {
                if (competition.NorwegianCount)
                {
                    addText(page, (result.HitsTotal + result.FigureHitsTotal).ToString(),
                            colResultTotPos, yPos, font, fontResultSize);
                }
                else
                {
                    addText(page, result.HitsTotal.ToString() + "/" + result.FigureHitsTotal.ToString(),
                            colResultTotPos, yPos, font, fontResultSize);
                }
                addText(page, result.PointsTotal.ToString(),
                        this.colResultPointsPos, yPos, font, fontResultSize);
                break;
            }

            case Structs.CompetitionTypeEnum.Precision:
            {
                addText(page, result.HitsTotal.ToString(),
                        this.colResultPointsPos, yPos, font, fontResultSize);
                break;
            }

            default:
                throw new ApplicationException("Not implemented yet");
            }

            string medalText = "";

            switch ((Structs.Medal)result.Medal)
            {
            case Structs.Medal.StandardSilver:
                medalText = "S";
                break;

            case Structs.Medal.StardardBrons:
                medalText = "B";
                break;
            }
            newYPos = addText(page, medalText, this.colResultStmPos, yPos, font, fontResultSize);

            if (competition.UsePriceMoney &&
                result.PriceMoney != 0)
            {
                newYPos = addText(page, result.PriceMoney.ToString() + ":-",
                                  this.colResultPricePos, yPos, font, fontResultSize);
            }

            string[] HitsPerStn = result.HitsPerStnString.Split(';');
            double   xPos       = colResultResultPos;
            double   xMaxPos    = colResultTotPos;

            foreach (string thisStnPre in HitsPerStn)
            {
                if (thisStnPre != "")
                {
                    string thisStn = thisStnPre;

                    switch (competition.Type)
                    {
                    case Structs.CompetitionTypeEnum.Field:
                    {
                        if (competition.NorwegianCount)
                        {
                        }
                        else
                        {
                            string[] parts = thisStn.Split('/');
                            int      hits  = int.Parse(parts[0]);
                            int      figureHits;

                            figureHits = int.Parse(parts[1]);

                            thisStn = hits.ToString();
                        }
                        break;
                    }

                    case Structs.CompetitionTypeEnum.MagnumField:
                    {
                        string[] parts = thisStn.Split('/');
                        int      hits  = int.Parse(parts[0]);
                        int      figureHits;
                        figureHits = int.Parse(parts[1]);

                        if (competition.NorwegianCount)
                        {
                            thisStn = (hits + figureHits).ToString();
                        }
                        else
                        {
                            thisStn = hits.ToString();
                        }
                        break;
                    }

                    case Structs.CompetitionTypeEnum.Precision:
                    {
                        break;
                    }

                    default:
                        throw new NotImplementedException();
                    }

                    int maxXSizeInPoints = (int)((xMaxPos - xPos) / conversionPixelsToMM);
                    if (font.getWordWidth(thisStn, fontSize) > maxXSizeInPoints)
                    {
                        xPos = colResultResultPos;
                        yPos = newYPos;
                    }
                    newYPos = addText(page, thisStn, xPos, yPos, font, fontResultSize);
                    xPos   += conversionPixelsToMM * font.getWordWidth(thisStn, fontSize);
                }
            }
            if (result.FinalShootingPlace != 100)
            {
                addText(page, "(" + result.FinalShootingPlace.ToString() + ")",
                        xPos, yPos, font, fontResultSize);
            }

            return(newYPos);
        }