/// <summary>
        /// Gets a Location from the database by LocationDescription
        /// </summary>
        /// <param name="description">LocationDescription to search for in the database</param>
        /// <returns>LocationClass object representing the Location in the database corresponding to the provided description</returns>
        public LocationClass GetLocationByDescription(string description)
        {
            LocationClass location = BuildLocationFromDBLocations(db.Locations.First(l => l.LocationDescription == description));

            //BuildLocationOrderHistory(location);
            return(location);
        }
        public ActionResult NewLocation(LocationClass location)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    repo.AddNewLocation(location);
                    repo.SaveChanges();

                    return(RedirectToAction(nameof(AdminOptions)));
                }
                else
                {
                    return(View());
                }
            }
            catch (ArgumentException ex)
            {
                ModelState.AddModelError("Id", ex.Message);

                return(View());
            }
            catch
            {
                return(View());
            }
        }
 /// <summary>
 /// Populates OrderHistory of LocationClass object by retrieving DataAccess Orders with corresponding LocationID from database and sending them to BuildOrderFromDBOrder
 /// </summary>
 /// <param name="location">LocationClass object whose orderHistory has not yet been loaded</param>
 public void BuildLocationOrderHistory(LocationClass location)
 {
     foreach (var order in db.Orders.Where(o => o.LocationId == location.LocationID).ToList())
     {
         location.OrderHistory.Add(BuildOrderFromDBOrder(order));
     }
 }
        /// <summary>
        /// Updates a Locations entry in the database to reflect status of inventory and menu changes
        /// </summary>
        /// <param name="location">LocationClass object representing the location to be updated</param>
        public void UpdateLocation(LocationClass location)
        {
            var trackedLocation = db.Locations.Find(location.LocationID);

            trackedLocation.Inventory = location.GetInventory();
            trackedLocation.Menu      = location.GetMenu();
            db.Locations.Update(trackedLocation);
        }
        public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
        {
            UITableViewCell cell     = tableView.DequeueReusableCell("location_id");
            LocationClass   thisList = AppData.offlineLocationList[indexPath.Row];

            cell.TextLabel.Text = thisList.locationName;
            return(cell);
        }
        /// <summary>
        /// Adds a new location to the database
        /// </summary>
        /// <param name="location">LocationClass object to be added to the database</param>
        public void AddNewLocation(LocationClass location)
        {
            Locations trackedLocation = new Locations();

            trackedLocation.LocationDescription = location.LocationDescription;
            trackedLocation.Menu      = location.GetMenu();
            trackedLocation.Inventory = location.GetInventory();
            db.Add(trackedLocation);
        }
        private void sendButton_Click(object sender, EventArgs e)
        {
            LocationClass client   = new LocationClass();
            string        h        = "-h";
            string        ip       = ipTextBox.Text;
            string        p        = "-p";
            string        port     = portTextBox.Text;
            string        name     = nameTextBox.Text;
            string        location = locationTextBox.Text;
            string        protocol = null;

            //This pulls all of the information from the UI
            if (protocolComboBox.SelectedItem.ToString() == "HTTP 0.9")
            {
                protocol = "-h9";
            }
            else if (protocolComboBox.SelectedItem.ToString() == "HTTP 1.0")
            {
                protocol = "-h0";
            }
            else if (protocolComboBox.SelectedItem.ToString() == "HTTP 1.1")
            {
                protocol = "-h1";
            }
            else
            {
            }
            //This sets the protocol depending on what one was chosen.
            List <string> userInputList = new List <string>();

            userInputList.Add(h);
            userInputList.Add(ip);
            userInputList.Add(p);
            userInputList.Add(port);
            userInputList.Add(name);
            userInputList.Add(location);
            userInputList.Add(protocol);
            string[] userInput = new string[userInputList.Count()];
            //This sorts the inputs into a array as long as the number of inputs put in.
            for (int i = 0; i < userInputList.Count(); i++)
            {
                if (userInputList[i] != null)
                {
                    userInput[i] = userInputList[i];
                }
            }
            if (name == "" || name == null)
            {
                clientOutput.Text += "Please enter a name \r\n";
            }
            else
            {
                string clientOutputString = client.RunClient(userInput);
                clientOutput.Text += clientOutputString;
            }
            //This checks that the user entered a name, and if so runs the request.
        }
        /// <summary>
        /// Builds a UserClass object from a DataAccess Users Object
        /// </summary>
        /// <param name="user">DataAccess Users Object from database to be converted</param>
        /// <returns>UserClass object built from DataAccess Users object</returns>
        private UserClass BuildUserFromDBUser(Users user)
        {
            LocationClass location = BuildLocationFromDBLocations(db.Locations.Find(user.DefaultLocation));
            UserClass     User     = new UserClass(
                user.UserId,
                user.FirstName,
                user.LastName,
                location
                );

            User.Password = user.Password;
            return(User);
        }
