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; }
public KCell(KCell c, bool MultipleCell = false) : base(c, MultipleCell) { KConnection tempConnection; Enum.TryParse(ConnectionInfo, out tempConnection); KConnectionType = tempConnection; _CellType = CellType.K; }
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); } }
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); } }
//public void DatFileAppendLoop(StringBuilder sb, string str, int length) //{ // // don't go beyond the amount of digits allowed in the cell // for (int i = 0; i < length; i++) // { // // need to get all characters from the string // if (i < str.Length) // { // sb.Append(str[i]); // } // // then start adding spaces // else // { // sb.Append(' '); // } // } //} //public string SaveDatFile() //{ // StringBuilder sb = new StringBuilder(); // // header is the name of the app file // sb.AppendLine(_AppName); // // get the row // foreach (List<Cell> listOFCells in _Cells) // { // string str = ""; // // get the cell // foreach (Cell c in listOFCells) // { // if (c is KCell) // { // str = (c as KCell).KValue; // DatFileAppendLoop(sb, str, c.Digits); // } // else // { // str = c.Value.ToString(); // DatFileAppendLoop(sb, str, c.Digits); // } // sb.Append(','); // } // sb.Append("\r\n"); // } // return sb.ToString(); //} public string Save() { StringBuilder sb = new StringBuilder(); sb.AppendLine(_AppName); foreach (List <Cell> listOfCells in _Cells) { foreach (Cell c in listOfCells) { if (c.ValueChanged) { if (c is KCell) { //sb.Append((c as KCell).KValue + ","); KCell kc = c as KCell; for (int i = 0; i < kc.Digits; i++) { // add characters for the full length of the string, do not add sb.Append(i < kc.KValue.Length ? kc.KValue[i] : ' '); } } else { //sb.Append(c.Value + ","); for (int i = 0; i < c.Digits; i++) { // add characters for the full length of the string, do not add sb.Append(i < c.Value.ToString().Length ? c.Value.ToString()[i] : ' '); } } } else { // no value entered or changed, do not change. for (int i = 0; i < c.Digits; i++) { sb.Append(' '); } } sb.Append(","); } sb.AppendLine(); } return(sb.ToString()); }
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); }
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; }
public KCell(KCell c, bool MultipleCell = false) : base(c, MultipleCell) { KConnection tempConnection; Enum.TryParse(ConnectionInfo, out tempConnection); KConnectionType = tempConnection; _CellType = CellType.K; }
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); }