//=======================================================
 //Author: LinhTN
 //Function : Xoa Check Point
 //=======================================================
 private void btnDelete_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
 {
     CheckPointBO aCheckPointBO = new CheckPointBO();
     IDCheckPoint = int.Parse(gridView1.GetFocusedRowCellValue("ID").ToString());
     DialogResult result = MessageBox.Show("Bạn có muốn xóa check point " + IDCheckPoint.ToString() + " này không?", "Xóa check point", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
     if (result == DialogResult.Yes)
     {
         aCheckPointBO.Delete_ByID(IDCheckPoint);
         MessageBox.Show("Xóa thành công");
         ReloadData();
     }
 }
        //=======================================================
        //Author: LinhTN
        //Function : Load Check Point
        //=======================================================
        public void ReloadData()
        {
            CheckPointBO aCheckPointBO = new CheckPointBO();
            List<CheckPoints> aListTemp = aCheckPointBO.Select_All();
            List<CheckPointEN> aListCheckPoints = new List<CheckPointEN>();
            CheckPointEN aCheckPointEN;
            for (int i = 0; i < aListTemp.Count; i++)
            {
                aCheckPointEN = new CheckPointEN();
                aCheckPointEN.SetValue(aListTemp[i]);
                if (aCheckPointEN.Type == 1)
                {
                    aCheckPointEN.TypeDisplay = "Check In Sớm";
                }
                else
                {
                    aCheckPointEN.TypeDisplay = "Check Out Muộn";
                }
                aListCheckPoints.Add(aCheckPointEN);
            }

            dgvCheckPoint.DataSource = aListCheckPoints;
            dgvCheckPoint.RefreshDataSource();
        }
        public double CaculateBooking(int IDBookingRoom, DateTime StartTime, DateTime EndTime)
        {
            try
            {
                BookingRoomsBO aBookingRoomsBO = new BookingRoomsBO();
                BookingRooms aBookingRooms = aBookingRoomsBO.Select_ByID(IDBookingRoom);

                if (aBookingRooms != null)
                {
                    TimeSpan dis = EndTime.Subtract(StartTime);
                    double a = (dis.TotalHours) / 24;
                    double a1 = 0;
                    if (a < 1)
                    {
                        a1 = Math.Floor(a);
                    }
                    else
                    {
                        a1 = Math.Round(a);
                    }

                    double addtimeStart = 0;
                    double addtimeEnd = 0;
                    DateTime CheckIn = DateTime.Parse(StartTime.ToString("HH:mm"));
                    DateTime CheckOut = DateTime.Parse(EndTime.ToString("HH:mm"));

                    if (aBookingRooms.Type == 3)//Tính checkin sớm và Checkout muộn
                    {
                        CheckPointBO aCheckPointBO = new CheckPointBO();
                        List<CheckPoints> aListCheckPoint = aCheckPointBO.Select_All();
                        for (int i = 0; i < aListCheckPoint.Count; i++)
                        {
                            if (aListCheckPoint[i].Type == 1) // checkIn som
                            {
                                if (aListCheckPoint[i].From <= CheckIn.TimeOfDay && CheckIn.TimeOfDay <= aListCheckPoint[i].To)
                                {
                                    addtimeStart = aListCheckPoint[i].AddTime;
                                }
                            }

                            else if (aListCheckPoint[i].Type == 2) // CheckOut muon
                            {
                                if (aListCheckPoint[i].From <= CheckOut.TimeOfDay && CheckOut.TimeOfDay <= aListCheckPoint[i].To)
                                {
                                    addtimeEnd = aListCheckPoint[i].AddTime;
                                }
                            }

                        }

                        double result = a1 + addtimeEnd + addtimeStart;
                        if (result < 1)
                        {
                            return 1;
                        }
                        else
                        {
                            return result;
                        }
                    }
                    else if (aBookingRooms.Type == 0) //Không tính checkIn sớm và checkout muộn.
                    {
                        return a1;
                    }
                    else if (aBookingRooms.Type == 2) //Tính checkin sớm ,không tính checkout muộn.
                    {
                        CheckPointBO aCheckPointBO = new CheckPointBO();
                        List<CheckPoints> aListCheckPoint = aCheckPointBO.Select_All();
                        for (int i = 0; i < aListCheckPoint.Count; i++)
                        {
                            if (aListCheckPoint[i].Type == 1) // checkIn som
                            {
                                if (aListCheckPoint[i].From <= CheckIn.TimeOfDay && CheckIn.TimeOfDay <= aListCheckPoint[i].To)
                                {
                                    addtimeStart = aListCheckPoint[i].AddTime;
                                }
                            }
                        }

                        return a1 + addtimeStart;

                    }
                    else if (aBookingRooms.Type == 1) //Không tính checkin sớm ,tính checkout muộn
                    {
                        CheckPointBO aCheckPointBO = new CheckPointBO();
                        List<CheckPoints> aListCheckPoint = aCheckPointBO.Select_All();
                        for (int i = 0; i < aListCheckPoint.Count; i++)
                        {
                            if (aListCheckPoint[i].Type == 2) // CheckOut muon
                            {
                                if (aListCheckPoint[i].From <= CheckOut.TimeOfDay && CheckOut.TimeOfDay <= aListCheckPoint[i].To)
                                {
                                    addtimeEnd = aListCheckPoint[i].AddTime;
                                }
                            }

                        }

                        return a1 + addtimeEnd;
                    }

                }
                return 0;
            }
            catch (Exception ex)
            {
                throw new Exception("ReceptionTaskBO.CaculateBooking \n" + ex.ToString());
            }
        }
        public double GetAddTimeEnd(int Type, DateTime EndTime)
        {
            try
            {

                double addtimeEnd = 0;

                    DateTime CheckOut = DateTime.Parse(EndTime.ToString("HH:mm"));

                    if (Type == 3)//Tính checkin sớm và Checkout muộn
                    {
                        CheckPointBO aCheckPointBO = new CheckPointBO();
                        List<CheckPoints> aListCheckPoint = aCheckPointBO.Select_All();
                        for (int i = 0; i < aListCheckPoint.Count; i++)
                        {
                            if (aListCheckPoint[i].Type == 2) // CheckOut muon
                            {
                                if (aListCheckPoint[i].From <= CheckOut.TimeOfDay && CheckOut.TimeOfDay <= aListCheckPoint[i].To)
                                {
                                    addtimeEnd = aListCheckPoint[i].AddTime;
                                }
                            }

                        }

                        return addtimeEnd;

                    }
                    else if (Type == 0) //Không tính checkIn sớm và checkout muộn.
                    {
                        return addtimeEnd;
                    }
                    else if (Type == 1) //Không tính checkin sớm ,tính checkout muộn
                    {
                        CheckPointBO aCheckPointBO = new CheckPointBO();
                        List<CheckPoints> aListCheckPoint = aCheckPointBO.Select_All();
                        for (int i = 0; i < aListCheckPoint.Count; i++)
                        {
                            if (aListCheckPoint[i].Type == 2) // CheckOut muon
                            {
                                if (aListCheckPoint[i].From <= CheckOut.TimeOfDay && CheckOut.TimeOfDay <= aListCheckPoint[i].To)
                                {
                                    addtimeEnd = aListCheckPoint[i].AddTime;
                                }
                            }

                        }

                        return addtimeEnd;
                    }
                    else if (Type == 2) //Không tính checkIn sớm và checkout muộn.
                    {
                        return addtimeEnd;
                    }

                return addtimeEnd;
            }
            catch (Exception ex)
            {
                throw new Exception("ReceptionTaskBO.CaculateBooking \n" + ex.ToString());
            }
        }
        public double GetAddTimeStart(DateTime StartTime)
        {
            try
            {
                double addtimeStart = 0;

                DateTime CheckIn = DateTime.Parse(StartTime.ToString("HH:mm"));
                CheckPointBO aCheckPointBO = new CheckPointBO();
                List<CheckPoints> aListCheckPoint = aCheckPointBO.Select_All();
                for (int i = 0; i < aListCheckPoint.Count; i++)
                {
                    if (aListCheckPoint[i].Type == 1) // checkIn som
                    {
                        if (aListCheckPoint[i].From <= CheckIn.TimeOfDay && CheckIn.TimeOfDay <= aListCheckPoint[i].To)
                        {
                            addtimeStart = aListCheckPoint[i].AddTime;
                        }
                    }

                }
                return addtimeStart;
            }
            catch (Exception ex)
            {
                throw new Exception("ReceptionTaskBO.CaculateBooking \n" + ex.ToString());
            }
        }