-
Notifications
You must be signed in to change notification settings - Fork 0
/
modFunctions.cs
310 lines (278 loc) · 8.49 KB
/
modFunctions.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
using Microsoft.VisualBasic;
using System;
using System.Collections.Specialized;
using System.Text;
using System.Windows.Forms;
using UpgradeHelpers.DB.ADO;
using UpgradeHelpers.Gui;
namespace SKS
{
internal static class modFunctions
{
internal static void AppendAND(ref string filter)
{
//UPGRADE_WARNING: (2080) IsEmpty was upgraded to a comparison and has a new behavior. More Information: https://www.mobilize.net/vbtonet/ewis/ewi2080
if (!String.IsNullOrEmpty(filter))
{
filter = filter + " AND ";
}
}
internal static bool AddToCollection(OrderedDictionary col, string Item)
{
bool result = false;
if (!Exists(col, Item))
{
col.Add(Item, Item);
result = true;
}
return result;
}
internal static bool Exists(OrderedDictionary col, string Index)
{
object o = null;
try
{
//UPGRADE_WARNING: (1068) col() of type Variant is being forced to Scalar. More Information: https://www.mobilize.net/vbtonet/ewis/ewi1068
o = col[Index];
}
catch
{
}
//UPGRADE_WARNING: (2080) IsEmpty was upgraded to a comparison and has a new behavior. More Information: https://www.mobilize.net/vbtonet/ewis/ewi2080
return !Object.Equals(o, null);
}
internal static double DoubleValue(string strValue)
{
if (Strings.Len(strValue) != 0)
{
return Double.Parse(strValue);
}
else
{
return 0;
}
}
internal static bool ValidateTextBoxDouble(TextBox txBox, Form parentForm)
{
bool result = false;
try
{
DoubleValue(txBox.Text);
return true;
}
catch
{
modMain.LogStatus("The value inserted is not valid", parentForm);
txBox.Text = "";
txBox.Focus();
result = false;
}
return result;
}
internal static bool ValidateTextDouble(string text, Form parentForm)
{
bool result = false;
try
{
DoubleValue(text);
return true;
}
catch
{
modMain.LogStatus("The value inserted is not valid", parentForm);
result = false;
}
return result;
}
internal static void SelectAll(TextBox txtBox)
{
txtBox.SelectionStart = 0;
txtBox.SelectionLength = Strings.Len(txtBox.Text);
}
internal static int UpCase(int KeyAscii)
{
return Strings.Asc(Strings.Chr(KeyAscii).ToString().ToUpper()[0]);
}
//'''''''''''''''''''''''''''''''''
//'' Combobox related functions '''
//'''''''''''''''''''''''''''''''''
internal static void LoadCombo(string Table, ComboBox combo, string field, string valueField = "")
{
modConnection.ExecuteSql("Select * From " + Table);
combo.Items.Clear();
//UPGRADE_WARNING: (2080) IsEmpty was upgraded to a comparison and has a new behavior. More Information: https://www.mobilize.net/vbtonet/ewis/ewi2080
if (!String.IsNullOrEmpty(valueField))
{
while (!modConnection.rs.EOF)
{
combo.AddItem(Convert.ToString(modConnection.rs[field]));
combo.SetItemData(combo.GetNewIndex(), Convert.ToInt32(modConnection.rs[valueField]));
modConnection.rs.MoveNext();
}
}
else
{
while (!modConnection.rs.EOF)
{
combo.AddItem(Convert.ToString(modConnection.rs[field]));
modConnection.rs.MoveNext();
}
}
//If strDefault <> Empty Then
// combo = strDefault
//End If
}
internal static bool ComboEmpty(ComboBox combo, object strip = null, int Index = 0)
{
bool result = false;
if (combo.SelectedIndex == -1)
{
result = true;
MessageBox.Show("Please select an option from the list", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
//UPGRADE_WARNING: (2080) IsEmpty was upgraded to a comparison and has a new behavior. More Information: https://www.mobilize.net/vbtonet/ewis/ewi2080
if (!Index.Equals(0))
{
//strip.SelectedItem = strip.Tabs(Index)
}
combo.Focus();
}
else
{
result = false;
}
return result;
}
internal static bool NoRecords(ListView lstView, string Prompt = "")
{
if (lstView.Items.Count == 0 || lstView.FocusedItem == null)
{
//UPGRADE_WARNING: (2080) IsEmpty was upgraded to a comparison and has a new behavior. More Information: https://www.mobilize.net/vbtonet/ewis/ewi2080
if (!String.IsNullOrEmpty(Prompt))
{
MessageBox.Show(Prompt, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
return true;
}
else
{
return false;
}
}
internal static string RcrdId(string Table, string Identifier = "", string FldNo = "")
{
int RcrdNo = 0;
modConnection.ExecuteSql("Select * from " + Table + " order by " + FldNo + " ASC");
if (!modConnection.rs.EOF)
{
modConnection.rs.MoveLast();
RcrdNo = Convert.ToInt32(Convert.ToDouble(modConnection.rs[FldNo]) + 1);
}
else
{
RcrdNo = 1;
}
//UPGRADE_WARNING: (2080) IsEmpty was upgraded to a comparison and has a new behavior. More Information: https://www.mobilize.net/vbtonet/ewis/ewi2080
if (!String.IsNullOrEmpty(Identifier))
{
return Identifier + RcrdNo.ToString() + DateTime.Today.ToString("MM");
}
else
{
return RcrdNo.ToString();
}
}
//''''''''''''''''''''''''''''''''''''''''
internal static void SearchShow(string Table, string fieldToSearch, string itemToSearch)
{
frmSearch.DefInstance.Search(Table, fieldToSearch, itemToSearch);
frmSearch.DefInstance.ShowDialog();
}
internal static double ValBox(string Prompt, PictureBox Icon, string Title = "", double Default = 0, string Header = "Value Box")
{
//With frmValue
// If Title <> Empty Then
// .Caption = Title
// Else
// .Caption = App.Title
// End If
// .lblHeader.Caption = StrConv(Header, vbUpperCase)
// .imgIcon.Picture = Icon.Picture
// .lblPrompt.Caption = Prompt
// .Default Val(Default)
// .Show vbModal
// ValBox = Val(.txtValue.Text)
// Unload frmValue
//End With
return 0;
}
internal static bool TextBoxEmpty(TextBox stext, object TabObject = null, int TabIndex = 0)
{
//UPGRADE_WARNING: (2080) IsEmpty was upgraded to a comparison and has a new behavior. More Information: https://www.mobilize.net/vbtonet/ewis/ewi2080
bool result = false;
if (String.IsNullOrEmpty(stext.Text.Trim()) || stext.Text == " / / ")
{
result = true;
MessageBox.Show("You need to fill in all required fields", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
//UPGRADE_WARNING: (2080) IsEmpty was upgraded to a comparison and has a new behavior. More Information: https://www.mobilize.net/vbtonet/ewis/ewi2080
if (!TabIndex.Equals(0))
{
//TabObject.SelectedItem = TabObject.Tabs(TabIndex)
}
stext.Focus();
}
else
{
result = false;
}
return result;
}
internal static bool TextBoxNumberEmpty(TextBox textbox)
{
//if the input is not a numeric then true
bool result = false;
if (!Information.IsNumeric(textbox.Text))
{
result = true;
MessageBox.Show("The field requires a numeric value.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
textbox.Focus();
SelectAll(textbox);
}
else
{
result = false;
}
return result;
}
//UPGRADE_NOTE: (7001) The following declaration (SaveDetection) seems to be dead code More Information: https://www.mobilize.net/vbtonet/ewis/ewi7001
//private void SaveDetection(string Reference, string Title, string Description, string Table)
//{
//modConnection.ExecuteSql2("Select * from " + Table);
//modConnection.rs2.AddNew();
//modConnection.rs2["record_no"] = Conversion.Val(RcrdId(Table, "", "record_no"));
//modConnection.rs2["Reference"] = Reference;
//modConnection.rs2["war_type"] = Title;
//modConnection.rs2["Description"] = Description;
//modConnection.rs2.Update();
//}
internal static string ExecErr(string Prompt, string PromptFld = "", string Table = "", string RcrdFld = "", string RcrdStr = "")
{
StringBuilder Rcrds = new StringBuilder();
//UPGRADE_WARNING: (2080) IsEmpty was upgraded to a comparison and has a new behavior. More Information: https://www.mobilize.net/vbtonet/ewis/ewi2080
if (!String.IsNullOrEmpty(Table))
{
modConnection.ExecuteSql("Select * from " + Table + " where " + RcrdFld + " = '" + RcrdStr + "'");
while (!modConnection.rs.EOF)
{
Rcrds.Append(Convert.ToString(modConnection.rs[PromptFld]) + "; ");
modConnection.rs.MoveNext();
}
return "Error: " + Prompt + Environment.NewLine + Environment.NewLine +
"Related Records: " + Rcrds.ToString();
}
else
{
return Prompt;
}
}
}
}