예제 #1
0
 /// <summary>
 /// initialize Form, populate grid with rows/columns,
 ///  create a new spreadsheet, and subscribe to spreadsheet event
 /// </summary>
 public Form1()
 {
     InitializeComponent();
     CreateRowsColumns();
     _spreadsheet = new SpreadsheetEngine.Spreadsheet(50, 26);
     _spreadsheet.CellPropertyChanged += HandleCellChangedEvent;
 }
        //implement execute interface
        public IUndoRedoCmd Execute(Spreadsheet sheet)
        {
            Cell theCell = sheet.GetCell(_cellName);
            string oldText = theCell.Text;
            theCell.Text = _cellText;

            //return cmd for redo/undo stack
            return new TextCmd(_cellName, oldText);
        }
        //implement execute interface
        public IUndoRedoCmd Execute(Spreadsheet sheet)
        {
            Cell theCell = sheet.GetCell(_cellName);
            int oldColor = theCell.BGColor;
            theCell.BGColor = _cellColor;

            //return cmd for redo/undo stack
            return new BGColorCmd(_cellName, oldColor);
        }
예제 #4
0
        public IUndoRedo Execute(Spreadsheet ss)
        {
            //commented code below is used if we using a string for cell name instead of row and column
            //int col = m_CellName[0] - 'A';//col index of variable (provider_cell) value
            //int row = Convert.ToInt32(m_CellName.Substring(1)) - 1;//row index of variable (provider_cell) value

            Cell cell = ss.getCell(m_CellRow, m_CellCol);

            cell.BGColor = m_RGB;//cell color is retored

            return (new RestoreColor(m_RGB, m_CellRow, m_CellCol));
        }
예제 #5
0
        public void undo(Spreadsheet ss)
        {
            //don't call this function unless we have items in the m_Undos stack

            //pop from the undo stack
            //execute the undo that was popped off and push that action on to the redo stack

            //pop two things off at a time (switching between stacks determines which of the two you will use
            //think of it as undos using the odd numbers and redos using the even numbers
            m_Redos.Push(m_Undos.Pop());
            m_Redos.Push((m_Undos.Pop().Exec(ss)));//after we do this put it on the redo stack
        }
예제 #6
0
 public void redo(Spreadsheet ss)
 {
     //don't call this function unless we have items in the m_Undos stack
     //execute the redo that was popped off and push that action on to the undo stack
     m_Undos.Push(m_Redos.Pop());
     m_Undos.Push(m_Redos.Pop().Exec(ss));//after we redo it put this on the undo stack
 }
예제 #7
0
        public UndoRedoCollection Exec(Spreadsheet ss)
        {
            List<IUndoRedo> inverseCommands = new List<IUndoRedo>();

            foreach (IUndoRedo cmd in m_Cmds)
            {
                inverseCommands.Insert(0, cmd.Execute(ss));//push this result
            }

            //do the commands and return the opposite

            return new UndoRedoCollection(m_Text, inverseCommands);
        }
예제 #8
0
        /// <summary>
        /// Execute the redo right here,
        /// </summary>
        /// <param name="sheet"></param>
        public void Redo(Spreadsheet sheet)
        {
            UndoRedoCollection commands = redoStack.Pop();

            undoStack.Push(commands.Restore(sheet));
        }
