Example #1
0
        private void changePlace(Structs.Station station1, Structs.Station station2)
        {
            int tempStationNr = station1.StationNr;

            station1.StationNr = station2.StationNr;
            station2.StationNr = tempStationNr;
            CommonCode.UpdateStation(station1);
            CommonCode.UpdateStation(station2);
            checkStationsNumbers();
        }
Example #2
0
        private void chkPoints_Click(object sender, EventArgs e)
        {
            CheckBox chkPoints       = (CheckBox)sender;
            string   stationnrString = chkPoints.Name.Replace("Points", "");

            Structs.Station station = CommonCode.GetStation(int.Parse(stationnrString),
                                                            chkDistiguish.Checked);
            station.Points = chkPoints.Checked;
            CommonCode.UpdateStation(station);
        }
Example #3
0
 private void btnAddStation_Click(object sender, System.EventArgs e)
 {
     Structs.Station station = new Structs.Station();
     station.CompetitionId = CommonCode.GetCompetitions()[0].CompetitionId;
     station.Figures       = 3;
     station.Points        = false;
     station.Shoots        = 6;
     station.StationNr     = CommonCode.GetStationsCount() + 1;
     CommonCode.NewStation(station, false);
 }
Example #4
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            Button btnDelete       = (Button)sender;
            string stationnrString = btnDelete.Name.Replace("DeleteStation", "");

            Structs.Station station = CommonCode.GetStation(int.Parse(stationnrString),
                                                            chkDistiguish.Checked);
            DialogResult res =
                MessageBox.Show("Är du säker på att du vill radera station " +
                                station.StationNr.ToString() + "?",
                                "Bekräfta radering",
                                MessageBoxButtons.YesNo);

            try
            {
                if (res == DialogResult.Yes)
                {
                    Trace.WriteLine("FStationsField: Deleting station " +
                                    station.StationNr.ToString());
                    CommonCode.DelStation(station);
                    checkStationsNumbers();
                }
            }
            catch (ApplicationException exc)
            {
                if (exc.Message.IndexOf("CompetitorResults") > -1)
                {
                    Trace.WriteLine(
                        "FStationsField: Failed to delete station since there is results for this station." +
                        "Asking user what to do.");

                    res =
                        MessageBox.Show("Det finns inmatade resultat för denna station. " +
                                        "Är du verkligen säker på att du vill radera station " +
                                        station.StationNr.ToString() + "?",
                                        "Bekräfta radering",
                                        MessageBoxButtons.YesNo,
                                        MessageBoxIcon.Warning,
                                        MessageBoxDefaultButton.Button2);
                    if (res == DialogResult.Yes)
                    {
                        Trace.WriteLine("FStationsField: Deleting results and station " +
                                        station.StationNr.ToString());
                        CommonCode.DelStation(station, true);
                        checkStationsNumbers();
                    }
                }
                else
                {
                    throw;
                }
            }
        }
Example #5
0
        private void btnNext_Click(object sender, EventArgs e)
        {
            Button btnPrevious     = (Button)sender;
            string stationnrString = btnPrevious.Name.Replace("NextStation", "");

            Structs.Station stationCurrent = CommonCode.GetStation(int.Parse(stationnrString),
                                                                   chkDistiguish.Checked);
            Structs.Station stationPrevious = CommonCode.GetStation(int.Parse(stationnrString) + 1,
                                                                    chkDistiguish.Checked);

            changePlace(stationCurrent, stationPrevious);
        }
Example #6
0
        private void numNumberOfShoots_ValueChanged(NumericUpDown numNumberOfShoots)
        {
            string stationnrString = numNumberOfShoots.Name.Replace("NumberOfShoots", "");

            Structs.Station station = CommonCode.GetStation(int.Parse(stationnrString),
                                                            chkDistiguish.Checked);
            if (numNumberOfShoots.Value > numNumberOfShoots.Maximum)
            {
                numNumberOfShoots.Value = numNumberOfShoots.Maximum;
            }
            if (numNumberOfShoots.Value < numNumberOfShoots.Minimum)
            {
                numNumberOfShoots.Value = numNumberOfShoots.Minimum;
            }
            station.Shoots = (int)numNumberOfShoots.Value;
            CommonCode.UpdateStation(station);
        }
Example #7
0
        private void checkStationsNumbers()
        {
            Trace.WriteLine("FStationsField: checkStationsNumbers started.");
            Structs.Station[] stations = GetStations();

            for (int i = 0; i < stations.Length; i++)
            {
                Structs.Station station = stations[i];
                if (station.StationNr != i + 1)
                {
                    Trace.WriteLine("FStationsField: checkStationsNumbers found one problem:" +
                                    "Station " + station.StationNr.ToString() +
                                    " is changing number to " + (i + 1).ToString());
                    station.StationNr = i + 1;
                    CommonCode.UpdateStation(station);
                }
            }
            Trace.WriteLine("FStationsField: checkStationsNumbers started.");
        }
