public override void ExecuteCommand(SpreadSheet spreadSheet, IValidator validator)
        {
            base.ExecuteCommand(spreadSheet, validator);
            int sum = GetSum(spreadSheet);

            InsertNumber(spreadSheet, sum);
        }
        public Form1()
        {
            this.InitializeComponent();
            this.dataGridView1.Columns.Clear();

            // Create the columns and set their values
            for (int i = 0; i < this.alphabet.Length; i++)
            {
                this.dataGridView1.Columns.Add(this.alphabet[i].ToString(), this.alphabet[i].ToString());
            }

            // The initial width of the cell could not fit the values, so I had to manually change it
            this.dataGridView1.RowHeadersWidth = 50;

            // Create the rows and set their values
            for (int i = 0; i < 50; i++)
            {
                this.dataGridView1.Rows.Add();
                this.dataGridView1.Rows[i].HeaderCell.Value = (i + 1).ToString();
            }

            // Set the dimensions of the spreadsheet
            this.sheet = new SpreadSheet(50, 26);

            // Subscribe the spreadsheet to the event
            this.sheet.CellPropertyChanged  += this.OnCellPropertyChanged;
            this.sheet.ColorPropertyChanged += this.OnCellPropertyChanged;

            this.dataGridView1.CellBeginEdit          += this.DataGridView1_CellBeginEdit;
            this.dataGridView1.CellEndEdit            += this.DataGridView1_CellEndEdit;
            this.dataGridView1.BackgroundColorChanged += this.ChangeBackToolStripMenuItem_Click;
            this.undoToolStripMenuItem.Enabled         = false;
            this.redoTextToolStripMenuItem.Enabled     = false;
        }
示例#3
0
        public void SelectSpreadSheetTest()
        {
            var w     = 10;
            var h     = 10;
            var cells = new List <SpreadSheetCell>()
            {
                new SpreadSheetCell(1, 1, "10"),
                new SpreadSheetCell(1, 2, "20"),
                new SpreadSheetCell(1, 3, "30")
            };
            var sheet        = SpreadSheet.CreateSheet(w, h, cells);
            var selectCommad = _commandParser.PaserCommand("S");
            var selectSheet  = selectCommad.Operate("1 1 1 2", sheet);
            var cell1x1yVal  = selectSheet.GetVal(1, 1);
            var cell1x2yVal  = selectSheet.GetVal(1, 2);
            var cell1x3yVal  = selectSheet.GetVal(1, 3);

            Assert.True("10" == cell1x1yVal && "20" == cell1x2yVal && null == cell1x3yVal);

            Assert.Throws <SpreadSheetException>(() =>
            {
                selectCommad.Operate("11 11", sheet);
            });

            Assert.Throws <SpreadSheetException>(() =>
            {
                selectCommad.Operate("1 2 2", sheet);
            });
        }
        private void InsertNumber(SpreadSheet spreadSheet, int sum)
        {
            var insertNumberCommand   = new InsertNumberCommand(X3, Y3, sum);
            var insertNumberValidator = new InsertNumberValidator();

            insertNumberCommand.ExecuteCommand(spreadSheet, insertNumberValidator);
        }
示例#5
0
        public void Validate(SpreadSheet spreadSheet, IBaseCommand command)
        {
            var createNewSpreadSheetCommand = command as CreateNewSpreadSheetCommand;

            if (createNewSpreadSheetCommand == null)
            {
                throw new ArgumentException("Invalid command type", nameof(command));
            }

            if (createNewSpreadSheetCommand.Width <= 0)
            {
                throw new ValidationException($"Width should more than 0. Parameter name: {nameof(createNewSpreadSheetCommand.Width)}");
            }

            if (createNewSpreadSheetCommand.Height <= 0)
            {
                throw new ValidationException($"Height should more than 0. Parameter name: {nameof(createNewSpreadSheetCommand.Height)}");
            }

            // Breaks unit test because console window is not opened during tests I suppose
            if ((createNewSpreadSheetCommand.Width * Globals.CellSize) + 1 >= Console.WindowWidth)
            {
                throw new ValidationException($"Width should be less than window width. Parameter name: {createNewSpreadSheetCommand.Width}");
            }

            if (createNewSpreadSheetCommand.Height >= Console.WindowHeight)
            {
                throw new ValidationException($"Height should be less than window height. Parameter name: {nameof(createNewSpreadSheetCommand.Height)}");
            }
        }
