-
Notifications
You must be signed in to change notification settings - Fork 0
/
frmActionOrderRequest.cs
265 lines (235 loc) · 8.98 KB
/
frmActionOrderRequest.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
using Microsoft.VisualBasic;
using System;
using System.Windows.Forms;
using UpgradeHelpers.DB.ADO;
using UpgradeHelpers.Helpers;
namespace SKS
{
internal partial class frmActionOrderRequest
: System.Windows.Forms.Form
{
private double currentSubTotal = 0;
private double currentTotal = 0;
private double currentTax = 0;
private double currentFreightCharge = 0;
private double currentTotalTax = 0;
public int Action = 0;
public int OrderId = 0;
public frmActionOrderRequest()
: base()
{
if (m_vb6FormDefInstance == null)
{
if (m_InitializingDefInstance)
{
m_vb6FormDefInstance = this;
}
else
{
try
{
//For the start-up form, the first instance created is the default instance.
if (System.Reflection.Assembly.GetExecutingAssembly().EntryPoint != null && System.Reflection.Assembly.GetExecutingAssembly().EntryPoint.DeclaringType == this.GetType())
{
m_vb6FormDefInstance = this;
}
}
catch
{
}
}
}
//This call is required by the Windows Form Designer.
InitializeComponent();
ReLoadForm(false);
}
private void cmdApprove_Click(Object eventSender, EventArgs eventArgs)
{
try
{
if (txtStatus.Text.ToUpper() == "APPROVED")
{
modMain.LogStatus("Order is already approved, not need to be approved again", this);
return;
}
if (txtStatus.Text.ToUpper() == "CANCELLED")
{
modMain.LogStatus("Order was already approved by " + txtChangedBy.Text + " on " + txtChanged.Text + ", it cannot be approved", this);
return;
}
}
catch (System.Exception excep)
{
//UPGRADE_WARNING: (2081) Err.Number has a new behavior. More Information: https://www.mobilize.net/vbtonet/ewis/ewi2081
MessageBox.Show("An error has occurred adding the data. Error: (" + Information.Err().Number.ToString() + ") " + excep.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void cmdCancel_Click(Object eventSender, EventArgs eventArgs)
{
try
{
if (txtStatus.Text.ToUpper() == "CANCELLED")
{
modMain.LogStatus("Order was already cancelled, not need to be cancelled again", this);
return;
}
if (txtStatus.Text.ToUpper() == "APPROVED")
{
modMain.LogStatus("Order was already cancelled by " + txtChangedBy.Text + " on " + txtChanged.Text + ", it cannot be canceled", this);
return;
}
if (MessageBox.Show("Do you want to cancel the order request?", "Confirm cancellation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != System.Windows.Forms.DialogResult.Yes)
{
return;
}
// UPDATE
modConnection.ExecuteSql("Update OrderRequests Set Status = 'CANCELLED', ChangedBy = '" + modMain.UserId + "', ChangedDate = #" + DateTimeHelper.ToString(DateTime.Today) + "#" +
" Where OrderId = " + OrderId.ToString());
LoadData();
MessageBox.Show("The order was successfully cancelled", Application.ProductName);
this.Close();
}
catch (System.Exception excep)
{
//UPGRADE_WARNING: (2081) Err.Number has a new behavior. More Information: https://www.mobilize.net/vbtonet/ewis/ewi2081
MessageBox.Show("An error has occurred adding the data. Error: (" + Information.Err().Number.ToString() + ") " + excep.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
//UPGRADE_WARNING: (2080) Form_Load event was upgraded to Form_Load method and has a new behavior. More Information: https://www.mobilize.net/vbtonet/ewis/ewi2080
private void Form_Load()
{
//LoadData
if (Action != 0)
{
switch((Action))
{
case 1 :
cmdApprove_Click(cmdApprove, new EventArgs());
break;
case 2 :
cmdCancel_Click(cmdCancel, new EventArgs());
break;
}
}
}
public void LoadData()
{
currentSubTotal = 0;
currentTotalTax = 0;
modConnection.ExecuteSql("Select o.OrderDate, u.Fullname, o.Status, c.CompanyName, c.ContactFirstName + ' ' + c.ContactLastName as Contact, o.ChangedDate, o.ChangedBy, o.FreightCharge, o.SalesTaxRate, o.RequiredByDate, o.PromisedByDate, o.Notes " +
"From OrderRequests as o, Users as u, Customers as c " +
"Where o.OrderID = " + OrderId.ToString() + " And u.Username = o.EmployeeId And c.CustomerId = o.CustomerId");
if (modConnection.rs.EOF)
{
modMain.LogStatus("The order with the ID '" + OrderId.ToString() + "' does not exist", this);
return;
}
txtOrderID.Text = OrderId.ToString();
txtReceived.Text = Convert.ToString(modConnection.rs["OrderDate"]);
txtReceivedBy.Text = Convert.ToString(modConnection.rs["Fullname"]);
//UPGRADE_WARNING: (1049) Use of Null/IsNull() detected. More Information: https://www.mobilize.net/vbtonet/ewis/ewi1049
if (System.DBNull.Value.Equals(modConnection.rs["Notes"]))
{
txtNotes.Text = Convert.ToString(modConnection.rs["Notes"]);
}
txtFreightCharge.Text = Convert.ToString(modConnection.rs["FreightCharge"]);
currentFreightCharge = Convert.ToDouble(modConnection.rs["FreightCharge"]);
txtSalesTax.Text = Convert.ToString(modConnection.rs["SalesTaxRate"]);
currentTax = Convert.ToDouble(modConnection.rs["SalesTaxRate"]);
txtCustomerCompany.Text = Convert.ToString(modConnection.rs["CompanyName"]);
txtCustomerContact.Text = Convert.ToString(modConnection.rs["Contact"]);
txtStatus.Text = Convert.ToString(modConnection.rs["Status"]);
txtRequiredBy.Text = Convert.ToString(modConnection.rs["RequiredByDate"]);
txtPromisedBy.Text = Convert.ToString(modConnection.rs["PromisedByDate"]);
//UPGRADE_WARNING: (1049) Use of Null/IsNull() detected. More Information: https://www.mobilize.net/vbtonet/ewis/ewi1049
if (System.DBNull.Value.Equals(modConnection.rs["ChangedDate"]))
{
txtChanged.Text = Convert.ToString(modConnection.rs["ChangedDate"]);
}
//UPGRADE_WARNING: (1049) Use of Null/IsNull() detected. More Information: https://www.mobilize.net/vbtonet/ewis/ewi1049
if (System.DBNull.Value.Equals(modConnection.rs["ChangedBy"]))
{
txtChangedBy.Text = Convert.ToString(modConnection.rs["ChangedBy"]);
}
bool isRequested = txtStatus.Text == "REQUESTED";
lblChanged.Visible = !isRequested;
lblChangedBy.Visible = !isRequested;
txtChanged.Visible = !isRequested;
txtChangedBy.Visible = !isRequested;
cmdApprove.Enabled = true; // Requested
cmdCancel.Enabled = true; // Requested
if (txtStatus.Text == "APPROVED")
{
lblChanged.Text = "Approved Date:";
lblChangedBy.Text = "Approved By:";
}
else
{
lblChanged.Text = "Cancelled Date:";
lblChangedBy.Text = "Cancelled By:";
}
LoadDetails();
DisplayTotals();
}
private void DisplayTotals()
{
currentTotal = currentFreightCharge + currentSubTotal + currentTotalTax;
txtSubTotal.Text = StringsHelper.Format(currentSubTotal, "#,##0.00");
txtTotalTax.Text = StringsHelper.Format(currentTotalTax, "#,##0.00");
txtTotal.Text = StringsHelper.Format(currentTotal, "#,##0.00");
}
private void AddToTotals(double current)
{
currentSubTotal += current;
currentTotalTax = currentSubTotal * currentTax;
currentTotal = currentFreightCharge + currentSubTotal + currentTotalTax;
txtSubTotal.Text = StringsHelper.Format(currentSubTotal, "#,##0.00");
txtTotalTax.Text = StringsHelper.Format(currentTotalTax, "#,##0.00");
txtTotal.Text = StringsHelper.Format(currentTotal, "#,##0.00");
}
private void cmdClose_Click(Object eventSender, EventArgs eventArgs)
{
this.Close();
}
private void LoadDetails()
{
modConnection.ExecuteSql("Select d.Quantity, p.ProductID, p.ProductName, d.UnitPrice, d.SalePrice, p.UnitsInStock, p.UnitsOnOrder, Str(p.QuantityPerUnit) + p.Unit, d.LineTotal From Products as p, OrderRequestDetails as d " +
"Where d.OrderID = " + OrderId.ToString() + " And d.ProductId = p.ProductId");
int lng = 0;
int intLoopCount = 0;
int i = 0;
fgDetails.RowsCount = 0;
fgDetails.ColumnsCount = 9;
fgDetails.FixedColumns = 0;
fgDetails.AddItem("Quantity" + "\t" + "Code" + "\t" + "Product" + "\t" + "UnitPrice" + "\t" + "Price" + "\t" + "Existence" + "\t" + "Ordered" + "\t" + "Quantity per unit" + "\t" + "Line Total");
fgDetails.RowsCount = modConnection.rs.RecordCount + 1;
if (fgDetails.RowsCount == 1)
{
fgDetails.FixedRows = 0;
}
else
{
fgDetails.FixedRows = 1;
}
i = 1;
while (!modConnection.rs.EOF)
{
int tempForEndVar = modConnection.rs.FieldsMetadata.Count;
for (int j = 1; j <= tempForEndVar; j++)
{
//UPGRADE_WARNING: (2080) IsEmpty was upgraded to a comparison and has a new behavior. More Information: https://www.mobilize.net/vbtonet/ewis/ewi2080
if (modConnection.rs.GetField(i) != null)
{
fgDetails[i, j - 1].Value = Convert.ToString(modConnection.rs[j - 1]);
}
}
AddToTotals(Convert.ToDouble(modConnection.rs["LineTotal"]));
modConnection.rs.MoveNext();
i++;
}
}
private void Form_Closed(Object eventSender, EventArgs eventArgs)
{
}
}
}