Exemple #1
0
        private bool IsFormValid()
        {
            DisplayName_TextBox_LostFocus(null, null);
            URI_ComboBox_LostFocus(null, null);

            return(TextBoxRegex.GetIsValid(DisplayName_TextBox) && TileSize_ComboBox.Text != "");
        }
        private void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
        {
            // make sure quantity is in correct format
            if (TextBoxRegex.GetIsValid(TextBoxQuantity) == false)
            {
                FlyoutWarmingText.Text = "Wrong numerical value!";
                FlyoutWarming.ShowAt(TextBoxQuantity);
                args.Cancel = true;
                return;
            }

            if (TextBoxRegex.GetIsValid(TextBoxCost) == false)
            {
                FlyoutWarmingText.Text = "Wrong numerical value!";
                FlyoutWarming.ShowAt(TextBoxCost);
                args.Cancel = true;
                return;
            }

            // perform real update
            TextBoxQuantity.GetBindingExpression(TextBox.TextProperty).UpdateSource();
            TextBoxCost.GetBindingExpression(TextBox.TextProperty).UpdateSource();
            DatePickerPurchaseDate.GetBindingExpression(DatePicker.DateProperty).UpdateSource();
            ComboBoxProvider.GetBindingExpression(ComboBox.SelectedValueProperty).UpdateSource();
        }
Exemple #3
0
        private bool IsFormValid()
        {
            DisplayName_TextBox_LostFocus(null, null);
            CustomUri_TextBox_LostFocus(null, null);

            return(TextBoxRegex.GetIsValid(DisplayName_TextBox) && TextBoxRegex.GetIsValid(CustomUri_TextBox));
        }
Exemple #4
0
 private void DisplayName_TextBox_LostFocus(object sender, RoutedEventArgs e)
 {
     if (!TextBoxRegex.GetIsValid(DisplayName_TextBox))
     {
         DisplayName_TextBox.BorderBrush = new SolidColorBrush(Colors.Red);
     }
     else
     {
         DisplayName_TextBox.ClearValue(BorderBrushProperty);
     }
 }
 private void TextBoxValidated_TextChanged(object sender, TextChangedEventArgs e)
 {
     if (TextBoxRegex.GetIsValid(TextBoxValidated))
     {
         IsValid = true;
     }
     else
     {
         IsValid = false;
     }
     if (_showValidation)
     {
         IsNotValidState = !IsValid;
     }
 }
