Example #1
0
File: Form1.cs Project: 3505VFD/VFD
        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //Set dialog properties
            saveFileDialog1.DefaultExt  = "sprd";
            saveFileDialog1.Filter      = "Spreadsheet files (*.sprd)|*.sprd|All files (*.*)|*.*";
            saveFileDialog1.FilterIndex = 1;

            //Show the actual dialog
            DialogResult result = saveFileDialog1.ShowDialog();

            if (result == DialogResult.OK)
            {
                try
                {
                    if (!saveFileDialog1.FileName.Equals(""))
                    {
                        if (ss.Changed == true)
                        {
                            ss.Save(saveFileDialog1.FileName); //Saves the spreadsheet's state in the spreadsheet
                            this.Text = saveFileDialog1.FileName.Substring(saveFileDialog1.FileName.LastIndexOf('\\') + 1);
                        }
                    }
                }
                catch
                {
                    MessageBox.Show("Error: Could not save file to disk.");
                }
            }
        }
Example #2
0
        /// <summary>
        /// This method is run when the 'Save' button is clicked.  The method saves a
        /// spreadsheet to a specified filepath.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void saveMenuItem_Click(object sender, EventArgs e)
        {
            if (ReferenceEquals(fileName, null)) // If no file name has been specificed
            {
                saveAsToolStripMenuItem_Click(sender, e);
            }
            // if the spreadsheet hasn't been saved yet, call the Save As method instead

            // if the file name is still empty, it means Save As was just canceled so return
            if (ReferenceEquals(fileName, null))
            {
                saveCanceled = true;
                return;
            }


            // If the spreadsheet has been changed then save it
            if (spreadsheet.Changed)
            {
                spreadsheet.Save(fileName);
            }

            // Changed should now be false, so show that the spreadsheet has been saved
            if (!spreadsheet.Changed)
            {
                toolStripStatusLabel1.Text = "Saved Successfully";
            }

            // if not, do nothing
        }
Example #3
0
 /// <summary>
 /// Handles a request to save file
 /// </summary>
 public void HandleSave()
 {
     try
     {
         if (SaveLocation == null)
         {
             // save file must save a "ss" format
             SaveFileDialog saveFileDialog1 = new SaveFileDialog();
             saveFileDialog1.Filter = "SpreadSheet files|*.ss|All files|*.*";
             saveFileDialog1.Title  = "Save SpreadSheet File";
             saveFileDialog1.ShowDialog();
             //save the file
             if (saveFileDialog1.FileName != "")
             {
                 SaveLocation = saveFileDialog1.FileName;
                 model.Save(File.CreateText(SaveLocation.Replace("\\", "/")));
             }
         }
         else
         {
             model.Save(File.CreateText(SaveLocation.Replace("\\", "/")));
         }
     }
     catch (Exception e)
     {
         MessageBox.Show("An error occurred", e.Message);
     }
 }
Example #4
0
        /// <summary>
        /// Opens dialog for user to save their spreadsheet
        /// </summary>
        internal void save()
        {
            //Creates save dialog box
            SaveFileDialog saveDialog = new SaveFileDialog();

            saveDialog.Title            = "Save Spreadsheet";
            saveDialog.Filter           = "Spreadsheet files (*.sprd)|*.sprd|All files (*.*)|*.*";
            saveDialog.FilterIndex      = 1;
            saveDialog.RestoreDirectory = true;
            saveDialog.AddExtension     = true;
            saveDialog.DefaultExt       = ".sprd";
            saveDialog.OverwritePrompt  = true;
            DialogResult result = saveDialog.ShowDialog();

            // Saves file or shows error message
            if (result == DialogResult.OK)
            {
                try
                {
                    sheet.Save(saveDialog.FileName);
                    saveDialog.Dispose();
                }
                catch
                {
                    MessageBox.Show("Error saving. Please check file name and try again.", "Invalid file", MessageBoxButtons.OK);
                    saveDialog.Dispose();
                }
            }
        }
Example #5
0
        /// <summary>
        /// Event to save as file, prompts dialog if not saved
        /// </summary>
        /// <param name="fileName"></param>
        private void HandleSaveFile(String fileName)
        {
            TextWriter r = new StreamWriter(fileName);

            previousFile = fileName;
            sheet.Save(r);
            r.Close();
        }
