F_P_00001.cs 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. 
  2. using System;
  3. using System.Diagnostics;
  4. using System.IO;
  5. using System.Reflection;
  6. using System.Windows.Forms;
  7. using Dongke.IBOSS.PRD.Basics.BaseResources;
  8. using Dongke.IBOSS.PRD.Basics.Library;
  9. using Dongke.IBOSS.PRD.Client.CommonModule;
  10. using Dongke.IBOSS.PRD.WCF.DataModels;
  11. using Dongke.IBOSS.PRD.WCF.Proxys;
  12. namespace Dongke.IBOSS.PRD.Client.Public
  13. {
  14. public partial class F_P_00001 : Form
  15. {
  16. public static int AccountID = 1;
  17. private string _filePath = LocalPath.RootPath + Constant.INI_FILE_NAME;
  18. //配置文件路径
  19. private string _iniFilePath = LocalPath.RootPath + Constant.INI_FILE_NAME;
  20. private string _localiniFilePath = AppDomain.CurrentDomain.BaseDirectory + Constant.INI_FILE_NAME;
  21. private string _ipAddress = null;
  22. private string _serverPort = null;
  23. public F_P_00001()
  24. {
  25. InitializeComponent();
  26. // 存在该文件,直接读取该文件,否则不读取
  27. if (!File.Exists(_localiniFilePath) && File.Exists(this._iniFilePath))
  28. {
  29. File.Copy(this._iniFilePath, _localiniFilePath);
  30. }
  31. _filePath = this._localiniFilePath;
  32. }
  33. private void F_P_00001_Load(object sender, EventArgs e)
  34. {
  35. this.lblTest.Text = this.Text;
  36. }
  37. private void F_P_00001_Shown(object sender, EventArgs e)
  38. {
  39. try
  40. {
  41. if (this.CheckIP(true))
  42. {
  43. // 设定静态常量中的web服务地址
  44. ProxySettings.ResetRemoteAddress(this._ipAddress, this._serverPort);
  45. }
  46. this.btnFP00002_Click(null, null);
  47. }
  48. catch (Exception ex)
  49. {
  50. // 对异常进行共通处理
  51. ExceptionManager.HandleEventException(this.ToString(),
  52. MethodBase.GetCurrentMethod().Name, this.Text, ex);
  53. }
  54. }
  55. private void btnSetting_Click(object sender, System.EventArgs e)
  56. {
  57. try
  58. {
  59. F_SYS_0102 frmSYS0102 = new F_SYS_0102();
  60. if (frmSYS0102.ShowDialog(this) == DialogResult.OK)
  61. {
  62. this._ipAddress = Utility.ReadIniFile(Constant.INI_SECTION_NET,
  63. Constant.INI_KEY_IP, this._filePath);
  64. this._serverPort = Utility.ReadIniFile(Constant.INI_SECTION_NET,
  65. Constant.INI_KEY_PORT, this._filePath);
  66. // 设定静态常量中的web服务地址
  67. ProxySettings.ResetRemoteAddress(this._ipAddress, this._serverPort);
  68. }
  69. }
  70. catch (Exception ex)
  71. {
  72. // 对异常进行共通处理
  73. ExceptionManager.HandleEventException(this.ToString(),
  74. MethodBase.GetCurrentMethod().Name, this.Text, ex);
  75. }
  76. }
  77. private void btnUpdate_Click(object sender, System.EventArgs e)
  78. {
  79. try
  80. {
  81. if (!AutoUp())
  82. {
  83. MessageBox.Show("已是最新版本,无需升级。", Messages.MSG_TITLE_I01
  84. , MessageBoxButtons.OK, MessageBoxIcon.Information);
  85. }
  86. }
  87. catch (Exception ex)
  88. {
  89. // 对异常进行共通处理
  90. ExceptionManager.HandleEventException(this.ToString(),
  91. MethodBase.GetCurrentMethod().Name, this.Text, ex);
  92. }
  93. }
  94. private bool CheckService()
  95. {
  96. if (!this.CheckIP(false))
  97. {
  98. MessageBox.Show("未配置服务地址或端口。\r\n请先配置服务地址和端口,再进行操作。", Messages.MSG_TITLE_W01
  99. , MessageBoxButtons.OK, MessageBoxIcon.Warning);
  100. return false;
  101. }
  102. AutoUp();
  103. return true;
  104. }
  105. private bool CheckIP(bool isSet)
  106. {
  107. if (isSet && File.Exists(this._filePath))
  108. {
  109. this._ipAddress = Utility.ReadIniFile(Constant.INI_SECTION_NET,
  110. Constant.INI_KEY_IP, this._filePath);
  111. this._serverPort = Utility.ReadIniFile(Constant.INI_SECTION_NET,
  112. Constant.INI_KEY_PORT, this._filePath);
  113. string accountID = Utility.ReadIniFile(Constant.INI_SECTION_SETTINGS,
  114. "AccountID", this._filePath);
  115. if (!string.IsNullOrWhiteSpace(accountID))
  116. {
  117. F_P_00001.AccountID = int.Parse(accountID);
  118. }
  119. else
  120. {
  121. Utility.WriteIniFile(Constant.INI_SECTION_SETTINGS, "AccountID",
  122. F_P_00001.AccountID.ToString(), this._filePath);
  123. }
  124. }
  125. if (string.IsNullOrWhiteSpace(this._ipAddress) ||
  126. string.IsNullOrWhiteSpace(this._serverPort))
  127. {
  128. if (isSet)
  129. {
  130. F_SYS_0102 fsys0102 = new F_SYS_0102();
  131. if (fsys0102.ShowDialog() == DialogResult.OK)
  132. {
  133. this._ipAddress = Utility.ReadIniFile(Constant.INI_SECTION_NET,
  134. Constant.INI_KEY_IP, this._filePath);
  135. this._serverPort = Utility.ReadIniFile(Constant.INI_SECTION_NET,
  136. Constant.INI_KEY_PORT, this._filePath);
  137. return true;
  138. }
  139. }
  140. return false;
  141. }
  142. return true;
  143. }
  144. public static bool AutoUp()
  145. {
  146. FileVersionInfo info = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location);
  147. // 自动更新
  148. NeedUpgradeResultEntity needUpgradeInfo = PublicModuleProxy.Service.IsNeedUpgrade(info.FileVersion);
  149. if (needUpgradeInfo.UpgradeState)
  150. {
  151. //needUpgradeInfo.GradeInfo =
  152. // string.Format("本地程序版本:{0}\r\n最新程序版本:{1}",
  153. // info.FileVersion, needUpgradeInfo.ServerVersion);
  154. // 如果有提示信息提示,没有就跳过
  155. //if (!string.IsNullOrEmpty(needUpgradeInfo.GradeInfo))
  156. //{
  157. // F_SYS_0103 frmAutoUpgradeInfo = new F_SYS_0103(needUpgradeInfo.GradeInfo);
  158. // DialogResult dialogResult = frmAutoUpgradeInfo.ShowDialog(this);
  159. // if (dialogResult != DialogResult.OK)
  160. // {
  161. // Application.Exit();
  162. // }
  163. // else
  164. // {
  165. // Application.Exit();
  166. // //Process.Start("AutoUpgrade.exe");
  167. // Process.Start(System.AppDomain.CurrentDomain.BaseDirectory + "AutoUpgrade.exe", "IBOSSPRDPublic.exe");
  168. // }
  169. // Process.Start(System.AppDomain.CurrentDomain.BaseDirectory + "AutoUpgrade.exe", "IBOSSPRDPublic.exe");
  170. //}
  171. //else
  172. {
  173. Application.Exit();
  174. Process.Start(System.AppDomain.CurrentDomain.BaseDirectory + "AutoUpgrade.exe", "IBOSSPRDPublic.exe");
  175. }
  176. return true;
  177. }
  178. else
  179. {
  180. return false;
  181. }
  182. }
  183. private void btnFP00002_Click(object sender, EventArgs e)
  184. {
  185. try
  186. {
  187. if (!this.CheckService())
  188. {
  189. return;
  190. }
  191. F_P_00002 FP00002 = new F_P_00002();
  192. FP00002.ShowDialog(this);
  193. }
  194. catch (Exception ex)
  195. {
  196. // 对异常进行共通处理
  197. ExceptionManager.HandleEventException(this.ToString(),
  198. MethodBase.GetCurrentMethod().Name, this.Text, ex);
  199. }
  200. }
  201. private void btnClose_Click(object sender, EventArgs e)
  202. {
  203. this.Close();
  204. }
  205. private void btnCache_Click(object sender, EventArgs e)
  206. {
  207. System.Diagnostics.Process.Start(LocalPath.RootPath);
  208. }
  209. }
  210. }