Exemple #6
0
        // event handlers
        private void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
        {
            // make sure name and unit are not empty string
            if (string.IsNullOrWhiteSpace(TextBoxName.Text))
            {
                FlyoutWarmingText.Text = "Name cannot be empty!";
                FlyoutWarming.ShowAt(TextBoxName);
                args.Cancel = true;
                return;
            }
            if (ComboBoxCategory.SelectedIndex == -1)
            {
                FlyoutWarmingText.Text = "Category cannot be empty!";
                FlyoutWarming.ShowAt(ComboBoxCategory);
                args.Cancel = true;
                return;
            }
            if (string.IsNullOrWhiteSpace(TextBoxUnitPrice.Text))
            {
                FlyoutWarmingText.Text = "Unit Price cannot be empty!";
                FlyoutWarming.ShowAt(TextBoxUnitPrice);
                args.Cancel = true;
                return;
            }
            if (TextBoxRegex.GetIsValid(TextBoxUnitPrice) == false)
            {
                FlyoutWarmingText.Text = "Wrong numerical value!";
                FlyoutWarming.ShowAt(TextBoxUnitPrice);
                args.Cancel = true;
                return;
            }

            // perform real update
            TextBoxName.GetBindingExpression(TextBox.TextProperty).UpdateSource();
            ComboBoxCategory.GetBindingExpression(ComboBox.SelectedValueProperty).UpdateSource();
            TextBoxUnitPrice.GetBindingExpression(TextBox.TextProperty).UpdateSource();
            ImageThumbnail.GetBindingExpression(Image.SourceProperty).UpdateSource();
            this.recipe.ThumbnailFilename = this.thumbnailFilename;
        }
        private async Task AddUser(string resource, Method method)
        {
            SubmitButton.IsEnabled = false;

            if (!string.IsNullOrEmpty(roomname.Text) && !string.IsNullOrEmpty(localization.Text) && TextBoxRegex.GetIsValid(numberofpeople))
            {
                LoginModel SavedResponseObj = await helper.ReadFileAsync <LoginModel>("response");

                AddRoomModel roomObj = new AddRoomModel
                {
                    RoomName       = roomname.Text.Trim(),
                    Location       = localization.Text.Trim(),
                    Availability   = availability.SelectedIndex + 1,
                    NumberOfPeople = Convert.ToInt32(numberofpeople.Text)
                };
                string json = JsonConvert.SerializeObject(roomObj);

                RestClient  client  = new RestClient(IP.Adress);
                RestRequest request = new RestRequest("Room/create", Method.POST);
                _ = request.AddParameter("application/json", json, ParameterType.RequestBody);
                _ = request.AddParameter("Authorization", "Bearer " + SavedResponseObj.Token, ParameterType.HttpHeader);
                IRestResponse response = client.Execute(request);

                if (response.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    _ = await new CustomDialog("Sala dodana poprawnie.", null, CustomDialog.Type.Information).ShowAsync();
                    SubmitButton.IsEnabled = true;
                }
                else
                {
                    _ = await new CustomDialog("Wystąpił błąd podczas komunikacji z serwerem.", response.StatusCode.ToString(), CustomDialog.Type.Error).ShowAsync();
                    SubmitButton.IsEnabled = true;
                }
            }
            else
            {
                _ = await new CustomDialog("Wprowadzono błędne dane.", null, CustomDialog.Type.Warning).ShowAsync();
                SubmitButton.IsEnabled = true;
            }
        }
Exemple #8
0
        private bool IsFormValid()
        {
            CustomUri_TextBox_LostFocus(null, null);

            return(TextBoxRegex.GetIsValid(CustomUri_TextBox));
        }
        private async Task AddUser(string resource, Method method)
        {
            SubmitButton.IsEnabled = false;

            if (!string.IsNullOrEmpty(username.Text) && !string.IsNullOrEmpty(password.Password) && !string.IsNullOrEmpty(passwordconfirm.Password) && password.Password == passwordconfirm.Password && TextBoxRegex.GetIsValid(email))
            {
                LoginModel SavedResponseObj = await helper.ReadFileAsync <LoginModel>("response");

                AddUserModel userObj = new AddUserModel
                {
                    UserName = username.Text.Trim(),
                    Password = password.Password.Trim(),
                    Name     = name.Text.Trim(),
                    Surname  = surname.Text.Trim(),
                    Email    = email.Text.Trim(),
                    Active   = activity.IsChecked ?? true,
                    UserType = usertype.SelectedItem.ToString()
                };
                string json = JsonConvert.SerializeObject(userObj);

                RestClient  client  = new RestClient(IP.Adress);
                RestRequest request = new RestRequest(resource, method);
                _ = request.AddParameter("application/json", json, ParameterType.RequestBody);
                _ = request.AddParameter("Authorization", "Bearer " + SavedResponseObj.Token, ParameterType.HttpHeader);
                if (IsEditMode)
                {
                    _ = request.AddParameter("id", UserID, ParameterType.UrlSegment);
                }
                IRestResponse response = client.Execute(request);

                if (response.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    SubmitButton.IsEnabled = true;

                    if (IsEditMode)
                    {
                        _ = await new CustomDialog("Użytkownik edytowany poprawnie.", null, CustomDialog.Type.Information).ShowAsync();
                        CleanupInput();

                        Frame    rootFrame = Window.Current.Content as Frame;
                        MainPage homePage  = rootFrame.Content as MainPage;
                        _ = homePage.NavigationFrame.Navigate(typeof(UsersPage), null, new DrillInNavigationTransitionInfo());
                    }
                    else
                    {
                        _ = await new CustomDialog("Użytkownik stworzony poprawnie.", null, CustomDialog.Type.Information).ShowAsync();
                        CleanupInput();
                    }
                }
                else
                {
                    _ = await new CustomDialog("Wystąpił błąd podczas komunikacji z serwerem.", response.StatusCode.ToString(), CustomDialog.Type.Error).ShowAsync();
                    SubmitButton.IsEnabled = true;
                }
            }
            else
            {
                _ = await new CustomDialog("Wprowadzono błędne dane.", null, CustomDialog.Type.Warning).ShowAsync();
                SubmitButton.IsEnabled = true;
            }
        }
