/// <summary> /// This event handler fr any chenges in cell text. /// </summary> /// <param name="sender">object sender.</param> /// <param name="e"> event handler.</param> private void DataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e) { // this.sheet.GetCell(e.RowIndex, e.ColumnIndex).Text = this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString(); this.sheet.CellTextChanged(e.RowIndex, e.ColumnIndex, (string)this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value); ICommand cmd = new ChangeText(this.sheet.GetCell(e.RowIndex, e.ColumnIndex), this.sheet.GetCell(e.RowIndex, e.ColumnIndex).Value, (string)this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value); this.commandManager.AddUndo(cmd); this.UndoRedoAvailable(); }
public void TestChangeColortExecuteMethod() { Spreadsheet spreadsheet = new Spreadsheet(26, 50); Invoker commandControl = new Invoker(); ICommand cmd1 = new ChangeText(spreadsheet.GetCell(1, 1), "10", "50"); cmd1.Execute(); Assert.AreEqual(spreadsheet.GetCell(1, 1).Text, "50"); cmd1.UnExecute(); Assert.AreEqual(spreadsheet.GetCell(1, 1).Text, "10"); }
public void TestRedoUNdoCommand() { Spreadsheet spreadsheet = new Spreadsheet(26, 50); Invoker commandControl = new Invoker(); ICommand cmd = new ChangeText(spreadsheet.GetCell(1, 1), "40", "20"); cmd.Execute(); commandControl.AddUndo(cmd); Assert.AreEqual(spreadsheet.GetCell(1, 1).Text, "20"); commandControl.UndoCommand(); Assert.AreEqual(spreadsheet.GetCell(1, 1).Text, "40"); commandControl.RedoCommand(); Assert.AreEqual(spreadsheet.GetCell(1, 1).Text, "20"); }