public void Formula3(AbstractSpreadsheet ss) { Set(ss, "A1", "= A3 + A5"); Set(ss, "A2", "= A5 + A4"); Set(ss, "A3", "= A5"); Set(ss, "A4", "= A5"); Set(ss, "A5", "9.0"); VV(ss, "A1", 18.0); VV(ss, "A2", 18.0); Set(ss, "A5", "8.0"); VV(ss, "A1", 16.0); VV(ss, "A2", 16.0); }
public void Formula1(AbstractSpreadsheet ss) { Set(ss, "a1", "= a2 + a3"); Set(ss, "a2", "= b1 + b2"); Assert.IsInstanceOfType(ss.GetCellValue("a1"), typeof(FormulaError)); Assert.IsInstanceOfType(ss.GetCellValue("a2"), typeof(FormulaError)); Set(ss, "a3", "5.0"); Set(ss, "b1", "2.0"); Set(ss, "b2", "3.0"); VV(ss, "a1", 10.0, "a2", 5.0); Set(ss, "b2", "4.0"); VV(ss, "a1", 11.0, "a2", 6.0); }
public void Formula1(AbstractSpreadsheet ss) { Set(ss, "A1", "= A2 + A3"); Set(ss, "A2", "= B1 + B2"); Assert.IsInstanceOfType(ss.GetCellValue("A1"), typeof(FormulaError)); Assert.IsInstanceOfType(ss.GetCellValue("A2"), typeof(FormulaError)); Set(ss, "A3", "5.0"); Set(ss, "B1", "2.0"); Set(ss, "B2", "3.0"); VV(ss, "A1", 10.0, "A2", 5.0); Set(ss, "B2", "4.0"); VV(ss, "A1", 11.0, "A2", 6.0); }
public void Formula3(AbstractSpreadsheet ss) { Set(ss, "a1", "= a3 + a5"); Set(ss, "a2", "= a5 + a4"); Set(ss, "a3", "= a5"); Set(ss, "a4", "= a5"); Set(ss, "a5", "9.0"); VV(ss, "a1", 18.0); VV(ss, "a2", 18.0); Set(ss, "a5", "8.0"); VV(ss, "a1", 16.0); VV(ss, "a2", 16.0); }
/// <summary> /// One argument constructor taking in a filename /// Used for Open /// </summary> /// <param name="fileName"></param> public Form1(string fileName) { InitializeComponent(); spreadsheetPanel1.SelectionChanged += displaySelection; spreadsheet = new Spreadsheet(fileName, n => true, n => n.ToUpper(), "ps6"); letters = new List <string> { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" }; //update_all_textboxes(); update_NonEmpty_Cells(); savedRecently = true; }
// //You can use the following additional attributes as you write your tests: // //Use ClassInitialize to run code before running the first test in the class //[ClassInitialize()] //public static void MyClassInitialize(TestContext testContext) //{ //} // //Use ClassCleanup to run code after all tests in a class have run //[ClassCleanup()] //public static void MyClassCleanup() //{ //} // //Use TestInitialize to run code before running each test //[TestInitialize()] //public void MyTestInitialize() //{ //} // //Use TestCleanup to run code after each test has run //[TestCleanup()] //public void MyTestCleanup() //{ //} // #endregion // Verifies cells and their values, which must alternate. public void VV(AbstractSpreadsheet sheet, params object[] constraints) { for (int i = 0; i < constraints.Length; i += 2) { if (constraints[i + 1] is double) { Assert.AreEqual((double)constraints[i + 1], (double)sheet.GetCellValue((string)constraints[i]), 1e-9); } else { Assert.AreEqual(constraints[i + 1], sheet.GetCellValue((string)constraints[i])); } } }
public Controller(ISpreadsheetView window) { this.window = window; spreadsheet = new Spreadsheet(); activeCell = "A1"; window.CloseEvent += HandleClose; window.XCloseEvent += XHandleClose; window.FileChosenEvent += HandleFileChosen; window.NewEvent += HandleNew; window.SelectionEvent += HandleSelectionChanged; window.ContentsEvent += HandleContentsBoxChange; window.FileSaveEvent += HandleSaveChosen; window.HelpEvent += HandleHelp; }
public void TestGeneralSetAndGetCellContents() { AbstractSpreadsheet s = buildSheet(); Assert.AreEqual(s.GetCellContents("A1").GetType(), typeof(Formula)); Assert.AreEqual("", s.GetCellContents("A2")); Assert.AreEqual("Hello World", s.GetCellContents("A3")); Assert.AreEqual(5.0, s.GetCellContents("B1")); Assert.AreEqual(s.GetCellContents("B2").GetType(), typeof(Formula)); Assert.AreEqual(s.GetCellContents("B3").GetType(), typeof(Formula)); Assert.AreEqual(s.GetCellContents("C1").GetType(), typeof(Formula)); Assert.AreEqual(6.0, s.GetCellContents("C2")); Assert.AreEqual("", s.GetCellContents("C3")); }
/// <summary> /// Controller constructor. /// </summary> public Controller(ISpreadsheetGUI window) { this.window = window; spreadsheet = new Spreadsheet(); save = ""; window.NewEvent += HandleNew; window.CloseEvent += HandleClose; window.KeyDownEvent += HandleKeyDown; window.SelectionChangeEvent += HandleSelectionChange; window.ContentsChangeEvent += HandleContentsChange; window.SaveCheckEvent += HandleSaveCheck; window.OpenEvent += HandleOpen; window.SaveEvent += HandleSave; window.SavingEvent += HandleSaving; }
public void MediumSheet(AbstractSpreadsheet ss) { Set(ss, "A1", "1.0"); Set(ss, "A2", "2.0"); Set(ss, "A3", "3.0"); Set(ss, "A4", "4.0"); Set(ss, "B1", "= A1 + A2"); Set(ss, "B2", "= A3 * A4"); Set(ss, "C1", "= B1 + B2"); VV(ss, "A1", 1.0, "A2", 2.0, "A3", 3.0, "A4", 4.0, "B1", 3.0, "B2", 12.0, "C1", 15.0); Set(ss, "A1", "2.0"); VV(ss, "A1", 2.0, "A2", 2.0, "A3", 3.0, "A4", 4.0, "B1", 4.0, "B2", 12.0, "C1", 16.0); Set(ss, "B1", "= A1 / A2"); VV(ss, "A1", 2.0, "A2", 2.0, "A3", 3.0, "A4", 4.0, "B1", 1.0, "B2", 12.0, "C1", 13.0); }
public SpreadsheetGUI() { InitializeComponent(); this.ss = new Spreadsheet(); docName.Text = "Untitled Spreadsheet"; int col; int row; cells.GetSelection(out col, out row); string name = getCellName(col, row); cellName.Text = name; SelectionChanged(cells); SetStyle(ControlStyles.SupportsTransparentBackColor, true); this.BackColor = Color.Transparent; }
/// <summary> /// Constructor for the Spreadsheet. /// </summary> public Form1() { InitializeComponent(); sheet = new Spreadsheet(s => true, s => s.ToUpper(), "ps6"); spreadsheetPanel1.SelectionChanged += displaySelection; spreadsheetPanel1.SetSelection(0, 0); displaySelection(spreadsheetPanel1); spreadsheetPanel1.SendToBack(); spreadsheetPanel1.Focus(); ContentField.BringToFront(); ContentField.Focus(); this.Hide(); }
/// <summary> /// GUI constructor /// </summary> public Form1() { InitializeComponent(); BGWorker = new BackgroundWorker(); BGWorker.DoWork += new DoWorkEventHandler(BGDoWork); // When spreadsheetPanel's selection is changed, run the getselectionvalues method. SpreadSheetPanel.SelectionChanged += GetSelectionValues; // Cell A1 is selected initially CurrentCellName = "A1"; CellNameDisplayLabel.Text = CurrentCellName; // Create underlying spreadsheet. Spreadsheet = new Spreadsheet(Validator, Normalizer, "ps6"); }
/// <summary> /// constructor /// </summary> public SpreadsheetGUI() { SSModel = new Spreadsheet(s => Regex.IsMatch(s, @"^[a-zA-Z][1-9][0-9]?$"), s => s.ToUpper(), "ps6"); cellChanged = false; InitializeComponent(); // This an example of registering a method so that it is notified when // an event happens. The SelectionChanged event is declared with a // delegate that specifies that all methods that register with it must // take a SpreadsheetPanel as its parameter and return nothing. So we // register the displaySelection method below. // This could also be done graphically in the designer, as has been // demonstrated in class. spreadsheetPanel1.SelectionChanged += displaySelection; spreadsheetPanel1.SetSelection(0, 0); displayCurrentCell(0, 0); }
/// <summary> /// Opens a previously saved document /// </summary> private void open_Click(object sender, EventArgs e) { int num = 1; if (ss.Changed) //check if current document has been modified { saveCheck(out num); } if (num == 0) { save_Click(sender, e); num = 1; } //user wishes to save if (num == 1) //open the document { try{ openFileDialog1.Filter = "Spreadsheet Files (.ss)|*.ss|All Files (*.*)|*.*"; openFileDialog1.FilterIndex = 1; openFileDialog1.FileName = ""; DialogResult result = openFileDialog1.ShowDialog(); // Show the dialog. if (result == DialogResult.OK) // Test result. { string file = openFileDialog1.FileName; using (TextReader open = new StreamReader(file)) { ss = new Spreadsheet(open); cells.Clear(); int col, row; foreach (string s in ss.GetNamesOfAllNonemptyCells()) //Calculate all the cell values { getColRow(s, out col, out row); cells.SetValue(col, row, ss.GetCellValue(s).ToString()); } docName.Text = System.IO.Path.GetFileNameWithoutExtension(file); //set document name to opened file name ssName = file; savedas = true; } docName_TextChanged(sender, e); } SelectionChanged(cells); } //Error Message\\ catch (SpreadsheetReadException) { MessageBox.Show("The file you tried to open may be corrupt"); } } }
/// <summary> /// Single param constructor creates a new controller for passed ISpreadSheetView /// </summary> /// <param name="_view"></param> public Controller(ISpreadSheetView _view) { this.view = _view; var re = new Regex("^[A-Z][1-9][0-9]?$"); //creates new regex limited to (A1-Z99) inclusive this.model = new Spreadsheet(re); //creates new spreadhseet model with designated regex //register all events to handlers view.SetCellContents += HandleSetCellContents; view.GetCellValue += HandleGetCellValue; view.GetCellContents += HandleGetCellContents; view.HelpMenu += HandleHelpMenu; view.SaveSpreadsheet += HandleSaveSpreadsheet; view.SaveAs += HandleSaveAs; view.OpenSpreadsheet += HandleOpenSpreadsheet; view.OpenNewSpreadsheet += HandleOpenNewSpreadsheet; view.CloseEvent += HandleCloseEvent; // Dont forget to update the 2 argument constructor }
/// <summary> /// Creates a new PS6 spreadsheet form with the given file path /// </summary> /// <param name="filePath"></param> public PS6(string filePath) { InitializeComponent(); try { spreadsheet = new Spreadsheet(filePath, isValid, s => s.ToUpper(), "PS6"); } catch (Exception) { MessageBox.Show("File could not be read, check filename/extension/version/contents"); } this.spreadsheetPanel1.SelectionChanged += onCellClicked; this.AcceptButton = EnterButton; saveFileName = filePath; DisplayCellValues(spreadsheet.GetNamesOfAllNonemptyCells(), spreadsheetPanel1); }
public Form1(Spreadsheet sheet) { InitializeComponent(); this.sheet = sheet; foreach (String cellName in sheet.GetNamesOfAllNonemptyCells()) { updateCell(cellName, spreadsheetPanel1); } spreadsheetPanel1.SelectionChanged += displaySelection; spreadsheetPanel1.SetSelection(0, 0); displaySelection(spreadsheetPanel1); spreadsheetPanel1.SendToBack(); spreadsheetPanel1.Focus(); ContentField.BringToFront(); ContentField.Focus(); }
/// <summary> /// Handles request to open file /// </summary> private void HandleFileChosen(string filename) { try { TextReader read = File.OpenText(filename); spreadsheet = new Spreadsheet(read); window.Title = filename; ClearSheet(); foreach (string s in spreadsheet.GetNamesOfAllNonemptyCells()) { setCell(s); } RefreshTextBoxes(); read.Close(); } catch (Exception e) { window.Message = "Unable to open file\n" + e.Message; } }
/// <summary> /// deals with open a new file /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void openToolStripMenuItem_Click(object sender, EventArgs e) { //check if orignal file has been changed if so ask if they want to save. String message = "Would you like to save before closing?"; var result1 = MessageBox.Show(message, "Closing", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result1 == DialogResult.Yes) { saveFile(); } //With help from www.dotnetperls.com //show dialog DialogResult result = openFileDialog1.ShowDialog(); //check result if (result == DialogResult.OK) { string fileName = openFileDialog1.FileName; try { //make new spreadsheet SSModel = new Spreadsheet(fileName, s => Regex.IsMatch(s, @"^[a-zA-Z][1-9][0-9]?$"), s => s.ToUpper(), "ps6"); //fill in the cells in the GUI foreach (String cellName in SSModel.GetNamesOfAllNonemptyCells()) { setRowAndCol(cellName); spreadsheetPanel1.SetValue(col, row, SSModel.GetCellValue(cellName).ToString()); } //set up the spreadsheet spreadsheetPanel1.SetSelection(0, 0); displayCurrentCell(0, 0); }catch (Exception ex) { MessageBox.Show("An error occured:\n " + ex.Message); } } }
public SimpleSpreadsheetGUI() { this.grid_widget = new SpreadsheetGridWidget(); coordinateMap = new Dictionary <Point, string>(); spreadsheet = new Spreadsheet(s => true, s => s.ToUpper(), "six"); labelTimer = new Timer(); // Call the AutoGenerated code InitializeComponent(); //Start a timer for Auto-Save. timer = new Timer(); timer.Interval = 30_000; //30 seconds defined for the interval. timer.Enabled = true; timer.Tick += new System.EventHandler(AutoSave); // Add event handler and select a start cell grid_widget.SelectionChanged += DisplaySelection; grid_widget.SetSelection(0, 0, false); cellName_Textbox.Text = "A1"; cellValue_Textbox.Text = spreadsheet.GetCellValue("A1").ToString(); }
/// <summary> /// Multiple param constructor creates a new controller for a view opened from a file, handles hooking /// and populates the new spreadsheet gui with saved contents /// </summary> /// <param name="_view"></param> /// <param name="ss"></param> /// <param name="pathOpenedFrom"></param> public Controller(ISpreadSheetView _view, AbstractSpreadsheet ss, string pathOpenedFrom) { this.view = _view; this.model = ss; //register all events view.SetCellContents += HandleSetCellContents; view.GetCellValue += HandleGetCellValue; view.GetCellContents += HandleGetCellContents; view.HelpMenu += HandleHelpMenu; view.OpenSpreadsheet += HandleOpenSpreadsheet; view.OpenNewSpreadsheet += HandleOpenNewSpreadsheet; view.SaveSpreadsheet += HandleSaveSpreadsheet; view.SaveAs += HandleSaveAs; view.CloseEvent += HandleCloseEvent; // Dont forget to update the 1 argument constructor // populate all cells foreach (string cellName in this.model.GetNamesOfAllNonemptyCells()) { this.HandleUpdateCellDisplay(cellName); } }
/// <summary> /// Creates a file dialog that allows an existing file to be opened in the same window /// It will clear the contents of the existing window, and populate the window with the contents /// of the spreadsheet to be opened. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void openFileDialog1_FileOk(object sender, CancelEventArgs e) { try { // getting the filename from the file dialog string filePath = openFileDialog1.FileName; // emptying the spreadsheet spreadsheetPanel1.Clear(); //creating a new spreadsheet from the specified file path spread = new Spreadsheet(filePath, s => true, s => s.ToUpper(), "ps6"); this.Text = filePath; // updating the name of the spreadsheet window fileName = filePath; saved = true; // setting the displays of the input boxes at the top DisplayControlsOnSelection(spreadsheetPanel1); // setting the display of the panels DisplayPanelOnOpen(spreadsheetPanel1); // adding the DisplayControlsOnSelection to event handler for the spreadsheet panel spreadsheetPanel1.SelectionChanged += DisplayControlsOnSelection; // setting the cursor to the CellContents input box CellContents.Select(); } catch { MessageBox.Show("There was an error opening the file. Please make sure that the filepath is correct, and that the file is a valid spreadsheet file."); } }
public void RunNewFromFile(AbstractSpreadsheet ss, string name) { // Create the window and the controller SpreadSheetWindow window = new SpreadSheetWindow(); // One more form is running windowCount++; window.Title = name; window.PreviousSaveName = window.Title; // When this form closes, we want to find out window.FormClosed += (o, e) => { if (--windowCount <= 0) { ExitThread(); } }; // Run the form window.Show(); new Controller(window, ss, name); }
// For setting a spreadsheet cell. public IEnumerable <string> Set(AbstractSpreadsheet sheet, string name, string contents) { List <string> result = new List <string>(sheet.SetContentsOfCell(name, contents)); return(result); }
public void NumberFormula2(AbstractSpreadsheet ss) { Set(ss, "A1", "= 4.6"); VV(ss, "A1", 4.6); }
public void NumberFormula1(AbstractSpreadsheet ss) { Set(ss, "A1", "4.1"); Set(ss, "C1", "= A1 + 4.2"); VV(ss, "C1", 8.3); }
public void EmptyArgument(AbstractSpreadsheet ss) { Set(ss, "A1", "4.1"); Set(ss, "C1", "= A1 + B1"); Assert.IsInstanceOfType(ss.GetCellValue("C1"), typeof(FormulaError)); }
public void DivisionByZero2(AbstractSpreadsheet ss) { Set(ss, "A1", "5.0"); Set(ss, "A3", "= A1 / 0.0"); Assert.IsInstanceOfType(ss.GetCellValue("A3"), typeof(FormulaError)); }
public void OneNumber(AbstractSpreadsheet ss) { Set(ss, "C1", "17.5"); VV(ss, "C1", 17.5); }