-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRoom.cs
More file actions
188 lines (157 loc) · 6.14 KB
/
Copy pathRoom.cs
File metadata and controls
188 lines (157 loc) · 6.14 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
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;
using System.Data.SqlClient;
namespace HotelManagementSystem
{
public partial class Room : UserControl
{
public Room()
{
InitializeComponent();
}
SqlConnection cn = new SqlConnection(@"data source=.\SQLEXPRESS; initial catalog=Hotel; integrated security=true;");
DataSet ds = new DataSet();
DataTable dt = new DataTable();
bool s;
public void chargerDGV()
{
dt.Clear();
SqlCommand cmd = new SqlCommand("select r.num_chambre,c.cat,r.prix_chambre,r.Disponibilite from Room r, catégorie c where r.type_chambre = c.Id_cat", cn);
if (cn.State == ConnectionState.Closed) { cn.Open(); }
SqlDataReader drv = cmd.ExecuteReader();
dt.Load(drv);
dataGridView1.DataSource = dt;
cn.Close();
}
public void chargerCb()
{
DataTable dtco = new DataTable();
SqlCommand cmd = new SqlCommand("select * from catégorie",cn);
cn.Open();
SqlDataReader drv = cmd.ExecuteReader();
dtco.Load(drv);
comboBox1.DataSource = dtco;
comboBox1.DisplayMember = "cat";
comboBox1.ValueMember = "Id_cat";
comboBox1.SelectedIndex = -1;
cn.Close();
}
int methodeRechercher()
{
int y = -1;
for (int i = 0; i < dt.Rows.Count; i++)
{
if (dt.Rows[i][1].ToString()== textBox1.Text)
{
y = i;
}
}
return y;
}
private void label3_Click(object sender, EventArgs e)
{
}
private void Room_Load_1(object sender, EventArgs e)
{
chargerDGV();
chargerCb();
}
private void button1_Click(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
if (radioButton1.Checked == true) { s = true; }
else { s = false; }
if( textBox1.Text=="" || textBox2.Text == "" || comboBox1.Text=="")
{
MessageBox.Show("Veuillez Remplir tout les champs ", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else
{
string st = "update Room set prix_chambre= "+decimal.Parse(textBox2.Text)+" , Disponibilite= '"+s+"' where num_chambre = "+textBox1.Text;
if (cn.State == ConnectionState.Closed) { cn.Open(); }
SqlCommand cmd = new SqlCommand(st, cn);
cmd.ExecuteNonQuery();
chargerDGV();
}
}
private void button1_Click_1(object sender, EventArgs e)
{
if (radioButton1.Checked == true) { s = true; }
else { s = false; }
if (textBox1.Text == "" || textBox2.Text == "" || comboBox1.Text == "")
{
MessageBox.Show("Veuillez Remplir tout les champs ", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else
{
int y = methodeRechercher();
if (y == -1)
{
string st = "insert into Room (num_chambre,type_chambre,prix_chambre,Disponibilite) values (" + textBox1.Text + "," + comboBox1.SelectedValue + ",'" + textBox2.Text + "','" + s + "')";
if (cn.State == ConnectionState.Closed) { cn.Open(); }
SqlCommand cmd = new SqlCommand(st, cn);
cmd.ExecuteNonQuery();
cn.Close();
chargerDGV();
}
else
{
MessageBox.Show("Numéro de Chambre déjà existant ", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
}
private void button3_Click(object sender, EventArgs e)
{
if (textBox1.Text == "" )
{
MessageBox.Show("Veuillez Remplir le champ demandé ", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else
{ string st = "delete Room where num_chambre=" + textBox1.Text;
if (cn.State == ConnectionState.Closed) { cn.Open(); }
SqlCommand cmd = new SqlCommand(st, cn);
cmd.ExecuteNonQuery();
chargerDGV();
}
}
private void button4_Click(object sender, EventArgs e)
{
textBox1.Clear();
textBox2.Clear();
comboBox1.Text = "";
}
private void button5_Click(object sender, EventArgs e)
{
string st = "select * from Room where num_chambre=" + textBox1.Text;
if(cn.State == ConnectionState.Closed) { cn.Open(); }
SqlCommand cmd = new SqlCommand(st, cn);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
comboBox1.Text = dr[2].ToString();
textBox2.Text = dr[3].ToString();
if (dr[4].ToString() == "True") { radioButton1.Checked = true; }
else { radioButton2.Checked = true; }
}
cn.Close();
chargerDGV();
}
private void dataGridView1_Click(object sender, EventArgs e)
{
textBox1.Text = dataGridView1.CurrentRow.Cells[0].Value.ToString();
comboBox1.Text = dataGridView1.CurrentRow.Cells[1].Value.ToString();
textBox2.Text= dataGridView1.CurrentRow.Cells[2].Value.ToString();
if(dataGridView1.CurrentRow.Cells[3].Value.ToString() == "True") { radioButton1.Checked = true; }
if (dataGridView1.CurrentRow.Cells[3].Value.ToString() == "False") { radioButton2.Checked = true; }
}
}
}