Пример #9
0
 public void BuildInventory(LocationClass location)
 {
     ToppingNames = new List <string>();
     ToppingStock = new List <int>();
     for (int i = 0; i < location.toppings.Count; i++)
     {
         if (location.inventory[i] != -1)
         {
             ToppingNames.Add(location.toppings[i]);
             ToppingStock.Add(location.inventory[i]);
         }
     }
 }
Пример #10
0
 public void BuildMenus(LocationClass location)
 {
     toppingMenu = new Dictionary <int, string>();
     foreach (var topping in location.toppings)
     {
         if (location.inventory[topping.Key] != -1)
         {
             toppingMenu.Add(topping.Key, topping.Value);
         }
     }
     toppingList = new List <string>();
     toppingKeys = new List <int>();
     foreach (var topping in toppingMenu)
     {
         toppingList.Add(topping.Value);
         toppingKeys.Add(topping.Key);
     }
 }
Пример #11
0
        public List <string> ComplexProcessingBasedOnObjects()
        {
            int                   amount   = Amount;
            LocationClass         location = new LocationClass();
            DateTime              now      = DateTime.Now;
            List <InputDataClass> input    = service.GetDataBatch(amount);
            var                   adults   = input.Where(x => now.Subtract(x.BirthDate).TotalDays > 18 * 365)
                                             .Select(x => new
            {
                Name     = string.Format("{0} {1}", x.Firstname, x.Lastname),
                Employee = service.GetEmployee(x.EmployeeId)
            });
            var nearBy = adults.Where(x => locationService.DistanceWithClass(location, x.Employee.Address) < 10.0)
                         .Select(x => x.Name)
                         .ToList();

            return(nearBy);
        }
Пример #12
0
        ///////////////////////////////////////////////////////////////////////
        /// Listing 6-10
        public List <string> PeopleEmployeedWithinLocation_Classes(int amount, LocationClass location)
        {
            List <string>          result = new List <string>();
            List <PersonDataClass> input  = service.GetPersonsInBatchClasses(amount);
            DateTime now = DateTime.Now;

            for (int i = 0; i < input.Count; ++i)
            {
                PersonDataClass item = input[i];
                if (now.Subtract(item.BirthDate).TotalDays > 18 * 365)
                {
                    var employee = service.GetEmployeeClass(item.EmployeeId);
                    if (locationService.DistanceWithClass(location, employee.Address) < 10.0)
                    {
                        string name = string.Format("{0} {1}", item.Firstname, item.Lastname);
                        result.Add(name);
                    }
                }
            }
            return(result);
        }
Пример #13
0
        public void LocationClassToLocationShouldMapCorrectly()
        {
            // Arrange
            var config = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile <ClassToDomainProfile>();
            });
            IMapper mapper = new Mapper(config);
            var     id     = Guid.NewGuid();

            var locationclass = new LocationClass();

            locationclass.Id = id;
            locationclass.G  = "Gate";
            locationclass.P  = "Position";
            locationclass.R  = "Row";
            locationclass.Ra = true;
            locationclass.Sc = "Source";
            locationclass.St = "Site";
            locationclass.T  = "Type";
            locationclass.W  = "warehouse";
            // Act
            var model = mapper.Map <Location>(locationclass);

            // Assert
            model.Should().NotBeNull();
            model.Id.Should().Be(id);
            model.Gate.Should().Be(locationclass.G);
            model.Position.Should().Be(locationclass.P);
            model.Row.Should().Be(locationclass.R);
            model.Site.Should().Be(locationclass.St);
            model.Source.Should().Be(locationclass.Sc);
            model.Type.Should().Be(locationclass.T);
            model.Warehouse.Should().Be(locationclass.W);
            model.IsRack.Should().Be(locationclass.Ra);
        }
Пример #14
0
 public ActionResult LocationEdit(LocationClass model)
 {
     return(View("LocationIndex"));
 }