示例#6
0
        public void SpreadSheetTest()
        {
            SpreadSheet s  = new SpreadSheet(3, 3);
            Format      f1 = new Format {
                FontName = "Osaka", FontSize = 12
            };
            Format f2 = new Format {
                FontName = "Monaco", FontSize = 10
            };

            for (int x = 0; x < 3; x++)
            {
                for (int y = 0; y < 3; y++)
                {
                    s.SetData(x, y, "foo");
                    if (x % 2 == 0)
                    {
                        s.SetFormat(x, y, f1);
                    }
                    else
                    {
                        s.SetFormat(x, y, f2);
                    }
                }
            }
            Assert.Equal("Monaco", s.Cell(1, 1).Format.FontName);
            Assert.Equal("Osaka", s.Cell(2, 1).Format.FontName);
        }
示例#7
0
        private void PrintBorder(SpreadSheet spreadSheet)
        {
            int count  = (spreadSheet.Width * Globals.CellSize) + 1;
            var border = new string(Globals.Border, count);

            Console.WriteLine(border);
        }
示例#8
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (investmentText.Text.Length > 0)
            {
                investment = Double.Parse(investmentText.Text);
            }

            //Process dividend amount list
            string shareSheet = @"C:\Users\FelixXingyao\Desktop\Share\dividend.xlsx";
            //string shareSheet = @"E:\\Share\\dividend.xlsx";
            DataTable dividendTable = new SpreadSheet(shareSheet, "").CurrentSpreadSheet;

            DataColumn[] dividendKeys = new DataColumn[1];
            dividendKeys[0]          = dividendTable.Columns[0];
            dividendTable.PrimaryKey = dividendKeys;

            //Process share price list
            string priceSheet = @"C:\Users\FelixXingyao\Desktop\Share\sharePrice.xlsx";
            //string priceSheet = @"E:\\Share\\sharePrice.xlsx";
            DataTable priceTable = new SpreadSheet(priceSheet, "").CurrentSpreadSheet;

            DataColumn[] priceKeys = new DataColumn[1];
            priceKeys[0]          = priceTable.Columns[0];
            priceTable.PrimaryKey = priceKeys;

            //Combine two lists
            DataTable combinedTable = FactoryDataTableParser.combineDataTables(dividendTable, priceTable, investment);

            Share[] shares;
            FactoryDataTableParser.FillShareList(out shares, combinedTable);

            dataGrid.ItemsSource = shares;
        }
示例#9
0
 public Semantics(Cell baseCell, Dictionary<string, Cell> cells,
     Network network, SpreadSheet spreadSheet)
 {
     _baseCell = baseCell;
       _cells = cells;
       _network = network;
       _spreadSheet = spreadSheet;
 }
示例#10
0
        public void CreateSpreadSheetTest()
        {
            var w     = 10;
            var h     = 10;
            var sheet = SpreadSheet.CreateSheet(w, h);

            Assert.True(w == sheet.Width && h == sheet.Height, $"成功创建了一个宽为{w},高为{h}的表格");
        }
示例#11
0
 Semantics(Cell baseCell, Dictionary <string, Cell> cells,
           Network network, SpreadSheet spreadSheet)
 {
     _baseCell    = baseCell;
     _cells       = cells;
     _network     = network;
     _spreadSheet = spreadSheet;
 }
        public void TestSelfReference()
        {
            SpreadSheet sheet = new SpreadSheet(50, 26);

            sheet.GetCell(0, 0).Text = "=A1";

            Assert.That(sheet.GetCell(0, 0).Value, Is.EqualTo("!Self Reference"));
        }
        public void TestBadInput()
        {
            SpreadSheet sheet = new SpreadSheet(50, 26);

            sheet.GetCell(0, 0).Text = "=1A1A1";

            Assert.That(sheet.GetCell(0, 0).Value, Is.EqualTo("!Bad Input"));
        }
示例#14
0
        public Form1()
        {
            ColorWindow     = new ColorDialog();
            SpreadSheetData = new SpreadSheet(50, 26);
            SpreadSheetData.CellPropertyChanged += Cell_PropertyChange; // Subscribing to the SpreadSheet Exception
            //SpreadSheetData.UndoPropertyChanged += Undo_RedoChange;

            InitializeComponent();
        }
示例#15
0
        public void Empty_SpreadSheet_Index_Operator_Throws_Exception()
        {
            // arrange
            // act
            var spreadSheet = new SpreadSheet();

            // assert
            Assert.ThrowsException <IndexOutOfRangeException>(() => spreadSheet[1, 1]);
        }
示例#16
0
        public void Empty_SpreadSheet_Height_Equals_Zero()
        {
            // arrange
            // act
            var spreadSheet = new SpreadSheet();

            // assert
            Assert.AreEqual(0, spreadSheet.Height);
        }
