예제 #1
0
        private void ShiftTimeMarker(object sender, EventArgs e)
        {
            if (dataGridView1.SelectedItems.Count == 1 &&
                GetDataGrid().SelectedItems[0].Tag is Game.Marker)
            {
                var mi    = (ToolStripMenuItem)sender;
                var shift = Convert.ToInt32(mi.Tag);

                foreach (ListViewItem row in GetDataGrid().SelectedItems)
                {
                    var mki = (Game.Marker)row.Tag;
                    Log.Write("MANUAL SHIFT TIME BEFORE " + mki.ToString());
                    mki.TimeVideo += shift;
                    mki.FlagUpdate = true;
                    mki.row        = null;
                    Log.Write("MANUAL SHIFT TIME AFTER " + mki.ToString());
                }

                /*Marker mk = (Game.Marker)GetDataGrid().SelectedItems[0].Tag;
                 * List<Marker> sibl = new List<Marker>();
                 * if (mk.ActionId == 14)
                 *  sibl.Add(mk);
                 * else
                 *  sibl = game.GetSiblings(mk);
                 *
                 * int shift = Convert.ToInt32(mi.Tag);
                 *
                 * foreach (Game.Marker mki in sibl)
                 * {
                 *  Log.Write("MANUAL SHIFT TIME BEFORE " + mki.ToString());
                 *  mki.TimeVideo += shift;
                 *  mki.FlagUpdate = true;
                 *  mki.row = null;
                 *  Log.Write("MANUAL SHIFT TIME AFTER " + mk.ToString());
                 * }*/

                lock (game.Markers)
                {
                    MarkerList.SaveToFile(game.Match.Id, game.Markers);
                }

                lock (game.Markers)
                    game.RecalcActualTime(game.Markers, game.Half);

                ReloadDataGridView(true);
            }
        }
