/// <summary> /// /// </summary> /// <param name="reader"></param> /// <exception cref="XmlException.XmlException">Not parsing an xml file</exception> public void ReadXml(XmlReader reader) { try { reader.ReadStartElement(XmlTags.ListCases); while (reader.NodeType != XmlNodeType.EndElement) { AbstractCase c = null; switch (reader.LocalName) { case AmountCase.XMLNAME: c = new AmountCase(reader); break; case DateCase.XMLNAME: c = new DateCase(reader); break; case DescriptionCase.XMLNAME: c = new DescriptionCase(reader); break; case FixDescriptionCase.XMLNAME: c = new FixDescriptionCase(reader); break; case GrayUnaccessibleCase.XMLNAME: c = new GrayUnaccessibleCase(reader); break; case OkayCase.XMLNAME: c = new OkayCase(reader); break; case ReadonlyAmountCase.XMLNAME: c = new ReadonlyAmountCase(reader); break; } if (c == null) { throw new Exception("Parsing error. Are you sure the xml file is correct?"); } Add(c); } reader.ReadEndElement(); } catch (XmlException) { throw new XmlException("XmlException : You are not parsing an Xml file"); } }
/// <summary> /// Updates the real and theoretical amount of a column /// </summary> /// <param name="col">The updated column</param> private void UpdateAmounts(int col) { // It's not an account column if (col == 0 || col >= ColumnCount - 2) { return; } int colC = ColumnCount; int colC2 = colC - 2; int rowC = RowCount; // Both amounts begin with the initial amount decimal initialAmount = (this[GetCaseIndex(col, 1)] as AmountCase).Amount; decimal sumReal = initialAmount; decimal sumTheo = initialAmount; // For every operation row for (int i = 2; i < rowC - 2; ++i) { AmountCase c = this[GetCaseIndex(col, i)] as AmountCase; if (c == null) { continue; } decimal caseAmount = c.Amount; // Theoretical amount sumTheo += caseAmount; // Real amount OkayCase okayC = this[GetCaseIndex(colC2, i)] as OkayCase; if (okayC != null && okayC.IsOkay) { sumReal += caseAmount; } } // Update real amount & theoretical amount (this[GetCaseIndex(col, rowC - 2)] as ReadonlyAmountCase).Amount = sumReal; (this[GetCaseIndex(col, rowC - 1)] as ReadonlyAmountCase).Amount = sumTheo; }
/// <summary> /// If the value of an AmountCase or an OkayCase changes => this method is called /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void CaseChanged(object sender, PropertyChangedEventArgs e) { if (ModifyingColumns) { return; } AmountCase c = sender as AmountCase; OkayCase c1 = sender as OkayCase; int col = -1; if (c == null) { if (c1 == null) // If the case isn't an OkayCase or AmountCase { return; } else // It's an okay case { int colC = ColumnCount - 2; for (int i = 1; i < colC; ++i) // Find the AmountCase in the row (the rest is GrayUnaccessible) { if (this[GetCaseIndex(i, c1.Row)] is AmountCase) { col = i; break; } } } } else // If it's an amount case, we have the column that needs to be updated { col = c.Column; } if (col != -1) { UpdateAmounts(col); } }