예제 #1
0
        /// <summary>
        /// Delete Selected Row from DataGrid and DB
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DeleteExpenseBtn_Click(object sender, RoutedEventArgs e)
        {
            expense exp = ExpenseDataGrid.SelectedItem as expense;

            _expenseAccess.RemoveExpense(exp);
            expDataGrid.Items.Refresh();
        }
        /// <summary>
        /// Fetch selected row from Database, update Grid and DB
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void UpdateBtn_Click(object sender, RoutedEventArgs e)
        {
            var validator = Validate();

            if (validator)
            {
                expense editExp = (from ex in context.expenses
                                   where ex.expense_id == this.expense.expense_id
                                   select ex).Single();

                editExp.expense_name    = formExpenseName.Text;
                editExp.expense_cost    = Double.Parse(formExpenseCost.Text);
                editExp.contractor_name = formContractorName.Text;
                editExp.expense_desc    = formExpenseDescription.Text;
                editExp.expense_type    = expTypeOp.IsChecked == true
                    ? expTypeOp.Content.ToString()
                    : expTypeAdm.Content.ToString();

                context.SaveChanges();
                MainWindow.ExpenseDataGrid.ItemsSource = context.expenses.ToList();

                MessageBoxButton mbBtn   = MessageBoxButton.OK;
                string           header  = "Update Expense";
                string           message = $"Expense id:{editExp.expense_id} has been altered.";
                MessageBoxImage  icon    = MessageBoxImage.Information;
                MessageBoxResult result  = MessageBox.Show(message, header, mbBtn, icon);

                Close();
            }
        }
        /// <summary>
        /// Update Expense Window for Expense CRUD Operations.
        /// </summary>
        /// <param name="id"></param>
        /// <param name="expName"></param>
        /// <param name="expCost"></param>
        /// <param name="ctrName"></param>
        /// <param name="expDesc"></param>
        /// <param name="expType"></param>
        public UpdateExpense()
        {
            InitializeComponent();

            expense = GetSelectedExpense();
            SetFields(expense);
        }
예제 #4
0
        /// <summary>
        /// Creates expense based on provided fields.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ApplyBtn_Click(object sender, RoutedEventArgs e)
        {
            var validator = Validate();

            if (validator)
            {
                //Map Textbox fields to new expense object
                expense expense = new expense
                {
                    expense_name    = formExpenseName.Text,
                    expense_cost    = Double.Parse(formExpenseCost.Text),
                    expense_desc    = formExpenseDescription.Text,
                    contractor_name = formContractorName.Text,
                    expense_type    = expTypeOp.IsChecked == true
                        ? expTypeOp.Content.ToString()
                        : expTypeAdm.Content.ToString()
                };

                //Add expense to DataGrid and DB
                _expenseAccess.AddExpense(expense, propertyId);

                Close();

                MessageBoxButton mbBtn   = MessageBoxButton.OK;
                string           header  = "Add Expense";
                string           message = $"Expense: {expense.expense_name} has been created.";
                MessageBoxImage  icon    = MessageBoxImage.Information;
                MessageBoxResult result  = MessageBox.Show(message, header, mbBtn, icon);
            }
        }
        /// <summary>
        /// Set window fields based on select row
        /// </summary>
        private void SetFields(expense expense)
        {
            formExpenseName.Text        = expense.expense_name;
            formExpenseCost.Text        = expense.expense_cost.ToString("F");
            formContractorName.Text     = expense.contractor_name;
            formExpenseDescription.Text = expense.expense_desc;

            if (expense.expense_type == "Operational")
            {
                expTypeOp.IsChecked = true;
            }
            else if (expense.expense_type == "Administrative")
            {
                expTypeAdm.IsChecked = true;
            }
        }