-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddEntryForm.cs
More file actions
107 lines (89 loc) · 4.09 KB
/
Copy pathAddEntryForm.cs
File metadata and controls
107 lines (89 loc) · 4.09 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
96
97
98
99
100
101
102
103
104
105
106
107
using System;
using Eto.Drawing;
using Eto.Forms;
namespace devtime
{
public class AddEntryForm : Dialog<bool>
{
public DateTime Date { get; private set; }
public long LoggedTime { get; private set; }
private readonly string _context;
private readonly DateTimePicker _datePicker;
private readonly NumericStepper _hoursStepper;
private readonly NumericStepper _minutesStepper;
private readonly NumericStepper _secondsStepper;
private readonly NumericStepper _msStepper;
public AddEntryForm(string context)
{
Title = "Add entry";
Icon = IconLoader.LoadIcon("add.png");
Resizable = false;
_context = context;
_datePicker = new DateTimePicker { Mode = DateTimePickerMode.Date, Value = DateTime.Today, Width = 100 };
_hoursStepper = new NumericStepper { MinValue = 0, MaxValue = 24, Value = 0, DecimalPlaces = 0, Width = 80 };
_minutesStepper = new NumericStepper { MinValue = 0, MaxValue = 59, Value = 0, DecimalPlaces = 0, Width = 80 };
_secondsStepper = new NumericStepper { MinValue = 0, MaxValue = 59, Value = 0, DecimalPlaces = 0, Width = 80 };
_msStepper = new NumericStepper { MinValue = 0, MaxValue = 999, Value = 0, 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 = "Date:" }, _datePicker),
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;
}
if (_datePicker.Value == null)
{
MessageBox.Show(this, "Please select a date.", "devtime error", MessageBoxButtons.OK, MessageBoxType.Error);
return;
}
Date = _datePicker.Value.Value.Date;
string dateStr = Date.ToString("yyyy-MM-dd");
if (DB.DateExists(_context, dateStr))
{
MessageBox.Show(this, "An entry for this day already exists.", "devtime error", MessageBoxButtons.OK, MessageBoxType.Error);
return;
}
LoggedTime = ms + (s * 1000L) + (m * 60000L) + (h * 3600000L);
Close(true);
}
}
}