-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCustomer.cs
140 lines (130 loc) · 7.71 KB
/
Customer.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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Furniture_System
{
public partial class Customer : MetroFramework.Forms.MetroForm
{
public Customer(string un)
{
InitializeComponent();
UN = un;
}
FurnitureDB FurDB = new FurnitureDB();
string UN;
private void btn_Back_Click(object sender, EventArgs e)
{
this.Hide();
Dashboard obj = new Dashboard(UN);
obj.Show();
}
private void Customer_FormClosed(object sender, FormClosedEventArgs e)
{
Dashboard obj = new Dashboard(UN);
obj.Show();
}
private void btn_search_Click(object sender, EventArgs e)
{
try
{
if (txt_search.Text.Length != 0)
metroGrid_Cus.DataSource = FurDB.getData("select Fname as [First name],Lname as [Last name],NIC as [NIC no],AdrsL1 as [Address line1],AdrsL2 as [Address line2],AdrsL3 as [Address line3],Customer_No as [Contact No] from Customer where Fname like '"+txt_search.Text+"%'");
if (txt_search.Text.Length == 0)
metroGrid_Cus.DataSource = FurDB.getData("select Fname as [First name],Lname as [Last name],NIC as [NIC no],AdrsL1 as [Address line1],AdrsL2 as [Address line2],AdrsL3 as [Address line3],Customer_No as [Contact No] from Customer");
}
catch (Exception)
{
MetroFramework.MetroMessageBox.Show(this, "Please check again!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
FurDB.CloseCon();
}
}
private void btn_update_Click(object sender, EventArgs e)
{
try
{
if ((txt_Fname.Text.Length != 0) && (txt_Lname.Text.Length != 0) && (txt_NIC.Text.Length != 0) && (txt_AdrsL1.Text.Length != 0) && (txt_AdrsL2.Text.Length != 0) && (txt_Customer_No.Text.Length != 0) && (txt_Customer_No.Text.Length == 10) && (txt_Customer_No.Text.Any(char.IsDigit)) && txt_Fname.Text.All(char.IsLetter) && txt_Lname.Text.All(char.IsLetter))
{
if ((FurDB.Insert_Update_Delete("update Customer set Fname='" + txt_Fname.Text + "',Lname='" + txt_Lname.Text + "',AdrsL1='" + txt_AdrsL1.Text + "',AdrsL2='" + txt_AdrsL2.Text + "',AdrsL3='" + txt_AdrsL3.Text + "',Customer_No='" + txt_Customer_No.Text + "' where NIC='" + txt_NIC.Text + "'") == 1))
{
MetroFramework.MetroMessageBox.Show(this, "Updated successfully!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
txt_Fname.Clear(); txt_Lname.Clear(); txt_NIC.Clear(); txt_AdrsL1.Clear(); txt_AdrsL2.Clear(); txt_AdrsL3.Clear(); txt_Customer_No.Clear(); metroGrid_CusDetails.DataSource = null;
}
else
MetroFramework.MetroMessageBox.Show(this, "Data cannot update!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
MetroFramework.MetroMessageBox.Show(this, "Please enter all fields!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
catch(Exception)
{
MetroFramework.MetroMessageBox.Show(this, "Please check again!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
FurDB.CloseCon();
}
}
private void btn_search2_Click(object sender, EventArgs e)
{
try
{
if (txt_search2.Text.Length != 0)
metroGrid_CusDetails.DataSource = FurDB.getData("select Fname as [First name],Lname as [Last name],NIC as [NIC no],AdrsL1 as [Address line1],AdrsL2 as [Address line2],AdrsL3 as [Address line3],Customer_No as [Contact No] from Customer where Fname like '" + txt_search2.Text + "%'");
if (txt_search2.Text.Length == 0)
metroGrid_CusDetails.DataSource = FurDB.getData("select Fname as [First name],Lname as [Last name],NIC as [NIC no],AdrsL1 as [Address line1],AdrsL2 as [Address line2],AdrsL3 as [Address line3],Customer_No as [Contact No] from Customer");
}
catch (Exception)
{
MetroFramework.MetroMessageBox.Show(this, "Please check again!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
FurDB.CloseCon();
}
}
private void metroGrid_CusDetails_CellClick(object sender, DataGridViewCellEventArgs e)
{
txt_Fname.Text = metroGrid_CusDetails.CurrentRow.Cells[0].Value.ToString();
txt_Lname.Text = metroGrid_CusDetails.CurrentRow.Cells[1].Value.ToString();
txt_NIC.Text = metroGrid_CusDetails.CurrentRow.Cells[2].Value.ToString();
txt_AdrsL1.Text = metroGrid_CusDetails.CurrentRow.Cells[3].Value.ToString();
txt_AdrsL2.Text = metroGrid_CusDetails.CurrentRow.Cells[4].Value.ToString();
txt_AdrsL3.Text = metroGrid_CusDetails.CurrentRow.Cells[5].Value.ToString();
txt_Customer_No.Text = metroGrid_CusDetails.CurrentRow.Cells[6].Value.ToString();
}
private void btn_clear_Click(object sender, EventArgs e)
{
txt_Fname.Clear();txt_Lname.Clear();txt_NIC.Clear();txt_AdrsL1.Clear();txt_AdrsL2.Clear();txt_AdrsL3.Clear();txt_Customer_No.Clear();metroGrid_CusDetails.DataSource = null;
}
private void btn_remove_Click(object sender, EventArgs e)
{
try
{
if ((txt_Fname.Text.Length != 0) && (txt_Lname.Text.Length != 0) && (txt_NIC.Text.Length != 0) && (txt_AdrsL1.Text.Length != 0) && (txt_AdrsL2.Text.Length != 0) && (txt_Customer_No.Text.Length != 0))
{
if (FurDB.readData("select * from Full_Receipt where Cus_ID='"+txt_NIC.Text+"'")==false || FurDB.readData("select * from Installment_Receipt where Cust_ID='"+txt_NIC.Text+"'")==false)
{
if (MetroFramework.MetroMessageBox.Show(this, "Do you want to remove?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes)
{
if (FurDB.Insert_Update_Delete("delete from Customer where NIC = '" + txt_NIC.Text + "'") == 1)
{
MetroFramework.MetroMessageBox.Show(this, "Customer removed successfully!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
txt_Fname.Clear(); txt_Lname.Clear(); txt_NIC.Clear(); txt_AdrsL1.Clear(); txt_AdrsL2.Clear(); txt_AdrsL3.Clear(); txt_Customer_No.Clear(); metroGrid_CusDetails.DataSource = null;
}
else
MetroFramework.MetroMessageBox.Show(this, "Customer cannot remove!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
else
MetroFramework.MetroMessageBox.Show(this, "Customer already bought an Item(s)!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
MetroFramework.MetroMessageBox.Show(this, "Please enter all fields!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
catch (Exception)
{
MetroFramework.MetroMessageBox.Show(this, "Please check again!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
FurDB.CloseCon();
}
}
}
}