示例#1
0
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                if (MatchOpenFileDialog.ShowDialog(this) == DialogResult.OK)
                {
                    var pgnFileText = File.ReadAllText(MatchOpenFileDialog.FileName);
                    var matches     = _matchFactory.Load(pgnFileText);

                    switch (matches.Count)
                    {
                    case 0:
                        MessageBox.Show("No games found", "Invalid or empty PGN file specified", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        break;

                    case 1:
                        NewGame(matches.First().Game);
                        break;

                    default:
                        NewGame(matches.First().Game);
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                ex.ToMessageBox();
            }
        }
示例#2
0
        private void button4_Click_1(object sender, EventArgs e)
        {
            if (MatchOpenFileDialog.ShowDialog() == DialogResult.Cancel)
            {
                return;
            }

            DialogResult dialogResult = default;

            if (matchFileName != null)
            {
                dialogResult = MessageBox.Show(@"We have loaded some file with matches. Merge them?

Press Yes to verge
Press No to rewrite exited file
Press Cancel to save exited file",
                                               "File exist", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);

                if (dialogResult == DialogResult.Cancel)
                {
                    return;
                }
            }


            matchFileName = MatchOpenFileDialog.FileName;

            XmlSerializer xmlSerializer = new XmlSerializer(typeof(List <Pupil>));

            try
            {
                using (FileStream fs = new FileStream(matchFileName, FileMode.Open))
                {
                    if (dialogResult == DialogResult.No)
                    {
                        pupilsFromXml = new List <Pupil>();
                    }
                    PushNewToXml((List <Pupil>)xmlSerializer.Deserialize(fs), pupilsFromXml);
                }
                lblMatchFileError.Text      = "File have read";
                lblMatchFileError.ForeColor = Color.Green;
                btnSaveXml.Enabled          = true;
                btnSaveAsXml.Enabled        = true;
                btnMakeXlsx.Enabled         = true;
            }
            catch (Exception)
            {
                lblMatchFileError.Text      = "Upps... Wrong file";
                lblMatchFileError.ForeColor = Color.Red;
            }

            PushXmlToCsv(markTable.Pupils, pupilsFromXml);
        }