Esempio n. 1
0
        public GridData(List <Cell> defaultRow, string nameOfApp)
        {
            foreach (Cell c in defaultRow)
            {
                if (c.CellType == CellType.K)
                {
                    KCell kc = c as KCell;
                    if (kc.KConnectionType != KConnection.AUTO)
                    {
                        continue;
                    }

                    // initialize auto value to 1, user can respecify at a later time
                    kc.Value = 1;
                }
                else if (c.CellType == CellType.C)
                {
                    CCell cc = c as CCell;

                    if (cc != null)
                    {
                        _CalculationCells.Add(cc);
                    }
                }
            }
            _Cells.Add(defaultRow);
            _AppName = nameOfApp;
        }
Esempio n. 2
0
        public void AddCellToOptions(Cell c, List <Cell> cells, bool newMultiCellRow)
        {
            var kCell = c as KCell;
            var cCell = c as CCell;
            var mCell = c as MCell;
            var wCell = c as WCell;

            if (kCell != null)
            {
                KCell kc = new KCell(kCell, newMultiCellRow);
                AddOptionCell(kc);
            }
            else if (cCell != null)
            {
                List <string> names = cCell.ConnectionInfo.Split(new char[] { '(', ')', '+', '-', '*', '/', '^' }).ToList();

                // need for TryParse
                double n;

                List <string> dependencyNamesPossibleDupes = (from name in names
                                                              where name.Length > 0 &&
                                                              !double.TryParse(name, out n)       // make sure the value isn't a direct value
                                                              select name).ToList();

                List <string> dependencyNames = dependencyNamesPossibleDupes.Distinct().ToList();


                List <Cell> dependencies = new List <Cell>();

                foreach (string name in dependencyNames)
                {
                    Cell dependency = cells.First(x => x.Label == name);

                    if (dependency != null)
                    {
                        dependencies.Add(dependency);
                    }
                }

                CCell cc = new CCell(cCell, dependencies, newMultiCellRow);

                AddOptionCell(cc);
            }
            else if (mCell != null)
            {
                MCell mc = new MCell(mCell, newMultiCellRow);

                AddOptionCell(mc);
            }
            else if (wCell != null)
            {
                WCell wc = new WCell(wCell, newMultiCellRow);

                AddOptionCell(wc);
            }
        }
Esempio n. 3
0
        public void AddCellToOptions(Cell c, List<Cell> cells, bool newMultiCellRow)
        {
            var kCell = c as KCell;
            var cCell = c as CCell;
            var mCell = c as MCell;
            var wCell = c as WCell;
            if (kCell != null)
            {
                KCell kc = new KCell(kCell, newMultiCellRow);
                AddOptionCell(kc);
            }
            else if (cCell != null)
            {
                List<string> names = cCell.ConnectionInfo.Split(new char[] { '(', ')', '+', '-', '*', '/', '^' }).ToList();

                // need for TryParse
                double n;

                List<string> dependencyNamesPossibleDupes = (from name in names
                                                                where name.Length > 0 &&
                                                                !double.TryParse(name, out n)     // make sure the value isn't a direct value
                                                                select name).ToList();

                List<string> dependencyNames = dependencyNamesPossibleDupes.Distinct().ToList();


                List<Cell> dependencies = new List<Cell>();

                foreach (string name in dependencyNames)
                {
                    Cell dependency = cells.First(x => x.Label == name);

                    if (dependency != null)
                        dependencies.Add(dependency);
                }

                CCell cc = new CCell(cCell, dependencies, newMultiCellRow);
                    
                AddOptionCell(cc);
            }
            else if (mCell != null)
            {
                MCell mc = new MCell(mCell, newMultiCellRow);

                AddOptionCell(mc);
            }
            else if (wCell != null)
            {
                WCell wc = new WCell(wCell, newMultiCellRow);

                AddOptionCell(wc);
            }
        }
Esempio n. 4
0
        public CCell(CCell c, List <Cell> dependencies, bool multiCell = false) : base(c, multiCell)
        {
            _Calculation  = new Calculation(ConnectionInfo);
            _Dependencies = new Dictionary <Cell, bool>();
            _CellType     = CellType.C;

            // need to call copy contructors for dependencies passed from old cells


            foreach (Cell dependency in dependencies)
            {
                _Dependencies.Add(dependency, false);
            }
        }
Esempio n. 5
0
        public void CheckAndUpdateDependency(Cell cell)
        {
            int row = cell.RowIndex;

            List <Cell> rowValues = _Cells[row];

            List <CCell> calcCells = (from calculation in rowValues
                                      where calculation is CCell
                                      select calculation as CCell).ToList();

            foreach (CCell cc in calcCells)
            {
                // update dependency to make sure if value is changed
                // and has an actual value
                if (cc.IsDependency(cell))
                {
                    cc.Dependencies[cell] = cell.ValueChanged;
                    cc.CheckDependencies();
                }
            }

            // need to check multiple cells for dependencies as well
            List <MultipleCell> multiCells = (from multi in rowValues
                                              where multi is MultipleCell
                                              select multi as MultipleCell).ToList();

            foreach (MultipleCell mc in multiCells)
            {
                foreach (Cell c in mc.CellOptions)
                {
                    CCell calc = c as CCell;
                    if (calc == null)
                    {
                        continue;
                    }

                    if (calc.IsDependency(cell))
                    {
                        calc.Dependencies[cell] = cell.ValueChanged;
                        calc.CheckDependencies();
                    }
                }
            }
        }
