-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReception.cs
More file actions
202 lines (165 loc) · 7.14 KB
/
Copy pathReception.cs
File metadata and controls
202 lines (165 loc) · 7.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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
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 Reception : UserControl
{
public Reception()
{
InitializeComponent();
}
SqlConnection cn = new SqlConnection(@"data source=.\SQLEXPRESS; initial catalog=Hotel; integrated security=true;");
DataSet ds = new DataSet();
DataTable dt = new DataTable();
decimal prix = 1;
private void label5_Click(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text == "" || textBox2.Text == "" || comboBox1.Text == "" || textBox3.Text=="" || comboBox2.Text=="")
{
MessageBox.Show("Veuillez Remplir tout les champs ", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else
{
double nbr_days=1;
double TotalPrix=0;
DateTime d1 = dateTimePicker1.Value;
DateTime d2 = dateTimePicker2.Value;
TimeSpan T = d2 - d1;
if (double.Parse(T.TotalDays.ToString()) <= 1)
{
prix = chercherprix(comboBox2.Text);
TotalPrix = double.Parse(prix.ToString());
}
else
{
nbr_days = Math.Round(double.Parse(T.TotalDays.ToString()),0, MidpointRounding.AwayFromZero);
prix= chercherprix(comboBox2.Text);
TotalPrix = double.Parse(prix.ToString()) * nbr_days;
}
//*******************************************************************//
string st = "insert into Customer (cin,nom,prenom,numtel,type_chambre,num_chambre,check_in,check_out,nbr_jour,prix) values ('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "'," + comboBox1.SelectedValue + "," + comboBox2.SelectedValue + ",'" + d1.ToString("dd/MM/yyyy") + "','" + d2.ToString("dd/MM/yyyy") + "','" + nbr_days + "','" + TotalPrix + "')";
if (cn.State == ConnectionState.Closed) { cn.Open(); }
SqlCommand cmd = new SqlCommand(st, cn);
cmd.ExecuteNonQuery();
cn.Close();
chargerDGV();
}
}
public void chargerDGV()
{
dt.Clear();
SqlCommand cmd = new SqlCommand("select * from Customer", cn);
if (cn.State == ConnectionState.Closed) { cn.Open(); }
SqlDataReader drv = cmd.ExecuteReader();
dt.Load(drv);
dataGridView1.DataSource = dt;
cn.Close();
}
public void chargerCb1()
{
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();
}
public void chargerCb2(string a)
{
DataTable dtc = new DataTable();
SqlCommand cmd = new SqlCommand("select r.Id_room, r.num_chambre from Room r, catégorie c where c.Id_cat = r.type_chambre and c.cat like '" + a + "'", cn);
if (cn.State == ConnectionState.Closed) { cn.Open(); }
SqlDataReader drv = cmd.ExecuteReader();
dtc.Load(drv);
comboBox2.DataSource = dtc;
comboBox2.DisplayMember = "num_chambre";
comboBox2.ValueMember = "Id_room";
comboBox2.SelectedIndex = -1;
cn.Close();
}
private void Reception_Load(object sender, EventArgs e)
{
chargerCb1();
chargerDGV();
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
chargerCb2(comboBox1.Text);
}
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
//MessageBox.Show(comboBox2.Text);
//chercherprix(comboBox2.SelectedValue.ToString());
}
decimal chercherprix(string pp)
{
decimal Tprix=-1;
string stprix = "select prix_chambre from Room where num_chambre like '" + pp +"'" ;
if(pp != "" )
{
if (cn.State == ConnectionState.Closed) { cn.Open(); }
SqlCommand cmdprix = new SqlCommand(stprix, cn);
Tprix=decimal.Parse( cmdprix.ExecuteScalar().ToString());
// Tprix = cmdprix.ExecuteNonQuery();
//prix = decimal.Parse();
cn.Close();
}
return Tprix;
}
private void dataGridView1_Click(object sender, EventArgs e)
{
textBox1.Text = dataGridView1.CurrentRow.Cells[1].Value.ToString();
textBox2.Text = dataGridView1.CurrentRow.Cells[2].Value.ToString();
textBox3.Text = dataGridView1.CurrentRow.Cells[3].Value.ToString();
textBox4.Text = dataGridView1.CurrentRow.Cells[4].Value.ToString();
comboBox1.Text = dataGridView1.CurrentRow.Cells[5].Value.ToString();
comboBox2.Text = dataGridView1.CurrentRow.Cells[6].Value.ToString();
dateTimePicker1.Value = DateTime.Parse( dataGridView1.CurrentRow.Cells[7].Value.ToString());
dateTimePicker2.Value = DateTime.Parse(dataGridView1.CurrentRow.Cells[8].Value.ToString());
}
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 Customer where cin = '"+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();
textBox3.Clear();
textBox4.Clear();
comboBox1.ResetText();
comboBox2.ResetText();
dateTimePicker1.Value = DateTime.Now;
dateTimePicker2.Value = DateTime.Now;
}
private void button2_Click(object sender, EventArgs e)
{
}
}
}