-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddAppointment.xaml.cs
More file actions
154 lines (116 loc) · 5.02 KB
/
Copy pathAddAppointment.xaml.cs
File metadata and controls
154 lines (116 loc) · 5.02 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
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
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Globalization;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace BOP3_Task_1_C_Sharp_Application_Development
{
/// <summary>
/// Interaction logic for AddAppointment.xaml
/// </summary>
public partial class AddAppointment : Window
{
public AddAppointment()
{
InitializeComponent();
}
private void StartTimeCalendar_SelectedDatesChanged(object sender, SelectionChangedEventArgs e) {
startTimeTextBox.Text = startTimePick.SelectedDate.ToString();
endTimeTextBox.Text = startTimePick.SelectedDate.ToString();
}
private void EndTimeCalendar_SelectedDatesChanged(object sender, SelectionChangedEventArgs e)
{
endTimeTextBox.Text = endTimePick.SelectedDate.ToString();
}
private void MonthlyCalendar_DisplayDateChanged(object sender, CalendarDateChangedEventArgs e) { }
private void MonthlyCalendar_DisplayModeChanged(object sender, CalendarModeChangedEventArgs e) { }
public Dashboard dashboardObject;
private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
{
}
public static bool appIsOutsideBusinessHours(DateTime startTime, DateTime endTime)
{
startTime = startTime.ToLocalTime();
endTime = endTime.ToLocalTime();
DateTime businessStart = DateTime.Today.AddHours(8); // 8am
DateTime businessEnd = DateTime.Today.AddHours(17); // 5pm
if (startTime.TimeOfDay > businessStart.TimeOfDay && startTime.TimeOfDay < businessEnd.TimeOfDay &&
endTime.TimeOfDay > businessStart.TimeOfDay && endTime.TimeOfDay < businessEnd.TimeOfDay)
return false;
return true;
}
private void addButton_Click(object sender, EventArgs e)
{
if (String.IsNullOrWhiteSpace(customerIdTextBox.Text) ||
String.IsNullOrWhiteSpace(typeTextBox.Text) ||
String.IsNullOrWhiteSpace(startTimeTextBox.Text) ||
String.IsNullOrWhiteSpace(endTimeTextBox.Text))
{
MessageBox.Show("Ensure all field are valid.");
}
DateTime timestamp = DateTime.Now;
int userId = SharedDataHelp.getCurrentUserId();
string username = SharedDataHelp.getCurrentUserName();
DateTime startTime = DateTime.Parse(startTimeTextBox.Text).ToUniversalTime();
DateTime endTime = DateTime.Parse(endTimeTextBox.Text).ToUniversalTime();
Record record = new Record();
record.customerId = customerIdTextBox.Text;
record.end = endTime;
record.start = startTime;
record.table = "appointment";
record.timestamp = timestamp;
record.userName = username;
record.type = typeTextBox.Text;
record.userId = userId;
try
{
if (SharedDataHelp.AppointmentConflictCheck(DateTime.Parse(SharedDataHelp.convertToTimezone(startTime.ToString())), DateTime.Parse(SharedDataHelp.convertToTimezone(endTime.ToString()))))
MessageBox.Show("Exception occured, appointment time conflics with another appointment");
else
{
try
{
if (SharedDataHelp.AppointmentBusinessHoursCheck(DateTime.Parse(SharedDataHelp.convertToTimezone(startTime.ToString())), DateTime.Parse(SharedDataHelp.convertToTimezone(endTime.ToString()))))
MessageBox.Show("Exception occured, appointments need to be within normal business hours");
else
{
SharedDataHelp.createRecord(record);
dashboardObject.updateCalendar();
Close();
}
}
catch (Exception ex) {
MessageBox.Show(ex.Message);
}
}
}
catch (Exception ex) {
MessageBox.Show(ex.Message);
}
}
private void cancelButton_Click(object sender, EventArgs e)
{
Close();
}
private void AddAppointment_Load(object sender, EventArgs e)
{
}
public void businessHours()
{
MessageBox.Show("Exception occured, appointments need to be within normal business hours");
}
public void appOverlap()
{
MessageBox.Show("Exception occured, your appointment time is conflicting with an already present appointment");
}
}
}