async void OnfaviriteClicked(object sender, EventArgs args) { bool connect = await WebData.CheckConnection(); // проверка подключения if (connect == false) { return; } ToolbarItem item = (ToolbarItem)sender; FavoriteRoom room = Client.isRoomFavoit(Current); if (room == null) // добавление { FavoriteRoom newroom = await new FavRoomService().Add((Current.Clone() as Room).ToFavRoom(Client.CurrentClient.ClientId)); if (newroom != null) { DbService.AddFavoriteRoom(newroom); item.IconImageSource = "@drawable/stared.png"; } } else // удаление { bool deleted = await new FavRoomService().Delete(room.FavoriteRoomId); if (deleted) { DbService.RemoveFavoriteRoom(room); item.IconImageSource = "@drawable/unstared.png"; } } }
// Операции с заметкой public async void OnButtonSaveClicked(object sender, EventArgs args) { bool connect = await WebData.CheckConnection(); if (connect == false) { return; } ImageButton btn = (ImageButton)sender; if (btn.AutomationId == "0") { return; } Note note = Client.FindNoteById(Int32.Parse(btn.AutomationId)); if (note == null) { return; } Note send = (Note)note.Clone(); send.Room = null; foreach (var editor in ClientPage.Editors) { if (editor.AutomationId == btn.AutomationId) { send.Text = editor.Text; break; } } foreach (var date in ClientPage.Dates) { if (date.AutomationId == btn.AutomationId) { send.Date = DateTime.Now.ToString("dd/MM/yyyy"); date.Text = send.Date; break; } } Note getnote = await new NoteService().Update(send); if (getnote != null) // если обновлена на вервере { note.Text = send.Text; note.Date = send.Date; DbService.UpdateNote(note); DependencyService.Get <IToast>().Show("Текст заметки обновлен"); GetClientPage(); return; } DependencyService.Get <IToast>().Show("Не удалось сохранить заметку"); }
public async void OnButtonDeleteClicked(object sender, EventArgs args) { bool connect = await WebData.CheckConnection(); if (connect == false) { return; } ImageButton btn = (ImageButton)sender; if (btn.AutomationId == "0") { return; } Note note = Client.FindNoteById(Int32.Parse(btn.AutomationId)); if (note == null) { return; } Note getnote = await new NoteService().Delete(note.NoteId); if (getnote != null) // если удалена с сервера { DbService.RemoveNote(note); DependencyService.Get <IToast>().Show("Заметка о " + note?.RoomName + " удалена"); // что бы не происходил скролл в начало страницы, обновляю только контент List <Frame> v = ((StackLayout)((ScrollView)Content).Content).Children .Where(x => x is Frame) .Select(view => view as Frame) .Where(f => f.AutomationId != btn.AutomationId) .ToList(); StackLayout stackLayout = new StackLayout(); stackLayout.Margin = 20; stackLayout.Children.Add(ClientPage.NameLab); stackLayout.Children.Add(ClientPage.LoginLab); stackLayout.Children.Add(ClientPage.NoteCount); foreach (var frame in v) { stackLayout.Children.Add(frame); } stackLayout.Children.Add(ClientPage.LoginOutBtn); ((ScrollView)Content).Content = stackLayout; // GetClientPage(); return; } DependencyService.Get <IToast>().Show("Не удалось удалить заметку"); }
async void OnButtonSaveClicked(object sender, EventArgs args) { if (NoteText.Text == "") { DependencyService.Get <IToast>().Show("Ну и зачем так делать?"); return; } bool connect = await WebData.CheckConnection(); if (connect == false) { return; } // если загружено здание и есть установленное помещение, создаем связь с помещением if (BuildingData.CurrentBuilding != null) { if (BuildingData.CurrentBuilding.Name == SearchBarBuilding.Text && RoomData.isThatRoom(SearchBarRoom.Text) != null) { roomnote = RoomData.isThatRoom(SearchBarRoom.Text); } } NoteService noteService = new NoteService(); // посылаем заметку на сервер Note note = await noteService.Add(new Note(NoteText.Text, SearchBarRoom.Text, roomid : roomnote?.RoomId, building : SearchBarBuilding.Text, clientid : Client.CurrentClient.ClientId, clientname : Client.CurrentClient.Name)); if (note != null) // если сервер вернул данные по заметке - загрузить в пользователя { DbService.AddNote(note); await Navigation.PopAsync(); return; } else { await DisplayAlert("Ошибка", "Сервер не вернул данные", "OK"); return; } }
public async void LoginIn(object sender, EventArgs e) { if (LoginPage.LoginBox.Text == "" || LoginPage.PasswBox.Text == "") { DependencyService.Get <IToast>().Show("Введены не все поля"); return; } if (isLoading) { DependencyService.Get <IToast>().Show("Пользователь уже загружается"); return; } bool connect = await WebData.CheckConnection(); if (connect == false) { return; } isLoading = true; var client = await new ClientService().Authrization(LoginPage.LoginBox.Text, LoginPage.PasswBox.Text); if (client != null) // если сервер вернул данные пользователя - загрузить в пользователя { Client.setClient(Int32.Parse(client["Id"]), client["Name"], client["Login"]); DbService.SaveClient(Client.CurrentClient); // сохранили пользователя List <Note> clientnotes = await new NoteService().GetClient(Client.CurrentClient.ClientId); RemoveDuplicateNote(clientnotes); // если эта заметка уже загружена как публичная - удалить RemoveNonLoadedRoomId(clientnotes); // если заметка связаны с незагруженным помещением - отвязать DbService.AddNote(clientnotes); DbService.AddFavoriteRoom(await new FavRoomService().Get(Client.CurrentClient.ClientId)); isLoading = false; GetClientPage(); return; } else { await DisplayAlert("Ошибка", "Неверный логин или пароль", "OK"); isLoading = false; return; } }
public async void OnSwitched(object sender, EventArgs args) { Switch switcher = (Switch)sender; if (switcher.AutomationId == "0") { return; } bool connect = await WebData.CheckConnection(); if (connect == false) { return; } Note note = Client.FindNoteById(Int32.Parse(switcher.AutomationId)); if (note == null) { return; } Note send = (Note)note.Clone(); send.Room = null; send.isPublic = switcher.IsToggled; Note getnote = await new NoteService().Update(send); if (getnote != null) // если обновлена на вервере { note.isPublic = send.isPublic; DbService.UpdateNote(note); if (note.isPublic) { DependencyService.Get <IToast>().Show("Заметка стала публичной"); } else { DependencyService.Get <IToast>().Show("Заметка стала приватной"); } // GetClientPage(); return; } }
public async void RegistrClient(object sender, EventArgs e) { if (RegisrationPage.NameBox.Text == "" || RegisrationPage.LoginBox.Text == "" || RegisrationPage.PasswBox.Text == "" || RegisrationPage.PasswCheckBox.Text == "") { DependencyService.Get <IToast>().Show("Не все поля заполнены"); return; } if (RegisrationPage.PasswBox.Text != RegisrationPage.PasswCheckBox.Text) { DependencyService.Get <IToast>().Show("Пароли не совпадают"); return; } bool connect = await WebData.CheckConnection(); if (connect == false) { return; } ClientService clientService = new ClientService(); // отправка данных регистрации на сервер var client = await clientService. Register(RegisrationPage.NameBox.Text, RegisrationPage.LoginBox.Text, RegisrationPage.PasswBox.Text); // если сервер вернул данные пользователя - загрузить в пользователя if (client != null) { Client.setClient(Int32.Parse(client["Id"]), client["Name"], client["Login"]); DbService.SaveClient(Client.CurrentClient); // сохранили пользователя // DbService.LoadUser(); GetClientPage(); return; } else { await DisplayAlert("Ошибка", "Сервер не вернул данные", "OK"); return; } }
protected async override void OnAppearing() { base.OnAppearing(); if (BuildingData.CurrentBuilding != null) { BuildingTitle.Text = "Загруженое здание: " + BuildingData.CurrentBuilding.Name.ToString(); } bool connect = await WebData.CheckConnection(); if (connect == false) { return; } if ((DateTime.Now - lastRequest).TotalSeconds > 20) { lastRequest = DateTime.Now; DependencyService.Get <IToast>().Show("Обновление списка зданий"); BuildingDetailPage.BuildingLoad = true; BuildingView.ItemsSource = null; await LoadBuildingsAsync(); lastRequest = DateTime.Now; BuildingDetailPage.BuildingLoad = false; DependencyService.Get <IToast>().Show("Список обновлен"); } BuildingView.ItemsSource = BuildingData.Buildings; if (BuildingData.CurrentBuilding != null) { BuildingTitle.Text = "Загруженое здание: " + BuildingData.CurrentBuilding.Name.ToString(); } if (BuildingData.Buildings.Count == 0) { BuildingTitle.Text = "Нет доступных зданий"; } }
public static async Task <List <Building> > LoadBuildingsAsync() { bool connect = await WebData.CheckConnection(); if (connect == false) { return(null); } DbService.RemoveUncurrentBuildings(); BuildingData.Buildings = new List <Building>(); List <Building> buildings = await new BuildingService().GetBuildings(); DbService.AddBuilding(buildings.Where(b => b.BuildingId != BuildingData.CurrentBuilding?.BuildingId).ToList()); var currentloadedbuilding = buildings.Where(b => b.BuildingId == BuildingData.CurrentBuilding?.BuildingId).FirstOrDefault(); if (currentloadedbuilding != null) { BuildingData.CurrentBuilding.Name = currentloadedbuilding.Name; BuildingData.CurrentBuilding.Site = currentloadedbuilding.Site; BuildingData.CurrentBuilding.Addrees = currentloadedbuilding.Addrees; BuildingData.CurrentBuilding.TimeTable = currentloadedbuilding.TimeTable; BuildingData.CurrentBuilding.Description = currentloadedbuilding.Description; DbService.SaveDb(); } BuildingData.Buildings = DbService.LoadAllBuildings(); BuildingData.CurrentBuilding = BuildingData.Buildings .Where(b => b.BuildingId == currentloadedbuilding?.BuildingId) .FirstOrDefault(); return(BuildingData.Buildings); }
public async void Load() { BuildingLoad = true; bool connect = await WebData.CheckConnection(); if (connect == false) { return; } DependencyService.Get <IToast>().Show("Загрузка здания"); FloorData.Floors = new List <Floor>(); RoomData.Rooms = new List <Room>(); WorkerData.Workers = new List <Worker>(); PointData.Points = new List <PointM>(); PointData.RoomPoints = new List <PointM>(); PointData.CurrentFloorRoomPoints = new List <PointM>(); EdgeData.Edges = new List <EdgeM>(); EdgeData.Ways = new List <EdgeM>(); EdgeData.CurrentFloorWalls = new List <EdgeM>(); NoteData.Notes = new List <Note>(); List <Floor> floors = await new FloorService().GetFloors(Current.BuildingId); List <Room> rooms = await new RoomService().GetRooms(Current.BuildingId); List <Worker> workers = await new WorkerService().GetWorkers(Current.BuildingId); List <PointM> points = await new PointService().GetPoints(Current.BuildingId); List <EdgeM> edges = await new EdgeService().GetEdges(Current.BuildingId); List <Note> notes = await new NoteService().GetPublic(Current.BuildingId); List <Note> clientnotes = null; // получить все публичные заметки не текущего пользователя if (Client.CurrentClient?.ClientId != null) { notes = notes.Where(n => n.ClientId != Client.CurrentClient.ClientId).ToList(); clientnotes = await new NoteService().GetClient(Client.CurrentClient.ClientId); } foreach (var n in notes) { n.ClientId = null; } Authorization.RemoveNonLoadedRoomId(clientnotes, rooms); DbService.RemoveCurrentBuilding(); try { DbService.AddFloor(floors); DbService.AddRoom(rooms); DbService.AddWorker(workers); DbService.AddPoing(points); DbService.AddEdge(edges); DbService.SaveDb(); DbService.AddNote(notes); DbService.AddNote(clientnotes); } catch (System.Exception e) { if (e is Microsoft.EntityFrameworkCore.DbUpdateException || e is System.InvalidCastException) { // DbService.RemoveCurrentBuilding(); DependencyService.Get <IToast>().Show("Загруженые здания некорректны"); } BuildingLoad = false; return; } FloorData.Floors = DbService.LoadAllFloors(); RoomData.Rooms = DbService.LoadAllRooms(); WorkerData.Workers = DbService.LoadAllWorkers(); PointData.Points = DbService.LoadAllPoints(); EdgeData.Edges = DbService.LoadAllEdges(); NoteData.Notes = DbService.LoadAllNotes(); BuildingData.CurrentBuilding = Current; PointData.RoomPoints = PointData.Points .Where(p => p.IsWaypoint == true) .Where(c => c.Room != null).ToList(); DependencyService.Get <IToast>().Show("Здание загружено"); DownloadBut.Text = "Обновить"; BuildingLoad = false; BuildingPage.isUpdate = true; RoomGroup.UpdateList(); }