-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServiceIntegration.cs
More file actions
333 lines (288 loc) · 13.6 KB
/
Copy pathServiceIntegration.cs
File metadata and controls
333 lines (288 loc) · 13.6 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
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace DB_Project
{
public partial class ServiceIntegrationForm : Form
{
// Connection string for SQL Server database
private string connectionString = @"Data Source=ABDULSABOOR190\SQLEXPRESS;Initial Catalog=sabbbb;Integrated Security=True;Encrypt=False";
public ServiceIntegrationForm()
{
InitializeComponent();
SetupForm();
}
private void SetupForm()
{
// Initialize the combo box with default selection
if (cmbType.Items.Count > 0)
cmbType.SelectedIndex = 0;
}
// Helper method to highlight the active sidebar button
private void HighlightActiveButton(Button activeButton)
{
// Reset all buttons
foreach (Control c in panelSidebar.Controls)
{
if (c is Button btn)
{
btn.BackColor = Color.FromArgb(45, 62, 80);
btn.ForeColor = Color.White;
}
}
// Highlight active button
activeButton.BackColor = Color.FromArgb(41, 128, 185);
activeButton.ForeColor = Color.White;
}
// Event handler for combo box selection change
private void cmbType_SelectedIndexChanged(object sender, EventArgs e)
{
// Show hotel-specific fields only when "Hotel" is selected
if (cmbType.SelectedItem != null && cmbType.SelectedItem.ToString() == "Hotel")
{
groupBox3.Visible = true;
}
else
{
groupBox3.Visible = false;
}
}
// Method to validate user inputs
private bool ValidateInputs()
{
if (string.IsNullOrWhiteSpace(txtProviderName.Text))
{
MessageBox.Show("Please enter a provider name.", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return false;
}
if (cmbType.SelectedItem == null)
{
MessageBox.Show("Please select a provider type.", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return false;
}
if (string.IsNullOrWhiteSpace(txtLocation.Text))
{
MessageBox.Show("Please enter a location.", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return false;
}
if (string.IsNullOrWhiteSpace(txtServiceName.Text))
{
MessageBox.Show("Please enter a service name.", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return false;
}
if (numPricePerUnit.Value <= 0)
{
MessageBox.Show("Price per unit must be greater than zero.", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return false;
}
if (numTotalUnits.Value <= 0)
{
MessageBox.Show("Total units must be greater than zero.", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return false;
}
// Hotel-specific validation
if (cmbType.SelectedItem.ToString() == "Hotel" && string.IsNullOrWhiteSpace(txtAddress.Text))
{
MessageBox.Show("Please enter a hotel address.", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return false;
}
return true;
}
// Method to insert a new service provider
private int InsertServiceProvider()
{
int providerId = -1;
string type = cmbType.SelectedItem.ToString().ToLower();
try
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
// First, create a new user entry
string insertUserQuery = @"
INSERT INTO AppUser (email, password_hash, registration_status, role, is_active)
VALUES (@Email, 'dummyHash', 'approved', 'service_provider', 1);
SELECT SCOPE_IDENTITY();";
SqlCommand cmdUser = new SqlCommand(insertUserQuery, connection);
cmdUser.Parameters.AddWithValue("@Email", $"{txtProviderName.Text.Replace(" ", "")}@travelexplorer.com");
// Get the new user ID
int userId = Convert.ToInt32(cmdUser.ExecuteScalar());
// Now insert into ServiceProviderProfile
string insertProviderQuery = @"
INSERT INTO ServiceProviderProfile (user_id, provider_name, type, location, contact_info, is_verified)
VALUES (@UserId, @ProviderName, @Type, @Location, 'contact', 1);";
SqlCommand cmdProvider = new SqlCommand(insertProviderQuery, connection);
cmdProvider.Parameters.AddWithValue("@UserId", userId);
cmdProvider.Parameters.AddWithValue("@ProviderName", txtProviderName.Text);
cmdProvider.Parameters.AddWithValue("@Type", type);
cmdProvider.Parameters.AddWithValue("@Location", txtLocation.Text);
cmdProvider.ExecuteNonQuery();
// If it's a hotel, add hotel details
if (type == "hotel")
{
// Build amenities string
List<string> amenities = new List<string>();
if (chkPool.Checked) amenities.Add("Pool");
if (chkWifi.Checked) amenities.Add("WiFi");
if (chkBreakfast.Checked) amenities.Add("Breakfast");
if (chkParking.Checked) amenities.Add("Parking");
string amenitiesStr = string.Join(", ", amenities);
string insertHotelQuery = @"
INSERT INTO Hotel (provider_id, name, address, star_rating, amenities, total_rooms, description)
VALUES (@ProviderId, @Name, @Address, 3, @Amenities, 10, 'Standard hotel description');";
SqlCommand cmdHotel = new SqlCommand(insertHotelQuery, connection);
cmdHotel.Parameters.AddWithValue("@ProviderId", userId);
cmdHotel.Parameters.AddWithValue("@Name", txtProviderName.Text);
cmdHotel.Parameters.AddWithValue("@Address", txtAddress.Text);
cmdHotel.Parameters.AddWithValue("@Amenities", amenitiesStr);
cmdHotel.ExecuteNonQuery();
}
providerId = userId;
}
}
catch (Exception ex)
{
MessageBox.Show($"Database error: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
return providerId;
}
// Method to insert a new service
private void InsertService(int providerId)
{
try
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
string insertServiceQuery = @"
INSERT INTO Service (provider_id, name, type, price_per_unit, total_units, location, description, status)
VALUES (@ProviderId, @Name, @Type, @PricePerUnit, @TotalUnits, @Location, 'Service description', 'available');";
SqlCommand cmd = new SqlCommand(insertServiceQuery, connection);
cmd.Parameters.AddWithValue("@ProviderId", providerId);
cmd.Parameters.AddWithValue("@Name", txtServiceName.Text);
cmd.Parameters.AddWithValue("@Type", cmbType.SelectedItem.ToString().ToLower());
cmd.Parameters.AddWithValue("@PricePerUnit", numPricePerUnit.Value);
cmd.Parameters.AddWithValue("@TotalUnits", numTotalUnits.Value);
cmd.Parameters.AddWithValue("@Location", txtLocation.Text);
cmd.ExecuteNonQuery();
}
}
catch (Exception ex)
{
MessageBox.Show($"Database error: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
// Event handler for the Save button
private void btnSave_Click(object sender, EventArgs e)
{
if (!ValidateInputs())
return;
try
{
// Begin transaction by inserting provider first
int providerId = InsertServiceProvider();
if (providerId > 0)
{
// Then insert the service
InsertService(providerId);
MessageBox.Show("Service information saved successfully!", "Success",
MessageBoxButtons.OK, MessageBoxIcon.Information);
// Clear form fields after successful save
ClearFields();
}
else
{
MessageBox.Show("Failed to create service provider.", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
catch (Exception ex)
{
MessageBox.Show($"An error occurred: {ex.Message}", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
// Clear all form fields
private void ClearFields()
{
txtProviderName.Clear();
txtLocation.Clear();
txtServiceName.Clear();
numPricePerUnit.Value = 0;
numTotalUnits.Value = 0;
txtAddress.Clear();
chkPool.Checked = false;
chkWifi.Checked = false;
chkBreakfast.Checked = false;
chkParking.Checked = false;
if (cmbType.Items.Count > 0)
cmbType.SelectedIndex = 0;
}
// Event handler for the Cancel button
private void btnCancel_Click(object sender, EventArgs e)
{
// Close the form
this.Close();
}
// Navigation button handlers
private void btnRegistration_Click_1(object sender, EventArgs e)
{
ServiceIntegrationForm abc = new ServiceIntegrationForm();
abc.Show();
}
private void button1_Click(object sender, EventArgs e)
{
ServiceListingForm abc = new ServiceListingForm();
abc.Show();
}
private void button2_Click(object sender, EventArgs e)
{
BookingManagementForm abc = new BookingManagementForm();
abc.Show();
}
private void button3_Click(object sender, EventArgs e)
{
PerformanceReportForm abc = new PerformanceReportForm();
abc.Show();
}
#region Event handlers for UI elements - empty implementations
private void panelTopBar_Paint(object sender, PaintEventArgs e) { }
private void lblTravelExplorer_Click(object sender, EventArgs e) { }
private void panelSidebar_Paint(object sender, PaintEventArgs e) { }
private void groupBox1_Enter(object sender, EventArgs e) { }
private void txtLocation_TextChanged(object sender, EventArgs e) { }
private void txtProviderName_TextChanged(object sender, EventArgs e) { }
private void label4_Click(object sender, EventArgs e) { }
private void label3_Click(object sender, EventArgs e) { }
private void label2_Click(object sender, EventArgs e) { }
private void groupBox2_Enter(object sender, EventArgs e) { }
private void numTotalUnits_ValueChanged(object sender, EventArgs e) { }
private void numPricePerUnit_ValueChanged(object sender, EventArgs e) { }
private void txtServiceName_TextChanged(object sender, EventArgs e) { }
private void label7_Click(object sender, EventArgs e) { }
private void label6_Click(object sender, EventArgs e) { }
private void label5_Click(object sender, EventArgs e) { }
private void groupBox3_Enter(object sender, EventArgs e) { }
private void chkParking_CheckedChanged(object sender, EventArgs e) { }
private void chkBreakfast_CheckedChanged(object sender, EventArgs e) { }
private void chkWifi_CheckedChanged(object sender, EventArgs e) { }
private void chkPool_CheckedChanged(object sender, EventArgs e) { }
private void txtAddress_TextChanged(object sender, EventArgs e) { }
private void label8_Click(object sender, EventArgs e) { }
private void btnRegistration_Click(object sender, EventArgs e) { }
private void btnSearchBooking_Click(object sender, EventArgs e) { }
private void btnDashboard_Click(object sender, EventArgs e) { }
private void btnDigitalTravelPass_Click(object sender, EventArgs e) { }
private void btnReview_Click(object sender, EventArgs e) { }
private void btnProfile_Click(object sender, EventArgs e) { }
private void btnServiceIntegration_Click(object sender, EventArgs e) { }
#endregion
}
}