-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCustomer_Details.cs
154 lines (148 loc) · 5.83 KB
/
Customer_Details.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
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 System.IO;
using System.Text.RegularExpressions;
namespace GAD_Cousework._01
{
public partial class Customer_Details : MetroFramework.Forms.MetroForm
{
public Customer_Details()
{
InitializeComponent();
}
DBConnection obj = new DBConnection();
private void Customer_Details_Load(object sender, EventArgs e)
{
error_msg.Text = "";
}
private void Btn_search_Click_1(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(txt_cusid.Text))
{
error_msg.Text = "Please Enter the Customer ID. Ex:C001";
txt_cusid.Focus();
}
else
{
string query = "SELECT * FROM Customer WHERE Customer_ID='" + txt_cusid.Text + "'";
metroGrid_customer.DataSource = obj.Display(query);
}
}
private void Btn_update_Click_1(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(txt_cusid.Text))
{
error_msg.Text = "Please Enter the Customer ID. Ex:C001";
txt_cusid.Focus();
}
else if (string.IsNullOrEmpty(txt_cusfname.Text))
{
error_msg.Text = "First Name cannot be blank";
txt_cusfname.Focus();
}
else if (txt_cusfname.Text.Any(char.IsDigit))
{
error_msg.Text = "First Name cannot have numbers";
txt_cusfname.Focus();
}
else if (string.IsNullOrEmpty(txt_cuslname.Text))
{
error_msg.Text = "Last Name cannot be blank";
txt_cuslname.Focus();
}
else if (txt_cuslname.Text.Any(char.IsDigit))
{
error_msg.Text = "Last Name cannot have numbers";
txt_cuslname.Focus();
}
else if (txt_cusemail.Text.Length == 0)
{
error_msg.Text = "Please Enter Email Address";
txt_cusemail.Focus();
}
else if (!Regex.IsMatch(txt_cusemail.Text, @"^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$"))
{
error_msg.Text = "Enter a valid email. Ex:[email protected]";
txt_cusemail.Focus();
}
else if (!Regex.IsMatch(txt_cusphoneno.Text, @"^(?:7|0|(?:\+94))[0-9]{8,9}$"))
{
error_msg.Text = "Phone No must have 10 numbers";
txt_cusphoneno.Focus();
}
else if (string.IsNullOrEmpty(txt_cusaddress.Text))
{
error_msg.Text = "Address cannot be blank";
txt_cusaddress.Focus();
}
else if (string.IsNullOrEmpty(txt_cusnicno.Text))
{
error_msg.Text = "NIC NO cannot be blank";
txt_cusnicno.Focus();
}
else if (txt_cusnicno.Text.Length > 12)
{
error_msg.Text = "Please Enter a valid NIC NO";
txt_cusnicno.Focus();
}
else
{
try
{
error_msg.Text = "";
string query = "UPDATE Customer SET First_Name='" + txt_cusfname.Text + "',Last_Name='" + txt_cuslname.Text + "',Email='" + txt_cusemail.Text + "',Phone_No='" + txt_cusphoneno.Text + "',Address='" + txt_cusaddress.Text + "',NIC='" + txt_cusnicno.Text + "' WHERE Customer_ID='" + txt_cusid.Text + "'";
int line = obj.Save_Update_Delete(query);
if (line == 1)
MessageBox.Show("Data Saved Successfuly", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
else
MessageBox.Show("Data is Not Saved.Check Again", "Info", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
catch (Exception)
{
MessageBox.Show("Check Again", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void Btn_delete_Click_1(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(txt_cusid.Text))
{
error_msg.Text = "Please Enter the Customer ID. Ex:C001";
txt_cusid.Focus();
}
else
{
try
{
string query = "DELETE FROM Customer WHERE Customer_ID='" + txt_cusid.Text + "'";
int line = obj.Save_Update_Delete(query);
if (line == 1)
MessageBox.Show("Data deleted Successfuly", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
else
MessageBox.Show("Data is Not Deleted", "Info", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
catch (Exception)
{
MessageBox.Show("Check Again", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void Btn_clear_Click_1(object sender, EventArgs e)
{
txt_cusid.Clear();
txt_cusfname.Clear();
txt_cuslname.Clear();
txt_cusemail.Clear();
txt_cusphoneno.Clear();
txt_cusnicno.Clear();
txt_cusaddress.Clear();
}
}
}