async void LoginButtonClicked(object sender, EventArgs args) { DatabaseGET conn = new DatabaseGET(); var personalInfo = await conn.getUserInfo(userType.Text, email.Text, password.Text); if (personalInfo.Count > 0) { if (userType.Text == "Resident") { CurrentUser.ID = Convert.ToInt32(personalInfo[0].residentID); CurrentUser.type = 'R'; LiveWell.Helpers.Settings.GeneralSettings = "" + CurrentUser.type + CurrentUser.ID; await Navigation.PushModalAsync(new MainOrSearchHouse()); } else if (userType.Text == "Employee") { CurrentUser.ID = Convert.ToInt32(personalInfo[0].employeeID); CurrentUser.type = 'E'; LiveWell.Helpers.Settings.GeneralSettings = "" + CurrentUser.type + CurrentUser.ID; await Navigation.PushModalAsync(new EmployeeMain()); } else if (userType.Text == "Owner") { CurrentUser.ID = Convert.ToInt32(personalInfo[0].ownerID); CurrentUser.type = 'O'; LiveWell.Helpers.Settings.GeneralSettings = "" + CurrentUser.type + CurrentUser.ID; await Navigation.PushModalAsync(new Owner()); } } else { errorMessage.Text = "Please type correct email address and password"; } }
async void populateList(int price, String accommodationType, int numRooms, int maxDistance) { List <Address> addresses; DatabaseGET conn = new DatabaseGET(); if (accommodationType == "ALL") { addresses = await conn.getAddress(); } else { addresses = await conn.getAddress(price, accommodationType, numRooms); } List <QuickViewAddress> address = new List <QuickViewAddress>(); MyMap.Pins.Clear(); for (int i = 0; i < addresses.Count; i++) { double accommodationLatitude = addresses[i].latitude; double accommodationLongitude = addresses[i].longitude; double distance = CalculateDistance(accommodationLatitude, accommodationLongitude, userPositionLatitude, userPositionLongitude); if (distance < maxDistance) { address.Add(new QuickViewAddress(addresses[i].address + ", Distance: " + distance)); addPins(addresses[i].address, addresses[i].accommodationType); await Task.Delay(100); } } quickview.ItemsSource = address; quickview.RowHeight = 30; title.Text = "Explore " + address.Count + " Accommodations"; }
async void populateList(int price, String accommodationType, int numRooms, int maxDistance) { List <Address> addresses; DatabaseGET conn = new DatabaseGET(); if (accommodationType == "ALL") { addresses = await conn.getAddress(); } else { addresses = await conn.getAddress(price, accommodationType, numRooms); } list = new List <QuickViewImage>(); for (int i = 0; i < addresses.Count; i++) { double accommodationLatitude = addresses[i].latitude; double accommodationLongitude = addresses[i].longitude; double distance = CalculateDistance(accommodationLatitude, accommodationLongitude, userPositionLatitude, userPositionLongitude); if (distance < maxDistance) { list.Add(new QuickViewImage(addresses[i].imageUrl, addresses[i].address, addresses[i].accommodationType, addresses[i].buildingID, addresses[i].price, addresses[i].numRooms)); } } quickview.ItemsSource = list; quickview.RowHeight = 400; title.Text = "Explore " + list.Count + " Accommodations"; }
async void populatePage() { Debug.WriteLine(listID); DatabaseGET conn = new DatabaseGET(); items = await conn.getProductsOnList(listID); productList = new List <Product>(); for (int i = 0; i < items.Count; i++) { productList.Add(new Product(items[i].imageUrl, items[i].itemName)); } MessagingCenter.Subscribe <AddProduct, List <ConnectHelpers.Item> >(this, "newList", (sender, refresh) => { productList = new List <Product>(); for (int i = 0; i < refresh.Count; i++) { productList.Add(new Product(refresh[i].imageUrl, refresh[i].itemName)); } products.ItemsSource = productList; }); products.ItemsSource = productList; products.RowHeight = 60; products.IsPullToRefreshEnabled = true; }
async void add(Object sender, EventArgs e) { DatabaseGET conn = new DatabaseGET(); List <Food> foods = await conn.getFoods(); var imageUrl = "https://firebasestorage.googleapis.com/v0/b/livewell-78cf1.appspot.com/o/question.jpg?alt=media&token=7ac00a49-b7a1-4ce1-b447-31eba31406ea"; for (int i = 0; i < foods.Count; i++) { if (foods[i].name.Equals(item.Text.ToLower())) { imageUrl = foods[i].imageUrl; } } DatabasePOST conn2 = new DatabasePOST(); if (newList == 0) { Debug.WriteLine(listID + " " + item.Text + " " + imageUrl); await conn2.postItem(listID, item.Text, imageUrl); //MessagingCenter.Send(this, "newList", await conn.getLists(1)); await Navigation.PushModalAsync(new ListDetails(listID, name, user)); } else { Debug.WriteLine(listID + " " + item.Text + " " + imageUrl); await conn2.postItem(listID, item.Text, imageUrl); //MessagingCenter.Send(this, "newList", await conn.getLists(1)); await Navigation.PopModalAsync(); } }
async void populateSuggestions() { DatabaseGET conn = new DatabaseGET(); List <ConnectHelpers.Item> suggestions = await conn.getSuggestions(CurrentUser.ID); items = new List <Item>(); for (int i = 0; i < suggestions.Count; i++) { items.Add(new Item(suggestions[i].itemName)); } suggestedItems.ItemsSource = items; }
async void fine(Object o, EventArgs e) { DatabaseGET conn2 = new DatabaseGET(); List <ConnectHelpers.EmployeeInfo> employee = await conn2.getEmployeeInfo(Convert.ToInt32(CurrentUser.ID)); String[] types = { "Noise violation", "Late rent", "Stolen/damaged property", "Other" }; DatabasePOST conn = new DatabasePOST(); await conn.postFine(employee[0].buildingID, types[type.SelectedIndex], unit.Text, amount.Text); await DisplayAlert("Success", "Fine issued", "OK"); unit.Text = ""; amount.Text = ""; }
async void getFirstName() { DatabaseGET conn = new DatabaseGET(); Debug.WriteLine(CurrentUser.ID); List <ResidentInfo> info = await conn.getResidentInfo(CurrentUser.ID); for (int i = 0; i < info.Count; i++) { if (Convert.ToInt32(info[i].residentID) == CurrentUser.ID) { title.Text = "Hi, " + info[i].firstName + "!"; } } }
async void populateList() { DatabaseGET conn = new DatabaseGET(); employee = await conn.getEmployeeInfo(CurrentUser.ID); requests = await conn.getMaintenance(employee[0].buildingID); List <Request> allRequests = new List <Request>(); for (int i = 0; i < requests.Count; i++) { allRequests.Add(new Request(requests[i].summary, requests[i].number)); } requestList.ItemsSource = allRequests; }
async void boughtClick(object sender, EventArgs e) { if (bought.Text.Equals("")) { await DisplayAlert("Error", "Please specify amount you bought for", "Okay"); } else { //gets residents on the list //adds split balance to amount of roommate who clicks button //adds notification for user letting them know list is bought //deleted list from database, keeps items for suggestion purposes DatabaseGET conn = new DatabaseGET(); List <ListInformation> list = await conn.getLists(listID); List <String> roommateIDs = new List <string>(); if (list[0].residentID1 != null && !list[0].residentID1.Equals(CurrentUser.ID + "")) { roommateIDs.Add(list[0].residentID1); } if (list[0].residentID2 != null && !list[0].residentID2.Equals(CurrentUser.ID + "")) { roommateIDs.Add(list[0].residentID2); } if (list[0].residentID3 != null && !list[0].residentID3.Equals(CurrentUser.ID + "")) { roommateIDs.Add(list[0].residentID3); } if (list[0].residentID4 != null && !list[0].residentID4.Equals(CurrentUser.ID + "")) { roommateIDs.Add(list[0].residentID4); } String purchaseAmount = (Convert.ToDouble(amount.Text) / (roommateIDs.Count + 1)).ToString(); DatabasePOST conn2 = new DatabasePOST(); await conn2.chargeAllAndNotify(purchaseAmount, CurrentUser.ID + "", roommateIDs, listID, listName.Text); //NotificationHandler notifications = new NotificationHandler(); //notifications.send(amount, "1", roommateIDs, listID, listName.Text); await DisplayAlert("Success", "Purchase recorded and roommate(s) notified", "OK"); await Navigation.PushModalAsync(new Resident()); } }
async void populateList() { List <Address> addresses; DatabaseGET conn = new DatabaseGET(); addresses = await conn.getFavorite(); list = new List <QuickViewImage>(); quickview.ItemsSource = list; for (int i = 0; i < addresses.Count; i++) { list.Add(new QuickViewImage(addresses[i].imageUrl, addresses[i].address, addresses[i].accommodationType, addresses[i].buildingID, addresses[i].price, addresses[i].numRooms)); System.Diagnostics.Debug.WriteLine(addresses[i].buildingID); } quickview.ItemsSource = list; quickview.RowHeight = 400; title.Text = "Favorite " + addresses.Count + " Accommodations"; }
async void populateList() { DatabaseGET conn = new DatabaseGET(); List <ConnectHelpers.NotificationHandler> notifications = await conn.getNotifications(CurrentUser.type, CurrentUser.ID); List <QuickViewNotif> all = new List <QuickViewNotif>(); for (int i = notifications.Count - 1; i >= 0; i--) { if (notifications[i].type.Equals("maintenance")) { all.Add(new QuickViewNotif("Maintenance request for " + notifications[i].description, "Maintenance request")); } if (notifications[i].type.Equals("updateEmployee")) { all.Add(new QuickViewNotif(notifications[i].description, "Update")); } } quickview.ItemsSource = all; quickview.RowHeight = 60; }
async void populateLists() { DatabaseGET conn = new DatabaseGET(); lists = await conn.getLists(CurrentUser.ID); //List which will come from database with all the list items and information list = new List <ListInfo>(); List <int> added = new List <int>(); for (int i = 0; i < lists.Count; i++) { if (lists[i].residentID1 != null && lists[i].residentID2 != null && lists[i].residentID3 != null && lists[i].residentID4 != null && !added.Contains(Convert.ToInt32(lists[i].listID))) { list.Add(new ListInfo(lists[i].listName, await conn.getName(lists[i].residentID1) + ", " + await conn.getName(lists[i].residentID2) + ", " + await conn.getName(lists[i].residentID3) + ", & " + await conn.getName(lists[i].residentID4), lists[i].listID)); added.Add(Convert.ToInt32(lists[i].listID)); } else if (lists[i].residentID1 != null && lists[i].residentID2 != null && lists[i].residentID3 != null && !added.Contains(Convert.ToInt32(lists[i].listID))) { list.Add(new ListInfo(lists[i].listName, await conn.getName(lists[i].residentID1) + ", " + await conn.getName(lists[i].residentID2) + ", & " + await conn.getName(lists[i].residentID3), lists[i].listID)); added.Add(Convert.ToInt32(lists[i].listID)); } else if (lists[i].residentID1 != null && lists[i].residentID2 != null && !added.Contains(Convert.ToInt32(lists[i].listID))) { list.Add(new ListInfo(lists[i].listName, await conn.getName(lists[i].residentID1) + " & " + await conn.getName(lists[i].residentID2), lists[i].listID)); added.Add(Convert.ToInt32(lists[i].listID)); } else if (!added.Contains(Convert.ToInt32(lists[i].listID))) { list.Add(new ListInfo(lists[i].listName, await conn.getName(lists[i].residentID1), lists[i].listID)); added.Add(Convert.ToInt32(lists[i].listID)); } } allLists.ItemsSource = list; allLists.RowHeight = 60; }
async void populatePage() { //Instantiates conenction object and calls method which gets notifications given a residentID DatabaseGET conn = new DatabaseGET(); List <balance> balances = await conn.getBalances(CurrentUser.ID); List <ConnectHelpers.NotificationHandler> notifications = await conn.getNotifications(CurrentUser.type, CurrentUser.ID); List <ResidentInfo> resident = await(conn.getResidentInfo(CurrentUser.ID)); String amount = (Convert.ToDouble(balances[0].amount1) + Convert.ToDouble(balances[0].amount2) + Convert.ToDouble(balances[0].amount3) + Convert.ToDouble(balances[0].amount4) + Convert.ToDouble(balances[0].bAmount)).ToString(); if (amount.Equals("0")) { balance.Text = "$0.00"; } else { balance.Text = "$" + amount; } //Sets text for room information at top of screen address.Text = resident[0].address; room.Text = resident[0].number; String roommates = ""; for (int i = 0; i < resident.Count; i++) { if (i == resident.Count - 2) { roommates += resident[i].firstName + " " + resident[i].lastName + ", & "; } else if (i == resident.Count - 1) { roommates += resident[i].firstName + " " + resident[i].lastName; } else { roommates += resident[i].firstName + " " + resident[i].lastName + ", "; } } residents.Text = roommates; //Creates list of notifications for use in UI List <QuickViewNotif> notifs = new List <QuickViewNotif>(); String first = ""; String last = ""; for (int i = notifications.Count - 1; i >= 0; i--) { if (notifications[i].type == "payRoom") { List <ResidentInfo> name = await conn.getResidentInfo(Convert.ToInt32(notifications[i].sender)); for (int j = 0; j < name.Count; j++) { if (name[j].residentID.Equals(notifications[i].sender)) { first = name[j].firstName; last = name[j].lastName; } } notifs.Add(new QuickViewNotif(first + " " + last + " paid $" + notifications[i].amount + " for '" + notifications[i].description + "'", "Roommate paid")); } if (notifications[i].type == "payBuilding") { notifs.Add(new QuickViewNotif("You paid $" + notifications[i].amount + " to owner", "Payment to building")); } if (notifications[i].type == "maintenanceScheduled") { notifs.Add(new QuickViewNotif(notifications[i].description, "Maintenance Scheduled")); } if (notifications[i].type == "fine") { notifs.Add(new QuickViewNotif("Your room was fined $" + notifications[i].amount + " for '" + notifications[i].description + "'.", "Fine")); } if (notifications[i].type == "update") { notifs.Add(new QuickViewNotif(notifications[i].description, "Update")); } if (notifications[i].type == "bought") { List <ResidentInfo> name = await conn.getResidentInfo(Convert.ToInt32(notifications[i].sender)); for (int j = 0; j < name.Count; j++) { if (name[j].residentID.Equals(notifications[i].sender)) { first = name[j].firstName; last = name[j].lastName; } } notifs.Add(new QuickViewNotif(first + " " + last + " bought '" + notifications[i].description + "' and you owe $" + notifications[i].amount, "Debt incurrence")); } } //Sets the source of the listview and the row height quickview.ItemsSource = notifs; quickview.RowHeight = 60; }
async void populateList() { //Instantiates conenction object and calls method which gets notifications given a residentID DatabaseGET conn = new DatabaseGET(); List <balance> balances = await conn.getBalances(CurrentUser.ID); List <ConnectHelpers.NotificationHandler> notifications = await conn.getPayments(CurrentUser.ID); String amount = (Convert.ToDouble(balances[0].amount1) + Convert.ToDouble(balances[0].amount2) + Convert.ToDouble(balances[0].amount3) + Convert.ToDouble(balances[0].amount4)).ToString(); if (amount.Equals("0")) { roomBill.Text = "$0.00"; } else { roomBill.Text = "$" + amount; } buildingBill.Text = "$" + balances[0].bAmount; //Payment history of the current user List <PayRecord> pay = new List <PayRecord>(); String first = ""; String last = ""; for (int i = notifications.Count - 1; i >= 0; i--) { if (notifications[i].type == "payRoom") { List <ResidentInfo> name = await conn.getResidentInfo(Convert.ToInt32(notifications[i].sender)); for (int j = 0; j < name.Count; j++) { if (name[j].residentID.Equals(notifications[i].sender)) { first = name[j].firstName; last = name[j].lastName; } } pay.Add(new PayRecord(first + " " + last + " paid $" + notifications[i].amount + " for '" + notifications[i].description + "'", "Roommate paid")); } if (notifications[i].type == "payBuilding") { pay.Add(new PayRecord("You paid $" + notifications[i].amount + " to owner", "Payment to building")); } if (notifications[i].type == "fine") { pay.Add(new PayRecord("Your room was fined $" + notifications[i].amount + " for '" + notifications[i].description + "'.", "Fine")); } if (notifications[i].type == "bought") { List <ResidentInfo> name = await conn.getResidentInfo(Convert.ToInt32(notifications[i].sender)); for (int j = 0; j < name.Count; j++) { if (name[j].residentID.Equals(notifications[i].sender)) { first = name[j].firstName; last = name[j].lastName; } } pay.Add(new PayRecord(first + " " + last + " bought '" + notifications[i].description + "' and you owe $" + notifications[i].amount + ".", "Debt incurrence")); } } //Sets listview to the payment list and sets row height payHistory.ItemsSource = pay; payHistory.RowHeight = 60; }