Example #1
0
        /// <summary>
        /// テキストボックスフォーカス取得時
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void TextBox_GotFocus(object sender, RoutedEventArgs e)
        {
            if (!this.WVM.IsEditing)
            {
                TextBox textBox = sender as TextBox;
                this._popup.SetBinding(Popup.StaysOpenProperty, new Binding(IsKeyboardFocusedProperty.Name)
                {
                    Source = textBox
                });
                this._popup.PlacementTarget = textBox;
                this.WVM.IsEditing          = true;

                this.lastDateValueVM = textBox.DataContext as DateValueViewModel;
            }
            e.Handled = true;
        }
Example #2
0
 /// <summary>
 /// 日付金額リスト追加時
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void DataGrid_AddingNewItem(object sender, AddingNewItemEventArgs e)
 {
     if (this.WVM.DateValueVMList.Count == 0)
     {
         e.NewItem = new DateValueViewModel()
         {
             ActDate = this.selectedDate ?? DateTime.Today, ActValue = null
         };
     }
     else
     {
         // リストに入力済の末尾のデータの日付を追加時に採用する
         DateValueViewModel lastVM = this.WVM.DateValueVMList[this.WVM.DateValueVMList.Count - 1];
         e.NewItem = new DateValueViewModel()
         {
             ActDate = this.WVM.IsDateAutoIncrement ? lastVM.ActDate.AddDays(1) : lastVM.ActDate, ActValue = null
         };
     }
 }
