Exemple #1
0
 /// <summary>
 /// "Save" functionality for use in the saveToolStripMenuItem_Click method
 /// </summary>
 private void save()
 {
     if (saveFileName == null)
     {
         saveAs();
     }
     else
     {
         spreadsheet.Save(saveFileName);
     }
 }
Exemple #2
0
 /// <summary>
 /// Event that saves a file when pressed
 /// </summary>
 /// <param name="sender"> Button </param>
 /// <param name="e"> Press Event </param>
 private void Save_Button_Click(object sender, EventArgs e)
 {
     if (saveFilePath != null)
     {
         spreadsheet.Save(saveFilePath);
         MessageBox.Show("Saved.");
     }
     else
     {
         Save();;
     }
 }
Exemple #3
0
 /// <summary>
 /// Handles SaveEvent.
 /// </summary>
 private void HandleSave()
 {
     if (save == "")
     {
         window.AskSave();
     }
     else
     {
         TextWriter writer = new StreamWriter(save);
         spreadsheet.Save(writer);
         writer.Close();
     }
 }
Exemple #4
0
        /// <summary>
        /// Saves the current spreadsheet to a file.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // Create save dialog window and add filter.
            SaveFileDialog saveFileDialog = new SaveFileDialog();

            saveFileDialog.Filter = "sprd files (*.sprd)|*sprd| All files (*.*)|*.*";
            // Display the window to user.
            saveFileDialog.ShowDialog();

            // If .sprd is not added to end of filename, add the extension.
            if (!saveFileDialog.FileName.EndsWith(".sprd"))
            {
                saveFileDialog.FileName += ".sprd";
            }
            // Attempt to save spreadsheet.
            try
            {
                Spreadsheet.Save(saveFileDialog.FileName);
            }
            // If exception is thrown, display error message and exit window.
            catch (Exception)
            {
                MessageBox.Show(null, "Error saving file.", "Error");
            }
        }
Exemple #5
0
        /// <summary>
        /// Event when "File -> Open" is clicked.
        /// </summary>
        /// <param name="sender">Open Button</param>
        /// <param name="e">Open button click event</param>
        private void OpenMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                OpenFileDialog open = new OpenFileDialog();
                open.Filter = "Spreadsheet Files (*.sprd) | *.sprd |All files (*.*) | *.*";

                if (open.ShowDialog() == DialogResult.OK)
                {
                    string file = open.FileName;
                    this.spreadsheet = new Spreadsheet(file, s => true, s => s.ToUpper(), "six");
                    this.grid_widget.Clear();

                    //If the spreadsheet has been saved, then there should be cells used, which need to be gathered to fill in to the new spreadsheet.
                    IEnumerable <string> usedCells = spreadsheet.GetNamesOfAllNonemptyCells();
                    GetCellCoordsAndSet(usedCells);

                    //The given file that was opened is now the new saveFilePath for the spreadsheet GUI.
                    saveFilePath = file;

                    spreadsheet.Save(saveFilePath);
                }
            }
            catch (SpreadsheetReadWriteException)
            {
                MessageBox.Show("Invalid file type.");
            }
        }
        //Save file
        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // if there is no filename, use the Save As method
            if (ReferenceEquals(fileName, null))
            {
                saveAsToolStripMenuItem_Click(sender, e);
            }

            //if the Save As was cancelled, don't save.
            if (ReferenceEquals(fileName, null))
            {
                return;
            }
            //since the save wasn't canceled and we have a location, save the spreadsheet
            cells.Save(fileName);
        }
        /// <summary>
        /// Handles save request
        /// </summary>
        private void HandleSaveChosen(string filename)
        {
            StreamWriter w = new StreamWriter(filename);

            window.Title = filename;
            spreadsheet.Save(w);
            w.Close();
        }
Exemple #8
0
        /// <summary>
        /// helper method Deals with saving a file
        /// </summary>

        private void saveFile()
        {
            //note Filter set up in Form1.cs[Design]
            saveFileDialog1.ShowDialog();
            //check to see that user entered something
            if (saveFileDialog1.FileName != "")
            {
                SSModel.Save(saveFileDialog1.FileName);
            }
        }
Exemple #9
0
        /// <summary>
        /// Opens a file dialog that will save the specificed file from the save dialog
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void saveFileDialog1_FileOk(object sender, CancelEventArgs e)
        {
            try
            {
                // getting the filepath from the saveFileDialog
                string filePath = saveFileDialog1.FileName;
                // saving the contents to the spreadsheet object
                spread.Save(filePath);
                saved = true;

                // setting the name of the spreadsheet window to the file path
                fileName  = filePath;
                this.Text = filePath;
            }
            catch
            {
                MessageBox.Show("There was an error while saving your file. Please check the filepath and try again.");
            }
        }
Exemple #10
0
        /// <summary>
        /// Save the document 'as'
        /// </summary>
        private void savedas_Click(object sender, EventArgs e)
        {
            saveFileDialog1.DefaultExt   = "ss";
            saveFileDialog1.FileName     = docName.Text;
            saveFileDialog1.AddExtension = true;
            saveFileDialog1.Filter       = "Spreadsheet Files (.ss)|*.ss|All Files (*.*)|*.*";
            DialogResult result = saveFileDialog1.ShowDialog();                             // Show the dialog.

            if (result == DialogResult.OK)
            {
                string file = saveFileDialog1.FileName;
                using (save = new StreamWriter(file))
                {
                    savedas = true;
                    ss.Save(save);
                    ssName = file;
                }
                MessageBox.Show("Saved");
                docName.Text = System.IO.Path.GetFileNameWithoutExtension(saveFileDialog1.FileName);
                docName_TextChanged(sender, e);
            }
        }
Exemple #11
0
        /// <summary>
        /// Triggered when the Save option is selected in the file menu
        /// Opens the file explorer and allows the user to pick file path and name
        /// Saves the current spreadsheet state to a .sprd file
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Save_Click(object sender, EventArgs e)
        {
            SaveFileDialog dialog = new SaveFileDialog();

            dialog.AddExtension = true;
            dialog.Filter       = "Text Files (*.sprd)|*.sprd|All Files (*.*)|*.*";
            dialog.ShowDialog();
            string savePath = dialog.FileName;

            if (!string.IsNullOrWhiteSpace(savePath))
            {
                spreadsheet.Save(savePath);
            }
            savedRecently = true;
        }
Exemple #12
0
        private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // Displays a SaveFileDialog so the user can save the Image
            // assigned to Button2.
            SaveFileDialog saveFileDialog1 = new SaveFileDialog();

            saveFileDialog1.Filter = "Spreadsheet File|*.sprd|All Files|*";
            saveFileDialog1.Title  = "Save a Spreadsheet File";
            saveFileDialog1.ShowDialog();

            // If the file name is not an empty string open it for saving.
            if (saveFileDialog1.FileName != "")
            {
                try
                {
                    sheet.Save(saveFileDialog1.FileName);
                    currFileName = saveFileDialog1.FileName;
                }
                catch (Exception exception)
                {
                    MessageBox.Show("Unable to save Spreadsheet file: " + exception.Message);
                }
            }
        }
Exemple #13
0
 /// <summary>
 /// Calls the spreadsheet to save
 /// </summary>
 /// <param name="filename"></param>
 public void Save(string filename)
 {
     ss.Save(filename);
 }