CNAS取数仪器端升级
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

1345 Zeilen
61KB

  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. case DataSourceType.Kingbase:
  137. this.tabcDS.SelectedIndex = 9;
  138. this.txtKingbaselHost.Text = syncInstrumentItem.SyncInstrumentDSInfo.Host;
  139. this.txtKingbaselServer.Text = syncInstrumentItem.SyncInstrumentDSInfo.ServerName;
  140. this.txtKingbaselUser.Text = syncInstrumentItem.SyncInstrumentDSInfo.UserId;
  141. this.txtKingbaselPwd.Text = syncInstrumentItem.SyncInstrumentDSInfo.UserPwd;
  142. this.txtKingbaselPort.Text = syncInstrumentItem.SyncInstrumentDSInfo.Port;
  143. break;
  144. default:
  145. break;
  146. }
  147. //加载旧的CNAS数据库信息
  148. if (syncInstrumentItem.SyncTargetDBInfo != null)
  149. {
  150. targetDataBaseInfo = syncInstrumentItem.SyncTargetDBInfo;
  151. }
  152. else
  153. syncInstrumentItem.SyncTargetDBInfo = new DataBaseInfo();
  154. this.txtDBHost.Text = targetDataBaseInfo.DBHost;
  155. this.txtDBName.Text = targetDataBaseInfo.DBName;
  156. this.txtDBUser.Text = targetDataBaseInfo.DBUser;
  157. this.txtDBPwd.Text = targetDataBaseInfo.DBPwd;
  158. this.txtPort.Text = targetDataBaseInfo.DBPort;
  159. }
  160. private void btnOK_Click(object sender, EventArgs e)
  161. {
  162. //点击确定按钮
  163. //InstrumentData instrumentData = null;
  164. switch (syncInstrumentItem.SyncInstrumentDSInfo.InstrumentDataSourceType)
  165. {
  166. case DataSourceType.Access:
  167. syncInstrumentItem.SyncInstrumentDSInfo.Path = this.txtAccessPath.Text.Trim();
  168. syncInstrumentItem.SyncInstrumentDSInfo.Host = "";
  169. syncInstrumentItem.SyncInstrumentDSInfo.ServerName = "";
  170. syncInstrumentItem.SyncInstrumentDSInfo.UserId = this.txtAccessUser.Text.Trim();
  171. syncInstrumentItem.SyncInstrumentDSInfo.UserPwd = this.txtAceessPwd.Text.Trim();
  172. syncInstrumentItem.SyncInstrumentDSInfo.DsPathType = this.cbxAccessRemote.Checked ? PathType.Remote : PathType.Local;
  173. syncInstrumentItem.SyncInstrumentDSInfo.RemoteUser = this.txtAccessRemoteUser.Text.Trim();
  174. syncInstrumentItem.SyncInstrumentDSInfo.RemotePwd = this.txtAccessRemotePwd.Text.Trim();
  175. break;
  176. case DataSourceType.SQLLite:
  177. syncInstrumentItem.SyncInstrumentDSInfo.Path = this.txtSqlitePath.Text.Trim();
  178. syncInstrumentItem.SyncInstrumentDSInfo.Host = "";
  179. syncInstrumentItem.SyncInstrumentDSInfo.ServerName = "";
  180. syncInstrumentItem.SyncInstrumentDSInfo.UserId = this.txtSqliteUser.Text.Trim();
  181. syncInstrumentItem.SyncInstrumentDSInfo.UserPwd = this.txtSqlitePwd.Text.Trim();
  182. syncInstrumentItem.SyncInstrumentDSInfo.DsPathType = this.cbxSqliteRemote.Checked ? PathType.Remote : PathType.Local;
  183. syncInstrumentItem.SyncInstrumentDSInfo.RemoteUser = this.txtSqliteRemoteUser.Text.Trim();
  184. syncInstrumentItem.SyncInstrumentDSInfo.RemotePwd = this.txtSqliteRemotePwd.Text.Trim();
  185. break;
  186. case DataSourceType.SQL:
  187. syncInstrumentItem.SyncInstrumentDSInfo.Host = this.txtSqlServerHost.Text.Trim();
  188. syncInstrumentItem.SyncInstrumentDSInfo.ServerName = this.txtSqlServerName.Text.Trim();
  189. syncInstrumentItem.SyncInstrumentDSInfo.UserId = this.txtSqlServerUser.Text.Trim();
  190. syncInstrumentItem.SyncInstrumentDSInfo.UserPwd = this.txtSqlServerPwd.Text.Trim();
  191. break;
  192. case DataSourceType.MySQL:
  193. syncInstrumentItem.SyncInstrumentDSInfo.Host = this.txtMySqlHost.Text.Trim();
  194. syncInstrumentItem.SyncInstrumentDSInfo.ServerName = this.txtMySqlServer.Text.Trim();
  195. syncInstrumentItem.SyncInstrumentDSInfo.UserId = this.txtMySqlUser.Text.Trim();
  196. syncInstrumentItem.SyncInstrumentDSInfo.UserPwd = this.txtMySqlPwd.Text.Trim();
  197. syncInstrumentItem.SyncInstrumentDSInfo.Port = this.txtMySqlPort.Text.Trim();
  198. break;
  199. case DataSourceType.Oracle:
  200. syncInstrumentItem.SyncInstrumentDSInfo.Host = this.txtOracleHost.Text.Trim();
  201. syncInstrumentItem.SyncInstrumentDSInfo.ServerName = this.txtOracleSource.Text.Trim();
  202. syncInstrumentItem.SyncInstrumentDSInfo.UserId = this.txtOracleUserId.Text.Trim();
  203. syncInstrumentItem.SyncInstrumentDSInfo.UserPwd = this.txtOraclePwd.Text.Trim();
  204. syncInstrumentItem.SyncInstrumentDSInfo.Port = this.txtOraclePort.Text.Trim();
  205. break;
  206. case DataSourceType.FoxPro:
  207. syncInstrumentItem.SyncInstrumentDSInfo.Path = this.txtFoxProFolder.Text.Trim();
  208. syncInstrumentItem.SyncInstrumentDSInfo.Host = "";
  209. syncInstrumentItem.SyncInstrumentDSInfo.ServerName = "";
  210. syncInstrumentItem.SyncInstrumentDSInfo.UserId = this.txtFoxProUserId.Text.Trim();
  211. syncInstrumentItem.SyncInstrumentDSInfo.UserPwd = this.txtFoxProPwd.Text.Trim();
  212. syncInstrumentItem.SyncInstrumentDSInfo.DsPathType = this.cbxFoxProRemote.Checked ? PathType.Remote : PathType.Local;
  213. syncInstrumentItem.SyncInstrumentDSInfo.RemoteUser = this.txtRemoteFoxProUserId.Text.Trim();
  214. syncInstrumentItem.SyncInstrumentDSInfo.RemotePwd = this.txtRemoteFoxProPwd.Text.Trim();
  215. break;
  216. case DataSourceType.TXT:
  217. syncInstrumentItem.SyncInstrumentDSInfo.Path = this.txtInportTxt.Text.Trim();
  218. syncInstrumentItem.SyncInstrumentDSInfo.Host = "";
  219. syncInstrumentItem.SyncInstrumentDSInfo.ServerName = "";
  220. syncInstrumentItem.SyncInstrumentDSInfo.UserId = "";
  221. syncInstrumentItem.SyncInstrumentDSInfo.UserPwd = "";
  222. syncInstrumentItem.SyncInstrumentDSInfo.DsPathType = this.cbxRemoteTxt.Checked ? PathType.Remote : PathType.Local;
  223. syncInstrumentItem.SyncInstrumentDSInfo.RemoteUser = this.txtRemoteTxtUserId.Text.Trim();
  224. syncInstrumentItem.SyncInstrumentDSInfo.RemotePwd = this.txtRemoteTxtPwd.Text.Trim();
  225. break;
  226. case DataSourceType.Excel:
  227. case DataSourceType.PostgreSQL:
  228. syncInstrumentItem.SyncInstrumentDSInfo.Host = this.txtPostgreSqlHost.Text.Trim();
  229. syncInstrumentItem.SyncInstrumentDSInfo.ServerName = this.txtPostgreSqlServer.Text.Trim();
  230. syncInstrumentItem.SyncInstrumentDSInfo.UserId = this.txtPostgreSqlUser.Text.Trim();
  231. syncInstrumentItem.SyncInstrumentDSInfo.UserPwd = this.txtPostgreSqlPwd.Text.Trim();
  232. syncInstrumentItem.SyncInstrumentDSInfo.Port = this.txtPostgreSqlPort.Text.Trim();
  233. break;
  234. case DataSourceType.Kingbase:
  235. syncInstrumentItem.SyncInstrumentDSInfo.Host = this.txtKingbaselHost.Text.Trim();
  236. syncInstrumentItem.SyncInstrumentDSInfo.ServerName = this.txtKingbaselServer.Text.Trim();
  237. syncInstrumentItem.SyncInstrumentDSInfo.UserId = this.txtKingbaselUser.Text.Trim();
  238. syncInstrumentItem.SyncInstrumentDSInfo.UserPwd = this.txtKingbaselPwd.Text.Trim();
  239. syncInstrumentItem.SyncInstrumentDSInfo.Port = this.txtKingbaselPort.Text.Trim();
  240. break;
  241. default:
  242. syncInstrumentItem.SyncInstrumentDSInfo.Path = this.txtInportExcel.Text.Trim();
  243. syncInstrumentItem.SyncInstrumentDSInfo.Host = "";
  244. syncInstrumentItem.SyncInstrumentDSInfo.ServerName = "";
  245. syncInstrumentItem.SyncInstrumentDSInfo.UserId = "";
  246. syncInstrumentItem.SyncInstrumentDSInfo.UserPwd = "";
  247. syncInstrumentItem.SyncInstrumentDSInfo.DsPathType = this.cbxExcelRemote.Checked ? PathType.Remote : PathType.Local;
  248. syncInstrumentItem.SyncInstrumentDSInfo.RemoteUser = this.txtRemoteExcelUser.Text.Trim();
  249. syncInstrumentItem.SyncInstrumentDSInfo.RemotePwd = this.txtRemoteExcelPwd.Text.Trim();
  250. break;
  251. }
  252. object[] obj = new object[] { "", "", "" };
  253. //instrumentData = InstrumentDataFact.CreateInstrumentDataSource(syncInstrumentItem.SyncInstrumentDSInfo, obj);
  254. //dictInstrument = instrumentData.GetInstrumentData();
  255. //目标库的信息
  256. if (GlobalCommonOperation.strStartWebApi != "1")
  257. {
  258. syncInstrumentItem.SyncTargetDBInfo.DBHost = this.txtDBHost.Text.Trim();
  259. syncInstrumentItem.SyncTargetDBInfo.DBName = this.txtDBName.Text.Trim();
  260. syncInstrumentItem.SyncTargetDBInfo.DBUser = this.txtDBUser.Text.Trim();
  261. syncInstrumentItem.SyncTargetDBInfo.DBPwd = this.txtDBPwd.Text.Trim();
  262. syncInstrumentItem.SyncTargetDBInfo.DBPort = this.txtPort.Text.Trim();
  263. }
  264. else
  265. syncInstrumentItem.SyncTargetDBInfo = targetDataBaseInfo;
  266. this.InstrumentDelegate(syncInstrumentItem);
  267. //this.InstrumentItemData(dictInstrument);
  268. this.Close();
  269. }
  270. private void btnOpenFileExcel_Click(object sender, EventArgs e)
  271. {
  272. if (syncInstrumentItem.Code == null) return;
  273. if (syncInstrumentItem.SyncInstrumentDSInfo == null)
  274. syncInstrumentItem.SyncInstrumentDSInfo = new InstrumentDataSourceInfo();
  275. syncInstrumentItem.SyncInstrumentDSInfo.InstrumentDataSourceType = DataSourceType.Excel;
  276. if (strReadExcelMode == "0")
  277. {
  278. OpenFileDialog openFile = new OpenFileDialog
  279. {
  280. Filter = "Excel(*.xlsx)|*.xlsx|Excel(*.xls)|*.xls",
  281. InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
  282. Multiselect = false
  283. };
  284. if (openFile.ShowDialog() == DialogResult.Cancel) return;
  285. this.txtInportExcel.Text = syncInstrumentItem.SyncInstrumentDSInfo.Path = openFile.FileName;
  286. string fileType = System.IO.Path.GetExtension(openFile.FileName);
  287. if (string.IsNullOrEmpty(fileType)) return;
  288. }
  289. else
  290. {
  291. FolderBrowserDialog dialog = new FolderBrowserDialog();
  292. dialog.Description = "请选择文件路径";
  293. if (dialog.ShowDialog() == DialogResult.Cancel) return;
  294. this.txtInportExcel.Text = syncInstrumentItem.SyncInstrumentDSInfo.Path = dialog.SelectedPath;
  295. }
  296. }
  297. private void tabcDS_Selected(object sender, TabControlEventArgs e)
  298. {
  299. //切换的时候,检查其他类型数据源是否有值,如果有值,将提示删除旧值才能配置新值
  300. if (e.TabPage == tabExcel)
  301. {
  302. //检查tabAccess页面是否为空 //检查tabSQLite页面是否为空
  303. if (!CheckAccessControl() || !CheckSQLiteControl() || !CheckSQLServerControl() || !CheckMySqlControl() || !CheckOracleControl() || !CheckFoxproControl() || !CheckTxtControl())
  304. {
  305. if (MessageBox.Show("其他数据源存在已保存数据,继续将删除这些值,是否继续", "提示", MessageBoxButtons.OKCancel) == DialogResult.OK)
  306. {
  307. ClearAccessControl();
  308. ClearSqliteControl();
  309. ClearSQLServerControl();
  310. ClearMySQLControl();
  311. ClearOracleControl();
  312. ClearFoxproControl();
  313. ClearTxtControl();
  314. ClearObjectValue();
  315. }
  316. else
  317. {
  318. ChangeSelectTabPageByType();
  319. return;
  320. }
  321. }
  322. syncInstrumentItem.SyncInstrumentDSInfo.InstrumentDataSourceType = DataSourceType.Excel;
  323. }
  324. if (e.TabPage == tabAccess)
  325. {
  326. //检查tabAccess页面是否为空 //检查tabSQLite页面是否为空
  327. if (!CheckExcelControl() || !CheckSQLiteControl() || !CheckSQLServerControl() || !CheckMySqlControl() || !CheckOracleControl() || !CheckFoxproControl() || !CheckTxtControl())
  328. {
  329. if (MessageBox.Show("其他数据源存在已保存数据,继续将删除这些值,是否继续", "提示", MessageBoxButtons.OKCancel) == DialogResult.OK)
  330. {
  331. ClearExcelControl();
  332. ClearSqliteControl();
  333. ClearSQLServerControl();
  334. ClearMySQLControl();
  335. ClearOracleControl();
  336. ClearFoxproControl();
  337. ClearTxtControl();
  338. ClearObjectValue();
  339. }
  340. else
  341. {
  342. ChangeSelectTabPageByType();
  343. return;
  344. }
  345. }
  346. syncInstrumentItem.SyncInstrumentDSInfo.InstrumentDataSourceType = DataSourceType.Access;
  347. }
  348. if (e.TabPage == tabSQLite)
  349. {
  350. //检查tabAccess页面是否为空 //检查tabSQLite页面是否为空
  351. if (!CheckExcelControl() || !CheckAccessControl() || !CheckSQLServerControl() || !CheckMySqlControl() || !CheckOracleControl() || !CheckFoxproControl() || !CheckTxtControl())
  352. {
  353. if (MessageBox.Show("其他数据源存在已保存数据,继续将删除这些值,是否继续", "提示", MessageBoxButtons.OKCancel) == DialogResult.OK)
  354. {
  355. ClearAccessControl();
  356. ClearExcelControl();
  357. ClearSQLServerControl();
  358. ClearMySQLControl();
  359. ClearOracleControl();
  360. ClearFoxproControl();
  361. ClearTxtControl();
  362. ClearObjectValue();
  363. }
  364. else
  365. {
  366. ChangeSelectTabPageByType();
  367. return;
  368. }
  369. }
  370. syncInstrumentItem.SyncInstrumentDSInfo.InstrumentDataSourceType = DataSourceType.SQLLite;
  371. }
  372. if (e.TabPage == tabSQLServer)
  373. {
  374. //检查tabAccess页面是否为空 //检查tabSQLite页面是否为空
  375. if (!CheckExcelControl() || !CheckAccessControl() || !CheckSQLiteControl() || !CheckMySqlControl() || !CheckOracleControl() || !CheckFoxproControl() || !CheckTxtControl())
  376. {
  377. if (MessageBox.Show("其他数据源存在已保存数据,继续将删除这些值,是否继续", "提示", MessageBoxButtons.OKCancel) == DialogResult.OK)
  378. {
  379. ClearAccessControl();
  380. ClearExcelControl();
  381. ClearSqliteControl();
  382. ClearMySQLControl();
  383. ClearOracleControl();
  384. ClearFoxproControl();
  385. ClearTxtControl();
  386. ClearObjectValue();
  387. }
  388. else
  389. {
  390. ChangeSelectTabPageByType();
  391. return;
  392. }
  393. }
  394. syncInstrumentItem.SyncInstrumentDSInfo.InstrumentDataSourceType = DataSourceType.SQL;
  395. }
  396. if (e.TabPage == tabMySql)
  397. {
  398. //检查tabAccess页面是否为空 //检查tabSQLite页面是否为空
  399. if (!CheckExcelControl() || !CheckAccessControl() || !CheckSQLiteControl() || !CheckSQLServerControl() || !CheckOracleControl() || !CheckFoxproControl() || !CheckTxtControl())
  400. {
  401. if (MessageBox.Show("其他数据源存在已保存数据,继续将删除这些值,是否继续", "提示", MessageBoxButtons.OKCancel) == DialogResult.OK)
  402. {
  403. ClearAccessControl();
  404. ClearExcelControl();
  405. ClearSqliteControl();
  406. ClearSQLServerControl();
  407. ClearOracleControl();
  408. ClearFoxproControl();
  409. ClearTxtControl();
  410. ClearObjectValue();
  411. }
  412. else
  413. {
  414. ChangeSelectTabPageByType();
  415. return;
  416. }
  417. }
  418. syncInstrumentItem.SyncInstrumentDSInfo.InstrumentDataSourceType = DataSourceType.MySQL;
  419. }
  420. if (e.TabPage == tabOracle)
  421. {
  422. //检查tabAccess页面是否为空 //检查tabSQLite页面是否为空
  423. if (!CheckExcelControl() || !CheckAccessControl() || !CheckSQLiteControl() || !CheckSQLServerControl() || !CheckMySqlControl() || !CheckFoxproControl() || !CheckTxtControl())
  424. {
  425. if (MessageBox.Show("其他数据源存在已保存数据,继续将删除这些值,是否继续", "提示", MessageBoxButtons.OKCancel) == DialogResult.OK)
  426. {
  427. ClearAccessControl();
  428. ClearExcelControl();
  429. ClearSqliteControl();
  430. ClearSQLServerControl();
  431. ClearMySQLControl();
  432. ClearFoxproControl();
  433. ClearTxtControl();
  434. ClearObjectValue();
  435. }
  436. else
  437. {
  438. ChangeSelectTabPageByType();
  439. return;
  440. }
  441. }
  442. syncInstrumentItem.SyncInstrumentDSInfo.InstrumentDataSourceType = DataSourceType.Oracle;
  443. }
  444. if (e.TabPage == tabFoxPro)
  445. {
  446. if (!CheckExcelControl() || !CheckAccessControl() || !CheckSQLiteControl() || !CheckSQLServerControl() || !CheckMySqlControl() || !CheckOracleControl() || !CheckTxtControl())
  447. {
  448. if (MessageBox.Show("其他数据源存在已保存数据,继续将删除这些值,是否继续", "提示", MessageBoxButtons.OKCancel) == DialogResult.OK)
  449. {
  450. ClearAccessControl();
  451. ClearExcelControl();
  452. ClearSqliteControl();
  453. ClearSQLServerControl();
  454. ClearMySQLControl();
  455. ClearOracleControl();
  456. ClearTxtControl();
  457. ClearObjectValue();
  458. }
  459. else
  460. {
  461. ChangeSelectTabPageByType();
  462. return;
  463. }
  464. }
  465. syncInstrumentItem.SyncInstrumentDSInfo.InstrumentDataSourceType = DataSourceType.FoxPro;
  466. }
  467. if (e.TabPage == tabTxt)
  468. {
  469. if (!CheckExcelControl() || !CheckAccessControl() || !CheckSQLiteControl() || !CheckSQLServerControl() || !CheckMySqlControl() || !CheckOracleControl() || !CheckFoxproControl())
  470. {
  471. if (MessageBox.Show("其他数据源存在已保存数据,继续将删除这些值,是否继续", "提示", MessageBoxButtons.OKCancel) == DialogResult.OK)
  472. {
  473. ClearAccessControl();
  474. ClearExcelControl();
  475. ClearSqliteControl();
  476. ClearSQLServerControl();
  477. ClearMySQLControl();
  478. ClearOracleControl();
  479. ClearFoxproControl();
  480. ClearObjectValue();
  481. }
  482. else
  483. {
  484. ChangeSelectTabPageByType();
  485. return;
  486. }
  487. }
  488. syncInstrumentItem.SyncInstrumentDSInfo.InstrumentDataSourceType = DataSourceType.TXT;
  489. }
  490. if (e.TabPage == tabPostgreSql)
  491. {
  492. if (!CheckExcelControl() || !CheckAccessControl() || !CheckSQLiteControl() ||
  493. !CheckSQLServerControl() || !CheckMySqlControl() || !CheckOracleControl() ||
  494. !CheckFoxproControl() || !CheckTxtControl())
  495. {
  496. if (MessageBox.Show("其他数据源存在已保存数据,继续将删除这些值,是否继续", "提示",
  497. MessageBoxButtons.OKCancel) == DialogResult.OK)
  498. {
  499. ClearAccessControl();
  500. ClearExcelControl();
  501. ClearSqliteControl();
  502. ClearSQLServerControl();
  503. ClearMySQLControl();
  504. ClearOracleControl();
  505. ClearFoxproControl();
  506. ClearTxtControl();
  507. ClearObjectValue();
  508. }
  509. else
  510. {
  511. ChangeSelectTabPageByType();
  512. return;
  513. }
  514. }
  515. syncInstrumentItem.SyncInstrumentDSInfo.InstrumentDataSourceType = DataSourceType.PostgreSQL;
  516. }
  517. if (e.TabPage == tabKingbase)
  518. {
  519. if (!CheckExcelControl() || !CheckAccessControl() || !CheckSQLiteControl() ||
  520. !CheckSQLServerControl() || !CheckMySqlControl() || !CheckOracleControl() ||
  521. !CheckFoxproControl() || !CheckTxtControl() || !CheckPostgreSqlControl())
  522. {
  523. if (MessageBox.Show("其他数据源存在已保存数据,继续将删除这些值,是否继续", "提示",
  524. MessageBoxButtons.OKCancel) == DialogResult.OK)
  525. {
  526. ClearAccessControl();
  527. ClearExcelControl();
  528. ClearSqliteControl();
  529. ClearSQLServerControl();
  530. ClearMySQLControl();
  531. ClearOracleControl();
  532. ClearFoxproControl();
  533. ClearTxtControl();
  534. ClearPostgreSqlControl();
  535. ClearObjectValue();
  536. }
  537. else
  538. {
  539. ChangeSelectTabPageByType();
  540. return;
  541. }
  542. }
  543. syncInstrumentItem.SyncInstrumentDSInfo.InstrumentDataSourceType = DataSourceType.Kingbase;
  544. }
  545. if (e.TabPage == tabDm)
  546. {
  547. if (!CheckExcelControl() || !CheckAccessControl() || !CheckSQLiteControl() ||
  548. !CheckSQLServerControl() || !CheckMySqlControl() || !CheckOracleControl() ||
  549. !CheckFoxproControl() || !CheckTxtControl() || !CheckPostgreSqlControl() ||
  550. !CheckKingbaseControl())
  551. {
  552. if (MessageBox.Show("其他数据源存在已保存数据,继续将删除这些值,是否继续", "提示",
  553. MessageBoxButtons.OKCancel) == DialogResult.OK)
  554. {
  555. ClearAccessControl();
  556. ClearExcelControl();
  557. ClearSqliteControl();
  558. ClearSQLServerControl();
  559. ClearMySQLControl();
  560. ClearOracleControl();
  561. ClearFoxproControl();
  562. ClearTxtControl();
  563. ClearPostgreSqlControl();
  564. ClearKingbaseControl();
  565. ClearObjectValue();
  566. }
  567. else
  568. {
  569. ChangeSelectTabPageByType();
  570. return;
  571. }
  572. }
  573. syncInstrumentItem.SyncInstrumentDSInfo.InstrumentDataSourceType = DataSourceType.Dm;
  574. }
  575. }
  576. //根据数据源类型切换Tab页
  577. private void ChangeSelectTabPageByType()
  578. {
  579. switch (syncInstrumentItem.SyncInstrumentDSInfo.InstrumentDataSourceType)
  580. {
  581. case DataSourceType.SQLLite:
  582. tabcDS.SelectedTab = tabSQLite;
  583. break;
  584. case DataSourceType.Access:
  585. tabcDS.SelectedTab = tabAccess;
  586. break;
  587. case DataSourceType.SQL:
  588. tabcDS.SelectedTab = tabSQLServer;
  589. break;
  590. case DataSourceType.Oracle:
  591. tabcDS.SelectedTab = tabOracle;
  592. break;
  593. case DataSourceType.FoxPro:
  594. tabcDS.SelectedTab = tabFoxPro;
  595. break;
  596. case DataSourceType.TXT:
  597. tabcDS.SelectedTab = tabTxt;
  598. break;
  599. case DataSourceType.Excel:
  600. case DataSourceType.PostgreSQL:
  601. case DataSourceType.Kingbase:
  602. default:
  603. tabcDS.SelectedTab = tabExcel;
  604. break;
  605. }
  606. }
  607. private bool CheckExcelControl()
  608. {
  609. if (this.txtInportExcel.Text != "")
  610. return false;
  611. else
  612. return true;
  613. }
  614. private bool CheckAccessControl()
  615. {
  616. if (this.txtAccessPath.Text != "" || this.txtAccessUser.Text != "" || this.txtAceessPwd.Text != "")
  617. return false;
  618. else
  619. return true;
  620. }
  621. private bool CheckSQLiteControl()
  622. {
  623. if (this.txtSqlitePath.Text != "" || this.txtSqliteUser.Text != "" || this.txtSqlitePwd.Text != "")
  624. return false;
  625. else
  626. return true;
  627. }
  628. private bool CheckSQLServerControl()
  629. {
  630. if (this.txtSqlServerHost.Text.Trim() != "" || this.txtSqlServerName.Text.Trim() != "" || this.txtSqlServerPwd.Text.Trim() != "" || this.txtSqlServerUser.Text.Trim() != "")
  631. return false;
  632. else
  633. return true;
  634. }
  635. private bool CheckMySqlControl()
  636. {
  637. if (this.txtMySqlHost.Text.Trim() != "" || this.txtMySqlServer.Text.Trim() != "" || this.txtMySqlUser.Text.Trim() != "" || this.txtMySqlPwd.Text.Trim() != "" || this.txtMySqlPort.Text.Trim() != "")
  638. return false;
  639. else
  640. return true;
  641. }
  642. private bool CheckOracleControl()
  643. {
  644. if (this.txtOraclePort.Text.Trim() != "" || this.txtOraclePwd.Text.Trim() != "" || this.txtOracleHost.Text.Trim() != "" || this.txtOracleSource.Text.Trim() != "" || this.txtOracleUserId.Text.Trim() != "")
  645. return false;
  646. else
  647. return true;
  648. }
  649. private bool CheckFoxproControl()
  650. {
  651. if (this.txtFoxProFolder.Text.Trim() != "" || this.txtFoxProUserId.Text.Trim() != "" || this.txtFoxProPwd.Text.Trim() != "" || this.txtRemoteFoxProUserId.Text.Trim() != "" || this.txtRemoteFoxProPwd.Text.Trim() != "")
  652. {
  653. return false;
  654. }
  655. else
  656. return true;
  657. }
  658. private bool CheckTxtControl()
  659. {
  660. if (this.txtInportTxt.Text.Trim() != "" || this.txtRemoteTxtUserId.Text.Trim() != "" || this.txtRemoteTxtPwd.Text.Trim() != "")
  661. return false;
  662. else
  663. return true;
  664. }
  665. private void btnCNASTestLink_Click(object sender, EventArgs e)
  666. {
  667. //this.txtDBHost.Text.Trim(), this.txtDBName.Text.Trim(), this.txtDBUser.Text.Trim(), this.txtDBPwd.Text.Trim(),this.txtPort.Text.Trim()
  668. if (CnasDataOperationFact.CnasDataOperation().TestConnect(new DataBaseInfo()
  669. {
  670. DBHost = this.txtDBHost.Text.Trim(),
  671. DBName = this.txtDBName.Text.Trim(),
  672. DBUser = this.txtDBUser.Text.Trim(),
  673. DBPwd = this.txtDBPwd.Text.Trim(),
  674. DBPort = this.txtPort.Text.Trim()
  675. }))
  676. MessageBox.Show("连接成功!");
  677. else
  678. MessageBox.Show("连接失败!");
  679. }
  680. private void ClearExcelControl()
  681. {
  682. this.txtInportExcel.Text = "";
  683. this.txtRemoteExcelUser.Text = "";
  684. this.txtRemoteExcelPwd.Text = "";
  685. }
  686. private void ClearAccessControl()
  687. {
  688. this.txtAccessPath.Text = "";
  689. this.txtAccessUser.Text = "";
  690. this.txtAceessPwd.Text = "";
  691. this.txtAccessRemoteUser.Text = "";
  692. this.txtAccessRemotePwd.Text = "";
  693. }
  694. private void ClearSqliteControl()
  695. {
  696. this.txtSqliteUser.Text = "";
  697. this.txtSqlitePath.Text = "";
  698. this.txtSqlitePwd.Text = "";
  699. this.txtSqliteRemoteUser.Text = "";
  700. this.txtSqliteRemotePwd.Text = "";
  701. }
  702. private void ClearSQLServerControl()
  703. {
  704. this.txtSqlServerHost.Text = "";
  705. this.txtSqlServerName.Text = "";
  706. this.txtSqlServerUser.Text = "";
  707. this.txtSqlServerPwd.Text = "";
  708. }
  709. private void ClearMySQLControl()
  710. {
  711. this.txtMySqlHost.Text = "";
  712. this.txtMySqlServer.Text = "";
  713. this.txtMySqlUser.Text = "";
  714. this.txtMySqlPwd.Text = "";
  715. this.txtMySqlPort.Text = "";
  716. }
  717. private void ClearOracleControl()
  718. {
  719. this.txtOracleHost.Text = "";
  720. this.txtOracleSource.Text = "";
  721. this.txtOracleUserId.Text = "";
  722. this.txtOraclePwd.Text = "";
  723. this.txtOraclePort.Text = "";
  724. }
  725. private void ClearFoxproControl()
  726. {
  727. this.txtFoxProFolder.Text = "";
  728. this.txtFoxProUserId.Text = "";
  729. this.txtFoxProPwd.Text = "";
  730. this.txtRemoteFoxProUserId.Text = "";
  731. this.txtRemoteFoxProPwd.Text = "";
  732. }
  733. private void ClearTxtControl()
  734. {
  735. this.txtInportTxt.Text = "";
  736. this.txtRemoteTxtUserId.Text = "";
  737. this.txtRemoteTxtPwd.Text = "";
  738. }
  739. /// <summary>
  740. /// 清空对象中存储的值
  741. /// </summary>
  742. private void ClearObjectValue()
  743. {
  744. syncInstrumentItem.SyncInstrumentDSInfo.Host = "";
  745. syncInstrumentItem.SyncInstrumentDSInfo.ServerName = "";
  746. syncInstrumentItem.SyncInstrumentDSInfo.Path = "";
  747. syncInstrumentItem.SyncInstrumentDSInfo.UserId = "";
  748. syncInstrumentItem.SyncInstrumentDSInfo.UserPwd = "";
  749. syncInstrumentItem.SyncInstrumentDSInfo.Port = "";
  750. syncInstrumentItem.SyncInstrumentDSInfo.DsPathType = PathType.Local;
  751. syncInstrumentItem.SyncInstrumentDSInfo.RemoteUser = "";
  752. syncInstrumentItem.SyncInstrumentDSInfo.RemotePwd = "";
  753. }
  754. private void btnOpenFileAccess_Click(object sender, EventArgs e)
  755. {
  756. if (syncInstrumentItem.Code == null) return;
  757. if (syncInstrumentItem.SyncInstrumentDSInfo == null)
  758. syncInstrumentItem.SyncInstrumentDSInfo = new InstrumentDataSourceInfo();
  759. syncInstrumentItem.SyncInstrumentDSInfo.InstrumentDataSourceType = DataSourceType.Access;
  760. if (strReadAccessMode == "0")
  761. {
  762. OpenFileDialog openFile = new OpenFileDialog
  763. {
  764. Filter = "Microsoft Access(*.mdb)|*.mdb|Microsoft Access(*.accdb)|*.accdb",
  765. InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
  766. Multiselect = false
  767. };
  768. if (openFile.ShowDialog() == DialogResult.Cancel) return;
  769. this.txtAccessPath.Text = syncInstrumentItem.SyncInstrumentDSInfo.Path = openFile.FileName;
  770. string fileType = System.IO.Path.GetExtension(openFile.FileName);
  771. if (string.IsNullOrEmpty(fileType)) return;
  772. }
  773. else
  774. {
  775. FolderBrowserDialog dialog = new FolderBrowserDialog();
  776. dialog.Description = "请选择文件路径";
  777. if (dialog.ShowDialog() == DialogResult.Cancel) return;
  778. this.txtAccessPath.Text = syncInstrumentItem.SyncInstrumentDSInfo.Path = dialog.SelectedPath;
  779. }
  780. }
  781. private void btnOpenFileSQLite_Click(object sender, EventArgs e)
  782. {
  783. if (syncInstrumentItem.Code == null) return;
  784. if (syncInstrumentItem.SyncInstrumentDSInfo == null)
  785. syncInstrumentItem.SyncInstrumentDSInfo = new InstrumentDataSourceInfo();
  786. syncInstrumentItem.SyncInstrumentDSInfo.InstrumentDataSourceType = DataSourceType.SQLLite;
  787. if (strReadSqliteMode == "0")
  788. {
  789. OpenFileDialog openFile = new OpenFileDialog
  790. {
  791. Filter = "SQLite(*.db)|*.db",
  792. InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
  793. Multiselect = false
  794. };
  795. if (openFile.ShowDialog() == DialogResult.Cancel) return;
  796. this.txtSqlitePath.Text = syncInstrumentItem.SyncInstrumentDSInfo.Path = openFile.FileName;
  797. string fileType = System.IO.Path.GetExtension(openFile.FileName);
  798. if (string.IsNullOrEmpty(fileType)) return;
  799. }
  800. else
  801. {
  802. FolderBrowserDialog dialog = new FolderBrowserDialog();
  803. dialog.Description = "请选择文件路径";
  804. if (dialog.ShowDialog() == DialogResult.Cancel) return;
  805. this.txtSqlitePath.Text = syncInstrumentItem.SyncInstrumentDSInfo.Path = dialog.SelectedPath;
  806. }
  807. }
  808. private void btnTestSQLLink_Click(object sender, EventArgs e)
  809. {
  810. if (this.txtSqlServerHost.Text.Trim() == "" || this.txtSqlServerName.Text.Trim() == "" || this.txtSqlServerUser.Text.Trim() == "")
  811. {
  812. MessageBox.Show("请填写相关连接信息。");
  813. return;
  814. }
  815. InstrumentDataSourceInfo dbinfo = new InstrumentDataSourceInfo();
  816. dbinfo.Host = this.txtSqlServerHost.Text.Trim();
  817. dbinfo.ServerName = this.txtSqlServerName.Text.Trim();
  818. dbinfo.UserId = this.txtSqlServerUser.Text.Trim();
  819. dbinfo.UserPwd = this.txtSqlServerPwd.Text.Trim();
  820. dbinfo.Port = this.txtSqlServerPort.Text.Trim();
  821. if (new SQLServerInstrumentData(dbinfo, new object[] {
  822. "",
  823. "",
  824. ""
  825. }).TestSQLServerLink())
  826. MessageBox.Show("连接成功!");
  827. else
  828. MessageBox.Show("连接失败!");
  829. }
  830. private void cbxExcelRemote_CheckedChanged(object sender, EventArgs e)
  831. {
  832. if (!cbxExcelRemote.Checked)
  833. {
  834. this.btnOpenFileExcel.Visible = true;
  835. lblExcelRemotePwd.Visible = false;
  836. lblExcelRemoteUser.Visible = false;
  837. txtRemoteExcelUser.Visible = false;
  838. txtRemoteExcelPwd.Visible = false;
  839. }
  840. else
  841. {
  842. this.btnOpenFileExcel.Visible = false;
  843. lblExcelRemotePwd.Visible = true;
  844. lblExcelRemoteUser.Visible = true;
  845. txtRemoteExcelUser.Visible = true;
  846. txtRemoteExcelPwd.Visible = true;
  847. }
  848. }
  849. private void cbxAccessRemote_CheckedChanged(object sender, EventArgs e)
  850. {
  851. if (cbxAccessRemote.Checked)
  852. {
  853. btnOpenFileAccess.Visible = false;
  854. lblAccessRemoteUser.Visible = true;
  855. lblAccessRemotePwd.Visible = true;
  856. txtAccessRemoteUser.Visible = true;
  857. txtAccessRemotePwd.Visible = true;
  858. }
  859. else
  860. {
  861. btnOpenFileAccess.Visible = true;
  862. lblAccessRemoteUser.Visible = false;
  863. lblAccessRemotePwd.Visible = false;
  864. txtAccessRemoteUser.Visible = false;
  865. txtAccessRemotePwd.Visible = false;
  866. }
  867. }
  868. private void cbxSqliteRemote_CheckedChanged(object sender, EventArgs e)
  869. {
  870. if (cbxSqliteRemote.Checked)
  871. {
  872. btnOpenFileSQLite.Visible = false;
  873. lblSqliteRemoteUser.Visible = true;
  874. lblSqliteRemotePwd.Visible = true;
  875. txtSqliteRemoteUser.Visible = true;
  876. txtSqliteRemotePwd.Visible = true;
  877. }
  878. else
  879. {
  880. btnOpenFileSQLite.Visible = true;
  881. lblSqliteRemoteUser.Visible = false;
  882. lblSqliteRemotePwd.Visible = false;
  883. txtSqliteRemoteUser.Visible = false;
  884. txtSqliteRemotePwd.Visible = false;
  885. }
  886. }
  887. private void btnMySqlTest_Click(object sender, EventArgs e)
  888. {
  889. if (CnasDataOperationFact.CnasDataOperation().TestConnect(new DataBaseInfo()
  890. {
  891. DBHost = this.txtMySqlHost.Text.Trim(),
  892. DBName = this.txtMySqlServer.Text.Trim(),
  893. DBUser = this.txtMySqlUser.Text.Trim(),
  894. DBPwd = this.txtMySqlPwd.Text.Trim(),
  895. DBPort = this.txtMySqlPort.Text.Trim()
  896. }))
  897. MessageBox.Show("连接成功!");
  898. else
  899. MessageBox.Show("连接失败!");
  900. }
  901. private void btnOracleTestLink_Click(object sender, EventArgs e)
  902. {
  903. if (this.txtOracleHost.Text.Trim() == "" || this.txtOracleSource.Text.Trim() == "" || this.txtOracleUserId.Text.Trim() == "" || this.txtOraclePort.Text.Trim() == "")
  904. {
  905. MessageBox.Show("请填写相关连接信息。");
  906. return;
  907. }
  908. InstrumentDataSourceInfo dbinfo = new InstrumentDataSourceInfo();
  909. dbinfo.Host = this.txtOracleHost.Text.Trim();
  910. dbinfo.ServerName = this.txtOracleSource.Text.Trim();
  911. dbinfo.UserId = this.txtOracleUserId.Text.Trim();
  912. dbinfo.UserPwd = this.txtOraclePwd.Text.Trim();
  913. dbinfo.Port = this.txtOraclePort.Text.Trim();
  914. if (new OracleInstrumentData(dbinfo, new object[] {
  915. "",
  916. "",
  917. ""
  918. }).TestSQLServerLink())
  919. MessageBox.Show("连接成功!");
  920. else
  921. MessageBox.Show("连接失败!");
  922. }
  923. private void txtFileOpenFoxPro_Click(object sender, EventArgs e)
  924. {
  925. if (syncInstrumentItem.Code == null) return;
  926. if (syncInstrumentItem.SyncInstrumentDSInfo == null)
  927. syncInstrumentItem.SyncInstrumentDSInfo = new InstrumentDataSourceInfo();
  928. syncInstrumentItem.SyncInstrumentDSInfo.InstrumentDataSourceType = DataSourceType.FoxPro;
  929. if (strReadFoxproMode == "0")
  930. {
  931. OpenFileDialog openFile = new OpenFileDialog
  932. {
  933. Filter = "Foxpro文件(*.dbf)|*.dbf",
  934. InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
  935. Multiselect = false
  936. };
  937. if (openFile.ShowDialog() == DialogResult.Cancel) return;
  938. this.txtFoxProFolder.Text = syncInstrumentItem.SyncInstrumentDSInfo.Path = openFile.FileName;
  939. string fileType = System.IO.Path.GetExtension(openFile.FileName);
  940. if (string.IsNullOrEmpty(fileType)) return;
  941. }
  942. else
  943. {
  944. FolderBrowserDialog dialog = new FolderBrowserDialog();
  945. dialog.Description = "请选择文件路径";
  946. if (dialog.ShowDialog() == DialogResult.Cancel) return;
  947. this.txtFoxProFolder.Text = syncInstrumentItem.SyncInstrumentDSInfo.Path = dialog.SelectedPath;
  948. }
  949. }
  950. private void cbxFoxProRemote_CheckedChanged(object sender, EventArgs e)
  951. {
  952. if (!cbxFoxProRemote.Checked)
  953. {
  954. this.btnFileOpenFoxPro.Visible = true;
  955. lblFoxproRemoteUserId.Visible = false;
  956. lblFoxproRemotePwd.Visible = false;
  957. txtRemoteFoxProUserId.Visible = false;
  958. txtRemoteFoxProPwd.Visible = false;
  959. }
  960. else
  961. {
  962. this.btnFileOpenFoxPro.Visible = false;
  963. lblFoxproRemoteUserId.Visible = true;
  964. lblFoxproRemotePwd.Visible = true;
  965. txtRemoteFoxProUserId.Visible = true;
  966. txtRemoteFoxProPwd.Visible = true;
  967. }
  968. }
  969. private void btnOpenFileTxt_Click(object sender, EventArgs e)
  970. {
  971. if (syncInstrumentItem.Code == null) return;
  972. if (syncInstrumentItem.SyncInstrumentDSInfo == null)
  973. syncInstrumentItem.SyncInstrumentDSInfo = new InstrumentDataSourceInfo();
  974. syncInstrumentItem.SyncInstrumentDSInfo.InstrumentDataSourceType = DataSourceType.TXT;
  975. if (strReadTxtMode == "0")
  976. {
  977. OpenFileDialog openFile = new OpenFileDialog
  978. {
  979. Filter = "文本文件(*.txt)|*.txt|所有文件(*.*)|*.*",
  980. InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
  981. Multiselect = false
  982. };
  983. if (openFile.ShowDialog() == DialogResult.Cancel) return;
  984. this.txtInportTxt.Text = syncInstrumentItem.SyncInstrumentDSInfo.Path = openFile.FileName;
  985. string fileType = System.IO.Path.GetExtension(openFile.FileName);
  986. if (string.IsNullOrEmpty(fileType)) return;
  987. }
  988. else
  989. {
  990. FolderBrowserDialog dialog = new FolderBrowserDialog();
  991. dialog.Description = "请选择文件路径";
  992. if (dialog.ShowDialog() == DialogResult.Cancel) return;
  993. this.txtInportTxt.Text = syncInstrumentItem.SyncInstrumentDSInfo.Path = dialog.SelectedPath;
  994. }
  995. }
  996. private void cbxRemoteTxt_CheckedChanged(object sender, EventArgs e)
  997. {
  998. if (!cbxRemoteTxt.Checked)
  999. {
  1000. this.btnOpenFileTxt.Visible = true;
  1001. lblTxtRemoteUserId.Visible = false;
  1002. lblTxtRemoteUserPwd.Visible = false;
  1003. txtRemoteTxtUserId.Visible = false;
  1004. txtRemoteTxtPwd.Visible = false;
  1005. }
  1006. else
  1007. {
  1008. this.btnOpenFileTxt.Visible = false;
  1009. lblTxtRemoteUserId.Visible = true;
  1010. lblTxtRemoteUserPwd.Visible = true;
  1011. txtRemoteTxtUserId.Visible = true;
  1012. txtRemoteTxtPwd.Visible = true;
  1013. }
  1014. }
  1015. private void cbxTargetDBSelect_SelectedIndexChanged(object sender, EventArgs e)
  1016. {
  1017. if (cbxTargetDBSelect.SelectedIndex == 0)
  1018. {
  1019. if (GlobalCommonOperation.strStartWebApi == "1")
  1020. {
  1021. targetDataBaseInfo = new DataBaseInfo()
  1022. {
  1023. DataBaseCode = "cnas"
  1024. };
  1025. }
  1026. else
  1027. {
  1028. DataBaseInfo CNASDataBase = FileOperation.GetLocalCnasDB();
  1029. if (CNASDataBase != null)
  1030. {
  1031. this.txtDBHost.Text = CNASDataBase.DBHost;
  1032. this.txtDBName.Text = CNASDataBase.DBName;
  1033. this.txtDBUser.Text = CNASDataBase.DBUser;
  1034. this.txtDBPwd.Text = CNASDataBase.DBPwd;
  1035. this.txtPort.Text = CNASDataBase.DBPort;
  1036. }
  1037. }
  1038. }
  1039. else if (cbxTargetDBSelect.SelectedIndex == 1)
  1040. {
  1041. if (GlobalCommonOperation.strStartWebApi == "1")
  1042. {
  1043. targetDataBaseInfo = new DataBaseInfo()
  1044. {
  1045. DataBaseCode = "platform"
  1046. };
  1047. }
  1048. else
  1049. {
  1050. DataBaseInfo PlatDataBase = FileOperation.GetLocalPlatFormDB();
  1051. if (PlatDataBase != null)
  1052. {
  1053. this.txtDBHost.Text = PlatDataBase.DBHost;
  1054. this.txtDBName.Text = PlatDataBase.DBName;
  1055. this.txtDBUser.Text = PlatDataBase.DBUser;
  1056. this.txtDBPwd.Text = PlatDataBase.DBPwd;
  1057. this.txtPort.Text = PlatDataBase.DBPort;
  1058. }
  1059. }
  1060. }
  1061. }
  1062. private bool CheckPostgreSqlControl()
  1063. {
  1064. if (this.txtPostgreSqlHost.Text.Trim() != "" || this.txtPostgreSqlServer.Text.Trim() != "" ||
  1065. this.txtPostgreSqlUser.Text.Trim() != "" || this.txtPostgreSqlPwd.Text.Trim() != "" ||
  1066. this.txtPostgreSqlPort.Text.Trim() != "")
  1067. return false;
  1068. else
  1069. return true;
  1070. }
  1071. private void ClearPostgreSqlControl()
  1072. {
  1073. this.txtPostgreSqlHost.Text = "";
  1074. this.txtPostgreSqlServer.Text = "";
  1075. this.txtPostgreSqlUser.Text = "";
  1076. this.txtPostgreSqlPwd.Text = "";
  1077. this.txtPostgreSqlPort.Text = "";
  1078. }
  1079. private bool CheckKingbaseControl()
  1080. {
  1081. if (this.txtKingbaselHost.Text.Trim() != "" || this.txtKingbaselServer.Text.Trim() != "" ||
  1082. this.txtKingbaselUser.Text.Trim() != "" || this.txtKingbaselPwd.Text.Trim() != "" ||
  1083. this.txtKingbaselPort.Text.Trim() != "")
  1084. return false;
  1085. else
  1086. return true;
  1087. }
  1088. private void ClearKingbaseControl()
  1089. {
  1090. this.txtKingbaselHost.Text = "";
  1091. this.txtKingbaselServer.Text = "";
  1092. this.txtKingbaselUser.Text = "";
  1093. this.txtKingbaselPwd.Text = "";
  1094. this.txtKingbaselPort.Text = "";
  1095. }
  1096. private void btnKingbaselConn_Click(object sender, EventArgs e)
  1097. {
  1098. if (this.txtKingbaselHost.Text.Trim() == "" || this.txtKingbaselServer.Text.Trim() == "" ||
  1099. this.txtKingbaselUser.Text.Trim() == "" || this.txtKingbaselPort.Text.Trim() == "")
  1100. {
  1101. MessageBox.Show("请填写相关连接信息。");
  1102. return;
  1103. }
  1104. InstrumentDataSourceInfo dbinfo = new InstrumentDataSourceInfo();
  1105. dbinfo.Host = this.txtKingbaselHost.Text.Trim();
  1106. dbinfo.ServerName = this.txtKingbaselServer.Text.Trim();
  1107. dbinfo.UserId = this.txtKingbaselUser.Text.Trim();
  1108. dbinfo.UserPwd = this.txtKingbaselPwd.Text.Trim();
  1109. dbinfo.Port = this.txtKingbaselPort.Text.Trim();
  1110. // 假设有KingbaseInstrumentData类来处理连接测试
  1111. if (new KingbaseServerInstrumentData(dbinfo, new object[] { "", "", "" }).TestSQLServerLink())
  1112. MessageBox.Show("连接成功!");
  1113. else
  1114. MessageBox.Show("连接失败!");
  1115. }
  1116. private void btnPostgreSqlConn_Click(object sender, EventArgs e)
  1117. {
  1118. if (this.txtPostgreSqlHost.Text.Trim() == "" || this.txtPostgreSqlServer.Text.Trim() == "" ||
  1119. this.txtPostgreSqlUser.Text.Trim() == "" || this.txtPostgreSqlPort.Text.Trim() == "")
  1120. {
  1121. MessageBox.Show("请填写相关连接信息。");
  1122. return;
  1123. }
  1124. InstrumentDataSourceInfo dbinfo = new InstrumentDataSourceInfo();
  1125. dbinfo.Host = this.txtPostgreSqlHost.Text.Trim();
  1126. dbinfo.ServerName = this.txtPostgreSqlServer.Text.Trim();
  1127. dbinfo.UserId = this.txtPostgreSqlUser.Text.Trim();
  1128. dbinfo.UserPwd = this.txtPostgreSqlPwd.Text.Trim();
  1129. dbinfo.Port = this.txtPostgreSqlPort.Text.Trim();
  1130. //SQLServerInstrumentData
  1131. if (new PostgreSQLServerInstrumentData(dbinfo, new object[] {
  1132. "",
  1133. "",
  1134. ""
  1135. }).TestSQLServerLink())
  1136. MessageBox.Show("连接成功!");
  1137. else
  1138. MessageBox.Show("连接失败!");
  1139. //if (new PostgreSQLServerInstrumentData(dbinfo, new object[] { "", "", "" }).TestConnection())
  1140. // MessageBox.Show("连接成功!");
  1141. //else
  1142. // MessageBox.Show("连接失败!");
  1143. //if (this.txtSqlServerHost.Text.Trim() == "" || this.txtSqlServerName.Text.Trim() == "" || this.txtSqlServerUser.Text.Trim() == "")
  1144. //{
  1145. // MessageBox.Show("请填写相关连接信息。");
  1146. // return;
  1147. //}
  1148. //InstrumentDataSourceInfo dbinfo = new InstrumentDataSourceInfo();
  1149. //dbinfo.Host = this.txtSqlServerHost.Text.Trim();
  1150. //dbinfo.ServerName = this.txtSqlServerName.Text.Trim();
  1151. //dbinfo.UserId = this.txtSqlServerUser.Text.Trim();
  1152. //dbinfo.UserPwd = this.txtSqlServerPwd.Text.Trim();
  1153. //dbinfo.Port = this.txtSqlServerPort.Text.Trim();
  1154. //if (new SQLServerInstrumentData(dbinfo, new object[] {
  1155. // "",
  1156. // "",
  1157. // ""
  1158. //}).TestSQLServerLink())
  1159. // MessageBox.Show("连接成功!");
  1160. //else
  1161. // MessageBox.Show("连接失败!");
  1162. }
  1163. private void btnDmConn_Click(object sender, EventArgs e)
  1164. {
  1165. if (this.txtDmHost.Text.Trim() == "" || this.txtDmServer.Text.Trim() == "" ||
  1166. this.txtDmUser.Text.Trim() == "" || this.btnDmConn.Text.Trim() == "")
  1167. {
  1168. MessageBox.Show("请填写相关连接信息。");
  1169. return;
  1170. }
  1171. InstrumentDataSourceInfo dbinfo = new InstrumentDataSourceInfo();
  1172. dbinfo.Host = this.txtDmHost.Text.Trim();
  1173. dbinfo.ServerName = this.txtDmServer.Text.Trim();
  1174. dbinfo.UserId = this.txtDmUser.Text.Trim();
  1175. dbinfo.UserPwd = this.txtDmPwd.Text.Trim();
  1176. dbinfo.Port = this.btnDmConn.Text.Trim();
  1177. if (new DmServerInstrumentData(dbinfo, new object[] { "", "", "" }).TestSQLServerLink())
  1178. MessageBox.Show("连接成功!");
  1179. else
  1180. MessageBox.Show("连接失败!");
  1181. }
  1182. private bool CheckDmControl()
  1183. {
  1184. if (this.txtDmHost.Text.Trim() != "" || this.txtDmServer.Text.Trim() != "" ||
  1185. this.txtDmUser.Text.Trim() != "" || this.txtDmPwd.Text.Trim() != "" ||
  1186. this.btnDmConn.Text.Trim() != "")
  1187. return false;
  1188. else
  1189. return true;
  1190. }
  1191. private void ClearDmControl()
  1192. {
  1193. this.txtDmHost.Text = "";
  1194. this.txtDmServer.Text = "";
  1195. this.txtDmUser.Text = "";
  1196. this.txtDmPwd.Text = "";
  1197. this.btnDmConn.Text = "";
  1198. }
  1199. }
  1200. }