/// <summary>
        /// Handles the Click event of the CmdImport control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
        private void CmdImport_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                using (var db = new WintertalentiadeDataContext2(Properties.Settings.Default.WintertalentiadeConnectionString, _user, _pwd))
                {
                    var groups = db.T_Groups.ToList();

                    foreach (var athlet in ViewModel.Athlets)
                    {
                        var newAthlet = new T_Athlet()
                        {
                            GroupId           = groups.Single(g => g.GroupNumber == athlet.Group).GroupId,
                            AthletLastName    = athlet.LastName,
                            AthletFirstName   = athlet.FirstName,
                            AthletGender      = athlet.Gender == null ? (char?)null : athlet.Gender[0],
                            AthletDateOfBirth = athlet.DateOfBirth,
                            AthletClub        = athlet.Club
                        };

                        db.T_Athlets.InsertOnSubmit(newAthlet);
                    }

                    db.SubmitChanges();
                }

                MessageBox.Show("OK");
            }
            catch (Exception ex)
            {
                MessageBox.Show("Fehler: " + ex.ToString());
            }
        }
示例#2
0
        /// <summary>
        /// Handles the Click event of the CmdImport control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
        private void CmdImport_Click(object sender, RoutedEventArgs e)
        {
            if (ViewModel.SelectedStationValue == null)
            {
                // kein "StationValue" ausgewählt!
                MessageBox.Show("Kein Stations-Wert gewählt!");
                return;
            }

            var stationValueId = ViewModel.SelectedStationValue.Id;

            try
            {
                using (var db = new WintertalentiadeDataContext2(Properties.Settings.Default.WintertalentiadeConnectionString, _user, _pwd))
                {
                    var results = db.T_Results.Where(r => r.StationValueId == stationValueId).ToList();

                    foreach (var dataRow in ViewModel.DataRows)
                    {
                        var newResult = results.SingleOrDefault(r => r.AthletId == dataRow.Id);

                        if (newResult == null)
                        {
                            // es gibt das Ergebnis noch nicht
                            newResult = new T_Result()
                            {
                                AthletId       = dataRow.Id,
                                StationValueId = stationValueId
                            };

                            db.T_Results.InsertOnSubmit(newResult);
                        }

                        // Wert zuweisen
                        newResult.ResultValue = dataRow.Value;
                    }

                    db.SubmitChanges();
                }

                MessageBox.Show("OK");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
示例#3
0
        /// <summary>
        /// Handles the Click event of the CmdImport2018TestData control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
        private void CmdImport2018TestData_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (MessageBox.Show("Wirklich?", "Testdaten von 2018 importieren", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                {
                    var rnd = new Random();

                    using (var db = new WintertalentiadeDataContext2(Properties.Settings.Default.WintertalentiadeConnectionString, txtUser.Text, txtPwd.Text))
                    {
                        var allAthlets       = db.T_Athlets.ToList();
                        var allStations      = db.T_Stations.ToList();
                        var allStationValues = db.T_StationValues.ToList();

                        foreach (var station in allStations)
                        {
                            if (station.StationNumber < 90)
                            {
                                var stationValues = allStationValues.Where(asv => asv.StationId == station.StationId).OrderBy(asv => asv.StationValueIndex).ToList();

                                #region Testdaten lesen

                                var allLines = File.ReadAllLines($@"D:\DATEN\Dokumente\MRV\Wintertalentiade\Testdaten2018\{station.StationNumber}.txt").ToList();
                                allLines = allLines.Where(l => !string.IsNullOrEmpty(l)).ToList();

                                var testDataAthlets = new List <TestDataAthlet>();
                                foreach (var line in allLines)
                                {
                                    Debug.WriteLine($"{station.StationNumber} - {line}");
                                    var columns      = line.Split('\t').ToList();
                                    var id           = int.Parse(columns[0]);
                                    var valueStrings = columns.Skip(7).ToList();
                                    valueStrings = valueStrings.Select(vs => "0" + vs).ToList();
                                    var values = valueStrings.Select(vs => float.Parse(vs.Replace(".", ","))).ToList();

                                    testDataAthlets.Add(new TestDataAthlet()
                                    {
                                        Id = id, Values = values
                                    });
                                }

                                #endregion

                                foreach (var athlet in allAthlets)
                                {
                                    var testData = testDataAthlets.SingleOrDefault(tda => tda.Id == athlet.AthletId);
                                    if (testData != null)
                                    {
                                    }

                                    var index = 0;
                                    foreach (var stationValue in stationValues)
                                    {
                                        // neues Ergebnis
                                        var newResult = new T_Result()
                                        {
                                            AthletId       = athlet.AthletId,
                                            StationValueId = stationValue.StationValueId,
                                            ResultValue    = testData.Values[index]
                                        };

                                        db.T_Results.InsertOnSubmit(newResult);

                                        index++;
                                    }
                                }
                            }
                        }

                        db.SubmitChanges();
                    }

                    MessageBox.Show("Fertig");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Fehler: " + ex.ToString());
            }
        }
示例#4
0
        /// <summary>
        /// Handles the Click event of the CmdCreateRandomResults control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
        private void CmdCreateRandomResults_Click(object sender, RoutedEventArgs e)
        {
            if (MessageBox.Show("Wirklich?", "Zufallsergebnisse einfügen", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
            {
                var rnd = new Random();

                using (var db = new WintertalentiadeDataContext2(Properties.Settings.Default.WintertalentiadeConnectionString, txtUser.Text, txtPwd.Text))
                {
                    var allAthlets       = db.T_Athlets.ToList();
                    var allStations      = db.T_Stations.ToList();
                    var allStationValues = db.T_StationValues.ToList();
                    var allResults       = db.T_Results.ToList();

                    foreach (var station in allStations)
                    {
                        if (station.StationNumber < 90)
                        {
                            var stationValues = allStationValues.Where(asv => asv.StationId == station.StationId).OrderBy(asv => asv.StationValueIndex).ToList();

                            foreach (var athlet in allAthlets)
                            {
                                var randomValues = new List <float>();

                                switch (station.StationNumber)
                                {
                                case 2:
                                    randomValues.Add(GetRandomFloat(rnd, 1.5, 2.1));
                                    randomValues.Add(GetRandomFloat(rnd, 2, 3.1));
                                    break;

                                case 3:
                                    randomValues.Add(GetRandomFloat(rnd, 4.1, 6.2));
                                    randomValues.Add(GetRandomFloat(rnd, 5.2, 7.1));
                                    break;

                                case 4:
                                    randomValues.Add(rnd.Next(17, 27));
                                    break;

                                case 5:
                                    randomValues.Add(GetRandomFloat(rnd, 2, 7));
                                    randomValues.Add(GetRandomFloat(rnd, 3, 8));
                                    randomValues.Add(GetRandomFloat(rnd, 2, 6));
                                    break;

                                case 7:
                                    randomValues.Add(GetRandomFloat(rnd, 15, 25));
                                    break;

                                case 8:
                                    randomValues.Add(rnd.Next(17, 27));
                                    break;

                                case 9:
                                    randomValues.Add(rnd.Next(11, 24));
                                    break;

                                case 11:
                                    randomValues.Add(GetRandomFloat(rnd, 15, 19));
                                    break;

                                case 13:
                                    randomValues.Add(GetRandomFloat(rnd, 13, 22));
                                    break;

                                case 14:
                                    randomValues.Add(rnd.Next(80, 400));
                                    break;
                                }

                                var index = 0;
                                foreach (var stationValue in stationValues)
                                {
                                    var existingResult = allResults.SingleOrDefault(r => r.AthletId == athlet.AthletId && r.StationValueId == stationValue.StationValueId);
                                    if (existingResult != null)
                                    {
                                        // es gibt das Ergebnis schon
                                        // => nichts machen
                                    }
                                    else
                                    {
                                        // neues Ergebnis
                                        var newResult = new T_Result()
                                        {
                                            AthletId       = athlet.AthletId,
                                            StationValueId = stationValue.StationValueId,
                                            ResultValue    = randomValues[index]
                                        };
                                        db.T_Results.InsertOnSubmit(newResult);
                                    }

                                    index++;
                                }
                            }
                        }
                    }

                    db.SubmitChanges();
                }

                MessageBox.Show("Fertig");
            }
        }
示例#5
0
        /// <summary>
        /// Handles the Click event of the CmdCalculateStationResults control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
        private void CmdCalculateStationResults_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (MessageBox.Show("Wirklich?", "Stationsergebnisse berechnen", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                {
                    // neu berechnen
                    using (var db = new WintertalentiadeDataContext2(Properties.Settings.Default.WintertalentiadeConnectionString, txtUser.Text, txtPwd.Text))
                    {
                        // alles einlesen
                        var allAthlets               = db.T_Athlets.ToList();
                        var allStations              = db.T_Stations.ToList();
                        var allStationValues         = db.T_StationValues.ToList();
                        var allResults               = db.T_Results.ToList();
                        var calculatedStationResults = db.T_CalculatedStationResults.ToList();

                        // alle Stationen durchgehen
                        foreach (var station in allStations)
                        {
                            // Stationswerte der aktuellen Station
                            var stationValues   = allStationValues.Where(asv => asv.StationId == station.StationId).OrderBy(asv => asv.StationValueIndex).ToList();
                            var stationValueIds = stationValues.Select(sv => sv.StationValueId).ToList();

                            var executeCode = new ExecuteCode(station.StationFormula);

                            // alle Athleten durchgehen
                            foreach (var athlet in allAthlets)
                            {
                                // die Ergebnisse des aktuellen Athleten an der aktuellen Station
                                var results = allResults.Where(r => (r.AthletId == athlet.AthletId) && stationValueIds.Contains(r.StationValueId)).ToList();

                                float points;

                                // es muss genau so viele Ergebnisse geben wie Stationswerte
                                if (results.Count() == stationValues.Count())
                                {
                                    // passt

                                    // Ergebnisse müssen genau so sortiert sein wie die Stationswerte!
                                    // ('stationValues' ist gemäß 'StationValueIndex' sortiert und demnach auch 'stationValueIds')
                                    var sortedResults = stationValueIds.Select(svid => results.Single(r => r.StationValueId == svid)).ToList();

                                    // Punkte berechnen
                                    var resultValues = sortedResults.Select(r => r.ResultValue).ToList();

                                    try
                                    {
                                        points = executeCode.CallCalculateResult(resultValues);
                                    }
#pragma warning disable CS0168 // Variable is declared but never used
                                    catch (Exception ex)
#pragma warning restore CS0168 // Variable is declared but never used
                                    {
                                        var message = $"Fehler bei Formel: '{station.StationFormula}', Werte: {string.Join(" / ", resultValues)}";
                                        MessageBox.Show(message);
                                        throw new Exception(message);
                                    }
                                }
                                else
                                {
                                    // passt nicht
                                    // => dann kann man auch keine Punkte berechnen
                                    points = 0;
                                }

                                // Punkte speichern
                                var calculatedStationResult = calculatedStationResults.SingleOrDefault(csr => (csr.AthletId == athlet.AthletId) && (csr.StationId == station.StationId));
                                if (calculatedStationResult == null)
                                {
                                    // es gibt noch kein Ergebnis
                                    var newCalculatedStationResult = new T_CalculatedStationResult()
                                    {
                                        AthletId    = athlet.AthletId,
                                        StationId   = station.StationId,
                                        ResultValue = points
                                    };

                                    db.T_CalculatedStationResults.InsertOnSubmit(newCalculatedStationResult);
                                }
                                else
                                {
                                    // es gibt schon ein Ergebnis
                                    calculatedStationResult.ResultValue = points;
                                }
                            }
                        }

                        db.SubmitChanges();
                    }

                    MessageBox.Show("Fertig");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Fehler: " + ex.ToString());
            }
        }