Advertisement
Guest User

Untitled

a guest
Mar 10th, 2013
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.20 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Net;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Documents;
  8. using System.Windows.Input;
  9. using System.Windows.Media;
  10. using System.Windows.Media.Animation;
  11. using System.Windows.Shapes;
  12. using Microsoft.Phone.Controls;
  13.  
  14. using System.Text.RegularExpressions;
  15.  
  16. namespace PhoneApp3
  17. {
  18.     public partial class MainPage : PhoneApplicationPage
  19.     {
  20.         // Constructor
  21.         public MainPage()
  22.         {
  23.             InitializeComponent();
  24.             TxtNombre.Text = "";
  25.             TxtScore.Text = "";
  26.             txtBInfo.Text = "";
  27.         }
  28.  
  29.         private bool NombreValido(string Nombre)
  30.         {
  31.             Regex r = default(Regex);
  32.             r = new Regex("^[a-zA-Z0-9]+$");
  33.             return r.IsMatch(Nombre);
  34.         }
  35.  
  36.         private bool OnlyNumbers(string Score)
  37.         {
  38.             Regex r = default(Regex);
  39.             r = new Regex("^[0-9]+$");
  40.             return r.IsMatch(Score);
  41.         }
  42.  
  43.         private void btnSave_Click(object sender, RoutedEventArgs e)
  44.         {
  45.             if (NombreValido(TxtNombre.Text.Trim()) == false)
  46.             {
  47.                 txtBInfo.Foreground = new SolidColorBrush(Color.FromArgb(255, 255, 0, 0));
  48.                 txtBInfo.Text = "Error: Falta Nombre/Nombre incorrecto";
  49.                 MessageBox.Show("El nombre sólo puede contener letras y/o números", "Atención", MessageBoxButton.OK);
  50.                 TxtNombre.Focus();
  51.                 return;
  52.             }            
  53.             else if (TxtScore.Text.Trim() == "" || OnlyNumbers(TxtScore.Text) == false)
  54.             {
  55.                 txtBInfo.Foreground = new SolidColorBrush(Color.FromArgb(255, 255, 0, 0));
  56.                 txtBInfo.Text = "Error: Falta Puntuación";
  57.                 MessageBox.Show("No has especificado la puntuación o es incorrecta. Sólo números plz.", "Atención", MessageBoxButton.OK);
  58.                 TxtScore.Focus();
  59.                 return;
  60.             }            
  61.             else
  62.             {
  63.                 try
  64.                 {
  65.                     ServiceReference1.Service1Client mHIScore = new ServiceReference1.Service1Client();
  66.                     mHIScore.InsertarHIScoreCompleted += new EventHandler<ServiceReference1.InsertarHIScoreCompletedEventArgs>(mHIScore_InsertarHIScoreCompleted);
  67.                     mHIScore.InsertarHIScoreAsync(TxtNombre.Text.Trim(), Int32.Parse(TxtScore.Text));
  68.                 }
  69.                 catch (Exception ex)
  70.                 {
  71.                     txtBInfo.Text = ex.Message;
  72.                 }
  73.             }
  74.         }
  75.  
  76.         void mHIScore_InsertarHIScoreCompleted(object sender, ServiceReference1.InsertarHIScoreCompletedEventArgs e)
  77.         {
  78.             int? iD = e.Result;
  79.             if (iD.HasValue)
  80.             {
  81.                 txtBInfo.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 255, 255));
  82.                 txtBInfo.Text = "Success: " + iD;
  83.                 MessageBox.Show("Se guardó el registro en la base de datos. ID = " + iD, "Info", MessageBoxButton.OK);
  84.             }
  85.             else
  86.                 txtBInfo.Text = "Error";
  87.         }
  88.     }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement