示例#1
0
        public void TestDBCon()
        {
            SearchDB dba    = new SearchDB();
            bool     worked = dba.DBConnectionTest();

            Assert.AreEqual(true, worked);
        }
示例#2
0
        static SearchDB GetDB(string path)
        {
            SearchDB db = new SearchDB();

            // check if theres a db to read
            if (File.Exists(path))
            {
                Console.WriteLine("reading from db");
                var dbData = File.ReadAllText(path);
                try
                {
                    db = JsonConvert.DeserializeObject <SearchDB>(dbData);
                }
                catch (Exception e)
                {
                    Console.WriteLine("invalid db reseting");
                    db = new SearchDB();
                    UpdateDB(path, db);
                }
            }
            else
            {
                // if the db doesnt exist create it for later updating
                Console.WriteLine("creating db");
                File.WriteAllText(path, JsonConvert.SerializeObject(db));
            }

            return(db);
        }
示例#3
0
        static void IndexFiles(SearchDB db, string dbPath)
        {
            var storingFolder = "IndexedFiles";
            var folder        = "C:\\Users\\yehuda nahon\\Documents\\books";

            // check the path is a valid path
            if (!IsDirectory(folder))
            {
                Console.WriteLine("path is not a directory");
            }

            if (!Directory.Exists(storingFolder))
            {
                Directory.CreateDirectory(storingFolder);
            }

            Console.WriteLine("indexing files...");

            var files = Directory.GetFiles(folder);

            db.IndexFiles(files, storingFolder);

            Console.WriteLine("updating data base");
            try
            {
                UpdateDB(dbPath, db);
            }
            catch (Exception e)
            {
                Console.WriteLine("failed updating db");
            }

            Console.WriteLine("finished writing to json file");
        }
示例#4
0
        public async Task <SearchResult> GetResult(string sessionId)
        {
            bool isComplete = false;
            var  final      = new SearchResult()
            {
                Hotels = new List <Hotel>()
            };
            var db  = new SearchDB();
            var res = await db.GetResult(sessionId);

            if (res.Count == 15)
            {
                isComplete = true;
            }

            foreach (var result in res)
            {
                final.Hotels.AddRange(result.Hotels);
                //foreach (var hotel in result.Hotels)
                //{

                //}
            }

            final.Status = new Status {
                MoreResults = !isComplete
            };
            return(final);
        }
示例#5
0
 static void UpdateDB(string path, SearchDB dB)
 {
     using (StreamWriter file = File.CreateText(path))
     {
         JsonSerializer serializer = new JsonSerializer();
         //serialize object directly into file stream
         serializer.Serialize(file, dB);
     }
 }
示例#6
0
 void Awake()
 {
     if (instance)
     {
         DestroyImmediate(gameObject);
         return;
     }
     instance = this;
     DontDestroyOnLoad(gameObject);
 }
示例#7
0
 public void InitSearch(string sessionId, SearchCriteria criteria)
 {
     Parallel.For(0, 15, async(i) =>
     {
         await Task.Yield();
         var randomizer = new Random();
         await(Task.Delay(randomizer.Next(10000, 15000)));
         var supplier = new HotelSupplier();
         var result   = supplier.Search(criteria);
         var db       = new SearchDB();
         await db.StoreSearchResult(sessionId, i, result);
     });
 }
示例#8
0
        /**
         * Wyszukiwanie
         * Ten sam mechanizm co przy dodawaniu
         **/
        private List <Models.Activity> GetSearchList(int search)
        {
            var activities = new List <Models.Activity>();

            switch (search)
            {
            case 1:     //date
                DateTime?d_date = GetFromUser.GetDateFromUser();
                if (d_date == null)
                {
                    return(null);
                }
                DateTime date = d_date.Value;
                activities = SearchDB.SearchDate(date, user);
                break;

            case 2:     //type
                var type = GetFromUser.GetTypeFromUser();
                if (type == null)
                {
                    return(null);
                }
                activities = SearchDB.SearchType(type, user);
                break;

            case 3:     //distance
                var d_distance = GetFromUser.GetDistanceFromUser();
                if (d_distance == null)
                {
                    return(null);
                }
                var distance = d_distance.Value;
                activities = SearchDB.SearchDistance(distance, user);
                break;

            case 4:     //note
                var note = GetFromUser.GetNoteFromUser();
                if (note == "esc")
                {
                    return(null);
                }
                activities = SearchDB.SearchNote(note, user);
                break;
            }
            return(activities);
        }
