-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGuestForm.cs
177 lines (158 loc) · 6.57 KB
/
GuestForm.cs
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Hotel_Management_System
{
public partial class GuestForm : Form
{
GuestClass guest = new GuestClass();
public GuestForm()
{
InitializeComponent();
}
private void button_clean_Click(object sender, EventArgs e)
{
textBox_id.Clear();
textBox_fName.Clear();
textBox_lName.Clear();
textBox_phone.Clear();
textBox_city.Clear();
}
private void button_save_Click(object sender, EventArgs e)
{
if (textBox_id.Text == "" || textBox_fName.Text == "" || textBox_phone.Text == "")
{
MessageBox.Show("Required Field - Id no, first name and phone no:", "Required Field", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
try
{
string id = textBox_id.Text;
string fname = textBox_fName.Text;
string lname = textBox_lName.Text;
string phone = textBox_phone.Text;
string city = textBox_city.Text;
Boolean insertGuest = guest.insertGuest(id, fname, lname, phone, city);
if (insertGuest)
{
MessageBox.Show("New guest save successfuly", "Guest Saved", MessageBoxButtons.OK, MessageBoxIcon.Information);
getTable();
// you can clear all text after the save action
button_clean.PerformClick();
}
else
{
MessageBox.Show("ERROR - guest not inserted", "Error Save", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
private void button_delete_Click(object sender, EventArgs e)
{
if (textBox_id.Text == "")
{
MessageBox.Show("Required Field - Id no", "Required Field", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
try
{
string id = textBox_id.Text;
Boolean deleteGuest = guest.removeGuest(id);
if (deleteGuest)
{
MessageBox.Show("guest data remove successfuly", "Guest Removed", MessageBoxButtons.OK, MessageBoxIcon.Information);
getTable();
// you can clear all text after the delete action
button_clean.PerformClick();
}
else
{
MessageBox.Show("ERROR - guest not Remove", "Error delete", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
private void GuestForm_Load(object sender, EventArgs e)
{
dataGridView_guest.DefaultCellStyle.ForeColor = Color.Black;
getTable();
}
private void getTable()
{
dataGridView_guest.DataSource = guest.getGuest(); [UNTUK KONEKSI DARI FORM KE DATABASE]NAMPILIN DATA YANG DI DATABASE BUAT MEMUNCULKAN DATA DI UI. OTOMATIS BUAT ATRIBUT BARU DI DATABASE NYAMBUNGNYA DI BOOLEAN INSERTGUEST.
}
private void button_update_Click(object sender, EventArgs e)
{
if (textBox_id.Text == "" || textBox_fName.Text == "" || textBox_phone.Text == "")
{
MessageBox.Show("Required Field - Id no, first name and phone no:", "Required Field", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
try
{
string id = textBox_id.Text;
string fname = textBox_fName.Text;
string lname = textBox_lName.Text;
string phone = textBox_phone.Text;
string city = textBox_city.Text;
Boolean editGuest = guest.editGuest(id, fname, lname, phone, city);
if (editGuest)
{
MessageBox.Show("Guest data Update successfuly", "Update Successfuly", MessageBoxButtons.OK, MessageBoxIcon.Information);
getTable();
button_clean.PerformClick();
}
else
{
MessageBox.Show("ERROR - guest data not update", "Error Update", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
//Display the selectet cell data from datagridview to textboxes;
private void dataGridView_guest_CellClick(object sender, DataGridViewCellEventArgs e)
{
textBox_id.Text = dataGridView_guest.CurrentRow.Cells[0].Value.ToString();
textBox_fName.Text = dataGridView_guest.CurrentRow.Cells[1].Value.ToString();
textBox_lName.Text = dataGridView_guest.CurrentRow.Cells[2].Value.ToString();
textBox_phone.Text = dataGridView_guest.CurrentRow.Cells[3].Value.ToString();
textBox_city.Text = dataGridView_guest.CurrentRow.Cells[4].Value.ToString();
}
private void label_exit_MouseEnter(object sender, EventArgs e)
{
label_exit.ForeColor = Color.Red;
}
private void label_exit_MouseLeave(object sender, EventArgs e)
{
label_exit.ForeColor = Color.White;
}
private void label_exit_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void dataGridView_guest_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
}
}