public int Load(String saveFileName) { int structSize = (sizeof(Int32) + sizeof(bool) + sizeof(long)); FileStream fileStream = new FileStream(saveFileName, FileMode.OpenOrCreate); BinaryReader brFile = new BinaryReader(fileStream); fileStream.Seek(0, SeekOrigin.Begin); int structsCount = brFile.ReadInt32(); if (structsCount == (brFile.BaseStream.Length - 1) / structSize) { _ltdFull.Clear(); _ltmdInfo.Clear(); for (int i = 0; i < structsCount; i++) { TaxData tempTaxData = new TaxData(brFile.ReadBoolean(), new DateTime(brFile.ReadInt64()), brFile.ReadInt32()); TaxMetaData tempTaxMetaData; _ltdFull.Add(tempTaxData); tempTaxMetaData = _ltmdInfo.Find((item) => { return(item.Month == tempTaxData.Date.Month && item.Year == tempTaxData.Date.Year); }); if (tempTaxMetaData == null) { tempTaxMetaData = new TaxMetaData(tempTaxData.Date.Year, tempTaxData.Date.Month); _ltmdInfo.Add(tempTaxMetaData); } tempTaxMetaData.ExcludedDays.Remove(tempTaxData.Date.Day); tempTaxMetaData.TaxAmount += tempTaxData.Amount; } this.ApplayFilter(); brFile.Close(); fileStream.Close(); return(1); } brFile.Close(); fileStream.Close(); return(0); }
public void FillList(DateTime date, int moneyAmount, bool isNew) { TaxMetaData tmdCurrent; if (!isNew) { tmdCurrent = _ltmdInfo.Find(delegate(TaxMetaData item) { return(item.Month == date.Month && item.Year == date.Year); }); foreach (TaxData item in this.Items) { if (!item.Active) { tmdCurrent.ExcludedDays.Add(item.Date.Day); } } tmdCurrent.TaxAmount = moneyAmount; } else { tmdCurrent = new TaxMetaData(date.Year, date.Month, moneyAmount); } RemoveMonth(date.Year, date.Month, isNew); _ltmdInfo.Add(tmdCurrent); List <int> lValues = tmdCurrent.AmountList; for (int i = 0, j = 0; i < tmdCurrent.DaysInMonth; i++, date += TimeSpan.FromDays(1)) { if (!tmdCurrent.ExcludedDays.Contains(i + 1)) { this.Add(new TaxData(true, date, lValues[j++])); } } this.ResetBindings(); }