示例#9
0
        static void Search(SearchDB db)
        {
            Console.WriteLine("Enter the words to search");

            var text = Console.ReadLine();

            // split the text to words and make all words lowercase to fix abnormality (also removing all single letters words from the list)
            var punctuation = text.Where(Char.IsPunctuation).Distinct().ToArray();

            var words = text.Split(new char[0], StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim(punctuation).ToLower()).Where(x => x.Length > 1);

            foreach (var word in words)
            {
                var files = db.SearchWord(word);
                Console.WriteLine(word + ":");
                files.ForEach(file => Console.WriteLine("- " + file));
            }
        }
示例#10
0
        public bool validateReservationNumber(int resNum)
        {
            SearchDB db = new SearchDB();

            return(db.searchReservationDB(resNum) == 1 ? true : false);
        }
示例#11
0
        public IActionResult Search([Bind("IsCustomDutyPaid,NumberOfSeates,NumberOfDoors,IsRegistered,IsNonSmokingVehicle,//Owners,HasParkingCamera,HasParkingSensors,HasCentralDoorLock,HasPanoramaRoof,HasSportPackage,HasElectricHeatedSeats,HasAirCondition,IsUsed,Interior,Make,Model,City,Kilometers,Fuel,CubicCapacity,IsManual,Color,PriceFrom,PriceTo,ProductionYearFrom,ProductionYearTo,NumberOfDoors")] SearchDB search)
        {
            var result = _context.Vehicles.Where(d => d.Brand == search.Make);

            if (!string.IsNullOrEmpty(search.Model))
            {
                result = result.Where(d => d.Model == search.Model);
            }
            if (!string.IsNullOrEmpty(search.City))
            {
                result = result.Where(d => d.City == search.City);
            }
            if (!string.IsNullOrEmpty(search.Fuel))
            {
                result = result.Where(d => d.Fuel == search.Fuel);
            }
            if (search.Kilometers > 0)
            {
                result = result.Where(d => d.Kilometers == search.Kilometers);
            }
            if (search.CubicCapacity > 0)
            {
                result = result.Where(d => d.CubicCapacity == search.CubicCapacity);
            }
            if (search.IsManual == true)
            {
                result = result.Where(d => d.IsManual == search.IsManual);
            }
            if (search.IsCustomDutyPaid == true)
            {
                result = result.Where(d => d.CubicCapacity == search.CubicCapacity);
            }
            if (search.PriceFrom > 0)
            {
                result = result.Where(d => d.Price >= search.PriceFrom);
            }
            if (search.PriceTo > search.PriceFrom)
            {
                result = result.Where(d => d.Price <= search.PriceTo);
            }
            if (search.ProductionYearFrom >= DateTime.Now.AddYears(-100).Year)
            {
                result = result.Where(d => d.ProductionYear >= search.ProductionYearFrom);
            }
            if (search.ProductionYearTo > search.ProductionYearFrom)
            {
                result = result.Where(d => d.ProductionYear <= search.ProductionYearFrom);
            }
            //VhlDetails atributes
            if (!string.IsNullOrEmpty(search.Interior))
            {
                result = result.Where(d => d.VehicleDetails.Any(l => l.Interior == search.Interior));
            }
            if (search.NumberOfSeates > 0)
            {
                result = result.Where(d => d.VehicleDetails.Any(l => l.NumberOfSeates == search.NumberOfSeates));
            }
            if (search.NumberOfDoors > 0)
            {
                result = result.Where(d => d.VehicleDetails.Any(l => l.NumberOfDoors == search.NumberOfDoors));
            }
            if (search.IsRegistered == true)
            {
                result = result.Where(d => d.VehicleDetails.Any(l => l.IsRegistered == search.IsRegistered));
            }
            if (search.IsNonSmokingVehicle == true)
            {
                result = result.Where(d => d.VehicleDetails.Any(l => l.IsNonSmokingVehicle == search.IsNonSmokingVehicle));
            }
            if (search.Owners > 0)
            {
                result = result.Where(d => d.VehicleDetails.Any(l => l.Owners == search.Owners));
            }
            if (search.HasParkingCamera == true)
            {
                result = result.Where(d => d.VehicleDetails.Any(l => l.HasParkingCamera == search.HasParkingCamera));
            }
            if (search.HasParkingSensors == true)
            {
                result = result.Where(d => d.VehicleDetails.Any(l => l.HasParkingSensors == search.HasParkingSensors));
            }
            if (search.HasCentralDoorLock == true)
            {
                result = result.Where(d => d.VehicleDetails.Any(l => l.HasCentralDoorLock == search.HasCentralDoorLock));
            }
            if (search.HasPanoramaRoof == true)
            {
                result = result.Where(d => d.VehicleDetails.Any(l => l.HasPanoramaRoof == search.HasPanoramaRoof));
            }
            if (search.HasSportPackage == true)
            {
                result = result.Where(d => d.VehicleDetails.Any(l => l.HasSportPackage == search.HasSportPackage));
            }
            if (search.HasElectricHeatedSeats == true)
            {
                result = result.Where(d => d.VehicleDetails.Any(l => l.HasElectricHeatedSeats == search.HasElectricHeatedSeats));
            }
            if (search.HasAirCondition == true)
            {
                result = result.Where(d => d.VehicleDetails.Any(l => l.HasAirCondition == search.HasAirCondition));
            }
            if (search.IsUsed == true)
            {
                result = result.Where(d => d.VehicleDetails.Any(l => l.IsUsed == search.IsUsed));
            }
            if (!string.IsNullOrEmpty(search.Color))
            {
                result = result.Where(d => d.VehicleDetails.Any(l => l.Color == search.Color));
            }
            if (search.IsCustomDutyPaid == true)
            {
                result = result.Where(d => d.VehicleDetails.Any(l => l.IsCustomDutyPaid == search.IsCustomDutyPaid));
            }

            search.Result    = result.ToList();
            ViewData["Make"] = _context.CarsList.Select(d => d.Make).Distinct().ToList().Select(d => new SelectListItem {
                Value = d, Text = d
            });
            return(View("Index", search));
        }
