CNAS取数仪器端升级
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

223 lines
8.7KB

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