Exemple #10
0
        private async void SignIn_Button(object sejnder, RoutedEventArgs e)
        {
            SubmitButton.IsEnabled = false;

            if (!string.IsNullOrEmpty(password.Password) && TextBoxRegex.GetIsValid(email) && NetworkInterface.GetIsNetworkAvailable())
            {
                SignInModel loginObj = new SignInModel
                {
                    Email    = email.Text,
                    Password = password.Password,
                };
                string json = JsonConvert.SerializeObject(loginObj);

                ConnectionModel IP      = new ConnectionModel();
                RestClient      client  = new RestClient(IP.Adress);
                RestRequest     request = new RestRequest("Account/login", Method.POST);
                _ = request.AddParameter("application/json", json, ParameterType.RequestBody);
                IRestResponse response = client.Execute(request);

                if (response.StatusCode != System.Net.HttpStatusCode.InternalServerError && response.StatusCode != System.Net.HttpStatusCode.NotFound && response.StatusCode != System.Net.HttpStatusCode.BadGateway && response.StatusCode != System.Net.HttpStatusCode.BadRequest && response.StatusCode != 0)
                {
                    LoginModel tokenObj = JsonConvert.DeserializeObject <LoginModel>(response.Content);

                    JwtSecurityTokenHandler handler   = new JwtSecurityTokenHandler();
                    SecurityToken           jsonToken = handler.ReadToken(tokenObj.Token);

                    LoginModel tokenvalidateObj = new LoginModel
                    {
                        UserName = ((JwtSecurityToken)jsonToken).Payload["userName"].ToString(),
                        Name     = ((JwtSecurityToken)jsonToken).Payload["name"].ToString(),
                        surName  = ((JwtSecurityToken)jsonToken).Payload["sureName"].ToString(),
                        Email    = ((JwtSecurityToken)jsonToken).Payload["email"].ToString(),
                        role     = ((JwtSecurityToken)jsonToken).Payload["role"].ToString(),
                        Token    = tokenObj.Token,
                        IsLoged  = true
                    };

                    if (response.StatusCode == System.Net.HttpStatusCode.OK)
                    {
                        _ = await helper.SaveFileAsync("response", tokenvalidateObj);

                        SubmitButton.IsEnabled = true;

                        _ = Frame.Navigate(typeof(MainPage), null, new DrillInNavigationTransitionInfo());
                    }
                    else
                    {
                        _ = await new CustomDialog("Wystąpił błąd podczas komunikacji z serwerem.", response.StatusCode.ToString(), CustomDialog.Type.Error).ShowAsync();
                        SubmitButton.IsEnabled = true;
                    }
                }
                else
                {
                    _ = await new CustomDialog("Konto o podanym loginie/haśle nie istnieje lub brak połączenia z serwerem.", response.StatusCode.ToString(), CustomDialog.Type.Error).ShowAsync();
                    SubmitButton.IsEnabled = true;
                }
            }
            else
            {
                _ = await new CustomDialog("Wprowadzono błędne dane lub brak połączenia z internetem.", null, CustomDialog.Type.Warning).ShowAsync();
                SubmitButton.IsEnabled = true;
            }
        }