示例#12
0
        public static int validateOwnerForPet(int resNum, int petNum)
        {
            SearchDB db = new SearchDB();

            return(db.searchPetOwner(resNum, petNum));
        }
示例#13
0
        public bool validateReservationForPet(int petNum, int resNum)
        {
            SearchDB db = new SearchDB();

            return(db.searchReservationForPet(petNum, resNum) == 1 ? true : false);
        }
示例#14
0
        public bool validatePetResNum(int petResNum)
        {
            SearchDB db = new SearchDB();

            return(db.searchPetResDB(petResNum) == 1 ? true : false);
        }
示例#15
0
        public char getPetSize(int petNumber)
        {
            SearchDB db = new SearchDB();

            return(db.getPetSize(petNumber));
        }
示例#16
0
        public bool validateConflictingReservations(int petNum, DateTime startDate, DateTime endDate)   // checks if pet already has vaccination on those days
        {
            SearchDB db = new SearchDB();

            return(db.searchConflictingReservations(petNum, startDate, endDate) == 0 ? true : false);
        }
示例#17
0
 public ActionResult Search(SearchDB searchFor)
 {
     return(View(searchFor));
 }
示例#18
0
        public bool validateOwnerNumber(int ownNum)
        {
            SearchDB db = new SearchDB();

            return(db.searchOwnerDB(ownNum) == 1 ? true : false);
        }
示例#19
0
        private void SearchButton_Click(object sender, RoutedEventArgs e)
        {
            var mainWindow = (MainWindow)Application.Current.MainWindow;
            List <Model1.Activity> activities = null;
            string comboBoxItem = (string)SearchComboBox.SelectedItem;

            switch (comboBoxItem)
            {
            case "type":
                string type = (string)TypeComboBox.SelectedItem;
                if (type != null)
                {
                    activities = SearchDB.SearchType(type, user);
                }
                else
                {
                    InfoLabel.Content = "Bad Data";
                }
                break;

            case "distance":
                if (!string.IsNullOrEmpty(DistanceTextBox.Text))
                {
                    var distance = float.Parse(DistanceTextBox.Text);
                    activities = SearchDB.SearchDistance(distance, user);
                }
                else
                {
                    InfoLabel.Content = "Bad Data";
                }
                break;

            case "date":
                if (DatePicker.SelectedDate != null)
                {
                    DateTime date = DatePicker.SelectedDate.Value;
                    activities = SearchDB.SearchDate(date, user);
                }
                else
                {
                    InfoLabel.Content = "Bad Data";
                }
                break;

            case "note":
                string note = NoteTextBox.Text;
                if (!string.IsNullOrEmpty(note))
                {
                    activities = SearchDB.SearchNote(note, user);
                }
                else
                {
                    InfoLabel.Content = "Bad Data";
                }
                break;
            }
            if (activities != null)
            {
                mainWindow.Frame.Navigate(new View.Activity.MainView(activities));
            }
        }
示例#20
0
        public bool validateVaccNumber(int vaccNum)
        {
            SearchDB db = new SearchDB();

            return(db.searchVaccDB(vaccNum) == 1 ? true : false);
        }
示例#21
0
 public List <Search> ReadSaleByBrandIdModelId(int brandId, int modelId)
 {
     return(SearchDB.ReadSaleByBrandIdModelId(brandId, modelId));
 }