CNAS取数仪器端升级
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

frmBalanceDB.cs 8.1KB

5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. using CnasSynchronusClient;
  2. using CnasSynchrousModel;
  3. using System;
  4. using System.IO;
  5. using System.Windows.Forms;
  6. using System.Xml.Serialization;
  7. namespace CNASBalanceDBManage
  8. {
  9. public partial class frmBalanceDB : Form
  10. {
  11. public DataBaseInfo CNASDataBase { get; set; }
  12. public DataBaseInfo PlatDataBase { get; set; }
  13. public string strOldPwd { get; set; }
  14. public frmBalanceDB()
  15. {
  16. InitializeComponent();
  17. }
  18. private void btnCNASTestLink_Click(object sender, EventArgs e)
  19. {
  20. if (this.txtDBHost.Text.Trim() == "" || this.txtDBName.Text.Trim() == "" || this.txtDBUser.Text.Trim() == "" || this.txtDBPwd.Text.Trim() == "" || this.txtPort.Text.Trim()=="")
  21. {
  22. MessageBox.Show("不允许为空!");
  23. return;
  24. }
  25. if (CnasDataOperationFact.CnasDataOperation().TestConnect(this.txtDBHost.Text.Trim(), this.txtDBName.Text.Trim(), this.txtDBUser.Text.Trim(), this.txtDBPwd.Text.Trim(), this.txtPort.Text.Trim()))
  26. MessageBox.Show("连接成功!");
  27. else
  28. MessageBox.Show("连接失败!");
  29. }
  30. private void frmBalanceDB_Load(object sender, EventArgs e)
  31. {
  32. CNASDataBase = FileOperation.GetLocalCnasDB();
  33. if (this.CNASDataBase != null)
  34. {
  35. this.txtDBHost.Text = CNASDataBase.DBHost;
  36. this.txtDBName.Text = CNASDataBase.DBName;
  37. this.txtDBUser.Text = CNASDataBase.DBUser;
  38. this.txtDBPwd.Text = CNASDataBase.DBPwd;
  39. this.txtPort.Text = CNASDataBase.DBPort;
  40. }
  41. PlatDataBase = FileOperation.GetLocalPlatFormDB();
  42. if(PlatDataBase!=null)
  43. {
  44. this.txtPlatHost.Text = PlatDataBase.DBHost;
  45. this.txtPlatServer.Text = PlatDataBase.DBName;
  46. this.txtPlatUser.Text = PlatDataBase.DBUser;
  47. this.txtPlatPwd.Text = PlatDataBase.DBPwd;
  48. this.txtPlatPort.Text = PlatDataBase.DBPort;
  49. }
  50. strOldPwd = FileOperation.GetLocalOperationPwd();
  51. }
  52. private void btnOK_Click(object sender, EventArgs e)
  53. {
  54. bool bIfSavePwd = false;
  55. if (this.txtDBHost.Text.Trim() == "" || this.txtDBName.Text.Trim() == "" || this.txtDBUser.Text.Trim() == "" || this.txtDBPwd.Text.Trim() == "" || this.txtPort.Text.Trim() == "")
  56. {
  57. MessageBox.Show("CNAS数据库配置不允许为空!");
  58. return;
  59. }
  60. if (this.txtPlatHost.Text.Trim() == "" || this.txtPlatServer.Text.Trim() == "" || this.txtPlatUser.Text.Trim() == "" || this.txtPlatPwd.Text.Trim() == "" || this.txtPlatPort.Text.Trim() == "")
  61. {
  62. MessageBox.Show("平台数据库配置不允许为空!");
  63. return;
  64. }
  65. if (this.txtOldPwd.Text == "" && this.txtNewPwd.Text == "" && this.txtRepeatPwd.Text == "") //此时认为用户无意修改密码
  66. {
  67. bIfSavePwd = false;
  68. }
  69. else
  70. {
  71. //旧密码不正确
  72. if (this.txtOldPwd.Text == ""||(this.txtOldPwd.Text != "" && this.txtOldPwd.Text != strOldPwd))
  73. {
  74. MessageBox.Show("旧操作密码错误!");
  75. return;
  76. }
  77. if (this.txtNewPwd.Text.Trim() == "")
  78. {
  79. MessageBox.Show("新操作密码不能为空!");
  80. return;
  81. }
  82. if (this.txtOldPwd.Text == this.txtNewPwd.Text)
  83. {
  84. MessageBox.Show("新旧操作密码不能一样!");
  85. return;
  86. }
  87. if (this.txtNewPwd.Text.Trim() != this.txtRepeatPwd.Text.Trim())
  88. {
  89. MessageBox.Show("重复输入操作密码不一样!");
  90. return;
  91. }
  92. bIfSavePwd = true;
  93. }
  94. //目标库的信息
  95. CNASDataBase.DBHost = this.txtDBHost.Text.Trim();
  96. CNASDataBase.DBName = this.txtDBName.Text.Trim();
  97. CNASDataBase.DBUser = this.txtDBUser.Text.Trim();
  98. CNASDataBase.DBPwd = this.txtDBPwd.Text.Trim();
  99. CNASDataBase.DBPort = this.txtPort.Text.Trim();
  100. PlatDataBase.DBHost = this.txtPlatHost.Text.Trim();
  101. PlatDataBase.DBName = this.txtPlatServer.Text.Trim();
  102. PlatDataBase.DBUser = this.txtPlatUser.Text.Trim();
  103. PlatDataBase.DBPwd = this.txtPlatPwd.Text.Trim();
  104. PlatDataBase.DBPort = this.txtPlatPort.Text.Trim();
  105. /*一套有点恶心的逻辑,但没想到其他的方案*/
  106. //保存数据到本地
  107. if (!bIfSavePwd) //此时没有修改密码,此时只判断两个数据库配置的存储
  108. {
  109. bool bSaveCNAS = FileOperation.SaveLocalCnasDB(CNASDataBase);
  110. bool bSavePlat= FileOperation.SaveLocalPlatDB(PlatDataBase);
  111. if (bSaveCNAS && bSavePlat)
  112. {
  113. MessageBox.Show("数据库配置保存成功!");
  114. }
  115. else if (bSaveCNAS && !bSavePlat)
  116. {
  117. MessageBox.Show("平台数据库配置保存失败。");
  118. }
  119. else if (!bSaveCNAS && bSavePlat)
  120. {
  121. MessageBox.Show("CNAS数据库配置保存失败。");
  122. }
  123. else
  124. {
  125. MessageBox.Show("数据库配置保存失败。");
  126. }
  127. }
  128. else
  129. {
  130. string strMsg = "";
  131. bool bSaveDB = bSaveDataBase(ref strMsg);
  132. bool bSavePwd = FileOperation.SaveLocalOperationPwd(this.txtNewPwd.Text.Trim());
  133. if (bSaveDB == true && bSavePwd == true)
  134. {
  135. MessageBox.Show("保存成功!");
  136. }
  137. else if (bSaveDB == true && bSavePwd == false)
  138. {
  139. MessageBox.Show("数据库配置保存成功,操作密码保存失败!");
  140. }
  141. else if (bSaveDB == false && bSavePwd == true)
  142. {
  143. MessageBox.Show(strMsg+"操作密码设置保存成功!");
  144. }
  145. else
  146. {
  147. MessageBox.Show("保存失败!");
  148. }
  149. }
  150. }
  151. private bool bSaveDataBase(ref string strMsg)
  152. {
  153. bool bSaveCNAS = FileOperation.SaveLocalCnasDB(CNASDataBase);
  154. bool bSavePlat = FileOperation.SaveLocalPlatDB(PlatDataBase);
  155. if (bSaveCNAS && bSavePlat)
  156. {
  157. strMsg="数据库配置保存成功!";
  158. return true;
  159. }
  160. else if (bSaveCNAS && !bSavePlat)
  161. {
  162. strMsg = "平台数据库配置保存失败。";
  163. return false;
  164. }
  165. else if (!bSaveCNAS && bSavePlat)
  166. {
  167. strMsg = "CNAS数据库配置保存失败。";
  168. return false;
  169. }
  170. else
  171. {
  172. strMsg = "数据库配置保存失败。";
  173. return false;
  174. }
  175. }
  176. private void btnPlatTest_Click(object sender, EventArgs e)
  177. {
  178. if (this.txtPlatHost.Text.Trim() == "" || this.txtPlatServer.Text.Trim() == "" || this.txtPlatUser.Text.Trim() == "" || this.txtPlatPwd.Text.Trim() == "" || this.txtPlatPort.Text.Trim() == "")
  179. {
  180. MessageBox.Show("平台数据库配置不允许为空!");
  181. return;
  182. }
  183. if (CnasDataOperationFact.CnasDataOperation().TestConnect(this.txtPlatHost.Text.Trim(), this.txtPlatServer.Text.Trim(), this.txtPlatUser.Text.Trim(), this.txtPlatPwd.Text.Trim(), this.txtPlatPort.Text.Trim()))
  184. MessageBox.Show("连接成功!");
  185. else
  186. MessageBox.Show("连接失败!");
  187. }
  188. }
  189. }