Esempio n. 6
0
        public void AddRow()
        {
            int nextRow = _Cells.Count;

            // check each cell

            List <Cell> cells = new List<Cell>();

            foreach (Cell c in _Cells[nextRow - 1])
            {
                if (c.CellType == CellType.C)
                {
                    CCell cc = c as CCell;

                    List<string> names = cc.ConnectionInfo.Split(new char[] { '(', ')', '+', '-', '*', '/', '^' }).ToList();

                    // need for TryParse
                    double n;

                    List<string> dependencyNamesPossibleDupes = new List<string>(); /* = (from name in names
                                                                 where name.Length > 0 &&
                                                                 !double.TryParse(name, out n)     // make sure the value isn't an integer
                                                                 select name).ToList(); */

                    foreach (string name in names)
                    {
                        if (name.Length > 0 && !double.TryParse(name, out n))
                        {
                            dependencyNamesPossibleDupes.Add(name);
                        }
                    }

                    // quicker way to get distinct values
                    HashSet<string> dependencyNames = new HashSet<string>(dependencyNamesPossibleDupes);

                    //List<string> dependencyNames = dependencyNamesPossibleDupes.Distinct().ToList();

                    List<Cell> dependencies = new List<Cell>();

                    foreach (string name in dependencyNames)
                    {
                        Cell dependency = cells.First(x => x.Label == name);

                        if (dependency != null)
                            dependencies.Add(dependency);
                    }

                    CCell copyWithCorrectRow = new CCell(cc, dependencies);
                    _CalculationCells.Add(copyWithCorrectRow);
                    cells.Add(copyWithCorrectRow);
                }
                else if (c.CellType == CellType.W)
                {
                    WCell wc = c as WCell;
                    cells.Add(new WCell(wc));
                }
                else if (c.CellType == CellType.K)
                {
                    KCell kc = c as KCell;

                    KCell kcToAdd = new KCell(kc);

                    if (kcToAdd.KConnectionType == KConnection.AUTO)
                        kcToAdd.Value = kc.Value + 1;
                    if (kcToAdd.KConnectionType == KConnection.DITTO)
                        kcToAdd.KValue = kc.KValue;
                    cells.Add(kcToAdd);
                }
                else if(c.CellType == CellType.M)
                {
                    MCell mc = c as MCell;
                    cells.Add(new MCell(mc));
                }
                else if (c.CellType == CellType.Multiple)
                {
                    MultipleCell multiple = c as MultipleCell;
                    cells.Add(new MultipleCell(multiple, cells));
                }
                else if (c.CellType == CellType.NewScreen)
                {
                    NewScreen ns = c as NewScreen;
                    cells.Add(new NewScreen(ns));
                }

            }
            _Cells.Add(cells);
        }
Esempio n. 7
0
        public List<Cell> ReturnCellsInRow(int rowNumber)
        {
            List<Cell> cols = new List<Cell>();
            int colIndex = 0;

            foreach (List<string> l in _parsedFile)
            {
                MultipleCell multi = null;

                // there will be 5 items in each .APP file
                if (l.Count != 5) break;

                string label = l[0];
                string type = l[1];
                int digits;  // not really necessary for this application, but leaving for reverse compatibility
                int.TryParse(l[2], out digits);

                int precision;
                int.TryParse(l[3], out precision);
                string connectionInfo = l[4];

                switch (type)
                {
                    // keyboard cell
                    case "K":
                        if (MultipleCell.IsMultiCell(label) && cols.OfType<MultipleCell>().ToList().Count > 0) colIndex--;
                        KCell k = new KCell(label, digits, precision, connectionInfo, rowNumber, colIndex);
                        if (MultipleCell.IsMultiCell(label))
                        {
                            multi = BuildMultipleCell(k, cols);
                            if(multi != null) cols.Add(multi);
                        }
                        else
                        {
                            cols.Add(k);
                        }
                        break;
                    // weight cell
                    case "W":
                        if (MultipleCell.IsMultiCell(label) && cols.OfType<MultipleCell>().ToList().Count > 0) colIndex--;
                        WCell w = new WCell(label, digits, precision, connectionInfo, rowNumber, colIndex);

                        if (MultipleCell.IsMultiCell(label))
                        {
                            multi = BuildMultipleCell(w, cols);
                            if(multi != null) cols.Add(multi);
                        }
                        else
                        {
                            cols.Add(w);
                        }
                        break;
                    // calculation cell
                    case "C":
                        List<string> names =
                            connectionInfo.Split(new char[] { '(', ')', '+', '-', '*', '/', '^' }).ToList();

                        // need for TryParse
                        double n;

                        List<string> dependencyNamesPossibleDupes = (from name in names
                            where name.Length > 0 &&
                            !double.TryParse(name, out n)     // make sure the value isn't an integer
                            select name).ToList();

                        List<string> dependencyNames = dependencyNamesPossibleDupes.Distinct().ToList();

                        List<Cell> dependencies = new List<Cell>();

                        foreach (string name in dependencyNames)
                        {
                            Cell dependency = cols.First(x => x.Label == name);

                            if(dependency != null)
                                dependencies.Add(dependency);
                        }

                        if (MultipleCell.IsMultiCell(label) && cols.OfType<MultipleCell>().ToList().Count > 0) colIndex--;

                        CCell c = new CCell(label, digits, precision, connectionInfo, rowNumber, colIndex,
                            dependencies);

                        if (MultipleCell.IsMultiCell(label))
                        {
                            multi = BuildMultipleCell(c, cols);
                            if(multi != null) cols.Add(multi);
                        }
                        else
                        {
                            cols.Add(c);
                        }

                        break;
                    // mirror cell
                    case "M":
                        // find cell to mirror
                        var columnToMirror = cols.FirstOrDefault(x => x.Label == connectionInfo);

                        if (MultipleCell.IsMultiCell(label) && cols.OfType<MultipleCell>().ToList().Count > 0) colIndex--;
                        MCell m = new MCell(label, digits, precision, connectionInfo, rowNumber, colIndex, columnToMirror);

                        if (MultipleCell.IsMultiCell(label))
                        {
                            multi = BuildMultipleCell(m, cols);
                            if(multi != null) cols.Add(multi);
                        }
                        else
                        {
                            cols.Add(m);
                        }
                        break;
                    // newscreen, for backwards compatibility
                    case "0":
                        NewScreen newScreen = new NewScreen(label, digits, precision, connectionInfo, rowNumber, colIndex);
                        cols.Add(newScreen);
                        break;

                }

                colIndex++;
            }

            return cols;
        }