Example #8
0
        private void saveCurrentStation()
        {
            Trace.WriteLine("FStations: saveCurrentStation on thread \"" +
                            Thread.CurrentThread.Name + "\" ( " +
                            AppDomain.GetCurrentThreadId().ToString() + " )");

            if (CommonCode.GetCompetitions().Length == 0)
            {
                return;
            }

            foreach (Structs.Station station in stationList)
            {
                if (station.StationNr == int.Parse(this.lblStationNr.Text))
                {
                    // Found station, so change it by creating a new and
                    // updating with that
                    Structs.Station updStation = station;

                    updStation.CompetitionId = station.CompetitionId;
                    updStation.Figures       = (int)this.numNumberOfFigures.Value;
                    updStation.Shoots        = (int)this.numNumberOfShoots.Value;
                    updStation.Points        = this.chkPoints.Checked;
                    updStation.StationId     = station.StationId;
                    updStation.StationNr     = station.StationNr;

                    CommonCode.UpdateStation(updStation);
                    Trace.WriteLine("FStations: saveCurrentStation ended.");
                    return;
                }
            }
            Structs.Station newStation = new Structs.Station();
            newStation.StationId     = int.Parse(this.lblStationNr.Text);
            newStation.CompetitionId = CommonCode.GetCompetitions()[0].CompetitionId;
            newStation.Figures       = (int)this.numNumberOfFigures.Value;
            newStation.Points        = this.chkPoints.Checked;
            newStation.Shoots        = (int)this.numNumberOfShoots.Value;
            newStation.StationNr     = int.Parse(this.lblStationNr.Text);
            CommonCode.NewStation(newStation);

            Trace.WriteLine("FStations: saveCurrentStation ended.");
        }
Example #9
0
        private void saveCurrent()
        {
            int nrOfStations         = (int)numNrOfSeries.Value;
            int nrOfShootsPerStation = (int)numNrOfShootPerSeries.Value;

            int shoots  = 0;
            int figures = 0;

            switch (chkUseOnlyOneBoxForResult.Checked)
            {
            case true:
                figures = 1;
                shoots  = 10 * nrOfShootsPerStation;
                break;

            case false:
                figures = nrOfShootsPerStation;
                shoots  = 10 * nrOfShootsPerStation;
                break;
            }
            for (int i = 1; i <= CommonCode.GetStationsCount(); i++)
            {
                Structs.Station station = CommonCode.GetStation(i, false);
                station.Figures = figures;
                station.Shoots  = shoots;
                CommonCode.UpdateStation(station);
            }

            while (CommonCode.GetStationsCount() < nrOfStations)
            {
                Structs.Station station = new Structs.Station();
                station.CompetitionId = CommonCode.GetCompetitions()[0].CompetitionId;
                station.Figures       = figures;
                station.Points        = false;
                station.Shoots        = shoots;
                station.StationNr     = CommonCode.GetStationsCount() + 1;
                CommonCode.NewStation(station, false);
            }
            while (CommonCode.GetStationsCount() > nrOfStations)
            {
                Structs.Station station = CommonCode.GetStation(CommonCode.GetStationsCount(), false);
                CommonCode.DelStation(station);
            }

            Structs.Competition competition = CommonCode.GetCompetitions()[0];
            int timeAvailable = competition.PatrolTimeBetween;
            int timeNeeded    = calculateTimeRequirements();

            if (timeNeeded > timeAvailable)
            {
                DialogResult res = MessageBox.Show("Du har avsatt " + timeAvailable.ToString() +
                                                   " minuter för varje skjutlag.\r\n\r\n" +
                                                   "Beräknad tid för varje skjutlag med hänsyn taget till " +
                                                   "skjuttid (6 minuter per serie) och markeringstid " +
                                                   "(6 minuter per serie) är " +
                                                   timeNeeded.ToString() + " minuter.\r\n\r\n" +
                                                   "Vill du öka upp avsatt tid?",
                                                   "Kontrollberäkning",
                                                   MessageBoxButtons.YesNo,
                                                   MessageBoxIcon.Warning);
                if (res == DialogResult.Yes)
                {
                    competition.PatrolTimeBetween = timeNeeded;
                    CommonCode.UpdateCompetition(competition);
                    DateTime         patrolStart = competition.StartTime;
                    Structs.Patrol[] patrols     = CommonCode.GetPatrols();
                    for (int i = 0; i < patrols.Length; i++)
                    {
                        Structs.Patrol patrol = patrols[i];

                        //Trace.WriteLine(patrol.StartDateTimeDisplay.ToShortTimeString());
                        patrol.StartDateTime        = patrolStart;
                        patrol.StartDateTimeDisplay = patrolStart;
                        CommonCode.UpdatePatrol(patrol);

                        patrolStart = patrolStart.AddMinutes(timeNeeded);
                    }
                }
            }
        }
