-
Notifications
You must be signed in to change notification settings - Fork 0
/
BackOrder.cs
417 lines (343 loc) · 14.4 KB
/
BackOrder.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
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.Reporting.WinForms;
using ReportEngine.Barcoding;
using System.IO;
using System.Drawing.Imaging;
using System.Drawing.Printing;
using System.Data.SqlClient;
namespace LMSWarehouse
{
public partial class FrmBackOrder : Form
{
string OrderType;
int WarehouseID;
int CompanyID;
private ReportViewerPrint Rep = new ReportViewerPrint();
private Wrapper WS = new Wrapper();
public FrmBackOrder(int fCompanyID, int fWarehouseID, string fOrderType)
{
OrderType = fOrderType;
CompanyID = fCompanyID;
WarehouseID = fWarehouseID;
InitializeComponent();
}
private void FBackOrder_Load(object sender, EventArgs e)
{
RefreshData();
}
private void LoadDetail(int OrderID)
{
DataSet ds = WS.GetStockDetail(OrderID);
dgOrderDetail.DataSource = ds.Tables[0];
}
private void dgOrderDetail_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e)
{
}
private void dgOrderDetail_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (e.RowIndex >= 0)
{
Color c;
if (dgOrderDetail.Rows[e.RowIndex].Cells["QTY"].Value.ToString().Trim() ==
dgOrderDetail.Rows[e.RowIndex].Cells["QTY Processed"].Value.ToString().Trim())
{
c = Color.LightGreen;
}
else
{
c = Color.Pink;
}
try
{
if (int.Parse(dgOrderDetail.Rows[e.RowIndex].Cells["QTY Processed"].Value.ToString()) >
int.Parse(dgOrderDetail.Rows[e.RowIndex].Cells["QTY"].Value.ToString().Trim()))
c = Color.LightGreen;
}
catch
{
}
e.CellStyle.BackColor = c;
}
}
private void dgOrder_SelectionChanged(object sender, EventArgs e)
{
try
{
int OrdID = 0;
if (int.TryParse(dgOrder.CurrentRow.Cells["StockOrder_ID"].Value.ToString(), out OrdID))
{
LoadDetail(OrdID);
}
}
catch
{
int OrdID = 0;
}
}
private void tdBtnNewOrder_Click(object sender, EventArgs e)
{
LMSWarehouse.FrmStockOrder FStockOrder = new FrmStockOrder(CompanyID, WarehouseID, 0, OrderType);
FStockOrder.ShowDialog();
RefreshData();
}
private void tsEditOrder_Click(object sender, EventArgs e)
{
int OrdID = 0;
if (int.TryParse(dgOrder.CurrentRow.Cells["StockOrder_ID"].Value.ToString(), out OrdID))
{
LMSWarehouse.FrmStockOrder FStockOrder = new FrmStockOrder(CompanyID, WarehouseID, OrdID, OrderType);
FStockOrder.ShowDialog();
RefreshData();
}
}
private void RefreshData()
{
if (OrderType.ToUpper() == "SALE")
{
tsBtnReceiveOrder.Visible = false;
toolStripButtonRecFloor.Visible = false;
}
//SqlDataReader ds = WS.GetIncompleteOrders(WarehouseID, OrderType);
//DataTable dt = new DataTable();
// if (ds.HasRows)
// {
// int OrdID = 0;
// dt.Load(ds);
// dgOrder.DataSource = dt;
// if (int.TryParse(dgOrder.CurrentRow.Cells["StockOrder_ID"].Value.ToString(), out OrdID))
// {
// LoadDetail(OrdID);
// }
// }
//Replaced with data reader
DataSet ds = WS.GetIncompleteOrders(WarehouseID, OrderType);
if (ds.Tables[0].Rows.Count > 0)
{
int OrdID = 0;
dgOrder.DataSource = ds.Tables[0];
if (int.TryParse(dgOrder.CurrentRow.Cells["StockOrder_ID"].Value.ToString(), out OrdID))
{
LoadDetail(OrdID);
}
}
}
private void tsBtnReceiveOrder_Click(object sender, EventArgs e)
{
string MType = "PO";
string MDesc = "Purchase Order";
if (OrderType.ToUpper() == "SALE")
{
MDesc = "Sales Order: " + dgOrder.CurrentRow.Cells["OrderReference"].Value.ToString();
MType = "PI";
}
else
{
MDesc = "Purchase Order: " + dgOrder.CurrentRow.Cells["OrderReference"].Value.ToString();
MType = "PO";
}
int OrdID = 0;
if (int.TryParse(dgOrder.CurrentRow.Cells["StockOrder_ID"].Value.ToString(), out OrdID))
{
LMSWarehouse.FrmReceiveOrder FReceiveOrder = new FrmReceiveOrder(OrdID);
FReceiveOrder.ShowDialog();
RefreshData();
//FrmItemScan FItemScan = new FrmItemScan(MType, CompanyID, WarehouseID, 0, OrdID, MDesc);
//FItemScan.ShowDialog();
//RefreshData();
}
else
{
MessageBox.Show("No Order was selected");
}
}
private void toolStripButtonDelete_Click(object sender, EventArgs e)
{
int OrdID = 0;
if (int.TryParse(dgOrder.CurrentRow.Cells["StockOrder_ID"].Value.ToString(), out OrdID))
{
if (dgOrder.CurrentRow.Cells["OrderStatus"].Value.ToString().ToUpper() == "INDUCTED")
{
WS.DeleteStockOrder(OrdID);
RefreshData();
}
else
{
MessageBox.Show("Processing has already begun on this order and can not be deleted");
}
}
}
private void toolStripAllocate_Click(object sender, EventArgs e)
{
bool ValidOrder = false;
int OrderID = 0;
ValidOrder = int.TryParse(dgOrder.CurrentRow.Cells["StockOrder_ID"].Value.ToString(), out OrderID);
if ((ValidOrder) && (MessageBox.Show("Are you sure you want to allocate this purchase order to available sales orders?", "Sales order allocation", MessageBoxButtons.YesNo) == DialogResult.Yes))
{
int OrderAllocated = 0;
DataSet dpo = WS.GetStockDetail(OrderID);
for (int x = 0; x < dpo.Tables[0].Rows.Count; x++)
{
int POStock = int.Parse(dpo.Tables[0].Rows[x]["QTY Processed"].ToString());
if (POStock > 0)
{
if (int.Parse(dpo.Tables[0].Rows[x]["OrderStatus_ID"].ToString()) == 3)
POStock = 0;
DataSet dsa = WS.GetSKUStockOrderDetail(int.Parse(dpo.Tables[0].Rows[x]["Product_ID"].ToString()));
if (dsa.Tables[0].Rows.Count > 0)
{
WS.SetStockFromPutAway(WarehouseID, 99000000, int.Parse(dpo.Tables[0].Rows[x]["QTY Processed"].ToString()),
int.Parse(dpo.Tables[0].Rows[x]["StockOrderDetail_ID"].ToString()));
}
for (int y = 0; y < dsa.Tables[0].Rows.Count; y++)
{
if (POStock > 0)
{
if (POStock >= int.Parse(dsa.Tables[0].Rows[y]["QTY"].ToString()))
{
OrderAllocated = OrderAllocated + 1;
WS.SetStockFromPick(WarehouseID, 99000000, int.Parse(dsa.Tables[0].Rows[y]["QTY"].ToString()),
int.Parse(dsa.Tables[0].Rows[y]["StockOrderDetail_ID"].ToString()));
Rep.PrintDN(int.Parse(dsa.Tables[0].Rows[y]["StockOrder_ID"].ToString()));
POStock = POStock - int.Parse(dsa.Tables[0].Rows[y]["QTY"].ToString());
}
}
}
}
}
if (OrderAllocated > 0)
MessageBox.Show(OrderAllocated.ToString() + " Sales Orders were allocated");
else
MessageBox.Show("No Sales orders matched the items on this Purchase Order.");
}
}
private void toolStripButtonSearch_Click(object sender, EventArgs e)
{
for (int x = 0; x < dgOrder.RowCount; x++)
{
dgOrder.Rows[x].Selected = false;
}
for (int x = 0; x < dgOrder.RowCount; x++)
{
if (dgOrder.Rows[x].Cells["OrderReference"].Value.ToString().ToUpper().Contains(toolStriptxtSearch.Text.ToUpper()))
{
dgOrder.Rows[x].Selected = true;
int OrdID = 0;
if (int.TryParse(dgOrder.Rows[x].Cells["StockOrder_ID"].Value.ToString(), out OrdID))
{
LoadDetail(OrdID);
}
x = dgOrder.RowCount;
}
}
}
private void btnImportOrder_Click(object sender, EventArgs e)
{
Utils ut = new Utils();
foreach (string file in Directory.GetFiles(ut.ImportPath, "*.*"))
{
string MyFileName = Path.GetFileName(file);
string fileResult = CheckImportType(MyFileName);
if (fileResult == "Invalid")
{
MessageBox.Show("Invalid File: " + file);
//File.Move(ImportPath + MyFileName, ImportPath + "sts_delete\\" + MyFileName);
}
else if (fileResult == "Purchase Order")
{
MessageBox.Show(fileResult);
StreamReader xmlReader = new StreamReader(file);
string xml = xmlReader.ReadToEnd();
MessageBox.Show(ut.ImportPOOrderXML(xml, WarehouseID,CompanyID));
}
else if (fileResult == "Sales Order")
{
MessageBox.Show(fileResult);
StreamReader xmlReader = new StreamReader(file);
string xml = xmlReader.ReadToEnd();
MessageBox.Show(ut.ImportSOOrderXML(xml, WarehouseID, CompanyID));
//MessageBox.Show(fileResult);
}
else if (fileResult == "Purchase Order XLS")
{
//MessageBox.Show(fileResult);
//MessageBox.Show(ut.ImportPOOrderXLS(file, WarehouseID, CompanyID));
//MessageBox.Show(fileResult);
}
else if (fileResult == "Sales Order XLS")
{
//MessageBox.Show(fileResult);
//StreamReader xmlReader = new StreamReader(file);
//string xml = xmlReader.ReadToEnd();
//MessageBox.Show(ut.ImportSOOrderXML(xml, WarehouseID, CompanyID));
//MessageBox.Show(fileResult);
}
}
}
private string CheckImportType(string FileName)
{
string Result = FileName.Substring(0, 2);
if (Result.ToUpper() == "PO")
Result = "Purchase Order";
else if (Result.ToUpper() == "SO")
Result = "Sales Order";
else
Result = "Invalid";
string ExcelResult = FileName.Substring(0, 4);
if (ExcelResult.ToUpper() == "SERI")
Result = "Purchase Order XLS";
else if (ExcelResult.ToUpper() == "TEST")
Result = "Sales Order XLS";
return Result;
}
private void toolStripButtonRecFloor_Click(object sender, EventArgs e)
{
string MType = "PO";
string MDesc = "Purchase Order";
if (OrderType.ToUpper() == "SALE")
{
MDesc = "Sales Order: " + dgOrder.CurrentRow.Cells["OrderReference"].Value.ToString();
MType = "PI";
}
else
{
MDesc = "Purchase Order: " + dgOrder.CurrentRow.Cells["OrderReference"].Value.ToString();
MType = "POF";
}
int OrdID = 0;
if (int.TryParse(dgOrder.CurrentRow.Cells["StockOrder_ID"].Value.ToString(), out OrdID))
{
//LMSWarehouse.FrmReceiveOrder FReceiveOrder = new FrmReceiveOrder(OrdID);
//FReceiveOrder.ShowDialog();
//RefreshData();
FrmItemScan FItemScan = new FrmItemScan(MType, CompanyID, WarehouseID, 0, OrdID, MDesc);
FItemScan.ShowDialog();
RefreshData();
}
else
{
MessageBox.Show("No Order was selected");
}
}
private void toolStripButtonCloseOrder_Click(object sender, EventArgs e)
{
WS.UpdateSetOrderStatus(int.Parse(dgOrder.CurrentRow.Cells["StockOrder_ID"].Value.ToString()), 3);
}
private void toolStripButtonDetail_Click(object sender, EventArgs e)
{
FrmItemDetail fItemDetail = new FrmItemDetail(CompanyID, WarehouseID, 0,0, dgOrder.CurrentRow.Cells["OrderReference"].Value.ToString());
fItemDetail.ShowDialog();
}
private void toolStripButtonInterface_Click(object sender, EventArgs e)
{
FrmStockOrderImport fItemDetail = new FrmStockOrderImport(CompanyID, WarehouseID, OrderType);
fItemDetail.ShowDialog();
RefreshData();
}
}
}