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.

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