Example #6
0
 /// <summary>
 /// Handles Save menu
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void SaveToolStripMenuItem_Click(object sender, EventArgs e)
 {
     // if the current spreadsheet hasn't been saved to an existing file,
     // prompt user to save; otherwise, save directly to the existing file
     if (currentOpenFileName == string.Empty)
     {
         SaveSS();
     }
     else
     {
         spreadsheet.Save(currentOpenFileName);
     }
 }
 /// <summary>
 /// Event handler for when the user clicks Save
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void SaveButton_Click(object sender, EventArgs e)
 {
     //If fileName has not been specified open the Save Dialog
     if (fileName == "")
     {
         ShowSaveDialog();
     }
     //Else override the existing file
     else
     {
         spreadsheet.Save(fileName);
     }
 }
Example #8
0
        /// <summary>
        /// Event handler for the "save" menu item
        /// </summary>
        /// <param name="sender">Object sending event</param>
        /// <param name="e">Event arguments</param>
        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //Found SaveFileDialog example from MSDN

            SaveFileDialog saveFileDialog1 = new SaveFileDialog();

            //Default extensions used by Save File Dialog
            saveFileDialog1.Filter           = "sprd files (*.sprd)|*.sprd|All files (*.*)|*.*";
            saveFileDialog1.FilterIndex      = 1;
            saveFileDialog1.RestoreDirectory = true;

            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    spreadSheet.Save(saveFileDialog1.FileName);
                }
                catch
                {
                    MessageBox.Show("Error saving file", "Error",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Exclamation,
                                    MessageBoxDefaultButton.Button1);
                }
            }
        }
Example #9
0
        /// <summary>
        /// Saves the spreadsheet
        /// </summary>
        /// <param name="filename"></param>
        private void HandleSave(String filename)
        {
            TextWriter saveFile = null;

            ssModule.Save(saveFile = File.CreateText(filename));
            saveFile.Close();
        }
Example #10
0
 /// <summary>
 /// A private Event Handler that is called whenever the SaveEvent is fired. Calls the models
 /// save method with the passed in desired file name.
 /// </summary>
 /// <param name="filename">The desired name for the model's contents to be saved under</param>
 private void HandleSaveEvent(string filename)
 {
     using (StreamWriter sw = new StreamWriter(filename))
     {
         spreadsheet.Save(sw);
         window.SetTitle(filename);
     }
 }
Example #11
0
 /// <summary>
 /// Saves the spreadsheet
 /// </summary>
 /// <param name="dest">The destination of where the spreadsheet should be saved</param>
 private void HandleSave(string dest)
 {
     try
     {
         spreadsheet.Save(File.CreateText(dest));
     }catch (IOException)
     {
         window.Message = "Error saving file.";
     }
 }
Example #12
0
 /// <summary>
 /// If click the saveToolStripMenuItem, do the following reaction
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void saveToolStripMenuItem_Click(object sender, EventArgs e)
 {
     // filePath is null, excute saveAsToolStripMenuItem_Click function
     if (filePath == null)
     {
         saveAsToolStripMenuItem_Click(sender, e);
     }
     // the sheet has been changed, save the sheet directly
     if (sheet.Changed)
     {
         sheet.Save(docName);
         MessageBox.Show("Successfully saved.", "Message");
     }
     // if the sheet hasn't been changed. do nothing
     if (!sheet.Changed)
     {
         return;
     }
 }
Example #13
0
 /// <summary>
 /// Handles a request to save the spreadsheet.
 /// </summary>
 private void HandleSaveSpreadsheet(string fileName)
 {
     if (fileName == "")
     {
         return;
     }
     System.IO.TextWriter saveName = new System.IO.StreamWriter(fileName);
     spreadsheet.Save(saveName);
     saveName.Close();
 }
Example #14
0
 /// <summary>
 /// tied to async work. Saving, in worst case, could be sort of time consuming.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
 {
     lock (sendlock)
     {
         try { sheetModel.Save(filePath); }
         catch (SpreadsheetReadWriteException ex)
         {
             MessageBox.Show("Could not save " + docName + "\n" + ex.Message);
         }
     }
 }
Example #15
0
 private void HandleSave(string filename)
 {
     try
     {
         spreadsheet.Save(new StreamWriter(filename));
         window.Changed = spreadsheet.Changed;
     }
     catch (Exception e)
     {
         window.Message = "Unable to save file\n" + e.Message;
     }
 }
Example #16
0
        /// <summary>
        /// Method that enoveked the saving event.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //opens up the save dialof
            SaveFileDialog dialog = new SaveFileDialog();

            dialog.Filter = "sprd files (*.sprt|*.sprd|All files (*.*)|*.*";
            //saves file in .sprd format in XML file.
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                formSpreadsheet.Save(dialog.FileName);
            }
        }
