|
@@ -2,24 +2,116 @@
|
|
|
using Prism.Mvvm;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
+using System.Data.Entity;
|
|
|
using System.Linq;
|
|
|
+using System.Runtime.InteropServices;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
+using System.Windows.Controls;
|
|
|
+using System.Windows.Forms.DataVisualization.Charting;
|
|
|
+using System.Windows.Media;
|
|
|
+
|
|
|
+// https://www.c-sharpcorner.com/article/static-and-dynamic-line-chart-in-wpf-with-mvvm-pattern-using-prism-library/
|
|
|
|
|
|
namespace DontHarmDesktop.ViewModels.Reports
|
|
|
{
|
|
|
public class EmployeeCostVM : BindableBase
|
|
|
{
|
|
|
+ /// <summary>
|
|
|
+ /// Команда "Сформировать"
|
|
|
+ /// </summary>
|
|
|
public DelegateCommand StartCmd { get; set; }
|
|
|
|
|
|
- public EmployeeCostVM()
|
|
|
+ /// <summary>
|
|
|
+ /// Даные для графика
|
|
|
+ /// </summary>
|
|
|
+ private List<KeyValuePair<string, int>> Costs { get; set; }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Интерфейс для отображения точек
|
|
|
+ /// </summary>
|
|
|
+ private readonly Series SeriesInterface;
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Фильтр по имени
|
|
|
+ /// </summary>
|
|
|
+ public string FilterName { get; set; }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Фильтр по ценности.
|
|
|
+ /// 0: От 0 до 100
|
|
|
+ /// 1: От 101 до 250
|
|
|
+ /// 2: От 251
|
|
|
+ /// </summary>
|
|
|
+ public int PriceIndex { get; set; }
|
|
|
+
|
|
|
+ public EmployeeCostVM(Series series)
|
|
|
{
|
|
|
StartCmd = new DelegateCommand(StartExecuted);
|
|
|
+ Costs = new List<KeyValuePair<string, int>>();
|
|
|
+ SeriesInterface = series;
|
|
|
+ FilterName = "";
|
|
|
+ PriceIndex = -1;
|
|
|
}
|
|
|
|
|
|
public void StartExecuted()
|
|
|
{
|
|
|
+ Refresh();
|
|
|
+ }
|
|
|
+
|
|
|
+ private async void Refresh()
|
|
|
+ {
|
|
|
+ var db = new Models.Entities();
|
|
|
+ Costs.Clear();
|
|
|
+
|
|
|
+ await db.users.ForEachAsync(u =>
|
|
|
+ {
|
|
|
+ // Фильтр имени пользователя
|
|
|
+ if (!string.IsNullOrEmpty(FilterName) && !u.HumanName.ToLower().Contains(FilterName.ToLower()))
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ float priceness = u.Priceness;
|
|
|
+
|
|
|
+ // Фильтр ценности
|
|
|
+ int lowerPriceness;
|
|
|
+ int higherPriceness;
|
|
|
+ switch(PriceIndex)
|
|
|
+ {
|
|
|
+ case 0:
|
|
|
+ lowerPriceness = 0;
|
|
|
+ higherPriceness = 100;
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ lowerPriceness = 101;
|
|
|
+ higherPriceness = 250;
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ lowerPriceness = 251;
|
|
|
+ higherPriceness = int.MaxValue;
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ lowerPriceness = 0;
|
|
|
+ higherPriceness = int.MaxValue;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if (!(lowerPriceness < priceness && priceness < higherPriceness))
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ Costs.Add(new KeyValuePair<string, int>
|
|
|
+ (
|
|
|
+ u.HumanName,
|
|
|
+ (int)priceness
|
|
|
+ ));
|
|
|
+ });
|
|
|
|
|
|
+ SeriesInterface.Points.Clear();
|
|
|
+ Costs.ForEach(
|
|
|
+ item => SeriesInterface.Points.AddXY(item.Key, item.Value)
|
|
|
+ );
|
|
|
}
|
|
|
}
|
|
|
}
|