コード例 #1
0
 public PrinterTest()
 {
     InitializeComponent();
     try
     {
         AppVersionServices.GetAndroidStoreAppVersion();
     }
     catch (Exception ex)
     {
         string exmsg = ex.Message;
     }
 }
コード例 #2
0
        public async void UserLoginVerification()
        {
            User   resultObj     = null;
            string appversionmsg = string.Empty;

            ShowLoading(true);
            IsOnline = VerifyInternet();
            try
            {
                await Task.Run(() =>
                {
                    appversionmsg = AppVersionServices.GetAndroidStoreAppVersion();
                });

                if (appversionmsg == string.Empty || appversionmsg == "")
                {
                    if ((entryUserID.Text != null && entryUserID.Text.Length >= 4) && (entryPassword.Text != null && entryPassword.Text.Length >= 8))
                    {
                        if (DeviceInternet.InternetConnected())
                        {
                            await GetAPIToken();
                            await GetCurrentLocation();


                            if (App.Current.Properties.ContainsKey("apitoken"))
                            {
                                DALUserLogin objdalLogin  = new DALUserLogin();
                                UserLogin    objinputuser = new UserLogin();
                                objinputuser.UserName      = entryUserID.Text.Trim();
                                objinputuser.Password      = entryPassword.Text.Trim();
                                objinputuser.Latitude      = Latitude;
                                objinputuser.Longitude     = Longitude;
                                objinputuser.LoginDeviceID = GetDeviceUniqueID();
                                APIResponse objAPIResponse;
                                objAPIResponse = objdalLogin.LoginVerification(Convert.ToString(App.Current.Properties["apitoken"]), objinputuser);
                                if (objAPIResponse != null)
                                {
                                    if (objAPIResponse.Result)
                                    {
                                        resultObj = JsonConvert.DeserializeObject <User>(Convert.ToString(objAPIResponse.Object));
                                        App.Current.Properties["LoginUser"] = resultObj;
                                        resultObj.LoginDeviceID             = LoginDeviceID;
                                        MasterHomePage masterPage = null;
                                        DateTime       toDay      = DateTime.Parse(resultObj.LocationParkingLotID.LotCloseTime);
                                        // Load VehicleTypes in SQLLite
                                        await App.SQLiteDb.SaveAllVehicleTypesInSQLLite(Convert.ToString(App.Current.Properties["apitoken"]), resultObj.LocationParkingLotID.LocationID.LocationID);

                                        await App.SQLiteDb.SaveVehiclesParkingFeesDetailOnLogin(Convert.ToString(App.Current.Properties["apitoken"]), resultObj.LocationParkingLotID.LocationParkingLotID);

                                        await DisplayAlert("Alert", "Your Location and Lot details are:" + resultObj.LocationParkingLotID.LocationID.LocationName + "-" + resultObj.LocationParkingLotID.LocationParkingLotName, "Ok");

                                        if ((resultObj.UserTypeID.UserTypeName.ToUpper()) == ("Operator".ToUpper()))
                                        {
                                            if (DateTime.Now < toDay)
                                            {
                                                await Task.Run(() =>
                                                {
                                                    if (string.IsNullOrEmpty(cookieUserName) && string.IsNullOrEmpty(cookiePassword))
                                                    {
                                                        SaveUserLogin(Convert.ToString(App.Current.Properties["apitoken"]), resultObj);
                                                    }
                                                    SecureStorage.SetAsync("apitoken", Convert.ToString(App.Current.Properties["apitoken"]));
                                                    SecureStorage.SetAsync("UserName", entryUserID.Text.Trim());
                                                    SecureStorage.SetAsync("Password", entryPassword.Text.Trim());
                                                    masterPage = new MasterHomePage();
                                                });

                                                await Navigation.PushAsync(masterPage);
                                            }
                                            else
                                            {
                                                await DisplayAlert("Alert", "Please contact Admin,lot time (" + toDay + ") closed", "Cancel");

                                                ShowLoading(false);
                                            }
                                        }
                                        else
                                        {
                                            await Task.Run(() =>
                                            {
                                                if (string.IsNullOrEmpty(cookieUserName) && string.IsNullOrEmpty(cookiePassword))
                                                {
                                                    SaveUserLogin(Convert.ToString(App.Current.Properties["apitoken"]), resultObj);
                                                }
                                                SecureStorage.SetAsync("apitoken", Convert.ToString(App.Current.Properties["apitoken"]));
                                                SecureStorage.SetAsync("UserName", entryUserID.Text.Trim());
                                                SecureStorage.SetAsync("Password", entryPassword.Text.Trim());
                                                masterPage = new MasterHomePage();
                                            });

                                            await Navigation.PushAsync(masterPage);
                                        }
                                    }
                                    else
                                    {
                                        await DisplayAlert("Alert", objAPIResponse.Message, "Cancel");

                                        ShowLoading(false);
                                    }
                                }
                                else
                                {
                                    await DisplayAlert("Alert", "Invalid Credentials", "Cancel");

                                    ShowLoading(false);
                                }
                            }
                            else
                            {
                                await DisplayAlert("Alert", "Unable to connect API.Please contact Admin", "Ok");

                                ShowLoading(false);
                            }
                        }
                        else
                        {
                            await DisplayAlert("Alert", "Please check your Internet connection", "Ok");

                            ShowLoading(false);
                        }
                    }
                    else
                    {
                        await DisplayAlert("Alert", "Please enter Valid UserID and Password.", "Ok");

                        ShowLoading(false);
                    }
                    ShowLoading(false);
                }
                else
                {
                    await DisplayAlert("Alert", appversionmsg, "Ok");

                    ShowLoading(false);
                    Device.OpenUri(new Uri("https://play.google.com/store/apps/details?id=com.sprvtec.InstaOperator"));
                    DependencyService.Get <ILaunchActivity>().LaunchActivityInAndroid("com.sprvtec.InstaOperator");
                }
            }
            catch (Exception ex)
            {
                dal_Exceptionlog.InsertException(Convert.ToString(App.Current.Properties["apitoken"]), "Operator App", ex.Message, "LoginPage.xaml.cs", "", "BtnSignIn_Clicked");
                ShowLoading(false);
                await DisplayAlert("Alert", "Unable to connect API" + ex.Message, "Ok");
            }
        }