コード例 #1
0
        public async void InputPinMethod(string value)
        {
            WarningText    = "";
            WarningVisible = false;
            if (value == "Delete")
            {
                if (pin.Length > 0)
                {
                    pin = pin.Remove(pin.Length - 1);
                    int countPin = pin.Length;
                    HintColorChange(countPin);
                }
            }
            else
            {
                bool isExistvalue = Unities.CheckDigitaAndLength(value, 1);
                if (!isExistvalue)
                {
                    WarningText    = "ค่าที่ใส่ไม่ใช่ตัวเลข";
                    WarningVisible = true;
                    try
                    {
                        Vibration.Vibrate();
                        var duration = TimeSpan.FromSeconds(1);
                        Vibration.Vibrate(duration);
                    }
                    catch (FeatureNotSupportedException ex)
                    {
                    }
                    catch (Exception ex)
                    {
                    }
                }
                pin += value;
                int countPin = pin.Length;
                HintColorChange(countPin);
                if (countPin == 6)
                {
                    if (oldPin != "" && newPin != "")
                    {
                        repeatNewPin = pin;
                        if (newPin == repeatNewPin)
                        {
                            var updateData = await _pinService.UpdatePin(newPin, oldPin, email);

                            if (updateData != null && !updateData.IsError)
                            {
                                await PopupNavigation.Instance.PushAsync(new ChangePasswordSuccess());

                                await Application.Current.MainPage.Navigation.PopAsync();
                            }
                        }
                        else
                        {
                            pin      = "";
                            countPin = pin.Length;
                            HintColorChange(countPin);
                            WarningText    = "รหัสผ่านทั้ง 2 ครั้งไม่ตรงกัน";
                            WarningVisible = true;
                            try
                            {
                                Vibration.Vibrate();
                                var duration = TimeSpan.FromSeconds(1);
                                Vibration.Vibrate(duration);
                            }
                            catch (FeatureNotSupportedException ex)
                            {
                            }
                            catch (Exception ex)
                            {
                            }
                        }
                    }
                    else if (oldPin != "")
                    {
                        ChangeDataRepeatNewPin();
                    }
                    else
                    {
                        var loginPinData = await _pinService.LoginByPin(pin, email);

                        if (loginPinData != null && !loginPinData.IsError && loginPinData.Model != null)
                        {
                            if (loginPinData.Model.IsLogin)
                            {
                                await SecureStorage.SetAsync("CountLogin", "0");

                                ChangeDataNewPin();
                            }
                            else
                            {
                                pin      = "";
                                countPin = pin.Length;
                                HintColorChange(countPin);
                                WarningText    = "รหัสผ่านไม่ถูกต้อง";
                                WarningVisible = true;
                                try
                                {
                                    Vibration.Vibrate();
                                    var duration = TimeSpan.FromSeconds(1);
                                    Vibration.Vibrate(duration);
                                }
                                catch (FeatureNotSupportedException ex)
                                {
                                }
                                catch (Exception ex)
                                {
                                }
                                countLogin++;
                                await SecureStorage.SetAsync("CountLogin", countLogin.ToString());

                                if (countLogin >= 5)
                                {
                                    ForceLogout();
                                }
                            }
                        }
                        else
                        {
                            pin      = "";
                            countPin = pin.Length;
                            HintColorChange(countPin);
                            WarningText    = "ไม่สามารถเชื่อมต่อได้";
                            WarningVisible = true;
                            try
                            {
                                Vibration.Vibrate();
                                var duration = TimeSpan.FromSeconds(1);
                                Vibration.Vibrate(duration);
                            }
                            catch (FeatureNotSupportedException ex)
                            {
                            }
                            catch (Exception ex)
                            {
                            }
                        }
                    }
                }
                if (countPin > 6)
                {
                    pin = pin.Substring(0, 5);
                }
            }
        }