CNAS取数仪器端升级
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

1150 řádky
52KB

  1. using CnasSynchronusClient;
  2. using CnasSynchrousModel;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Data;
  7. using System.Drawing;
  8. using System.IO;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Windows.Forms;
  12. using System.Xml.Serialization;
  13. namespace CNAS_DBSync
  14. {
  15. public delegate void InstrumentItemDataHanlder(Dictionary<string, DataTable> dictInstrument);
  16. public partial class frmDatabaseParams : Form
  17. {
  18. public SyncInstrumentItemInfo syncInstrumentItem = new SyncInstrumentItemInfo(); //仪器信息项
  19. public Dictionary<string, DataTable> dictInstrument = new Dictionary<string, DataTable>();
  20. public InstumentCodeHanlder InstrumentDelegate; //传递仪器编码委托
  21. public InstrumentItemDataHanlder InstrumentItemData; //传递仪器项委托
  22. private string strReadExcelMode = ""; //读取Excel数据模式
  23. private string strReadFoxproMode = ""; //读取Foxpro数据模式
  24. private string strReadTxtMode = "";//读取Txt数据模式
  25. private string strReadSqliteMode = ""; //读取sqlite数据模式
  26. private string strReadAccessMode = ""; //读取Access数据模式
  27. public DataBaseInfo targetDataBaseInfo = new DataBaseInfo(); //数据库
  28. public SqlServerFormatConfig sqlServerFormat { get; set; }
  29. public frmDatabaseParams(SyncInstrumentItemInfo syncInstrumentItem)
  30. {
  31. InitializeComponent();
  32. this.syncInstrumentItem = syncInstrumentItem;
  33. //读取Excel和FoxPro的模式
  34. strReadExcelMode = FileOperation.GetFormatConfigData<ExcelFormatConfig>("ExcelFormatConfig.xml").ReadExcelFileMode;
  35. strReadFoxproMode = FileOperation.GetFormatConfigData<FoxProFormatConfig>("FoxProFormatConfig.xml").ReadFoxProFileMode;
  36. strReadTxtMode = FileOperation.GetFormatConfigData<NormalFileFormatConfig>("NormalFileFormatConfig.xml").ReadNormalFileMode;
  37. strReadSqliteMode = FileOperation.GetFormatConfigData<SqliteFormatConfig>("SqliteFormatConfig.xml").ReadSqliteFileMode;
  38. strReadAccessMode = FileOperation.GetFormatConfigData<AccessFormatConfig>("AccessFormatConfig.xml").ReadAccessFileMode;
  39. sqlServerFormat = FileOperation.GetFormatConfigData<SqlServerFormatConfig>("SqlServerFormatConfig.xml");
  40. if (GlobalCommonOperation.strStartWebApi == "1")
  41. {
  42. this.txtDBHost.Enabled = false;
  43. this.txtDBName.Enabled = false;
  44. this.txtDBUser.Enabled = false;
  45. this.txtDBPwd.Enabled = false;
  46. this.txtPort.Enabled = false;
  47. btnCNASTestLink.Enabled = false;
  48. }
  49. }
  50. private void frmDatabaseParams_Load(object sender, EventArgs e)
  51. {
  52. tabExcel.Text = strReadExcelMode == "0" ? "Excel(文件)" : "Excel(文件夹)";
  53. tabFoxPro.Text = strReadFoxproMode == "0" ? "Foxpro(文件)" : "Foxpro(文件夹)";
  54. tabTxt.Text = strReadTxtMode == "0" ? "TXT(文件)" : "TXT(文件夹)";
  55. tabSQLite.Text = strReadSqliteMode == "0" ? "Sqlite(文件)" : "Sqlite(文件夹)";
  56. tabAccess.Text = strReadAccessMode == "0" ? "Access(文件)" : "Access(文件夹)";
  57. //if(sqlServerFormat)
  58. if (syncInstrumentItem.SyncInstrumentDSInfo == null)
  59. syncInstrumentItem.SyncInstrumentDSInfo = new InstrumentDataSourceInfo();
  60. //如果有旧值,加载旧的值
  61. switch (syncInstrumentItem.SyncInstrumentDSInfo.InstrumentDataSourceType)
  62. {
  63. case DataSourceType.Excel:
  64. this.tabcDS.SelectedIndex = 0;
  65. this.txtInportExcel.Text = syncInstrumentItem.SyncInstrumentDSInfo.Path;
  66. this.cbxExcelRemote.Checked = syncInstrumentItem.SyncInstrumentDSInfo.DsPathType == PathType.Local ? false : true;
  67. this.txtRemoteExcelUser.Text = syncInstrumentItem.SyncInstrumentDSInfo.RemoteUser;
  68. this.txtRemoteExcelPwd.Text = syncInstrumentItem.SyncInstrumentDSInfo.RemotePwd;
  69. break;
  70. case DataSourceType.FoxPro:
  71. this.tabcDS.SelectedIndex = 1;
  72. this.txtFoxProFolder.Text = syncInstrumentItem.SyncInstrumentDSInfo.Path;
  73. this.txtFoxProUserId.Text = syncInstrumentItem.SyncInstrumentDSInfo.UserId;
  74. this.txtFoxProPwd.Text = syncInstrumentItem.SyncInstrumentDSInfo.UserPwd;
  75. this.cbxFoxProRemote.Checked = syncInstrumentItem.SyncInstrumentDSInfo.DsPathType == PathType.Local ? false : true;
  76. this.txtRemoteFoxProUserId.Text = syncInstrumentItem.SyncInstrumentDSInfo.RemoteUser;
  77. this.txtRemoteFoxProPwd.Text = syncInstrumentItem.SyncInstrumentDSInfo.RemotePwd;
  78. break;
  79. case DataSourceType.Access:
  80. this.tabcDS.SelectedIndex = 2;
  81. this.txtAccessPath.Text = syncInstrumentItem.SyncInstrumentDSInfo.Path;
  82. this.txtAccessUser.Text = syncInstrumentItem.SyncInstrumentDSInfo.UserId;
  83. this.txtAceessPwd.Text = syncInstrumentItem.SyncInstrumentDSInfo.UserPwd;
  84. this.cbxAccessRemote.Checked = syncInstrumentItem.SyncInstrumentDSInfo.DsPathType == PathType.Local ? false : true;
  85. this.txtAccessRemoteUser.Text = syncInstrumentItem.SyncInstrumentDSInfo.RemoteUser;
  86. this.txtAccessRemotePwd.Text = syncInstrumentItem.SyncInstrumentDSInfo.RemotePwd;
  87. break;
  88. case DataSourceType.SQLLite:
  89. this.tabcDS.SelectedIndex = 3;
  90. this.txtSqlitePath.Text = syncInstrumentItem.SyncInstrumentDSInfo.Path;
  91. this.txtSqliteUser.Text = syncInstrumentItem.SyncInstrumentDSInfo.UserId;
  92. this.txtSqlitePwd.Text = syncInstrumentItem.SyncInstrumentDSInfo.UserPwd;
  93. this.cbxSqliteRemote.Checked = syncInstrumentItem.SyncInstrumentDSInfo.DsPathType == PathType.Local ? false : true;
  94. this.txtSqliteRemoteUser.Text = syncInstrumentItem.SyncInstrumentDSInfo.RemoteUser;
  95. this.txtSqliteRemotePwd.Text = syncInstrumentItem.SyncInstrumentDSInfo.RemotePwd;
  96. break;
  97. case DataSourceType.SQL:
  98. this.tabcDS.SelectedIndex = 4;
  99. this.txtSqlServerHost.Text = syncInstrumentItem.SyncInstrumentDSInfo.Host;
  100. this.txtSqlServerName.Text = syncInstrumentItem.SyncInstrumentDSInfo.ServerName;
  101. this.txtSqlServerUser.Text = syncInstrumentItem.SyncInstrumentDSInfo.UserId;
  102. this.txtSqlServerPwd.Text = syncInstrumentItem.SyncInstrumentDSInfo.UserPwd;
  103. //this.txtSqlServerConnect.Text = sqlServerFormat.SqlServerConnection;
  104. break;
  105. case DataSourceType.MySQL:
  106. this.tabcDS.SelectedIndex = 5;
  107. this.txtMySqlHost.Text = syncInstrumentItem.SyncInstrumentDSInfo.Host;
  108. this.txtMySqlServer.Text = syncInstrumentItem.SyncInstrumentDSInfo.ServerName;
  109. this.txtMySqlUser.Text = syncInstrumentItem.SyncInstrumentDSInfo.UserId;
  110. this.txtMySqlPwd.Text = syncInstrumentItem.SyncInstrumentDSInfo.UserPwd;
  111. this.txtMySqlPort.Text = syncInstrumentItem.SyncInstrumentDSInfo.Port;
  112. break;
  113. case DataSourceType.Oracle:
  114. this.tabcDS.SelectedIndex = 6;
  115. this.txtOracleHost.Text = syncInstrumentItem.SyncInstrumentDSInfo.Host;
  116. this.txtOracleSource.Text = syncInstrumentItem.SyncInstrumentDSInfo.ServerName;
  117. this.txtOracleUserId.Text = syncInstrumentItem.SyncInstrumentDSInfo.UserId;
  118. this.txtOraclePwd.Text = syncInstrumentItem.SyncInstrumentDSInfo.UserPwd;
  119. this.txtOraclePort.Text = syncInstrumentItem.SyncInstrumentDSInfo.Port;
  120. break;
  121. case DataSourceType.TXT:
  122. this.tabcDS.SelectedIndex = 7;
  123. this.txtInportTxt.Text = syncInstrumentItem.SyncInstrumentDSInfo.Path;
  124. this.cbxRemoteTxt.Checked = syncInstrumentItem.SyncInstrumentDSInfo.DsPathType == PathType.Local ? false : true;
  125. this.txtRemoteTxtUserId.Text = syncInstrumentItem.SyncInstrumentDSInfo.RemoteUser;
  126. this.txtRemoteTxtPwd.Text = syncInstrumentItem.SyncInstrumentDSInfo.RemotePwd;
  127. break;
  128. case DataSourceType.PostgreSQL:
  129. this.tabcDS.SelectedIndex = 8;
  130. this.txtPostgreSqlHost.Text = syncInstrumentItem.SyncInstrumentDSInfo.Host;
  131. this.txtPostgreSqlServer.Text = syncInstrumentItem.SyncInstrumentDSInfo.ServerName;
  132. this.txtPostgreSqlUser.Text = syncInstrumentItem.SyncInstrumentDSInfo.UserId;
  133. this.txtPostgreSqlPwd.Text = syncInstrumentItem.SyncInstrumentDSInfo.UserPwd;
  134. this.txtPostgreSqlPort.Text = syncInstrumentItem.SyncInstrumentDSInfo.Port;
  135. break;
  136. default:
  137. break;
  138. }
  139. //加载旧的CNAS数据库信息
  140. if (syncInstrumentItem.SyncTargetDBInfo != null)
  141. {
  142. targetDataBaseInfo = syncInstrumentItem.SyncTargetDBInfo;
  143. }
  144. else
  145. syncInstrumentItem.SyncTargetDBInfo = new DataBaseInfo();
  146. this.txtDBHost.Text = targetDataBaseInfo.DBHost;
  147. this.txtDBName.Text = targetDataBaseInfo.DBName;
  148. this.txtDBUser.Text = targetDataBaseInfo.DBUser;
  149. this.txtDBPwd.Text = targetDataBaseInfo.DBPwd;
  150. this.txtPort.Text = targetDataBaseInfo.DBPort;
  151. }
  152. private void btnOK_Click(object sender, EventArgs e)
  153. {
  154. //点击确定按钮
  155. //InstrumentData instrumentData = null;
  156. switch (syncInstrumentItem.SyncInstrumentDSInfo.InstrumentDataSourceType)
  157. {
  158. case DataSourceType.Access:
  159. syncInstrumentItem.SyncInstrumentDSInfo.Path = this.txtAccessPath.Text.Trim();
  160. syncInstrumentItem.SyncInstrumentDSInfo.Host = "";
  161. syncInstrumentItem.SyncInstrumentDSInfo.ServerName = "";
  162. syncInstrumentItem.SyncInstrumentDSInfo.UserId = this.txtAccessUser.Text.Trim();
  163. syncInstrumentItem.SyncInstrumentDSInfo.UserPwd = this.txtAceessPwd.Text.Trim();
  164. syncInstrumentItem.SyncInstrumentDSInfo.DsPathType = this.cbxAccessRemote.Checked ? PathType.Remote : PathType.Local;
  165. syncInstrumentItem.SyncInstrumentDSInfo.RemoteUser = this.txtAccessRemoteUser.Text.Trim();
  166. syncInstrumentItem.SyncInstrumentDSInfo.RemotePwd = this.txtAccessRemotePwd.Text.Trim();
  167. break;
  168. case DataSourceType.SQLLite:
  169. syncInstrumentItem.SyncInstrumentDSInfo.Path = this.txtSqlitePath.Text.Trim();
  170. syncInstrumentItem.SyncInstrumentDSInfo.Host = "";
  171. syncInstrumentItem.SyncInstrumentDSInfo.ServerName = "";
  172. syncInstrumentItem.SyncInstrumentDSInfo.UserId = this.txtSqliteUser.Text.Trim();
  173. syncInstrumentItem.SyncInstrumentDSInfo.UserPwd = this.txtSqlitePwd.Text.Trim();
  174. syncInstrumentItem.SyncInstrumentDSInfo.DsPathType = this.cbxSqliteRemote.Checked ? PathType.Remote : PathType.Local;
  175. syncInstrumentItem.SyncInstrumentDSInfo.RemoteUser = this.txtSqliteRemoteUser.Text.Trim();
  176. syncInstrumentItem.SyncInstrumentDSInfo.RemotePwd = this.txtSqliteRemotePwd.Text.Trim();
  177. break;
  178. case DataSourceType.SQL:
  179. syncInstrumentItem.SyncInstrumentDSInfo.Host = this.txtSqlServerHost.Text.Trim();
  180. syncInstrumentItem.SyncInstrumentDSInfo.ServerName = this.txtSqlServerName.Text.Trim();
  181. syncInstrumentItem.SyncInstrumentDSInfo.UserId = this.txtSqlServerUser.Text.Trim();
  182. syncInstrumentItem.SyncInstrumentDSInfo.UserPwd = this.txtSqlServerPwd.Text.Trim();
  183. break;
  184. case DataSourceType.MySQL:
  185. syncInstrumentItem.SyncInstrumentDSInfo.Host = this.txtMySqlHost.Text.Trim();
  186. syncInstrumentItem.SyncInstrumentDSInfo.ServerName = this.txtMySqlServer.Text.Trim();
  187. syncInstrumentItem.SyncInstrumentDSInfo.UserId = this.txtMySqlUser.Text.Trim();
  188. syncInstrumentItem.SyncInstrumentDSInfo.UserPwd = this.txtMySqlPwd.Text.Trim();
  189. syncInstrumentItem.SyncInstrumentDSInfo.Port = this.txtMySqlPort.Text.Trim();
  190. break;
  191. case DataSourceType.Oracle:
  192. syncInstrumentItem.SyncInstrumentDSInfo.Host = this.txtOracleHost.Text.Trim();
  193. syncInstrumentItem.SyncInstrumentDSInfo.ServerName = this.txtOracleSource.Text.Trim();
  194. syncInstrumentItem.SyncInstrumentDSInfo.UserId = this.txtOracleUserId.Text.Trim();
  195. syncInstrumentItem.SyncInstrumentDSInfo.UserPwd = this.txtOraclePwd.Text.Trim();
  196. syncInstrumentItem.SyncInstrumentDSInfo.Port = this.txtOraclePort.Text.Trim();
  197. break;
  198. case DataSourceType.FoxPro:
  199. syncInstrumentItem.SyncInstrumentDSInfo.Path = this.txtFoxProFolder.Text.Trim();
  200. syncInstrumentItem.SyncInstrumentDSInfo.Host = "";
  201. syncInstrumentItem.SyncInstrumentDSInfo.ServerName = "";
  202. syncInstrumentItem.SyncInstrumentDSInfo.UserId = this.txtFoxProUserId.Text.Trim();
  203. syncInstrumentItem.SyncInstrumentDSInfo.UserPwd = this.txtFoxProPwd.Text.Trim();
  204. syncInstrumentItem.SyncInstrumentDSInfo.DsPathType = this.cbxFoxProRemote.Checked ? PathType.Remote : PathType.Local;
  205. syncInstrumentItem.SyncInstrumentDSInfo.RemoteUser = this.txtRemoteFoxProUserId.Text.Trim();
  206. syncInstrumentItem.SyncInstrumentDSInfo.RemotePwd = this.txtRemoteFoxProPwd.Text.Trim();
  207. break;
  208. case DataSourceType.TXT:
  209. syncInstrumentItem.SyncInstrumentDSInfo.Path = this.txtInportTxt.Text.Trim();
  210. syncInstrumentItem.SyncInstrumentDSInfo.Host = "";
  211. syncInstrumentItem.SyncInstrumentDSInfo.ServerName = "";
  212. syncInstrumentItem.SyncInstrumentDSInfo.UserId = "";
  213. syncInstrumentItem.SyncInstrumentDSInfo.UserPwd = "";
  214. syncInstrumentItem.SyncInstrumentDSInfo.DsPathType = this.cbxRemoteTxt.Checked ? PathType.Remote : PathType.Local;
  215. syncInstrumentItem.SyncInstrumentDSInfo.RemoteUser = this.txtRemoteTxtUserId.Text.Trim();
  216. syncInstrumentItem.SyncInstrumentDSInfo.RemotePwd = this.txtRemoteTxtPwd.Text.Trim();
  217. break;
  218. case DataSourceType.Excel:
  219. case DataSourceType.PostgreSQL:
  220. default:
  221. syncInstrumentItem.SyncInstrumentDSInfo.Path = this.txtInportExcel.Text.Trim();
  222. syncInstrumentItem.SyncInstrumentDSInfo.Host = "";
  223. syncInstrumentItem.SyncInstrumentDSInfo.ServerName = "";
  224. syncInstrumentItem.SyncInstrumentDSInfo.UserId = "";
  225. syncInstrumentItem.SyncInstrumentDSInfo.UserPwd = "";
  226. syncInstrumentItem.SyncInstrumentDSInfo.DsPathType = this.cbxExcelRemote.Checked ? PathType.Remote : PathType.Local;
  227. syncInstrumentItem.SyncInstrumentDSInfo.RemoteUser = this.txtRemoteExcelUser.Text.Trim();
  228. syncInstrumentItem.SyncInstrumentDSInfo.RemotePwd = this.txtRemoteExcelPwd.Text.Trim();
  229. break;
  230. }
  231. object[] obj = new object[] { "", "", "" };
  232. //instrumentData = InstrumentDataFact.CreateInstrumentDataSource(syncInstrumentItem.SyncInstrumentDSInfo, obj);
  233. //dictInstrument = instrumentData.GetInstrumentData();
  234. //目标库的信息
  235. if (GlobalCommonOperation.strStartWebApi != "1")
  236. {
  237. syncInstrumentItem.SyncTargetDBInfo.DBHost = this.txtDBHost.Text.Trim();
  238. syncInstrumentItem.SyncTargetDBInfo.DBName = this.txtDBName.Text.Trim();
  239. syncInstrumentItem.SyncTargetDBInfo.DBUser = this.txtDBUser.Text.Trim();
  240. syncInstrumentItem.SyncTargetDBInfo.DBPwd = this.txtDBPwd.Text.Trim();
  241. syncInstrumentItem.SyncTargetDBInfo.DBPort = this.txtPort.Text.Trim();
  242. }
  243. else
  244. syncInstrumentItem.SyncTargetDBInfo = targetDataBaseInfo;
  245. this.InstrumentDelegate(syncInstrumentItem);
  246. //this.InstrumentItemData(dictInstrument);
  247. this.Close();
  248. }
  249. private void btnOpenFileExcel_Click(object sender, EventArgs e)
  250. {
  251. if (syncInstrumentItem.Code == null) return;
  252. if (syncInstrumentItem.SyncInstrumentDSInfo == null)
  253. syncInstrumentItem.SyncInstrumentDSInfo = new InstrumentDataSourceInfo();
  254. syncInstrumentItem.SyncInstrumentDSInfo.InstrumentDataSourceType = DataSourceType.Excel;
  255. if (strReadExcelMode == "0")
  256. {
  257. OpenFileDialog openFile = new OpenFileDialog
  258. {
  259. Filter = "Excel(*.xlsx)|*.xlsx|Excel(*.xls)|*.xls",
  260. InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
  261. Multiselect = false
  262. };
  263. if (openFile.ShowDialog() == DialogResult.Cancel) return;
  264. this.txtInportExcel.Text = syncInstrumentItem.SyncInstrumentDSInfo.Path = openFile.FileName;
  265. string fileType = System.IO.Path.GetExtension(openFile.FileName);
  266. if (string.IsNullOrEmpty(fileType)) return;
  267. }
  268. else
  269. {
  270. FolderBrowserDialog dialog = new FolderBrowserDialog();
  271. dialog.Description = "请选择文件路径";
  272. if (dialog.ShowDialog() == DialogResult.Cancel) return;
  273. this.txtInportExcel.Text = syncInstrumentItem.SyncInstrumentDSInfo.Path = dialog.SelectedPath;
  274. }
  275. }
  276. private void tabcDS_Selected(object sender, TabControlEventArgs e)
  277. {
  278. //切换的时候,检查其他类型数据源是否有值,如果有值,将提示删除旧值才能配置新值
  279. if (e.TabPage == tabExcel)
  280. {
  281. //检查tabAccess页面是否为空 //检查tabSQLite页面是否为空
  282. if (!CheckAccessControl() || !CheckSQLiteControl() || !CheckSQLServerControl() || !CheckMySqlControl() || !CheckOracleControl() || !CheckFoxproControl() || !CheckTxtControl())
  283. {
  284. if (MessageBox.Show("其他数据源存在已保存数据,继续将删除这些值,是否继续", "提示", MessageBoxButtons.OKCancel) == DialogResult.OK)
  285. {
  286. ClearAccessControl();
  287. ClearSqliteControl();
  288. ClearSQLServerControl();
  289. ClearMySQLControl();
  290. ClearOracleControl();
  291. ClearFoxproControl();
  292. ClearTxtControl();
  293. ClearObjectValue();
  294. }
  295. else
  296. {
  297. ChangeSelectTabPageByType();
  298. return;
  299. }
  300. }
  301. syncInstrumentItem.SyncInstrumentDSInfo.InstrumentDataSourceType = DataSourceType.Excel;
  302. }
  303. if (e.TabPage == tabAccess)
  304. {
  305. //检查tabAccess页面是否为空 //检查tabSQLite页面是否为空
  306. if (!CheckExcelControl() || !CheckSQLiteControl() || !CheckSQLServerControl() || !CheckMySqlControl() || !CheckOracleControl() || !CheckFoxproControl() || !CheckTxtControl())
  307. {
  308. if (MessageBox.Show("其他数据源存在已保存数据,继续将删除这些值,是否继续", "提示", MessageBoxButtons.OKCancel) == DialogResult.OK)
  309. {
  310. ClearExcelControl();
  311. ClearSqliteControl();
  312. ClearSQLServerControl();
  313. ClearMySQLControl();
  314. ClearOracleControl();
  315. ClearFoxproControl();
  316. ClearTxtControl();
  317. ClearObjectValue();
  318. }
  319. else
  320. {
  321. ChangeSelectTabPageByType();
  322. return;
  323. }
  324. }
  325. syncInstrumentItem.SyncInstrumentDSInfo.InstrumentDataSourceType = DataSourceType.Access;
  326. }
  327. if (e.TabPage == tabSQLite)
  328. {
  329. //检查tabAccess页面是否为空 //检查tabSQLite页面是否为空
  330. if (!CheckExcelControl() || !CheckAccessControl() || !CheckSQLServerControl() || !CheckMySqlControl() || !CheckOracleControl() || !CheckFoxproControl() || !CheckTxtControl())
  331. {
  332. if (MessageBox.Show("其他数据源存在已保存数据,继续将删除这些值,是否继续", "提示", MessageBoxButtons.OKCancel) == DialogResult.OK)
  333. {
  334. ClearAccessControl();
  335. ClearExcelControl();
  336. ClearSQLServerControl();
  337. ClearMySQLControl();
  338. ClearOracleControl();
  339. ClearFoxproControl();
  340. ClearTxtControl();
  341. ClearObjectValue();
  342. }
  343. else
  344. {
  345. ChangeSelectTabPageByType();
  346. return;
  347. }
  348. }
  349. syncInstrumentItem.SyncInstrumentDSInfo.InstrumentDataSourceType = DataSourceType.SQLLite;
  350. }
  351. if (e.TabPage == tabSQLServer)
  352. {
  353. //检查tabAccess页面是否为空 //检查tabSQLite页面是否为空
  354. if (!CheckExcelControl() || !CheckAccessControl() || !CheckSQLiteControl() || !CheckMySqlControl() || !CheckOracleControl() || !CheckFoxproControl() || !CheckTxtControl())
  355. {
  356. if (MessageBox.Show("其他数据源存在已保存数据,继续将删除这些值,是否继续", "提示", MessageBoxButtons.OKCancel) == DialogResult.OK)
  357. {
  358. ClearAccessControl();
  359. ClearExcelControl();
  360. ClearSqliteControl();
  361. ClearMySQLControl();
  362. ClearOracleControl();
  363. ClearFoxproControl();
  364. ClearTxtControl();
  365. ClearObjectValue();
  366. }
  367. else
  368. {
  369. ChangeSelectTabPageByType();
  370. return;
  371. }
  372. }
  373. syncInstrumentItem.SyncInstrumentDSInfo.InstrumentDataSourceType = DataSourceType.SQL;
  374. }
  375. if (e.TabPage == tabMySql)
  376. {
  377. //检查tabAccess页面是否为空 //检查tabSQLite页面是否为空
  378. if (!CheckExcelControl() || !CheckAccessControl() || !CheckSQLiteControl() || !CheckSQLServerControl() || !CheckOracleControl() || !CheckFoxproControl() || !CheckTxtControl())
  379. {
  380. if (MessageBox.Show("其他数据源存在已保存数据,继续将删除这些值,是否继续", "提示", MessageBoxButtons.OKCancel) == DialogResult.OK)
  381. {
  382. ClearAccessControl();
  383. ClearExcelControl();
  384. ClearSqliteControl();
  385. ClearSQLServerControl();
  386. ClearOracleControl();
  387. ClearFoxproControl();
  388. ClearTxtControl();
  389. ClearObjectValue();
  390. }
  391. else
  392. {
  393. ChangeSelectTabPageByType();
  394. return;
  395. }
  396. }
  397. syncInstrumentItem.SyncInstrumentDSInfo.InstrumentDataSourceType = DataSourceType.MySQL;
  398. }
  399. if (e.TabPage == tabOracle)
  400. {
  401. //检查tabAccess页面是否为空 //检查tabSQLite页面是否为空
  402. if (!CheckExcelControl() || !CheckAccessControl() || !CheckSQLiteControl() || !CheckSQLServerControl() || !CheckMySqlControl() || !CheckFoxproControl() || !CheckTxtControl())
  403. {
  404. if (MessageBox.Show("其他数据源存在已保存数据,继续将删除这些值,是否继续", "提示", MessageBoxButtons.OKCancel) == DialogResult.OK)
  405. {
  406. ClearAccessControl();
  407. ClearExcelControl();
  408. ClearSqliteControl();
  409. ClearSQLServerControl();
  410. ClearMySQLControl();
  411. ClearFoxproControl();
  412. ClearTxtControl();
  413. ClearObjectValue();
  414. }
  415. else
  416. {
  417. ChangeSelectTabPageByType();
  418. return;
  419. }
  420. }
  421. syncInstrumentItem.SyncInstrumentDSInfo.InstrumentDataSourceType = DataSourceType.Oracle;
  422. }
  423. if (e.TabPage == tabFoxPro)
  424. {
  425. if (!CheckExcelControl() || !CheckAccessControl() || !CheckSQLiteControl() || !CheckSQLServerControl() || !CheckMySqlControl() || !CheckOracleControl() || !CheckTxtControl())
  426. {
  427. if (MessageBox.Show("其他数据源存在已保存数据,继续将删除这些值,是否继续", "提示", MessageBoxButtons.OKCancel) == DialogResult.OK)
  428. {
  429. ClearAccessControl();
  430. ClearExcelControl();
  431. ClearSqliteControl();
  432. ClearSQLServerControl();
  433. ClearMySQLControl();
  434. ClearOracleControl();
  435. ClearTxtControl();
  436. ClearObjectValue();
  437. }
  438. else
  439. {
  440. ChangeSelectTabPageByType();
  441. return;
  442. }
  443. }
  444. syncInstrumentItem.SyncInstrumentDSInfo.InstrumentDataSourceType = DataSourceType.FoxPro;
  445. }
  446. if (e.TabPage == tabTxt)
  447. {
  448. if (!CheckExcelControl() || !CheckAccessControl() || !CheckSQLiteControl() || !CheckSQLServerControl() || !CheckMySqlControl() || !CheckOracleControl() || !CheckFoxproControl())
  449. {
  450. if (MessageBox.Show("其他数据源存在已保存数据,继续将删除这些值,是否继续", "提示", MessageBoxButtons.OKCancel) == DialogResult.OK)
  451. {
  452. ClearAccessControl();
  453. ClearExcelControl();
  454. ClearSqliteControl();
  455. ClearSQLServerControl();
  456. ClearMySQLControl();
  457. ClearOracleControl();
  458. ClearFoxproControl();
  459. ClearObjectValue();
  460. }
  461. else
  462. {
  463. ChangeSelectTabPageByType();
  464. return;
  465. }
  466. }
  467. syncInstrumentItem.SyncInstrumentDSInfo.InstrumentDataSourceType = DataSourceType.TXT;
  468. }
  469. if (e.TabPage == tabPostgreSql)
  470. {
  471. if (!CheckExcelControl() || !CheckAccessControl() || !CheckSQLiteControl() ||
  472. !CheckSQLServerControl() || !CheckMySqlControl() || !CheckOracleControl() ||
  473. !CheckFoxproControl() || !CheckTxtControl())
  474. {
  475. if (MessageBox.Show("其他数据源存在已保存数据,继续将删除这些值,是否继续", "提示",
  476. MessageBoxButtons.OKCancel) == DialogResult.OK)
  477. {
  478. ClearAccessControl();
  479. ClearExcelControl();
  480. ClearSqliteControl();
  481. ClearSQLServerControl();
  482. ClearMySQLControl();
  483. ClearOracleControl();
  484. ClearFoxproControl();
  485. ClearTxtControl();
  486. ClearObjectValue();
  487. }
  488. else
  489. {
  490. ChangeSelectTabPageByType();
  491. return;
  492. }
  493. }
  494. syncInstrumentItem.SyncInstrumentDSInfo.InstrumentDataSourceType = DataSourceType.PostgreSQL;
  495. }
  496. }
  497. //根据数据源类型切换Tab页
  498. private void ChangeSelectTabPageByType()
  499. {
  500. switch (syncInstrumentItem.SyncInstrumentDSInfo.InstrumentDataSourceType)
  501. {
  502. case DataSourceType.SQLLite:
  503. tabcDS.SelectedTab = tabSQLite;
  504. break;
  505. case DataSourceType.Access:
  506. tabcDS.SelectedTab = tabAccess;
  507. break;
  508. case DataSourceType.SQL:
  509. tabcDS.SelectedTab = tabSQLServer;
  510. break;
  511. case DataSourceType.Oracle:
  512. tabcDS.SelectedTab = tabOracle;
  513. break;
  514. case DataSourceType.FoxPro:
  515. tabcDS.SelectedTab = tabFoxPro;
  516. break;
  517. case DataSourceType.TXT:
  518. tabcDS.SelectedTab = tabTxt;
  519. break;
  520. case DataSourceType.Excel:
  521. case DataSourceType.PostgreSQL:
  522. default:
  523. tabcDS.SelectedTab = tabExcel;
  524. break;
  525. }
  526. }
  527. private bool CheckExcelControl()
  528. {
  529. if (this.txtInportExcel.Text != "")
  530. return false;
  531. else
  532. return true;
  533. }
  534. private bool CheckAccessControl()
  535. {
  536. if (this.txtAccessPath.Text != "" || this.txtAccessUser.Text != "" || this.txtAceessPwd.Text != "")
  537. return false;
  538. else
  539. return true;
  540. }
  541. private bool CheckSQLiteControl()
  542. {
  543. if (this.txtSqlitePath.Text != "" || this.txtSqliteUser.Text != "" || this.txtSqlitePwd.Text != "")
  544. return false;
  545. else
  546. return true;
  547. }
  548. private bool CheckSQLServerControl()
  549. {
  550. if (this.txtSqlServerHost.Text.Trim() != "" || this.txtSqlServerName.Text.Trim() != "" || this.txtSqlServerPwd.Text.Trim() != "" || this.txtSqlServerUser.Text.Trim() != "")
  551. return false;
  552. else
  553. return true;
  554. }
  555. private bool CheckMySqlControl()
  556. {
  557. if (this.txtMySqlHost.Text.Trim() != "" || this.txtMySqlServer.Text.Trim() != "" || this.txtMySqlUser.Text.Trim() != "" || this.txtMySqlPwd.Text.Trim() != "" || this.txtMySqlPort.Text.Trim() != "")
  558. return false;
  559. else
  560. return true;
  561. }
  562. private bool CheckOracleControl()
  563. {
  564. if (this.txtOraclePort.Text.Trim() != "" || this.txtOraclePwd.Text.Trim() != "" || this.txtOracleHost.Text.Trim() != "" || this.txtOracleSource.Text.Trim() != "" || this.txtOracleUserId.Text.Trim() != "")
  565. return false;
  566. else
  567. return true;
  568. }
  569. private bool CheckFoxproControl()
  570. {
  571. if (this.txtFoxProFolder.Text.Trim() != "" || this.txtFoxProUserId.Text.Trim() != "" || this.txtFoxProPwd.Text.Trim() != "" || this.txtRemoteFoxProUserId.Text.Trim() != "" || this.txtRemoteFoxProPwd.Text.Trim() != "")
  572. {
  573. return false;
  574. }
  575. else
  576. return true;
  577. }
  578. private bool CheckTxtControl()
  579. {
  580. if (this.txtInportTxt.Text.Trim() != "" || this.txtRemoteTxtUserId.Text.Trim() != "" || this.txtRemoteTxtPwd.Text.Trim() != "")
  581. return false;
  582. else
  583. return true;
  584. }
  585. private void btnCNASTestLink_Click(object sender, EventArgs e)
  586. {
  587. //this.txtDBHost.Text.Trim(), this.txtDBName.Text.Trim(), this.txtDBUser.Text.Trim(), this.txtDBPwd.Text.Trim(),this.txtPort.Text.Trim()
  588. if (CnasDataOperationFact.CnasDataOperation().TestConnect(new DataBaseInfo()
  589. {
  590. DBHost = this.txtDBHost.Text.Trim(),
  591. DBName = this.txtDBName.Text.Trim(),
  592. DBUser = this.txtDBUser.Text.Trim(),
  593. DBPwd = this.txtDBPwd.Text.Trim(),
  594. DBPort = this.txtPort.Text.Trim()
  595. }))
  596. MessageBox.Show("连接成功!");
  597. else
  598. MessageBox.Show("连接失败!");
  599. }
  600. private void ClearExcelControl()
  601. {
  602. this.txtInportExcel.Text = "";
  603. this.txtRemoteExcelUser.Text = "";
  604. this.txtRemoteExcelPwd.Text = "";
  605. }
  606. private void ClearAccessControl()
  607. {
  608. this.txtAccessPath.Text = "";
  609. this.txtAccessUser.Text = "";
  610. this.txtAceessPwd.Text = "";
  611. this.txtAccessRemoteUser.Text = "";
  612. this.txtAccessRemotePwd.Text = "";
  613. }
  614. private void ClearSqliteControl()
  615. {
  616. this.txtSqliteUser.Text = "";
  617. this.txtSqlitePath.Text = "";
  618. this.txtSqlitePwd.Text = "";
  619. this.txtSqliteRemoteUser.Text = "";
  620. this.txtSqliteRemotePwd.Text = "";
  621. }
  622. private void ClearSQLServerControl()
  623. {
  624. this.txtSqlServerHost.Text = "";
  625. this.txtSqlServerName.Text = "";
  626. this.txtSqlServerUser.Text = "";
  627. this.txtSqlServerPwd.Text = "";
  628. }
  629. private void ClearMySQLControl()
  630. {
  631. this.txtMySqlHost.Text = "";
  632. this.txtMySqlServer.Text = "";
  633. this.txtMySqlUser.Text = "";
  634. this.txtMySqlPwd.Text = "";
  635. this.txtMySqlPort.Text = "";
  636. }
  637. private void ClearOracleControl()
  638. {
  639. this.txtOracleHost.Text = "";
  640. this.txtOracleSource.Text = "";
  641. this.txtOracleUserId.Text = "";
  642. this.txtOraclePwd.Text = "";
  643. this.txtOraclePort.Text = "";
  644. }
  645. private void ClearFoxproControl()
  646. {
  647. this.txtFoxProFolder.Text = "";
  648. this.txtFoxProUserId.Text = "";
  649. this.txtFoxProPwd.Text = "";
  650. this.txtRemoteFoxProUserId.Text = "";
  651. this.txtRemoteFoxProPwd.Text = "";
  652. }
  653. private void ClearTxtControl()
  654. {
  655. this.txtInportTxt.Text = "";
  656. this.txtRemoteTxtUserId.Text = "";
  657. this.txtRemoteTxtPwd.Text = "";
  658. }
  659. /// <summary>
  660. /// 清空对象中存储的值
  661. /// </summary>
  662. private void ClearObjectValue()
  663. {
  664. syncInstrumentItem.SyncInstrumentDSInfo.Host = "";
  665. syncInstrumentItem.SyncInstrumentDSInfo.ServerName = "";
  666. syncInstrumentItem.SyncInstrumentDSInfo.Path = "";
  667. syncInstrumentItem.SyncInstrumentDSInfo.UserId = "";
  668. syncInstrumentItem.SyncInstrumentDSInfo.UserPwd = "";
  669. syncInstrumentItem.SyncInstrumentDSInfo.Port = "";
  670. syncInstrumentItem.SyncInstrumentDSInfo.DsPathType = PathType.Local;
  671. syncInstrumentItem.SyncInstrumentDSInfo.RemoteUser = "";
  672. syncInstrumentItem.SyncInstrumentDSInfo.RemotePwd = "";
  673. }
  674. private void btnOpenFileAccess_Click(object sender, EventArgs e)
  675. {
  676. if (syncInstrumentItem.Code == null) return;
  677. if (syncInstrumentItem.SyncInstrumentDSInfo == null)
  678. syncInstrumentItem.SyncInstrumentDSInfo = new InstrumentDataSourceInfo();
  679. syncInstrumentItem.SyncInstrumentDSInfo.InstrumentDataSourceType = DataSourceType.Access;
  680. if (strReadAccessMode == "0")
  681. {
  682. OpenFileDialog openFile = new OpenFileDialog
  683. {
  684. Filter = "Microsoft Access(*.mdb)|*.mdb|Microsoft Access(*.accdb)|*.accdb",
  685. InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
  686. Multiselect = false
  687. };
  688. if (openFile.ShowDialog() == DialogResult.Cancel) return;
  689. this.txtAccessPath.Text = syncInstrumentItem.SyncInstrumentDSInfo.Path = openFile.FileName;
  690. string fileType = System.IO.Path.GetExtension(openFile.FileName);
  691. if (string.IsNullOrEmpty(fileType)) return;
  692. }
  693. else
  694. {
  695. FolderBrowserDialog dialog = new FolderBrowserDialog();
  696. dialog.Description = "请选择文件路径";
  697. if (dialog.ShowDialog() == DialogResult.Cancel) return;
  698. this.txtAccessPath.Text = syncInstrumentItem.SyncInstrumentDSInfo.Path = dialog.SelectedPath;
  699. }
  700. }
  701. private void btnOpenFileSQLite_Click(object sender, EventArgs e)
  702. {
  703. if (syncInstrumentItem.Code == null) return;
  704. if (syncInstrumentItem.SyncInstrumentDSInfo == null)
  705. syncInstrumentItem.SyncInstrumentDSInfo = new InstrumentDataSourceInfo();
  706. syncInstrumentItem.SyncInstrumentDSInfo.InstrumentDataSourceType = DataSourceType.SQLLite;
  707. if (strReadSqliteMode == "0")
  708. {
  709. OpenFileDialog openFile = new OpenFileDialog
  710. {
  711. Filter = "SQLite(*.db)|*.db",
  712. InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
  713. Multiselect = false
  714. };
  715. if (openFile.ShowDialog() == DialogResult.Cancel) return;
  716. this.txtSqlitePath.Text = syncInstrumentItem.SyncInstrumentDSInfo.Path = openFile.FileName;
  717. string fileType = System.IO.Path.GetExtension(openFile.FileName);
  718. if (string.IsNullOrEmpty(fileType)) return;
  719. }
  720. else
  721. {
  722. FolderBrowserDialog dialog = new FolderBrowserDialog();
  723. dialog.Description = "请选择文件路径";
  724. if (dialog.ShowDialog() == DialogResult.Cancel) return;
  725. this.txtSqlitePath.Text = syncInstrumentItem.SyncInstrumentDSInfo.Path = dialog.SelectedPath;
  726. }
  727. }
  728. private void btnTestSQLLink_Click(object sender, EventArgs e)
  729. {
  730. if (this.txtSqlServerHost.Text.Trim() == "" || this.txtSqlServerName.Text.Trim() == "" || this.txtSqlServerUser.Text.Trim() == "")
  731. {
  732. MessageBox.Show("请填写相关连接信息。");
  733. return;
  734. }
  735. InstrumentDataSourceInfo dbinfo = new InstrumentDataSourceInfo();
  736. dbinfo.Host = this.txtSqlServerHost.Text.Trim();
  737. dbinfo.ServerName = this.txtSqlServerName.Text.Trim();
  738. dbinfo.UserId = this.txtSqlServerUser.Text.Trim();
  739. dbinfo.UserPwd = this.txtSqlServerPwd.Text.Trim();
  740. dbinfo.Port = this.txtSqlServerPort.Text.Trim();
  741. if (new SQLServerInstrumentData(dbinfo, new object[] {
  742. "",
  743. "",
  744. ""
  745. }).TestSQLServerLink())
  746. MessageBox.Show("连接成功!");
  747. else
  748. MessageBox.Show("连接失败!");
  749. }
  750. private void cbxExcelRemote_CheckedChanged(object sender, EventArgs e)
  751. {
  752. if (!cbxExcelRemote.Checked)
  753. {
  754. this.btnOpenFileExcel.Visible = true;
  755. lblExcelRemotePwd.Visible = false;
  756. lblExcelRemoteUser.Visible = false;
  757. txtRemoteExcelUser.Visible = false;
  758. txtRemoteExcelPwd.Visible = false;
  759. }
  760. else
  761. {
  762. this.btnOpenFileExcel.Visible = false;
  763. lblExcelRemotePwd.Visible = true;
  764. lblExcelRemoteUser.Visible = true;
  765. txtRemoteExcelUser.Visible = true;
  766. txtRemoteExcelPwd.Visible = true;
  767. }
  768. }
  769. private void cbxAccessRemote_CheckedChanged(object sender, EventArgs e)
  770. {
  771. if (cbxAccessRemote.Checked)
  772. {
  773. btnOpenFileAccess.Visible = false;
  774. lblAccessRemoteUser.Visible = true;
  775. lblAccessRemotePwd.Visible = true;
  776. txtAccessRemoteUser.Visible = true;
  777. txtAccessRemotePwd.Visible = true;
  778. }
  779. else
  780. {
  781. btnOpenFileAccess.Visible = true;
  782. lblAccessRemoteUser.Visible = false;
  783. lblAccessRemotePwd.Visible = false;
  784. txtAccessRemoteUser.Visible = false;
  785. txtAccessRemotePwd.Visible = false;
  786. }
  787. }
  788. private void cbxSqliteRemote_CheckedChanged(object sender, EventArgs e)
  789. {
  790. if (cbxSqliteRemote.Checked)
  791. {
  792. btnOpenFileSQLite.Visible = false;
  793. lblSqliteRemoteUser.Visible = true;
  794. lblSqliteRemotePwd.Visible = true;
  795. txtSqliteRemoteUser.Visible = true;
  796. txtSqliteRemotePwd.Visible = true;
  797. }
  798. else
  799. {
  800. btnOpenFileSQLite.Visible = true;
  801. lblSqliteRemoteUser.Visible = false;
  802. lblSqliteRemotePwd.Visible = false;
  803. txtSqliteRemoteUser.Visible = false;
  804. txtSqliteRemotePwd.Visible = false;
  805. }
  806. }
  807. private void btnMySqlTest_Click(object sender, EventArgs e)
  808. {
  809. if (CnasDataOperationFact.CnasDataOperation().TestConnect(new DataBaseInfo()
  810. {
  811. DBHost = this.txtMySqlHost.Text.Trim(),
  812. DBName = this.txtMySqlServer.Text.Trim(),
  813. DBUser = this.txtMySqlUser.Text.Trim(),
  814. DBPwd = this.txtMySqlPwd.Text.Trim(),
  815. DBPort = this.txtMySqlPort.Text.Trim()
  816. }))
  817. MessageBox.Show("连接成功!");
  818. else
  819. MessageBox.Show("连接失败!");
  820. }
  821. private void btnOracleTestLink_Click(object sender, EventArgs e)
  822. {
  823. if (this.txtOracleHost.Text.Trim() == "" || this.txtOracleSource.Text.Trim() == "" || this.txtOracleUserId.Text.Trim() == "" || this.txtOraclePort.Text.Trim() == "")
  824. {
  825. MessageBox.Show("请填写相关连接信息。");
  826. return;
  827. }
  828. InstrumentDataSourceInfo dbinfo = new InstrumentDataSourceInfo();
  829. dbinfo.Host = this.txtOracleHost.Text.Trim();
  830. dbinfo.ServerName = this.txtOracleSource.Text.Trim();
  831. dbinfo.UserId = this.txtOracleUserId.Text.Trim();
  832. dbinfo.UserPwd = this.txtOraclePwd.Text.Trim();
  833. dbinfo.Port = this.txtOraclePort.Text.Trim();
  834. if (new OracleInstrumentData(dbinfo, new object[] {
  835. "",
  836. "",
  837. ""
  838. }).TestSQLServerLink())
  839. MessageBox.Show("连接成功!");
  840. else
  841. MessageBox.Show("连接失败!");
  842. }
  843. private void txtFileOpenFoxPro_Click(object sender, EventArgs e)
  844. {
  845. if (syncInstrumentItem.Code == null) return;
  846. if (syncInstrumentItem.SyncInstrumentDSInfo == null)
  847. syncInstrumentItem.SyncInstrumentDSInfo = new InstrumentDataSourceInfo();
  848. syncInstrumentItem.SyncInstrumentDSInfo.InstrumentDataSourceType = DataSourceType.FoxPro;
  849. if (strReadFoxproMode == "0")
  850. {
  851. OpenFileDialog openFile = new OpenFileDialog
  852. {
  853. Filter = "Foxpro文件(*.dbf)|*.dbf",
  854. InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
  855. Multiselect = false
  856. };
  857. if (openFile.ShowDialog() == DialogResult.Cancel) return;
  858. this.txtFoxProFolder.Text = syncInstrumentItem.SyncInstrumentDSInfo.Path = openFile.FileName;
  859. string fileType = System.IO.Path.GetExtension(openFile.FileName);
  860. if (string.IsNullOrEmpty(fileType)) return;
  861. }
  862. else
  863. {
  864. FolderBrowserDialog dialog = new FolderBrowserDialog();
  865. dialog.Description = "请选择文件路径";
  866. if (dialog.ShowDialog() == DialogResult.Cancel) return;
  867. this.txtFoxProFolder.Text = syncInstrumentItem.SyncInstrumentDSInfo.Path = dialog.SelectedPath;
  868. }
  869. }
  870. private void cbxFoxProRemote_CheckedChanged(object sender, EventArgs e)
  871. {
  872. if (!cbxFoxProRemote.Checked)
  873. {
  874. this.btnFileOpenFoxPro.Visible = true;
  875. lblFoxproRemoteUserId.Visible = false;
  876. lblFoxproRemotePwd.Visible = false;
  877. txtRemoteFoxProUserId.Visible = false;
  878. txtRemoteFoxProPwd.Visible = false;
  879. }
  880. else
  881. {
  882. this.btnFileOpenFoxPro.Visible = false;
  883. lblFoxproRemoteUserId.Visible = true;
  884. lblFoxproRemotePwd.Visible = true;
  885. txtRemoteFoxProUserId.Visible = true;
  886. txtRemoteFoxProPwd.Visible = true;
  887. }
  888. }
  889. private void btnOpenFileTxt_Click(object sender, EventArgs e)
  890. {
  891. if (syncInstrumentItem.Code == null) return;
  892. if (syncInstrumentItem.SyncInstrumentDSInfo == null)
  893. syncInstrumentItem.SyncInstrumentDSInfo = new InstrumentDataSourceInfo();
  894. syncInstrumentItem.SyncInstrumentDSInfo.InstrumentDataSourceType = DataSourceType.TXT;
  895. if (strReadTxtMode == "0")
  896. {
  897. OpenFileDialog openFile = new OpenFileDialog
  898. {
  899. Filter = "文本文件(*.txt)|*.txt|所有文件(*.*)|*.*",
  900. InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
  901. Multiselect = false
  902. };
  903. if (openFile.ShowDialog() == DialogResult.Cancel) return;
  904. this.txtInportTxt.Text = syncInstrumentItem.SyncInstrumentDSInfo.Path = openFile.FileName;
  905. string fileType = System.IO.Path.GetExtension(openFile.FileName);
  906. if (string.IsNullOrEmpty(fileType)) return;
  907. }
  908. else
  909. {
  910. FolderBrowserDialog dialog = new FolderBrowserDialog();
  911. dialog.Description = "请选择文件路径";
  912. if (dialog.ShowDialog() == DialogResult.Cancel) return;
  913. this.txtInportTxt.Text = syncInstrumentItem.SyncInstrumentDSInfo.Path = dialog.SelectedPath;
  914. }
  915. }
  916. private void cbxRemoteTxt_CheckedChanged(object sender, EventArgs e)
  917. {
  918. if (!cbxRemoteTxt.Checked)
  919. {
  920. this.btnOpenFileTxt.Visible = true;
  921. lblTxtRemoteUserId.Visible = false;
  922. lblTxtRemoteUserPwd.Visible = false;
  923. txtRemoteTxtUserId.Visible = false;
  924. txtRemoteTxtPwd.Visible = false;
  925. }
  926. else
  927. {
  928. this.btnOpenFileTxt.Visible = false;
  929. lblTxtRemoteUserId.Visible = true;
  930. lblTxtRemoteUserPwd.Visible = true;
  931. txtRemoteTxtUserId.Visible = true;
  932. txtRemoteTxtPwd.Visible = true;
  933. }
  934. }
  935. private void cbxTargetDBSelect_SelectedIndexChanged(object sender, EventArgs e)
  936. {
  937. if (cbxTargetDBSelect.SelectedIndex == 0)
  938. {
  939. if (GlobalCommonOperation.strStartWebApi == "1")
  940. {
  941. targetDataBaseInfo = new DataBaseInfo()
  942. {
  943. DataBaseCode = "cnas"
  944. };
  945. }
  946. else
  947. {
  948. DataBaseInfo CNASDataBase = FileOperation.GetLocalCnasDB();
  949. if (CNASDataBase != null)
  950. {
  951. this.txtDBHost.Text = CNASDataBase.DBHost;
  952. this.txtDBName.Text = CNASDataBase.DBName;
  953. this.txtDBUser.Text = CNASDataBase.DBUser;
  954. this.txtDBPwd.Text = CNASDataBase.DBPwd;
  955. this.txtPort.Text = CNASDataBase.DBPort;
  956. }
  957. }
  958. }
  959. else if (cbxTargetDBSelect.SelectedIndex == 1)
  960. {
  961. if (GlobalCommonOperation.strStartWebApi == "1")
  962. {
  963. targetDataBaseInfo = new DataBaseInfo()
  964. {
  965. DataBaseCode = "platform"
  966. };
  967. }
  968. else
  969. {
  970. DataBaseInfo PlatDataBase = FileOperation.GetLocalPlatFormDB();
  971. if (PlatDataBase != null)
  972. {
  973. this.txtDBHost.Text = PlatDataBase.DBHost;
  974. this.txtDBName.Text = PlatDataBase.DBName;
  975. this.txtDBUser.Text = PlatDataBase.DBUser;
  976. this.txtDBPwd.Text = PlatDataBase.DBPwd;
  977. this.txtPort.Text = PlatDataBase.DBPort;
  978. }
  979. }
  980. }
  981. }
  982. private void btnPostgreSqlConn_Click(object sender, EventArgs e)
  983. {
  984. if (CnasDataOperationFact.CnasDataOperation().TestConnect(new DataBaseInfo()
  985. {
  986. DBHost = this.txtPostgreSqlHost.Text.Trim(),
  987. DBName = this.txtPostgreSqlServer.Text.Trim(),
  988. DBUser = this.txtPostgreSqlUser.Text.Trim(),
  989. DBPwd = this.txtPostgreSqlPwd.Text.Trim(),
  990. DBPort = this.txtPostgreSqlPort.Text.Trim()
  991. }))
  992. MessageBox.Show("连接成功!");
  993. else
  994. MessageBox.Show("连接失败!");
  995. //if (this.txtPostgreSqlHost.Text.Trim() == "" || this.txtPostgreSqlServer.Text.Trim() == "" ||
  996. // this.txtPostgreSqlUser.Text.Trim() == "" || this.txtPostgreSqlPort.Text.Trim() == "")
  997. //{
  998. // MessageBox.Show("请填写相关连接信息。");
  999. // return;
  1000. //}
  1001. //InstrumentDataSourceInfo dbinfo = new InstrumentDataSourceInfo();
  1002. //dbinfo.Host = this.txtPostgreSqlHost.Text.Trim();
  1003. //dbinfo.ServerName = this.txtPostgreSqlServer.Text.Trim();
  1004. //dbinfo.UserId = this.txtPostgreSqlUser.Text.Trim();
  1005. //dbinfo.UserPwd = this.txtPostgreSqlPwd.Text.Trim();
  1006. //dbinfo.Port = this.txtPostgreSqlPort.Text.Trim();
  1007. //if (new PostgreSqlInstrumentData(dbinfo, new object[] { "", "", "" }).TestConnection())
  1008. // MessageBox.Show("连接成功!");
  1009. //else
  1010. // MessageBox.Show("连接失败!");
  1011. }
  1012. private bool CheckPostgreSqlControl()
  1013. {
  1014. if (this.txtPostgreSqlHost.Text.Trim() != "" || this.txtPostgreSqlServer.Text.Trim() != "" ||
  1015. this.txtPostgreSqlUser.Text.Trim() != "" || this.txtPostgreSqlPwd.Text.Trim() != "" ||
  1016. this.txtPostgreSqlPort.Text.Trim() != "")
  1017. return false;
  1018. else
  1019. return true;
  1020. }
  1021. private void ClearPostgreSqlControl()
  1022. {
  1023. this.txtPostgreSqlHost.Text = "";
  1024. this.txtPostgreSqlServer.Text = "";
  1025. this.txtPostgreSqlUser.Text = "";
  1026. this.txtPostgreSqlPwd.Text = "";
  1027. this.txtPostgreSqlPort.Text = "";
  1028. }
  1029. }
  1030. }