-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEditEntryForm.cs
More file actions
95 lines (78 loc) · 3.49 KB
/
Copy pathEditEntryForm.cs
File metadata and controls
95 lines (78 loc) · 3.49 KB
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
using System;
using Eto.Drawing;
using Eto.Forms;
namespace devtime
{
public class EditEntryForm : Dialog<bool>
{
public long LoggedTime { get; private set; }
private readonly NumericStepper _hoursStepper;
private readonly NumericStepper _minutesStepper;
private readonly NumericStepper _secondsStepper;
private readonly NumericStepper _msStepper;
public EditEntryForm(long currentLoggedTime)
{
Title = "Edit entry";
Icon = IconLoader.LoadIcon("edit-time.png");
Resizable = false;
long h = currentLoggedTime / 3600000;
currentLoggedTime %= 3600000;
long m = currentLoggedTime / 60000;
currentLoggedTime %= 60000;
long s = currentLoggedTime / 1000;
currentLoggedTime %= 1000;
long ms = currentLoggedTime;
_hoursStepper = new NumericStepper { MinValue = 0, MaxValue = 24, Value = h, DecimalPlaces = 0, Width = 80 };
_minutesStepper = new NumericStepper { MinValue = 0, MaxValue = 59, Value = m, DecimalPlaces = 0, Width = 80 };
_secondsStepper = new NumericStepper { MinValue = 0, MaxValue = 59, Value = s, DecimalPlaces = 0, Width = 80 };
_msStepper = new NumericStepper { MinValue = 0, MaxValue = 999, Value = ms, DecimalPlaces = 0, Width = 80 };
var okButton = new Button { Text = "OK", Width = 70, Height = 23 };
okButton.Click += (sender, e) => OkClick();
var cancelButton = new Button { Text = "Cancel", Width = 70, Height = 23 };
cancelButton.Click += (sender, e) => Close(false);
DefaultButton = okButton;
AbortButton = cancelButton;
var grid = new TableLayout
{
Spacing = new Size(5, 3),
Padding = new Padding(10, 5, 10, 3),
Rows =
{
new TableRow(new Label { Text = "Hours (0-24):" }, _hoursStepper),
new TableRow(new Label { Text = "Minutes (0-59):" }, _minutesStepper),
new TableRow(new Label { Text = "Seconds (0-59):" }, _secondsStepper),
new TableRow(new Label { Text = "Milliseconds:" }, _msStepper)
}
};
var buttonLayout = new StackLayout
{
Orientation = Orientation.Horizontal,
Spacing = 5,
Items = { okButton, cancelButton }
};
Content = new StackLayout
{
HorizontalContentAlignment = HorizontalAlignment.Stretch,
Items =
{
grid,
new StackLayout { Padding = new Padding(10, 0, 10, 5), HorizontalContentAlignment = HorizontalAlignment.Right, Items = { buttonLayout } }
}
};
}
private void OkClick()
{
int h = (int)_hoursStepper.Value;
int m = (int)_minutesStepper.Value;
int s = (int)_secondsStepper.Value;
int ms = (int)_msStepper.Value;
if (h == 24 && (m > 0 || s > 0 || ms > 0))
{
MessageBox.Show(this, "Logged time is invalid (24 hours are logged; all other inputs must be 0).", "devtime error", MessageBoxButtons.OK, MessageBoxType.Error);
return;
}
LoggedTime = ms + (s * 1000L) + (m * 60000L) + (h * 3600000L);
Close(true);
}
}
}