-
Notifications
You must be signed in to change notification settings - Fork 0
/
FormEditBudget.cs
97 lines (80 loc) · 2.08 KB
/
FormEditBudget.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
using System;
using System.Windows.Forms;
using Trip_Budget_Tracker.Models.Services;
using Trip_Expense_Tracker;
using Trip_Expense_Tracker.Models.Dto;
using Trip_Expense_Tracker.Models.Interfaces;
using Trip_Expense_Tracker.Models.Repositories;
namespace Trip_Budget_Tracker
{
public partial class FormEditBudget : Form
{
private readonly int _pk;
public FormEditBudget(int pk)
{
_pk = pk;
InitializeComponent();
this.buttonSave.Click += ButtonSave_Click;
this.buttonDelete.Click += ButtonDelete_Click;
this.Load += FormEditBudget_Load;
}
private void FormEditBudget_Load(object sender, EventArgs e)
{
this.Text = "修改預算項目";
this.FormBorderStyle = FormBorderStyle.Fixed3D;
this.MaximizeBox = false;
BindData();
}
private void ButtonDelete_Click(object sender, EventArgs e)
{
new BudgetService(GetRepo()).Delete(_pk);
MessageBox.Show($"項目已刪除!");
{
this.DialogResult = DialogResult.OK;
var container = this.Owner as IDataContainer;
if (container != null)
{
container.Display();
this.DialogResult = DialogResult.OK;
}
else
{
MessageBox.Show("Owner 表單沒有實作IDateContainer介面");
this.DialogResult = DialogResult.OK;
}
}
}
private void ButtonSave_Click(object sender, EventArgs e)
{
var service = new BudgetService(GetRepo());
BudgetDto dto = new BudgetDto
{
Budgno = _pk,
Name = textBox1.Text,
//Budgno = int.TryParse(textBox2.Text, out int value) ? value : 0
};
service.Update(dto);
MessageBox.Show($"項目已更新");
var container = this.Owner as IDataContainer;
if (container != null)
{
container.Display();
}
else
{
MessageBox.Show("Owner 表單沒有實作IDateContainerur介面");
this.DialogResult = DialogResult.OK;//關閉自己
}
}
private void BindData()
{
BudgetDto model = new BudgetService(GetRepo()).Get(_pk);
textBox1.Text = model.Name;
textBox2.Text = model.Budgno.ToString();
}
private IBudgetRepository GetRepo()
{
return new BudgetEFRepo();
}
}
}