/// <summary> /// 显示年度汇总 /// </summary> /// <param name="account"></param> private async void DisplayYear(ExpenseAccount account) { var task1 = Task.Run(() => { List <EnergyExpense> data = new List <EnergyExpense>(); for (int i = startYear; i <= nowYear; i++) { var yearData = BusinessFactory <ElectricExpenseBusiness> .Instance.FindYearByAccount(account.Id, i); if (yearData.Count() == 0) { continue; } EnergyExpense energyExpense = new EnergyExpense(); energyExpense.BelongDate = new DateTime(i, 1, 1); energyExpense.Quantum = yearData.Sum(r => r.TotalQuantity); energyExpense.Amount = yearData.Sum(r => r.TotalAmount); data.Add(energyExpense); } return(data); }); var result1 = await task1; this.electricYearChart.SetChartTitle(account.ShortName + "历年用电对比"); this.electricYearChart.SetSeriesLengedText(0, "用电量(度)"); this.electricYearChart.DataSource = result1; var task2 = Task.Run(() => { List <EnergyExpense> data = new List <EnergyExpense>(); for (int i = startYear; i <= nowYear; i++) { var yearData = BusinessFactory <WaterExpenseBusiness> .Instance.FindYearByAccount(account.Id, i); if (yearData.Count() == 0) { continue; } EnergyExpense energyExpense = new EnergyExpense(); energyExpense.BelongDate = new DateTime(i, 1, 1); energyExpense.Quantum = yearData.Sum(r => r.TotalQuantity); energyExpense.Amount = yearData.Sum(r => r.TotalAmount); data.Add(energyExpense); } return(data); }); var result2 = await task2; this.waterYearChart.SetChartTitle(account.ShortName + "历年用水对比"); this.waterYearChart.SetSeriesLengedText(0, "用水量(吨)"); this.waterYearChart.DataSource = result2; this.electricYearGridMod.SetAccount(this.currentAccount, EnergyExpenseType.Electric); this.waterYearGridMod.SetAccount(this.currentAccount, EnergyExpenseType.Water); }
/// <summary> /// 载入水费支出 /// </summary> /// <param name="account"></param> /// <param name="year"></param> /// <returns></returns> private async Task <List <EnergyExpense> > LoadWater(ExpenseAccount account, int year) { var task = Task.Run(() => { List <EnergyExpense> expenseData = new List <EnergyExpense>(); var waterExpense = BusinessFactory <WaterExpenseBusiness> .Instance.FindYearByAccount(account.Id, year); foreach (var exp in waterExpense) { var model = new EnergyExpense(); model.BelongDate = exp.BelongDate; model.Quantum = exp.TotalQuantity; model.Amount = exp.TotalAmount; model.UnitPrice = exp.TotalAmount / exp.TotalQuantity; expenseData.Add(model); } return(expenseData); }); return(await task); }
/// <summary> /// 载入电费支出 /// </summary> /// <param name="account"></param> /// <param name="year"></param> /// <returns></returns> private async Task <List <EnergyExpense> > LoadElectric(ExpenseAccount account, int year) { var task = Task.Run(() => { List <EnergyExpense> electricData = new List <EnergyExpense>(); var electricExpense = BusinessFactory <ElectricExpenseBusiness> .Instance.FindYearByAccount(account.Id, year); foreach (var exp in electricExpense) { var model = new EnergyExpense(); model.BelongDate = exp.BelongDate; model.Quantum = exp.TotalQuantity; model.Amount = exp.TotalAmount; model.AdditionData = exp.TotalPrize; electricData.Add(model); } return(electricData); }); return(await task); }
/// <summary> /// 载入电费支出 /// </summary> /// <param name="group"></param> /// <param name="year"></param> private async Task <List <EnergyExpense> > LoadElectric(Group group, int year) { var task = Task.Run(() => { var items = BusinessFactory <GroupBusiness> .Instance.FindAllItems(group.Id); List <EnergyExpense> data = new List <EnergyExpense>(); foreach (var item in items) { var expense = BusinessFactory <ElectricExpenseBusiness> .Instance.FindYearByAccount(item.OrganizationId, year); foreach (var exp in expense) { var energyExpense = data.SingleOrDefault(r => r.BelongDate == exp.BelongDate); if (energyExpense != null) { energyExpense.Amount += exp.TotalAmount; energyExpense.Quantum += exp.TotalQuantity; energyExpense.AdditionData += exp.TotalPrize; } else { var model = new EnergyExpense(); model.BelongDate = exp.BelongDate; model.Quantum = exp.TotalQuantity; model.Amount = exp.TotalAmount; model.AdditionData = exp.TotalPrize; data.Add(model); } } } return(data); }); return(await task); }
/// <summary> /// 显示摘要 /// </summary> /// <param name="account"></param> private async void DisplaySummary(ExpenseAccount account) { this.ctrAccountInfo.SetAccount(account); //用电 if (account.EnergyType.Contains(1)) { this.electricMeterGrid.DataSource = account.ElectricMeters; var task = Task.Run(() => { List <EnergyExpense> electricData = new List <EnergyExpense>(); var electricExpense = BusinessFactory <ElectricExpenseBusiness> .Instance.FindYearByAccount(account.Id, this.nowYear); foreach (var exp in electricExpense) { var model = new EnergyExpense(); model.BelongDate = exp.BelongDate; model.Quantum = exp.TotalQuantity; model.Amount = exp.TotalAmount; model.AdditionData = exp.TotalPrize; electricData.Add(model); } return(electricData); }); var data = await task; this.currentYearElectricGrid.DataSource = data; this.currentYearElectricGrid.ShowAddition("功率因数奖(元)"); this.currentYearElectricChart.SetChartTitle(string.Format("{0}{1}年电量消耗", account.ShortName, this.nowYear)); this.currentYearElectricChart.SetDataSource(data); } //用水 if (account.EnergyType.Contains(2)) { this.waterMeterGrid.DataSource = account.WaterMeters; var task = Task.Run(() => { List <EnergyExpense> waterData = new List <EnergyExpense>(); var electricExpense = BusinessFactory <WaterExpenseBusiness> .Instance.FindYearByAccount(account.Id, this.nowYear); foreach (var exp in electricExpense) { var model = new EnergyExpense(); model.BelongDate = exp.BelongDate; model.Quantum = exp.TotalQuantity; model.Amount = exp.TotalAmount; waterData.Add(model); } return(waterData); }); var data = await task; this.currentYearWaterGrid.DataSource = data; this.currentYearWaterChart.SetChartTitle(string.Format("{0}{1}年水量消耗", account.ShortName, this.nowYear)); this.currentYearWaterChart.SetDataSource(data); } }
/// <summary> /// 显示摘要 /// </summary> /// <param name="group"></param> private async void DisplaySummary(Group group) { this.txtGroupName.Text = group.Name; var items = BusinessFactory <GroupBusiness> .Instance.FindAllItems(group.Id); var task1 = Task.Run(() => { List <EnergyExpense> data = new List <EnergyExpense>(); foreach (var item in items) { var expense = BusinessFactory <ElectricExpenseBusiness> .Instance.FindYearByAccount(item.OrganizationId, year); foreach (var exp in expense) { var energyExpense = data.SingleOrDefault(r => r.BelongDate == exp.BelongDate); if (energyExpense != null) { energyExpense.Amount += exp.TotalAmount; energyExpense.Quantum += exp.TotalQuantity; energyExpense.AdditionData += exp.TotalPrize; } else { var model = new EnergyExpense(); model.BelongDate = exp.BelongDate; model.Quantum = exp.TotalQuantity; model.Amount = exp.TotalAmount; model.AdditionData = exp.TotalPrize; data.Add(model); } } } return(data); }); var data1 = await task1; this.currentYearElectricGrid.ShowUnitPrice = false; this.currentYearElectricGrid.ShowAddition("功率因数奖(元)"); this.currentYearElectricGrid.DataSource = data1; var task2 = Task.Run(() => { List <EnergyExpense> waterData = new List <EnergyExpense>(); foreach (var item in items) { var expense = BusinessFactory <WaterExpenseBusiness> .Instance.FindYearByAccount(item.OrganizationId, year); foreach (var exp in expense) { var energyExpense = waterData.SingleOrDefault(r => r.BelongDate == exp.BelongDate); if (energyExpense != null) { energyExpense.Amount += exp.TotalAmount; energyExpense.Quantum += exp.TotalQuantity; } else { var model = new EnergyExpense(); model.BelongDate = exp.BelongDate; model.Quantum = exp.TotalQuantity; model.Amount = exp.TotalAmount; waterData.Add(model); } } } return(waterData); }); var data2 = await task2; this.currentYearWaterGrid.ShowUnitPrice = true; this.currentYearWaterGrid.DataSource = data2; }