Пример #15
0
        static void locationToDict()
        {
            for (int i = 0; i < AppData.offlineLocationList.Count; i++)
            {
                var allItemsDict = new NSMutableDictionary();
                NSMutableDictionary anyListDataDict = new NSMutableDictionary();
                LocationClass       location        = AppData.offlineLocationList[i];
                for (int j = 0; j < location.courses.Count; j++)
                {
                    CoursesClass        item         = location.courses[j];
                    NSMutableDictionary eachItemDict = new NSMutableDictionary();
                    eachItemDict.SetValueForKey((NSString)item.Uid,
                                                (NSString)"uid");
                    eachItemDict.SetValueForKey((NSString)item.CourseName,
                                                (NSString)"course_name");
                    eachItemDict.SetValueForKey((NSString)item.LocationID,
                                                (NSString)"location_id");
                    eachItemDict.SetValueForKey((NSString)item.LocationName,
                                                (NSString)"location_name");
                    eachItemDict.SetValueForKey((NSString)item.SurfaceType,
                                                (NSString)"surface_type");
                    eachItemDict.SetValueForKey((NSString)item.Distance.ToString(),
                                                (NSString)"distance");
                    eachItemDict.SetValueForKey((NSString)item.Units,
                                                (NSString)"units");
                    eachItemDict.SetValueForKey((NSString)item.ConversionFactor.ToString(),
                                                (NSString)"conversion_factor");
                    eachItemDict.SetValueForKey((NSString)item.HandicapBuffer,
                                                (NSString)"handicap_buffer");
                    eachItemDict.SetValueForKey((NSString)item.HandicapCutOff,
                                                (NSString)"handicap_cutoff");
                    eachItemDict.SetValueForKey((NSString)item.IsRelay.ToString(),
                                                (NSString)"is_relay");
                    eachItemDict.SetValueForKey((NSString)item.RelayIDs.ToString(),
                                                (NSString)"relay_id");
                    eachItemDict.SetValueForKey((NSString)item.MinAge.ToString(),
                                                (NSString)"min_age");
                    eachItemDict.SetValueForKey((NSString)item.TrophyAwards.ToString(),
                                                (NSString)"trophy_awards");
                    eachItemDict.SetValueForKey((NSString)item.TrophyID.ToString(),
                                                (NSString)"trophy_id");
                    eachItemDict.SetValueForKey((NSString)item.NumberOfLegs.ToString(),
                                                (NSString)"num_legs");

                    allItemsDict.SetValueForKey(eachItemDict,
                                                (NSString)(item.CourseName));
                }



                object[] locationKeys   = { "location_id", "location_name", "location_X", "location_Y" };
                object[] locationValues = { location.locationID, location.locationName, location.posX, location.posY };

                var locationDict = NSDictionary.FromObjectsAndKeys(locationValues, locationKeys);

                //anyListDataDict = new NSMutableDictionary();

                anyListDataDict.SetValueForKey(allItemsDict, (NSString)location.locationName);
                allItemsDict.SetValueForKey(locationDict, (NSString)"location_info");

                AppData.LocationNode.GetChild(location.locationName)
                .SetValue <NSDictionary>(anyListDataDict);
            }
        }
