示例#1
0
        private async void confirmButton_click(object sender, RoutedEventArgs e)
        {
            string str;

            //如果没有点击item
            if (confirmButton.Content.ToString() == "确定")
            {
                TextBlock tb   = (TextBlock)ComboBox.SelectedItem;
                string    name = tb.Text;
                //var i = new MessageDialog(this.ComboBox1.SelectedIndex.ToString()).ShowAsync();
                if (this.ComboBox1.SelectedIndex == 0)
                {
                    number.Text = "+" + number.Text;
                }
                else
                {
                    number.Text = "-" + number.Text;
                }
                float  money  = float.Parse(number.Text);
                string heheda = leftMoney.Text;
                float  left   = float.Parse(leftMoney.Text.Substring(1));
                left += money;
                ck    = new CheckbookItem(number.Text, name, date.Date.DateTime, false, tip.Text);
                var result = await HttpUtil.AddCheckbookItem(App.account, ck);

                int cno = (int)result["cno"];
                ViewModel.AddCheckbookItem(cno.ToString(), ck.COST, ck.NAME, ck.DATETIME, false, "", ck.NOTE);
                leftMoney.Text = "¥" + left.ToString();
                str            = "¥" + left.ToString();
                leftMoney.Text = str;
                number.Text    = "";
                tip.Text       = "";
            }
            //如果点击了item
            else
            {
                //ViewModel.SelectedItem = (Models.CheckbookItem)(e.ClickedItem);
                TextBlock tb   = (TextBlock)ComboBox.SelectedItem;
                string    name = tb.Text;
                await HttpUtil.EditCheckbookItem(App.account, int.Parse(ViewModel.SelectedItem.CNO), new CheckbookItem(ViewModel.SelectedItem.COST, ViewModel.SelectedItem.NAME, date.Date.DateTime, ViewModel.SelectedItem.STATE, tip.Text));

                ViewModel.updateCheckbookItem(number.Text, name, date.Date.DateTime, ViewModel.SelectedItem.STATE, tip.Text);
                confirmButton.Content = "确定";
                number.Text           = "";
                tip.Text            = "";
                ComboBox1.IsEnabled = true;
                number.IsReadOnly   = false;
            }
        }