-
Notifications
You must be signed in to change notification settings - Fork 4
/
frmAddProductTo.cs
386 lines (354 loc) · 14.9 KB
/
frmAddProductTo.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
using Microsoft.VisualBasic;
using System;
using System.Collections.Specialized;
using UpgradeHelpers.DB.ADO;
using Mobilize.WebMap.Common.Attributes;
using Mobilize.Web.Extensions;
namespace SKS
{
[Observable]
internal partial class frmAddProductTo
: Mobilize.Web.Form
{
public frmAddProductTo()
: 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();
}
private void frmAddProductTo_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]
public int Id { get; set; } = 0;
[Intercepted]
public string ObjectReferred { get; set; } = "";
[Intercepted]
public string Table { get; set; } = "";
[Intercepted]
public string ColumnName { get; set; } = "";
[Intercepted]
public bool SavedChanges { get; set; } = false;
[Intercepted]
private OrderedDictionary productsStored { get; set; } = null;
[Intercepted]
private OrderedDictionary productsToDelete { get; set; } = null;
[Intercepted]
private OrderedDictionary productsToAdd { get; set; } = null;
[Intercepted]
private bool editingData { get; set; } = false;
[Intercepted]
private string currentIdProduct { get; set; } = "";
[Intercepted]
private bool codeGeneratedChange { get; set; } = false;
private void chkAll_CheckStateChanged(Object eventSender, EventArgs eventArgs)
{
bool check = chkAll.CheckState == Mobilize.Web.CheckState.Checked;
int tempForEndVar = lvProductsBy.Items.Count;
for ( modMain.i = 1; modMain.i <= tempForEndVar; modMain.i++ )
{
lvProductsBy.Items[modMain.i - 1].Checked = check;
}
}
private void cmdClose_Click(Object eventSender, EventArgs eventArgs)
{
this.Close();
}
private void cmdProducts_Click(Object eventSender, EventArgs eventArgs)
{
frmProducts.DefInstance.ShowDialog();
txtCode.Text = frmProducts.DefInstance.CurrentProductID;
txtName.Text = "";
DoSearchProduct();
}
private void cmdRemove_Click(Object eventSender, EventArgs eventArgs)
{
string productIdToDelete = "";
for ( modMain.i = lvProductsBy.Items.Count; modMain.i >= 1; modMain.i-- )
{
if ( lvProductsBy.Items[modMain.i - 1].Checked )
{
productIdToDelete = lvProductsBy.Items[modMain.i - 1].Text;
if ( modFunctions.Exists(productsStored, productIdToDelete) )
{
if ( modFunctions.Exists(productsToAdd, productIdToDelete) )
{
productsToDelete.Remove(productIdToDelete);
}
else
{
modFunctions.AddToCollection(productsToDelete, productIdToDelete);
}
}
else
{
if ( modFunctions.Exists(productsToAdd, currentIdProduct) )
{
productsToAdd.Remove(currentIdProduct);
}
}
lvProductsBy.Items.RemoveAt(modMain.i - 1);
editingData = true;
}
}
}
private void cmdSave_Click(Object eventSender, EventArgs eventArgs)
{
if ( productsToAdd.Count == 0 && productsToDelete.Count == 0 )
{
editingData = true;
Mobilize.Web.MessageBox.Show("No data to be saved", "No data modified", Mobilize.Web.MessageBoxButtons.OK, Mobilize.Web.MessageBoxIcon.Information);
this.Close();
return ;
}
SavedChanges = true;
string productCode = "";
foreach ( string productCodeIterator in productsToAdd.Values )
{
productCode = productCodeIterator;
modConnection.ExecuteSql("Insert into " + Table + "(" + ColumnName + ", ProductID) Values (" + Id.ToString() + ", '" + productCode + "')");
productCode = default(string);
}
foreach ( string productCodeIterator2 in productsToDelete.Values )
{
productCode = productCodeIterator2;
modConnection.ExecuteSql("Delete from " + Table + " Where " + ColumnName + " = " + Id.ToString() + " And ProductID = '" + productCode + "'");
productCode = default(string);
}
editingData = false;
Mobilize.Web.MessageBox.Show("Data was succesfully saved", "New data", Mobilize.Web.MessageBoxButtons.OK, Mobilize.Web.MessageBoxIcon.Information);
this.Close();
return ;
Mobilize.Web.MessageBox.Show("An error has occurred adding the data. Error: (" + Mobilize.Web.Information.Err().Number.ToString() + ") " + Mobilize.Web.Information.Err().Description, "Error", Mobilize.Web.MessageBoxButtons.OK, Mobilize.Web.MessageBoxIcon.Error);
}
public void LoadData()
{
editingData = false;
editingData = false;
codeGeneratedChange = false;
this.Text = "Add product(s) to " + ObjectReferred;
lblProductsRelated.Text = "Products related to " + ObjectReferred;
productsStored = new OrderedDictionary(System.StringComparer.OrdinalIgnoreCase);
productsToDelete = new OrderedDictionary(System.StringComparer.OrdinalIgnoreCase);
productsToAdd = new OrderedDictionary(System.StringComparer.OrdinalIgnoreCase);
LoadProductsById();
}
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 lvProducts_ItemClick(Mobilize.Web.ListViewItem Item)
{
AddProductToSet();
}
private void txtCode_TextChanged(Object eventSender, EventArgs eventArgs)
{
DoSearchProduct();
}
//Private Sub txtCode_KeyPress(KeyAscii As Integer)
//KeyAscii = UpCase(KeyAscii)
//End Sub
private void txtCode_Leave(Object eventSender, EventArgs eventArgs)
{
if ( lvProducts.Items.Count == 1 )
{
AddProductToSet();
}
}
private void txtName_TextChanged(Object eventSender, EventArgs eventArgs)
{
DoSearchProduct();
}
private void LoadProductsById()
{
string productCode = "";
modConnection.ExecuteSql("Select p.ProductID, p.ProductName, p.UnitPrice, p.QuantityPerUnit, p.Unit from Products as p, " + Table + " as pb Where pb." + ColumnName + " = " + Id.ToString() + " And pb.ProductId = p.ProductId");
modMain.LogStatus("There are " + modConnection.rs.RecordCount.ToString() + " records with the selected criteria", this);
Mobilize.Web.ListViewItem x = null;
if ( modConnection.rs.RecordCount > 0 )
{
while ( !modConnection.rs.EOF )
{
//productCode = CStr(rs.Fields(0).value)
productCode = Convert.ToString(modConnection.rs[0]);
modFunctions.AddToCollection(productsStored, productCode);
x = lvProductsBy.Items.Add(productCode);
for ( modMain.i = 1; modMain.i <= 2; 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]);
}
}
Mobilize.Web.ListView.GetListViewSubItem(x, 3).Text = Convert.ToString(modConnection.rs[3]) + Convert.ToString(modConnection.rs[4]);
modConnection.rs.MoveNext();
}
}
}
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();
modMain.LogStatus("There are " + modConnection.rs.RecordCount.ToString() + " records with the selected criteria", this);
Mobilize.Web.ListViewItem x = null;
if ( modConnection.rs.RecordCount > 0 )
{
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 AddProductToSet()
{
Mobilize.Web.ListViewItem y = null;
int i = 0;
bool found = false;
Mobilize.Web.ListViewItem x = 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 ( !(lvProducts.FocusedItem is null) )
{
y = lvProducts.FocusedItem;
currentIdProduct = lvProducts.FocusedItem.Text;
found = false;
int tempForEndVar = lvProductsBy.Items.Count;
for ( i = 1; i <= tempForEndVar; i++ )
{
if ( lvProductsBy.Items[i - 1].Text == currentIdProduct )
{
lvProductsBy.Items[lvProductsBy.Items[i - 1].Index].Selected = true;
found = true;
break;
}
else if ( String.CompareOrdinal(lvProductsBy.Items[i - 1].Text, currentIdProduct) > 0 )
{
break;
}
}
if ( !found )
{
editingData = true;
if ( !modFunctions.Exists(productsStored, currentIdProduct) )
{
if ( modFunctions.Exists(productsToDelete, currentIdProduct) )
{
productsToDelete.Remove(currentIdProduct);
}
else
{
modFunctions.AddToCollection(productsToAdd, currentIdProduct);
}
}
else
{
if ( modFunctions.Exists(productsToDelete, currentIdProduct) )
{
productsToDelete.Remove(currentIdProduct);
}
}
x = lvProductsBy.Items.Insert(i - 1, currentIdProduct);
Mobilize.Web.ListView.GetListViewSubItem(x, 1).Text = Mobilize.Web.ListView.GetListViewSubItem(y, 1).Text;
Mobilize.Web.ListView.GetListViewSubItem(x, 2).Text = Mobilize.Web.ListView.GetListViewSubItem(y, 2).Text;
Mobilize.Web.ListView.GetListViewSubItem(x, 3).Text = Mobilize.Web.ListView.GetListViewSubItem(y, 5).Text + Mobilize.Web.ListView.GetListViewSubItem(y, 6).Text;
}
}
}
//UPGRADE_NOTE: (7001) The following declaration (ClearFields) seems to be dead code More Information: https://docs.mobilize.net/vbuc/ewis#7001
//private void ClearFields()
//{
//codeGeneratedChange = true;
//txtCode.Text = "";
//txtName.Text = "";
//lvProducts.Items.Clear();
//lvProductsBy.Items.Clear();
//txtCode.Focus();
//editingData = false;
//codeGeneratedChange = false;
//}
private void Form_Closed(Object eventSender, EventArgs eventArgs)
{
}
}
}