コード例 #1
0
            public void WriteHotelAvailability(HotelAvailability hotelAvailability)
            {
                Application application = new Application();

                if (application == null)
                {
                    throw new Exception("Excel is not properly installed");
                }
                application.DisplayAlerts = false;
                DateTime startDate = hotelAvailability.GetEarliestKnownDate();
                DateTime endDate   = hotelAvailability.GetLatestKnownDate();

                Workbook  workbook  = application.Workbooks.Add();
                Worksheet worksheet = (Worksheet)workbook.Worksheets.get_Item(1);

                worksheet.Name = hotelAvailability.Name.GetDisplayName();

                worksheet.Cells[1, 1] = hotelAvailability.Name.GetDisplayName();

                Console.WriteLine("About to add date labels");
                AddAllDateLabels(worksheet, startDate, endDate);

                Console.WriteLine("About to add availabilities");
                AddAllAvailabilities(worksheet, hotelAvailability, startDate, endDate);

                Directory.CreateDirectory(fileOutputPath);
                workbook.SaveAs(fileOutputPath + hotelAvailability.Name.GetDisplayName() + ".xls", XlFileFormat.xlWorkbookNormal, null, null, null, null, XlSaveAsAccessMode.xlShared);
                workbook.Close(true);
                application.Quit();

                Console.WriteLine("Excel file created");
            }
コード例 #2
0
        public static async Task <HotelAvailability> GetAvailabilityForHotel(HotelName hotelName, DateTime startDate, DateTime endDate)
        {
            Dictionary <string, Object> roomsData = ReadRoomDataFromFile(hotelName);

            HotelAvailability hotelAvailability = new HotelAvailability(hotelName);
            List <DateTime>   requestDates      = CalculateRequestDates(startDate, endDate);

            foreach (DateTime requestDate in requestDates)
            {
                await AddAvailabilityAroundDate(hotelAvailability, requestDate, roomsData);
            }
            hotelAvailability.TrimDateRange(startDate, endDate);

            Console.WriteLine("\nEarliest available date for " + hotelName.Name + ": " + hotelAvailability.GetEarliestKnownDate().ToLongDateString());
            Console.WriteLine("Latest available date for " + hotelName.Name + ": " + hotelAvailability.GetLatestKnownDate().ToLongDateString() + "\n");
            Console.WriteLine("Total number of rooms gathered for " + hotelName.Name + ": " + hotelAvailability.RoomAvailabilities.Count);
            return(hotelAvailability);
        }