Example #1
0
        /// <summary>
        /// Extracts show information from this form and contructs a list of Show objects to intantiate a new CastinSheet with.
        /// </summary>
        private void GenerateCastingSheet()
        {
            shows = new List <Show>();

            for (int i = 0; i < showBoxes.Count; i++)
            {
                Panel   p = (Panel)showBoxes[i].Controls["panS" + (i + 1)];
                TextBox t = (TextBox)showBoxes[i].Controls["txtS" + (i + 1) + "Name"];
                Show    s = new Show(t.Text);

                TextBox nb;
                for (int j = 0; j < charNumbers[i]; j++)
                {
                    nb = (TextBox)p.Controls["txtS" + (i + 1) + "C" + (j + 1)];
                    if (!nb.Text.Equals(""))
                    {
                        s.addRole(nb.Text);
                    }
                }
                shows.Add(s);
            }
            CastingSheet cs = new CastingSheet(shows, (int)numUDChoices.Value);

            cs.Show();
        }
Example #2
0
        private void BtnLoad_Click(object sender, EventArgs e)
        {
            var fileContent = string.Empty;
            var filePath    = string.Empty;

            using (OpenFileDialog ofd = new OpenFileDialog())
            {
                ofd.Filter           = "Theatre Group Casting Sheet (*.tgcs)|*.tgcs|All files (*.*)|*.*";
                ofd.FilterIndex      = 0;
                ofd.RestoreDirectory = true;

                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    //Get the path of specified file
                    filePath = ofd.FileName;

                    //Read the contents of the file into a stream
                    var fileStream = ofd.OpenFile();

                    using (StreamReader reader = new StreamReader(fileStream))
                    {
                        fileContent = reader.ReadToEnd();
                    }
                }
            }
            if (!fileContent.Equals(string.Empty))
            {
                try
                {
                    string[] s = { "", "" };
                    s = fileContent.Split('|');
                    string json       = s[0];
                    string choicesTxt = s[1];
                    shows = JsonConvert.DeserializeObject <List <Show> >(json);
                    CastingSheet cs = new CastingSheet(shows, (s[1].Equals("") ? 6 : Convert.ToInt32(s[1])), filePath);
                    cs.Show();
                }
                catch (JsonException ex)
                {
                    MessageBox.Show("Error: loaded file is corrupt and cannot be deserialised." + Environment.NewLine + ex.Message);
                }
                catch (IndexOutOfRangeException ex)
                {
                    MessageBox.Show("Error: loaded file is corrupt and cannot be loaded." + Environment.NewLine + ex.Message);
                }
                catch (FormatException ex)
                {
                    MessageBox.Show("Error: loaded file is corrupt and cannot be loaded." + Environment.NewLine + ex.Message);
                }
            }
        }