Advertisement
isotonicq

nice

Jan 7th, 2017
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.17 KB | None | 0 0
  1.  
  2.             scannerQuiz.OnScanResult += (result) =>
  3.             {
  4.                 scannerQuiz.IsScanning = false;
  5.  
  6.                 if (CrossConnectivity.Current.IsConnected)
  7.                 {
  8.                     Device.BeginInvokeOnMainThread(async () =>
  9.                     {
  10.                         try
  11.                         {
  12.                             int code = Convert.ToInt32(result.Text);
  13.  
  14.                             if (code > 99 && code < 106)
  15.                             {
  16.                                 var response = await Json_Responses.JSONdownloader.downloader($"{Host.ip}use/{Host.username}/{result.Text}?format=json");
  17.                                 var permision = JsonConvert.DeserializeObject<JSONpermission>(response.ToString());
  18.  
  19.                                 if (permision.can == true)
  20.                                 {
  21.                                    var modalPage = new QuizDialog(Convert.ToInt32(result.Text));
  22.                                    await Navigation.PushModalAsync(modalPage);
  23.                                    await Navigation.PopAsync();
  24.                                    scannerQuiz.IsScanning = true;
  25.                                 }
  26.                                 else
  27.                                 {
  28.                                     await DisplayAlert("Błąd", "Kod już został wcześniej użyty", "ok");
  29.                                     await Navigation.PopAsync();
  30.                                     scannerQuiz.IsScanning = true;
  31.                                 }
  32.                             }
  33.                             else if (code > 299 && code < 400)
  34.                             {
  35.                                 await DisplayAlert("Informacje", "Aby odczytać ten kod przejdź do kategorii informacje", "ok");
  36.                                 await Navigation.PopAsync();
  37.                                 scannerQuiz.IsScanning = true;
  38.                             }
  39.                             else if (code > 199 && code < 300)
  40.                             {
  41.                                 await DisplayAlert("Informacje", "Aby odczytać ten kod przejdź do kategorii punkty", "ok");
  42.                                 await Navigation.PopAsync();
  43.                                 scannerQuiz.IsScanning = true;
  44.                             }
  45.                             else
  46.                                 throw new Exception();
  47.                         }
  48.                         catch
  49.                         {
  50.                             await DisplayAlert("Błąd", "Zeskanowano kod o złym formacie lub kategorii", "ok");
  51.                             await Navigation.PopAsync();
  52.                             scannerQuiz.IsScanning = true;
  53.                         }
  54.  
  55.                     });
  56.                 }
  57.                 else
  58.                 {
  59.                     Device.BeginInvokeOnMainThread(async () =>
  60.                     {
  61.                         await DisplayAlert("Błąd", "Proszę sprawdzić łącze internetowe", "ok");
  62.                         await Navigation.PopAsync();
  63.                         scannerQuiz.IsScanning = true;
  64.                     });      
  65.                 }
  66.             };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement