-
Notifications
You must be signed in to change notification settings - Fork 0
/
GlobalData.cs
341 lines (307 loc) · 11.5 KB
/
GlobalData.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
using System;
using System.Collections.Generic;
using System.Data;
using MySql.Data.MySqlClient;
using System.Globalization;
using System.Linq;
using System.Net.NetworkInformation;
using System.Text;
using System.Windows.Forms;
namespace LOB
{
public class GlobalData
{
public static string GUsername;
public static int GUserID;
public static string GCompName;
public static int GCompID;
public static string GMacAddress;
public static string GServerName;
public static MySqlConnection GCon;
public static string GUserGroup;
public static int GStockRoomID;
public static string GAddress;
public static string GTps;
public static string GComAdd1;
public static string GComAdd2;
public static string GComTp1;
public static string GComCity;
public static int GCashACC;
public static int GSaleACC;
public static int GPurchaseACC;
public static int GExpenseACC;
public static int GCreditACC;
StringBuilder gSB = new StringBuilder();
MySqlDataReader sqlReader;
DataSet dSet = new DataSet();
DataTable dataTable = new DataTable();
MySqlDataAdapter sqlAdapter = new MySqlDataAdapter();
//Connect SQL
public MySqlConnection ConnectSQL()
{
try
{
//MySqlConnection myCon = new MySqlConnection(@"Data Source = SERVER\SQL2008; Initial Catalog = myPOS; User ID = sa; Password = avmctechnologies@2018");
MySqlConnection myCon = new MySqlConnection(@"server=localhost;port=3306;database=myPOS;uid=root;password='';persistsecurityinfo=True");
myCon.Open();
return myCon;
}
catch (MySqlException ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
return null;
}
finally
{
}
}
public DataSet getDataSet(string cQuery, string cTableName)
{
try
{
MySqlCommand MySqlCommand = new MySqlCommand();
{
MySqlCommand.Connection = GCon;
MySqlCommand.CommandType = CommandType.Text;
MySqlCommand.CommandText = cQuery;
}
sqlAdapter = new MySqlDataAdapter();
dSet = new DataSet();
{
sqlAdapter.SelectCommand = MySqlCommand;
sqlAdapter.Fill(dSet, cTableName);
}
return dSet;
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
return null;
}
}
public void SayMessage(string cMessage, int cId, string cTag)
{
frmSuccessMessage frmMessage = new frmSuccessMessage();
frmMessage.SayMessage(cMessage, cId, cTag);
frmMessage.ShowDialog();
}
public void FillComboBoxALL(ComboBox comboBox, string cTableName, string cWhereClause)
{
try
{
string strQuery = " SELECT CustID, NameOF FROM " + cTableName + " " + cWhereClause;
MySqlCommand MySqlCommand = new MySqlCommand();
{
MySqlCommand.Connection = GCon;
MySqlCommand.CommandType = CommandType.Text;
MySqlCommand.CommandText = strQuery;
}
sqlAdapter = new MySqlDataAdapter();
dataTable = new DataTable();
{
sqlAdapter.SelectCommand = MySqlCommand;
sqlAdapter.Fill(dataTable);
}
comboBox.Items.Clear();
DataRow row = dataTable.NewRow();
row["NameOF"] = "ALL";
dataTable.Rows.InsertAt(row, 0);
comboBox.DataSource = dataTable;
comboBox.ValueMember = "CustID";
comboBox.DisplayMember = "NameOF";
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
finally
{
dataTable = null;
}
}
public string GetValue(string cQuery, string cField)
{
try
{
var result = "";
MySqlCommand MySqlCommand = new MySqlCommand();
{
MySqlCommand.Connection = GCon;
MySqlCommand.CommandType = CommandType.Text;
MySqlCommand.CommandText = cQuery;
}
sqlAdapter = new MySqlDataAdapter();
dataTable = new DataTable();
{
sqlAdapter.SelectCommand = MySqlCommand;
sqlAdapter.Fill(dataTable);
}
foreach (DataRow dROW in dataTable.Rows)
{
result = dROW[cField].ToString();
}
return result;
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
return null;
}
finally
{
dataTable = null;
}
}
public void FillComboBox(ComboBox comboBox, string cTableName, string cWhereClause)
{
comboBox.DataSource = getDataSet("SELECT CustID, NameOF FROM " + cTableName + " " + cWhereClause, cTableName).Tables[0];
comboBox.ValueMember = "CustID";
comboBox.DisplayMember = "NameOF";
}
public Boolean AlreadyExist(string cQuery)
{
Boolean isExist = false;
try
{
MySqlCommand MySqlCommand = new MySqlCommand();
{
MySqlCommand.Connection = GCon;
MySqlCommand.CommandType = CommandType.Text;
MySqlCommand.CommandText = cQuery;
}
sqlAdapter = new MySqlDataAdapter();
dataTable = new DataTable();
{
sqlAdapter.SelectCommand = MySqlCommand;
sqlAdapter.Fill(dataTable);
}
if (dataTable.Rows.Count > 0)
{
isExist = true;
}
else
{
isExist = false;
}
return isExist;
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
return false;
}
finally
{
dataTable = null;
}
}
public static string GetMACAddress()
{
NetworkInterface[] nInterface = NetworkInterface.GetAllNetworkInterfaces();
String sMacAddress = string.Empty;
foreach (NetworkInterface adapter in nInterface)
{
if (sMacAddress == String.Empty)
{
IPInterfaceProperties Properties = adapter.GetIPProperties();
sMacAddress = adapter.GetPhysicalAddress().ToString();
}
}
return sMacAddress;
}
public DataTable getDataTable(string cQuery)
{
try
{
MySqlCommand MySqlCommand = new MySqlCommand();
{
MySqlCommand.Connection = GCon;
MySqlCommand.CommandType = CommandType.Text;
MySqlCommand.CommandText = cQuery;
}
sqlAdapter = new MySqlDataAdapter();
dataTable = new DataTable();
{
sqlAdapter.SelectCommand = MySqlCommand;
sqlAdapter.Fill(dataTable);
}
return dataTable;
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
return null;
}
}
public long getUniqueNumber(string cTranCode, int cCompID)
{
long gLastNo = 0;
gSB.Clear();
gSB.Append("SELECT LastID FROM tblLastID WHERE TranCode = '" + cTranCode + "' AND CompID = " + cCompID + " ");
if(AlreadyExist(gSB.ToString()))
{
MySqlCommand command = new MySqlCommand("UPDATE tblLastID SET LastID = LastID + 1 WHERE TranCode = '" + cTranCode + "' AND CompID = " + cCompID + "", GCon);
command.ExecuteNonQuery();
gLastNo = Convert.ToInt64(GetValue(gSB.ToString(), "LastID"));
return gLastNo;
}
else
{
MySqlCommand command = new MySqlCommand("INSERT INTO tblLastID(LastID, TranCode, CompID) VALUES (1, '" + cTranCode + "', " + cCompID + ") ", GCon);
command.ExecuteNonQuery();
gLastNo = 1;
return gLastNo;
}
}
public DateTime getFirstDate(ComboBox cComboFDate)
{
string tmpVal = "";
switch (cComboFDate.SelectedIndex)
{
case 0:
tmpVal = "01-Jan-" + DateTime.Now.Year;
break;
case 1:
tmpVal = DateTime.Now.ToShortDateString();
break;
case 2:
tmpVal = "01-" + CultureInfo.CurrentCulture.DateTimeFormat.GetAbbreviatedMonthName(DateTime.Now.Month).ToString() + "-" + DateTime.Now.Year;
break;
case 3:
tmpVal = "01-" + CultureInfo.CurrentCulture.DateTimeFormat.GetAbbreviatedMonthName(DateTime.Now.AddMonths(-1).Month).ToString() + "-" + DateTime.Now.Year;
break;
case 4:
tmpVal = "01-Jan-" + DateTime.Now.Year;
break;
default:
break;
}
return Convert.ToDateTime(tmpVal);
}
public DateTime getLastDate(ComboBox cComboFDate, DateTime cFDate)
{
string tmpVal = "";
switch (cComboFDate.SelectedIndex)
{
case 0:
tmpVal = "31-Dec-" + DateTime.Now.Year;
break;
case 1:
tmpVal = DateTime.Now.ToShortDateString();
break;
case 2:
tmpVal = DateTime.Now.ToShortDateString();
break;
case 3:
tmpVal = cFDate.AddMonths(1).AddDays(-1).ToShortDateString();
break;
case 4:
tmpVal = DateTime.Now.ToShortDateString();
break;
default:
break;
}
return Convert.ToDateTime(tmpVal);
}
}
}