Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddEntryForm.cs
More file actions
Latest commit
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
usingSystem;
usingEto.Drawing;
usingEto.Forms;
namespacedevtime
{
publicclassAddEntryForm:Dialog<bool>
{
publicDateTimeDate{get;privateset;}
publiclongLoggedTime{get;privateset;}
privatereadonlystring_context;
privatereadonlyDateTimePicker_datePicker;
privatereadonlyNumericStepper_hoursStepper;
privatereadonlyNumericStepper_minutesStepper;
privatereadonlyNumericStepper_secondsStepper;
privatereadonlyNumericStepper_msStepper;
publicAddEntryForm(stringcontext)
{
Title="Add entry";
Icon=IconLoader.LoadIcon("add.png");
Resizable=false;
_context=context;
_datePicker=newDateTimePicker{Mode=DateTimePickerMode.Date,Value=DateTime.Today,Width=100};
_hoursStepper=newNumericStepper{MinValue=0,MaxValue=24,Value=0,DecimalPlaces=0,Width=80};
_minutesStepper=newNumericStepper{MinValue=0,MaxValue=59,Value=0,DecimalPlaces=0,Width=80};
_secondsStepper=newNumericStepper{MinValue=0,MaxValue=59,Value=0,DecimalPlaces=0,Width=80};
_msStepper=newNumericStepper{MinValue=0,MaxValue=999,Value=0,DecimalPlaces=0,Width=80};
varokButton=newButton{Text="OK",Width=70,Height=23};
okButton.Click+=(sender,e)=>OkClick();
varcancelButton=newButton{Text="Cancel",Width=70,Height=23};
cancelButton.Click+=(sender,e)=>Close(false);
DefaultButton=okButton;
AbortButton=cancelButton;
vargrid=newTableLayout
{
Spacing=newSize(5,3),
Padding=newPadding(10,5,10,3),
Rows=
{
newTableRow(newLabel{Text="Date:"},_datePicker),
newTableRow(newLabel{Text="Hours (0-24):"},_hoursStepper),
newTableRow(newLabel{Text="Minutes (0-59):"},_minutesStepper),
newTableRow(newLabel{Text="Seconds (0-59):"},_secondsStepper),
newTableRow(newLabel{Text="Milliseconds:"},_msStepper)
}
};
varbuttonLayout=newStackLayout
{
Orientation=Orientation.Horizontal,
Spacing=5,
Items={okButton,cancelButton}
};
Content=newStackLayout
{
HorizontalContentAlignment=HorizontalAlignment.Stretch,
Items=
{
grid,
newStackLayout{Padding=newPadding(10,0,10,5),HorizontalContentAlignment=HorizontalAlignment.Right,Items={buttonLayout}}
}
};
}
privatevoidOkClick()
{
inth=(int)_hoursStepper.Value;
intm=(int)_minutesStepper.Value;
ints=(int)_secondsStepper.Value;
intms=(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;
stringdateStr=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);
}
}
}