// Notify Mirror Cell Dependents Event Handler void NewBalance_NotifyDependents(object sender, EventArgs e) { //Update dependents value Cell c = sender as Cell; if (c == null) { return; } string valueToSend; if (c is KCell) { KCell kc = c as KCell; if (kc.KValue != String.Empty) { valueToSend = kc.KValue; } else { valueToSend = kc.Value.ToString(); } } else if (c is MCell) { MCell mc = c as MCell; valueToSend = mc.MValue; } else { if (c.Value == null) { valueToSend = String.Empty; } else { valueToSend = c.Value.ToString(); } } // Cell's will only be dependent within the current row for (int i = 0; i < NewBalanceDataGridView.ColumnCount; i++) { MCell mc = ViewData.GetCell(c.RowIndex, i) as MCell; if (mc == null) { continue; } if (mc.IsDependent(c)) { mc.MValue = valueToSend; } } }
public KCell DeepCopy() { var tmp343 = new KCell(); if ((C != null) && __isset.c) { tmp343.C = this.C; } tmp343.__isset.c = this.__isset.c; if (__isset.ts) { tmp343.Ts = this.Ts; } tmp343.__isset.ts = this.__isset.ts; if ((V != null) && __isset.v) { tmp343.V = this.V.ToArray(); } tmp343.__isset.v = this.__isset.v; return(tmp343); }
public async global::System.Threading.Tasks.Task ReadAsync(TProtocol iprot, CancellationToken cancellationToken) { iprot.IncrementRecursionDepth(); try { TField field; await iprot.ReadStructBeginAsync(cancellationToken); while (true) { field = await iprot.ReadFieldBeginAsync(cancellationToken); if (field.Type == TType.Stop) { break; } switch (field.ID) { case 1: if (field.Type == TType.List) { { TList _list358 = await iprot.ReadListBeginAsync(cancellationToken); K = new List <byte[]>(_list358.Count); for (int _i359 = 0; _i359 < _list358.Count; ++_i359) { byte[] _elem360; _elem360 = await iprot.ReadBinaryAsync(cancellationToken); K.Add(_elem360); } await iprot.ReadListEndAsync(cancellationToken); } } else { await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken); } break; case 2: if (field.Type == TType.List) { { TList _list361 = await iprot.ReadListBeginAsync(cancellationToken); Cells = new List <KCell>(_list361.Count); for (int _i362 = 0; _i362 < _list361.Count; ++_i362) { KCell _elem363; _elem363 = new KCell(); await _elem363.ReadAsync(iprot, cancellationToken); Cells.Add(_elem363); } await iprot.ReadListEndAsync(cancellationToken); } } else { await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken); } break; case 3: if (field.Type == TType.List) { { TList _list364 = await iprot.ReadListBeginAsync(cancellationToken); Serial_cells = new List <KCellSerial>(_list364.Count); for (int _i365 = 0; _i365 < _list364.Count; ++_i365) { KCellSerial _elem366; _elem366 = new KCellSerial(); await _elem366.ReadAsync(iprot, cancellationToken); Serial_cells.Add(_elem366); } await iprot.ReadListEndAsync(cancellationToken); } } else { await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken); } break; default: await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken); break; } await iprot.ReadFieldEndAsync(cancellationToken); } await iprot.ReadStructEndAsync(cancellationToken); } finally { iprot.DecrementRecursionDepth(); } }
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); }
// Finished Editing Cell Event Handler void NewBalanceDataGridView_CellEndEdit(object sender, System.Windows.Forms.DataGridViewCellEventArgs e) { _cellBeginEdit = NewBalanceDataGridView[e.ColumnIndex, e.RowIndex]; // arbitrary number bool changed; double?d = null; string s = String.Empty; // need to update logic layer string valueToCheck = (string)_cellBeginEdit.Value ?? ""; if (valueToCheck == oldCellValue) { return; } else { changed = true; } if (_cellBeginEdit.Value != null) { d = nullableDoubleTryParse(_cellBeginEdit.Value.ToString()); } if (_cellBeginEdit.Value != null && d == null) { s = _cellBeginEdit.Value.ToString(); } switch (ViewData.GetCellType(e.RowIndex, e.ColumnIndex)) { // don't update if value is not valid case CellType.C: CCell c = ViewData.GetCell(e.RowIndex, e.ColumnIndex) as CCell; if (c == null) { return; } if (changed == true && d != null) { c.OverrideValue((double)d); } else { c.Value = null; } break; case CellType.K: KCell k = ViewData.GetCell(e.RowIndex, e.ColumnIndex) as KCell; if (k == null) { return; } if (s.Length > 0) { k.KValue = s; } else if (d != null && changed == true) { k.KValue = d.ToString(); } else { k.KValue = null; } break; case CellType.M: MCell m = ViewData.GetCell(e.RowIndex, e.ColumnIndex) as MCell; if (m == null) { return; } if (changed == true && d != null) { m.OverrideValue((double)d); } else { m.Value = null; } break; case CellType.W: WCell w = ViewData.GetCell(e.RowIndex, e.ColumnIndex) as WCell; if (w == null) { return; } if (changed == true && d != null) { w.Value = d; } else { w.Value = null; } break; } RecentlySaved = false; }
//Load File Event Handler private void loadToolStripMenuItem_Click(object sender, EventArgs e) { // add string to keep current file name after openfiledialog OpenFileDialog o = new OpenFileDialog() { InitialDirectory = Settings.Default.DefaultPath, RestoreDirectory = true }; if (NewBalanceDataGridView.RowCount > 0) { SaveCheck sc = new SaveCheck(); sc.LabelCorrectlyFromLoad(); DialogResult result = sc.ShowDialog(); if (result == DialogResult.Yes && !string.IsNullOrEmpty(_currentOpenFile)) { saveToolStripMenuItem_Click(this, EventArgs.Empty); } else if (result == DialogResult.Retry || string.IsNullOrEmpty(_currentOpenFile)) { saveAsToolStripMenuItem_Click(this, EventArgs.Empty); } } if (o.ShowDialog() == DialogResult.OK) { FileStream fs = new FileStream(o.FileName, FileMode.Open); StreamReader r = new StreamReader(fs); // first line is the app name string appName = r.ReadLine(); try { EmptyGridView(appName); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK); return; } this.Text = "NewBalance - " + appName; string s; int row = 0, column; double placeHolder; bool firstLine = true; while ((s = r.ReadLine()) != null) { if (!firstLine) { AddRowToDataAndView(); } var items = s.Split(','); column = 0; foreach (string item in items) { if (!String.IsNullOrWhiteSpace(item)) { if (double.TryParse(item, out placeHolder)) { ViewData.GetCell(row, column).Value = placeHolder; } // string, need to set correct string value for celltype // only K has a string value else { KCell kc = ViewData.GetCell(row, column) as KCell; if (kc != null) { kc.KValue = item; } } } column++; } firstLine = false; row++; } r.Close(); fs.Close(); saveToolStripMenuItem.Enabled = true; saveAsToolStripMenuItem.Enabled = true; addRowButton.Enabled = true; // Don't annoy user if they just loaded the file RecentlySaved = true; } }
// Logic Value Changed Event Handler void NewBalance_CellValueChanged(object sender, PropertyChangedEventArgs e) { Cell c = sender as Cell; if (e.PropertyName == "String") { if (sender is KCell) { KCell k = sender as KCell; if (k.KValue != String.Empty) { NewBalanceDataGridView.Rows[k.RowIndex].Cells[k.ColumnIndex].Value = k.KValue; } else { NewBalanceDataGridView.Rows[k.RowIndex].Cells[k.ColumnIndex].Value = k.Value.ToString(); } } else if (sender is MCell) { MCell m = sender as MCell; NewBalanceDataGridView.Rows[m.RowIndex].Cells[m.ColumnIndex].Value = m.MValue; } } else { if (c != null && c.Value == null) { if (c is KCell) { KCell kc = c as KCell; if (kc.KValue != String.Empty) { NewBalanceDataGridView.Rows[c.RowIndex].Cells[c.ColumnIndex].Value = kc.KValue; } else { NewBalanceDataGridView.Rows[c.RowIndex].Cells[c.ColumnIndex].Value = null; } } else if (c is MultipleCell) { MultipleCell mc = c as MultipleCell; if (mc.SelectedValue != null) { NewBalanceDataGridView.Rows[c.RowIndex].Cells[c.ColumnIndex].Value = mc.SelectedValue; } else { NewBalanceDataGridView.Rows[c.RowIndex].Cells[c.ColumnIndex].Value = null; } } else { NewBalanceDataGridView.Rows[c.RowIndex].Cells[c.ColumnIndex].Value = null; } } else { if (c != null) { // need to check if there is a calculation with sender as a dependency ViewData.CheckAndUpdateDependency(c); NewBalanceDataGridView.Rows[c.RowIndex].Cells[c.ColumnIndex].Value = c.Value.ToString(); if (ViewData.HasMultipleCells()) { MultipleCell mc = null; for (int i = 0; i < NewBalanceDataGridView.ColumnCount; i++) { if (ViewData.GetCellType(c.RowIndex, i) == CellType.Multiple) { mc = ViewData.GetCell(c.RowIndex, i) as MultipleCell; break; } } if (mc == null) { return; } // Update Value to the currently selected cell ViewData.CheckAndUpdateMultipleDependency(c, mc); if (mc.ColumnIndex == c.ColumnIndex && mc.RowIndex == c.RowIndex) { NewBalanceDataGridView.Rows[c.RowIndex].Cells[c.ColumnIndex].Value = mc.SelectedValue.ToString(); } } } } } }