Ejemplo n.º 1
0
 private async void btnCreate_Click(object sender, RoutedEventArgs e)
 {
     if (string.IsNullOrEmpty(txtId.Text))
     {
         await new MessageDialog("ID can not be blank").ShowAsync();
         txtId.Focus(FocusState.Keyboard);
         return;
     }
     else if (string.IsNullOrEmpty(txtTitle.Text) || txtTitle.Text.Length < 3 || txtTitle.Text.Length > 10)
     {
         await new MessageDialog("Title can not be blank").ShowAsync();
         txtTitle.Focus(FocusState.Keyboard);
         return;
     }
     else if (string.IsNullOrEmpty(txtGenre.Text))
     {
         await new MessageDialog("Genre can not be blank").ShowAsync();
         txtGenre.Focus(FocusState.Keyboard);
         return;
     }
     else if (string.IsNullOrEmpty(txtROY.Text))
     {
         await new MessageDialog("ROY can not be blank").ShowAsync();
         txtROY.Focus(FocusState.Keyboard);
         return;
     }
     else
     {
         Models.Game game = new Models.Game
         {
             Id    = int.Parse(txtId.Text),
             Title = txtTitle.Text,
             Genre = txtGenre.Text,
             Year  = txtROY.Text,
         };
         Models.GameContext.gList.Add(game);
         await new MessageDialog("Add account completed").ShowAsync();
     }
 }
Ejemplo n.º 2
0
 private void btnCreate_Click(object sender, EventArgs e)
 {
     //Id
     if (string.IsNullOrEmpty(txtId.Text))
     {
         MessageBox.Show("Id is required!");
         return;
     }
     else if (Regex.IsMatch(txtId.Text, "\\d+") == false)
     {
         MessageBox.Show("Id is invalid. Id must be a number!");
         return;
     }
     //Title
     else if (string.IsNullOrEmpty(txtTitle.Text))
     {
         MessageBox.Show("Title is required!");
         return;
     }
     else if (txtTitle.Text.Length < 3)
     {
         MessageBox.Show("Title is invalid. Title length must be larger than 3 character !");
         return;
     }
     //Genre
     else if (string.IsNullOrEmpty(txtGenre.Text))
     {
         MessageBox.Show("Genre is required!");
         return;
     }
     else if (txtGenre.Text != "hanh dong" && txtGenre.Text != "giai tri")
     {
         MessageBox.Show("Genre is invalid. Genre must be 'hanh dong' or 'giai tri' !");
         return;
     }
     //Year
     else if (string.IsNullOrEmpty(txtYear.Text))
     {
         MessageBox.Show("Year is required!");
         return;
     }
     //Price
     else if (string.IsNullOrEmpty(txtPrice.Text))
     {
         MessageBox.Show("Price is required!");
         return;
     }
     else if (Regex.IsMatch(txtPrice.Text, "\\d+") == false)
     {
         MessageBox.Show("Price is invalid. Price must be a number!");
         return;
     }
     else if (double.Parse(txtPrice.Text) <= 0)
     {
         MessageBox.Show("Price is invalid. Price must be larger than 0!");
         return;
     }
     else
     {
         Models.Game game = new Models.Game();
         game._Id            = int.Parse(txtId.Text);
         game._Title         = txtTitle.Text;
         game._Genre         = txtGenre.Text;
         game._YearOfRelease = txtYear.Text;
         game._Price         = double.Parse(txtPrice.Text);
         Models.GameContext.gList.Add(game);
         MessageBox.Show("Add game completed!");
     }
 }