[这不是Windows Phone 7]FitnessTrackerPlus(健身)四.注册(完结)

一.注册页面

View Code
 1 <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
2 <TextBlock Height="30" HorizontalAlignment="Left" Margin="45,273,0,0" Name="TextBlock" Text="问题" VerticalAlignment="Top" />
3 <TextBox Height="72" HorizontalAlignment="Left" Margin="91,255,0,0" Name="QuestionTextBox" Text="" VerticalAlignment="Top" Width="339" />
4 <TextBlock Height="30" HorizontalAlignment="Left" Margin="45,382,0,0" Name="textBlock2" Text="答案" VerticalAlignment="Top" />
5 <TextBox Height="72" HorizontalAlignment="Left" Margin="91,357,0,0" Name="AnswerTextBox" Text="" VerticalAlignment="Top" Width="339" />
6 <Button Content="注册" Height="72" HorizontalAlignment="Left" Margin="172,466,0,0" Name="RegisterBtn" VerticalAlignment="Top" Width="160" Click="RegisterBtn_Click" />
7 <TextBlock Height="30" HorizontalAlignment="Left" Margin="45,79,0,0" Name="textBlock3" Text="邮箱" VerticalAlignment="Top" />
8 <TextBox Height="72" HorizontalAlignment="Left" Margin="91,61,0,0" Name="EmialText" Text="" VerticalAlignment="Top" Width="339" />
9 <TextBlock Height="30" HorizontalAlignment="Left" Margin="45,188,0,0" Name="textBlock4" Text="密码" VerticalAlignment="Top" />
10 <TextBox Height="72" HorizontalAlignment="Left" Margin="91,163,0,0" Name="PwdText" Text="" VerticalAlignment="Top" Width="339" />
11 </Grid>

二.后台代码

View Code
 1 FitnessTrackerPlusEntities entites = new FitnessTrackerPlusEntities(new Uri("http://192.168.1.104/FitnessTrackerPlusDataService.svc"));
2 public RegisterPage()
3 {
4 InitializeComponent();
5 }
6 //注册
7 private void RegisterBtn_Click(object sender, RoutedEventArgs e)
8 {
9
10 int i = 0;
11 string name = "";
12 if (!Regex.IsMatch(EmialText.Text, @"^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$"))
13 {
14 MessageBox.Show("邮箱格式错误");
15 }
16 else
17 {
18 foreach (var item in EmialText.Text)
19 {
20 i++;
21 if (item == '@')
22 {
23 name = EmialText.Text.Substring(0, i - 1);
24 }
25
26 }
27 var u = new users()
28 {
29
30 email_address = EmialText.Text,
31 username = name,
32 password = MD5.GetMd5String(PwdText.Text).ToUpper(),
33 locked = false,
34 created_date = DateTime.Now.Date,
35 account_type = 1,
36 online = false,
37 disabled = false,
38 security_question = QuestionTextBox.Text,
39 security_answer = MD5.GetMd5String(AnswerTextBox.Text).ToUpper()
40 };
41 entites.AddTousers(u);
42 entites.BeginSaveChanges(SaveComplete_Callback, null);
43 }
44
45
46
47
48 }
49 private void SaveComplete_Callback(IAsyncResult result)
50 {
51
52 var reponse = entites.EndSaveChanges(result);
53 try
54 {
55
56 Messge("注册成功!");
57
58 }
59 catch (Exception ex)
60 {
61
62 Messge(ex.Message.ToString());
63 }
64
65 }
66 private void Messge(string msg)
67 {
68 this.Dispatcher.BeginInvoke(() => { MessageBox.Show(msg); });
69 }



原文地址:https://www.cnblogs.com/tubufeng/p/2407868.html