-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathStatsUI.cs
209 lines (175 loc) · 7 KB
/
StatsUI.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using LiveCharts;
using LiveCharts.Wpf;
using System.Windows.Media;
namespace Kimathi_Construction
{
public partial class StatsUI : UserControl
{
private static StatsUI _instance;
private ChartValues<double> cIncome;
double incDay0 = 0; double incDay5 = 0; double incDay10 = 0;
double incDay15 = 0; double incDay20 = 0; double incDay25 = 0;
double incDayLast = 0;
public static StatsUI Instance
{
get
{
if (_instance == null)
{
_instance = new StatsUI();
}
return _instance;
}
}
public StatsUI()
{
InitializeComponent();
MonthlyUISet();
cartesianChart1.DataClick += CartesianChart1OnDataClick;
}
private void CartesianChart1OnDataClick(object sender, ChartPoint chartPoint)
{
MessageBox.Show("You clicked (" + chartPoint.X + "," + chartPoint.Y + ")");
}
public void Global_StatsUI_Load()
{
//update chart or not
}
private void StatsUI_Load(object sender, EventArgs e)
{
//UI code
SetToolTip(owner, "Follow at twitter @Job_Getabu ;)");
}
private void SetToolTip(Control ctl, string message)
{
ToolTip toolTip1 = new ToolTip();
toolTip1.UseFading = true;
toolTip1.UseAnimation = true;
toolTip1.IsBalloon = true;
toolTip1.AutoPopDelay = 5000;
toolTip1.InitialDelay = 1000;
toolTip1.ReshowDelay = 500;
toolTip1.ShowAlways = true;
toolTip1.SetToolTip(ctl, message);
}
private void owner_Click(object sender, EventArgs e)
{
//UI code
SetToolTip(owner, "Follow at twitter @Job_Getabu ;)");
string fbPage = "https://twitter.com/job_getabu";
try
{
System.Diagnostics.ProcessStartInfo sInfo = new System.Diagnostics.ProcessStartInfo(fbPage);
System.Diagnostics.Process.Start(sInfo);
}
catch (Exception) { }
}
private void btnRefresh_Click(object sender, EventArgs e)
{
}
public void MonthlyUISet()
{
using (var context = new KimathiEntities())
{
var GMonth = DateTime.Now.Month;
var GYear = DateTime.Now.Year;
var firstDayOfMonth = new DateTime(GYear, GMonth, 1);
var lastDayOfMonth = firstDayOfMonth.AddMonths(1).AddDays(-1);
#region var init
var incomeListAsync =
context.Works.ToList();
//Days for income
incDay0 = incomeListAsync.Where(x => x.TimeIn == firstDayOfMonth | x.TimeIn.Value.Day == 1)
.Select(
item =>
{
var hrs = item.TimeOut.Value - item.TimeIn.Value;
return hrs.TotalHours * int.Parse(PayrollUI.Instance.tbRate.Text);
}
).FirstOrDefault();
incDay5 = incomeListAsync.Where(x => x.TimeIn.Value.Day > 1 & x.TimeIn.Value.Day < 6)
.Select(
item =>
{
var hrs = item.TimeOut.Value - item.TimeIn.Value;
return hrs.TotalHours * int.Parse(PayrollUI.Instance.tbRate.Text);
}
).FirstOrDefault();
incDay10 = incomeListAsync.Where(x => x.TimeIn.Value.Day > 5 & x.TimeIn.Value.Day < 11)
.Select(
item =>
{
var hrs = item.TimeOut.Value - item.TimeIn.Value;
return hrs.TotalHours * int.Parse(PayrollUI.Instance.tbRate.Text);
}
).FirstOrDefault();
incDay15 = incomeListAsync.Where(x => x.TimeIn.Value.Day > 10 & x.TimeIn.Value.Day < 16)
.Select(
item =>
{
var hrs = item.TimeOut.Value - item.TimeIn.Value;
return hrs.TotalHours * int.Parse(PayrollUI.Instance.tbRate.Text);
}
).FirstOrDefault();
incDay20 = incomeListAsync.Where(x => x.TimeIn.Value.Day > 15 & x.TimeIn.Value.Day < 26)
.Select(
item =>
{
var hrs = item.TimeOut.Value - item.TimeIn.Value;
return hrs.TotalHours * int.Parse(PayrollUI.Instance.tbRate.Text);
}
).FirstOrDefault();
incDay25 = incomeListAsync.Where(x => x.TimeIn.Value.Day > 25 & x.TimeIn.Value.Day < 31)
.Select(
item =>
{
var hrs = item.TimeOut.Value - item.TimeIn.Value;
return hrs.TotalHours * int.Parse(PayrollUI.Instance.tbRate.Text);
}
).FirstOrDefault();
incDayLast = incomeListAsync.Where(x => x.TimeIn.Value.Day == lastDayOfMonth.Day)
.Select(
item =>
{
var hrs = item.TimeOut.Value - item.TimeIn.Value;
return hrs.TotalHours * int.Parse(PayrollUI.Instance.tbRate.Text);
}
).FirstOrDefault();
#endregion
cIncome = new ChartValues<double> { incDay0, incDay5, incDay10, incDay15, incDay20, incDay25, incDayLast };
cartesianChart1.Series = new SeriesCollection
{
new LineSeries
{
Title = "Payment",
Values = cIncome
},
};
cartesianChart1.AxisX.Add(new Axis
{
Title = "Days",
Labels = new[] { "0", "5", "10", "15", "20", "25", "30" }
});
cartesianChart1.AxisY.Add(new Axis
{
Title = "Amount",
LabelFormatter = value => $"KES {String.Format("{0:0,0}", value)}"
//value.ToString("C3", CultureInfo.CreateSpecificCulture("sw-KE"))
});
cartesianChart1.LegendLocation = LegendLocation.Right;
}
}
private class hrs
{
}
}
}