コード例 #1
0
        public bool UpdateHotelBooking(string BookingID, string CustomerID, string BookingDate, string BookingType, string Hotel, string Room, int Night)
        {
            SqlConnection myconn = GetSqlConnection();
            int           update;
            bool          flag = false;

            //update statment
            string sql = "Update Booking set CustomerID=@CustomerID,Date=@date,type=@type,Package=@Package,Hotel=@hotel,Room=@room,HotelNight=@night where ID=@ID";

            //Using Booking Class
            hotelBooking ht = new hotelBooking(CustomerID, BookingDate, BookingType, Hotel, Room, Night);

            //define sql command and parameters

            SqlCommand cmd = new SqlCommand(sql, myconn);

            cmd.Parameters.AddWithValue("@ID", BookingID);
            cmd.Parameters.AddWithValue("@CustomerID", ht.GetCustomerID);
            cmd.Parameters.AddWithValue("@date", ht.GetDate);
            cmd.Parameters.AddWithValue("@type", ht.GetBookingType);
            cmd.Parameters.AddWithValue("@Package", DBNull.Value);
            cmd.Parameters.AddWithValue("@hotel", ht.GetHotelName);
            cmd.Parameters.AddWithValue("@room", ht.GetRoomType);
            cmd.Parameters.AddWithValue("@night", ht.GetNight);

            try
            {
                myconn.Open();                  //opens the connection
                update = cmd.ExecuteNonQuery(); //executes the sql command
                if (update >= 1)
                {
                    flag = true;
                }
                else
                {
                    flag = false;
                }
            }
            catch (SqlException ex)
            {//display on the console the exeception message
                Console.WriteLine(ex.ToString());
                Console.ReadLine();
            }
            finally
            {// Close the connection
                myconn.Close();
            }
            if (flag == true)
            { //counting the amount and update the record in the database
                sql = "update Booking set charge=0, Discount=0, Deposit=0, Total =(select (hr.Price * b.HotelNight) from Booking b,Hotel h, HotelRoom hr where b.Hotel = H.HotelName and h.HotelName = hr.Hotel and b.Room = hr.Room and b.ID =@ID) where ID = @ID";
                SqlCommand cmn = new SqlCommand(sql, myconn);
                cmn.Parameters.AddWithValue("@ID", BookingID);
                try
                {
                    myconn.Open();                  //opens the connection
                    update = cmn.ExecuteNonQuery(); //executes the sql command
                    if (update >= 1)
                    {
                        flag = true;
                    }
                    else
                    {
                        flag = false;
                    }
                }
                catch (SqlException ex)
                {//display on the console the exeception message
                    Console.WriteLine(ex.ToString());
                    Console.ReadLine();
                }
                finally
                {// Close the connection
                    myconn.Close();
                }
            }
            return(flag);
        }
コード例 #2
0
        public bool HotelBooking(string ID, string BookingDate, string BookingType, string Hotel, string Room, int Night)
        {
            SqlConnection myconn = GetSqlConnection();
            int           add;
            bool          flag = false;
            string        sql  = "Insert into Booking (CustomerID, Date, Type, Package, Hotel, Room, HotelNight) values (@ID,@BookingDate,@BookingType,@Location,@Hotel,@Room,@Night)";

            //Using Booking Class
            hotelBooking ht = new hotelBooking(ID, BookingDate, BookingType, Hotel, Room, Night);

            //define sql command and parameters
            SqlCommand cmd = new SqlCommand(sql, myconn);

            cmd.Parameters.AddWithValue("@ID", ht.GetCustomerID);
            cmd.Parameters.AddWithValue("@BookingType", ht.GetBookingType);
            cmd.Parameters.AddWithValue("@Location", DBNull.Value);
            cmd.Parameters.AddWithValue("@BookingDate", ht.GetDate);
            cmd.Parameters.AddWithValue("@Hotel", ht.GetHotelName);
            cmd.Parameters.AddWithValue("@Room", ht.GetRoomType);
            cmd.Parameters.AddWithValue("@Night", ht.GetNight);
            try
            {
                myconn.Open();               //opens the connection
                add = cmd.ExecuteNonQuery(); //executes the sql command
                if (add >= 1)
                {
                    flag = true;
                }
                else
                {
                    flag = false;
                }
            }
            catch (SqlException ex)
            {//display on the console the exeception message
                Console.WriteLine(ex.ToString());
                Console.ReadLine();
            }
            finally
            {// Close the connection
                myconn.Close();
            }

            if (flag == true)
            {//counting the totalamount of booking
                sql = "update Booking set Total =(select (hr.Price * b.HotelNight) from Booking b,Hotel h, HotelRoom hr where b.Hotel = H.HotelName and h.HotelName = hr.Hotel and b.Room = hr.Room and b.ID = (select MAX(ID) from Booking)) where ID = (select MAX(ID) from Booking)";
                SqlCommand cmn = new SqlCommand(sql, myconn);
                try
                {
                    myconn.Open();               //opens the connection
                    add = cmn.ExecuteNonQuery(); //executes the sql command
                    if (add >= 1)
                    {
                        flag = true;
                    }
                    else
                    {
                        flag = false;
                    }
                }
                catch (SqlException ex)
                {//display on the console the exeception message
                    Console.WriteLine(ex.ToString());
                    Console.ReadLine();
                }
                finally
                {// Close the connection
                    myconn.Close();
                }
            }
            else
            {
                flag = false;
            }

            return(flag);
        }