(1)AA制程序设计完成总结
page1:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
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 using Microsoft.Phone.Shell; 14 15 namespace AA 16 { 17 public partial class MainPage : PhoneApplicationPage 18 { 19 string str1=""; 20 string str2=""; 21 // 构造函数 22 public MainPage() 23 { 24 //加入图标 25 26 StandardTileData NewTitleData = new StandardTileData 27 { 28 //前面 29 Title = " ", 30 BackgroundImage = new Uri("Images/2.png", UriKind.Relative), 31 Count = 0, 32 //背面 33 BackTitle = " ", 34 BackBackgroundImage = new Uri("Images/3.png", UriKind.Relative), 35 BackContent = " " 36 }; 37 ShellTile tile = ShellTile.ActiveTiles.First(); 38 tile.Update(NewTitleData); 39 InitializeComponent(); 40 } 41 42 public void button1_Click(object sender, RoutedEventArgs e) 43 { 44 str1 = (checkBox1.IsChecked == true ? "买单|" : "")+(checkBox4.IsChecked==true?"点菜|":"")+ 45 (checkBox5.IsChecked == true ? "跑腿|" : "") + (checkBox3.IsChecked == true ? "预定座位|" : "")+ 46 (checkBox2.IsChecked == true ? "来回车费|" : ""); 47 str2 = textBox1.Text;//姓名之间以逗号隔开 48 49 NavigationService.Navigate(new Uri("/Page1.xaml?" 50 +"param1="+str1 51 +"¶m2="+str2 52 , UriKind.Relative)); 53 } 54 55 protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e) 56 { 57 58 59 //this.State["content"] = str1; 60 this.State["title"] = str2; 61 //this.State["check1"] = checkBox1.IsChecked; 62 //this.State["check2"] = checkBox2.IsChecked; 63 //this.State["check3"] = checkBox3.IsChecked; 64 //this.State["check4"] = checkBox4.IsChecked; 65 //this.State["check5"] = checkBox5.IsChecked; 66 base.OnNavigatedFrom(e); 67 68 } 69 protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) 70 { 71 if (this.State.ContainsKey("title")) 72 { 73 this.textBox1.Text = State["title"] as string; 74 } 75 76 base.OnNavigatedTo(e); 77 } 78 } 79 }
page2:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 整个page2中的cs代码 2 3 using System; 4 using System.Collections.Generic; 5 using System.Linq; 6 using System.Net; 7 using System.Windows; 8 using System.Windows.Controls; 9 using System.Windows.Documents; 10 using System.Windows.Input; 11 using System.Windows.Media; 12 using System.Windows.Media.Animation; 13 using System.Windows.Shapes; 14 using Microsoft.Phone.Controls; 15 16 namespace AA 17 { 18 public partial class Page1 : PhoneApplicationPage 19 { 20 static int x, y; 21 static int a,b; 22 int l = 0; 23 int m,m1;//全局m变量 24 25 string[] ItemName=new string[10]; 26 string[] ItemElse=new string[20]; 27 string[] options; 28 29 30 public Page1() 31 { 32 InitializeComponent(); 33 } 34 35 private void button1_Click(object sender, RoutedEventArgs e) 36 { 37 this.NavigationService.GoBack(); 38 } 39 protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) 40 { 41 string paramValue1 = NavigationContext.QueryString["param1"];//存储选择的选项 42 string paramValue2 = NavigationContext.QueryString["param2"];//存储名字信息 43 options = paramValue1.Split('|');//分割paramValue1得到选择的各个选项,此时的到的选项有可能为空 44 string[] names = paramValue2.Split(',');//分割paramValue2得到各个名字 45 46 a = names.Length;//成功得到名字的个数 (验证)MessageBox.Show("名字的个数:"+a.ToString()); 47 b = options.Length-1;//成功得到选项的个数-最后为空的那个选项//MessageBox.Show(a.ToString()); 48 49 if(a<b) 50 { 51 MessageBox.Show("额,人数不够,没法判决!"); 52 return; 53 } 54 55 56 Random obj=new Random(); //定义随机函数类的对象 57 ItemName[0] = names[obj.Next(a)]; 58 // 59 if (b != 0) 60 { 61 for (int k = 1; k < b; ) //选出不重复的b个人放到ItemName数组中。 62 { 63 int sum = 0; 64 ItemName[k] = names[obj.Next(a)]; 65 for (int n = 0; n <= k - 1; n++)//如果数组中名字重复,则原地再次执行。 66 { 67 if (ItemName[k] == ItemName[n]) 68 { sum += 1; } 69 } 70 if (sum != 0) 71 { } 72 else 73 k++; 74 } 75 //foreach(string y in ItemName) 76 //{ 77 // MessageBox.Show(y);//验证成功 78 //} 79 } 80 else 81 return; 82 83 84 //MessageBox.Show("嘎嘎"); 85 //for (int i=0;i<10;i++) 86 //{ 87 // MessageBox.Show(ItemName[i]); 88 //} 89 90 //把剩下的人存在ItemElse数组中 91 for (int p = 0; p < a;p++ ) 92 { 93 int sum1 = 0; 94 for (int q = 0; q < b; q++) //b为ItemName数组中字符的个数 95 { 96 if(names[p]==ItemName[q]) 97 { 98 sum1 += 1; 99 } 100 } 101 if (sum1 == 0) 102 { 103 104 ItemElse[l] = names[p]; 105 l++; 106 } 107 } 108 109 110 //自动生成控件组合(前b个人会特殊照顾) 111 for ( m = 0; m < b; m++) // for (int i = 0; i < a; i++) 112 { 113 if(ItemName[0].Length!=0&&options[m].Length!=0) 114 { 115 GenerateControl(); 116 } 117 118 119 } 120 //接下来是从b+1到a个人的处理,他们很幸福,负责“享受”。 121 for (m1 = 0; m1 < a-b;m1++ ) 122 { 123 124 GenerateControlElse(); 125 126 } 127 128 } 129 private void GenerateControl() 130 { 131 string fuze = "负责"; 132 TextBlock tb1 = new TextBlock(); 133 tb1.Text =ItemName[m]+"->"+fuze+"->"+options[m]; 134 tb1.FontFamily = new FontFamily("Segoe WP Bold"); 135 tb1.FontSize = 30; 136 tb1.Foreground = new SolidColorBrush(Colors.Red); 137 this.listBox1.Items.Add(tb1); 138 } 139 private void GenerateControlElse() 140 { 141 string fuze1 = "负责"; 142 string xiangshou = "享受"; 143 TextBlock tb1 = new TextBlock(); 144 tb1.Text = ItemElse[m1] + "-》" + fuze1 + "-》" + xiangshou; 145 146 tb1.FontFamily = new FontFamily("Segoe WP Bold"); 147 tb1.FontSize = 30; 148 tb1.Foreground = new SolidColorBrush(Colors.Red); 149 this.listBox1.Items.Add(tb1); 150 } 151 152 private void listBox1_SelectionChanged(object sender, SelectionChangedEventArgs e) 153 { 154 155 } 156 } 157 }