示例#17
0
        public void Empty_SpreadSheet_Width_Equals_Zero()
        {
            // arrange
            // act
            var spreadSheet = new SpreadSheet();

            // assert
            Assert.AreEqual(0, spreadSheet.Width);
        }
        public void TestGetCell()
        {
            SpreadSheet sheet = new SpreadSheet(50, 26);

            sheet.GetCell(0, 0).Text = "0";
            sheet.GetCell(1, 1).Text = "=A1";

            Assert.That(sheet.GetCell(1, 1).Value, Is.EqualTo(sheet.GetCell(0, 0).Text));
        }
        public void Validate(SpreadSheet spreadSheet, IBaseCommand command)
        {
            var quitCommand = command as QuitCommand;

            if (quitCommand == null)
            {
                throw new ArgumentException("Invalid command type", nameof(command));
            }
        }
示例#20
0
        public async Task <SpreadSheet> Insert(SpreadSheet spreadSheet)
        {
            var filename = Path.Combine(_workDir, spreadSheet.Id);
            var json     = JsonSerializer.Serialize(spreadSheet);

            await File.WriteAllTextAsync(filename, json);

            return(spreadSheet);
        }
示例#21
0
    public void Start()
    {
        var gameConfigSheet = new SpreadSheet(SpreadSheetKeys.GAME_CONFIG);

        gameConfigSheet.Download();
        headerKeys = new string[] { SpreadSheetKeys.HEADER_NAME, SpreadSheetKeys.HEADER_DATA, SpreadSheetKeys.HEADER_VALE };
        gameConfigSheet.OnDownloadComplete.Subscribe(JsonConfigdata => {
            PraseTranslation(JsonConfigdata);
        });
    }
        public void TestCircularReference()
        {
            SpreadSheet sheet = new SpreadSheet(50, 26);

            sheet.Ok = 1;
            sheet.GetCell(0, 0).Text = "=B1";
            sheet.GetCell(1, 0).Text = "=A1";

            Assert.That(sheet.GetCell(1, 0).Value, Is.EqualTo("!Circular Reference"));
        }
示例#23
0
        private static void ObserverPatternSection()
        {
            var dataSource = new DataSource();

            var chart = new Chart(dataSource);
            var sheet = new SpreadSheet(dataSource);

            dataSource.Value = 1;
            dataSource.Value = 2;
        }
        private DataTable GetSpreadsheetData(string filePath, string sheetName)
        {
            DataTable table = SpreadSheet.ImportToDataTable(filePath, sheetName);

            foreach (DataRow dr in table.Rows)
            {
                var r = dr.ItemArray;
            }
            return(table);
        }
示例#25
0
        private static void ExecuteObserver()
        {
            var spreadSheet = new SpreadSheet();
            var chart       = new Chart();
            var dataSource  = new DataSource();

            dataSource.AddObserver(spreadSheet);
            dataSource.AddObserver(chart);

            dataSource.Value = 3;
        }
 public IActionResult SpreadVna(SpreadSheet spread)
 {
     try
     {
         return(Ok(NPV(spread.values, spread.rate)));
     }
     catch (Exception ex)
     {
         return(NotFound(new { message = ex.Message }));
     }
 }
示例#27
0
        public void InsertNumberValidator_With_Negative_V1_Throws_ValidationException()
        {
            // arrange
            // act
            var spreadSheet = new SpreadSheet();
            var command     = new InsertNumberCommand(1, 1, -1);
            var validator   = new InsertNumberValidator();

            // assert
            Assert.ThrowsException <ValidationException>(() => validator.Validate(spreadSheet, command));
        }
示例#28
0
        public void QuitValidator_Invalid_Type()
        {
            // arrange
            // act
            var spreadSheet = new SpreadSheet();
            var command     = new QuitCommand();
            var validator   = new PerformSumValidator();

            // assert
            Assert.ThrowsException <ArgumentException>(() => validator.Validate(spreadSheet, command));
        }
 private void PopulateSpreadSheet(SpreadSheet spreadSheet)
 {
     spreadSheet.Cells.Clear();
     for (int y = Globals.SpreadSheetStartIndex; y <= Height; y++)
     {
         for (int x = Globals.SpreadSheetStartIndex; x <= Width; x++)
         {
             spreadSheet.Cells.Add(new Cell(x, y));
         }
     }
 }
示例#30
0
        public void Print(SpreadSheet spreadSheet)
        {
            if (spreadSheet == null)
            {
                throw new ArgumentNullException(nameof(spreadSheet));
            }

            PrintBorder(spreadSheet);
            PrintSpreadSheet(spreadSheet);
            PrintBorder(spreadSheet);
        }
示例#31
0
        public SpreadSheet Operate(string input, SpreadSheet spreadSheet = null)
        {
            if (spreadSheet == null)
            {
                throw new SpreadSheetException("您还未创建spreadSheet表,无法对其进行查询操作");
            }
            var selectPoints  = _selectSheetCellParser.GetSelectPoints(input);
            var selectCells   = spreadSheet.GetCells(selectPoints);
            var selectedSheet = SpreadSheet.CreateSheet(spreadSheet.Width, spreadSheet.Height, selectCells);

            return(selectedSheet);
        }