Exemplo n.º 1
0
 private void AddMainType(object sender, RoutedEventArgs e)
 {
     if (TextBoxMainType.Text.Length > 0)
     {
         string    name     = TextBoxMainType.Text;
         Main_type MainItem = new Main_type {
             Name = name
         };
         Sub_type defaultSubItem = new Sub_type {
             Name = name
         };
         App.APPDB.Main_type.InsertOnSubmit(MainItem);
         try
         {
             APPDB.SubmitChanges();
             defaultSubItem.Pid = MainItem.Id;
             APPDB.Sub_type.InsertOnSubmit(defaultSubItem);
             APPDB.SubmitChanges();
             MainTypeList.Add(MainItem);
         }
         catch (Exception ex)
         {
             MessageBox.Show("数据保存失败");
         }
     }
     this.Focus();
 }
Exemplo n.º 2
0
        //protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
        //{
        //    if (APPDB != null)
        //    {
        //        APPDB.SubmitChanges();
        //        APPDB.Dispose();
        //    }
        //    base.OnNavigatedFrom(e);
        //}

        protected override void OnBackKeyPress(CancelEventArgs e)
        {
            if (APPDB != null)
            {
                APPDB.SubmitChanges();
                APPDB.Dispose();
            }
            base.OnBackKeyPress(e);
        }
Exemplo n.º 3
0
 private void AddSubTypeClick(object sender, RoutedEventArgs e)
 {
     if (TextBoxSubType.Text.Length > 0)
     {
         string   name        = TextBoxSubType.Text;
         Sub_type SubTypeItem = new Sub_type {
             Name = name, Pid = pid
         };
         APPDB.Sub_type.InsertOnSubmit(SubTypeItem);
         try
         {
             APPDB.SubmitChanges();
             SubTypeList.Add(SubTypeItem);
         }
         catch (Exception ex)
         {
             MessageBox.Show("数据库错误,请尝试重新安装应用。");
         }
         TextBoxSubType.Text = "";
         this.Focus();
     }
 }
Exemplo n.º 4
0
        private void AddNewRecord(object sender, EventArgs e)
        {
            if (TextBoxMoneyInt.Text.Length == 0)
            {
                MessageBox.Show("请填写金额。");
                return;
            }

            if (TextBoxMoneyPoint.Text.Length == 1)
            {
                TextBoxMoneyPoint.Text = TextBoxMoneyPoint.Text + "0";
            }

            int money;

            try
            {
                money = int.Parse(TextBoxMoneyInt.Text) * 100 + int.Parse(TextBoxMoneyPoint.Text);
            }
            catch (Exception ex)
            {
                MessageBox.Show("请正确填写金额。");
                return;
            }
            DateTime today      = DateTime.Today;
            DateTime choiceDate = datePicker.Value.Value;
            Outgoing record     = new Outgoing {
                Money = money, Main_id = mTypeId, Sub_id = sTypeId, Time = choiceDate
            };

            APPDB.Outgoing.InsertOnSubmit(record);


            //清除过期信息
            if (homeInfo.Date != today)
            {
                homeInfo.Daysum = 0;
            }
            //下一周
            if ((today - homeInfo.Weekstart).Days > 7)
            {
                homeInfo.Weeksum   = 0;
                homeInfo.Weekstart = today.AddDays(-(int)today.DayOfWeek);
            }
            if (homeInfo.Date.Month != today.Month && homeInfo.Date.Year != today.Year)
            {
                homeInfo.Mouthsum = 0;
            }
            homeInfo.Date = today;

            if (homeInfo.Date.Year == choiceDate.Year)
            {
                if (homeInfo.Date.Month == choiceDate.Month)
                {
                    homeInfo.Mouthsum += money;
                }
                int weekDays = choiceDate.DayOfYear - homeInfo.Weekstart.DayOfYear;
                if (weekDays < 8 && weekDays > 0)
                {
                    homeInfo.Weeksum += money;
                }
                if (choiceDate == homeInfo.Date)
                {
                    homeInfo.Daysum += money;
                }
            }

            APPDB.SubmitChanges();
            NavigationService.GoBack();
        }