Example #10
0
        private void drawPanelStation(Structs.Station station, int x, int y, ref int tabStop)
        {
            Trace.WriteLine("FStationsField: Drawing station " + station.StationNr);
            int      x1       = 8;
            int      x2       = 112;
            int      y1       = 24;
            int      y2       = 48;
            int      y3       = 72;
            int      y4       = 96;
            int      y5       = 120;
            GroupBox grouping = new GroupBox();

            grouping.Name     = "GroupboxStation" + station.StationNr.ToString();
            grouping.Text     = "Station " + station.StationNr.ToString();
            grouping.Location = new Point(x, y);
            grouping.Size     = new Size(stationWidth, stationHeight);
            panelStations.Controls.Add(grouping);

            #region Labels
            // Labels
            Label label1 = new Label();
            label1.Text     = "Antal figurer";
            label1.Location = new Point(x1, y1);
            label1.Size     = new Size(100, 23);
            grouping.Controls.Add(label1);

            Label label2 = new Label();
            label2.Text     = "Antal skott";
            label2.Location = new Point(x1, y2);
            label2.Size     = new Size(100, 23);
            grouping.Controls.Add(label2);
            #endregion

            #region NumericUpDowns
            // nums
            NumericUpDown numNumberOfFigures = new NumericUpDown();
            numNumberOfFigures.Minimum       = 1;
            numNumberOfFigures.Maximum       = 6;
            numNumberOfFigures.Value         = station.Figures;
            numNumberOfFigures.Location      = new Point(x2, y1);
            numNumberOfFigures.Size          = new Size(40, 20);
            numNumberOfFigures.Name          = "NumberOfFigures" + station.StationNr.ToString();
            numNumberOfFigures.ValueChanged += new EventHandler(numNumberOfFigures_ValueChanged);
            numNumberOfFigures.KeyUp        += new KeyEventHandler(numNumberOfFigures_KeyUp);
            numNumberOfFigures.TabIndex      = tabStop++;
            numNumberOfFigures.TextAlign     = HorizontalAlignment.Right;
            grouping.Controls.Add(numNumberOfFigures);
            Trace.WriteLine("FStationsField: station " + station.StationNr +
                            ", Figures=" + station.Figures.ToString());

            NumericUpDown numNumberOfShoots = new NumericUpDown();
            numNumberOfShoots.Minimum       = 1;
            numNumberOfShoots.Maximum       = 6;
            numNumberOfShoots.Value         = station.Shoots;
            numNumberOfShoots.Location      = new Point(x2, y2);
            numNumberOfShoots.Size          = new Size(40, 20);
            numNumberOfShoots.Name          = "NumberOfShoots" + station.StationNr.ToString();
            numNumberOfShoots.ValueChanged += new EventHandler(numNumberOfShoots_ValueChanged);
            numNumberOfShoots.KeyUp        += new KeyEventHandler(numNumberOfShoots_KeyUp);
            numNumberOfShoots.TabIndex      = tabStop++;
            numNumberOfShoots.TextAlign     = HorizontalAlignment.Right;
            grouping.Controls.Add(numNumberOfShoots);
            Trace.WriteLine("FStationsField: station " + station.StationNr +
                            ", Shoots=" + station.Shoots.ToString());
            #endregion

            #region Checkboxes
            // Checkbox
            CheckBox chkPoints = new CheckBox();
            chkPoints.Checked  = station.Points;
            chkPoints.Text     = "Poängtavla/or";
            chkPoints.Location = new Point(x1, y3);
            chkPoints.Size     = new Size(144, 24);
            chkPoints.Name     = "Points" + station.StationNr.ToString();
            chkPoints.Click   += new EventHandler(chkPoints_Click);
            chkPoints.TabIndex = tabStop++;
            grouping.Controls.Add(chkPoints);
            Trace.WriteLine("FStationsField: station " + station.StationNr +
                            ", Points=" + station.Points.ToString());
            #endregion

            #region Buttons
            // Buttons
            Button btnPrevious = new Button();
            btnPrevious.Name     = "PreviousStation" + station.StationNr.ToString();
            btnPrevious.Text     = "Tidigare";
            btnPrevious.Location = new Point(x1, y4);
            btnPrevious.Size     = new Size(72, 23);
            btnPrevious.Click   += new EventHandler(btnPrevious_Click);
            btnPrevious.TabIndex = tabStop++;
            if (station.StationNr == 1)
            {
                btnPrevious.Enabled = false;
            }
            grouping.Controls.Add(btnPrevious);

            Button btnNext = new Button();
            btnNext.Name     = "NextStation" + station.StationNr.ToString();
            btnNext.Text     = "Senare";
            btnNext.Location = new Point(btnPrevious.Location.X + btnPrevious.Size.Width, y4);
            btnNext.Size     = new Size(btnPrevious.Size.Width, 23);
            btnNext.Click   += new EventHandler(btnNext_Click);
            btnNext.TabIndex = tabStop++;
            if (station.StationNr == CommonCode.GetStationsCount())
            {
                btnNext.Enabled = false;
            }
            grouping.Controls.Add(btnNext);

            Button btnDelete = new Button();
            btnDelete.Name     = "DeleteStation" + station.StationNr.ToString();
            btnDelete.Text     = "Radera";
            btnDelete.Location = new Point(x1, y5);
            btnDelete.Size     = new Size(144, 23);
            btnDelete.Click   += new EventHandler(btnDelete_Click);
            btnDelete.TabIndex = tabStop++;
            grouping.Controls.Add(btnDelete);
            #endregion
        }