Example #3
0
        /// <summary>
        /// フォーム読込完了時
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void ActionListRegistrationWindow_Loaded(object sender, RoutedEventArgs e)
        {
            ObservableCollection <BookViewModel> bookVMList = new ObservableCollection <BookViewModel>();
            int?          bookId         = null;
            BookViewModel selectedBookVM = null;
            BalanceKind   balanceKind    = BalanceKind.Outgo;

            int?   itemId   = null;
            string shopName = null;
            string remark   = null;

            switch (this.WVM.RegMode)
            {
            case RegistrationMode.Add: {
                bookId      = this.selectedBookId;
                balanceKind = BalanceKind.Outgo;
                DateTime actDate = this.selectedDate ?? ((this.selectedMonth == null || this.selectedMonth?.Month == DateTime.Today.Month) ? DateTime.Today : this.selectedMonth.Value);

                if (this.selectedRecordList == null)
                {
                    this.WVM.DateValueVMList.Add(new DateValueViewModel()
                        {
                            ActDate = actDate
                        });
                }
                else
                {
                    foreach (CsvComparisonViewModel.CsvRecord record in this.selectedRecordList)
                    {
                        this.WVM.DateValueVMList.Add(new DateValueViewModel()
                            {
                                ActDate = record.Date, ActValue = record.Value
                            });
                    }
                }
            }
            break;

            case RegistrationMode.Edit:
            case RegistrationMode.Copy: {
                using (DaoBase dao = this.builder.Build()) {
                    DaoReader reader = await dao.ExecQueryAsync(@"
SELECT book_id, item_id, action_id, act_time, act_value, shop_name, remark
FROM hst_action 
WHERE del_flg = 0 AND group_id = @{0};", this.selectedGroupId);

                    reader.ExecWholeRow((count, record) => {
                            int actionId     = -1;
                            DateTime actDate = DateTime.Now;
                            int actValue     = -1;

                            actionId = record.ToInt("action_id");
                            actDate  = record.ToDateTime("act_time");
                            actValue = record.ToInt("act_value");
                            bookId   = record.ToInt("book_id");
                            itemId   = record.ToInt("item_id");
                            shopName = record["shop_name"];
                            remark   = record["remark"];

                            DateValueViewModel vm = new DateValueViewModel()
                            {
                                ActionId = actionId,
                                ActDate  = actDate,
                                ActValue = Math.Abs(actValue)
                            };

                            balanceKind = Math.Sign(actValue) > 0 ? BalanceKind.Income : BalanceKind.Outgo;     // 収入 / 支出

                            this.groupedActionIdList.Add(vm.ActionId.Value);
                            this.WVM.DateValueVMList.Add(vm);
                            return(true);
                        });
                }
            }
            break;
            }

            using (DaoBase dao = this.builder.Build()) {
                DaoReader reader = await dao.ExecQueryAsync(@"
SELECT book_id, book_name FROM mst_book WHERE del_flg = 0 ORDER BY sort_order;");

                reader.ExecWholeRow((count, record) => {
                    BookViewModel vm = new BookViewModel()
                    {
                        Id = record.ToInt("book_id"), Name = record["book_name"]
                    };
                    bookVMList.Add(vm);
                    if (selectedBookVM == null || bookId == vm.Id)
                    {
                        selectedBookVM = vm;
                    }
                    return(true);
                });
            }

            this.WVM.BookVMList          = bookVMList;
            this.WVM.SelectedBookVM      = selectedBookVM;
            this.WVM.SelectedBalanceKind = balanceKind;

            await this.UpdateCategoryListAsync();

            await this.UpdateItemListAsync(itemId);

            await this.UpdateShopListAsync(shopName);

            await this.UpdateRemarkListAsync(remark);

            #region イベントハンドラの設定
            this.WVM.BookChanged += async() => {
                await this.UpdateCategoryListAsync();

                await this.UpdateItemListAsync();

                await this.UpdateShopListAsync();

                await this.UpdateRemarkListAsync();
            };
            this.WVM.BalanceKindChanged += async() => {
                await this.UpdateCategoryListAsync();

                await this.UpdateItemListAsync();

                await this.UpdateShopListAsync();

                await this.UpdateRemarkListAsync();
            };
            this.WVM.CategoryChanged += async() => {
                await this.UpdateItemListAsync();

                await this.UpdateShopListAsync();

                await this.UpdateRemarkListAsync();
            };
            this.WVM.ItemChanged += async() => {
                await this.UpdateShopListAsync();

                await this.UpdateRemarkListAsync();
            };
            #endregion
        }
Example #4
0
        /// <summary>
        /// フォーム読込完了時
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void ActionListRegistrationWindow_Loaded(object sender, RoutedEventArgs e)
        {
            int?        bookId      = null;
            BalanceKind balanceKind = BalanceKind.Outgo;

            int?   itemId   = null;
            string shopName = null;
            string remark   = null;

            // DBから値を読み込む
            switch (this.WVM.RegMode)
            {
            case RegistrationMode.Add: {
                bookId      = this.selectedBookId;
                balanceKind = BalanceKind.Outgo;
                DateTime actDate = this.selectedDate ?? ((this.selectedMonth == null || this.selectedMonth?.Month == DateTime.Today.Month) ? DateTime.Today : this.selectedMonth.Value);

                if (this.selectedRecordList == null)
                {
                    this.WVM.DateValueVMList.Add(new DateValueViewModel()
                        {
                            ActDate = actDate
                        });
                }
                else
                {
                    foreach (CsvComparisonViewModel.CsvRecord record in this.selectedRecordList)
                    {
                        this.WVM.DateValueVMList.Add(new DateValueViewModel()
                            {
                                ActDate = record.Date, ActValue = record.Value
                            });
                    }
                }
            }
            break;

            case RegistrationMode.Edit:
            case RegistrationMode.Copy: {
                using (DaoBase dao = this.builder.Build()) {
                    DaoReader reader = await dao.ExecQueryAsync(@"
SELECT book_id, item_id, action_id, act_time, act_value, shop_name, remark
FROM hst_action 
WHERE del_flg = 0 AND group_id = @{0};", this.selectedGroupId);

                    reader.ExecWholeRow((count, record) => {
                            int actionId     = -1;
                            DateTime actDate = DateTime.Now;
                            int actValue     = -1;

                            actionId = record.ToInt("action_id");
                            actDate  = record.ToDateTime("act_time");
                            actValue = record.ToInt("act_value");
                            bookId   = record.ToInt("book_id");
                            itemId   = record.ToInt("item_id");
                            shopName = record["shop_name"];
                            remark   = record["remark"];

                            DateValueViewModel vm = new DateValueViewModel()
                            {
                                ActionId = actionId,
                                ActDate  = actDate,
                                ActValue = Math.Abs(actValue)
                            };

                            balanceKind = Math.Sign(actValue) > 0 ? BalanceKind.Income : BalanceKind.Outgo; // 収入 / 支出

                            this.groupedActionIdList.Add(vm.ActionId.Value);
                            this.WVM.DateValueVMList.Add(vm);
                            return(true);
                        });
                }
            }
            break;
            }

            // WVMに値を設定する
            this.WVM.GroupId             = this.WVM.RegMode == RegistrationMode.Edit ? this.selectedGroupId : null;
            this.WVM.SelectedBalanceKind = balanceKind;

            // リストを更新する
            await this.UpdateBookListAsync(bookId);

            await this.UpdateCategoryListAsync();

            await this.UpdateItemListAsync(itemId);

            await this.UpdateShopListAsync(shopName);

            await this.UpdateRemarkListAsync(remark);

            // イベントハンドラを登録する
            this.RegisterEventHandlerToWVM();
        }