public void Search(List <StatisticTypeModel> statistics, DateTime startDate, DateTime endDate, bool isSortedByMonth) { _storageStatistics = statistics; _storageStartDate = startDate; _storageEndDate = endDate; _storageIsSortedByMonth = isSortedByMonth; _normalStatisticGroup.Clear(); _teacherFeeStatistcGroup = null; _classPaymentStatisticGroup = null; _diffStatisticGroup = null; foreach (StatisticTypeModel statistic in statistics) { if (statistic.StatisticType == StatisticTypeEnum.Capital) { _capitalStatisticGroup = new FinanceStatisticGroup <CapitalModel>(StatisticTypeEnum.Capital, StatisticTypeManagement.Instance.StatisticTypeCollection.Where(s => s.StatisticType == StatisticTypeEnum.Capital).First().ShownText, _generalDal.GetCapitals(startDate, endDate), startDate, endDate, isSortedByMonth); CapitalChangedEvent?.Invoke(_capitalStatisticGroup, isSortedByMonth); return; } else if (statistic.StatisticType == StatisticTypeEnum.ClassFee) { _classPaymentStatisticGroup = new FinanceStatisticGroup <ClassPaymentModel>(StatisticTypeEnum.ClassFee, StatisticTypeManagement.Instance.StatisticTypeCollection.Where(s => s.StatisticType == StatisticTypeEnum.ClassFee).First().ShownText, _paymentDal.GetClassPaymentList(startDate, endDate), startDate, endDate, isSortedByMonth); } else if (statistic.StatisticType == StatisticTypeEnum.TeacherFee) { _teacherFeeStatistcGroup = new FinanceStatisticGroup <TeacherFeeModel>(StatisticTypeEnum.TeacherFee, StatisticTypeManagement.Instance.StatisticTypeCollection.Where(s => s.StatisticType == StatisticTypeEnum.TeacherFee).First().ShownText, _paymentDal.GetTeacherFeeList(startDate, endDate), startDate, endDate, isSortedByMonth); } else if (statistic.StatisticType == StatisticTypeEnum.AllIncome) { _normalStatisticGroup.Add(new FinanceStatisticGroup <AccountInfoModel>(statistic.StatisticType, StatisticTypeManagement.Instance.StatisticTypeCollection.Where(s => s.StatisticType == statistic.StatisticType).First().ShownText, _paymentDal.GetAccountListByAll(true, startDate, endDate), startDate, endDate, isSortedByMonth)); if (_classPaymentStatisticGroup == null) { _classPaymentStatisticGroup = new FinanceStatisticGroup <ClassPaymentModel>(StatisticTypeEnum.ClassFee, StatisticTypeManagement.Instance.StatisticTypeCollection.Where(s => s.StatisticType == StatisticTypeEnum.ClassFee).First().ShownText, _paymentDal.GetClassPaymentList(startDate, endDate), startDate, endDate, isSortedByMonth); } } else if (statistic.StatisticType == StatisticTypeEnum.AllOutcome) { _normalStatisticGroup.Add(new FinanceStatisticGroup <AccountInfoModel>(statistic.StatisticType, StatisticTypeManagement.Instance.StatisticTypeCollection.Where(s => s.StatisticType == statistic.StatisticType).First().ShownText, _paymentDal.GetAccountListByAll(false, startDate, endDate), startDate, endDate, isSortedByMonth)); if (_teacherFeeStatistcGroup == null) { _teacherFeeStatistcGroup = new FinanceStatisticGroup <TeacherFeeModel>(StatisticTypeEnum.TeacherFee, StatisticTypeManagement.Instance.StatisticTypeCollection.Where(s => s.StatisticType == StatisticTypeEnum.TeacherFee).First().ShownText, _paymentDal.GetTeacherFeeList(startDate, endDate), startDate, endDate, isSortedByMonth); } } else if (statistic.StatisticType != StatisticTypeEnum.Diff) { _normalStatisticGroup.Add(new FinanceStatisticGroup <AccountInfoModel>(statistic.StatisticType, StatisticTypeManagement.Instance.StatisticTypeCollection.Where(s => s.StatisticType == statistic.StatisticType).First().ShownText, _paymentDal.GetAccountListByItem(statistic.ID, startDate, endDate), startDate, endDate, isSortedByMonth)); } } if (statistics.Where(s => s.StatisticType == StatisticTypeEnum.Diff).FirstOrDefault() != null) { _diffStatisticGroup = new Dictionary <DateTime, decimal>(); if (_classPaymentStatisticGroup == null) { _classPaymentStatisticGroup = new FinanceStatisticGroup <ClassPaymentModel>(StatisticTypeEnum.ClassFee, StatisticTypeManagement.Instance.StatisticTypeCollection.Where(s => s.StatisticType == StatisticTypeEnum.ClassFee).First().ShownText, _paymentDal.GetClassPaymentList(startDate, endDate), startDate, endDate, isSortedByMonth); } if (_teacherFeeStatistcGroup == null) { _teacherFeeStatistcGroup = new FinanceStatisticGroup <TeacherFeeModel>(StatisticTypeEnum.TeacherFee, StatisticTypeManagement.Instance.StatisticTypeCollection.Where(s => s.StatisticType == StatisticTypeEnum.TeacherFee).First().ShownText, _paymentDal.GetTeacherFeeList(startDate, endDate), startDate, endDate, isSortedByMonth); } if (_normalStatisticGroup.Where(s => s.StatisticType == StatisticTypeEnum.AllIncome).FirstOrDefault() == null) { _normalStatisticGroup.Add(new FinanceStatisticGroup <AccountInfoModel>(StatisticTypeEnum.AllIncome, StatisticTypeManagement.Instance.StatisticTypeCollection.Where(s => s.StatisticType == StatisticTypeEnum.AllIncome).First().ShownText, _paymentDal.GetAccountListByAll(true, startDate, endDate), startDate, endDate, isSortedByMonth)); } if (_normalStatisticGroup.Where(s => s.StatisticType == StatisticTypeEnum.AllOutcome).FirstOrDefault() == null) { _normalStatisticGroup.Add(new FinanceStatisticGroup <AccountInfoModel>(StatisticTypeEnum.AllOutcome, StatisticTypeManagement.Instance.StatisticTypeCollection.Where(s => s.StatisticType == StatisticTypeEnum.AllOutcome).First().ShownText, _paymentDal.GetAccountListByAll(false, startDate, endDate), startDate, endDate, isSortedByMonth)); } Dictionary <DateTime, decimal> IncomeGroup = _normalStatisticGroup.Where(s => s.StatisticType == StatisticTypeEnum.AllIncome).First().GroupDetais; Dictionary <DateTime, decimal> OutcomeGroup = _normalStatisticGroup.Where(s => s.StatisticType == StatisticTypeEnum.AllOutcome).First().GroupDetais; foreach (DateTime span in IncomeGroup.Keys) { _diffStatisticGroup.Add(span, IncomeGroup[span] + _classPaymentStatisticGroup.GroupDetais[span] - OutcomeGroup[span] - _teacherFeeStatistcGroup.GroupDetais[span]); } } FinanceStatisticChangedEvent?.Invoke(statistics, _normalStatisticGroup, _teacherFeeStatistcGroup, _classPaymentStatisticGroup, _diffStatisticGroup, isSortedByMonth); }