예제 #1
0
 /// <summary>
 /// new constructor with spreasheet as parameter, and Spreadsheetmodel
 /// it will call the spreadsheet model constructor first
 /// </summary>
 /// <param name="ss"></param>
 public Form1(Spreadsheet ss, SpreadsheetModel ssm)
     : this()
 {
     this.ss = ss;
     this.spreadsheetmodel = ssm;
     BindingModelEvent();
 }
예제 #2
0
 public void DivisionByZero1(AbstractSpreadsheet ss)
 {
     Set(ss, "A1", "4.1");
     Set(ss, "B1", "0.0");
     Set(ss, "C1", "= A1 / B1");
     Assert.IsInstanceOfType(ss.GetCellValue("C1"), typeof(FormulaError));
 }
예제 #3
0
        public string SetContentsWithFormulaReturnString(AbstractSpreadsheet sheet, string name, Formula formula)
        {
            List<string> cell_names = new List<string>(sheet.SetCellContents(name, formula));
            string[] cell_array = cell_names.ToArray();
            string text = string.Join(",", cell_array);

            return text;
        }
예제 #4
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);
 }
예제 #5
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);
 }
예제 #6
0
 // 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]));
         }
     }
 }
예제 #7
0
        // 
        //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]));
                }
            }
        }
예제 #8
0
 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);
 }
예제 #9
0
        /// <summary>
        /// Event for Open button on the File menu. Checks to save if a change has been made. Then opens a .sprd file.
        /// </summary>
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (documentChanged)
            {
                var result = MessageBox.Show(@"Do you want to save changes to " + documentName + @"?", @"Opening New Spreadsheet", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
                if (result == DialogResult.Yes)
                {
                    if (filepath == null)
                    {
                        saveAsMenuItem_Click(null, null);
                    }
                    else
                    {
                        saveToolStripMenuItem1_Click(null, null);
                    }
                }
                else if (result == DialogResult.Cancel)
                {
                    return;
                }
            }
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.Filter           = @"Spreadsheet Files (*.sprd)|*.sprd|All files (*.*)|*.*";
            openFileDialog1.FilterIndex      = 1;
            openFileDialog1.RestoreDirectory = true;

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                String filename = openFileDialog1.FileName;
                try
                {
                    ourSpreadsheet = new Spreadsheet(filename, isValid, Normalize, Version);
                }
                catch (Exception exception)
                {
                    MessageBox.Show(exception.GetType() + @":\n" + exception.Message);
                }
                filepath     = filename;
                documentName = Path.GetFileNameWithoutExtension(filename);
                saveToolStripMenuItem1.Enabled = false;
                this.Text       = documentName + @"- " + applicationName;
                documentChanged = false;
                spreadsheetPanel.Clear();
                UpdateCells(ourSpreadsheet.GetNamesOfAllNonemptyCells());
            }
        }
        /// <summary>
        /// Method for starting and initializing the form
        /// </summary>
        public Form1()
        {
            InitializeComponent();

            // Set the columnValue text box to be A when the form starts
            columnValue.Text = "A";
            // Set the rowValue text box to be 1 when the form starts
            rowValue.Text = 1.ToString();
            // Set the cellNameValue text box to be A1 when the form starts
            cellNameValue.Text = "A" + 1.ToString();

            // Initialize the spreadSheet when the form starts
            spreadSheet = new Spreadsheet();

            // Keep track of when the spreadSheet changes selection and call displaySelection when it does to update the spreadsheet panel
            spreadsheetPanel1.SelectionChanged += displaySelection;
        }
예제 #11
0
 /// <summary>
 /// Private method that is called when a mistake is made in hero mode. It deletes the save and resets the data.
 /// </summary>
 private void HeroModeReset()
 {
     if (filepath != null)
     {
         System.IO.File.Delete(filepath);
     }
     MessageBox.Show(
         @"You've made a mistake in HERO MODE. Your save has been deleted and the spreadsheet will now reset. Better luck next time!");
     ourSpreadsheet = new Spreadsheet(isValid, Normalize, Version);
     spreadsheetPanel.Clear();
     contentsBox.Text           = "";
     valueBox.Text              = "";
     heroMode                   = false;
     heroModeSaved              = false;
     spreadsheetPanel.BackColor = System.Drawing.SystemColors.Control;
     documentName               = "untitled";
     applicationName            = "Spreadsheet";
     this.Text                  = documentName + @"- " + applicationName;
 }
예제 #12
0
파일: Form1.cs 프로젝트: jimibue/cs3505
        /// <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);
            
        }
예제 #13
0
        /// <summary>
        /// Creates a new instance of Form1 with its own spreadsheet window and internal data structures.
        /// </summary>
        public spreadsheetWinForm()
        {
            InitializeComponent();

            // This could also be done graphically in the designer, as has been
            // demonstrated in class.
            spreadsheetPanel.SelectionChanged += cellSelected;
            spreadsheetPanel.SetSelection(2, 3);
            cellName.Text         = ((char)('A' + 2)) + @":" + (4);
            previousCellX         = 2;
            previousCellY         = 3;
            contentButton.Enabled = false;

            //Initialize our internal spreadsheet
            ourSpreadsheet = new Spreadsheet(isValid, Normalize, Version);

            //Jukebox
            jukebox             = new WMPLib.WindowsMediaPlayer();
            jukeboxPlay.Enabled = false;

            //Colorized Cells
            //coloredPoints = new HashSet<Point>();
        }
예제 #14
0
 public void NumberFormula2(AbstractSpreadsheet ss)
 {
     Set(ss, "A1", "= 4.6");
     VV(ss, "A1", 4.6);
 }
