-
Notifications
You must be signed in to change notification settings - Fork 0
/
frm3bCusCS.cs
204 lines (196 loc) · 7.23 KB
/
frm3bCusCS.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace IOOP
{
public partial class frm3bCusCS : Form
{
int price = 0;
string rqDate, nu;
int servcIid;
DateTime aDate = DateTime.Now;// Get the current time
public static string cusName;
static SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["myCS"].ToString());
public void showData()// Show the updated data
{
con.Open();
// Select data according the customer name and services status are pending
SqlDataAdapter sqlda = new SqlDataAdapter("select " +
"id, customerName, serviceType, serviceDemand, fee, requestDate, stat " +
"from services where customerName = '" + cusName + "' and status = 'pending'", con);
// Create a new table
DataTable ftbl = new DataTable();
sqlda.Fill(ftbl);// Adds the dataset into table
dgvCusCs.AutoGenerateColumns = false;// Stop auto generate one more columns in last column
dgvCusCs.DataSource = ftbl;// This DataGridView will display data for this table(ftb)
con.Close();
}
private void dgvCusCs_CellContentClick_1(object sender, DataGridViewCellEventArgs e)
{
servcIid = Convert.ToInt32(dgvCusCs.Rows[e.RowIndex].Cells[0].Value);// To get the service id
lstCusSt.Text = dgvCusCs.Rows[e.RowIndex].Cells[2].Value.ToString();// To get the data of grid view in listbox
}
public frm3bCusCS()
{
InitializeComponent();
}
public frm3bCusCS(string cn)
{
InitializeComponent();
cusName = cn;
}
private void btnCuscm_Click(object sender, EventArgs e)// Assign the fee of the service chosen
{
if (lstCusSt.SelectedIndex == 0)
{
if (rbtnN.Checked == true)
{
nu = "normal";
price = 50;
txtCheck.Text = price.ToString();
}
else if (rbtnU.Checked == true)
{
nu = "urgent";
price = 80;
txtCheck.Text = price.ToString();
}
}
else if (lstCusSt.SelectedIndex == 1)
{
if (rbtnN.Checked)
{
nu = "normal";
price = 60;
txtCheck.Text = price.ToString();
}
else if (rbtnU.Checked)
{
nu = "urgent";
price = 90;
txtCheck.Text = price.ToString();
}
}
else if (lstCusSt.SelectedIndex == 2)
{
if (rbtnN.Checked)
{
nu = "normal";
price = 380;
txtCheck.Text = price.ToString();
}
else if (rbtnU.Checked)
{
nu = "urgent";
price = 430;
txtCheck.Text = price.ToString();
}
}
else if (lstCusSt.SelectedIndex == 3)
{
if (rbtnN.Checked)
{
nu = "normal";
price = 160;
txtCheck.Text = price.ToString();
}
else if (rbtnU.Checked)
{
nu = "urgent";
price = 200;
txtCheck.Text = price.ToString();
}
}
else if (lstCusSt.SelectedIndex == 4)
{
if (rbtnN.Checked)
{
nu = "normal";
price = 180;
txtCheck.Text = price.ToString();
}
else if (rbtnU.Checked)
{
nu = "urgent";
price = 210;
txtCheck.Text = price.ToString();
}
}
else if (lstCusSt.SelectedIndex == 5)
{
if (rbtnN.Checked)
{
nu = "normal";
price = 100;
txtCheck.Text = price.ToString();
}
else if (rbtnU.Checked)
{
nu = "urgent";
price = 150;
txtCheck.Text = price.ToString();
}
}
else if (lstCusSt.SelectedIndex == 6)
{
if (rbtnN.Checked)
{
nu = "normal";
price = 80;
txtCheck.Text = price.ToString();
}
else if (rbtnU.Checked)
{
nu = "urgent";
price = 130;
txtCheck.Text = price.ToString();
}
}
else if (lstCusSt.SelectedIndex == 7)
{
if (rbtnN.Checked)
{
nu = "normal";
price = 70;
txtCheck.Text = price.ToString();
}
else if (rbtnU.Checked)
{
nu = "urgent";
price = 100;
txtCheck.Text = price.ToString();
}
}
}
private void btnUcs_Click(object sender, EventArgs e)
{
rqDate = aDate.ToString("yyyy-MM-dd");// Get the current time
Services obj1 = new Services(servcIid);
obj1.updateService(lstCusSt.Text, nu, price, rqDate);// Enter the data of changed service into database
MessageBox.Show("Successful change!");
txtCheck.Clear();// Clear this textbox when completed service changed
showData();// Show the updated data
}
private void frm3bCusCS_Load(object sender, EventArgs e)
{
con.Open();
// Select data according the customer name and services status are pending
SqlDataAdapter sqlda = new SqlDataAdapter("select " +
"id, customerName, serviceType, serviceDemand, fee, requestDate, stat " +
"from services where customerName = '" + cusName + "' and status = 'pending'", con);
DataTable ftbl = new DataTable();// Create a new table
sqlda.Fill(ftbl);// Adds the dataset into table
dgvCusCs.AutoGenerateColumns = false;// Stop auto generate one more columns in last column
dgvCusCs.DataSource = ftbl;// This DataGridView will display data for this table(ftbl)
con.Close();
}
}
}