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

1271 line
58KB

  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. }
  546. //根据数据源类型切换Tab页
  547. private void ChangeSelectTabPageByType()
  548. {
  549. switch (syncInstrumentItem.SyncInstrumentDSInfo.InstrumentDataSourceType)
  550. {
  551. case DataSourceType.SQLLite:
  552. tabcDS.SelectedTab = tabSQLite;
  553. break;
  554. case DataSourceType.Access:
  555. tabcDS.SelectedTab = tabAccess;
  556. break;
  557. case DataSourceType.SQL:
  558. tabcDS.SelectedTab = tabSQLServer;
  559. break;
  560. case DataSourceType.Oracle:
  561. tabcDS.SelectedTab = tabOracle;
  562. break;
  563. case DataSourceType.FoxPro:
  564. tabcDS.SelectedTab = tabFoxPro;
  565. break;
  566. case DataSourceType.TXT:
  567. tabcDS.SelectedTab = tabTxt;
  568. break;
  569. case DataSourceType.Excel:
  570. case DataSourceType.PostgreSQL:
  571. case DataSourceType.Kingbase:
  572. default:
  573. tabcDS.SelectedTab = tabExcel;
  574. break;
  575. }
  576. }
  577. private bool CheckExcelControl()
  578. {
  579. if (this.txtInportExcel.Text != "")
  580. return false;
  581. else
  582. return true;
  583. }
  584. private bool CheckAccessControl()
  585. {
  586. if (this.txtAccessPath.Text != "" || this.txtAccessUser.Text != "" || this.txtAceessPwd.Text != "")
  587. return false;
  588. else
  589. return true;
  590. }
  591. private bool CheckSQLiteControl()
  592. {
  593. if (this.txtSqlitePath.Text != "" || this.txtSqliteUser.Text != "" || this.txtSqlitePwd.Text != "")
  594. return false;
  595. else
  596. return true;
  597. }
  598. private bool CheckSQLServerControl()
  599. {
  600. if (this.txtSqlServerHost.Text.Trim() != "" || this.txtSqlServerName.Text.Trim() != "" || this.txtSqlServerPwd.Text.Trim() != "" || this.txtSqlServerUser.Text.Trim() != "")
  601. return false;
  602. else
  603. return true;
  604. }
  605. private bool CheckMySqlControl()
  606. {
  607. if (this.txtMySqlHost.Text.Trim() != "" || this.txtMySqlServer.Text.Trim() != "" || this.txtMySqlUser.Text.Trim() != "" || this.txtMySqlPwd.Text.Trim() != "" || this.txtMySqlPort.Text.Trim() != "")
  608. return false;
  609. else
  610. return true;
  611. }
  612. private bool CheckOracleControl()
  613. {
  614. if (this.txtOraclePort.Text.Trim() != "" || this.txtOraclePwd.Text.Trim() != "" || this.txtOracleHost.Text.Trim() != "" || this.txtOracleSource.Text.Trim() != "" || this.txtOracleUserId.Text.Trim() != "")
  615. return false;
  616. else
  617. return true;
  618. }
  619. private bool CheckFoxproControl()
  620. {
  621. if (this.txtFoxProFolder.Text.Trim() != "" || this.txtFoxProUserId.Text.Trim() != "" || this.txtFoxProPwd.Text.Trim() != "" || this.txtRemoteFoxProUserId.Text.Trim() != "" || this.txtRemoteFoxProPwd.Text.Trim() != "")
  622. {
  623. return false;
  624. }
  625. else
  626. return true;
  627. }
  628. private bool CheckTxtControl()
  629. {
  630. if (this.txtInportTxt.Text.Trim() != "" || this.txtRemoteTxtUserId.Text.Trim() != "" || this.txtRemoteTxtPwd.Text.Trim() != "")
  631. return false;
  632. else
  633. return true;
  634. }
  635. private void btnCNASTestLink_Click(object sender, EventArgs e)
  636. {
  637. //this.txtDBHost.Text.Trim(), this.txtDBName.Text.Trim(), this.txtDBUser.Text.Trim(), this.txtDBPwd.Text.Trim(),this.txtPort.Text.Trim()
  638. if (CnasDataOperationFact.CnasDataOperation().TestConnect(new DataBaseInfo()
  639. {
  640. DBHost = this.txtDBHost.Text.Trim(),
  641. DBName = this.txtDBName.Text.Trim(),
  642. DBUser = this.txtDBUser.Text.Trim(),
  643. DBPwd = this.txtDBPwd.Text.Trim(),
  644. DBPort = this.txtPort.Text.Trim()
  645. }))
  646. MessageBox.Show("连接成功!");
  647. else
  648. MessageBox.Show("连接失败!");
  649. }
  650. private void ClearExcelControl()
  651. {
  652. this.txtInportExcel.Text = "";
  653. this.txtRemoteExcelUser.Text = "";
  654. this.txtRemoteExcelPwd.Text = "";
  655. }
  656. private void ClearAccessControl()
  657. {
  658. this.txtAccessPath.Text = "";
  659. this.txtAccessUser.Text = "";
  660. this.txtAceessPwd.Text = "";
  661. this.txtAccessRemoteUser.Text = "";
  662. this.txtAccessRemotePwd.Text = "";
  663. }
  664. private void ClearSqliteControl()
  665. {
  666. this.txtSqliteUser.Text = "";
  667. this.txtSqlitePath.Text = "";
  668. this.txtSqlitePwd.Text = "";
  669. this.txtSqliteRemoteUser.Text = "";
  670. this.txtSqliteRemotePwd.Text = "";
  671. }
  672. private void ClearSQLServerControl()
  673. {
  674. this.txtSqlServerHost.Text = "";
  675. this.txtSqlServerName.Text = "";
  676. this.txtSqlServerUser.Text = "";
  677. this.txtSqlServerPwd.Text = "";
  678. }
  679. private void ClearMySQLControl()
  680. {
  681. this.txtMySqlHost.Text = "";
  682. this.txtMySqlServer.Text = "";
  683. this.txtMySqlUser.Text = "";
  684. this.txtMySqlPwd.Text = "";
  685. this.txtMySqlPort.Text = "";
  686. }
  687. private void ClearOracleControl()
  688. {
  689. this.txtOracleHost.Text = "";
  690. this.txtOracleSource.Text = "";
  691. this.txtOracleUserId.Text = "";
  692. this.txtOraclePwd.Text = "";
  693. this.txtOraclePort.Text = "";
  694. }
  695. private void ClearFoxproControl()
  696. {
  697. this.txtFoxProFolder.Text = "";
  698. this.txtFoxProUserId.Text = "";
  699. this.txtFoxProPwd.Text = "";
  700. this.txtRemoteFoxProUserId.Text = "";
  701. this.txtRemoteFoxProPwd.Text = "";
  702. }
  703. private void ClearTxtControl()
  704. {
  705. this.txtInportTxt.Text = "";
  706. this.txtRemoteTxtUserId.Text = "";
  707. this.txtRemoteTxtPwd.Text = "";
  708. }
  709. /// <summary>
  710. /// 清空对象中存储的值
  711. /// </summary>
  712. private void ClearObjectValue()
  713. {
  714. syncInstrumentItem.SyncInstrumentDSInfo.Host = "";
  715. syncInstrumentItem.SyncInstrumentDSInfo.ServerName = "";
  716. syncInstrumentItem.SyncInstrumentDSInfo.Path = "";
  717. syncInstrumentItem.SyncInstrumentDSInfo.UserId = "";
  718. syncInstrumentItem.SyncInstrumentDSInfo.UserPwd = "";
  719. syncInstrumentItem.SyncInstrumentDSInfo.Port = "";
  720. syncInstrumentItem.SyncInstrumentDSInfo.DsPathType = PathType.Local;
  721. syncInstrumentItem.SyncInstrumentDSInfo.RemoteUser = "";
  722. syncInstrumentItem.SyncInstrumentDSInfo.RemotePwd = "";
  723. }
  724. private void btnOpenFileAccess_Click(object sender, EventArgs e)
  725. {
  726. if (syncInstrumentItem.Code == null) return;
  727. if (syncInstrumentItem.SyncInstrumentDSInfo == null)
  728. syncInstrumentItem.SyncInstrumentDSInfo = new InstrumentDataSourceInfo();
  729. syncInstrumentItem.SyncInstrumentDSInfo.InstrumentDataSourceType = DataSourceType.Access;
  730. if (strReadAccessMode == "0")
  731. {
  732. OpenFileDialog openFile = new OpenFileDialog
  733. {
  734. Filter = "Microsoft Access(*.mdb)|*.mdb|Microsoft Access(*.accdb)|*.accdb",
  735. InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
  736. Multiselect = false
  737. };
  738. if (openFile.ShowDialog() == DialogResult.Cancel) return;
  739. this.txtAccessPath.Text = syncInstrumentItem.SyncInstrumentDSInfo.Path = openFile.FileName;
  740. string fileType = System.IO.Path.GetExtension(openFile.FileName);
  741. if (string.IsNullOrEmpty(fileType)) return;
  742. }
  743. else
  744. {
  745. FolderBrowserDialog dialog = new FolderBrowserDialog();
  746. dialog.Description = "请选择文件路径";
  747. if (dialog.ShowDialog() == DialogResult.Cancel) return;
  748. this.txtAccessPath.Text = syncInstrumentItem.SyncInstrumentDSInfo.Path = dialog.SelectedPath;
  749. }
  750. }
  751. private void btnOpenFileSQLite_Click(object sender, EventArgs e)
  752. {
  753. if (syncInstrumentItem.Code == null) return;
  754. if (syncInstrumentItem.SyncInstrumentDSInfo == null)
  755. syncInstrumentItem.SyncInstrumentDSInfo = new InstrumentDataSourceInfo();
  756. syncInstrumentItem.SyncInstrumentDSInfo.InstrumentDataSourceType = DataSourceType.SQLLite;
  757. if (strReadSqliteMode == "0")
  758. {
  759. OpenFileDialog openFile = new OpenFileDialog
  760. {
  761. Filter = "SQLite(*.db)|*.db",
  762. InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
  763. Multiselect = false
  764. };
  765. if (openFile.ShowDialog() == DialogResult.Cancel) return;
  766. this.txtSqlitePath.Text = syncInstrumentItem.SyncInstrumentDSInfo.Path = openFile.FileName;
  767. string fileType = System.IO.Path.GetExtension(openFile.FileName);
  768. if (string.IsNullOrEmpty(fileType)) return;
  769. }
  770. else
  771. {
  772. FolderBrowserDialog dialog = new FolderBrowserDialog();
  773. dialog.Description = "请选择文件路径";
  774. if (dialog.ShowDialog() == DialogResult.Cancel) return;
  775. this.txtSqlitePath.Text = syncInstrumentItem.SyncInstrumentDSInfo.Path = dialog.SelectedPath;
  776. }
  777. }
  778. private void btnTestSQLLink_Click(object sender, EventArgs e)
  779. {
  780. if (this.txtSqlServerHost.Text.Trim() == "" || this.txtSqlServerName.Text.Trim() == "" || this.txtSqlServerUser.Text.Trim() == "")
  781. {
  782. MessageBox.Show("请填写相关连接信息。");
  783. return;
  784. }
  785. InstrumentDataSourceInfo dbinfo = new InstrumentDataSourceInfo();
  786. dbinfo.Host = this.txtSqlServerHost.Text.Trim();
  787. dbinfo.ServerName = this.txtSqlServerName.Text.Trim();
  788. dbinfo.UserId = this.txtSqlServerUser.Text.Trim();
  789. dbinfo.UserPwd = this.txtSqlServerPwd.Text.Trim();
  790. dbinfo.Port = this.txtSqlServerPort.Text.Trim();
  791. if (new SQLServerInstrumentData(dbinfo, new object[] {
  792. "",
  793. "",
  794. ""
  795. }).TestSQLServerLink())
  796. MessageBox.Show("连接成功!");
  797. else
  798. MessageBox.Show("连接失败!");
  799. }
  800. private void cbxExcelRemote_CheckedChanged(object sender, EventArgs e)
  801. {
  802. if (!cbxExcelRemote.Checked)
  803. {
  804. this.btnOpenFileExcel.Visible = true;
  805. lblExcelRemotePwd.Visible = false;
  806. lblExcelRemoteUser.Visible = false;
  807. txtRemoteExcelUser.Visible = false;
  808. txtRemoteExcelPwd.Visible = false;
  809. }
  810. else
  811. {
  812. this.btnOpenFileExcel.Visible = false;
  813. lblExcelRemotePwd.Visible = true;
  814. lblExcelRemoteUser.Visible = true;
  815. txtRemoteExcelUser.Visible = true;
  816. txtRemoteExcelPwd.Visible = true;
  817. }
  818. }
  819. private void cbxAccessRemote_CheckedChanged(object sender, EventArgs e)
  820. {
  821. if (cbxAccessRemote.Checked)
  822. {
  823. btnOpenFileAccess.Visible = false;
  824. lblAccessRemoteUser.Visible = true;
  825. lblAccessRemotePwd.Visible = true;
  826. txtAccessRemoteUser.Visible = true;
  827. txtAccessRemotePwd.Visible = true;
  828. }
  829. else
  830. {
  831. btnOpenFileAccess.Visible = true;
  832. lblAccessRemoteUser.Visible = false;
  833. lblAccessRemotePwd.Visible = false;
  834. txtAccessRemoteUser.Visible = false;
  835. txtAccessRemotePwd.Visible = false;
  836. }
  837. }
  838. private void cbxSqliteRemote_CheckedChanged(object sender, EventArgs e)
  839. {
  840. if (cbxSqliteRemote.Checked)
  841. {
  842. btnOpenFileSQLite.Visible = false;
  843. lblSqliteRemoteUser.Visible = true;
  844. lblSqliteRemotePwd.Visible = true;
  845. txtSqliteRemoteUser.Visible = true;
  846. txtSqliteRemotePwd.Visible = true;
  847. }
  848. else
  849. {
  850. btnOpenFileSQLite.Visible = true;
  851. lblSqliteRemoteUser.Visible = false;
  852. lblSqliteRemotePwd.Visible = false;
  853. txtSqliteRemoteUser.Visible = false;
  854. txtSqliteRemotePwd.Visible = false;
  855. }
  856. }
  857. private void btnMySqlTest_Click(object sender, EventArgs e)
  858. {
  859. if (CnasDataOperationFact.CnasDataOperation().TestConnect(new DataBaseInfo()
  860. {
  861. DBHost = this.txtMySqlHost.Text.Trim(),
  862. DBName = this.txtMySqlServer.Text.Trim(),
  863. DBUser = this.txtMySqlUser.Text.Trim(),
  864. DBPwd = this.txtMySqlPwd.Text.Trim(),
  865. DBPort = this.txtMySqlPort.Text.Trim()
  866. }))
  867. MessageBox.Show("连接成功!");
  868. else
  869. MessageBox.Show("连接失败!");
  870. }
  871. private void btnOracleTestLink_Click(object sender, EventArgs e)
  872. {
  873. if (this.txtOracleHost.Text.Trim() == "" || this.txtOracleSource.Text.Trim() == "" || this.txtOracleUserId.Text.Trim() == "" || this.txtOraclePort.Text.Trim() == "")
  874. {
  875. MessageBox.Show("请填写相关连接信息。");
  876. return;
  877. }
  878. InstrumentDataSourceInfo dbinfo = new InstrumentDataSourceInfo();
  879. dbinfo.Host = this.txtOracleHost.Text.Trim();
  880. dbinfo.ServerName = this.txtOracleSource.Text.Trim();
  881. dbinfo.UserId = this.txtOracleUserId.Text.Trim();
  882. dbinfo.UserPwd = this.txtOraclePwd.Text.Trim();
  883. dbinfo.Port = this.txtOraclePort.Text.Trim();
  884. if (new OracleInstrumentData(dbinfo, new object[] {
  885. "",
  886. "",
  887. ""
  888. }).TestSQLServerLink())
  889. MessageBox.Show("连接成功!");
  890. else
  891. MessageBox.Show("连接失败!");
  892. }
  893. private void txtFileOpenFoxPro_Click(object sender, EventArgs e)
  894. {
  895. if (syncInstrumentItem.Code == null) return;
  896. if (syncInstrumentItem.SyncInstrumentDSInfo == null)
  897. syncInstrumentItem.SyncInstrumentDSInfo = new InstrumentDataSourceInfo();
  898. syncInstrumentItem.SyncInstrumentDSInfo.InstrumentDataSourceType = DataSourceType.FoxPro;
  899. if (strReadFoxproMode == "0")
  900. {
  901. OpenFileDialog openFile = new OpenFileDialog
  902. {
  903. Filter = "Foxpro文件(*.dbf)|*.dbf",
  904. InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
  905. Multiselect = false
  906. };
  907. if (openFile.ShowDialog() == DialogResult.Cancel) return;
  908. this.txtFoxProFolder.Text = syncInstrumentItem.SyncInstrumentDSInfo.Path = openFile.FileName;
  909. string fileType = System.IO.Path.GetExtension(openFile.FileName);
  910. if (string.IsNullOrEmpty(fileType)) return;
  911. }
  912. else
  913. {
  914. FolderBrowserDialog dialog = new FolderBrowserDialog();
  915. dialog.Description = "请选择文件路径";
  916. if (dialog.ShowDialog() == DialogResult.Cancel) return;
  917. this.txtFoxProFolder.Text = syncInstrumentItem.SyncInstrumentDSInfo.Path = dialog.SelectedPath;
  918. }
  919. }
  920. private void cbxFoxProRemote_CheckedChanged(object sender, EventArgs e)
  921. {
  922. if (!cbxFoxProRemote.Checked)
  923. {
  924. this.btnFileOpenFoxPro.Visible = true;
  925. lblFoxproRemoteUserId.Visible = false;
  926. lblFoxproRemotePwd.Visible = false;
  927. txtRemoteFoxProUserId.Visible = false;
  928. txtRemoteFoxProPwd.Visible = false;
  929. }
  930. else
  931. {
  932. this.btnFileOpenFoxPro.Visible = false;
  933. lblFoxproRemoteUserId.Visible = true;
  934. lblFoxproRemotePwd.Visible = true;
  935. txtRemoteFoxProUserId.Visible = true;
  936. txtRemoteFoxProPwd.Visible = true;
  937. }
  938. }
  939. private void btnOpenFileTxt_Click(object sender, EventArgs e)
  940. {
  941. if (syncInstrumentItem.Code == null) return;
  942. if (syncInstrumentItem.SyncInstrumentDSInfo == null)
  943. syncInstrumentItem.SyncInstrumentDSInfo = new InstrumentDataSourceInfo();
  944. syncInstrumentItem.SyncInstrumentDSInfo.InstrumentDataSourceType = DataSourceType.TXT;
  945. if (strReadTxtMode == "0")
  946. {
  947. OpenFileDialog openFile = new OpenFileDialog
  948. {
  949. Filter = "文本文件(*.txt)|*.txt|所有文件(*.*)|*.*",
  950. InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
  951. Multiselect = false
  952. };
  953. if (openFile.ShowDialog() == DialogResult.Cancel) return;
  954. this.txtInportTxt.Text = syncInstrumentItem.SyncInstrumentDSInfo.Path = openFile.FileName;
  955. string fileType = System.IO.Path.GetExtension(openFile.FileName);
  956. if (string.IsNullOrEmpty(fileType)) return;
  957. }
  958. else
  959. {
  960. FolderBrowserDialog dialog = new FolderBrowserDialog();
  961. dialog.Description = "请选择文件路径";
  962. if (dialog.ShowDialog() == DialogResult.Cancel) return;
  963. this.txtInportTxt.Text = syncInstrumentItem.SyncInstrumentDSInfo.Path = dialog.SelectedPath;
  964. }
  965. }
  966. private void cbxRemoteTxt_CheckedChanged(object sender, EventArgs e)
  967. {
  968. if (!cbxRemoteTxt.Checked)
  969. {
  970. this.btnOpenFileTxt.Visible = true;
  971. lblTxtRemoteUserId.Visible = false;
  972. lblTxtRemoteUserPwd.Visible = false;
  973. txtRemoteTxtUserId.Visible = false;
  974. txtRemoteTxtPwd.Visible = false;
  975. }
  976. else
  977. {
  978. this.btnOpenFileTxt.Visible = false;
  979. lblTxtRemoteUserId.Visible = true;
  980. lblTxtRemoteUserPwd.Visible = true;
  981. txtRemoteTxtUserId.Visible = true;
  982. txtRemoteTxtPwd.Visible = true;
  983. }
  984. }
  985. private void cbxTargetDBSelect_SelectedIndexChanged(object sender, EventArgs e)
  986. {
  987. if (cbxTargetDBSelect.SelectedIndex == 0)
  988. {
  989. if (GlobalCommonOperation.strStartWebApi == "1")
  990. {
  991. targetDataBaseInfo = new DataBaseInfo()
  992. {
  993. DataBaseCode = "cnas"
  994. };
  995. }
  996. else
  997. {
  998. DataBaseInfo CNASDataBase = FileOperation.GetLocalCnasDB();
  999. if (CNASDataBase != null)
  1000. {
  1001. this.txtDBHost.Text = CNASDataBase.DBHost;
  1002. this.txtDBName.Text = CNASDataBase.DBName;
  1003. this.txtDBUser.Text = CNASDataBase.DBUser;
  1004. this.txtDBPwd.Text = CNASDataBase.DBPwd;
  1005. this.txtPort.Text = CNASDataBase.DBPort;
  1006. }
  1007. }
  1008. }
  1009. else if (cbxTargetDBSelect.SelectedIndex == 1)
  1010. {
  1011. if (GlobalCommonOperation.strStartWebApi == "1")
  1012. {
  1013. targetDataBaseInfo = new DataBaseInfo()
  1014. {
  1015. DataBaseCode = "platform"
  1016. };
  1017. }
  1018. else
  1019. {
  1020. DataBaseInfo PlatDataBase = FileOperation.GetLocalPlatFormDB();
  1021. if (PlatDataBase != null)
  1022. {
  1023. this.txtDBHost.Text = PlatDataBase.DBHost;
  1024. this.txtDBName.Text = PlatDataBase.DBName;
  1025. this.txtDBUser.Text = PlatDataBase.DBUser;
  1026. this.txtDBPwd.Text = PlatDataBase.DBPwd;
  1027. this.txtPort.Text = PlatDataBase.DBPort;
  1028. }
  1029. }
  1030. }
  1031. }
  1032. private bool CheckPostgreSqlControl()
  1033. {
  1034. if (this.txtPostgreSqlHost.Text.Trim() != "" || this.txtPostgreSqlServer.Text.Trim() != "" ||
  1035. this.txtPostgreSqlUser.Text.Trim() != "" || this.txtPostgreSqlPwd.Text.Trim() != "" ||
  1036. this.txtPostgreSqlPort.Text.Trim() != "")
  1037. return false;
  1038. else
  1039. return true;
  1040. }
  1041. private void ClearPostgreSqlControl()
  1042. {
  1043. this.txtPostgreSqlHost.Text = "";
  1044. this.txtPostgreSqlServer.Text = "";
  1045. this.txtPostgreSqlUser.Text = "";
  1046. this.txtPostgreSqlPwd.Text = "";
  1047. this.txtPostgreSqlPort.Text = "";
  1048. }
  1049. private bool CheckKingbaseControl()
  1050. {
  1051. if (this.txtKingbaselHost.Text.Trim() != "" || this.txtKingbaselServer.Text.Trim() != "" ||
  1052. this.txtKingbaselUser.Text.Trim() != "" || this.txtKingbaselPwd.Text.Trim() != "" ||
  1053. this.txtKingbaselPort.Text.Trim() != "")
  1054. return false;
  1055. else
  1056. return true;
  1057. }
  1058. private void ClearKingbaseControl()
  1059. {
  1060. this.txtKingbaselHost.Text = "";
  1061. this.txtKingbaselServer.Text = "";
  1062. this.txtKingbaselUser.Text = "";
  1063. this.txtKingbaselPwd.Text = "";
  1064. this.txtKingbaselPort.Text = "";
  1065. }
  1066. private void btnKingbaselConn_Click(object sender, EventArgs e)
  1067. {
  1068. if (this.txtKingbaselHost.Text.Trim() == "" || this.txtKingbaselServer.Text.Trim() == "" ||
  1069. this.txtKingbaselUser.Text.Trim() == "" || this.txtKingbaselPort.Text.Trim() == "")
  1070. {
  1071. MessageBox.Show("请填写相关连接信息。");
  1072. return;
  1073. }
  1074. InstrumentDataSourceInfo dbinfo = new InstrumentDataSourceInfo();
  1075. dbinfo.Host = this.txtKingbaselHost.Text.Trim();
  1076. dbinfo.ServerName = this.txtKingbaselServer.Text.Trim();
  1077. dbinfo.UserId = this.txtKingbaselUser.Text.Trim();
  1078. dbinfo.UserPwd = this.txtKingbaselPwd.Text.Trim();
  1079. dbinfo.Port = this.txtKingbaselPort.Text.Trim();
  1080. // 假设有KingbaseInstrumentData类来处理连接测试
  1081. if (new KingbaseInstrumentData(dbinfo, new object[] { "", "", "" }).TestConnection())
  1082. MessageBox.Show("连接成功!");
  1083. else
  1084. MessageBox.Show("连接失败!");
  1085. }
  1086. private void btnPostgreSqlConn_Click(object sender, EventArgs e)
  1087. {
  1088. if (this.txtPostgreSqlHost.Text.Trim() == "" || this.txtPostgreSqlServer.Text.Trim() == "" ||
  1089. this.txtPostgreSqlUser.Text.Trim() == "" || this.txtPostgreSqlPort.Text.Trim() == "")
  1090. {
  1091. MessageBox.Show("请填写相关连接信息。");
  1092. return;
  1093. }
  1094. InstrumentDataSourceInfo dbinfo = new InstrumentDataSourceInfo();
  1095. dbinfo.Host = this.txtPostgreSqlHost.Text.Trim();
  1096. dbinfo.ServerName = this.txtPostgreSqlServer.Text.Trim();
  1097. dbinfo.UserId = this.txtPostgreSqlUser.Text.Trim();
  1098. dbinfo.UserPwd = this.txtPostgreSqlPwd.Text.Trim();
  1099. dbinfo.Port = this.txtPostgreSqlPort.Text.Trim();
  1100. //SQLServerInstrumentData
  1101. if (new PostgreSQLServerInstrumentData(dbinfo, new object[] {
  1102. "",
  1103. "",
  1104. ""
  1105. }).TestSQLServerLink())
  1106. MessageBox.Show("连接成功!");
  1107. else
  1108. MessageBox.Show("连接失败!");
  1109. //if (new PostgreSQLServerInstrumentData(dbinfo, new object[] { "", "", "" }).TestConnection())
  1110. // MessageBox.Show("连接成功!");
  1111. //else
  1112. // MessageBox.Show("连接失败!");
  1113. //if (this.txtSqlServerHost.Text.Trim() == "" || this.txtSqlServerName.Text.Trim() == "" || this.txtSqlServerUser.Text.Trim() == "")
  1114. //{
  1115. // MessageBox.Show("请填写相关连接信息。");
  1116. // return;
  1117. //}
  1118. //InstrumentDataSourceInfo dbinfo = new InstrumentDataSourceInfo();
  1119. //dbinfo.Host = this.txtSqlServerHost.Text.Trim();
  1120. //dbinfo.ServerName = this.txtSqlServerName.Text.Trim();
  1121. //dbinfo.UserId = this.txtSqlServerUser.Text.Trim();
  1122. //dbinfo.UserPwd = this.txtSqlServerPwd.Text.Trim();
  1123. //dbinfo.Port = this.txtSqlServerPort.Text.Trim();
  1124. //if (new SQLServerInstrumentData(dbinfo, new object[] {
  1125. // "",
  1126. // "",
  1127. // ""
  1128. //}).TestSQLServerLink())
  1129. // MessageBox.Show("连接成功!");
  1130. //else
  1131. // MessageBox.Show("连接失败!");
  1132. }
  1133. }
  1134. }