private async void blockButton_Clicked(object sender, EventArgs e) { StartLoading(); var stuff = new StuffModel(); stuff.MobileDevicKey = MobileStaticVariables.UserInfo.MobileDeviceKey; stuff.ColegueList.Add(_colegue); var cancellationTokenSource = new CancellationTokenSource(); await Task.Factory.StartNew(x => { try { string registration = ""; registration = MobileStaticVariables.WebUtils.SendAuthRequest("BlockManager", stuff); Logger.WriteLine("BlockManager : " + registration); if (registration == "") { throw new Exception("Получена пустая строка"); } stuff.ParseJson(registration); if (stuff.ResultState == RequestResult.Results.Success) { Device.BeginInvokeOnMainThread(async() => { await DisplayAlert("Ура", "Оператор заблокирован", "Продолжить"); EndLoading(); await Navigation.PopToRootAsync(); }); } else { Device.BeginInvokeOnMainThread(async() => { await DisplayAlert("Внимание", stuff.TranslateResult(stuff.ResultState), "Продолжить"); EndLoading(); }); } } catch (Exception ex) { Logger.WriteError(ex); Device.BeginInvokeOnMainThread(async() => { EndLoading(); await DisplayAlert("Внимание", "Не удается соедениться с сервером", "Повторить"); }); } }, TaskCreationOptions.AttachedToParent, cancellationTokenSource.Token); }
private async void continueButton_Clicked(object sender, EventArgs e) { string login = (Regex.IsMatch(loginEntry.Text, emailRegex)) ? loginEntry.Text : ""; string name = nameEntry.Text.Trim(); string position = positionEntry.Text.Trim(); string Shop = selectShopButton.Text; if (name != "") { if (login != "") { if ((Shop != "Магазин не выбран" && MobileStaticVariables.UserInfo.ShopList.Count != 1) || MobileStaticVariables.UserInfo.ShopList.Count == 1) { if (_colegue == null) { _colegue = new Colegue(); } _colegue.Email = login; _colegue.Name = name; _colegue.Position = position; if (MobileStaticVariables.UserInfo.ShopList.Count == 1) { _colegue.ShopKey = MobileStaticVariables.UserInfo.ShopList.FirstOrDefault().ShopKey; } else { if (dictTO.TryGetValue(Shop, out int shopKey)) { _colegue.ShopKey = shopKey; } } var stuff = new StuffModel(); stuff.MobileDevicKey = MobileStaticVariables.UserInfo.MobileDeviceKey; stuff.ColegueList.Clear(); stuff.ColegueList.Add(_colegue); var cancellationTokenSource = new CancellationTokenSource(); try { StartLoading(); await Task.Factory.StartNew(x => { try { string registration = ""; registration = MobileStaticVariables.WebUtils.SendAuthRequest("RegManager", stuff); Logger.WriteLine("registration : " + registration); if (registration == "") { throw new Exception("Получена пустая строка"); } stuff.ParseJson(registration); if (stuff.ResultState == RequestResult.Results.Success) { Device.BeginInvokeOnMainThread(async() => { await DisplayAlert("Ура", "Добавление прошло успешно", "Продолжить"); EndLoading(); await Navigation.PopToRootAsync(); }); } else { Device.BeginInvokeOnMainThread(async() => { await DisplayAlert("Внимание", stuff.TranslateResult(stuff.ResultState), "Продолжить"); EndLoading(); }); } } catch (Exception ex) { Logger.WriteError(ex); Device.BeginInvokeOnMainThread(async() => { EndLoading(); await DisplayAlert("Внимание", "Не удается соедениться с сервером", "Повторить"); }); } }, TaskCreationOptions.AttachedToParent, cancellationTokenSource.Token); } catch (Exception ex) { Logger.WriteError(ex); } } else { await DisplayAlert("Внимание", "Введите магазин, в котором будет работать Ваш будущий коллега", "Хорошо"); positionEntry.Focus(); } } else { await DisplayAlert("Внимание", "Введите почту, чтобы мы могли связаться с Вашим будущим колегой", "Хорошо"); loginEntry.Focus(); } } else { await DisplayAlert("Внимание", "Введите имя Вашего будущего коллеги", "Хорошо"); nameEntry.Focus(); } }
private void LoadStuff() { try { string crewInfo = ""; StuffModel crew = new StuffModel(); crew.MobileDevicKey = MobileStaticVariables.UserInfo.MobileDeviceKey; crewInfo = MobileStaticVariables.WebUtils.SendAuthRequest("GetMyCrew", crew); Logger.WriteLine("crewInfo : " + crewInfo); if (crewInfo == "") { throw new Exception("crewInfo не получены"); } crew = JsonConvert.DeserializeObject <StuffModel>(crewInfo); if (crew.ResultState == RequestResult.Results.Success) { StuffList.Clear(); MobileStaticVariables.UserInfo.Stuff = crew.ColegueList; MobileStaticVariables.UserInfo.SaveSetting((int)SettingsEnum.Stuff, JsonConvert.SerializeObject(MobileStaticVariables.UserInfo.Stuff)); if (crew.ColegueList.Count == 0) { Device.BeginInvokeOnMainThread(() => { listView.IsVisible = false; EndLoading(); emptyFrame.IsVisible = true; }); } { foreach (var item in crew.ColegueList) { var view = new CollegueModel(); view.Name = item.Name; view.Shop = item.ShopName; if (item.Position.Length == 0) { view.Posision = "(нет применчаний)"; } else { view.Posision = "(" + item.Position + ")"; } view.Data = item; if (item.UserState == UserStates.Blocked) { view.Name += " (заблокирован)"; } StuffList.Add(view); } Device.BeginInvokeOnMainThread(() => { listView.ItemsSource = StuffList; EndLoading(); }); } } else { Device.BeginInvokeOnMainThread(async() => { if (IsVisible) { await DisplayAlert("Внимание", crew.TranslateResult(crew.ResultState), "Хорошо"); EndLoading(); } }); } } catch (Exception ex) { Logger.WriteError(ex); Device.BeginInvokeOnMainThread(() => { EndLoading(); noConnectionLayout.IsVisible = true; Device.StartTimer(new TimeSpan(0, 0, 1), WaitInternetConnection); }); } finally { Device.BeginInvokeOnMainThread(() => { EndLoading(); }); } }