Exemple #1
0
        public async Task LoginByStore()
        {
            bool   isCheck      = false;
            bool   isEmail      = Helper.CheckEmailFormat(email);
            string messageEmail = "";

            if (!isEmail)
            {
                isCheck      = true;
                messageEmail = "Email ";
            }
            bool   isPassword      = Helper.CheckNonSpecialChar(password);
            string messagePassword = "";

            if (!isPassword)
            {
                isCheck         = true;
                messagePassword = "******";
            }
            if (isCheck)
            {
                ErrorViewModel errorViewModel = new ErrorViewModel(messageEmail + messagePassword + "ใส่ไม่ถูกต้อง", 1);
                await PopupNavigation.Instance.PushAsync(new Error(errorViewModel));
            }
            else
            {
                await PopupNavigation.Instance.PushAsync(new Views.Popup.LoadingPopup());

                var loginData = await _authService.Login(email, password);

                await PopupNavigation.Instance.PopAsync();

                if (loginData == null)
                {
                    ErrorViewModel errorViewModel = new ErrorViewModel("ไม่สามารถเข้าสู่ระบบได้", 1);
                    await PopupNavigation.Instance.PushAsync(new Error(errorViewModel));
                }
                else
                {
                    if (loginData.IsError != System.Net.HttpStatusCode.OK || loginData.Model == null)
                    {
                        ErrorViewModel errorViewModel = new ErrorViewModel("ไม่สามารถเข้าสู่ระบบได้", 1);
                        await PopupNavigation.Instance.PushAsync(new Error(errorViewModel));
                    }
                    else
                    {
                        await SecureStorage.SetAsync("RefreshToken", loginData.Model.RefreshToken);

                        await SecureStorage.SetAsync("Email", email);

                        await SecureStorage.SetAsync("AccountNumber", loginData.Model.EWalletAccNo);

                        App.AccountNumber = loginData.Model.EWalletAccNo;
                        App.Email         = email;
                        await SecureStorage.SetAsync("StoreName", loginData.Model.StoreName);

                        App.StoreName = loginData.Model.StoreName;
                        await Application.Current.MainPage.Navigation.PushAsync(new EnterPin());
                    }
                }
            }
        }
        public async void InputPinMethod(string value)
        {
            if (value == "Delete")
            {
                if (pin.Length > 0)
                {
                    pin = pin.Remove(pin.Length - 1);
                    int countPin = pin.Length;
                    HintColorChange(countPin);
                }
            }
            else
            {
                bool isExistvalue = Helper.CheckDigitaAndLength(value, 1);
                if (!isExistvalue)
                {
                    ErrorViewModel errorViewModel = new ErrorViewModel("ค่าที่ใส่ไม่ใช่ตัวเลข", 1);
                    await PopupNavigation.Instance.PushAsync(new Error(errorViewModel));
                }
                pin += value;
                int countPin = pin.Length;
                HintColorChange(countPin);
                if (countPin == 4)
                {
                    await PopupNavigation.Instance.PushAsync(new Views.Popup.LoadingPopup());

                    var refreshToken = await SecureStorage.GetAsync("RefreshToken");

                    var loginData = await _authService.LoginByPin(pin, refreshToken, App.Email);

                    await PopupNavigation.Instance.PopAsync();

                    if (loginData == null)
                    {
                        countLogout++;
                        ResetPin();
                        CheckCountLogin();
                        ErrorViewModel errorViewModel = new ErrorViewModel("ไม่สามารถเข้าสู่ระบบได้", 1);
                        await PopupNavigation.Instance.PushAsync(new Error(errorViewModel));
                    }
                    else if (loginData.IsError != System.Net.HttpStatusCode.OK || loginData.Model == null)
                    {
                        countLogout++;
                        ResetPin();
                        CheckCountLogin();
                        ErrorViewModel errorViewModel = new ErrorViewModel("ไม่สามารถเข้าสู่ระบบได้", 1);
                        await PopupNavigation.Instance.PushAsync(new Error(errorViewModel));
                    }
                    else
                    {
                        await SecureStorage.SetAsync("RefreshToken", loginData.Model.RefreshToken);

                        await SecureStorage.SetAsync("Token", loginData.Model.Token);

                        await SecureStorage.SetAsync("User", loginData.Model.User);

                        App.Email = await SecureStorage.GetAsync("Email");

                        App.StoreName = await SecureStorage.GetAsync("StoreName");

                        App.User   = loginData.Model.User;
                        App.UserId = loginData.Model.UserId;
                        //App.AccountNumber = loginData.Model.AccountNumber TODO:!!
                        int shiftId = loginData.Model.ShiftId;
                        if (shiftId > 0)
                        {
                            App.CheckShift  = true;
                            App.OpenShiftId = shiftId;
                        }
                        Application.Current.MainPage = new NavigationPage(new SaleView())
                        {
                            BackgroundColor = Color.White
                        };
                    }
                }
                if (countPin > 4)
                {
                    pin = pin.Substring(0, 3);
                }
            }
        }
        private async void CreateItem()
        {
            try
            {
                ResultViewModel result = new ResultViewModel {
                    IsError = true
                };
                if (IsUpdate)
                {
                    ItemModel item = new ItemModel()
                    {
                        Id             = UpdateItem.Id,
                        Name           = ItemName,
                        CategoryName   = SelectedCategory,
                        Price          = ConvertPrice(ItemPrice),
                        Cost           = ConvertPrice(ItemCost),
                        Color          = GetColor(),
                        Option1        = SetDefaultOption(),
                        Option1Price   = ConvertPrice(Price1),
                        Option2        = Option2,
                        Option2Price   = ConvertPrice(Price2),
                        Option3        = Option3,
                        Option3Price   = ConvertPrice(Price3),
                        Option4        = Option4,
                        Option4Price   = ConvertPrice(Price4),
                        CreateDateTime = UpdateItem.CreateDateTime,
                        UpdateDateTime = UpdateItem.UpdateDateTime,
                    };

                    result = await _productService.UpdateItem(item);
                }
                else
                {
                    if (String.IsNullOrEmpty(SelectedCategory) || SelectedCategory == "0")
                    {
                    }
                    else
                    {
                        ItemModel item = new ItemModel()
                        {
                            Name         = ItemName,
                            CategoryName = SelectedCategory,
                            Price        = ConvertPrice(ItemPrice),
                            Cost         = ConvertPrice(ItemCost),
                            Color        = GetColor(),
                            Option1      = Option1,
                            Option1Price = ConvertPrice(Price1),
                            Option2      = Option2,
                            Option2Price = ConvertPrice(Price2),
                            Option3      = Option3,
                            Option3Price = ConvertPrice(Price3),
                            Option4      = Option4,
                            Option4Price = ConvertPrice(Price4)
                        };
                        result = await _productService.CreateItem(item);
                    }
                }

                if (result != null && !result.IsError)
                {
                    ErrorViewModel errorViewModel = new ErrorViewModel("บันทึกรายการสำเร็จ", 3);
                    PopupNavigation.Instance.PushAsync(new Error(errorViewModel));
                    BackPageMethod();
                }
                else
                {
                    ErrorViewModel error = new ErrorViewModel("ผิดพลาด", 1);
                    PopupNavigation.Instance.PushAsync(new Error(error));
                }
            }
            catch (Exception)
            {
                throw;
            }
        }