-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddtocat.cs
316 lines (267 loc) · 10.6 KB
/
addtocat.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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
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 static System.Windows.Forms.VisualStyles.VisualStyleElement;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Button;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.ToolBar;
namespace The_Christie_NHS___Stock_control_program
{
public partial class addtocat : Form
{
public addtocat()
{
InitializeComponent();
}
private void addtocat_Load(object sender, EventArgs e)
{
}
private void assignedcheckBox_CheckedChanged(object sender, EventArgs e)
{
if (stockedcheckBox.Checked)
{
assignedcheckBox.Checked = false;
}
}
private void stockedcheckBox_CheckedChanged(object sender, EventArgs e)
{
if (assignedcheckBox.Checked)
{
stockedcheckBox.Checked = false;
}
}
// Return to main menu button
private void return_to_main_menu_Click(object sender, EventArgs e)
{
Application.Restart();
Environment.Exit(0);
}
private void label7_Click(object sender, EventArgs e)
{
}
private void csvlistbox_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void loadbutton_Click(object sender, EventArgs e)
{
// Pull directory path from settings
string directory_path;
using (var streamReader = new StreamReader(@"database_dir.txt", Encoding.UTF8))
{
directory_path = streamReader.ReadToEnd();
}
// Open csv file
string csvpath = (@$"{directory_path}\catagories.csv");
string[] csvlines = System.IO.File.ReadAllLines(csvpath);
// Display 1st column of csv in textbox
foreach (string csvline in csvlines)
{
string[] csvvalues = csvline.Split(',');
csvlistbox.Items.Add(csvvalues[0]);
}
// Disable the button
loadbutton.Enabled = false;
// Change text to "Loaded"
loadbutton.Text = "Loaded";
}
private void button2_Click(object sender, EventArgs e)
{
// If no selection has been made on the listbox, display error message
if (csvlistbox.SelectedIndex == -1)
{
MessageBox.Show("Please select a catagory from the list");
}
else
{
selectedcatagorybox.Text = csvlistbox.SelectedItem.ToString();
// Unlock / enable input boxes
serialnumberbox.Enabled = true;
assignedcheckBox.Enabled = true;
stockedcheckBox.Enabled = true;
ticketnumberbox.Enabled = true;
ordernumberbox.Enabled = true;
commentbox.Enabled = true;
bulkmodecheckbox.Enabled = true;
altkeyenter.Enabled = true;
bulkmodecheckbox.Checked = false;
// Change label colours
label6.ForeColor = SystemColors.Highlight;
label5.ForeColor = SystemColors.Highlight;
assignedcheckBox.ForeColor = SystemColors.Highlight;
stockedcheckBox.ForeColor = SystemColors.Highlight;
label9.ForeColor = SystemColors.Highlight;
label10.ForeColor = SystemColors.Highlight;
label7.ForeColor = SystemColors.Highlight;
}
}
private void storebutton_Click(object sender, EventArgs e)
{
// Adds the serial number to the selected model's .csv file
// Pull directory path from settings
string directory_path;
using (var streamReader = new StreamReader(@"database_dir.txt", Encoding.UTF8))
{
directory_path = streamReader.ReadToEnd();
}
// Acquire catagory .csv file name
string selected_catagory = selectedcatagorybox.Text.Replace(" ", string.Empty);
// If serial number is already in .csv
if (File.ReadLines(@$"{directory_path}\{selected_catagory}.csv").Any(line => line.Contains(serialnumberbox.Text)))
{
// Error message
MessageBox.Show($"Serial number {serialnumberbox.Text.ToString()} already exists in database");
// Clear boxes
serialnumberbox.Text = "";
if (bulkmodecheckbox.Checked == false)
{
ticketnumberbox.Text = "";
ordernumberbox.Text = "";
commentbox.Text = "";
}
else
{
// Dont clear boxes
}
}
else
{
// serial number doesn't exist
// Assigned or stocked decider
string assignedorstocked;
// If assigned checkbox is checked, assignedorstocked = "Assigned"
if (assignedcheckBox.Checked)
{
assignedorstocked = "Assigned";
}
// If stocked checkbox is checked, assignedorstocked = "Stocked"
else if (stockedcheckBox.Checked)
{
assignedorstocked = "Stocked";
}
// If neither are checked, assignedorstocked == ""
else
{
assignedorstocked = "";
}
// Set variable 'dateandtime' to current date and time
string dateandtime = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss");
// Append data to the .csv
System.IO.File.AppendAllText(@$"{directory_path}\{selected_catagory}.csv", serialnumberbox.Text + "," + assignedorstocked + "," + ticketnumberbox.Text + "," + ordernumberbox.Text + "," + commentbox.Text + "," + dateandtime + "," + Environment.NewLine);
// Set button text to "Stored" and coloured green
storebutton.Text = "Stored";
storebutton.ForeColor = Color.Green;
// Change stockedstatus label
stockedstatus.Text = (serialnumberbox.Text + " stocked.");
// Clear input boxes after submit
serialnumberbox.Text = "";
if (bulkmodecheckbox.Checked == false)
{
ticketnumberbox.Text = "";
ordernumberbox.Text = "";
commentbox.Text = "";
stockedcheckBox.Checked = false;
assignedcheckBox.Checked = false;
}
else
{
}
}
}
private void storebutton_KeyDown(object sender, KeyEventArgs e)
{
// Allows the user to use the 'enter' key to press the button
if (e.KeyCode == Keys.Enter)
storebutton.PerformClick();
}
private void serialnumberbox_TextChanged(object sender, EventArgs e)
{
// If serialnumberbox contains text, enable store button
if (serialnumberbox.Text.Length > 0 && selectedcatagorybox.Text.Length > 0)
{
storebutton.Enabled = true;
storebutton.Text = "Store";
storebutton.ForeColor = Color.Black;
}
else
{
storebutton.Enabled = false;
}
}
private void selectedcatagorybox_TextChanged(object sender, EventArgs e)
{
// If selectedcatagorybox contains text, enable store button
if (serialnumberbox.Text.Length > 0 && selectedcatagorybox.Text.Length > 0)
{
storebutton.Enabled = true;
storebutton.Text = "Store";
storebutton.ForeColor = Color.Black;
}
else
{
storebutton.Enabled = false;
}
}
private void label10_Click(object sender, EventArgs e)
{
}
private void textBox3_TextChanged(object sender, EventArgs e)
{
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void ordernumberbox_TextChanged(object sender, EventArgs e)
{
}
private void bulkmodecheckbox_CheckedChanged(object sender, EventArgs e)
{
if (bulkmodecheckbox.Checked == true)
{
// Change text colours
label5.ForeColor = SystemColors.ControlText;
assignedcheckBox.ForeColor = SystemColors.ControlText;
stockedcheckBox.ForeColor = SystemColors.ControlText;
label7.ForeColor = SystemColors.ControlText;
label9.ForeColor = SystemColors.ControlText;
label10.ForeColor = SystemColors.ControlText;
// Change optional text
label6.ForeColor = SystemColors.ControlText;
label6.Text = "(Bulk mode enabled)";
label6.Location = new Point(524, 174);
}
if (bulkmodecheckbox.Checked == false)
{
// Change text colours
label5.ForeColor = SystemColors.Highlight;
assignedcheckBox.ForeColor = SystemColors.Highlight;
stockedcheckBox.ForeColor = SystemColors.Highlight;
label7.ForeColor = SystemColors.Highlight;
label9.ForeColor = SystemColors.Highlight;
label10.ForeColor = SystemColors.Highlight;
// Change optional text
label6.ForeColor = SystemColors.Highlight;
label6.Text = "(Optional)";
label6.Location = new Point(552, 174);
}
}
private void label5_Click(object sender, EventArgs e)
{
}
private void altkeyenter_CheckedChanged(object sender, EventArgs e)
{
if (altkeyenter.Checked == true)
{
// When the 'Enter' key is pressed, the 'Store' button is pressed
this.AcceptButton = storebutton;
}
}
private void stockedstatus_Click(object sender, EventArgs e)
{
}
}
}