}//end method SetOwner public void SubmitCheckIn() { try { // Update table Customers, if there are new customers, add to database. UpdateCustomers(); int groupID = -1; // Check if there is group if (Groups.Rows.Count == 1) { groupID = (int)Groups.Rows[0]["GroupID"]; } // Get rooms int numOfRooms = Rooms.Rows.Count; // Scan room list to register to PHIEU_THUE_PHONG for (int i = 0; i < numOfRooms; i++) { VO.PhieuThuePhongVO ticket = new VO.PhieuThuePhongVO(); BUS.PhieuThuePhongBUS bus = new QLKS.BUS.PhieuThuePhongBUS(); // Set customer id ticket.MA_KHACH_HANG = (int)Rooms.Rows[i]["OwnerID"]; // Set group id if (groupID != -1) { ticket.MA_DOAN_KHACH = groupID; } else { ticket.MA_DOAN_KHACH = groupID; } ticket.MA_PHONG = (int)Rooms.Rows[i]["RoomID"]; ticket.NGAY_NHAN_PHONG = CheckInDay; // Insert and get the new id int ticketID = bus.InsertAndGetID(ticket); // Update room ticker id Rooms.Rows[i]["TicketID"] = ticketID; // Set room state to busy BUS.PhongBUS roomBus = new QLKS.BUS.PhongBUS(); roomBus.SetRoomState(ticket.MA_PHONG, TableRooms.RoomState.Busy); }//end for : scan all rooms // Scan all customer to register to table KHACH_TRO int numOfCustomers = Customers.Rows.Count; for (int j = 0; j < numOfCustomers; j++) { int roomNumber = (int)Customers.Rows[j]["RoomNumber"]; string filter = "RoomID = " + roomNumber.ToString(); DataRow matchedRoom = Rooms.Select(filter)[0]; VO.KhachTroVO ktRow = new QLKS.VO.KhachTroVO(); ktRow.MA_KHACH_HANG = (int)Customers.Rows[j]["CustomerID"]; ktRow.MA_PHIEU = (int)matchedRoom["TicketID"]; BUS.KhachTroBUS ktBus = new QLKS.BUS.KhachTroBUS(); int result = ktBus.Insert(ktRow); if (result <= 0) { throw new Exception("Không thể thêm dữ liệu vào bảng Khách Trọ"); } } //end for : scan all customers } //end try catch { throw; } //end catch } //end method SubmitCheckIn
}//end method Submit private void SubmitCheckIn() { DataRegister.UpdateCustomers(); bool IsGroup = groupInfo.IsAGroup(); int groupID = -1; if (IsGroup == true) { groupID = groupInfo.GetGroupID(); } int numOfRooms = DataRegister.Rooms.Rows.Count; // Scan room list for (int i = 0; i < numOfRooms; i++) { string roomNumber = DataRegister.Rooms.Rows[i]["RoomID"].ToString(); int ticketID = -1; int numOfCustomers = DataRegister.Customers.Rows.Count; // Scan customer list for (int j = 0; j < numOfCustomers; j++) { string roomNumber2 = DataRegister.Customers.Rows[j]["RoomNumber"].ToString(); if (roomNumber2.Equals(roomNumber)) { if (ticketID == -1) { VO.PhieuThuePhongVO item = new VO.PhieuThuePhongVO(); if (groupID != -1) { item.MA_DOAN_KHACH = groupID; } item.MA_KHACH_HANG = Int32.Parse(DataRegister.Customers.Rows[j]["CustomerID"].ToString()); item.MA_PHONG = Int32.Parse(DataRegister.Customers.Rows[j]["RoomNumber"].ToString()); item.NGAY_NHAN_PHONG = DateTime.Parse(dateCheckIn.Text); item.NGAY_TRA_PHONG = DateTime.Parse(dateCheckOut.Text); BUS.PhieuThuePhongBUS bus = new BUS.PhieuThuePhongBUS(); try { int result = bus.Insert(item); if (result == 0) { //code here }//end if there're some errors ticketID = result; }//end try catch (Exception e) { MessageBox.Show(e.Message); } //end catch } //end if : set owner else { VO.KhachTroVO ktItem = new VO.KhachTroVO(); ktItem.MA_PHIEU = ticketID; ktItem.MA_KHACH_HANG = Int32.Parse(DataRegister.Customers.Rows[j]["CustomerID"].ToString()); BUS.KhachTroBUS ktBus = new BUS.KhachTroBUS(); try { int result2 = ktBus.Insert(ktItem); if (result2 != 0) { } //end if } //end try catch (Exception e) { MessageBox.Show(e.Message); } //end catch } //end else } //end if : room number matched } //end for : customers } //end for : rooms } //end method SubmitCheckIn