예제 #2
0
        private void DoLoadMatchData(object ids)
        {
            try
            {
                sync.Execute(() => pictureBox1.Visible = true);
                ShowStatus("Загрузка данных матча...", 0);

                Web.GetTeamColorsKind();

                var   idm = Int32.Parse(ids.ToString());
                SizeF sizef;
                game = Web.GetMatchInfo(idm, out sizef);

                if (game == null)
                {
                    throw new Exception("Нет матча или выбран неверный тип игры!");
                }

                if (game.Match.Team1 == null || game.Match.Team1.Id == 0)
                {
                    throw new Exception("Нет команды 1");
                }
                if (game.Match.Team2 == null || game.Match.Team2.Id == 0)
                {
                    throw new Exception("Нет команды 2");
                }

                if (!sizef.IsEmpty)
                {
                    game.FieldSize = sizef;
                }

                ShowStatus("Загрузка игроков команды " + game.Match.Team2.ToString() + "...", 0);
                Web.GetPlayers(game.Match.Team2);

                if (game.Match.Team2.Players.Count == 0)
                {
                    throw new Exception("Нет состава команды " + game.Match.Team2);
                }

                ShowStatus("Загрузка игроков команды " + game.Match.Team1.ToString() + "...", 0);
                Web.GetPlayers(game.Match.Team1);

                if (game.Match.Team1.Players.Count == 0)
                {
                    throw new Exception("Нет состава команды " + game.Match.Team1);
                }

                ShowStatus("Загрузка параметров матча...", 0);

                game.Match.Team1.FinePlaces.Clear();
                game.Match.Team1.FinePlayers.Clear();

                game.Match.Team2.FinePlaces.Clear();
                game.Match.Team2.FinePlayers.Clear();

                Web.GetTeamColors(game.Match.Team1);
                Web.GetTeamColors(game.Match.Team2);

                var txt = game.Match.Team1.Name + " - " + game.Match.Team2.Name;

                game.Markers.Clear();

                sync.Execute(() =>
                {
                    label1.Text = game.Match.Tournament + " " +
                                  game.Match.Date.ToShortDateString() + " " +
                                  game.Match.Date.ToLongTimeString();

                    textBox4.Text = txt;
                });

                ShowStatus("Загрузка маркеров...", 0);

                var           lstSrv = Web.GetMarkers(game, game.Match.Id);
                List <Marker> lstLoc = MarkerList.LoadFromFile(game, game.Match.Id);

                foreach (Game.Marker mk in lstLoc)
                {
                    mk.game = game;
                }

                foreach (var mk in lstLoc.Where(o => !o.FlagDel).OrderBy(o => o.Half.Index).ThenBy(o => o.TimeVideo))
                {
                    var period = mk.Half.Index;
                    var half   = game.HalfList.FirstOrDefault(o => o.Index == period);
                    mk.Half = half;
                }

                game.Union(lstLoc, lstSrv);

                foreach (Game.Marker mk in game.Markers)
                {
                    mk.row = null;
                }

                ShowStatus("Синхронизация...", 0);
                var pl = game.Match.Team1.Players.Concat(game.Match.Team2.Players).ToList <Player>();

                //Восстановление и контроль составов
                foreach (var mk in game.Markers.Where(o => o.ActionId == 16))
                {
                    Team tm = null;
                    try
                    {
                        tm       = GetTeam(mk.team1_id, mk);
                        mk.Team1 = tm;
                    }
                    catch (TeamMarkerException ex)
                    {
                        mk.FlagDel = true;
                        ShowStatus(ex.Message, FormShowStatusCode.Error);
                        Thread.Sleep(100);
                        continue;
                    }

                    if (pl.Exists(o => o.Id == mk.player1_id))
                    {
                        var p = pl.First(o => o.Id == mk.player1_id);

                        if (mk is Game.Marker)
                        {
                            var mkg = (Game.Marker)mk;
                            if (mkg.Num > 0)
                            {
                                p.Number = mkg.Num;
                            }
                        }

                        var tm2 = game.Match.Team1 == tm ? game.Match.Team2 : game.Match.Team1;
                        if (tm2.Players.Exists(o => o.Id == p.Id))
                        {
                            throw new Exception(String.Format((string)"Ошибка в маркере расстановки {0}. Игрок {1} был в составе {2}, а теперь указан в команде соперника", (object)mk.Id, (object)p, tm2));
                        }

                        p.Team     = tm;
                        mk.Player1 = p;

                        if (!tm.Players.Exists(o => o.Id == p.Id))
                        {
                            tm.Players.Add(p);
                        }
                    }
                    else
                    {
                        if (mk.player1_id <= 0)
                        {
                            continue;
                        }

                        var p = Web.GetPlayer(mk.player1_id);
                        if (p != null)
                        {
                            p.Team     = tm;
                            mk.Player1 = p;

                            if (!tm.Players.Exists(o => o.Id == p.Id))
                            {
                                tm.Players.Add(p);
                            }
                            if (!pl.Exists(o => o.Id == p.Id))
                            {
                                pl.Add(p);
                            }
                        }
                        else
                        {
                            throw new Exception("Критическая ошибка: не могу загрузить игрока ID=" + mk.player1_id + " из состава команды " + tm.Name);
                        }
                    }
                }

                game.Match.Team1.Players.AddRange(
                    pl.Where(o
                             => o.Team != null &&
                             o.Team.Id == game.Match.Team1.Id &&
                             !game.Match.Team1.Players.Exists(o1 => o1.Id == o.Id)));

                game.Match.Team2.Players.AddRange(
                    pl.Where(o
                             => o.Team != null &&
                             o.Team.Id == game.Match.Team2.Id &&
                             !game.Match.Team2.Players.Exists(o1 => o1.Id == o.Id)));

                var errmklist = new List <Marker>();
                foreach (var mk in game.Markers.Where(o => o.ActionId != 16))
                {
                    if (mk.player1_id > 0)
                    {
                        var pla = pl.FirstOrDefault(o => o.Id == mk.player1_id);

                        if (pla == null)
                        {
                            try
                            {
                                mk.Player1 = Web.GetPlayer(mk.player1_id);
                            }
                            catch
                            {
                                mk.FlagDel = true;
                                errmklist.Add(mk);
                            }
                        }
                        else
                        {
                            mk.Player1 = pla;
                        }
                    }
                    else
                    if (mk.team1_id > 0)
                    {
                        try
                        {
                            mk.Team1 = GetTeam(mk.team1_id, mk);
                        }
                        catch (Exception ex)
                        { }
                    }

                    if (mk.player2_id > 0)
                    {
                        var opp = pl.FirstOrDefault(o => o.Id == mk.player2_id);

                        if (opp == null)
                        {
                            try
                            {
                                mk.Player2 = Web.GetPlayer(mk.player2_id);;
                            }
                            catch
                            {
                                mk.FlagDel = true;
                                errmklist.Add(mk);
                            }
                        }
                        else
                        {
                            mk.Player2 = opp;
                        }
                    }
                    else
                    if (mk.team2_id > 0)
                    {
                        try
                        {
                            mk.Team2 = GetTeam(mk.team2_id, mk);
                        }
                        catch (Exception ex)
                        { }
                    }
                }

                game.RefreshOvertimes();

                sync.Execute(() =>
                {
                    label1.Text   = game.Match.Tournament + " " + game.Match.Date.ToShortDateString() + " " + game.Match.Date.ToLongTimeString();
                    textBox4.Text = txt;
                });

                TeamDataRestore(game.Match.Team1);
                TeamDataRestore(game.Match.Team2);

                PlayerConverter.RefreshData(game.Match);
                TeamConverter.RefreshData(game.Match);

                sync.Execute(() =>
                {
                    checkBox1.Checked = !game.Match.Team1.Tactics[1].IsValid;
                    checkBox2.Checked = !game.Match.Team1.Tactics[1].IsValid;

                    comboBox1.Items.Clear();
                    foreach (var tc in game.Match.Team1.TeamColorsKind.Values)
                    {
                        comboBox1.Items.Add(tc);
                        if (tc.Kind == game.Match.Team1.Color.Kind)
                        {
                            comboBox1.SelectedItem = tc;
                        }
                    }

                    comboBox2.Items.Clear();
                    foreach (var tc in game.Match.Team2.TeamColorsKind.Values)
                    {
                        comboBox2.Items.Add(tc);
                        if (tc.Kind == game.Match.Team2.Color.Kind)
                        {
                            comboBox2.SelectedItem = tc;
                        }
                    }

                    changed_colors = false;
                });

                if (errmklist.Count > 0)
                {
                    var errmks = String.Empty;
                    for (var i = 0; i < errmklist.Count; i++)
                    {
                        if (i <= 2)
                        {
                            if (i > 0)
                            {
                                errmks += ",";
                            }
                            errmks += errmklist[i].Id;
                            if (i == 2)
                            {
                                errmks += "...";
                            }
                        }
                    }

                    ShowStatus(String.Format("Ошибочно указаны некоторые игроки. Эти маркеры {0} помечены на удаление.", errmks), FormShowStatusCode.Error);
                }
                else
                {
                }

                game.RecalcActualTime(game.Markers, null);

                sync.Execute(() => hockeyField1.Game = game);
                ShowStatus("Готово", 0);
            }
            catch (Exception ex)
            {
                game = null;
                ShowStatus(ex.Message, FormShowStatusCode.Error);
                HockeyGui.InvalidateRect();
            }
            finally
            {
                sync.Execute(() =>
                {
                    HockeyGui.InvalidateRect();
                    pictureBox1.Visible = false;
                });
                loading = false;
                UpdateUI();
            }
        }