protected override void OnNavigatedTo(NavigationEventArgs e) { ViewModel = ((ViewModels.M_moneyItemViewModel)e.Parameter); if (ViewModel.SelectedMonth == null) { //createButton.Content = "Create"; //var i = new MessageDialog("Welcome!").ShowAsync(); } else { string temp = ""; switch (ViewModel.SelectedMonth.month) { case 1: temp = "January"; break; case 2: temp = "February"; break; case 3: temp = "March"; break; case 4: temp = "April"; break; case 5: temp = "May"; break; case 6: temp = "June"; break; case 7: temp = "July"; break; case 8: temp = "August"; break; case 9: temp = "September"; break; case 10: temp = "October"; break; case 11: temp = "November"; break; case 12: temp = "December"; break; } year.Text = "Bill of " + temp; // todo:选出选中月的各类型的消费记录的金额。 double Func = 0, Foodc = 0, Otherc = 0, Studyc = 0, Transportc = 0, Clothesc = 0, sum = 1; // 筛选Fun类 var target = Convert.ToString(ViewModel.SelectedMonth.year) + "/" + Convert.ToString(ViewModel.SelectedMonth.month) + "/%"; double Funtotal = 0; using (var monthsearch = App.conn.Prepare("SELECT* FROM Message WHERE Time LIKE ? AND Type = ?")) { monthsearch.Bind(1, target); monthsearch.Bind(2, "Fun"); if (monthsearch.ColumnCount != 0) { while (monthsearch.Step() == SQLitePCL.SQLiteResult.ROW) { Funtotal += (double)monthsearch[1]; } } } Func = Funtotal; // 筛选Food类 double Foodtotal = 0; using (var monthsearch = App.conn.Prepare("SELECT* FROM Message WHERE Time LIKE ? AND Type = ?")) { monthsearch.Bind(1, target); monthsearch.Bind(2, "Food"); if (monthsearch.ColumnCount != 0) { while (monthsearch.Step() == SQLitePCL.SQLiteResult.ROW) { Foodtotal += (double)monthsearch[1]; } } } Foodc = Foodtotal; // 筛选Other类 double Othertotal = 0; using (var monthsearch = App.conn.Prepare("SELECT* FROM Message WHERE Time LIKE ? AND Type = ?")) { monthsearch.Bind(1, target); monthsearch.Bind(2, "Other"); if (monthsearch.ColumnCount != 0) { while (monthsearch.Step() == SQLitePCL.SQLiteResult.ROW) { Othertotal += (double)monthsearch[1]; } } } Otherc = Othertotal; // 筛选Study类 double Studytotal = 0; using (var monthsearch = App.conn.Prepare("SELECT* FROM Message WHERE Time LIKE ? AND Type = ?")) { monthsearch.Bind(1, target); monthsearch.Bind(2, "Study"); if (monthsearch.ColumnCount != 0) { while (monthsearch.Step() == SQLitePCL.SQLiteResult.ROW) { Studytotal += (double)monthsearch[1]; } } } Studyc = Studytotal; // 筛选Transport类 double Transporttotal = 0; using (var monthsearch = App.conn.Prepare("SELECT* FROM Message WHERE Time LIKE ? AND Type = ?")) { monthsearch.Bind(1, target); monthsearch.Bind(2, "Transport"); if (monthsearch.ColumnCount != 0) { while (monthsearch.Step() == SQLitePCL.SQLiteResult.ROW) { Transporttotal += (double)monthsearch[1]; } } } Transportc = Transporttotal; // 筛选Clothes类 double Clothestotal = 0; using (var monthsearch = App.conn.Prepare("SELECT* FROM Message WHERE Time LIKE ? AND Type = ?")) { monthsearch.Bind(1, target); monthsearch.Bind(2, "Clothes"); if (monthsearch.ColumnCount != 0) { while (monthsearch.Step() == SQLitePCL.SQLiteResult.ROW) { Clothestotal += (double)monthsearch[1]; } } } Clothesc = Clothestotal; sum = Func + Foodc + Otherc + Studyc + Transportc + Clothesc; //设置各条形图高度; food.Height = Foodc / sum * 200; fun.Height = Func / sum * 200; other.Height = Otherc / sum * 200; transport.Height = Transportc / sum * 200; clothes.Height = Clothesc / sum * 200; study.Height = Studyc / sum * 200; //设置百分比的值,并保留两位小数 foodtext.Text = String.Format("{0:F}", Foodc / sum * 100) + "%"; funtext.Text = String.Format("{0:F}", Func / sum * 100) + "%"; othertext.Text = String.Format("{0:F}", Otherc / sum * 100) + "%"; transporttext.Text = String.Format("{0:F}", Transportc / sum * 100) + "%"; clothestext.Text = String.Format("{0:F}", Clothesc / sum * 100) + "%"; studytext.Text = String.Format("{0:F}", Studyc / sum * 100) + "%"; //设置各消费金额 foodcost.Text = "¥" + Foodc.ToString(); funcost.Text = "¥" + Func.ToString(); othercost.Text = "¥" + Otherc.ToString(); transportcost.Text = "¥" + Transportc.ToString(); clothescost.Text = "¥" + Clothesc.ToString(); studycost.Text = "¥" + Studyc.ToString(); total.Text = sum.ToString(); } }
protected override void OnNavigatedTo(NavigationEventArgs e) { ViewModel = ((ViewModels.M_moneyItemViewModel)e.Parameter); if (ViewModel.SelectedYear == null) { //createButton.Content = "Create"; //var i = new MessageDialog("Welcome!").ShowAsync(); } else { // year.Text = "Bill of " + ViewModel.SelectedYear.year.ToString(); // todo:选出选中年的各类型的消费记录的金额。 double Func = 0, Foodc = 0, Otherc = 0, Studyc = 0, Transportc = 0, Clothesc = 0, sum = 1; // 筛选Fun类 var target = Convert.ToString(ViewModel.SelectedYear.year) + "/%"; double Funtotal = 0; using (var monthsearch = App.conn.Prepare("SELECT* FROM Message WHERE Time LIKE ? AND Type = ?")) { monthsearch.Bind(1, target); monthsearch.Bind(2, "Fun"); if (monthsearch.ColumnCount != 0) { while (monthsearch.Step() == SQLitePCL.SQLiteResult.ROW) { Funtotal += (double)monthsearch[1]; } } } Func = Funtotal; // 筛选Food类 double Foodtotal = 0; using (var monthsearch = App.conn.Prepare("SELECT* FROM Message WHERE Time LIKE ? AND Type = ?")) { monthsearch.Bind(1, target); monthsearch.Bind(2, "Food"); if (monthsearch.ColumnCount != 0) { while (monthsearch.Step() == SQLitePCL.SQLiteResult.ROW) { Foodtotal += (double)monthsearch[1]; } } } Foodc = Foodtotal; // 筛选Other类 double Othertotal = 0; using (var monthsearch = App.conn.Prepare("SELECT* FROM Message WHERE Time LIKE ? AND Type = ?")) { monthsearch.Bind(1, target); monthsearch.Bind(2, "Other"); if (monthsearch.ColumnCount != 0) { while (monthsearch.Step() == SQLitePCL.SQLiteResult.ROW) { Othertotal += (double)monthsearch[1]; } } } Otherc = Othertotal; // 筛选Study类 double Studytotal = 0; using (var monthsearch = App.conn.Prepare("SELECT* FROM Message WHERE Time LIKE ? AND Type = ?")) { monthsearch.Bind(1, target); monthsearch.Bind(2, "Study"); if (monthsearch.ColumnCount != 0) { while (monthsearch.Step() == SQLitePCL.SQLiteResult.ROW) { Studytotal += (double)monthsearch[1]; } } } Studyc = Studytotal; // 筛选Transport类 double Transporttotal = 0; using (var monthsearch = App.conn.Prepare("SELECT* FROM Message WHERE Time LIKE ? AND Type = ?")) { monthsearch.Bind(1, target); monthsearch.Bind(2, "Transport"); if (monthsearch.ColumnCount != 0) { while (monthsearch.Step() == SQLitePCL.SQLiteResult.ROW) { Transporttotal += (double)monthsearch[1]; } } } Transportc = Transporttotal; // 筛选Clothes类 double Clothestotal = 0; using (var monthsearch = App.conn.Prepare("SELECT* FROM Message WHERE Time LIKE ? AND Type = ?")) { monthsearch.Bind(1, target); monthsearch.Bind(2, "Clothes"); if (monthsearch.ColumnCount != 0) { while (monthsearch.Step() == SQLitePCL.SQLiteResult.ROW) { Clothestotal += (double)monthsearch[1]; } } } Clothesc = Clothestotal; sum = Func + Foodc + Otherc + Studyc + Transportc + Clothesc; food.Height = Foodc / sum * 200; fun.Height = Func / sum * 200; other.Height = Otherc / sum * 200; transport.Height = Transportc / sum * 200; clothes.Height = Clothesc / sum * 200; study.Height = Studyc / sum * 200; //设置百分比的值 foodtext.Text = String.Format("{0:F}", Foodc / sum * 100) + "%"; funtext.Text = String.Format("{0:F}", Func / sum * 100) + "%"; othertext.Text = String.Format("{0:F}", Otherc / sum * 100) + "%"; transporttext.Text = String.Format("{0:F}", Transportc / sum * 100) + "%"; clothestext.Text = String.Format("{0:F}", Clothesc / sum * 100) + "%"; studytext.Text = String.Format("{0:F}", Studyc / sum * 100) + "%"; //设置各消费金额 foodcost.Text = "¥" + Foodc.ToString(); funcost.Text = "¥" + Func.ToString(); othercost.Text = "¥" + Otherc.ToString(); transportcost.Text = "¥" + Transportc.ToString(); clothescost.Text = "¥" + Clothesc.ToString(); studycost.Text = "¥" + Studyc.ToString(); total.Text = sum.ToString(); } }