Пример #16
0
        public ActionResult getSupplierLocation(string search)
        {
            LocationClass supplier = new LocationClass();
            SearchClass   current  = JsonConvert.DeserializeObject <SearchClass>(search);


            //Insert record

            OdbcConnection OdbcConn =
                new OdbcConnection("Dsn=VHHAL202;uid=HACKT03;pwd=gfZhA7dQ");

            OdbcCommand myCommand = new OdbcCommand();

            myCommand.Connection = OdbcConn;
            OdbcConn.Open();

            string sqlGetUser = "******"HACKT03\".\"USERS\" where NAME = '" + current.name + "'";

            myCommand.CommandText = sqlGetUser;
            string id     = "";
            var    reader = myCommand.ExecuteReader();

            if (reader.Read())
            {
                //we hvae an existing record
                id = reader["userid"].ToString();
                reader.Close();
            }
            else
            {
                reader.Close();
                //Insert user
                string sqlInsert = $"insert into \"HACKT03\".\"USERS\" values(id_seq.NEXTVAL, '{current.name}', '', NEW ST_Point('Point ({current.location.x} {current.location.y})', 4326))";
                myCommand.CommandText = sqlInsert;
                myCommand.ExecuteNonQuery();

                sqlGetUser            = "******"HACKT03\".\"USERS\" where NAME = '" + current.name + "'";
                myCommand.CommandText = sqlGetUser;
                reader = myCommand.ExecuteReader();
                if (reader.Read())
                {
                    //we hvae an existing record
                    id = reader["userid"].ToString();
                }
                reader.Close();
            }

            foreach (var item in current.items)
            {
                myCommand.CommandText = $"INSERT INTO \"HACKT03\".\"TRANSACTIONS\" VALUES(id_seq_trans.NEXTVAL, {id}, 'DROP' , '{item.productType}', {item.amount}, 'Finished', '')";
                myCommand.ExecuteNonQuery();
            }


            string sql = "SELECT TOP 1 * FROM (select A.NAME AS \"USERNAME\",B.ID AS \"FACILITYID\", B.NAME AS \"FACILITYNAME\" , B.LOCATION.ST_X() AS \"LON\", B.LOCATION.ST_Y() AS \"LAT\", A.LOCATION.ST_Distance(B.LOCATION, 'meter') AS \"DISTANCE\" from \"HACKT03\".\"USERS\" A, \"HACKT03\".\"FACILITIES\" B  where A.NAME = '" + current.name + "') TEMP ORDER BY DISTANCE";

            myCommand.CommandText = sql;
            OdbcDataReader myReader = myCommand.ExecuteReader();

            try
            {
                //Get Neerest Center
                while (myReader.Read())
                {
                    supplier.x        = double.Parse(myReader["LON"].ToString());
                    supplier.y        = double.Parse(myReader["LAT"].ToString());
                    supplier.name     = myReader["FACILITYNAME"]?.ToString();
                    supplier.distance = Math.Round(0.000621371 * double.Parse(myReader["DISTANCE"].ToString()), 2);
                }
            }
            finally
            {
                myReader.Close();
                OdbcConn.Close();
            }

            //Return it
            //            supplier.x = -95.4805;
            //			supplier.y = 29;
            var data = Content(JsonConvert.SerializeObject(supplier), "application/json", System.Text.Encoding.UTF8);

            return(data);
        }
 internal double DistanceWithClass(LocationClass location, string address)
 {
     return(1.0);
 }
