-
Notifications
You must be signed in to change notification settings - Fork 0
/
frm2dModServRec.cs
215 lines (180 loc) · 8.83 KB
/
frm2dModServRec.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
using System;
using System.Collections;
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;
namespace IOOP
{
public partial class frm2dModServRec : Form
{
public int servID; // servID declared as global, but assigned at line 92
public string username;
public frm2dModServRec(string u)
{
InitializeComponent();
username = u;
dtpickCpDt.Format = DateTimePickerFormat.Custom; // set dateTimePicker to follow Custom Format
dtpickColDt.Format = DateTimePickerFormat.Custom;
}
private void frm2dModServRec_Load(object sender, EventArgs e)
{
dtpickCusForm("hide");
frm2dCtrlEnabled(false);
frm2dBtnEnabled(false);
grabAllServID();
}
private void dtpickCusForm(string soh) // method10: shows or hides dtpickValues, soh --> (show or hide)
{
if (soh == "hide")
{
dtpickCpDt.CustomFormat = " "; // set dateTimePicker to show no value (resemble empty)
dtpickColDt.CustomFormat = " ";
}
else // (soh == "show")
{
dtpickCpDt.CustomFormat = "yyyy-MM-dd"; // set dateTimePicker to show value (with the mentioned format)
dtpickColDt.CustomFormat = "yyyy-MM-dd";
}
}
private void grabAllServID() // method11: grabs all serviceID in services table, differ from grabServID() at frm2b --> (which has paramaters for servDmd and cmbName)
{
cmbServID.Items.Clear(); // clear comboBox items each time method is called, prevent adding redundant serviceIDs
cmbServID.Text = "";
ArrayList allservID = Services.ViewAllServ();
foreach (int i in allservID)
{
cmbServID.Items.Add(i.ToString());
}
// assign SelectedIndex and enable DroppedDownBox inside method (since only this form will use this method), grabServID() at frm2b --> (this part was done outside method)
cmbServID.SelectedIndex = -1;
cmbServID.DroppedDown = true;
}
private void frm2dCtrlEnabled(bool tof) // method12: enable or disable controls, tof --> true or false, DOES NOT include btnUpdate, btnDelete, btnBack & btnView
{
dtpickCpDt.Enabled = tof;
rdbCp.Enabled = tof;
rdbPending.Enabled = tof;
txtRmk.Enabled = tof;
dtpickColDt.Enabled = tof;
}
private void frm2dBtnEnabled(bool tof) // method13: enable or disable buttons, DOES NOT include btnView & btnBack
{
btnUpdate.Enabled = tof;
btnDelete.Enabled = tof;
}
private void btnView_Click(object sender, EventArgs e)
{
// calling class method from Service Report form (frm2c)
if (frm2cServCpRp.cmbVld(cmbServID) != 1) // returns int (0 --> inaccurate info, 1 --> accurate info)
{
cmbServID.Focus();
cmbServID.DroppedDown = true;
}
else
{
frm2dCtrlEnabled(true);
servID = int.Parse(cmbServID.Text); // text at comboBox will be an integer alr after validation, just have to convert to (int) data type
Services obj1 = new Services(servID); // creating obj for validated service_ID by calling constructor
Services.DisplayServRpInfo(obj1); // passing obj1 to the class method, obj1 = o1
// GET
if (obj1.Status == "Completed") // status can never be null, either Pending or Completed
rdbCp.Checked = true;
else
rdbPending.Checked = true;
// Pending Services will have null at all these entries, technically can use && as well, but || is better just in case one accidentally does not return null.
if (obj1.CompletionDt == null || obj1.Remark == null || obj1.CollectionDt == null)
{
dtpickCusForm("hide");
txtRmk.Clear();
frm2dCtrlEnabled(false);
MessageBox.Show("Service ID: " + servID.ToString() +
"\n\nService Status: " + rdbPending.Text +
"\nCompletion Date: nil" +
"\nRemarks: nil" +
"\nCollection Date: nil" +
"\n\nOnly DELETE option is available.", "Pending Record Alert", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
// cannot use method, frm2dBtnEnabled(bool tof) since one is true, the other is false
btnUpdate.Enabled = false;
btnDelete.Enabled = true; // only allow delete option
btnDelete.Focus();
}
else
{
dtpickCpDt.Focus(); // pulls the focus away from comboBox
dtpickCusForm("show"); // set dateTimePicker to show database value ("yyyy-MM-dd")
dtpickCpDt.Value = DateTime.Parse(obj1.CompletionDt);
txtRmk.Text = obj1.Remark;
dtpickColDt.Value = DateTime.Parse(obj1.CollectionDt);
frm2dBtnEnabled(true); // allow both update and delete option
}
}
}
private void btnDelete_Click(object sender, EventArgs e)
{
// confirms with user that he actually wants to delete
DialogResult result = MessageBox.Show("Service ID: " + servID.ToString() +
"\n\nAre you sure you want to delete this service record ?" +
"\n\nProceed: Press Yes" +
"\nCancel: Press No", "Delete Alert", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
if (result == DialogResult.No)
cmbServID.Focus();
else // DialogResultl.Yes
{
Services obj1 = new Services(servID); // servID validated & assigned at line 92, servID is public
// Services.DeleteServRec(obj1) returns string --> (status on whether delete to database was achieved)
MessageBox.Show(Services.DeleteServRec(obj1), "Delete Status", MessageBoxButtons.OK, MessageBoxIcon.Information);
frm2dRefresh();
frm2dBtnEnabled(false);
grabAllServID(); // After DELETE, grab all serviceID again from service table, to reflect changes
}
}
private void btnUpdate_Click(object sender, EventArgs e)
{
// Convert dateTimePicker values to string and desired format
string cpDt = dtpickCpDt.Value.Date.ToString("yyyy-MM-dd");
string colDt = dtpickColDt.Value.Date.ToString("yyyy-MM-dd");
string status;
if (rdbCp.Checked)
status = rdbCp.Text;
else
status = rdbPending.Text;
int cnt = 1;
if (frm2cServCpRp.rmkVld(txtRmk) != 1) // returns int (0 --> inaccurate info, 1 --> accurate info)
{
txtRmk.Focus();
cnt = 0;
}
else if (frm2cServCpRp.dtCheck(dtpickCpDt, dtpickColDt, cpDt) != 1) // returns int (0 --> compDt > collectDt, 1 --> collectDt >= compDt(company policy))
{
dtpickColDt.Focus();
cnt = 0;
}
if (cnt != 0) // all entries validated
{
frm2cServCpRp.updData(servID, cpDt, status, txtRmk.Text, colDt);
frm2dRefresh();
frm2dBtnEnabled(false);
}
}
private void frm2dRefresh() // method14: clear entries and disable controls (resemble frm2d form load appearance)
{
// clear entries
rdbCp.Checked = false;
rdbPending.Checked = false;
txtRmk.Clear();
dtpickCusForm("hide"); // unable to clear dtpick values, so just hide it
// disable controls
frm2dCtrlEnabled(false);
}
private void btnBack_Click(object sender, EventArgs e)
{
frm2aTechHP frmobj = new frm2aTechHP(username);
frmobj.ShowDialog();
}
}
}