Esempio n. 1
0
        public static bool CreateBooking(string pName, int pHouseNumber, string pHouseName, string pStreet, string pPostcode, DateTime pDateFrom, int pDaysDuration, double pPaymentAmount, Room pMyRoom, string pNotes)
        {
            int CustomerID = 0;
            Customer varCustomer = new Customer(pName, pHouseNumber, pHouseName, pStreet, pPostcode);

            if (!Customer.CheckCustomerExists(varCustomer))
            {//No customer exists, create one and update database.
                int CustomerRowsAffected = Customer.CreateCustomerRecord(varCustomer);

                if (CustomerRowsAffected == 1) { Logger.WriteLine("DEBUG", "Customer created and added to database successfully."); }
                else if (CustomerRowsAffected == 0) { Logger.WriteLine("ERROR", "Failed to update the database with new customer."); return false; }
                CustomerID = Customer.SearchForCustomerID(varCustomer);
            }
            else
            {//Customer already exists, get data from database.
                CustomerID = Customer.SearchForCustomerID(varCustomer);
            }

            if(CustomerID != 0)
            {//Customer ID exists
                List<Tuple<Type, string>> BookingAttributes = new List<Tuple<Type, string>>()
                {//Create list of values to be inserted.
                    new Tuple<Type, string>(typeof(int), pDaysDuration.ToSafeString() ),
                    new Tuple<Type, string>(typeof(DateTime), HelperMethods.FormatDateForSQL(pDateFrom.ToShortDateString()) ),
                    new Tuple<Type, string>(typeof(double), pPaymentAmount.ToSafeString() ),
                    new Tuple<Type, string>(typeof(int), pMyRoom.RoomID.ToSafeString() ),
                    new Tuple<Type, string>(typeof(int), CustomerID.ToSafeString() ),
                    new Tuple<Type, string>(typeof(string), pNotes )
                };
                List<PropertyInfo> ColumnsToBeAddedTo = new List<PropertyInfo>()
                {//Get BookingDetail object propertys
                    typeof(BookingDetail).GetProperty("Days"),
                    typeof(BookingDetail).GetProperty("DateStart"),
                    typeof(BookingDetail).GetProperty("PaymentAmount"),
                    typeof(BookingDetail).GetProperty("myRoom"),
                    typeof(BookingDetail).GetProperty("myCustomer"),
                    typeof(BookingDetail).GetProperty("Notes")
                };
                int BookingRowsAffected = DataAccess.ExecuteInsertQuery("ODS", Global.DBConfig["BookingTN"], ColumnsToBeAddedTo, BookingAttributes);

                if (BookingRowsAffected == 1) { Logger.WriteLine("DEBUG", "Booking created and added to database successfully."); }
                else if (BookingRowsAffected == 0) { Logger.WriteLine("ERROR", "Failed to update the database with new booking."); return false; }

                if(!SyncRoomRecord(pDaysDuration, pDateFrom, pPaymentAmount, pMyRoom.RoomID, CustomerID, pNotes)) { return false; }
            }
            else { return false; }
            return true;
        }
 private void LoadRoom()
 {
     assignedRoom = Room.GetRoomByID(selectedBooking.myRoom);
     TxtRoomID.Text = assignedRoom.RoomID.ToString();
     TxtRoomName.Text = assignedRoom.Name;
 }