Пример #18
0
        // LOGIC
        private static async void MenuLogic(Telegram.Bot.Types.Message message)
        {
            if (!dictionary.ContainsKey(message.Chat.Id))
            {
                dictionary[message.Chat.Id] = 0;
            }

            switch (message.Text.Split(' ').First())
            {
            // send inline keyboard
            case "Меню":
                dictionary[message.Chat.Id] = 0;
                ShowMenuMain(message);
                break;

            case "/admin":
                if (message.Chat.Username == "PotatOS")
                {
                    await Bot.SendTextMessageAsync(message.Chat.Id, "Hello, senpai ^_^");

                    dictionary[message.Chat.Id] = 80;
                }
                else
                {
                    Console.WriteLine("baka");
                }
                break;

            default:
                break;
            }

            if (dictionary[message.Chat.Id] >= 0 && dictionary[message.Chat.Id] < 3)
            {
                switch (message.Text)
                {
                case "Графити":
                    dictionary[message.Chat.Id] = 1;
                    ShowMenuBuy(message);
                    break;

                case "Район 1":
                    dictionary[message.Chat.Id] = 2;
                    string[] graphits = new string[] { "1", "2", "3", "4", "5", "0" };

                    ShowMenugraphits(message, graphits);

                    break;

                case "Обратная связь":
                    ShowTBA(message);
                    break;

                default:
                    break;
                }
            }

            if (dictionary[message.Chat.Id] >= 80 && dictionary[message.Chat.Id] < 500)
            {
                switch (message.Text)
                {
                case "/admin":
                    dictionary[message.Chat.Id] = 80;
                    ShowMenuAdmin(message);
                    break;

                case "Добавить графити":
                    ShowAdminAddProd(message);
                    dictionary[message.Chat.Id] = 81;
                    adminprod = new GraphityClass();
                    break;

                case "Удалить графити":
                    ShowAdminDelProd(message);
                    dictionary[message.Chat.Id] = 91;
                    break;

                case "Добавить район":
                    ShowAdminAddRegion(message);
                    dictionary[message.Chat.Id] = 101;
                    break;

                case "Удалить район":
                    ShowAdminDelRegion(message);
                    dictionary[message.Chat.Id] = 111;
                    break;

                case "Статистика":
                    ShowTBA(message);
                    break;

                case "Закрыть бота":
                    ShowTBA(message);
                    break;

                case "Открыть бота":
                    ShowTBA(message);
                    break;

                default:
                    break;
                }

                if (dictionary[message.Chat.Id] > 80 && dictionary[message.Chat.Id] < 500)
                {
                    string answer  = "";
                    int    localid = dictionary[message.Chat.Id];

                    switch (localid)
                    {
                    case 81:
                        answer = "[Название]: ";
                        dictionary[message.Chat.Id] += 1;
                        break;

                    case 82:
                        adminprod.title              = message.Text;
                        adminlocation                = new LocationClass();
                        answer                       = "[Размер]: ";
                        dictionary[message.Chat.Id] += 1;
                        break;

                    case 83:
                        adminprod.size = Convert.ToInt32(message.Text);
                        answer         = "[Широта]: ";
                        dictionary[message.Chat.Id] += 1;
                        break;

                    case 84:
                        adminlocation.latitude = float.Parse(message.Text, CultureInfo.InvariantCulture.NumberFormat);
                        answer = "[Долгота]: ";
                        dictionary[message.Chat.Id] += 1;
                        break;

                    case 85:
                        adminlocation.longitude = float.Parse(message.Text, CultureInfo.InvariantCulture.NumberFormat);
                        answer = "[Радиус]: ";
                        dictionary[message.Chat.Id] += 1;
                        break;

                    case 86:
                        adminlocation.radius = float.Parse(message.Text, CultureInfo.InvariantCulture.NumberFormat);
                        answer = "[Район]: ";
                        ShowTBA(message);
                        dictionary[message.Chat.Id] += 1;
                        break;

                    case 87:
                        adminprod.region     = Convert.ToInt32(message.Text);
                        adminlocation.author = 1;
                        answer  = JsonConvert.SerializeObject(adminlocation);
                        answer += JsonConvert.SerializeObject(adminprod);
                        answer += "Всё верно?";
                        ShowFinishDialog(message);
                        dictionary[message.Chat.Id] += 1;
                        break;

                    case 88:
                        if (message.Text == "Да")
                        {
                            // To-Do
                            ShowMenuAdmin(message);
                        }

                        else if (message.Text == "Нет")
                        {
                            adminlocation = new LocationClass();
                            adminprod     = new GraphityClass();
                            answer        = "Отменено";
                        }
                        else
                        {
                            answer  = JsonConvert.SerializeObject(adminlocation);
                            answer += JsonConvert.SerializeObject(adminprod);
                            answer += "Всё верно?";
                            ShowFinishDialog(message);
                        }
                        break;

                    default:
                        break;
                    }

                    if (dictionary[message.Chat.Id] == 191)
                    {
                    }
                    await Bot.SendTextMessageAsync(message.Chat.Id, answer);
                }
            }

            switch (message.Text.Split(' ').First())
            {
            case "111":
                await Bot.SendChatActionAsync(message.Chat.Id, ChatAction.Typing);

                await Task.Delay(500);     // simulate longer running task

                var inlineKeyboard = new InlineKeyboardMarkup(new[]
                {
                    new []     // first row
                    {
                        InlineKeyboardButton.WithCallbackData("1.1"),
                        InlineKeyboardButton.WithCallbackData("1.2"),
                    },
                    new []     // second row
                    {
                        InlineKeyboardButton.WithCallbackData("Купить"),
                    }
                });

                await Bot.SendTextMessageAsync(
                    message.Chat.Id,
                    "Choose",
                    replyMarkup : inlineKeyboard);

                break;


            // send a photo
            case "/photo":
                //await Bot.SendChatActionAsync(message.Chat.Id, ChatAction.UploadPhoto);

                const string file = @"Files/tux.jpg";

                var fileName = file.Split(Path.DirectorySeparatorChar).Last();

                using (var fileStream = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    await Bot.SendPhotoAsync(
                        message.Chat.Id,
                        fileStream,
                        "Nice Picture");
                }
                break;

            // request location or contact
            case "/request":
                var RequestReplyKeyboard1 = new ReplyKeyboardMarkup(new[]
                {
                    KeyboardButton.WithRequestLocation("Location"),
                    KeyboardButton.WithRequestContact("Contact"),
                });

                await Bot.SendTextMessageAsync(
                    message.Chat.Id,
                    "Who or Where are you?",
                    replyMarkup : RequestReplyKeyboard1);

                break;

            default:
                break;
            }
        }