private void InsertData(int index) { DataConnectSQL.Connect(); string user = "******"; int numGuest = 12; string numRoom = danhsachphongtrong.Rows[index].Cells[5].Value.ToString(); int num; int.TryParse(numRoom, out num); DateTime dateIn = DateTime.Now; DateTime dateOut = dateIn.AddDays(3); int result; string sql = "sp_booking"; //+ user +","+ numGuest + "," + numRoom + "," + checkIn + "," + checkOut + "," + result result = DataConnectSQL.ExcuteProcedure(sql, user, numGuest, num, dateIn, dateOut); if (result == 0) { MessageBox.Show("We're sorry about this !! \n This room is booked. Please try book the another!", "Error"); danhsachphongtrong.CancelEdit(); } else { MessageBox.Show("Successfull !!"); DataConnectSQL.Connect(); } }
private void LoadData() { DataConnectSQL.Connect(); string sql = "SELECT ks.maKS as STT,ks.tenKS as 'Tên khách sạn',ks.thanhPho as 'Thành phố',ks.soSao as 'Số sao',ks.giaTB as 'Giá cả',tt.maPhong as 'Số phòng',tt.tinhTrang as 'Tình trạng' FROM ((KhachSan ks JOIN LoaiPhong lp ON ks.maKS=lp.maKS) JOIN Phong p ON lp.maLoaiPhong=p.LoaiPhong) JOIN TrangThaiPhong tt ON p.maPhong=tt.maPhong"; DataTable dsKS = new DataTable(); dsKS = DataConnectSQL.LoadData(string.Format(sql)); //danhsachphongtrong.DataSource = dsKS; //this.tenKS.DataGridView.Rows.Add(dsKS.Rows[1][1]); //this.tenKS.DataGridView.Rows.Add(dsKS.Rows[2][1]); //this.STT.DataGridView.Columns.Add(dsKS.Columns[0]); for (int i = 0; i < dsKS.Rows.Count; i++) { danhsachphongtrong.Rows.Add(dsKS.Rows[i][0], dsKS.Rows[i][1], dsKS.Rows[i][2], dsKS.Rows[i][3], dsKS.Rows[i][4], dsKS.Rows[i][5], dsKS.Rows[i][6]); } }