예제 #9
0
        private bool Save_Pvt(TextWriter ToStream, Spreadsheet Sender)
        {
            XmlWriter xmlWrite = null;

            try
            {
                xmlWrite = XmlWriter.Create(ToStream); // initializes the XML Writer with the passed stream
            }
            catch (ArgumentException e)
            {
                throw e;
            }

            if (xmlWrite != null) // Ensures the stream is usable
            {
                using (xmlWrite)
                {
                    xmlWrite.WriteStartDocument(); // Places start tag
                    xmlWrite.WriteStartElement("Spreadsheet"); // Places the root node -> the spreadsheet itself

                    for (int i = 0; i < Sender.RowCount; i++) // iterates through every cell in the spreadsheet
                    {
                        for (int j = 0; j < Sender.ColumnCount; j++)
                        {
                            SpreadsheetCell from = Sender[i, j]; // grabs a cell

                            if (!Sender[i, j].IsDefault()) // Only saves those cells that have been altered
                            {
                                xmlWrite.WriteStartElement("Cell"); // Creates a cell start tag
                                xmlWrite.WriteAttributeString("Name", Sender.CellToString(from)); // Gives the cell a NAME attribute

                                if (from.Text != "") // No point in saving an empty string
                                {
                                    xmlWrite.WriteElementString("Text", from.Text); // sets the TEXT from the cell
                                    /* Cell's VALUE does NOT have to be saved
                                     * Every cell's text will be re-computed when it is loaded in
                                     * order does NOT matter, cell's that have references to it will simply be updated when it's their turn
                                     */
                                }
                                xmlWrite.WriteElementString("BGColor", from.BGColor.ToString()); // writes the BGColor element inside of the cell

                                xmlWrite.WriteEndElement(); // Ends the cell block
                            }
                        }
                    }

                    xmlWrite.WriteEndElement(); // Ends the Spreadsheet block
                    xmlWrite.WriteEndDocument(); // Ends file
                }

                return true;
            }

            return false;
        }
예제 #10
0
 public void Save(string ToFile, Spreadsheet Sender)
 {
     using (StreamWriter WriteStream = new StreamWriter(ToFile)) // Uses a StreamWriter -> can be changed to any stream
     {
         try
         {
             Save_Pvt(WriteStream, Sender); // Saves to the stream using XML Writer
             this.Saved = true; // If saving was successful, the save value is set to true
             this.FileName = ToFile; // current file name is updated
         }
         catch(Exception e)
         {
             throw e;
         }
     }
 }
예제 #11
0
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (!MainSave.Saved) // If the current session has not been saved, will prompt to save before loading
            {
                DialogResult loading = MessageBox.Show("Save before loading?", "Load Spreadsheet", MessageBoxButtons.YesNoCancel);

                if (loading == DialogResult.Yes)
                    saveAsToolStripMenuItem_Click(this, e); // saves the current form
                else if (loading == DialogResult.Cancel)
                    return;
            }

            OpenFileDialog OpenFrom = new OpenFileDialog(); // prompts the user to enter a file to open
            if (OpenFrom.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    mainSS = new Spreadsheet(this.height, this.width, DefaultBGColor); // Reinitializes the spreadsheet
                    dataGridView1.Rows.Clear(); // clears all rows in the UI
                    dataGridView1.Columns.Clear(); // clears all columns in the UI
                    Form1_Load(sender, e); // Reinitializes the DataGridView

                    MainSave.Load(OpenFrom.FileName, mainSS); // Loads the info from the input file
                    MainSave.Saved = true; // Form comes in as saved
                    SaveLabel.Text = "Load Successful.";
                    undoToolStripMenuItem.Enabled = false;
                    undoToolStripMenuItem.Text = "Undo"; // loading resets the undo system
                    redoToolStripMenuItem.Enabled = false;
                    redoToolStripMenuItem.Text = "Redo"; // loading resets the redo system
                }
                catch (Exception err) // catches an exception if the file failed to load
                {
                    DialogResult CannotOpen = MessageBox.Show(err.Message, "Error - Cannot Open File", MessageBoxButtons.OK);
                }
            }
        }
예제 #12
0
 public Form1()
 {
     InitializeComponent();
     mainSS = new Spreadsheet(this.height, this.width, DefaultBGColor); // Creats a new spreadsheet of size 50 rows by 26 columns with the default window color (-1)
     MainSave = new SaveLoad();
 }
