· 5 years ago · Feb 03, 2020, 06:12 AM
1using log4net;
2using log4net.Config;
3using POS_Client;
4using POS_Client.Utils;
5using POS_Client.WebService;
6using System;
7using System.Collections.Generic;
8using System.Data;
9using System.Deployment.Application;
10using System.IO;
11using System.Linq;
12using System.Net.NetworkInformation;
13using System.Reflection;
14using System.Security.Cryptography;
15using System.Text;
16using System.Threading;
17using System.Windows.Forms;
18using T00SharedLibraryDotNet20;
19
20internal static class Program
21{
22 private static bool _isDeployClickOnce = true;
23
24 private static bool _isHyweb = false;
25
26 private static string _ws = "posadmin";
27
28 private static bool _isFertilizer = true;
29
30 private static bool _isCropPestRange_NEW = true;
31
32 private static bool _isDataTransfer = false;
33
34 private static int _DBSchemaV = 12;
35
36 public static List<GoodObject> goodsTemp = new List<GoodObject>();
37
38 public static List<GoodObjectWithMoney> goodsWithMoneyTemp = new List<GoodObjectWithMoney>();
39
40 public static List<string> membersTemp = new List<string>();
41
42 public static List<string> commodityTemp = new List<string>();
43
44 private static string _version = _isDeployClickOnce ? ApplicationDeployment.CurrentDeployment.CurrentVersion.ToString(4) : "1.0";
45
46 private static int _SystemMode = 1;
47
48 private static int _RoleType;
49
50 private static readonly ILog _Logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
51
52 private static string _sysLastUpdate = _isDeployClickOnce ? ApplicationDeployment.CurrentDeployment.TimeOfLastUpdateCheck.ToLongDateString() : "2016/09/06 08:00:00";
53
54 private static string _sysFolder = Environment.GetFolderPath(Environment.SpecialFolder.System).Substring(0, 3);
55
56 private static string _DBName = "db.db3";
57
58 private static string _DataPath;
59
60 private static string _ConnString;
61
62 private static string _LincenseCode;
63
64 private static string _SiteNo;
65
66 private static string _ShopType;
67
68 private static string _UploadDataURL = "http://" + (_isHyweb ? "10.10.4.161:8888" : "posadmin.baphiq.gov.tw") + "/mPosCService/uploadData?wsdl";
69
70 private static string _DownloadDataURL = "http://" + (_isHyweb ? "10.10.4.161:8888" : "posadmin.baphiq.gov.tw") + "/mPosCService/ExpData?wsdl";
71
72 private static string _AuthURL = "http://" + (_isHyweb ? "10.10.4.161:8888" : "posadmin.baphiq.gov.tw") + "/mPosCService/PosCService?wsdl";
73
74 private static string _VerificationURL = "http://" + (_isHyweb ? "10.10.4.161:8888" : "posadmin.baphiq.gov.tw") + "/mPosMiddleware/POSService?wsdl";
75
76 private static string _casher;
77
78 private static string _CRCFile;
79
80 private static string _HardDiskSerialNo;
81
82 private static string _RegisterCode;
83
84 private static string _crcStatus;
85
86 private static string _printerName;
87
88 private static bool _isSaleOfFertilizer = false;
89
90 private static bool _isProgramUpgraded = false;
91
92 public static ILog Logger => _Logger;
93
94 public static int RoleType
95 {
96 get
97 {
98 return _RoleType;
99 }
100 set
101 {
102 _RoleType = value;
103 }
104 }
105
106 public static string ShopType
107 {
108 get
109 {
110 return _ShopType;
111 }
112 set
113 {
114 _ShopType = value;
115 }
116 }
117
118 public static string AuthURL => _AuthURL;
119
120 public static string DownloadURL => _DownloadDataURL;
121
122 public static string UploadDataURL => _UploadDataURL;
123
124 public static string VerificationURL => _VerificationURL;
125
126 public static bool IsDataTransfer => _isDataTransfer;
127
128 public static bool IsCropPestRange_NEW => _isCropPestRange_NEW;
129
130 public static bool IsHyweb => _isHyweb;
131
132 public static bool IsFertilizer => _isFertilizer;
133
134 public static string Version => _version;
135
136 public static int SystemMode
137 {
138 get
139 {
140 return _SystemMode;
141 }
142 set
143 {
144 _SystemMode = value;
145 }
146 }
147
148 public static string SiteNo
149 {
150 get
151 {
152 if (string.IsNullOrEmpty(_SiteNo))
153 {
154 return "";
155 }
156 return _SiteNo.PadLeft(2, '0');
157 }
158 set
159 {
160 _SiteNo = value;
161 }
162 }
163
164 public static string LincenseCode
165 {
166 get
167 {
168 return _LincenseCode;
169 }
170 set
171 {
172 _LincenseCode = value;
173 }
174 }
175
176 public static string Casher
177 {
178 get
179 {
180 return _casher;
181 }
182 set
183 {
184 _casher = value;
185 }
186 }
187
188 public static string ConnectionString
189 {
190 get
191 {
192 return _ConnString;
193 }
194 set
195 {
196 }
197 }
198
199 public static string CRCStatus
200 {
201 get
202 {
203 return _crcStatus;
204 }
205 set
206 {
207 _crcStatus = value;
208 }
209 }
210
211 public static string DataPath
212 {
213 get
214 {
215 return _DataPath;
216 }
217 set
218 {
219 }
220 }
221
222 public static string HardDiskSerialNo
223 {
224 get
225 {
226 return _HardDiskSerialNo;
227 }
228 set
229 {
230 }
231 }
232
233 public static string RegisterCode
234 {
235 get
236 {
237 return _RegisterCode;
238 }
239 set
240 {
241 }
242 }
243
244 public static string PrinterName
245 {
246 get
247 {
248 return _printerName;
249 }
250 set
251 {
252 _printerName = value;
253 }
254 }
255
256 public static bool IsDeployClickOnce
257 {
258 get
259 {
260 return _isDeployClickOnce;
261 }
262 set
263 {
264 }
265 }
266
267 public static bool IsSaleOfFertilizer
268 {
269 get
270 {
271 return _isSaleOfFertilizer;
272 }
273 set
274 {
275 _isSaleOfFertilizer = value;
276 }
277 }
278
279 public static bool Upgraded
280 {
281 get
282 {
283 return _isProgramUpgraded;
284 }
285 set
286 {
287 _isProgramUpgraded = value;
288 }
289 }
290
291 public static string SysLastUpdate
292 {
293 get
294 {
295 return _sysLastUpdate;
296 }
297 set
298 {
299 }
300 }
301
302 public static string systemFolder
303 {
304 get
305 {
306 return _sysFolder;
307 }
308 set
309 {
310 _sysFolder = value;
311 }
312 }
313
314 [STAThread]
315 private static void Main()
316 {
317 XmlConfigurator.ConfigureAndWatch(new FileInfo("log4net.config"));
318 _Logger.Info("POS_CLIENT 程式啟動 !!");
319 switch (_ws)
320 {
321 case "test":
322 _UploadDataURL = "http://10.10.4.161:8888/mPosCService/uploadData?wsdl";
323 _DownloadDataURL = "http://posadmin.baphiq.gov.tw/mPosCService/ExpData?wsdl";
324 _AuthURL = "http://10.10.4.161:8888/mPosCService/PosCService?wsdl";
325 _VerificationURL = "http://10.10.4.161:8888/mPosMiddleware/POSService?wsdl";
326 break;
327 case "posadmin":
328 _UploadDataURL = "http://posadmin.baphiq.gov.tw/mPosCService/uploadData?wsdl";
329 _DownloadDataURL = "http://posadmin.baphiq.gov.tw/mPosCService/ExpData?wsdl";
330 _AuthURL = "http://posadmin.baphiq.gov.tw/mPosCService/PosCService?wsdl";
331 _VerificationURL = "http://posadmin.baphiq.gov.tw/mPosMiddlewareDisable/POSService?wsdl";
332 break;
333 case "crop":
334 _UploadDataURL = "http://crop.baphiq.gov.tw/mPosCService/uploadData?wsdl";
335 _DownloadDataURL = "http://posadmin.baphiq.gov.tw/mPosCService/ExpData?wsdl";
336 _AuthURL = "http://crop.baphiq.gov.tw/mPosCService/PosCService?wsdl";
337 _VerificationURL = "http://crop.baphiq.gov.tw/mPosMiddleware/POSService?wsdl";
338 break;
339 }
340 try
341 {
342 Application.EnableVisualStyles();
343 Application.SetCompatibleTextRenderingDefault(defaultValue: false);
344 bool createdNew;
345 Mutex mutex = new Mutex(initiallyOwned: true, Application.ProductName, out createdNew);
346 if (createdNew)
347 {
348 new frmUpdate().ShowDialog();
349 if (!_isProgramUpgraded && InitSystemParams())
350 {
351 string dBHardDiskSerialNo = GetDBHardDiskSerialNo();
352 if (dBHardDiskSerialNo == "")
353 {
354 new frmInitSysParam().Show();
355 Application.Run();
356 }
357 else if (dBHardDiskSerialNo != _HardDiskSerialNo)
358 {
359 new frmInitSysParam().Show();
360 Application.Run();
361 }
362 else
363 {
364 string sql = "SELECT RegisterCode FROM hypos_RegisterLicense where isApproved = 'Y' order by CreateDate desc limit 1";
365 _RegisterCode = Convert.ToString(DataBaseUtilities.DBOperation(ConnectionString, sql, null, CommandOperationType.ExecuteScalar));
366 if ("-1".Equals(_RegisterCode))
367 {
368 new frmInitSysParam().Show();
369 Application.Run();
370 }
371 else
372 {
373 AuthResultObject authResultObject = new AuthenticationWs().hasInUseRetry(_RegisterCode);
374 if (bool.Parse(authResultObject.inUse))
375 {
376 string sql2 = "SELECT LicenseCode FROM hypos_RegisterLicense where isApproved = 'Y' order by CreateDate desc limit 1";
377 _LincenseCode = Convert.ToString(DataBaseUtilities.DBOperation(ConnectionString, sql2, null, CommandOperationType.ExecuteScalar));
378 string lastUpdateDate = DataBaseUtilities.DBOperation(ConnectionString, "SELECT DownloadLastUpdateDate FROM hypos_SysParam", null, CommandOperationType.ExecuteScalar).ToString();
379 new frmDownload(_LincenseCode, lastUpdateDate).ShowDialog();
380 _SiteNo = authResultObject.serial;
381 string sql3 = "update hypos_SysParam set SiteNo = {0} ";
382 DataBaseUtilities.DBOperation(ConnectionString, sql3, new string[1]
383 {
384 _SiteNo
385 }, CommandOperationType.ExecuteNonQuery);
386 ShopType = authResultObject.shopType;
387 if (!string.IsNullOrEmpty(ShopType))
388 {
389 string sql4 = "SELECT ShopIdNo FROM hypos_ShopInfoManage";
390 if (((DataTable)DataBaseUtilities.DBOperation(ConnectionString, sql4, null, CommandOperationType.ExecuteReaderReturnDataTable)).Rows.Count > 0)
391 {
392 if (ShopType.Equals("0"))
393 {
394 DataBaseUtilities.DBOperation(ConnectionString, "UPDATE hypos_ShopInfoManage SET IsRetailer = {0}, IsWholesaler = {1} ", new string[2]
395 {
396 "ON",
397 "ON"
398 }, CommandOperationType.ExecuteNonQuery);
399 }
400 else if (ShopType.Equals("1"))
401 {
402 DataBaseUtilities.DBOperation(ConnectionString, "UPDATE hypos_ShopInfoManage SET IsRetailer = {0}, IsWholesaler = {1} ", new string[2]
403 {
404 "ON",
405 "OFF"
406 }, CommandOperationType.ExecuteNonQuery);
407 }
408 else if (ShopType.Equals("2"))
409 {
410 DataBaseUtilities.DBOperation(ConnectionString, "UPDATE hypos_ShopInfoManage SET IsRetailer = {0}, IsWholesaler = {1} ", new string[2]
411 {
412 "OFF",
413 "ON"
414 }, CommandOperationType.ExecuteNonQuery);
415 }
416 }
417 else if (ShopType.Equals("0"))
418 {
419 DataBaseUtilities.DBOperation(ConnectionString, "INSERT INTO hypos_ShopInfoManage ( IsRetailer, IsWholesaler) VALUES( {0}, {1})", new string[2]
420 {
421 "ON",
422 "ON"
423 }, CommandOperationType.ExecuteNonQuery);
424 }
425 else if (ShopType.Equals("1"))
426 {
427 DataBaseUtilities.DBOperation(ConnectionString, "INSERT INTO hypos_ShopInfoManage ( IsRetailer, IsWholesaler) VALUES( {0}, {1}) ", new string[2]
428 {
429 "ON",
430 "OFF"
431 }, CommandOperationType.ExecuteNonQuery);
432 }
433 else if (ShopType.Equals("2"))
434 {
435 DataBaseUtilities.DBOperation(ConnectionString, "INSERT INTO hypos_ShopInfoManage ( IsRetailer, IsWholesaler) VALUES( {0}, {1}) ", new string[2]
436 {
437 "OFF",
438 "ON"
439 }, CommandOperationType.ExecuteNonQuery);
440 }
441 }
442 if (IsDataTransfer)
443 {
444 oldPOS_DataTransfer();
445 }
446 new frmLogin().Show();
447 Application.Run();
448 }
449 else
450 {
451 MessageBox.Show(authResultObject.message);
452 string[] strParameterArray = new string[2]
453 {
454 _RegisterCode,
455 DateTime.Now.ToString()
456 };
457 DataBaseUtilities.DBOperation(_ConnString, "UPDATE hypos_RegisterLicense SET isApproved = 'N', ApproveDate = {1} where RegisterCode = {0} ", strParameterArray, CommandOperationType.ExecuteNonQuery);
458 new frmInitSysParam().Show();
459 Application.Run();
460 }
461 }
462 }
463 if (NetworkInterface.GetIsNetworkAvailable())
464 {
465 try
466 {
467 new frmUploadData().ShowDialog();
468 }
469 catch (Exception ex)
470 {
471 _Logger.Fatal("上傳資料程序發生例外狀況:" + ex.ToString());
472 Console.WriteLine("Error Message : " + ex.Message);
473 MessageBox.Show("上傳失敗:網路異常");
474 }
475 }
476 AutoBackup();
477 }
478 _Logger.Info("POS_CLIENT 程式關閉 。");
479 mutex.ReleaseMutex();
480 if (_isProgramUpgraded)
481 {
482 Application.Restart();
483 }
484 }
485 else
486 {
487 MessageBox.Show($" \"{Application.ProductName}\" 執行中", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
488 }
489 }
490 catch (Exception ex2)
491 {
492 _Logger.Fatal("Main發生例外狀況:" + ex2.ToString());
493 MessageBox.Show($"Main發生例外狀況:「{ex2.ToString()}」");
494 }
495 }
496
497 private static string CheckShopType()
498 {
499 if (!NetworkInterface.GetIsNetworkAvailable())
500 {
501 DataTable dataTable = (DataTable)DataBaseUtilities.DBOperation(ConnectionString, "SELECT IsRetailer, IsWholesaler FROM hypos_ShopInfoManage", null, CommandOperationType.ExecuteReaderReturnDataTable);
502 string text = string.IsNullOrEmpty(dataTable.Rows[0]["IsRetailer"].ToString()) ? "NULL" : dataTable.Rows[0]["IsRetailer"].ToString();
503 string text2 = string.IsNullOrEmpty(dataTable.Rows[0]["IsWholesaler"].ToString()) ? "NULL" : dataTable.Rows[0]["IsWholesaler"].ToString();
504 if (text.Equals("ON") && text2.Equals("ON"))
505 {
506 ShopType = "0";
507 }
508 else if (text.Equals("ON") && (text2.Equals("OFF") || text2.Equals("NULL")))
509 {
510 ShopType = "1";
511 }
512 else if ((text.Equals("OFF") || text.Equals("NULL")) && text2.Equals("ON"))
513 {
514 ShopType = "2";
515 }
516 else
517 {
518 ShopType = "-1";
519 }
520 }
521 return "";
522 }
523
524 private static void AutoBackup()
525 {
526 _Logger.Info("DB自動備份 -- 開始");
527 string text = DataBaseUtilities.DBOperation(ConnectionString, TableOperation.Select, "AutoBackupPath", "hypos_CommonManage", "", "", null, null, CommandOperationType.ExecuteScalar).ToString();
528 if (!Directory.Exists(text))
529 {
530 Directory.CreateDirectory(text);
531 }
532 string str = "db_a_" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".db3";
533 File.Copy(DataPath + "\\db.db3", text + "\\" + str);
534 _Logger.Info("DB自動備份 -- 完成");
535 try
536 {
537 DirectoryInfo directoryInfo = new DirectoryInfo(text);
538 FileInfo[] files = directoryInfo.GetFiles("db_a_*.db3");
539 Array.Sort(files, (FileInfo x, FileInfo y) => y.CreationTime.CompareTo(x.CreationTime));
540 int num = 0;
541 List<string> list = new List<string>();
542 for (num = 0; num < files.Length; num++)
543 {
544 list.Add(files[num].ToString().Substring(0, 13));
545 }
546 list = list.Distinct().ToList();
547 for (num = 7; num < list.Count; num++)
548 {
549 list.RemoveAt(num);
550 }
551 List<int> list2 = new List<int>();
552 int num2 = 0;
553 for (num2 = 0; num2 < list.Count; num2++)
554 {
555 int num3 = 0;
556 for (num = 0; num < files.Length; num++)
557 {
558 if (files[num].ToString().Contains(list[num2]))
559 {
560 num3++;
561 }
562 if (num3 > 1 && files[num].ToString().Contains(list[num2]))
563 {
564 list2.Add(num);
565 }
566 }
567 }
568 list2 = list2.Distinct().ToList();
569 for (int i = 0; i < list2.Count; i++)
570 {
571 files[list2[i]].Delete();
572 }
573 files = directoryInfo.GetFiles("db_a_*.db3");
574 Array.Sort(files, (FileInfo x, FileInfo y) => y.CreationTime.CompareTo(x.CreationTime));
575 for (num = 7; num < files.Length; num++)
576 {
577 files[num].Delete();
578 }
579 }
580 catch (Exception ex)
581 {
582 _Logger.Fatal("清除舊資料時發生例外狀況:" + ex.ToString());
583 }
584 }
585
586 private static void AutoBackupDT()
587 {
588 string text = DataBaseUtilities.DBOperation(ConnectionString, TableOperation.Select, "AutoBackupPath", "hypos_CommonManage", "", "", null, null, CommandOperationType.ExecuteScalar).ToString();
589 if (!Directory.Exists(text))
590 {
591 Directory.CreateDirectory(text);
592 }
593 string str = "db_DT_" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".db3";
594 File.Copy(DataPath + "\\db.db3", text + "\\" + str);
595 }
596
597 private static void oldPOS_DataTransfer()
598 {
599 string value = DataBaseUtilities.DBOperation(ConnectionString, "SELECT SystemMode FROM hypos_SysParam", null, CommandOperationType.ExecuteScalar).ToString();
600 string value2 = DataBaseUtilities.DBOperation(ConnectionString, "SELECT IsDataTransfer FROM hypos_SysParam", null, CommandOperationType.ExecuteScalar).ToString();
601 if (!"Y".Equals(value2) && "".Equals(value))
602 {
603 new frmDataTransfer().ShowDialog();
604 if (File.Exists("C:\\Hypos\\Old_db.db3") && File.Exists("C:\\Hypos\\conn_log.txt"))
605 {
606 try
607 {
608 using (StreamReader streamReader = new StreamReader("C:\\\\Hypos\\\\conn_log.txt", Encoding.Unicode))
609 {
610 string text = streamReader.ReadToEnd();
611 if ("1".Equals(text.Substring(0, 1)))
612 {
613 try
614 {
615 AutoBackupDT();
616 new dbDataTransfer().ShowDialog();
617 DataBaseUtilities.DBOperation(ConnectionString, "UPDATE hypos_SysParam SET IsDataTransfer = 'Y'", null, CommandOperationType.ExecuteNonQuery);
618 }
619 catch (Exception ex)
620 {
621 MessageBox.Show($"dbDataTransfer發生例外狀況:「{ex.ToString()}」");
622 }
623 }
624 else if ("2".Equals(text.Substring(0, 1)))
625 {
626 DataBaseUtilities.DBOperation(ConnectionString, "UPDATE hypos_SysParam SET IsDataTransfer = 'Y'", null, CommandOperationType.ExecuteNonQuery);
627 MessageBox.Show("舊POS資料移轉程序已取消");
628 }
629 else
630 {
631 MessageBox.Show("舊POS系統資料匯入SQLite失敗。");
632 }
633 }
634 }
635 catch (Exception ex2)
636 {
637 MessageBox.Show($"開啟紀錄檔發生例外狀況:「{ex2.ToString()}」");
638 }
639 }
640 else if (File.Exists("C:\\Hypos\\conn_log.txt"))
641 {
642 try
643 {
644 using (StreamReader streamReader2 = new StreamReader("C:\\\\Hypos\\\\conn_log.txt", Encoding.Unicode))
645 {
646 string text2 = streamReader2.ReadToEnd();
647 if (!"2".Equals(text2.Substring(0, 1)))
648 {
649 MessageBox.Show("移轉程序失敗並結束。");
650 }
651 }
652 }
653 catch (Exception)
654 {
655 }
656 }
657 }
658 }
659
660 private static bool InitSystemParams()
661 {
662 try
663 {
664 _DataPath = (_isDeployClickOnce ? ApplicationDeployment.CurrentDeployment.DataDirectory : Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
665 _ConnString = "Data source=" + _DataPath + "\\db.db3;Password=1031;Version=3;Page Size=4096;Cache Size=2000;Synchronous=Full;";
666 _CRCFile = _DataPath + "\\Conn.log";
667 _HardDiskSerialNo = Encrypt(HardwareInfo.GetHDDSignature());
668 CheckDBSchema();
669 return true;
670 }
671 catch (Exception ex)
672 {
673 _Logger.Fatal("初始化程式參數過程中發生例外狀況 --" + ex.ToString());
674 MessageBox.Show($"初始化程式參數過程中發生例外狀況:「{ex.ToString()}」\r\n\r\n程式執行路徑為:「{DataPath}」", "例外訊息", MessageBoxButtons.OK, MessageBoxIcon.Hand);
675 }
676 return false;
677 }
678
679 private static string GetDBHardDiskSerialNo()
680 {
681 string sql = "SELECT HardDiskSerialNo FROM hypos_RegisterLicense where isApproved = 'Y' order by CreateDate desc limit 1";
682 string text = Convert.ToString(DataBaseUtilities.DBOperation(ConnectionString, sql, null, CommandOperationType.ExecuteScalar));
683 if ("-1".Equals(text))
684 {
685 return "";
686 }
687 return text;
688 }
689
690 public static int GetDBVersion()
691 {
692 try
693 {
694 DataTable dataTable = (DataTable)DataBaseUtilities.DBOperation(ConnectionString, TableOperation.Select, "*", "hypos_SysParam", "", "", null, null, CommandOperationType.ExecuteReaderReturnDataTable);
695 foreach (DataColumn column in dataTable.Columns)
696 {
697 if (column.Caption == "DBSchemaVersion")
698 {
699 return Convert.ToInt32(dataTable.Rows[0]["DBSchemaVersion"]);
700 }
701 }
702 return 0;
703 }
704 catch (Exception ex)
705 {
706 _Logger.Fatal("取得DB版本過程中發生例外狀況 --" + ex.ToString());
707 return -2;
708 }
709 }
710
711 private static void CheckDBSchema()
712 {
713 int num = GetDBVersion();
714 if (num != -2 && num != _DBSchemaV)
715 {
716 try
717 {
718 if (num < _DBSchemaV && num < 1)
719 {
720 string sql = "ALTER TABLE hypos_CUST_RTL ADD Verification TEXT";
721 string sql2 = "ALTER TABLE hypos_CUST_RTL ADD LastVerificationTime TEXT";
722 DataBaseUtilities.DBOperation(ConnectionString, sql, null, CommandOperationType.ExecuteNonQuery);
723 DataBaseUtilities.DBOperation(ConnectionString, sql2, null, CommandOperationType.ExecuteNonQuery);
724 num = 1;
725 }
726 if (num < _DBSchemaV && num < 2)
727 {
728 string sql3 = "ALTER TABLE hypos_GOODSLST ADD oldGDSNO TEXT";
729 string sql4 = "ALTER TABLE hypos_CUST_RTL ADD oldVIPNO TEXT; ALTER TABLE hypos_CUST_RTL ADD note TEXT;";
730 string sql5 = "ALTER TABLE hypos_Supplier ADD oldVENDO TEXT";
731 string sql6 = "ALTER TABLE hypos_main_sell ADD oldECRHDHSNo TEXT";
732 string sql7 = "ALTER TABLE hypos_PurchaseGoods_Master ADD oldCBNO TEXT";
733 string sql8 = "ALTER TABLE hypos_SysParam ADD IsDataTransfer TEXT";
734 DataBaseUtilities.DBOperation(ConnectionString, sql3, null, CommandOperationType.ExecuteNonQuery);
735 DataBaseUtilities.DBOperation(ConnectionString, sql4, null, CommandOperationType.ExecuteNonQuery);
736 DataBaseUtilities.DBOperation(ConnectionString, sql5, null, CommandOperationType.ExecuteNonQuery);
737 DataBaseUtilities.DBOperation(ConnectionString, sql6, null, CommandOperationType.ExecuteNonQuery);
738 DataBaseUtilities.DBOperation(ConnectionString, sql7, null, CommandOperationType.ExecuteNonQuery);
739 DataBaseUtilities.DBOperation(ConnectionString, sql8, null, CommandOperationType.ExecuteNonQuery);
740 num = 2;
741 }
742 if (num < _DBSchemaV && num < 3)
743 {
744 string sql9 = "ALTER TABLE hypos_main_sell ADD returnChange INTEGER";
745 DataBaseUtilities.DBOperation(ConnectionString, sql9, null, CommandOperationType.ExecuteNonQuery);
746 num = 3;
747 }
748 if (num < _DBSchemaV && num < 4)
749 {
750 string sql10 = "ALTER TABLE hypos_SysParam ADD IsCheckHyLicenceAndGoodslst TEXT";
751 DataBaseUtilities.DBOperation(ConnectionString, sql10, null, CommandOperationType.ExecuteNonQuery);
752 num = 4;
753 }
754 if (num < _DBSchemaV && num < 5)
755 {
756 string sql11 = "ALTER TABLE hypos_detailsell_log ADD sellDetailId INTEGER";
757 DataBaseUtilities.DBOperation(ConnectionString, sql11, null, CommandOperationType.ExecuteNonQuery);
758 num = 5;
759 }
760 if (num < _DBSchemaV && num < 6)
761 {
762 string[] array = new string[36]
763 {
764 "ALTER TABLE hypos_Form ADD Retailer INTEGER",
765 "ALTER TABLE hypos_Form ADD Wholesaler INTEGER",
766 "UPDATE hypos_Form SET Retailer = 1,Wholesaler = 0,ShowOrder = 1 WHERE FormID = 1",
767 "UPDATE hypos_Form SET Retailer = 1,Wholesaler = 0,FormColor = 'B',ShowOrder = 2 WHERE FormID = 2",
768 "UPDATE hypos_Form SET Retailer = 1,Wholesaler = 0,FormColor = 'B',ShowOrder = 3 WHERE FormID = 3",
769 "UPDATE hypos_Form SET Retailer = 1,Wholesaler = 0,ShowOrder = 4 WHERE FormID = 4",
770 "UPDATE hypos_Form SET Retailer = 1,Wholesaler = 1,FormColor = 'P',ShowOrder = 6 WHERE FormID = 5",
771 "UPDATE hypos_Form SET Retailer = 1,Wholesaler = 0 WHERE FormID = 6",
772 "UPDATE hypos_Form SET Retailer = 1,Wholesaler = 0,ShowOrder = 2 WHERE FormID = 7",
773 "UPDATE hypos_Form SET Retailer = 1,Wholesaler = 0,ShowOrder = 1 WHERE FormID = 9",
774 "UPDATE hypos_Form SET Retailer = 1,Wholesaler = 1,FormColor = 'P',ShowOrder = 8 WHERE FormID = 10",
775 "UPDATE hypos_Form SET Retailer = 1,Wholesaler = 1,FormName = '進貨管理',FormColor = 'B' WHERE FormID = 11",
776 "UPDATE hypos_Form SET Retailer = 1,Wholesaler = 1,FormName = '廠商管理',FormColor = 'B',ShowOrder = 6 WHERE FormID = 12",
777 "UPDATE hypos_Form SET Retailer = 1,Wholesaler = 1,FormColor = 'P',ShowOrder = 7 WHERE FormID = 13",
778 "UPDATE hypos_Form SET Retailer = 1,Wholesaler = 1,ShowOrder = 3 WHERE FormID = 14",
779 "INSERT INTO hypos_Form ( FormID,FormName,FormClass,FormColor,ShowOrder,FormType,Retailer,Wholesaler) VALUES( 15,'庫存管理','frmInventoryQuickEdit','B',5,0,1,1)",
780 "INSERT INTO hypos_ACL ( FormID,UserType) VALUES( 15,0)",
781 "INSERT INTO hypos_Form ( FormID,FormName,FormClass,FormColor,ShowOrder,FormType,Retailer,Wholesaler) VALUES( 16,'出貨管理','frmDeliveryMangement','O',9,0,0,1)",
782 "INSERT INTO hypos_ACL ( FormID,UserType) VALUES( 16,0)",
783 "INSERT INTO hypos_ACL ( FormID,UserType) VALUES( 16,1)",
784 "INSERT INTO hypos_Form ( FormID,FormName,FormClass,FormColor,ShowOrder,FormType,Retailer,Wholesaler) VALUES( 17,'庫存管理','frmInventoryQuickEdit','B',5,1,1,1)",
785 "INSERT INTO hypos_ACL ( FormID,UserType) VALUES( 17,0)",
786 "ALTER TABLE hypos_ShopInfoManage ADD IsRetailer TEXT",
787 "ALTER TABLE hypos_ShopInfoManage ADD IsWholesaler TEXT",
788 "ALTER TABLE hypos_Supplier ADD vendorId TEXT",
789 "ALTER TABLE hypos_Supplier ADD vendorName TEXT",
790 "ALTER TABLE hypos_Supplier ADD vendorType TEXT default '0'",
791 "ALTER TABLE hypos_PurchaseGoods_Detail ADD BatchNo TEXT",
792 "ALTER TABLE hypos_PurchaseGoods_Detail ADD MFGDate TEXT",
793 "ALTER TABLE hypos_PurchaseGoods_Detail ADD POSBatchNo TEXT",
794 "CREATE TABLE hypos_DeliveryGoods_Master( DeliveryId INTEGER PRIMARY KEY AUTOINCREMENT, DeliveryNo TEXT NOT NULL, DeliveryCustomNo TEXT, sumDiscount INT, OriSum INT, CurSum INT, items INT, itemstotal INT, BusinessName TEXT, CustomerLicNo TEXT, vendorNo TEXT, ShopType TEXT, changcount INT, status INT, DeliveryDate TEXT, editDate TEXT); ",
795 "CREATE TABLE hypos_DeliveryGoods_Master_log( DeliveryLogId INTEGER PRIMARY KEY AUTOINCREMENT, DeliveryNo TEXT, changeDate TEXT, isprint TEXT, iscancel INT, ischange INT, sum INT, sumDiscount INT); ",
796 "CREATE TABLE hypos_DeliveryGoods_Detail( DeliveryDeatialId INTEGER PRIMARY KEY AUTOINCREMENT, DeliveryNo TEXT, barcode TEXT, sellingPrice INT, num INT, subtotal INT, total INT, DeliveryDate TEXT, editDate TEXT, BatchNo TEXT, MFGDate TEXT, POSBatchNo TEXT); ",
797 "CREATE TABLE hypos_DeliveryGoods_Detail_Log( DeliveryDetailLogId INTEGER PRIMARY KEY AUTOINCREMENT, DeliveryLogId INT, DeliveryNo TEXT, barcode TEXT, sellingPrice INT, diffSellingPrice INT, num INT, diffNum INT, subtotal INT, total INT, editDate TEXT, DeliveryDeatialId INT); ",
798 "CREATE TABLE hypos_PurchaseGoodsBatchNo_log( id INTEGER PRIMARY KEY AUTOINCREMENT, POSBatchNo TEXT NOT NULL, BatchNo TEXT, MFGDate TEXT, barcode TEXT, num INT, PurchaseNo TEXT); ",
799 "CREATE TABLE hypos_BatchNo_log( id INTEGER PRIMARY KEY AUTOINCREMENT, POSBatchNo TEXT, barcode TEXT, num INT, backlogQuantity INT, createDate TEXT); "
800 };
801 for (int i = 0; i < array.Length; i++)
802 {
803 DataBaseUtilities.DBOperation(ConnectionString, array[i], null, CommandOperationType.ExecuteNonQuery);
804 }
805 num = 6;
806 }
807 if (num < _DBSchemaV && num < 7)
808 {
809 string[] array2 = new string[4]
810 {
811 "ALTER TABLE hypos_GOODSLST ADD DeliveryPrice INT default 0",
812 "ALTER TABLE hypos_GOODSLST ADD DeliveryPriceSetType TEXT default '0'",
813 "ALTER TABLE hypos_GOODSLST ADD DeliveryOpenPrice INT default 0",
814 "CREATE TABLE hypos_DeliveryPrice_log( id INTEGER PRIMARY KEY AUTOINCREMENT, GDSNO TEXT, price TEXT, Account TEXT, editDate TEXT, status TEXT); "
815 };
816 for (int j = 0; j < array2.Length; j++)
817 {
818 DataBaseUtilities.DBOperation(ConnectionString, array2[j], null, CommandOperationType.ExecuteNonQuery);
819 }
820 num = 7;
821 }
822 if (num < _DBSchemaV && num < 8)
823 {
824 string[] array3 = new string[1]
825 {
826 "ALTER TABLE hypos_DeliveryGoods_Detail ADD IsDeliveryOnly TEXT"
827 };
828 for (int k = 0; k < array3.Length; k++)
829 {
830 DataBaseUtilities.DBOperation(ConnectionString, array3[k], null, CommandOperationType.ExecuteNonQuery);
831 }
832 num = 8;
833 }
834 if (num < _DBSchemaV && num < 9)
835 {
836 string[] array4 = new string[5]
837 {
838 "ALTER TABLE hypos_DeliveryGoods_Detail ADD GoodsTotalCountLog INT",
839 "ALTER TABLE hypos_DeliveryGoods_Master ADD CreateDate TEXT",
840 "ALTER TABLE hypos_SysParam ADD UploadCountLastUpdateDate TEXT",
841 "ALTER TABLE hypos_SysParam ADD UploadShipLastUpdateDate TEXT",
842 "CREATE TABLE hypos_Sync_ship_detail_log( shipId INTEGER PRIMARY KEY AUTOINCREMENT, mainLogId INT, DeliveryNo TEXT, status TEXT, shipDateTime TEXT, vendorId TEXT, vendorName TEXT, vendorNO TEXT, itemNO INT, barcode TEXT, itemType TEXT, batchNO TEXT, MFD TEXT, shipQTY INT, salesTYPE TEXT, differNUM TEXT, dataType TEXT, dataName TEXT);"
843 };
844 for (int l = 0; l < array4.Length; l++)
845 {
846 DataBaseUtilities.DBOperation(ConnectionString, array4[l], null, CommandOperationType.ExecuteNonQuery);
847 }
848 num = 9;
849 }
850 if (num < _DBSchemaV && num < 10)
851 {
852 string[] array5 = new string[1]
853 {
854 "ALTER TABLE hypos_PurchaseGoods_Detail_Log ADD adjustType TEXT"
855 };
856 for (int m = 0; m < array5.Length; m++)
857 {
858 DataBaseUtilities.DBOperation(ConnectionString, array5[m], null, CommandOperationType.ExecuteNonQuery);
859 }
860 num = 10;
861 }
862 if (num < _DBSchemaV && num < 11)
863 {
864 string[] array6 = new string[4]
865 {
866 "ALTER TABLE hypos_InventoryAdjustment ADD batchNO TEXT",
867 "ALTER TABLE hypos_InventoryAdjustment ADD MFD TEXT",
868 "ALTER TABLE hypos_InventoryAdjustment ADD vendorId TEXT",
869 "ALTER TABLE hypos_InventoryAdjustment ADD vendorName TEXT"
870 };
871 for (int n = 0; n < array6.Length; n++)
872 {
873 DataBaseUtilities.DBOperation(ConnectionString, array6[n], null, CommandOperationType.ExecuteNonQuery);
874 }
875 num = 11;
876 }
877 if (num < _DBSchemaV && num < 12)
878 {
879 string[] array7 = new string[7]
880 {
881 "INSERT INTO hypos_Form ( FormID,FormName,FormClass,FormColor,ShowOrder,FormType,Retailer,Wholesaler) VALUES( 18,'無銷售回報','frmNoSaleReport','O',10,0,1,1)",
882 "INSERT INTO hypos_Form ( FormID,FormName,FormClass,FormColor,ShowOrder,FormType,Retailer,Wholesaler) VALUES( 19,'無銷售回報','frmNoSaleReport','O',7,1,1,1)",
883 "INSERT INTO hypos_ACL ( FormID,UserType) VALUES( 18,0)",
884 "INSERT INTO hypos_ACL ( FormID,UserType) VALUES( 18,1)",
885 "INSERT INTO hypos_ACL ( FormID,UserType) VALUES( 19,0)",
886 "INSERT INTO hypos_ACL ( FormID,UserType) VALUES( 19,1)",
887 "ALTER TABLE hypos_GOODSLST ADD hot_key TEXT"
888 };
889 for (int num2 = 0; num2 < array7.Length; num2++)
890 {
891 DataBaseUtilities.DBOperation(ConnectionString, array7[num2], null, CommandOperationType.ExecuteNonQuery);
892 }
893 num = 12;
894 }
895 DataBaseUtilities.DBOperation(ConnectionString, "Update hypos_SysParam set DBSchemaVersion = '" + _DBSchemaV + "'", null, CommandOperationType.ExecuteNonQuery);
896 }
897 catch (Exception ex)
898 {
899 _Logger.Fatal("確認及更新 DB Schema 過程中發生例外狀況 --" + ex.ToString());
900 }
901 }
902 }
903
904 private static RijndaelManaged GetRijndaelManaged(string secretKey)
905 {
906 byte[] array = new byte[16];
907 byte[] bytes = Encoding.UTF8.GetBytes(secretKey);
908 Array.Copy(bytes, array, Math.Min(array.Length, bytes.Length));
909 return new RijndaelManaged
910 {
911 Mode = CipherMode.CBC,
912 Padding = PaddingMode.PKCS7,
913 KeySize = 128,
914 BlockSize = 128,
915 Key = array,
916 IV = array
917 };
918 }
919
920 private static byte[] Encrypt(byte[] plainBytes, RijndaelManaged rijndaelManaged)
921 {
922 return rijndaelManaged.CreateEncryptor().TransformFinalBlock(plainBytes, 0, plainBytes.Length);
923 }
924
925 public static string Encrypt(string plainText)
926 {
927 return Convert.ToBase64String(Encrypt(Encoding.UTF8.GetBytes(plainText), GetRijndaelManaged("Hyweb@POS#E00T00")));
928 }
929}