Esempio n. 8
0
        public CCell(CCell c, List<Cell> dependencies, bool multiCell = false ) : base(c, multiCell)
        {
            _Calculation = new Calculation(ConnectionInfo);
            _Dependencies = new Dictionary<Cell, bool>();
            _CellType = CellType.C;

            // need to call copy contructors for dependencies passed from old cells


            foreach (Cell dependency in dependencies )
            {
                _Dependencies.Add(dependency, false);
            }
        }
Esempio n. 9
0
        public void AddRow()
        {
            int nextRow = _Cells.Count;

            // check each cell

            List <Cell> cells = new List <Cell>();

            foreach (Cell c in _Cells[nextRow - 1])
            {
                if (c.CellType == CellType.C)
                {
                    CCell cc = c as CCell;

                    List <string> names = cc.ConnectionInfo.Split(new char[] { '(', ')', '+', '-', '*', '/', '^' }).ToList();

                    // need for TryParse
                    double n;

                    List <string> dependencyNamesPossibleDupes = new List <string>(); /* = (from name in names
                                                                                       * where name.Length > 0 &&
                                                                                       * !double.TryParse(name, out n)     // make sure the value isn't an integer
                                                                                       * select name).ToList(); */


                    foreach (string name in names)
                    {
                        if (name.Length > 0 && !double.TryParse(name, out n))
                        {
                            dependencyNamesPossibleDupes.Add(name);
                        }
                    }

                    // quicker way to get distinct values
                    HashSet <string> dependencyNames = new HashSet <string>(dependencyNamesPossibleDupes);

                    //List<string> dependencyNames = dependencyNamesPossibleDupes.Distinct().ToList();


                    List <Cell> dependencies = new List <Cell>();

                    foreach (string name in dependencyNames)
                    {
                        Cell dependency = cells.First(x => x.Label == name);

                        if (dependency != null)
                        {
                            dependencies.Add(dependency);
                        }
                    }

                    CCell copyWithCorrectRow = new CCell(cc, dependencies);
                    _CalculationCells.Add(copyWithCorrectRow);
                    cells.Add(copyWithCorrectRow);
                }
                else if (c.CellType == CellType.W)
                {
                    WCell wc = c as WCell;
                    cells.Add(new WCell(wc));
                }
                else if (c.CellType == CellType.K)
                {
                    KCell kc = c as KCell;

                    KCell kcToAdd = new KCell(kc);

                    if (kcToAdd.KConnectionType == KConnection.AUTO)
                    {
                        kcToAdd.Value = kc.Value + 1;
                    }
                    if (kcToAdd.KConnectionType == KConnection.DITTO)
                    {
                        kcToAdd.KValue = kc.KValue;
                    }
                    cells.Add(kcToAdd);
                }
                else if (c.CellType == CellType.M)
                {
                    MCell mc = c as MCell;
                    cells.Add(new MCell(mc));
                }
                else if (c.CellType == CellType.Multiple)
                {
                    MultipleCell multiple = c as MultipleCell;
                    cells.Add(new MultipleCell(multiple, cells));
                }
                else if (c.CellType == CellType.NewScreen)
                {
                    NewScreen ns = c as NewScreen;
                    cells.Add(new NewScreen(ns));
                }
            }
            _Cells.Add(cells);
        }