-
Notifications
You must be signed in to change notification settings - Fork 0
/
ItemScan.cs
287 lines (241 loc) · 9.71 KB
/
ItemScan.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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Media;
namespace LMSWarehouse
{
public partial class FrmItemScan : Form
{
public int FromBinID = 0;
public int QtyMax = 0;
private string StockMoveType;
private int CompanyID;
private int WarehouseID;
private int UserID;
private int StockMoveOriginID;
private string MoveName;
private int StockMove = 0;
SoundPlayer spDuplicate;
SoundPlayer spAccept;
SoundPlayer spInvalid;
private Wrapper WS = new Wrapper();
public FrmItemScan(string fStockMoveType, int fCompanyID, int fWarehouseID, int fUserID, int fStockMoveOriginID, string fMoveName)
{
StockMoveType = fStockMoveType;
CompanyID = fCompanyID;
WarehouseID = fWarehouseID;
UserID = fUserID;
StockMoveOriginID = fStockMoveOriginID;
MoveName = fMoveName;
InitializeComponent();
}
private void pDetail_Paint(object sender, PaintEventArgs e)
{
}
private void toolStripContainer1_ContentPanel_Load(object sender, EventArgs e)
{
DataSet dt = WS.GetStockMoveType(StockMoveType, CompanyID,WarehouseID);
if (dt.Tables[0].Rows.Count > 0)
{
DataSet dg = null;
if ((StockMoveOriginID != 0) && (FromBinID == 0))
{
dg = WS.GetStockMoveItems(0, StockMoveOriginID);
}
else if (dt.Tables[0].Rows[0]["FromBin_ID"].ToString() != "0")
{
dg = WS.GetStockMoveItems(int.Parse(dt.Tables[0].Rows[0]["FromBin_ID"].ToString()), 0);
}
else if (FromBinID != 0)
{
dg = WS.GetStockMoveItems(FromBinID, 0);
lblQtyExpected.Text = QtyMax.ToString();
}
else
{
dg = WS.GetStockMoveItems(0, 0);
}
dgReceive.DataSource = dg.Tables[0];
for (int x = 0; x < dg.Tables[0].Rows.Count; x++)
{
if (dg.Tables[0].Rows[x]["Bin_ID"].ToString() == dt.Tables[0].Rows[0]["Bin_ID"].ToString())
{
lblScans.Items.Add(dg.Tables[0].Rows[x]["ItemBarCode"].ToString());
}
else
{
lbItem.Items.Add(dg.Tables[0].Rows[x]["ItemBarCode"].ToString());
}
}
DataSet sm = WS.GetStockMoveFromOrder(StockMoveOriginID);
if (sm.Tables[0].Rows.Count > 0)
{
StockMove = int.Parse(sm.Tables[0].Rows[0]["StockMove_ID"].ToString());
if (sm.Tables[0].Rows[0]["StockMove_ID"].ToString() == "0")
{
StockMove = WS.SetStockMove(WarehouseID, UserID, DateTime.Now, MoveName, StockMoveType);
WS.SetStockMoveDetailPOSO(StockMove, StockMoveOriginID);
}
}
else
{
StockMove = WS.SetStockMove(WarehouseID, UserID, DateTime.Now, MoveName, StockMoveType);
}
if (dt.Tables[0].Rows[0]["Bin_ID"].ToString() == "0")
{
lblStatus.Text = "Please Scan Bin...";
txtBin.Select();
}
else if (QtyMax > 0)
{
lblScanned.Text = "0";
lblQtyExpected.Text = QtyMax.ToString();
lblStatus.Text = "Please Scan Items...";
txtBin.Text = dt.Tables[0].Rows[0]["Bin_ID"].ToString();
txtBin.Enabled = false;
lblBin.Text = dt.Tables[0].Rows[0]["BinDescription"].ToString();
txtScan.Select();
}
else
{
lblScanned.Text = lblScans.Items.Count.ToString();
lblQtyExpected.Text = (lblScans.Items.Count + lbItem.Items.Count).ToString();
lblStatus.Text = "Please Scan Items...";
txtBin.Text = dt.Tables[0].Rows[0]["Bin_ID"].ToString();
txtBin.Enabled = false;
lblBin.Text = dt.Tables[0].Rows[0]["BinDescription"].ToString();
txtScan.Select();
}
}
else
{
MessageBox.Show("Stock Movement Type not setup Correctly");
Close();
}
}
private void txtScan_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyValue == 13)
{
if (lbItem.Items.Contains(txtScan.Text))
{
if (QtyMax != 0)
{
String searchValue = txtScan.Text;
foreach (DataGridViewRow row in dgReceive.Rows)
{
if (row.Cells["ItemBarCode"].Value.ToString().Equals(searchValue))
{
lblScanned.Text = (int.Parse(lblScanned.Text) + int.Parse(row.Cells["ItemQty"].Value.ToString())).ToString();
}
}
}
else
{
lblScanned.Text = (int.Parse(lblScanned.Text) + 1).ToString();
}
WS.SetItemTrack(StockMove, txtScan.Text, int.Parse(txtBin.Text));
pDetail.BackColor = Color.LightGreen;
lblStatus.Text = "Good Scan";
lblScans.Items.Add(txtScan.Text);
lbItem.Items.Remove(txtScan.Text);
spAccept.Play();
txtScan.Text = "";
if ((int.Parse(lblScanned.Text) >= QtyMax) && (QtyMax != 0))
{
MessageBox.Show("This Order Item is now FullFilled");
AsdjustStock();
Close();
}
}
else if (lblScans.Items.Contains(txtScan.Text))
{
pDetail.BackColor = Color.LightGoldenrodYellow;
lblStatus.Text = "Duplicate Scan";
txtScan.Text = "";
spDuplicate.Play();
}
else
{
pDetail.BackColor = Color.LightPink;
lblStatus.Text = "No Data Received";
txtScan.Text = "";
spInvalid.Play();
}
}
}
private void saveToolStripButton_Click(object sender, EventArgs e)
{
AsdjustStock();
Close();
}
private void AsdjustStock()
{
WS.SetStockMoveDetail(StockMove);
DataSet DL = WS.GetStockMovementPrev(StockMove);
for (int x = 0; x < DL.Tables[0].Rows.Count; x++)
{
WS.SetStockDelFromStockMove(WarehouseID, int.Parse(DL.Tables[0].Rows[x]["Bin_ID"].ToString()), int.Parse(DL.Tables[0].Rows[x]["Qty"].ToString()), int.Parse(DL.Tables[0].Rows[x]["StockMoveDetail_ID"].ToString()));
}
DataSet SA = WS.GetStockMovement(StockMove);
for (int x = 0; x < SA.Tables[0].Rows.Count; x++)
{
WS.SetStockAddFromStockMove(WarehouseID, int.Parse(SA.Tables[0].Rows[x]["Bin_ID"].ToString()), int.Parse(SA.Tables[0].Rows[x]["Qty"].ToString()), int.Parse(SA.Tables[0].Rows[x]["StockMoveDetail_ID"].ToString()));
}
}
private void txtBin_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyValue == 13)
{
try
{
DataSet ds = WS.GetBinBarCode(int.Parse(txtBin.Text));
if (ds.Tables[0].Rows.Count > 0)
{
lblBin.Text = ds.Tables[0].Rows[0]["BinDescription"].ToString();
lblStatus.Text = "Please Scan Items...";
txtBin.Enabled = false;
txtScan.Select();
}
else
{
lblBin.Text = "Bin not found";
txtBin.Text = "";
txtBin.Select();
}
}
catch
{
MessageBox.Show("Invalid barcode was scanned for Bin");
txtBin.Text = "";
txtBin.Select();
}
}
}
private void FrmItemScan_FormClosing(object sender, FormClosingEventArgs e)
{
AsdjustStock();
}
private void FrmItemScan_Load(object sender, EventArgs e)
{
try
{
spDuplicate = new SoundPlayer(@"C:\LMSWarehouse\_duplicate.wav");
spAccept = new SoundPlayer(@"C:\LMSWarehouse\_Accept.wav");
spInvalid = new SoundPlayer(@"C:\LMSWarehouse\_Unknown.wav");
}
catch
{
MessageBox.Show("Sound files are not installed properly");
}
}
private void txtScan_TextChanged(object sender, EventArgs e)
{
}
}
}