예제 #13
0
        private void newToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DialogResult Ensure = MessageBox.Show("Continue?", "New Spreadsheet", MessageBoxButtons.YesNo);

            if (Ensure == DialogResult.Yes) // Ensures the user meant to start a new form
            {
                if (!MainSave.Saved) // If the current form's state has not been saved, will ask if it should be 
                {
                    DialogResult closing = MessageBox.Show("Save Spreadsheet?", "New Spreadsheet", MessageBoxButtons.YesNoCancel);

                    if (closing == DialogResult.Yes)
                        saveToolStripMenuItem_Click(this, e); // Executes saving of form
                    else if (closing == DialogResult.Cancel)
                        return; // cancels the new form execution
                }

                mainSS = new Spreadsheet(this.height, this.width, DefaultBGColor); // Reinitializes the spreadsheet
                dataGridView1.Rows.Clear(); // clears all rows in the UI
                dataGridView1.Columns.Clear(); // clears all columns in the UI
                Form1_Load(sender, e); // Reinitializes the DataGridView
            }
        }
예제 #14
0
        // ops  redo action and does it
        public void Redo(Spreadsheet sheet)
        {
            UndoRedoCollection action = mRedos.Pop();

            mUndos.Push(action.Restore(sheet));
        }
        //execute the cmds
        public UndoRedoCollection Execute(Spreadsheet sheet)
        {
            List<IUndoRedoCmd> commands = new List<IUndoRedoCmd>();

            foreach(IUndoRedoCmd cmd in _cmds)
            {
                commands.Add(cmd.Execute(sheet));
            }

            return new UndoRedoCollection(commands, this.Description);
        }
 public void performRedo(Spreadsheet sheet)
 {
     UndoRedoCollection redo = _redos.Pop();
     _undos.Push(redo.Execute(sheet));
 }
예제 #17
0
 public void Load(string FromFile, Spreadsheet Sender)
 {
     using (StreamReader ReadStream = new StreamReader(FromFile)) // Uses a StreamReader -> can be changed to any stream
     {
         try
         {
             Load_Pvt(ReadStream, Sender); // attempts to load from the specified stream
             Sender.ClearUndoRedoSystem(); // Clears the undo/redo system
             this.FileName = FromFile; // updates the file name to the file that was just loaded in (allows to save to it again without prompting)
         }
         catch (XmlException e)
         {
             throw e;
         }
     }
 }
예제 #18
0
        private bool Load_Pvt(TextReader FromStream, Spreadsheet Sender)
        {
            XmlReader xmlRead = XmlReader.Create(FromStream); // initializes the XMLReader with the passed stream

            if (xmlRead != null)
            {
                using (xmlRead) // opens the stream
                {
                    SpreadsheetCell to = null; // changes to the cell that is pulled from the .xml file
                    while (!xmlRead.EOF) // while there is still information to be read
                    {
                        if (xmlRead.IsStartElement()) // ensures that the reader is at a start element
                        {
                            switch (xmlRead.Name) // checks various names -> skips over unknown names
                            {
                                case "Cell":
                                    xmlRead.MoveToFirstAttribute(); // moves to the name attribute
                                    string cell = xmlRead.Value;
                                    to = Sender.StringToCell(cell); // will grab the cell from the spreadsheet using this name/attribute
                                    xmlRead.Read(); 
                                    break;
                                case "Text":
                                    Sender[to.RowIndex, to.ColumnIndex].Text = xmlRead.ReadElementContentAsString(); // sets Text
                                    break;
                                case "BGColor":
                                    Sender[to.RowIndex, to.ColumnIndex].BGColor = xmlRead.ReadElementContentAsInt(); // sets BGColor
                                    break;
                                default: // simply reads over the unknown element -> also skips spreadsheet name (nothing is done here at the moment)
                                    xmlRead.Read();
                                    break;
                            }
                        }
                        else
                            xmlRead.Read(); // simply passed anything that is not a start element
                    }
                }

                return true;
            }

            return false;
        }
예제 #19
0
파일: Form1.cs 프로젝트: alexman258/CS321
        //public string version = SpreadsheetEngine.Spreadsheet.Version;

        public Spreadsheet()
        {
            InitializeComponent();
            SpSheet = new SpreadsheetEngine.Spreadsheet(26, 50);    // Set size of spreadsheet
            SpSheet.CellPropertyChanged += Spreadsheet_CellPropertyChanged;
        }