SqlConnection hmcon = new SqlConnection(ConfigurationManager.ConnectionStrings["HotelMgmtDB"].ConnectionString);
    int AID = 0;
    int lastID = 0;
    string SessionBooking_ID = "";
 protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            this.Page.Title = "Booking Master";
            if (Session["Booking_ID"] != null)
            {
                SessionBooking_ID = hfBooking_ID.Value = Session["Booking_ID"].ToString();
            }
Session.Remove("Booking_ID");
            // Session.Clear();
            GenerateBookingID();
            BindBookingMode();
            BindPayMode();
            BindBookingStatus();
            txtBookDate.Text = DateTime.Now.ToString("dd-MM-yyyy");
            txtBookFrom.Text = DateTime.Now.ToString("dd-MM-yyyy");
            DateTime dt11 = DateTime.Now;
            dt11 = dt11.AddDays(1);
            txtBookTill.Text = dt11.ToString("dd-MM-yyyy");
            txtDuration.Text = "1";
            txtNumPersons.Text = "1";
            txtAdults.Text = "1";
            BindRooms();
            GetRoomDetailsById();
            txtGuestName.Focus();
}
        }
    }
 public void GenerateBookingID()
    {
        try
        {
            string sql = "select ID  from Booking_Master";
            hmcon.Open();
            SqlCommand cmd = new SqlCommand(sql, hmcon);
            SqlDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                AID = Convert.ToInt32(dr["ID"]);
            }
            hmcon.Close();
            if (AID != 0)
            {
                String query11 = "SELECT MAX(ID) as 'LastID' FROM Booking_Master";
                hmcon.Open();
                SqlCommand cmdid = new SqlCommand(query11, hmcon);
                lastID = int.Parse(cmdid.ExecuteScalar().ToString()) + 1;
                txtBookingId.Text = lastID.ToString();
                hmcon.Close();
            }
            else
            {
                txtBookingId.Text = (lastID + 1).ToString();
            }
        }
        catch (Exception ex)
        {
            //lblPopMsg.ForeColor = System.Drawing.Color.Red;
            //lblPopMsg.Text = "Error Occured :";
            //mpeMessageAlert.Show();
        }
    }
    [System.Web.Script.Services.ScriptMethod()]
    [System.Web.Services.WebMethod]
    public static List<string> SearchGuest(string prefixText, int count)
    {
        using (SqlConnection hmcon = new SqlConnection())
        {
            hmcon.ConnectionString = ConfigurationManager.ConnectionStrings["HotelMgmtDB"].ConnectionString;
            using (SqlCommand cmd = new SqlCommand())
            {
                CultureInfo culterinfo = Thread.CurrentThread.CurrentCulture;
                TextInfo objtxtSerName = culterinfo.TextInfo;
                var SearchprefixText = objtxtSerName.ToUpper(prefixText);
                cmd.CommandText = "select ID,(Name+'  '+ LastName) as FullName from MstGuest where Name like '%" + SearchprefixText + "%' or LastName like '%" + SearchprefixText + "%' order by Name asc";
                cmd.Connection = hmcon;
                hmcon.Open();
                List<string> employees = new List<string>();
                using (SqlDataReader sdr = cmd.ExecuteReader())
                {
                    while (sdr.Read())
                    {
                        string item = AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(sdr["FullName"].ToString(), sdr["ID"].ToString());
                        employees.Add(item);
                    }
                }
                hmcon.Close();
                if (employees.Count == 0)
                {
                    employees.Add("No Match Found.");
                }
                return employees;
            }
        }
    }
    #region All Dropdown Bind Methods
    private void BindBookingMode()
    {
        SqlCommand cmd = new SqlCommand("Select * from MstBookMode", hmcon);
        SqlDataAdapter da = new SqlDataAdapter();
        da.SelectCommand = cmd;
        DataSet ds = new DataSet();
        da.Fill(ds);
        drpBookMode.DataSource = ds;
        drpBookMode.DataTextField = "Description";
        drpBookMode.DataValueField = "ID";
        drpBookMode.DataBind();
        //drpBookMode.Items.Insert(0, new ListItem("Please Select"));
    }
    private void BindRooms()
    {
        if (txtBookFrom.Text != "" && txtBookTill.Text != "")
        {
            //DateTime BookFrmDate = new DateTime();
            //BookFrmDate = DateTime.ParseExact(this.txtBookFrom.Text, "dd-MM-yyyy", null);
            //DateTime BookTillDate = new DateTime();
            //BookTillDate = DateTime.ParseExact(this.txtBookTill.Text, "dd-MM-yyyy", null);
            DateTime BookFrmDate1 = new DateTime();
            BookFrmDate1 = DateTime.ParseExact(this.txtBookFrom.Text, "dd-MM-yyyy", CultureInfo.InvariantCulture);
            DateTime BookTillDate = new DateTime();
            BookTillDate = DateTime.ParseExact(this.txtBookTill.Text, "dd-MM-yyyy", CultureInfo.InvariantCulture);
            SqlCommand cmd = new SqlCommand("Select * from MstRoom where ID not in(select Room_Id from Book_Details  where '" + BookFrmDate1 + "' <= CheckOUT_Date AND '" + BookTillDate + "' >=CheckIN_Date and Book_Status !=1 AND Book_Status!=4)", hmcon);
            SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = cmd;
            DataSet ds = new DataSet();
            da.Fill(ds);
            drpRoomNum.DataSource = ds;
            drpRoomNum.DataTextField = "Number";
            drpRoomNum.DataValueField = "ID";
            drpRoomNum.DataBind();
            //drpRoomNum.Items.Insert(0, new ListItem("Please Select"));
            //drpBookingStatus.Focus();
        }
    }
    private void BindPayMode()
    {
        SqlCommand cmd = new SqlCommand("Select * from MstPayMode", hmcon);
        SqlDataAdapter da = new SqlDataAdapter();
        da.SelectCommand = cmd;
        DataSet ds = new DataSet();
        da.Fill(ds);
        drpPayMode.DataSource = ds;
        drpPayMode.DataTextField = "Description";
        drpPayMode.DataValueField = "ID";
        drpPayMode.DataBind();
        //drpPayMode.Items.Insert(0, new ListItem("Please Select"));
    }
    private void BindBookingStatus()
    {
        SqlCommand cmd = new SqlCommand("Select * from MstBook_Status where ID !=1 and ID !=4 order by ID desc", hmcon);
        SqlDataAdapter da = new SqlDataAdapter();
        da.SelectCommand = cmd;
        DataSet ds = new DataSet();
        da.Fill(ds);
        drpBookingStatus.DataSource = ds;
        drpBookingStatus.DataTextField = "Description";
        drpBookingStatus.DataValueField = "ID";
        drpBookingStatus.DataBind();
        //drpBookingStatus.Items.Insert(0, new ListItem("Please Select"));
    }
    #endregion
  protected void SaveBooking()
    {
        try
        {
            if (hfGuestID.Value != "" && grdRoomDetails.Rows.Count > 0 && txtRegNumber.Text != "")
            {
                #region Save Record in Booking_Master Table
                DateTime dt = new DateTime();
                //dt = DateTime.ParseExact(this.txtBookDate.Text, "dd-MM-yyyy", null);
                dt = DateTime.ParseExact(this.txtBookDate.Text, "dd-MM-yyyy", null);//01-09-2017
                string BookinDate = dt.ToString();//9/1/2017 12:00:00 AM
                var No_OfRooms = grdRoomDetails.Rows.Count;
                string QueryBook_Master = "Insert into Booking_Master (Book_Date,No_Persons,No_Rooms,Guest_ID,Book_Mode,ArrivedFrom,VisitPurpose,RegNo,VehicalNum,TotalFare,GSTAmount,AmountPaid,PayMode,PayStatus) values ('" + BookinDate + "','" + txtNumPersons.Text + "','" + No_OfRooms + "','" + hfGuestID.Value + "','" + drpBookMode.SelectedValue + "','" + txtArrived.Text + "','" + txtVisitPurpose.Text + "','" + txtRegNumber.Text + "','" + txtVehicalNumber.Text + "','" + txtTotalFare.Text + "','" + txtGst.Text + "','" + txtAmtPaid.Text + "','" + drpPayMode.SelectedValue + "','" + drpPayStatus.SelectedValue + "')";
                SqlCommand cmdInsertBook_Master = new SqlCommand(QueryBook_Master, hmcon);
                hmcon.Open();
                cmdInsertBook_Master.ExecuteNonQuery();
                cmdInsertBook_Master.Dispose();
                hmcon.Close();
                GenerateBookingID();
                #endregion
                #region Save Record in Book_Details Table
                int Booking_Id = 0;
                if (lastID > 1)
                {
                    Booking_Id = lastID - 1;
                }
                else
                {
                    Booking_Id = lastID;
                }
                for (int i = 0; i < grdRoomDetails.Rows.Count; i++)
                {
                    Label Room_ID = (Label)grdRoomDetails.Rows[i].Cells[1].FindControl("lblRoomID");
                    Label BookedFrom = (Label)grdRoomDetails.Rows[i].Cells[1].FindControl("lblBookFrom");//01-09-2017
                    Label CheckInTime = (Label)grdRoomDetails.Rows[i].Cells[1].FindControl("lblCheckInTime");
                    Label BookedTill = (Label)grdRoomDetails.Rows[i].Cells[1].FindControl("lblBookTo");
                    Label CheckOutTime = (Label)grdRoomDetails.Rows[i].Cells[1].FindControl("lblCheckOutTime");
                    Label Duration = (Label)grdRoomDetails.Rows[i].Cells[1].FindControl("lblDuration");
                    Label RoomFare = (Label)grdRoomDetails.Rows[i].Cells[1].FindControl("lblRoomFare");
                    Label BookingStatus = (Label)grdRoomDetails.Rows[i].Cells[1].FindControl("lblBookingStatusID");
                    hmcon.Open();
                    DateTime BookFrmDate = new DateTime();
                    BookFrmDate = DateTime.ParseExact(BookedFrom.Text, "dd-MM-yyyy", null);//CultureInfo.InvariantCulture
                    string CheckIn_Time = Convert.ToDateTime(CheckInTime.Text.Trim()).ToString("hh:mm tt");
                    string CheckOut_Time = Convert.ToDateTime(CheckOutTime.Text.Trim()).ToString("hh:mm tt");
                    DateTime BookTillDate = new DateTime();
                    BookTillDate = DateTime.ParseExact(BookedTill.Text, "dd-MM-yyyy", null);
                    string queryInsertBook_Details = "Insert into Book_Details (CheckIN_Date,CheckIn_Time,CheckOUt_Date,CheckOut_Time,Room_ID,Book_Status,Book_Master_ID,Fare,Duration) values ('" + BookFrmDate + "','" + CheckIn_Time + "','" + BookTillDate + "','" + CheckOut_Time + "','" + Room_ID.Text + "','" + BookingStatus.Text + "','" + Booking_Id + "','" + RoomFare.Text + "','" + Duration.Text + "')";
                    // string queryInsertBook_Details = "Insert into Book_Details (CheckIN_Date ,CheckOUt_Date,Room_ID,Book_Status,Book_Master_ID,Fare,Duration) values ('" + BookedFrom.Text + "','" + BookedTill.Text + "','" + Room_ID.Text + "','" + BookingStatus.Text + "','" + Booking_Id + "','" + RoomFare.Text + "','" + Duration.Text + "')";
                    SqlCommand cmdInsertBook_Details = new SqlCommand(queryInsertBook_Details, hmcon);
                    cmdInsertBook_Details.ExecuteNonQuery();
                    cmdInsertBook_Details.Dispose();
                    hmcon.Close();
                }
                #endregion
                #region Save Record in MstGuestPersons Table
                for (int i = 0; i < grdGuestsDetails.Rows.Count; i++)
                {
                    Label GuestName = (Label)grdGuestsDetails.Rows[i].Cells[1].FindControl("lblName");
                    Label GuestLastName = (Label)grdGuestsDetails.Rows[i].Cells[1].FindControl("lblLastName");
                    Label Gender = (Label)grdGuestsDetails.Rows[i].Cells[1].FindControl("lblGender");
                    Label Age = (Label)grdGuestsDetails.Rows[i].Cells[1].FindControl("lblAge");
                    Label ID_Type = (Label)grdGuestsDetails.Rows[i].Cells[1].FindControl("lblID_Type_Key");
                    Label ID_Number = (Label)grdGuestsDetails.Rows[i].Cells[1].FindControl("lblIDNum");
                    hmcon.Open();
                    string queryInsertMstGuestPersons = "Insert into MstGuestPersons (Book_Master_ID,Name,LastName,Gender,Age,ID_Type,ID_Number) values ('" + Booking_Id + "','" + GuestName.Text + "','" + GuestLastName.Text + "','" + Gender.Text + "','" + Age.Text + "','" + ID_Type.Text + "','" + ID_Number.Text + "')";//Gender,,'" + Gender.Text + "'
                    SqlCommand cmdInsertMstGuestPersons = new SqlCommand(queryInsertMstGuestPersons, hmcon);
                    cmdInsertMstGuestPersons.ExecuteNonQuery();
                    cmdInsertMstGuestPersons.Dispose();
                    hmcon.Close();
                }
                #endregion
                //RoomDetailsBlankData();
                //GuestDetailsBlankData();
                GenerateBookingID();
                ClearAll();
                lblmsg.Text = "Booking Added !!!";
                lblMessage.Text = "Booking Added !!!";
                hfBooking_ID.Value = Booking_Id.ToString();
                mpeMessageBox.Show();
                mpePrintBill.Show();
            }
            else
            {
                if (hfGuestID.Value == "" && grdRoomDetails.Rows.Count == 0 && txtRegNumber.Text == "")
                {
                    lblmsg.Text = "Please add Guest Name,Rooms nd Register Num !!";
                    mpeMessageBox.Show();
                }
                else if (hfGuestID.Value == "")
                {
                    lblmsg.Text = "Please add Guest Name !!";
                    mpeMessageBox.Show();
                }
                else if (txtRegNumber.Text == "")
                {
                    lblmsg.Text = "Please add Register Number !!";
                    mpeMessageBox.Show();
                }
                else
                {
                    lblmsg.Text = "Please add Rooms !!";
                    mpeMessageBox.Show();
                }
            }
        }
        catch (Exception ex)
        {
            throw;
        }
    }
    protected void UpdateBooking()
    {
        try
        {
            int No_OfRooms = grdRoomDetails.Rows.Count;
            string Booking_ID = hfBooking_ID.Value;
            if (grdRoomDetails.Rows.Count > 0 && Booking_ID != "")
            {
                #region Update Record in Booking_Master Table
                DateTime dt = new DateTime();
                dt = DateTime.ParseExact(this.txtBookDate.Text, "dd-MM-yyyy", null);//01-09-2017
                string BookinDate = dt.ToString();//9/1/2017 12:00:00 AM
                string QueryBook_Master = "Update Booking_Master set Book_Date='" + BookinDate + "',No_Persons='" + txtNumPersons.Text + "',No_Rooms='" + No_OfRooms + "',Guest_ID='" + hfGuestID.Value + "',Book_Mode='" + drpBookMode.SelectedValue + "',ArrivedFrom='" + txtArrived.Text + "',VisitPurpose='" + txtVisitPurpose.Text + "',RegNo='" + txtRegNumber.Text + "',VehicalNum='" + txtVehicalNumber.Text + "',TotalFare='" + txtTotalFare.Text + "',GSTAmount='" + txtGst.Text + "',AmountPaid='" + txtAmtPaid.Text + "',PayMode='" + drpPayMode.SelectedValue + "',PayStatus='" + drpPayStatus.SelectedValue + "' where ID='" + Booking_ID + "'";
                //values ('" + BookinDate + "','" + txtNumPersons.Text + "','" + No_OfRooms + "','" + hfGuestID.Value + "','" + drpBookMode.SelectedValue + "','" + txtArrived.Text + "','" + txtVisitPurpose.Text + "','" + txtVehicalNumber.Text + "','" + txtTotalFare.Text + "','" + txtGst.Text + "','" + txtAmtPaid.Text + "','" + drpPayMode.SelectedValue + "','" + drpPayStatus.SelectedValue + "')
                SqlCommand cmdInsertBook_Master = new SqlCommand(QueryBook_Master, hmcon);
                hmcon.Open();
                cmdInsertBook_Master.ExecuteNonQuery();
                cmdInsertBook_Master.Dispose();
                hmcon.Close();
                GenerateBookingID();
                #endregion
                hmcon.Open();
                SqlCommand cmdDeleteBooking = new SqlCommand("Delete from Book_Details where Book_Master_ID='" + Booking_ID + "'", hmcon);
                cmdDeleteBooking.ExecuteNonQuery();
                cmdDeleteBooking.Dispose();
                hmcon.Close();
                hmcon.Open();
                SqlCommand cmdDeleteGuest = new SqlCommand("Delete from MstGuestPersons where Book_Master_ID='" + Booking_ID + "'", hmcon);
                cmdDeleteGuest.ExecuteNonQuery();
                cmdDeleteGuest.Dispose();
                hmcon.Close();
                #region Save Record in Book_Details Table
                //int Booking_Id = 0;
                //if (lastID > 1)
                //{
                //    Booking_Id = lastID - 1;
                //}
                //else
                //{
                //    Booking_Id = lastID;
                //}
                for (int i = 0; i < grdRoomDetails.Rows.Count; i++)
                {
                    Label Room_ID = (Label)grdRoomDetails.Rows[i].Cells[1].FindControl("lblRoomID");
                    Label BookedFrom = (Label)grdRoomDetails.Rows[i].Cells[1].FindControl("lblBookFrom");//01-09-2017
                    Label CheckInTime = (Label)grdRoomDetails.Rows[i].Cells[1].FindControl("lblCheckInTime");
                    Label BookedTill = (Label)grdRoomDetails.Rows[i].Cells[1].FindControl("lblBookTo");
                    Label CheckOutTime = (Label)grdRoomDetails.Rows[i].Cells[1].FindControl("lblCheckOutTime");
                    Label Duration = (Label)grdRoomDetails.Rows[i].Cells[1].FindControl("lblDuration");
                    Label RoomFare = (Label)grdRoomDetails.Rows[i].Cells[1].FindControl("lblRoomFare");
                    Label BookingStatus = (Label)grdRoomDetails.Rows[i].Cells[1].FindControl("lblBookingStatusID");
                    hmcon.Open();
                    DateTime BookFrmDate = new DateTime();
                    BookFrmDate = DateTime.ParseExact(BookedFrom.Text, "dd-MM-yyyy", null);//CultureInfo.InvariantCulture
                    string CheckIn_Time = Convert.ToDateTime(CheckInTime.Text.Trim()).ToString("hh:mm tt");
                    string CheckOut_Time = Convert.ToDateTime(CheckOutTime.Text.Trim()).ToString("hh:mm tt");
                    DateTime BookTillDate = new DateTime();
                    BookTillDate = DateTime.ParseExact(BookedTill.Text, "dd-MM-yyyy", null);
                    //string queryInsertBook_Details = "Insert into Book_Details (CheckIN_Date ,CheckOUt_Date,Room_ID,Book_Status,Book_Master_ID,Fare,Duration) values ('" + BookFrmDate + "','" + BookTillDate + "','" + Room_ID.Text + "','" + BookingStatus.Text + "','" + Booking_ID + "','" + RoomFare.Text + "','" + Duration.Text + "')";
                    string queryInsertBook_Details = "Insert into Book_Details (CheckIN_Date,CheckIn_Time,CheckOUt_Date,CheckOut_Time,Room_ID,Book_Status,Book_Master_ID,Fare,Duration) values ('" + BookFrmDate + "','" + CheckIn_Time + "','" + BookTillDate + "','" + CheckOut_Time + "','" + Room_ID.Text + "','" + BookingStatus.Text + "','" + Booking_ID + "','" + RoomFare.Text + "','" + Duration.Text + "')";
                    SqlCommand cmdInsertBook_Details = new SqlCommand(queryInsertBook_Details, hmcon);
                    cmdInsertBook_Details.ExecuteNonQuery();
                    cmdInsertBook_Details.Dispose();
                    hmcon.Close();
                }
                #endregion
                #region Save Record in MstGuestPersons Table
                for (int i = 0; i < grdGuestsDetails.Rows.Count; i++)
                {
                    Label GuestName = (Label)grdGuestsDetails.Rows[i].Cells[1].FindControl("lblName");
                    Label GuestLastName = (Label)grdGuestsDetails.Rows[i].Cells[1].FindControl("lblLastName");
                    Label Gender = (Label)grdGuestsDetails.Rows[i].Cells[1].FindControl("lblGender");
                    Label Age = (Label)grdGuestsDetails.Rows[i].Cells[1].FindControl("lblAge");
                    Label ID_Type = (Label)grdGuestsDetails.Rows[i].Cells[1].FindControl("lblID_Type_Key");
                    Label ID_Number = (Label)grdGuestsDetails.Rows[i].Cells[1].FindControl("lblIDNum");
                    hmcon.Open();
                    string queryInsertMstGuestPersons = "Insert into MstGuestPersons (Book_Master_ID,Name,LastName,Gender,Age,ID_Type,ID_Number) values ('" + Booking_ID + "','" + GuestName.Text + "','" + GuestLastName.Text + "','" + Gender.Text + "','" + Age.Text + "','" + ID_Type.Text + "','" + ID_Number.Text + "')";//Gender,,'" + Gender.Text + "'
                    SqlCommand cmdInsertMstGuestPersons = new SqlCommand(queryInsertMstGuestPersons, hmcon);
                    cmdInsertMstGuestPersons.ExecuteNonQuery();
                    cmdInsertMstGuestPersons.Dispose();
                    hmcon.Close();
                }
                #endregion
                //lblmsg.Text = "Booking Updated !!!";
                //mpeMessageBox.Show();
                hfBooking_ID.Value = Booking_ID;
                lblMessage.Text = "Booking Updated !!";
                mpePrintBill.Show();
            }
            else
            {
                RoomDetailsBlankData();
                GuestDetailsBlankData();
                GenerateBookingID();
            }
        }
        catch (Exception ex)
        {
            throw;
        }
    }
    #region All Controls Events
    protected void txtBookDate_TextChanged(object sender, EventArgs e)
    {
        txtGuestName.Focus();
    }
    protected void txtGuestName_TextChanged(object sender, EventArgs e)
    {
        txtArrived.Focus();
    }
    protected void txtArrived_TextChanged(object sender, EventArgs e)
    {
        txtVisitPurpose.Focus();
    }
    protected void txtVisitPurpose_TextChanged(object sender, EventArgs e)
    {
        drpBookMode.Focus();
    }
    protected void drpBookMode_SelectedIndexChanged(object sender, EventArgs e)
    {
        txtVehicalNumber.Focus();
    }
    protected void txtVehicalNumber_TextChanged(object sender, EventArgs e)
    {
        txtBookFrom.Focus();
    }
    protected void txtBookFrom_TextChanged(object sender, EventArgs e)
    {
        if (txtBookFrom.Text != "")
        {
            DateTime dt11 = DateTime.ParseExact(this.txtBookFrom.Text, "dd-MM-yyyy", null);
            dt11 = dt11.AddDays(1);
            txtBookTill.Text = dt11.ToString("dd-MM-yyyy");
        }
        if (txtBookFrom.Text != "" && txtBookTill.Text != "")
        {
            DateTime BookFrmDate = new DateTime();
            BookFrmDate = DateTime.ParseExact(this.txtBookFrom.Text, "dd-MM-yyyy", null);
            DateTime BookTillDate = new DateTime();
            BookTillDate = DateTime.ParseExact(this.txtBookTill.Text, "dd-MM-yyyy", null);
            BookFrmDate = new DateTime(BookFrmDate.Year, BookFrmDate.Month, BookFrmDate.Day);
            BookTillDate = new DateTime(BookTillDate.Year, BookTillDate.Month, BookTillDate.Day);
            int result = DateTime.Compare(BookFrmDate, BookTillDate);
            if (BookTillDate < BookFrmDate)
            {
                lblmsg.Text = "BookFrom Date Should Be Greater or Equal to BookTill Date..!!!";
                mpeMessageBox.Show();
                txtDuration.Text = "";
            }
            else
            {
                DateTime FrmDate = new DateTime();
                FrmDate = DateTime.ParseExact(this.txtBookFrom.Text, "dd-MM-yyyy", null);
                string FrmDate1 = FrmDate.ToString();
                DateTime ToDate = new DateTime();
                ToDate = DateTime.ParseExact(this.txtBookTill.Text, "dd-MM-yyyy", null);
                string ToDate1 = FrmDate.ToString();
                //DateTime FrmDate = DateTime.Parse(Convert.ToDateTime(txtBookFrom.Text).ToShortDateString());
                //DateTime ToDate = DateTime.Parse(Convert.ToDateTime(txtBookTill.Text).ToShortDateString());
                //DateTime FrmDate = Convert.ToDateTime(txtBookFrom.Text);
                //DateTime ToDate = Convert.ToDateTime(txtBookTill.Text);
                //DateTime FrmDa4te = DateTime.ParseExact(txtBookFrom.Text, "MM/dd/YYYY HH:mm", CultureInfo.InvariantCulture);
                //DateTime ToDate = DateTime.ParseExact(txtBookTill.Text, "MM/dd/YYYY HH:mm", CultureInfo.InvariantCulture);
                int Days = 0;
                TimeSpan diff = ToDate - FrmDate;
                if (diff.Days == 0)
                {
                    Days = diff.Days + 1;
                }
                else
                {
                    Days = diff.Days;
                }
                txtDuration.Text = Days.ToString();
                BindRooms();
                txtFloor.Text = "";
                txtRoomType.Text = "";
                txtRoomFare.Text = "";
            }
        }
        txtCheckINTime.Focus();
    }
    protected void txtBookTill_TextChanged(object sender, EventArgs e)
    {
        if (txtBookFrom.Text != "" && txtBookTill.Text != "")
        {
            //DateTime d1 = Convert.ToDateTime(txtBookFrom.Text);
            //DateTime d2 = Convert.ToDateTime(txtBookFrom.Text);
            DateTime BookFrmDate = new DateTime();
            BookFrmDate = DateTime.ParseExact(this.txtBookFrom.Text, "dd-MM-yyyy", null);
            DateTime BookTillDate = new DateTime();
            BookTillDate = DateTime.ParseExact(this.txtBookTill.Text, "dd-MM-yyyy", null);
            BookFrmDate = new DateTime(BookFrmDate.Year, BookFrmDate.Month, BookFrmDate.Day);
            BookTillDate = new DateTime(BookTillDate.Year, BookTillDate.Month, BookTillDate.Day);
            int result = DateTime.Compare(BookFrmDate, BookTillDate);
            if (BookTillDate < BookFrmDate)
            {
                lblmsg.Text = "BookFrom Date Should Be Greater or Equal to BookTill Date..!!!";
                mpeMessageBox.Show();
                txtDuration.Text = "";
            }
            else
            {
                DateTime FrmDate = new DateTime();
                FrmDate = DateTime.ParseExact(this.txtBookFrom.Text, "dd-MM-yyyy", null);
                string FrmDate1 = FrmDate.ToString();
                DateTime ToDate = new DateTime();
                ToDate = DateTime.ParseExact(this.txtBookTill.Text, "dd-MM-yyyy", null);
                string ToDate1 = FrmDate.ToString();
                //DateTime FrmDate = DateTime.Parse(Convert.ToDateTime(txtBookFrom.Text).ToShortDateString());
                //DateTime ToDate = DateTime.Parse(Convert.ToDateTime(txtBookTill.Text).ToShortDateString());
                //DateTime FrmDate = Convert.ToDateTime(txtBookFrom.Text);
                //DateTime ToDate = Convert.ToDateTime(txtBookTill.Text);
                //DateTime FrmDate = DateTime.ParseExact(txtBookFrom.Text, "MM/dd/YYYY HH:mm", CultureInfo.InvariantCulture);
                //DateTime ToDate = DateTime.ParseExact(txtBookTill.Text, "MM/dd/YYYY HH:mm", CultureInfo.InvariantCulture);
                int Days = 0;
                TimeSpan diff = ToDate - FrmDate;
                if (diff.Days == 0)
                {
                    Days = diff.Days + 1;
                }
                else
                {
                    Days = diff.Days;
                }
                txtDuration.Text = Days.ToString();
                BindRooms();
                txtFloor.Text = "";
                txtRoomType.Text = "";
                txtRoomFare.Text = "";
            }
        }
        drpRoomNum.Focus();
    }
    protected void drpRoomNum_SelectedIndexChanged(object sender, EventArgs e)
    {
        GetRoomDetailsById();
    }
    protected void GetRoomDetailsById()
    {
        String readData = "select rm.Price,rt.Description as RoomType,rf.Description as FloorNum from MstRoom rm inner join MstFloor rf on rm.Floor_Num= rf.ID inner join MstRoom_Type rt on rm.Room_Type= rt.ID where rm.ID='" + drpRoomNum.SelectedValue + "'";
        SqlCommand cmd = new SqlCommand(readData, hmcon);
        hmcon.Open();
        SqlDataReader dr = cmd.ExecuteReader();
        if (dr.Read())
        {
            txtFloor.Text = dr["FloorNum"].ToString();
            txtRoomType.Text = dr["RoomType"].ToString();
            txtRoomFare.Text = dr["Price"].ToString();
            drpBookingStatus.Focus();
        }
        hmcon.Close();
    }
    protected void drpBookingStatus_SelectedIndexChanged(object sender, EventArgs e)
    {
        btnAddRoom.Focus();
    }
    protected void txtNumPersons_TextChanged(object sender, EventArgs e)
    {
        txtAdults.Focus();
    }
    protected void txtAmtPaid_TextChanged(object sender, EventArgs e)
    {
        if (txtAmountPayable.Text != "" && txtAmtPaid.Text != "")
        {
            decimal BalAmount = Convert.ToDecimal(txtAmountPayable.Text) - (Convert.ToDecimal(txtAmtPaid.Text));
            txtBalAmt.Text = Convert.ToString(BalAmount);
            drpPayMode.Focus();
        }
    }
    protected void drpPayMode_SelectedIndexChanged(object sender, EventArgs e)
    {
        drpPayStatus.Focus();
    }
    protected void drpPayStatus_SelectedIndexChanged(object sender, EventArgs e)
    {
        btnSaveBooking.Focus();
    }
    #endregion