示例#1
0
        public IList <OfficeBusinessDistance> GetNearestOffices(OfficeQuery qry)
        {
            if (OfficeRepository == null)
            {
                throw new ArgumentNullException("Officerepository not defined");
            }

            return(OfficeRepository.GetNearestOffices(qry).Select(t => new OfficeBusinessDistance()
            {
                City = t.city,
                HasSupportDesk = (t.has_support_desk == "Y"),
                IsOpenInWeekends = (t.is_open_in_weekends == "Y"),
                Street = t.street,
                Latitude = t.latitude,
                Longitude = t.longitude,
                Id = t.id,
                Distance = Geography.HaversineDistance(new MapPoint()
                {
                    Latitude = t.latitude, Longitude = t.longitude
                },
                                                       new MapPoint()
                {
                    Latitude = qry.Latitude, Longitude = qry.Longitude
                },
                                                       Geography.DistanceUnit.Kilometers)
            })
                   //Correct rounding errors
                   .Where(t => t.Distance <= qry.Radius)
                   //Sort by distance
                   .OrderBy(t => t.Distance).ToList());
        }
 public void Init()
 {
     office = new Office();
     query  = new OfficeQuery();
     query.SetOffice(office);
     chair1 = new Chair("Blue", false, true);
     chair2 = new Chair("Brown", true, true);
     chair3 = new Chair("Black", false, false);
     chair4 = new Chair("White", true, true);
     lamp1  = new Lamp("Silver", 20, 20);
     table1 = new Table("White", 200, 100, 100);
     table2 = new Table("Brown", 300, 100, 80);
 }
示例#3
0
        public IList <office> GetNearestOffices(OfficeQuery qry)
        {
            using (var db = new ExcerciseEntities())
            {
                // Find coordinates in a rectangle instead of a radius to improve performance.
                // The index on the latitude and longitude columns will be hit in the database.
                var boundingBox = Geography.GetBoundingBox(new MapPoint()
                {
                    Latitude = qry.Latitude, Longitude = qry.Longitude
                }, qry.Radius);

                var query = db.offices.Where(v =>
                                             (v.latitude >= boundingBox.MinPoint.Latitude && v.latitude <= boundingBox.MaxPoint.Latitude &&
                                              v.longitude >= boundingBox.MinPoint.Longitude && v.longitude <= boundingBox.MaxPoint.Longitude
                                             ) &&
                                             (!qry.IsOpenInWeekends || v.is_open_in_weekends == "Y") &&
                                             (!qry.IsWithSupportDesk || v.has_support_desk == "Y")
                                             );

                return(query.Distinct().ToList <office>());
            }
        }
示例#4
0
        public static void Main(string[] args)
        {
            office          = new Office();
            inventory       = new Inventory();
            officeQuery     = new OfficeQuery();
            inventoryOutput = new StreamWriter("inventory.txt");
            officeOutput    = new StreamWriter("office.txt");

            office.SetInventory(inventory);
            officeQuery.SetOffice(office);


            Console.WriteLine("Office/Inventory App\n\nPress enter to generate and display furniture...");
            Console.ReadLine();

            //Generate some furniture
            //UI can be made so that users can create furniture and since it would only call constructors no logic is involved
            Chair chair1 = new Chair("Blue", false, true);
            Chair chair2 = new Chair("Brown", true, true);
            Chair chair3 = new Chair("Black", false, false);
            Chair chair4 = new Chair("White", true, true);
            Lamp  lamp1  = new Lamp("Silver", 20, 20);
            Table table1 = new Table("White", 200, 100, 100);
            Table table2 = new Table("Brown", 300, 100, 80);

            inventory.currentInventory.Add(chair1);
            inventory.currentInventory.Add(chair2);
            inventory.currentInventory.Add(chair3);
            inventory.currentInventory.Add(chair4);
            inventory.currentInventory.Add(lamp1);
            inventory.currentInventory.Add(table1);
            inventory.currentInventory.Add(table2);


            inventory.Write(Console.Out);

            Console.WriteLine("Furniture added to inventory\n\nPress enter to add some furniture to the office...");
            Console.ReadLine();

            office.AddFromInventory(1); //chair2
            office.AddFromInventory(1); //chair3
            office.AddFromInventory(2); //lamp1
            office.AddFromInventory(1); //chair4
            office.AddFromInventory(2); //table 2

            Console.WriteLine("Three chairs, one lamp, and one table added to office from inventory\n\nPress enter to get all the chairs in the office...");
            Console.ReadLine();

            officeQuery.GetNumberOfItems("Chair");

            Console.WriteLine("Press enter to get all the brown items in the office...");
            Console.ReadLine();

            officeQuery.QueryByColor("Brown");

            Console.WriteLine("Press enter to terminate and save inventory and office layout...");
            Console.ReadLine();

            inventory.Write(inventoryOutput); //Write current furniture to Project1/bin/inventory.txt

            //Write current furniture to Project1/bin/office.txt
            foreach (Furniture item in office.furnitureInOffice)
            {
                item.Write(officeOutput);
            }

            officeOutput.Close();
            inventoryOutput.Close();
        }