コード例 #1
0
        /// <summary>
        /// private helper function to help open the file
        /// </summary>
        /// <param name="OpenFileDialog"></param>
        private void open(OpenFileDialog OpenFileDialog)
        {
            // if the user hit ok
            if (OpenFileDialog.ShowDialog() == DialogResult.OK)
            {
                // set the file path to the OpenFileDialog.FileName
                filePath = OpenFileDialog.FileName;

                // change the extension of the file
                System.IO.Path.ChangeExtension(filePath, ".xml");

                // clear teh spreadsheetpanel and hide
                spreadsheetPanel1.Clear();
                this.Hide();

                // create a new form1 instance
                Form1 newform = new Form1(filePath);
                try
                {
                    // run the form and setvalues to the cells
                    SSContextSingleton.getContext().RunForm(newform);
                    Display();
                }
                catch (SpreadsheetReadWriteException)
                {
                    // show a messagebox if the file cannot be opened
                    MessageBox.Show("Unable to open the file.", "Message");
                }
            }
        }
コード例 #2
0
 /// <summary>
 /// makes new context exactly once
 /// </summary>
 /// <returns> a new contextsingleton if there isn't one already.</returns>
 public static SSContextSingleton getContext()
 {
     if (MyContext == null)
     {
         MyContext = new SSContextSingleton();
     }
     return(MyContext);
 }
コード例 #3
0
ファイル: Program.cs プロジェクト: prosperousZ/cs3500
        static void Main()
        {
            SSContextSingleton appcontext = SSContextSingleton.getContext();

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            appcontext.RunForm(new SpreadSheetForm());
            Application.Run(appcontext);
        }
コード例 #4
0
        /// <summary>
        /// If click the newToolStripMenuItem, do the following reaction
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void newToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // if the sheet has not been changed, hide this form and create a new one
            if (!(sheet.Changed))
            {
                this.Hide();
                SSContextSingleton.getContext().RunForm(new Form1());
            }
            else
            {
                // warning the user if they want to save first before creating
                DialogResult result = MessageBox.Show("Do you want to save this spreadsheet before creating a new spreadsheet?",
                                                      "Message", MessageBoxButtons.YesNoCancel);
                // if yes, save the file
                if (result == DialogResult.Yes)
                {
                    if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                    {
                        try
                        {
                            filePath = saveFileDialog1.FileName;
                            backgroundWorker1.RunWorkerAsync();
                            MessageBox.Show("Saved.");

                            getFileName();
                            this.Text = docName;
                        }
                        catch (SpreadsheetReadWriteException)
                        {
                            MessageBox.Show("Unable to save.");
                        }
                        this.Hide();
                        SSContextSingleton.getContext().RunForm(new Form1());
                    }
                }
                // if no, hide the form and creat a new one
                if (result == DialogResult.No)
                {
                    this.Hide();
                    SSContextSingleton.getContext().RunForm(new Form1());
                }
                // if cancle, do nothing
                if (result == DialogResult.Cancel)
                {
                    return;
                }
            }
        }
コード例 #5
0
 /// <summary>
 /// What happens when user clicks New
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void newToolStripMenuItem_Click(object sender, EventArgs e)
 {
     SSContextSingleton.getContext().RunForm(new SpreadSheetForm());
 }