-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpdateCustomer.cs
More file actions
95 lines (87 loc) · 2.95 KB
/
Copy pathUpdateCustomer.cs
File metadata and controls
95 lines (87 loc) · 2.95 KB
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using AviationMaintenanceManagementSystem.Features;
using AviationMaintenanceManagementSystem.ModelClasses;
using AviationMaintenanceManagementSystem.Data_CRUDops_;
using System.Drawing.Text;
namespace AviationMaintenanceManagementSystem
{
public partial class UpdateCustomer : Form
{
private readonly ICustomerFeature _customerFeature;
private Customer _currentCustomer;
public UpdateCustomer(ICustomerFeature customerFeature)
{
_customerFeature = customerFeature;
InitializeComponent();
btnSearch.Click += btnSearch_Click;
btnSave.Click += btnSave_Click;
btnCancel.Click += btnCancel_Click;
btnDelete.Click += btnDelete_Click;
}
private void btnSearch_Click(object sender, EventArgs e)
{
_currentCustomer = _customerFeature.GetCustomerById(txtCustomerID.Text);
if (_currentCustomer != null)
{
txtName.Text = _currentCustomer.Name;
txtPhone.Text = _currentCustomer.Phone;
txtEmail.Text = _currentCustomer.Email;
txtAddress.Text = _currentCustomer.Address;
}
else
{
MessageBox.Show("Customer not found");
}
}
private void btnSave_Click(object sender, EventArgs e)
{
if (_currentCustomer != null)
{
_currentCustomer.Name = txtName.Text;
_currentCustomer.Phone = txtPhone.Text;
_currentCustomer.Email = txtEmail.Text;
_currentCustomer.Address = txtAddress.Text;
_customerFeature.UpdateCustomer(_currentCustomer);
MessageBox.Show("Customer Updated");
}
else
{
MessageBox.Show("Invalid Action");
}
}
private void btnCancel_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnDelete_Click(object sender, EventArgs e)
{
if (_currentCustomer != null)
{
_customerFeature.DeleteCustomer(_currentCustomer.CustomerId);
MessageBox.Show("Customer Deleted");
Clearfields();
this.Close();
}
else
{
MessageBox.Show("Invalid Action");
}
}
private void Clearfields()
{
txtCustomerID.Text = string.Empty;
txtName.Text = string.Empty;
txtPhone.Text = string.Empty;
txtEmail.Text = string.Empty;
txtAddress.Text = string.Empty;
}
}
}