Esempio n. 1
0
        /// <summary>
        /// This method is run when the 'Open' button is clicked.  The method opens
        /// a saved spreadsheet from a file.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void openMenuItem_Click(object sender, EventArgs e)
        {
            // Referenced MSDN library for Filter syntax
            openFileDialog1.Filter     = "Spreadsheet Files (*.sprd)|*.sprd|All Files (*.*)|*.*";
            openFileDialog1.DefaultExt = ".sprd";
            openFileDialog1.FileName   = "";
            openFileDialog1.Title      = "Open";
            openFileDialog1.ShowDialog();

            // get the name of the selected file
            string openname = openFileDialog1.FileName;

            if (openname == "")
            {
                return;
            }


            if (openFileDialog1.FilterIndex == 1)
            {
                openFileDialog1.AddExtension = true;
            }


            if (spreadsheet.Changed)
            {
                DialogResult result = MessageBox.Show("your spreadsheet is not saved do you want to overwrite existing file",
                                                      "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

                // if 'No' then we don't want to open the file so return
                if (result == DialogResult.No)
                {
                    return;
                }
            }

            try // Try to load a spreadsheet from a file
            {
                foreach (string s in spreadsheet.GetNamesOfAllNonemptyCells())
                {
                    int CellColumnIndex = GetColIndex(s);
                    int CellRowIndex    = GetRowIndex(s);
                    spreadsheetPanel1.SetValue(CellColumnIndex, CellRowIndex, "");
                }



                spreadsheet = new Spreadsheet(openname, variablechecker, s => s.ToUpper(), "ps6");
                filename    = openname; // initialize to the filepath where opened
                this.Text   = openname; // set title to filename
                SpreadsheetUpdater();   // update the tool boxes

                // Update each cell in the GUI to show the values in the spreadsheet
                foreach (string s in spreadsheet.GetNamesOfAllNonemptyCells())
                {
                    UpdateCell(s);
                }

                // Changed should now be false, so show that the spreadsheet has been saved
                if (!spreadsheet.Changed)
                {
                    toolStripStatusLabel1.Text = "";
                }
            }
            catch (SpreadsheetReadWriteException s)
            {
                MessageBox.Show("no such file exist, please select another one", "error", MessageBoxButtons.OK, MessageBoxIcon.Error); // display the message from the exception
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Handles a request to open a new window.
        /// </summary>
        private void HandleNew()
        {
            Spreadsheet sheet = new Spreadsheet();

            window.OpenNew(sheet);
        }