private static void Main() { XmlConfigurator.ConfigureAndWatch(new FileInfo("log4net.config")); _Logger.Info("POS_CLIENT 程式啟動 !!"); switch (_ws) { case "test": _UploadDataURL = "http://10.10.4.161:8888/mPosCService/uploadData?wsdl"; _DownloadDataURL = "http://10.10.4.161:8888/mPosCService/ExpData?wsdl"; _AuthURL = "http://10.10.4.161:8888/mPosCService/PosCService?wsdl"; _VerificationURL = "http://10.10.4.161:8888/mPosMiddleware/POSService?wsdl"; break; case "posadmin": _UploadDataURL = "http://posadmin.baphiq.gov.tw/mPosCService/uploadData?wsdl"; _DownloadDataURL = "http://posadmin.baphiq.gov.tw/mPosCService/ExpData?wsdl"; _AuthURL = "http://posadmin.baphiq.gov.tw/mPosCService/PosCService?wsdl"; _VerificationURL = "http://posadmin.baphiq.gov.tw/mPosMiddlewareDisable/POSService?wsdl"; break; case "crop": _UploadDataURL = "http://crop.baphiq.gov.tw/mPosCService/uploadData?wsdl"; _DownloadDataURL = "http://posadmin.baphiq.gov.tw/mPosCService/ExpData?wsdl"; _AuthURL = "http://crop.baphiq.gov.tw/mPosCService/PosCService?wsdl"; _VerificationURL = "http://crop.baphiq.gov.tw/mPosMiddleware/POSService?wsdl"; break; } try { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); bool createdNew; Mutex mutex = new Mutex(true, Application.ProductName, out createdNew); if (createdNew) { new frmUpdate().ShowDialog(); if (!_isProgramUpgraded && InitSystemParams()) { string dBHardDiskSerialNo = GetDBHardDiskSerialNo(); if (dBHardDiskSerialNo == "") { new frmInitSysParam().Show(); Application.Run(); } else if (dBHardDiskSerialNo != _HardDiskSerialNo) { new frmInitSysParam().Show(); Application.Run(); } else { string sql = "SELECT RegisterCode FROM hypos_RegisterLicense where isApproved = 'Y' order by CreateDate desc limit 1"; _RegisterCode = Convert.ToString(DataBaseUtilities.DBOperation(ConnectionString, sql, null, CommandOperationType.ExecuteScalar)); if ("-1".Equals(_RegisterCode)) { new frmInitSysParam().Show(); Application.Run(); } else { AuthResultObject authResultObject = new AuthenticationWs().hasInUseRetry(_RegisterCode); if (bool.Parse(authResultObject.inUse)) { string sql2 = "SELECT LicenseCode FROM hypos_RegisterLicense where isApproved = 'Y' order by CreateDate desc limit 1"; _LincenseCode = Convert.ToString(DataBaseUtilities.DBOperation(ConnectionString, sql2, null, CommandOperationType.ExecuteScalar)); string lastUpdateDate = DataBaseUtilities.DBOperation(ConnectionString, "SELECT DownloadLastUpdateDate FROM hypos_SysParam", null, CommandOperationType.ExecuteScalar).ToString(); new frmDownload(_LincenseCode, lastUpdateDate).ShowDialog(); _SiteNo = authResultObject.serial; string sql3 = "update hypos_SysParam set SiteNo = {0} "; DataBaseUtilities.DBOperation(ConnectionString, sql3, new string[1] { _SiteNo }, CommandOperationType.ExecuteNonQuery); ShopType = authResultObject.shopType; if (!string.IsNullOrEmpty(ShopType)) { string sql4 = "SELECT ShopIdNo FROM hypos_ShopInfoManage"; if (((DataTable)DataBaseUtilities.DBOperation(ConnectionString, sql4, null, CommandOperationType.ExecuteReaderReturnDataTable)).Rows.Count > 0) { if (ShopType.Equals("0")) { DataBaseUtilities.DBOperation(ConnectionString, "UPDATE hypos_ShopInfoManage SET IsRetailer = {0}, IsWholesaler = {1} ", new string[2] { "ON", "ON" }, CommandOperationType.ExecuteNonQuery); } else if (ShopType.Equals("1")) { DataBaseUtilities.DBOperation(ConnectionString, "UPDATE hypos_ShopInfoManage SET IsRetailer = {0}, IsWholesaler = {1} ", new string[2] { "ON", "OFF" }, CommandOperationType.ExecuteNonQuery); } else if (ShopType.Equals("2")) { DataBaseUtilities.DBOperation(ConnectionString, "UPDATE hypos_ShopInfoManage SET IsRetailer = {0}, IsWholesaler = {1} ", new string[2] { "OFF", "ON" }, CommandOperationType.ExecuteNonQuery); } } else if (ShopType.Equals("0")) { DataBaseUtilities.DBOperation(ConnectionString, "INSERT INTO hypos_ShopInfoManage ( IsRetailer, IsWholesaler) VALUES( {0}, {1})", new string[2] { "ON", "ON" }, CommandOperationType.ExecuteNonQuery); } else if (ShopType.Equals("1")) { DataBaseUtilities.DBOperation(ConnectionString, "INSERT INTO hypos_ShopInfoManage ( IsRetailer, IsWholesaler) VALUES( {0}, {1}) ", new string[2] { "ON", "OFF" }, CommandOperationType.ExecuteNonQuery); } else if (ShopType.Equals("2")) { DataBaseUtilities.DBOperation(ConnectionString, "INSERT INTO hypos_ShopInfoManage ( IsRetailer, IsWholesaler) VALUES( {0}, {1}) ", new string[2] { "OFF", "ON" }, CommandOperationType.ExecuteNonQuery); } } if (IsDataTransfer) { oldPOS_DataTransfer(); } new frmLogin().Show(); Application.Run(); } else { MessageBox.Show(authResultObject.message); string[] strParameterArray = new string[2] { _RegisterCode, DateTime.Now.ToString() }; DataBaseUtilities.DBOperation(_ConnString, "UPDATE hypos_RegisterLicense SET isApproved = 'N', ApproveDate = {1} where RegisterCode = {0} ", strParameterArray, CommandOperationType.ExecuteNonQuery); new frmInitSysParam().Show(); Application.Run(); } } } if (NetworkInterface.GetIsNetworkAvailable()) { try { new frmUploadData().ShowDialog(); } catch (Exception ex) { _Logger.Fatal("上傳資料程序發生例外狀況:" + ex.ToString()); Console.WriteLine("Error Message : " + ex.Message); MessageBox.Show("上傳失敗:網路異常"); } } AutoBackup(); } _Logger.Info("POS_CLIENT 程式關閉 。"); mutex.ReleaseMutex(); if (_isProgramUpgraded) { Application.Restart(); } } else { MessageBox.Show(string.Format(" \"{0}\" 執行中", Application.ProductName), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } } catch (Exception ex2) { _Logger.Fatal("Main發生例外狀況:" + ex2.ToString()); MessageBox.Show(string.Format("Main發生例外狀況:「{0}」", ex2.ToString())); } }