Пример #1
0
        /// <summary>
        /// Fallowing method opens a spreadsheet from a saved source compatible with the implementation
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // creating an open Dialog window with extension properties
            OpenFileDialog openDialog = new OpenFileDialog();

            openDialog.Filter           = "Sprd Document (*.ss)|*.ss|All files(*.*)|*.*";
            openDialog.Title            = "0pen";
            openDialog.InitialDirectory = @"C:\";
            int col, row;

            // Opening the file selection Dialog box for the user to select a spreadsheet class
            if (openDialog.ShowDialog() == DialogResult.OK)
            {
                string name     = openDialog.FileName;
                Form1  openForm = new Form1(File.OpenText(name));
                openForm.Text     = name;
                openForm.fileName = name;
                MyApplicationContext.getAppContext().RunForm(openForm);

                try
                {
                    // Going through all the cells that exist in our spreadsheet class and adding it to the GUI
                    foreach (string cellName in openForm.spreadsheet.GetNamesOfAllNonemptyCells())
                    {
                        cellNameToColumnRowConverter(cellName, out col, out row);
                        openForm.spreadsheetPanel1.SetValue(col, row, openForm.spreadsheet.GetCellValue(cellName).ToString());
                        openForm.spreadsheetPanel1.SetSelection(col, row);
                        openForm.displaySelection(spreadsheetPanel1);
                    }
                } catch (Exception creatingFileException)
                { MessageBox.Show(creatingFileException.Message, "An Error occured reading in creating the spreadshit from the file given."); }
            }
        }
Пример #2
0
        /// <summary>
        ///  Deals with the Open menu
        ///  This will handle existed spreadsheet. set all cell contents and values
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // pop up the open file dialog form exsising DLL.
            OpenFileDialog openDialog = new OpenFileDialog();

            openDialog.Filter           = "Sprd Document (*.sprd)|*.sprd|All files(*.*)|*.*";
            openDialog.Title            = "0pen";
            openDialog.InitialDirectory = @"C:\";
            int col, row;

            if (openDialog.ShowDialog() == DialogResult.OK)
            {
                //find the path
                string filename   = openDialog.FileName;
                Form1  openedForm = new Form1(filename);
                openedForm.Text       = filename;
                openedForm.recentName = filename;
                MyApplicationContext.getAppContext().RunForm(openedForm);

                try
                {
                    //find non-empty cells and save
                    foreach (string cellname in openedForm.myspreadsheet.GetNamesOfAllNonemptyCells())
                    {
                        convertToColRow(cellname, out col, out row);
                        openedForm.spreadsheetPanel1.SetValue(col, row, openedForm.myspreadsheet.GetCellValue(cellname).ToString());
                        openedForm.spreadsheetPanel1.SetSelection(col, row);
                        openedForm.displaySelection(spreadsheetPanel1);
                    }
                }
                catch (Exception er)
                {
                    MessageBox.Show(er.Message, "Error");
                    openedForm.Close();
                }
            }
        }