예제 #1
0
        private void Button_Click_1(object sender, RoutedEventArgs e)//倒计时创建,数据库录入,更新DefaultPage
        {
            string countName = this.countName.Text;
            string countContent = this.countContent.Text;
            try
            {
                int allTime = int.Parse(this.allTime.Text);
                int curTime = int.Parse(this.curTime.Text);

                CountItem newCountItem = new CountItem
                {
                    CountName = countName,
                    CountContent = countContent,
                    AllTimes = allTime,
                    CurrentTimes = curTime
                };
                if (curTime > allTime || curTime < 0 || allTime < 0)
                {
                    MessageBox.Show("次数输入不符合规范,请重新输入!");
                    return;
                }
                if (App.selectedIndex == -1)
                {
                    App.CViewModel.AddCountItem(newCountItem);

                    this.NavigationService.Navigate(new Uri("/DefaultPage.xaml", UriKind.Relative));
                    MessageBox.Show("倒计时创建成功!");
                    if (allTime == curTime)
                    {
                        MessageBox.Show("注意:您的任务倒计时次数已经用完!");
                    }
                }
                else
                {
                    App.CViewModel.ModifyCountItem(App.selectedIndex, newCountItem);
                    this.NavigationService.Navigate(new Uri("/DefaultPage.xaml", UriKind.Relative));
                    MessageBox.Show("倒计时修改成功!");
                    if (allTime == curTime)
                    {
                        MessageBox.Show("注意:您的任务倒计时次数已经用完!");
                    }
                }
            }
            catch (FormatException excption)
            {
                MessageBox.Show("次数输入不符合规范,请重新输入!");
                return;
            }
        }
예제 #2
0
        public void ModifyCountItem(int Id, CountItem countForModify)
        {
            CountItem tmpItem = AllCountItems[Id];
            tmpItem.CountName = countForModify.CountName;
            tmpItem.CountContent = countForModify.CountContent;
            tmpItem.CurrentTimes = countForModify.CurrentTimes;
            tmpItem.AllTimes = countForModify.AllTimes;

            IQueryable<CountItem> tmpItemQuery = from CountItem count in countDB.Items where count.CountItemId == tmpItem.CountItemId
                                                 select count;
            CountItem tmpItem1 = tmpItemQuery.FirstOrDefault();
            tmpItem1.CountName = countForModify.CountName;
            tmpItem1.CountContent = countForModify.CountContent;
            tmpItem1.CurrentTimes = countForModify.CurrentTimes;
            tmpItem1.AllTimes = countForModify.AllTimes;
            countDB.SubmitChanges();
        }
예제 #3
0
 public void AddCountItem(CountItem newCountItem)
 {
     countDB.Items.InsertOnSubmit(newCountItem);
     countDB.SubmitChanges();
     AllCountItems.Add(newCountItem);
 }