Example #1
0
        private void InitializeCategories()
        {
            //unsub from events
            foreach (var item in spCategories.Children)
            {
                EditableItemControl control = (EditableItemControl)item;
                control.btnEditItem.Click   -= BtnEditCategory_Click;
                control.btnDeleteItem.Click -= BtnDeleteCategory_Click;
            }

            spCategories.Children.Clear();

            // get categories from db
            List <OperationTypeDto> categories = _operationTypeRepo.All();

            foreach (OperationTypeDto category in categories)
            {
                EditableItemControl item = new EditableItemControl();

                item.lblName.Content = category.Name;
                item.Id = category.Id;
                item.btnEditItem.Click   += BtnEditCategory_Click;
                item.btnDeleteItem.Click += BtnDeleteCategory_Click;

                spCategories.Children.Add(item);
            }
        }
Example #2
0
        private void InitializeAccounts()
        {
            //unsub from events
            foreach (var item in spAccounts.Children)
            {
                EditableItemControl control = (EditableItemControl)item;
                control.btnEditItem.Click   -= BtnEditAccount_Click;
                control.btnDeleteItem.Click -= BtnDeleteAccount_Click;
            }

            spAccounts.Children.Clear();

            //get accounts from db
            List <AccountDto> accounts = _accountRepo.All();

            foreach (AccountDto account in accounts)
            {
                EditableItemControl item = new EditableItemControl();

                item.lblName.Content = account.Name + " " + account.Currency.Name;
                item.Id = account.Id;
                item.btnEditItem.Click   += BtnEditAccount_Click;
                item.btnDeleteItem.Click += BtnDeleteAccount_Click;

                spAccounts.Children.Add(item);
            }
        }
Example #3
0
        private OperationTypeDto GetClickedCategory(object sender)
        {
            //get button parent until we reach the user control (Editable Item Control)
            DependencyObject ucParent = ((Button)sender).Parent;

            while (!(ucParent is UserControl))
            {
                ucParent = LogicalTreeHelper.GetParent(ucParent);
            }

            // cast to specific type from UserControl
            EditableItemControl userControl = (EditableItemControl)ucParent;

            //Get from Db the account with the id of the UserControl
            OperationTypeDto category = _operationTypeRepo.Get(userControl.Id);

            return(category);
        }