CNAS取数仪器端升级
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

frmDatabaseParams.cs 54KB

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