-
Notifications
You must be signed in to change notification settings - Fork 0
/
FormCreateExpense.cs
71 lines (59 loc) · 1.56 KB
/
FormCreateExpense.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Trip_Expense_Tracker.Models;
using Trip_Expense_Tracker.Models.Dto;
using Trip_Expense_Tracker.Models.Interfaces;
using Trip_Expense_Tracker.Models.Repositories;
using Trip_Expense_Tracker.Models.Services;
namespace Trip_Expense_Tracker
{
public partial class FormCreateExpense : Form
{
public FormCreateExpense()
{
InitializeComponent();
this.Load += FormCreateExpense_Load;
this.buttonSave.Click += buttonSave_Click;
}
private void FormCreateExpense_Load(object sender, EventArgs e)
{
this.Text = "新增消費項目";
this.FormBorderStyle = FormBorderStyle.Fixed3D;
this.MaximizeBox = false;
}
private IExpenseRepository GetRepo()
{
return new ExpenseEFRepo();
}
private void buttonSave_Click(object sender, EventArgs e)
{
ExpenseDto dto = new ExpenseDto()
{
Name = textBox1.Text,
Expeno= int.TryParse(textBox2.Text, out int value) ? value : 0
};
int newData = new ExpenseService(GetRepo()).Create(dto);
MessageBox.Show($"消費項目已更新!");
var container = this.Owner as IDataContainer;
if (container != null)
{
container.Display();
this.DialogResult = DialogResult.OK;
}
else
{
MessageBox.Show("Owner 表單沒有實作IDateContainerur介面");
this.DialogResult = DialogResult.OK;
}
}
}
}