コード例 #1
0
ファイル: DatabaseCalls.cs プロジェクト: hantus/NapierHoliday
 // finds all customers when provided a part of their name. Used when looking for existing customers by name
 public static List <CustomerItem> FindCustomerByName(string name)
 {
     try
     {
         using (SqlConnection con = Connect())
         {
             con.Open();
             string              sql          = String.Format("SELECT Name, Address FROM Customer WHERE Name LIKE '%{0}%';", name);
             SqlCommand          com          = new SqlCommand(sql, con);
             SqlDataReader       sdr          = com.ExecuteReader();
             List <CustomerItem> customerList = new List <CustomerItem>();
             while (sdr.Read())
             {
                 {
                     CustomerItem customerItem = new CustomerItem();
                     customerItem.Name    = sdr.GetString(0);
                     customerItem.Address = sdr.GetString(1);
                     customerList.Add(customerItem);
                 }
             }
             return(customerList);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         return(null);
     }
 }
コード例 #2
0
ファイル: DatabaseCalls.cs プロジェクト: hantus/NapierHoliday
 // retreives guest details
 public static CustomerItem GetSingleCustomerDetails(string name)
 {
     try
     {
         using (SqlConnection con = Connect())
         {
             con.Open();
             string sql = String.Format("SELECT * FROM Customer WHERE Name = '{0}';",
                                        name);
             SqlCommand    com      = new SqlCommand(sql, con);
             SqlDataReader sdr      = com.ExecuteReader();
             CustomerItem  customer = new CustomerItem();
             while (sdr.Read())
             {
                 {
                     customer.Id      = sdr.GetInt32(0);
                     customer.Name    = sdr.GetString(1);
                     customer.Address = sdr.GetString(2);
                 }
             }
             return(customer);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         return(null);
     }
 }
コード例 #3
0
ファイル: DatabaseCalls.cs プロジェクト: hantus/NapierHoliday
        // retreives details of 1 or many customers depending on the parameter provided. If provided with a customer number
        // it will get details of this customer. If 0 is passed it will get a list of all customers
        public static List <CustomerItem> GetCustomersDetails(int custNumber)
        {
            try
            {
                using (SqlConnection con = Connect())
                {
                    con.Open();
                    string sql;
                    if (custNumber == 0)
                    {
                        sql = String.Format("SELECT * FROM Customer;");
                    }
                    else
                    {
                        sql = String.Format("SELECT * FROM Customer WHERE Customer_Id = {0};",
                                            custNumber);
                    }

                    SqlCommand          com          = new SqlCommand(sql, con);
                    SqlDataReader       sdr          = com.ExecuteReader();
                    List <CustomerItem> customerList = new List <CustomerItem>();

                    while (sdr.Read())
                    {
                        {
                            CustomerItem customer = new CustomerItem();
                            customer.Id      = sdr.GetInt32(0);
                            customer.Name    = sdr.GetString(1);
                            customer.Address = sdr.GetString(2);
                            customerList.Add(customer);
                        }
                    }
                    return(customerList);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(null);
            }
        }
コード例 #4
0
        // retreives all information for a booking and reconstructs it into an object
        public static AbstractBooking RetreiveBooking(int bookingId)
        {
            Client                  customer       = null;
            List <Person>           guestList      = new List <Person>();
            int                     customerRef    = DatabaseCalls.GetCustIdForBooking(bookingId);
            CustomerItem            customerItem   = DatabaseCalls.GetCustomersDetails(customerRef).ElementAt(0);
            BusinessFacadeSingleton businessFacade = BusinessFacadeSingleton.Instance();

            customer = businessFacade.CreateClient(customerItem.Id, customerItem.Name, customerItem.Address);

            foreach (var guestItem in DatabaseCalls.GetGuestsDetails(0, bookingId))
            {
                GuestDecorator guest = businessFacade.CreateGuest(guestItem.Name, guestItem.PassportNumber, guestItem.Age);
                if (DatabaseCalls.IsCustomer(guest.Name))
                {
                    guest.SetComponent(customer);
                }
                guestList.Add(guest);
            }
            BookingItem bookingItem = DatabaseCalls.GetBookingDetails(bookingId);
            CarHireItem carHireItem = DatabaseCalls.GetCarHireDetails(bookingId);
            bool        carHire     = false;
            string      driver      = "";
            DateTime    hireStart   = DateTime.Today;
            DateTime    hireEnd     = DateTime.Today;

            if (carHireItem != null)
            {
                carHire   = true;
                driver    = carHireItem.Driver;
                hireStart = carHireItem.HireStart;
                hireEnd   = carHireItem.HireEnd;
            }
            var booking = businessFacade.CreateBooking(bookingId, bookingItem.Arrival, bookingItem.Departure, customer, guestList,
                                                       bookingItem.ChaletId, bookingItem.EveningMeal, bookingItem.Breakfast, carHire, hireStart,
                                                       hireEnd, driver);

            return(booking);
        }