-
Notifications
You must be signed in to change notification settings - Fork 4
/
frmAdjustStockManual.cs
484 lines (448 loc) · 19.1 KB
/
frmAdjustStockManual.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
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
using Microsoft.VisualBasic;
using System;
using System.Media;
using UpgradeHelpers.DB.ADO;
using UpgradeHelpers.Helpers;
using Mobilize.WebMap.Common.Attributes;
using Mobilize.Web.Extensions;
namespace SKS
{
[Observable]
internal partial class frmAdjustStockManual
: Mobilize.Web.Form
{
public frmAdjustStockManual()
: base()
{
if ( m_vb6FormDefInstance is 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 is 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 frmAdjustStockManual_Activated(System.Object eventSender, System.EventArgs eventArgs)
{
if ( Stub._UpgradeHelpers.Gui.Utils.ActivateHelper.myActiveForm != eventSender )
{
Stub._UpgradeHelpers.Gui.Utils.ActivateHelper.myActiveForm = (Mobilize.Web.Form)eventSender;
}
}
[Intercepted]
private bool editingData { get; set; } = false;
[Intercepted]
private string currentIdProduct { get; set; } = "";
[Intercepted]
private int currentIdStock { get; set; } = 0;
[Intercepted]
private string currentQuantityPerUnit { get; set; } = "";
[Intercepted]
private string currentUnit { get; set; } = "";
[Intercepted]
private string currentProductName { get; set; } = "";
[Intercepted]
private double currentStockPrice { get; set; } = 0;
[Intercepted]
private double currentStock { get; set; } = 0;
[Intercepted]
private double changedStockPrice { get; set; } = 0;
[Intercepted]
private double changedStock { get; set; } = 0;
[Intercepted]
private bool codeGeneratedChange { get; set; } = false;
[Intercepted]
private double quantity { get; set; } = 0;
[Intercepted]
private double stockPrice { get; set; } = 0;
[Intercepted]
private double unitPrice { get; set; } = 0;
private void cmdClose_Click(Object eventSender, EventArgs eventArgs)
{
this.Close();
}
private void cmdSave_Click(Object eventSender, EventArgs eventArgs)
{
int newStockId = 0;
int newManualLogId = 0;
int newStockLogId = 0;
editingData = false;
try
{
double deltaStockPrice = 0;
double deltaStock = 0;
changedStockPrice = Double.Parse(txtValues[0].Text);
changedStock = Double.Parse(txtValues[1].Text);
deltaStockPrice = changedStockPrice - currentStockPrice;
deltaStock = changedStock - currentStock;
if ( deltaStockPrice == 0 && deltaStock == 0 )
{
modMain.LogStatus("There is no modification of the Stock, the data won't be saved", this);
return ;
}
// UPDATE
modConnection.ExecuteSql("Update Stocks Set StockPrice = " + changedStockPrice.ToString() + ", Stock = " + changedStock.ToString() + " Where StockId = " + currentIdStock.ToString());
// NEW
modConnection.ExecuteSql("Select * from ManualStocks");
modConnection.rs.AddNew();
modConnection.rs["StockID"] = currentIdStock;
modConnection.rs["Quantity"] = deltaStock;
modConnection.rs["Price"] = deltaStockPrice;
modConnection.rs["User"] = modMain.UserId;
modConnection.rs["Date"] = DateTimeHelper.ToString(DateTime.Today);
modConnection.rs["Action"] = "MOD";
modConnection.rs.Update();
modConnection.ExecuteSql("SELECT last_insert_rowid()");
newManualLogId = Convert.ToInt32(modConnection.rs[0]);
//NEW
modConnection.ExecuteSql("Select * from StockLog");
modConnection.rs.AddNew();
modConnection.rs["User"] = modMain.UserId;
modConnection.rs["Date"] = DateTimeHelper.ToString(DateTime.Today);
modConnection.rs["Quantity"] = deltaStock;
modConnection.rs["StockPrice"] = deltaStockPrice;
modConnection.rs["ProductID"] = currentIdProduct;
modConnection.rs["StockID"] = currentIdStock;
modConnection.rs["DocType"] = "MANUAL";
modConnection.rs["DocID"] = newManualLogId;
modConnection.rs.Update();
modConnection.ExecuteSql("SELECT last_insert_rowid()");
newStockLogId = Convert.ToInt32(modConnection.rs[0]);
modConnection.ExecuteSql("Update Products Set UnitsInStock = UnitsInStock + " + deltaStock.ToString() + " Where ProductId = '& currentIdProduct &'");
if ( Mobilize.Web.MessageBox.Show("Data modified successfully" + Environment.NewLine + "Would you like to modify another stock manually?", "Modify data", Mobilize.Web.MessageBoxButtons.YesNo, Mobilize.Web.MessageBoxIcon.Question) == Mobilize.Web.DialogResult.Yes )
{
ClearFields();
}
else
{
this.Close();
}
}
catch( System.Exception excep )
{
Mobilize.Web.MessageBox.Show("An error has occurred adding the data. Error: (" + Mobilize.Web.Information.Err().Number.ToString() + ") " + excep.Message, "Error", Mobilize.Web.MessageBoxButtons.OK, Mobilize.Web.MessageBoxIcon.Error);
}
}
private void Form_FormClosing(Object eventSender, Mobilize.Web.FormClosingEventArgs eventArgs)
{
int Cancel = (eventArgs.Cancel) ? 1 : 0;
int UnloadMode = (int)eventArgs.CloseReason;
try
{
Mobilize.Web.DialogResult res = (Mobilize.Web.DialogResult)0;
if ( editingData )
{
res = Mobilize.Web.MessageBox.Show("Do you want to save the edited data?", "Save data", Mobilize.Web.MessageBoxButtons.YesNoCancel, Mobilize.Web.MessageBoxIcon.Question);
if ( res == Mobilize.Web.DialogResult.Yes )
{
cmdSave_Click(cmdSave, new EventArgs());
}
else if ( res != Mobilize.Web.DialogResult.No )
{
Cancel = -1;
}
}
}
finally
{
eventArgs.Cancel = Cancel != 0;
}
}
private void cmdProducts_Click(Object eventSender, EventArgs eventArgs)
{
frmProducts.DefInstance.ShowDialog();
txtCode.Text = frmProducts.DefInstance.CurrentProductID;
txtName.Text = "";
DoSearchProduct();
}
private void lvProducts_ItemClick(Mobilize.Web.ListViewItem Item)
{
DoSearchStocks();
}
private void lvStocks_ItemClick(Mobilize.Web.ListViewItem Item)
{
RetrieveDataProduct();
}
private void txtCode_TextChanged(Object eventSender, EventArgs eventArgs)
{
DoSearchProduct();
}
//Private Sub txtCode_KeyPress(KeyAscii As Integer)
//KeyAscii = UpCase(KeyAscii)
//End Sub
private void txtName_TextChanged(Object eventSender, EventArgs eventArgs)
{
DoSearchProduct();
}
private void DoSearchProduct()
{
string filter = "";
//UPGRADE_WARNING: (2080) IsEmpty was upgraded to a comparison and has a new behavior. More Information: https://docs.mobilize.net/vbuc/ewis#2080
if ( !String.IsNullOrEmpty(txtCode.Text) )
{
filter = "ProductId LIKE '%" + txtCode.Text + "%'";
}
//UPGRADE_WARNING: (2080) IsEmpty was upgraded to a comparison and has a new behavior. More Information: https://docs.mobilize.net/vbuc/ewis#2080
if ( !String.IsNullOrEmpty(txtName.Text) )
{
//UPGRADE_WARNING: (2080) IsEmpty was upgraded to a comparison and has a new behavior. More Information: https://docs.mobilize.net/vbuc/ewis#2080
if ( !String.IsNullOrEmpty(filter) )
{
filter = filter + " AND ";
}
filter = filter + "ProductName LIKE '%" + txtName.Text + "%'";
}
//UPGRADE_WARNING: (2080) IsEmpty was upgraded to a comparison and has a new behavior. More Information: https://docs.mobilize.net/vbuc/ewis#2080
if ( !String.IsNullOrEmpty(filter) )
{
filter = "Where " + filter;
}
modConnection.ExecuteSql("Select ProductID, ProductName, UnitPrice, UnitsInStock, UnitsOnOrder, QuantityPerUnit, Unit from Products " + filter);
lvProducts.Items.Clear();
Mobilize.Web.ListViewItem x = null;
if ( modConnection.rs.RecordCount == 0 )
{
modMain.LogStatus("There are no records with the selected criteria");
}
else
{
while ( !modConnection.rs.EOF )
{
x = lvProducts.Items.Add(Convert.ToString(modConnection.rs[0]));
int tempForEndVar = (modConnection.rs.FieldsMetadata.Count - 1);
for ( modMain.i = 1; modMain.i <= tempForEndVar; modMain.i++ )
{
//UPGRADE_WARNING: (2080) IsEmpty was upgraded to a comparison and has a new behavior. More Information: https://docs.mobilize.net/vbuc/ewis#2080
if ( !(modConnection.rs.GetField(modMain.i) is null) )
{
Mobilize.Web.ListView.GetListViewSubItem(x, modMain.i).Text = Convert.ToString(modConnection.rs[modMain.i]);
}
}
modConnection.rs.MoveNext();
}
if ( lvProducts.Items.Count == 1 )
{
lvProducts.Items[lvProducts.Items[0].Index].Selected = true;
}
}
}
private void DoSearchStocks()
{
if ( lvProducts.FocusedItem == null )
{
return ;
}
if ( editingData )
{
if ( Mobilize.Web.MessageBox.Show("Do you want to cancel previous edited data?", "Data edition", Mobilize.Web.MessageBoxButtons.YesNo, Mobilize.Web.MessageBoxIcon.Question) != Mobilize.Web.DialogResult.Yes )
{
return ;
}
}
string productId = lvProducts.FocusedItem.Text;
string productName = Mobilize.Web.ListView.GetListViewSubItem(lvProducts.FocusedItem, 1).Text;
currentIdProduct = lvProducts.FocusedItem.Text;
Mobilize.Web.ListViewItem withVar = null;
withVar = lvProducts.FocusedItem;
//UPGRADE_WARNING: (2080) IsEmpty was upgraded to a comparison and has a new behavior. More Information: https://docs.mobilize.net/vbuc/ewis#2080
if ( !String.IsNullOrEmpty(Mobilize.Web.ListView.GetListViewSubItem(withVar, 5).Text) )
{
currentQuantityPerUnit = Mobilize.Web.ListView.GetListViewSubItem(withVar, 5).Text;
}
//UPGRADE_WARNING: (2080) IsEmpty was upgraded to a comparison and has a new behavior. More Information: https://docs.mobilize.net/vbuc/ewis#2080
if ( !String.IsNullOrEmpty(Mobilize.Web.ListView.GetListViewSubItem(withVar, 6).Text) )
{
currentUnit = Mobilize.Web.ListView.GetListViewSubItem(withVar, 6).Text;
}
currentProductName = Mobilize.Web.ListView.GetListViewSubItem(withVar, 1).Text;
txtProductName.Text = productName;
txtUnit.Text = currentUnit;
txtQuantityPerUnit.Text = currentQuantityPerUnit;
modConnection.ExecuteSql("Select StockID, Stock, InitialStock, UnitPrice, " + "StockPrice, DateStarted, DateModified, User From Stocks " + " Where ProductId = '" + productId + "'");
lvStocks.Items.Clear();
Mobilize.Web.ListViewItem x = null;
if ( modConnection.rs.RecordCount == 0 )
{
modMain.LogStatus("There are no stock records of the product " + productName);
RetrieveDataProduct();
}
else
{
while ( !modConnection.rs.EOF )
{
x = lvStocks.Items.Add(Convert.ToString(modConnection.rs[0]));
int tempForEndVar = (modConnection.rs.FieldsMetadata.Count - 1);
for ( modMain.i = 1; modMain.i <= tempForEndVar; modMain.i++ )
{
Mobilize.Web.ListView.GetListViewSubItem(x, modMain.i).Text = Convert.ToString(modConnection.rs[modMain.i]);
}
modConnection.rs.MoveNext();
}
if ( lvStocks.Items.Count == 1 )
{
lvStocks.Items[lvStocks.Items[0].Index].Selected = true;
}
}
}
private void RetrieveDataProduct()
{
if ( editingData )
{
if ( Mobilize.Web.MessageBox.Show("Do you want to cancel previous edited data?", "Data edition", Mobilize.Web.MessageBoxButtons.YesNo, Mobilize.Web.MessageBoxIcon.Question) != Mobilize.Web.DialogResult.Yes )
{
return ;
}
}
bool setEmpty = true;
Mobilize.Web.ListViewItem withVar = null;
if ( lvStocks.FocusedItem != null )
{
//UPGRADE_WARNING: (2080) IsEmpty was upgraded to a comparison and has a new behavior. More Information: https://docs.mobilize.net/vbuc/ewis#2080
if ( !(lvStocks.FocusedItem is null) )
{
currentIdStock = Convert.ToInt32(Double.Parse(lvStocks.FocusedItem.Text));
withVar = lvStocks.FocusedItem;
currentStock = Double.Parse(Mobilize.Web.ListView.GetListViewSubItem(withVar, 1).Text);
currentStockPrice = Double.Parse(Mobilize.Web.ListView.GetListViewSubItem(withVar, 4).Text);
codeGeneratedChange = true;
txtOriginalQuantity.Text = currentStock.ToString();
txtOriginalPrice.Text = currentStockPrice.ToString();
txtStockID.Text = currentIdStock.ToString();
txtValues[0].Text = currentStockPrice.ToString();
txtValues[1].Text = currentStock.ToString();
lblNewQuantity.Text = StringsHelper.Format(currentStock * Double.Parse(currentQuantityPerUnit), "##,###.00") + currentUnit;
lblCurrentQuantity.Text = StringsHelper.Format(currentStock * Double.Parse(currentQuantityPerUnit), "##,###.00") + currentUnit;
codeGeneratedChange = false;
setEmpty = false;
txtValues[0].ReadOnly = false;
txtValues[1].ReadOnly = false;
txtValues[0].Focus();
}
}
if ( setEmpty )
{
codeGeneratedChange = true;
txtOriginalQuantity.Text = "";
txtOriginalPrice.Text = "";
txtStockID.Text = "";
txtValues[0].Text = "";
txtValues[1].Text = "";
lblNewQuantity.Text = "";
lblCurrentQuantity.Text = "";
codeGeneratedChange = false;
}
editingData = false;
}
private void txtValues_Enter(Object eventSender, EventArgs eventArgs)
{
int Index = Array.IndexOf(this.txtValues, eventSender);
modFunctions.SelectAll(txtValues[Index]);
}
private void txtValues_KeyPress(Object eventSender, Mobilize.Web.KeyPressEventArgs eventArgs)
{
int KeyAscii = Convert.ToInt32(eventArgs.KeyChar);
try
{
if ( KeyAscii >= ((int)Mobilize.Web.Keys.D0) && KeyAscii <= ((int)Mobilize.Web.Keys.D9) )
{
}
else if ( KeyAscii == ((int)Mobilize.Web.Keys.Back) || KeyAscii == ((int)Mobilize.Web.Keys.Clear) || KeyAscii == ((int)Mobilize.Web.Keys.Delete) )
{
}
else if ( KeyAscii == ((int)Mobilize.Web.Keys.Left) || KeyAscii == ((int)Mobilize.Web.Keys.Right) || KeyAscii == ((int)Mobilize.Web.Keys.Up) || KeyAscii == ((int)Mobilize.Web.Keys.Down) || KeyAscii == ((int)Mobilize.Web.Keys.Tab) )
{
}
else
{
KeyAscii = 0;
Stub._System.Media.SystemSounds.Beep.Play();
}
}
finally
{
if ( KeyAscii == 0 )
{
eventArgs.Handled = true;
}
eventArgs.KeyChar = Convert.ToChar(KeyAscii);
}
}
private void txtValues_TextChanged(Object eventSender, EventArgs eventArgs)
{
int Index = Array.IndexOf(this.txtValues, eventSender);
if ( !codeGeneratedChange )
{
editingData = true;
codeGeneratedChange = true;
//UPGRADE_WARNING: (2080) IsEmpty was upgraded to a comparison and has a new behavior. More Information: https://docs.mobilize.net/vbuc/ewis#2080
if ( !String.IsNullOrEmpty(txtValues[0].Text) )
{
changedStockPrice = Double.Parse(txtValues[0].Text);
}
//UPGRADE_WARNING: (2080) IsEmpty was upgraded to a comparison and has a new behavior. More Information: https://docs.mobilize.net/vbuc/ewis#2080
if ( !String.IsNullOrEmpty(txtValues[1].Text) )
{
changedStock = Double.Parse(txtValues[1].Text);
}
switch ( Index )
{
case 1:
if ( changedStock > currentStock )
{
changedStock = currentStock;
modMain.LogStatus("Cannot pass the original stock, to add more, add a new stock manually", this);
txtValues[1].Text = changedStock.ToString();
}
break;
}
lblNewQuantity.Text = StringsHelper.Format(changedStock * Double.Parse(currentQuantityPerUnit), "##,###.00") + currentUnit;
lblCurrentQuantity.Text = StringsHelper.Format(currentStock * Double.Parse(currentQuantityPerUnit), "##,###.00") + currentUnit;
codeGeneratedChange = false;
}
}
private void ClearFields()
{
codeGeneratedChange = true;
txtValues[0].Text = "";
txtValues[1].Text = "";
txtValues[0].ReadOnly = true;
txtValues[1].ReadOnly = true;
txtCode.Text = "";
txtName.Text = "";
txtUnit.Text = "";
txtStockID.Text = "";
txtOriginalPrice.Text = "";
txtOriginalQuantity.Text = "";
txtProductName.Text = "";
txtQuantityPerUnit.Text = "";
lvProducts.Items.Clear();
lvStocks.Items.Clear();
lblCurrentQuantity.Text = "";
lblNewQuantity.Text = "";
txtCode.Focus();
editingData = false;
codeGeneratedChange = false;
modMain.ClearLogStatus(this);
}
private void Form_Closed(Object eventSender, EventArgs eventArgs)
{
}
}
}