Example #17
0
        private void HandleSave()
        {
            if (string.IsNullOrEmpty(window.FileName))
            {
                //go to save as
                window.GoSaveAs();

                if (string.IsNullOrEmpty(window.FileName))
                {
                    cancelSave = true;
                    return;
                }
            }

            if (model.Changed)
            {
                File.Delete(window.FileName);
                //save spreadsheet
                model.Save(File.CreateText(window.FileName));
            }
        }
Example #18
0
        /// <summary>
        /// This method saves the current spreadsheet to a file path.
        /// </summary>
        /// <param name="FileName">File path that it should be saved to</param>
        private void SaveFile(string FileName)
        {
            //If it already exists, delete that existing file.
            if (File.Exists(FileName) && FileName == this.FileName)
            {
                File.Delete(FileName);
            }

            /*Depending on the filter, handle the file name differently. If the first index is selected and it
             * doesn't end in ".sprd", append that to the string.*/
            if (SaveDialogBox.FilterIndex == 2 || FileName.Substring(FileName.Length - 5) == ".sprd")
            {
                mainSpreadsheet.Save(FileName);
                this.FileName = FileName;
            }
            else
            {
                mainSpreadsheet.Save(FileName);
                this.FileName = FileName + ".sprd";
            }
            Text = Path.GetFileName(FileName);
        }
