每次坐火車都想靠著窗戶坐,看看風景人也舒服些,在網上找了下座位計算的方法,就做了一個小應用
注:不包括高鐵和動車
計算的代碼:
View Code
1 int Num;
2 if (int.TryParse(this.phoneTextBox_Num.Text.ToString(), out Num))
3 {
4 Debug.WriteLine(Num.ToString());
5 if (Num > 0 && Num <= 118)
6 {
7 if (Num == 1 || Num == 4 || Num == 114 || Num == 118)
8 {
9 this.textBlock_Out.Text = "您查詢的座位臨窗";
10 Debug.WriteLine("靠窗:" + Num.ToString() + "號");
11 }
12 else
13 {
14 if (Num > 4 || Num < 114)
15 {
16 //座位號碼減去4除以5餘1或0的座位均為靠窗座位,其中餘0者為兩座臨窗,餘1者為三座臨窗。
17 if ((Num - 4) % 5 == 1)
18 {
19 this.textBlock_Out.Text = "您查詢的座位兩座臨窗";
20 Debug.WriteLine("兩座靠窗:" + Num.ToString() + "號");
21 }
22 else if ((Num - 4) % 5 == 0)
23 {
24 this.textBlock_Out.Text = "您查詢的座位三座臨窗";
25 Debug.WriteLine("三座靠窗:" + Num.ToString() + "號");
26 }
27 else
28 {
29 this.textBlock_Out.Text = "您查詢的座位不臨窗";
30 Debug.WriteLine("不靠窗:" + Num.ToString() + "號");
31 }
32 }
33 }
34 }
35 else {
36 this.textBlock_Out.Text = "您輸入的座位號不正確";
37 }
38 }
39 else
40 {
41 this.phoneTextBox_Num.Text = "";
42 MessageBox.Show("請輸入數字!");
43 }
:http://files.cnblogs.com/lsmayday/Trainseat.xap