예제 #15
0
 public Form1()
 {
     InitializeComponent();
     //create a spreadsheet
     ss = new Spreadsheet(s => true, delegate(string s) { return s.ToUpper(); }, "ps6");
 }
예제 #16
0
 public void OneString(AbstractSpreadsheet ss)
 {
     Set(ss, "B1", "hello");
     VV(ss, "B1", "hello");
 }
예제 #17
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);
 }
예제 #18
0
 public void OneNumber(AbstractSpreadsheet ss)
 {
     Set(ss, "C1", "17.5");
     VV(ss, "C1", 17.5);
 }
예제 #19
0
파일: Form1.cs 프로젝트: jimibue/cs3505
        /// <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);
                }
            }
        }
예제 #20
0
 // 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;
 }
예제 #21
0
 public void OneNumber(AbstractSpreadsheet ss)
 {
     Set(ss, "C1", "17.5");
     VV(ss, "C1", 17.5);
 }
예제 #22
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);
 }
예제 #23
0
 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);
 }
예제 #24
0
 public void Formula2(AbstractSpreadsheet ss)
 {
     Set(ss, "a1", "= a2 + a3");
     Set(ss, "a2", "= a3");
     Set(ss, "a3", "6.0");
     VV(ss, "a1", 12.0, "a2", 6.0, "a3", 6.0);
     Set(ss, "a3", "5.0");
     VV(ss, "a1", 10.0, "a2", 5.0, "a3", 5.0);
 }
예제 #25
0
 public void DivisionByZero2(AbstractSpreadsheet ss)
 {
     Set(ss, "A1", "5.0");
     Set(ss, "A3", "= A1 / 0.0");
     Assert.IsInstanceOfType(ss.GetCellValue("A3"), typeof(FormulaError));
 }
예제 #26
0
 public void Formulas(AbstractSpreadsheet ss)
 {
     Set(ss, "A1", "4.4");
     Set(ss, "B1", "2.2");
     Set(ss, "C1", "= A1 + B1");
     Set(ss, "D1", "= A1 - B1");
     Set(ss, "E1", "= A1 * B1");
     Set(ss, "F1", "= A1 / B1");
     VV(ss, "C1", 6.6, "D1", 2.2, "E1", 4.4 * 2.2, "F1", 2.0);
 }
예제 #27
0
 public void EmptyArgument(AbstractSpreadsheet ss)
 {
     Set(ss, "A1", "4.1");
     Set(ss, "C1", "= A1 + B1");
     Assert.IsInstanceOfType(ss.GetCellValue("C1"), typeof(FormulaError));
 }
예제 #28
0
 public void NumberFormula1(AbstractSpreadsheet ss)
 {
     Set(ss, "A1", "4.1");
     Set(ss, "C1", "= A1 + 4.2");
     VV(ss, "C1", 8.3);
 }
예제 #29
0
 public void NumberFormula1(AbstractSpreadsheet ss)
 {
     Set(ss, "A1", "4.1");
     Set(ss, "C1", "= A1 + 4.2");
     VV(ss, "C1", 8.3);
 }
예제 #30
0
 public void OneFormula(AbstractSpreadsheet ss)
 {
     Set(ss, "A1", "4.1");
     Set(ss, "B1", "5.2");
     Set(ss, "C1", "= A1+B1");
     VV(ss, "A1", 4.1, "B1", 5.2, "C1", 9.3);
 }
예제 #31
0
 public void NumberFormula2(AbstractSpreadsheet ss)
 {
     Set(ss, "A1", "= 4.6");
     VV(ss, "A1", 4.6);
 }
예제 #32
0
 public void OneString(AbstractSpreadsheet ss)
 {
     Set(ss, "B1", "hello");
     VV(ss, "B1", "hello");
 }
예제 #33
0
        // 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);
        }
예제 #34
0
 public void StringArgument(AbstractSpreadsheet ss)
 {
     Set(ss, "A1", "4.1");
     Set(ss, "B1", "hello");
     Set(ss, "C1", "= A1 + B1");
     Assert.IsInstanceOfType(ss.GetCellValue("C1"), typeof(FormulaError));
 }
예제 #35
0
        private void SYNCEvent(String command)
        {
            //you need to create a spreadsheet here.
            ss = new Spreadsheet();
            String[] temp = CommandParser(command);
            ss.Version = temp[1];

            for (int i = 2; i < temp.Length && (i + 1) < temp.Length; i+=2)
            {
                String cell_name = temp[i];
                String cell_content = temp[i+1];
                ISet<string> CellToRecalculate = ss.SetContentsOfCell(cell_name, cell_content);

                //update the all the relative cell value on the spreadsheet panel
                //get the value of the namede cells, and convert to string
                object value = ss.GetCellValue(cell_name);
                string v;
                if (value is double)
                    v = (double)value + "";
                else if (value is string)
                    v = (string)value;
                else
                    v = "FormulaError";

                //set the value to the panel
                int col = cell_name.First() - 'A';
                int row = row = Int32.Parse(cell_name.Substring(1, cell_name.Length - 1)) - 1;
                spreadsheetPanel1.SetValue(col, row, v);

                //value of each dependent cell in the spreadsheet will be updated
                foreach (string s in CellToRecalculate)
                {
                    value = ss.GetCellValue(s);
                    col = s.First() - 'A';
                    row = Int32.Parse(s.Substring(1, s.Length - 1)) - 1;
                    spreadsheetPanel1.SetValue(col, row, "" + value);
                }
            }
        }