Example #19
0
        /// <summary>
        /// This method handles the event where the user clicks the Save option
        /// from the File menu. Is invoked after checking if the file was never
        /// saved before and presenting a Save as... dialog box to the user.
        /// </summary>
        /// <param name="fileName">The name of the file of the saved</param>
        private void HandleSave(string fileName)
        {
            // If the file is still not saved, return (since Save As dialog was cancelled).
            if (fileName.Equals("Unsaved Spreadsheet"))
            {
                saveCancelled = true;
                return;
            }

            // If the spreadsheet has been changed then save it
            if (spreadsheet.Changed)
            {
                spreadsheet.Save(File.CreateText(fileName));
            }

            // If spreadsheet now becomes unchanged, show Save Successful dialog.
            if (!spreadsheet.Changed)
            {
                window.Message("Spreadsheet Saved.", "Save complete",
                               MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Example #20
0
        /// <summary>
        ///  Deals with the Save menu
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //first saving the file
            if (recentName == null)
            {
                SaveFileDialog saveButton = new SaveFileDialog();
                saveButton.Filter           = "Sprd Document (*.sprd)|*.sprd|All files(*.*)|*.*";
                saveButton.Title            = "Save";
                saveButton.InitialDirectory = @"C:\";

                if (saveButton.ShowDialog() == DialogResult.OK)
                {
                    string filename = saveButton.FileName;
                    if (saveButton.FilterIndex == 1)
                    {
                        saveButton.AddExtension = true;
                    }
                    else
                    {
                        saveButton.AddExtension = false;
                    }
                    recentName = filename;
                    myspreadsheet.Save(filename);
                    //changing the title name
                    this.Text = saveButton.FileName;
                }
                else
                {
                    if (sender.ToString() == "Close")
                    {
                        seeyou = false;
                    }
                }
            }
            else
            {
                myspreadsheet.Save(recentName);   //second or more.
            }
        }
Example #21
0
 /// <summary>
 /// Saves file to a destination
 /// </summary>
 /// <param name="T"></param>
 private void SaveFile(TextWriter T)
 {
     if (model.Changed)
     {
         try
         {
             model.Save(T);
         }
         catch
         {
             window.Message = "Unable to save file.";
         }
     }
 }
Example #22
0
 private void HandleSave(FileStream fs)
 {
     using (StreamWriter s = new StreamWriter(fs))
     {
         try
         {
             spreadsheet.Save(s);
         }
         catch (IOException e)
         {
             spreadsheetView.DisplayMessage("Unkown error encountered while attempting to save file.");
         }
     }
 }
Example #23
0
        /// <summary>
        /// Method responsible for saving the the spreadsheet
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // if we don't have a file name yet
            if (fileName == null)
            {
                // Creating a save Dialog with parsing definition for the extension
                SaveFileDialog saveDialog = new SaveFileDialog();
                saveDialog.Filter           = "Spreadsheet Doc (*.ss)| *.ss | All files (*.*) | *.*";
                saveDialog.Title            = "Save";
                saveDialog.InitialDirectory = @"C:\";

                if (saveDialog.ShowDialog() == DialogResult.OK)
                {
                    string name = saveDialog.FileName;
                    // Checking if an extension of .ss should be added or not
                    if (saveDialog.FilterIndex == 1)
                    {
                        saveDialog.AddExtension = true;
                        fileName = name; // saving the file name
                        spreadsheet.Save(File.CreateText(name));
                    }
                    else
                    {
                        saveDialog.AddExtension = false;
                        fileName = name; // saving the file name
                        spreadsheet.Save(File.CreateText(name));
                    }
                }
            }
            else
            {
                if (sender.ToString() == "Close")
                {
                    cancel = false;
                }
            }
        }
Example #24
0
        /// <summary>
        /// Save button from file menu bar opens a file explorer, so that a file can be save
        /// .sprd is default save type. All file types and .txt are also available
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void saveButton_Click(object sender, EventArgs e)
        {
            SaveFileDialog sfd = new SaveFileDialog();

            sfd.Title    = "Save File";
            sfd.Filter   = "Spreadsheet (*.sprd)|*.sprd|All Files (*.*)|*.* |Text File (*.txt)|*.txt";
            sfd.FileName = this.Text;
            if (sfd.ShowDialog() == DialogResult.OK)
            {
                ss.Save(sfd.FileName);
                //change window name to name of file
                string name = sfd.FileName;
                this.Text = string.Format("{0} - MyEditor", System.IO.Path.GetFileName(name));
            }
        }
Example #25
0
        /// <summary>
        /// Menu item that saves a spreadsheet to a spreadsheet file
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void saveMenuItemClickHandler(object sender, EventArgs e)
        {
            SaveFileDialog d = new SaveFileDialog();

            d.Filter       = "Spreadsheet File (*.sprd)|*.sprd|All Files (*.*)|*.*";
            d.AddExtension = true;

            DialogResult result = d.ShowDialog();

            //User chose to save
            if (result == DialogResult.OK)
            {
                ss.Save(d.FileName);
            }
        }
Example #26
0
 private void HandleSaveSS(string filename)
 {
     try
     {
         using (TextWriter write = File.CreateText(filename))
         {
             if (model.Changed)
             {
                 model.Save(write);
             }
             else
             {
                 return;
             }
         }
     }
     catch (Exception)
     {
     }
 }
Example #27
0
        private void HandleSave()
        {
            Stream         myStream;
            SaveFileDialog saveFileDialog1 = new SaveFileDialog();

            saveFileDialog1.DefaultExt       = "ss";
            saveFileDialog1.Filter           = "Spreadsheet files (*.ss)|*.ss|All files (*.*)|*.*";
            saveFileDialog1.FilterIndex      = 1;
            saveFileDialog1.RestoreDirectory = true;

            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                if ((myStream = saveFileDialog1.OpenFile()) != null)
                {
                    myStream.Close();
                    TextWriter writer = File.CreateText(saveFileDialog1.FileName);
                    sheet.Save(writer);
                    window.Title = saveFileDialog1.FileName;
                }
            }
        }
Example #28
0
        /// <summary>
        /// A helper method to help save a Spreadsheet
        /// </summary>
        /// <citation> https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.savefiledialog?view=netcore-3.1 </citation>
        private void SaveSpreadsheet()
        {
            Stream         myStream;
            SaveFileDialog save = new SaveFileDialog();

            //Gives the user two options to filter through when saving the file, .sprd and all files
            save.Filter           = "Spreadsheet Files (*.sprd)|*.sprd|All files (*.*)|*.*";
            save.FilterIndex      = 1;
            save.RestoreDirectory = true;

            if (save.ShowDialog() == DialogResult.OK)
            {
                //Saves the file name that the user inputted
                string fileName = save.FileName;
                if ((myStream = save.OpenFile()) != null)
                {
                    myStream.Close();
                }
                //saves the XML version of the SpreadSheet using the filename enter by the user
                spreadsheet.Save(fileName);
            }
        }
 /// <summary>
 /// helper method to output and save the file
 /// </summary>
 /// <param name="filePath"></param>
 private void HandleSaveFile(string filePath)
 {
     using (StreamWriter writer = new StreamWriter(filePath))
         sheet.Save(writer);
 }
Example #30
0
 /// <summary>
 /// Get save method from spreadheet to save the file, send to controller
 /// </summary>
 /// <param name="filename"></param>
 public void Save(String filename)
 {
     ss.Save(new StreamWriter(filename));
 }