-
Notifications
You must be signed in to change notification settings - Fork 0
/
W_Rules.xaml.cs
149 lines (133 loc) · 5.41 KB
/
W_Rules.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*-----------------------------------------------
* WPF Window W_Rules 29.11.2017 Pavel Khrapkin
* ----------------------------------------------
* --- History ---
* 2017.05.25 - written
* 2017.08.9 - nElms column output
* 2017.08.20 - ListBox<Rules> calculation
* 2017.08.21 - Contect menu in ListBox
* 2017.11.29 - non-static Message adoption
* --- Known Issue & ToDos ---
* - еще нет диалога по допустимости CompSet для выбранного поставщика
* - не написан диалог по вводу и редактированию текста правила
*/
using System;
using System.Collections.Generic;
using System.Windows;
using log4net;
namespace TSmatch
{
/// <summary>
/// Interaction logic for W_Rules.xaml
/// </summary>
public partial class W_Rules : Window
{
public static readonly ILog log = LogManager.GetLogger("W_Rules");
Message.Message Msg = new Message.Message();
public delegate void NextPrimeDelegate();
private bool chkGroups, chkElements;
public W_Rules()
{
InitializeComponent();
Title = "TSmatch: работа с правилами";
DisplayRules();
}
private void DisplayRules()
{
List<Rl> items = getRuleItems(MainWindow.model, rePrice: false);
if (!chkGroups || !chkElements)
{
var mod = MainWindow.model;
mod.mh.Pricing(ref MainWindow.model);
if (!mod.sr.CheckModelIntegrity(mod)) Msg.AskFOK("Model is changed");
items = getRuleItems(MainWindow.model, rePrice: true);
}
WRules.ItemsSource = items;
}
private int nGr, nElms;
private double price;
private List<Rl> getRuleItems(Model.Model model, bool rePrice)
{
List<Rl> items = new List<Rl>();
int chkGr = 0, chkElm = 0;
foreach (var rule in MainWindow.model.Rules)
{
nGr = nElms = 0; price = 0;
if (rePrice)
foreach (var match in model.matches)
calcGr(match.group, rule, match.rule.text);
else
foreach (Group.Group gr in model.elmGroups) calcGr(gr, rule);
string gr_price = string.Format("{0}/{1}:{2,12:N2}р", nGr, nElms, price);
items.Add(new Rl(gr_price, rule.date, rule.sSupl, rule.sCS, rule.text));
chkGr += nGr; chkElm += nElms;
}
chkGroups = model.elmGroups.Count == chkGr;
chkElements = model.elements.Count == chkElm;
return items;
}
private void calcGr(Group.Group gr, Rule.Rule rule, string mtchRuleTxt = "")
{
if (gr.SupplierName != rule.sSupl || gr.CompSetName != rule.sCS) return;
if (mtchRuleTxt != "" && mtchRuleTxt != rule.text) return;
nGr++;
nElms += gr.guids.Count;
price += gr.totalPrice;
}
private void CheckIfChanges()
{
//25/5 throw new NotImplementedException();
}
private class Rl : IComparable<Rl>
{
public string gr_price { get; set; }
public string Date { get; set; }
public string Supplier { get; set; }
public string CompSet { get; set; }
public string RuleText { get; set; }
public string keyRule { get; set; }
public Rl(string _gr_price, DateTime date, string supl, string cs, string ruletxt)
{
gr_price = _gr_price;
Date = date.ToString("d.MM.yy H:mm");
Supplier = supl;
CompSet = cs;
RuleText = ruletxt;
}
int IComparable<Rl>.CompareTo(Rl other)
{
//11/8 if (Flag && !other.Flag) return -1;
//11/8 if (!Flag && other.Flag) return 1;
int result = -CompSet.CompareTo(other.CompSet);
if (result == 0) result = Supplier.CompareTo(other.Supplier);
if (result == 0) result = RuleText.CompareTo(other.RuleText);
return result;
}
}
private void RuleDel_click(object sender, RoutedEventArgs e)
{
if (!Msg.AskYN("Really delete rule?")) return;
Rl sel = (Rl)WRules.SelectedValue;
foreach (var r in MainWindow.model.Rules)
{
if (r.sSupl != sel.Supplier || r.sCS != sel.CompSet || r.text != sel.RuleText) continue;
MainWindow.model.Rules.Remove(r);
break;
}
MainWindow.model.isChanged = true;
WRules.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal
, new NextPrimeDelegate(DisplayRules));
}
private void RuleNew_click(object sender, RoutedEventArgs e)
{
}
private void RuleTextEdit_click(object sender, RoutedEventArgs e)
{
}
private void OK_button_Click(object sender, RoutedEventArgs e)
{
CheckIfChanges();
Close();
}
}
} // end namespace