CNAS取数仪器端升级
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

1160 行
50KB

  1. using CnasSynchronousCommon;
  2. using CnasSynchronusClient;
  3. using CnasSynchrousModel;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.ComponentModel;
  7. using System.Data;
  8. using System.Drawing;
  9. using System.IO;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Text.RegularExpressions;
  13. using System.Windows.Forms;
  14. using System.Xml.Linq;
  15. using System.Xml.Serialization;
  16. using static System.Runtime.CompilerServices.RuntimeHelpers;
  17. namespace CNAS_DBSync
  18. {
  19. public delegate void ReferenceChangeSyncParamHanlder(SyncInstrumentItemInfo syncInstrumentItem);
  20. public partial class frmSyncParams : Form
  21. {
  22. public List<SyncInstrumentItemInfo> lstSyncInstrument = new List<SyncInstrumentItemInfo>(); //本地存储的仪器数据源
  23. public SyncInstrumentItemInfo currentSyncItem = new SyncInstrumentItemInfo(); //当前正在操作的仪器项
  24. public Dictionary<string, DataTable> dictInstruTables = new Dictionary<string, DataTable>(); //当前仪器项的来源表结构
  25. private SyncInstrumentItemInfo syncInstrumentItem; //其他调用传递的仪器项
  26. public ReferenceChangeSyncParamHanlder ParamsChangedDelegate; //传递仪器参数委托
  27. private bool isLocked = false; // Track lock state
  28. private string strMode = "";
  29. private string strTableInfoMode = ""; //获取所有表信息的方式;0为自动获取,1为手动输入
  30. public frmSyncParams(SyncInstrumentItemInfo syncInstrumentItem = null)
  31. {
  32. InitializeComponent();
  33. dgvInstrument.AutoGenerateColumns = false;
  34. dgvInstrument.RowHeadersVisible = false;
  35. dgvInstruDS.AutoGenerateColumns = false;
  36. dgvInstruDS.RowHeadersVisible = false;
  37. dgvCnas.AutoGenerateColumns = false;
  38. dgvCnas.RowHeadersVisible = false;
  39. dgvMapping.AutoGenerateColumns = false;
  40. dgvMapping.RowHeadersVisible = false;
  41. if (syncInstrumentItem != null)
  42. {
  43. strMode = "Reference";
  44. this.syncInstrumentItem = syncInstrumentItem;
  45. this.btnAdd.Visible = false;
  46. this.btnDel.Visible = false;
  47. }
  48. if (LockStateOperation.GetLockState())
  49. {
  50. isLocked = true;
  51. btnLock.Text = "解锁";
  52. btnAdd.Enabled = false;
  53. btnDel.Enabled = false;
  54. }
  55. }
  56. private void btnLock_Click(object sender, EventArgs e)
  57. {
  58. if (isLocked)
  59. {
  60. // Try to unlock
  61. if (new frmLockPwd(false).ShowDialog() == DialogResult.OK)
  62. {
  63. isLocked = false;
  64. btnLock.Text = "锁定";
  65. btnAdd.Enabled = true;
  66. btnDel.Enabled = true;
  67. }
  68. }
  69. else
  70. {
  71. // Try to lock
  72. if (new frmLockPwd(true).ShowDialog() == DialogResult.OK)
  73. {
  74. isLocked = true;
  75. btnLock.Text = "解锁";
  76. btnAdd.Enabled = false;
  77. btnDel.Enabled = false;
  78. }
  79. }
  80. }
  81. private void Option1_Click(object sender, EventArgs e)
  82. {
  83. string strInstrumentCode = this.dgvInstrument.Rows[this.dgvInstrument.CurrentRow.Index].Cells[0].Value.ToString();
  84. frmSystemSetting frmSetting = new frmSystemSetting(lstSyncInstrument, strInstrumentCode);
  85. frmSetting.InstrumentDelegate = delegate (SyncInstrumentItemInfo Instrumentitem)
  86. {
  87. var lstInstrument = lstSyncInstrument.Where(s => s.Code == strInstrumentCode).ToList<SyncInstrumentItemInfo>();
  88. if (lstInstrument.Count == 1)
  89. {
  90. lstInstrument[0].Code = Instrumentitem.Code;
  91. lstInstrument[0].InstruType = Instrumentitem.InstruType;
  92. }
  93. };
  94. if (frmSetting.ShowDialog() == DialogResult.OK)
  95. {
  96. //绑定数据
  97. dgvInstrument.DataSource = new BindingList<SyncInstrumentItemInfo>(lstSyncInstrument);
  98. }
  99. //frmSetting.ShowDialog();
  100. }
  101. private void Option2_Click(object sender, EventArgs e)
  102. {
  103. // 处理选项2的点击事件
  104. MessageBox.Show("选项2被点击");
  105. }
  106. private void frmSyncParams_Load(object sender, EventArgs e)
  107. {
  108. if (syncInstrumentItem == null)
  109. {
  110. lstSyncInstrument = FileOperation.GetLocalSyncInStrumentData();
  111. }
  112. else
  113. {
  114. lstSyncInstrument = new List<SyncInstrumentItemInfo>() { syncInstrumentItem };
  115. }
  116. //绑定数据源,填写相关内容
  117. if (lstSyncInstrument.Count != 0)
  118. dgvInstrument.DataSource = new BindingList<SyncInstrumentItemInfo>(lstSyncInstrument);
  119. }
  120. /// <summary>
  121. /// 保存当前设置到本地
  122. /// </summary>
  123. /// <param name="sender"></param>
  124. /// <param name="e"></param>
  125. private void btnSave_Click(object sender, EventArgs e)
  126. {
  127. //将配置好的信息存储到本地文件中
  128. try
  129. {
  130. bool bIfSaveSuccess = true;
  131. if (strMode == "Reference")
  132. {
  133. if (!CheckIfHaveDateField(new List<SyncInstrumentItemInfo>() { currentSyncItem }))
  134. {
  135. MessageBox.Show("日期字段不允许为空!");
  136. return;
  137. }
  138. if (!CheckIfHaveKeyPrimaryField(lstSyncInstrument))
  139. {
  140. MessageBox.Show("关键字段不允许为空!");
  141. return;
  142. }
  143. //1.先加载所有数据 2.替换当前数据 3.重新保存
  144. List<SyncInstrumentItemInfo> lstDB = FileOperation.GetLocalSyncInStrumentData();
  145. var item = lstDB.Where(p => p.GUID == currentSyncItem.GUID).SingleOrDefault();
  146. if (item != null)
  147. {
  148. lstDB.Remove(item);
  149. lstDB.Add(currentSyncItem);
  150. }
  151. else
  152. {
  153. lstDB.Add(currentSyncItem);
  154. }
  155. //重新保存信息
  156. bIfSaveSuccess = FileOperation.SaveLocalSyncInStrumentData(lstDB);
  157. //委托发送参数
  158. this.ParamsChangedDelegate(syncInstrumentItem);
  159. }
  160. else
  161. {
  162. if (!CheckIfHaveDateField(lstSyncInstrument))
  163. {
  164. MessageBox.Show("日期字段不允许为空!");
  165. return;
  166. }
  167. if (!CheckIfHaveKeyPrimaryField(lstSyncInstrument))
  168. {
  169. MessageBox.Show("关键字段不允许为空!");
  170. return;
  171. }
  172. bIfSaveSuccess = FileOperation.SaveLocalSyncInStrumentData(lstSyncInstrument);
  173. }
  174. if (bIfSaveSuccess)
  175. MessageBox.Show("保存成功!");
  176. else
  177. MessageBox.Show("保存失败!");
  178. }
  179. catch (Exception ex)
  180. {
  181. MessageBox.Show("保存失败!错误信息为:" + ex.Message.ToString());
  182. AppLog.Error(ex.Message);
  183. }
  184. }
  185. private bool CheckIfHaveDateField(List<SyncInstrumentItemInfo> lstSyncInstrument)
  186. {
  187. bool bIfHave = true;
  188. foreach (var item in lstSyncInstrument)
  189. {
  190. if (item.LstSyncPramas == null) continue;
  191. if (item.LstSyncPramas.Count <= 0) continue;
  192. if (item.LstSyncPramas.Where(s => s.IfDateField == true).Count() != 1)
  193. {
  194. bIfHave = false;
  195. break;
  196. }
  197. }
  198. return bIfHave;
  199. }
  200. private bool CheckIfHaveKeyPrimaryField(List<SyncInstrumentItemInfo> lstSyncInstrument)
  201. {
  202. bool bIfHave = true;
  203. foreach (var item in lstSyncInstrument)
  204. {
  205. if (item.LstSyncPramas == null) continue;
  206. if (item.LstSyncPramas.Count <= 0) continue;
  207. if (item.LstSyncPramas.Where(s => s.IfPrimaryKey == true).Count() <= 0)
  208. {
  209. bIfHave = false;
  210. break;
  211. }
  212. }
  213. return bIfHave;
  214. }
  215. /// <summary>
  216. /// 新增仪器
  217. /// </summary>
  218. /// <param name="sender"></param>
  219. /// <param name="e"></param>
  220. private void btnAdd_Click(object sender, EventArgs e)
  221. {
  222. frmSystemSetting frmSetting = new frmSystemSetting(lstSyncInstrument);
  223. frmInstrumentCode frmCode = new frmInstrumentCode(lstSyncInstrument);
  224. frmSetting.InstrumentDelegate = delegate (SyncInstrumentItemInfo Instrumentitem)
  225. {
  226. lstSyncInstrument.Add(Instrumentitem);
  227. //绑定数据
  228. dgvInstrument.DataSource = new BindingList<SyncInstrumentItemInfo>(lstSyncInstrument);
  229. dgvInstrument.CurrentCell = dgvInstrument.Rows[dgvInstrument.Rows.Count - 1].Cells[0];
  230. dgvInstrument_SelectionChanged(null, null);
  231. };
  232. frmSetting.ShowDialog();
  233. }
  234. /// <summary>
  235. /// 删除仪器
  236. /// </summary>
  237. /// <param name="sender"></param>
  238. /// <param name="e"></param>
  239. private void btnDel_Click(object sender, EventArgs e)
  240. {
  241. if (dgvInstrument.Rows.Count <= 0) return;
  242. //当前选中行
  243. string strInstrumentCode = this.dgvInstrument.Rows[this.dgvInstrument.CurrentRow.Index].Cells[0].Value.ToString();
  244. //找到数据源中数据,删除
  245. var lstitem = lstSyncInstrument.Where(s => s.Code == strInstrumentCode).ToList<SyncInstrumentItemInfo>();
  246. if (lstitem == null)
  247. return;
  248. else if (lstitem.Count >= 1)
  249. {
  250. foreach (var item in lstitem)
  251. {
  252. lstSyncInstrument.Remove(item);
  253. }
  254. }
  255. //绑定数据
  256. dgvInstrument.DataSource = new BindingList<SyncInstrumentItemInfo>();
  257. dgvInstrument.DataSource = new BindingList<SyncInstrumentItemInfo>(lstSyncInstrument);
  258. //dgvInstrument.dgvInstrument_SelectionChanged()
  259. if (lstSyncInstrument.Count > 0)
  260. dgvInstrument_SelectionChanged(null, null);
  261. else
  262. {
  263. currentSyncItem = new SyncInstrumentItemInfo();
  264. dictInstruTables.Clear();
  265. cbxCnas.DataSource = null;
  266. cbxCnas.Items.Clear();
  267. cbxInstrument.DataSource = null;
  268. dgvInstruDS.DataSource = null;
  269. dgvCnas.DataSource = null;
  270. dgvMapping.DataSource = new BindingList<SyncParamasInfo>();
  271. }
  272. }
  273. private void dgvInstrument_SelectionChanged(object sender, EventArgs e)
  274. {
  275. if (dgvInstrument.Rows.Count <= 0 || dgvInstrument.Rows[dgvInstrument.CurrentRow.Index].Cells[0].Value == null)
  276. {
  277. currentSyncItem = new SyncInstrumentItemInfo();
  278. return;
  279. }
  280. //清空绑定
  281. cbxCnas.DataSource = null;
  282. cbxInstrument.DataSource = null;
  283. dgvInstruDS.DataSource = null;
  284. dgvCnas.DataSource = null;
  285. //当前选中单元格
  286. string strInstrumentCode = this.dgvInstrument.Rows[this.dgvInstrument.CurrentRow.Index].Cells[0].Value.ToString();
  287. var lstInstrument = lstSyncInstrument.Where(s => s.Code == strInstrumentCode).ToList<SyncInstrumentItemInfo>();
  288. if (lstInstrument.Count == 1)
  289. {
  290. currentSyncItem = lstInstrument[0];
  291. if (!string.IsNullOrWhiteSpace(currentSyncItem.CnasInstrumentColumn))
  292. txtInstrumentColumn.Text = currentSyncItem.CnasInstrumentColumn;
  293. else
  294. txtInstrumentColumn.Text = "";
  295. if (currentSyncItem.SyncInstrumentDSInfo != null && currentSyncItem.SyncInstrumentDSInfo.InstrumentDataSourceType != DataSourceType.None)
  296. {
  297. switch (currentSyncItem.SyncInstrumentDSInfo.InstrumentDataSourceType)
  298. {
  299. case DataSourceType.MySQL:
  300. case DataSourceType.Dm:
  301. case DataSourceType.Oracle:
  302. case DataSourceType.PostgreSQL:
  303. case DataSourceType.SQL:
  304. case DataSourceType.Kingbase:
  305. if (currentSyncItem.LstSyncPramas != null)
  306. dgvMapping.DataSource = new BindingList<SyncParamasInfo>(currentSyncItem.LstSyncPramas);
  307. //if (currentSyncItem.SyncInstrumentDSInfo.ServerName != "")
  308. // btnLoadDBData_Click(sender, e);
  309. break;
  310. default:
  311. if (currentSyncItem.LstSyncPramas != null)
  312. dgvMapping.DataSource = new BindingList<SyncParamasInfo>(currentSyncItem.LstSyncPramas);
  313. // btnLoadDBData_Click(sender, e);
  314. break;
  315. }
  316. }
  317. else
  318. {
  319. dgvMapping.DataSource = new BindingList<SyncParamasInfo>();
  320. }
  321. }
  322. else
  323. {
  324. dgvMapping.DataSource = new BindingList<SyncParamasInfo>();
  325. }
  326. }
  327. /// <summary>
  328. /// 切换选中表时发生
  329. /// </summary>
  330. /// <param name="sender"></param>
  331. /// <param name="e"></param>
  332. private void cbxInstrument_SelectedIndexChanged(object sender, EventArgs e)
  333. {
  334. if (cbxInstrument.Text == null) return;
  335. string strInstrumentCode = this.dgvInstrument.Rows[this.dgvInstrument.CurrentRow.Index].Cells[0].Value.ToString();
  336. // 使用LINQ查找匹配的数据
  337. SyncInstrumentItemInfo matchedInstrument = lstSyncInstrument.FirstOrDefault(x => x.Code == strInstrumentCode);
  338. InstrumentData instrumentDatas = InstrumentDataFact.CreateInstrumentDataSource(currentSyncItem.SyncInstrumentDSInfo, new object[] { "", "", "" });
  339. DataTable dtTableType = null;
  340. string strTableName_Instru = cbxInstrument.Text.ToString();
  341. if (matchedInstrument.SyncInstrumentDSInfo != null)
  342. {
  343. switch (matchedInstrument.SyncInstrumentDSInfo.InstrumentDataSourceType)
  344. {
  345. case DataSourceType.MySQL:
  346. dtTableType = SelectTableType.MySqlsec(strTableName_Instru);
  347. break;
  348. case DataSourceType.Dm:
  349. dtTableType = SelectTableType.DmSql(strTableName_Instru);
  350. break;
  351. case DataSourceType.Oracle:
  352. dtTableType = SelectTableType.OrcSql(strTableName_Instru, currentSyncItem);
  353. break;
  354. case DataSourceType.PostgreSQL:
  355. dtTableType = SelectTableType.PostgreSql(strTableName_Instru);
  356. break;
  357. case DataSourceType.SQL:
  358. dtTableType = SelectTableType.Sqlserversec(strTableName_Instru, currentSyncItem);
  359. break;
  360. case DataSourceType.Kingbase:
  361. dtTableType = SelectTableType.KingSql(strTableName_Instru);
  362. break;
  363. default:
  364. strTableName_Instru = matchedInstrument.SyncInstrumentDSInfo.InstrumentDataSourceType.ToString();
  365. strTableName_Instru = currentSyncItem.SyncInstrumentDSInfo.InstrumentDataSourceType.ToString();
  366. InstrumentData instrumentData = InstrumentDataFact.CreateInstrumentDataSource(matchedInstrument.SyncInstrumentDSInfo, new object[] { "", "", "" });
  367. dictInstruTables = instrumentData.GetInstrumentData();
  368. dictInstruTables = instrumentDatas.GetInstrumentData();
  369. if (dictInstruTables.ContainsKey(strTableName_Instru))
  370. dtTableType = dictInstruTables[strTableName_Instru];
  371. if (dictInstruTables.ContainsKey(cbxInstrument.Text))
  372. dtTableType = dictInstruTables[cbxInstrument.Text];
  373. break;
  374. }
  375. DataTable dtInstruShow = new DataTable();
  376. dtInstruShow.Columns.Add("InstruFieldName");
  377. dtInstruShow.Columns.Add("InstruDataType");
  378. dtInstruShow.Columns.Add("remark");
  379. if (dtTableType != null)
  380. {
  381. switch (matchedInstrument.SyncInstrumentDSInfo.InstrumentDataSourceType)
  382. {
  383. case DataSourceType.MySQL:
  384. case DataSourceType.Dm:
  385. case DataSourceType.PostgreSQL:
  386. case DataSourceType.SQL:
  387. case DataSourceType.Kingbase:
  388. for (int i = 0; i < dtTableType.Rows.Count; i++)
  389. {
  390. dtInstruShow.Rows.Add(new object[] { dtTableType.Rows[i]["ColumnName"], dtTableType.Rows[i]["DataType"], dtTableType.Rows[i]["remark"] });
  391. }
  392. break;
  393. case DataSourceType.Oracle:
  394. strTableName_Instru = cbxInstrument.Text.ToString();
  395. if (dictInstruTables.ContainsKey(strTableName_Instru))
  396. {
  397. DataTable dt = dictInstruTables[strTableName_Instru];
  398. if (dt != null)
  399. {
  400. dtInstruShow = new DataTable();
  401. dtInstruShow.Columns.Add("InstruFieldName");
  402. dtInstruShow.Columns.Add("InstruDataType");
  403. foreach (DataColumn dc in dt.Columns)
  404. {
  405. dtInstruShow.Rows.Add(new object[] { dc.ColumnName, dc.DataType });
  406. }
  407. dgvInstruDS.DataSource = dtInstruShow;
  408. }
  409. }
  410. break;
  411. default:
  412. foreach (DataColumn dc in dtTableType.Columns)
  413. {
  414. dtInstruShow.Rows.Add(new object[] { dc.ColumnName, dc.DataType, "" });
  415. }
  416. break;
  417. }
  418. }
  419. dgvInstruDS.DataSource = dtInstruShow;
  420. }
  421. }
  422. /// <summary>
  423. /// 切换表时发生
  424. /// </summary>
  425. /// <param name="sender"></param>
  426. /// <param name="e"></param>
  427. private void cbxCnas_SelectedIndexChanged(object sender, EventArgs e)
  428. {
  429. if (cbxCnas.Text == null) return;
  430. string strTableName_Cnas = cbxCnas.Text.ToString();
  431. DataTable dtTableStruct = CnasDataOperationFact.CnasDataOperation().GetCNASTableTypeLenth(strTableName_Cnas, currentSyncItem.SyncTargetDBInfo);
  432. //从数据库中加载数据表结构
  433. //DataTable dtTableStruct = CnasDataOperationFact.CnasDataOperation().GetCNASTablesStruct(strTableName_Cnas,currentSyncItem.SyncTargetDBInfo);
  434. if (dtTableStruct != null)
  435. {
  436. DataTable dtCnasShow = new DataTable();
  437. dtCnasShow.Columns.Add("CnasFieldName");
  438. dtCnasShow.Columns.Add("CnasDataType");
  439. dtCnasShow.Columns.Add("remark");
  440. for (int i = 0; i < dtTableStruct.Rows.Count; i++)
  441. {
  442. dtCnasShow.Rows.Add(new object[] { dtTableStruct.Rows[i]["ColumnName"], dtTableStruct.Rows[i]["DataType"], dtTableStruct.Rows[i]["remark"] });
  443. }
  444. dgvCnas.DataSource = null;
  445. dgvCnas.DataSource = dtCnasShow;
  446. //绑定数据
  447. cbxCNASColumn.DataSource = dtCnasShow.Copy();
  448. cbxCNASColumn.DisplayMember = "CnasFieldName";
  449. cbxCNASColumn.ValueMember = "CnasFieldName";
  450. if (dtTableStruct.Columns.Count > 0)
  451. {
  452. if (!string.IsNullOrWhiteSpace(currentSyncItem.CnasInstrumentColumn) && dtTableStruct.Columns.Contains(currentSyncItem.CnasInstrumentColumn))
  453. {
  454. cbxCNASColumn.Text = this.txtInstrumentColumn.Text = currentSyncItem.CnasInstrumentColumn;
  455. }
  456. //else
  457. //{
  458. // cbxCNASColumn.Text = this.txtInstrumentColumn.Text = "";
  459. //}
  460. }
  461. }
  462. }
  463. //增加映射
  464. private void btnAddMapping_Click(object sender, EventArgs e)
  465. {
  466. if (cbxInstrument.Text == null) return;
  467. if (cbxCnas.Text == null) return;
  468. if (dgvInstruDS.Rows.Count <= 0) return;
  469. if (dgvCnas.Rows.Count <= 0) return;
  470. SyncParamasInfo syncParamas = new SyncParamasInfo();
  471. if (currentSyncItem.LstSyncPramas == null) currentSyncItem.LstSyncPramas = new List<SyncParamasInfo>();
  472. if (dgvCnas.Rows[dgvCnas.CurrentCell.RowIndex].Cells[0].Value.ToString().ToUpper() == "ID")
  473. {
  474. MessageBox.Show("该字段为CNAS数据库保留字段,不允许插入数据,请重新选择!");
  475. return;
  476. }
  477. //仪器表名和选中行
  478. syncParamas.SourceTable = cbxInstrument.Text.ToString();
  479. syncParamas.SourceField = dgvInstruDS.Rows[dgvInstruDS.CurrentCell.RowIndex].Cells[0].Value.ToString();
  480. syncParamas.DataType = dgvInstruDS.Rows[dgvInstruDS.CurrentCell.RowIndex].Cells[1].Value.ToString().ToUpper();
  481. //CNAS表名和选中行
  482. syncParamas.TargetTable = cbxCnas.Text.ToString();
  483. syncParamas.TargetField = dgvCnas.Rows[dgvCnas.CurrentCell.RowIndex].Cells[0].Value.ToString();
  484. //验证数据合法性
  485. SyncParamsOperation paramsOperation = new SyncParamsOperation();
  486. if (paramsOperation.CheckTableIfRepeat(currentSyncItem.LstSyncPramas, syncParamas.SourceTable, syncParamas.TargetTable))
  487. {
  488. MessageBox.Show("已存在不同表单映射数据,无法添加!");
  489. return;
  490. }
  491. //if (paramsOperation.CheckSourceFieldRepeat(currentSyncItem.LstSyncPramas, syncParamas.SourceTable, syncParamas.SourceField))
  492. //{
  493. // MessageBox.Show("仪器数据源字段已分配,请重新选择!");
  494. // return;
  495. //}
  496. if (paramsOperation.CheckTargetFieldRepeat(currentSyncItem.LstSyncPramas, syncParamas.TargetTable, syncParamas.TargetField))
  497. {
  498. MessageBox.Show("CNAS端数据字段已分配,请重新选择!");
  499. return;
  500. }
  501. if (paramsOperation.CheckTargetKeepField(syncParamas.TargetField))
  502. {
  503. MessageBox.Show("CNAS端数据字段为保留字段,请重新选择!");
  504. return;
  505. }
  506. //绑定数据
  507. currentSyncItem.LstSyncPramas.Add(syncParamas);
  508. dgvMapping.DataSource = new BindingList<SyncParamasInfo>(currentSyncItem.LstSyncPramas);
  509. //选中最后一行
  510. dgvMapping.CurrentCell = dgvMapping.Rows[dgvMapping.Rows.Count - 1].Cells[0];
  511. }
  512. /// <summary>
  513. /// 删除映射
  514. /// </summary>
  515. /// <param name="sender"></param>
  516. /// <param name="e"></param>
  517. private void btnDelMap_Click(object sender, EventArgs e)
  518. {
  519. //当前选中项
  520. if (dgvMapping.CurrentCell == null) return;
  521. string strSourceField = dgvMapping.Rows[dgvMapping.CurrentCell.RowIndex].Cells["InstrumentField"].Value.ToString();
  522. string strTargetField = dgvMapping.Rows[dgvMapping.CurrentCell.RowIndex].Cells["CnasField"].Value.ToString();
  523. var lstDelItems = currentSyncItem.LstSyncPramas.Where(s => s.SourceField == strSourceField && s.TargetField == strTargetField).ToList<SyncParamasInfo>();
  524. if (lstDelItems.Count > 0)
  525. {
  526. foreach (var item in lstDelItems)
  527. {
  528. currentSyncItem.LstSyncPramas.Remove(item);
  529. }
  530. dgvMapping.DataSource = new BindingList<SyncParamasInfo>(currentSyncItem.LstSyncPramas);
  531. }
  532. }
  533. /// <summary>
  534. /// 配置数据库界面
  535. /// </summary>
  536. /// <param name="sender"></param>
  537. /// <param name="e"></param>
  538. private void btnDatabaseConfig_Click(object sender, EventArgs e)
  539. {
  540. frmDatabaseParams frmDatabase = new frmDatabaseParams(currentSyncItem);
  541. frmDatabase.InstrumentDelegate = delegate (SyncInstrumentItemInfo Instrumentitem)
  542. {
  543. this.currentSyncItem = Instrumentitem;
  544. };
  545. frmDatabase.InstrumentItemData = delegate (Dictionary<string, DataTable> dict)
  546. {
  547. //this.dictInstruTables = dict;
  548. };
  549. frmDatabase.ShowDialog();
  550. //加载数据
  551. if ((currentSyncItem.SyncInstrumentDSInfo.Host != null && currentSyncItem.SyncInstrumentDSInfo.Host.Length > 0) || (currentSyncItem.SyncInstrumentDSInfo.Path != null && currentSyncItem.SyncInstrumentDSInfo.Path.Length > 0))
  552. btnLoadDBData_Click(null, null);
  553. }
  554. private void btnLoadDBData_Click(object sender, EventArgs e)
  555. {
  556. string strInstrumentCode = this.dgvInstrument.Rows[this.dgvInstrument.CurrentRow.Index].Cells[0].Value.ToString();
  557. strTableInfoMode = FileOperation.GetSystemFormatConfigData(strInstrumentCode).TableInfoMode;
  558. if (strTableInfoMode == "1")
  559. {
  560. cbxInstrument.DropDownStyle = ComboBoxStyle.DropDown;
  561. //cbxCnas.DropDownStyle = ComboBoxStyle.DropDown;
  562. }
  563. int iReturn = 0;
  564. if (strTableInfoMode == "0")
  565. iReturn = LoadSourceAndTargetData(true);
  566. else
  567. iReturn = LoadSourceAndTargetData();
  568. switch (iReturn)
  569. {
  570. case -1:
  571. MessageBox.Show("未能成功获取设备数据库配置信息,请配置后重试!");
  572. break;
  573. case -2:
  574. MessageBox.Show("未能成功获取CNAS数据库配置信息,请配置后重试!");
  575. break;
  576. case -3:
  577. MessageBox.Show("未能成功获取仪器数据信息,请配置后重试!");
  578. break;
  579. case -4:
  580. MessageBox.Show("未能成功获取CNAS数据信息,请配置后重试!");
  581. break;
  582. case -5:
  583. DialogResult dr = MessageBox.Show("检测到数据连接配置已经修改,是否全部删除已经分配的字段映射?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
  584. if (dr == DialogResult.Yes)
  585. {
  586. //此时将全部删除已经分配的映射字段
  587. currentSyncItem.LstSyncPramas.Clear();
  588. currentSyncItem.lstFixedValue.Clear();
  589. dgvMapping.DataSource = new BindingList<SyncParamasInfo>();
  590. }
  591. break;
  592. case -6:
  593. MessageBox.Show("请先手动输入表名");
  594. break;
  595. case -7:
  596. MessageBox.Show("配置SQL查询没有结果,请检查SQL是否正确");
  597. break;
  598. default:
  599. break;
  600. }
  601. }
  602. /// <summary>
  603. /// 加载来源和目标数据的数据结构
  604. /// </summary>
  605. /// <param name="bIfLoading"></param>
  606. /// <returns></returns>
  607. public int LoadSourceAndTargetData(bool bIfLoading = false)
  608. {
  609. //检查配置信息
  610. if (currentSyncItem.SyncInstrumentDSInfo == null) return -1;
  611. if (currentSyncItem.SyncTargetDBInfo == null) return -2;
  612. bool bIfSameTable = true;
  613. //是否需要重新加载来源库
  614. if (bIfLoading)
  615. {
  616. InstrumentData instrumentData = InstrumentDataFact.CreateInstrumentDataSource(currentSyncItem.SyncInstrumentDSInfo, new object[] { "", "", "" });
  617. dictInstruTables = instrumentData.GetInstrumentData();
  618. }
  619. if (dictInstruTables.Count <= 0) return -3;
  620. //绑定ComboBox
  621. List<string> lstTableName = new List<string>();
  622. foreach (var item in dictInstruTables)
  623. {
  624. lstTableName.Add(item.Key);
  625. }
  626. cbxInstrument.DataSource = lstTableName;
  627. cbxInstrument.ValueMember = "";
  628. if (currentSyncItem.LstSyncPramas != null && currentSyncItem.LstSyncPramas.Count > 0)
  629. {
  630. if (lstTableName.Contains(currentSyncItem.LstSyncPramas[0].SourceTable) || lstTableName.Contains(currentSyncItem.LstSyncPramas[0].SourceTable.ToUpper()) || lstTableName.Contains(currentSyncItem.LstSyncPramas[0].SourceTable.ToLower()))
  631. cbxInstrument.Text = currentSyncItem.LstSyncPramas[0].SourceTable;
  632. else
  633. bIfSameTable = false;
  634. }
  635. //获取CNAS配置的数据库连接信息
  636. DataTable dtCNAS = CnasDataOperationFact.CnasDataOperation().GetAllCNASTablesName(currentSyncItem.SyncTargetDBInfo);
  637. if (dtCNAS != null && dtCNAS.Rows.Count > 0)
  638. {
  639. List<string> lstCnasTables = new List<string>();
  640. foreach (DataRow dr in dtCNAS.Rows)
  641. {
  642. if (dtCNAS.Columns.Contains("TABNAME"))
  643. lstCnasTables.Add(dr["TABNAME"].ToString());
  644. else if (dtCNAS.Columns.Contains("table_name"))
  645. lstCnasTables.Add(dr["table_name"].ToString());
  646. }
  647. cbxCnas.DataSource = lstCnasTables;
  648. cbxCnas.ValueMember = "";
  649. if (currentSyncItem.LstSyncPramas != null && currentSyncItem.LstSyncPramas.Count > 0)
  650. {
  651. if (lstCnasTables.Contains(currentSyncItem.LstSyncPramas[0].TargetTable) || lstCnasTables.Contains(currentSyncItem.LstSyncPramas[0].TargetTable.ToUpper()) || lstCnasTables.Contains(currentSyncItem.LstSyncPramas[0].TargetTable.ToLower()))
  652. {
  653. cbxCnas.Text = currentSyncItem.LstSyncPramas[0].TargetTable;
  654. //cbxCnas_SelectedIndexChanged(null, null);
  655. }
  656. else
  657. bIfSameTable = false;
  658. }
  659. }
  660. else
  661. return -4;
  662. if (!bIfSameTable)
  663. {
  664. return -5;
  665. }
  666. return 1;
  667. }
  668. public AccessFormatConfig AccessFormat { get; set; }
  669. public ExcelFormatConfig ExcelFormat { get; set; }
  670. public FoxProFormatConfig FoxProFormat { get; set; }
  671. public SqliteFormatConfig SqliteFormat { get; set; }
  672. public SqlServerFormatConfig SqlServerFormat { get; set; }
  673. public OracleFormatConfig OracleFormat { get; set; }
  674. public MySqlFormatConfig MySqlFormat { get; set; }
  675. public NormalFileFormatConfig NormalFileFormat { get; set; }
  676. public PostgreSqlFormatConfig PostgreSqlFormat { get; set; }
  677. public KingbaseFormatConfig KingbaseFormat { get; set; }
  678. public DmFormatConfig DmFormat { get; set; }
  679. /// <summary>
  680. /// 手动输入表名时,获取该表的表信息
  681. /// </summary>
  682. /// <returns></returns>
  683. public int LoadSourceAndTargetData()
  684. {
  685. if (currentSyncItem.SyncInstrumentDSInfo == null) return -1;
  686. if (currentSyncItem.SyncTargetDBInfo == null) return -2;
  687. string sqlName = "";
  688. string sql = "";
  689. ExcelFormat = FileOperation.GetFormatConfigData<ExcelFormatConfig>("ExcelFormatConfig.xml");
  690. AccessFormat = FileOperation.GetFormatConfigData<AccessFormatConfig>("AccessFormatConfig.xml");
  691. FoxProFormat = FileOperation.GetFormatConfigData<FoxProFormatConfig>("FoxProFormatConfig.xml");
  692. SqliteFormat = FileOperation.GetFormatConfigData<SqliteFormatConfig>("SqliteFormatConfig.xml");
  693. SqlServerFormat = FileOperation.GetFormatConfigData<SqlServerFormatConfig>("SqlServerFormatConfig.xml");
  694. OracleFormat = FileOperation.GetFormatConfigData<OracleFormatConfig>("OracleFormatConfig.xml");
  695. NormalFileFormat = FileOperation.GetFormatConfigData<NormalFileFormatConfig>("NormalFileFormatConfig.xml");
  696. switch (currentSyncItem.SyncInstrumentDSInfo.InstrumentDataSourceType)
  697. {
  698. case DataSourceType.MySQL:
  699. MySqlFormat = FileOperation.GetFormatConfigData<MySqlFormatConfig>("MySqlFormatConfig.xml");
  700. sqlName = MySqlFormat.AutoSql.MySqlViewName;
  701. sql = MySqlFormat.AutoSql.MySqlViewSql;
  702. break;
  703. case DataSourceType.Dm:
  704. DmFormat = FileOperation.GetFormatConfigData<DmFormatConfig>("DmFormatConfig.xml");
  705. sqlName = DmFormat.AutoSql.DmViewName;
  706. sql = DmFormat.AutoSql.DmViewSql;
  707. break;
  708. case DataSourceType.Oracle:
  709. OracleFormat = FileOperation.GetFormatConfigData<OracleFormatConfig>("OracleFormatConfig.xml");
  710. sqlName = OracleFormat.AutoSql.OracleViewName;
  711. sql = OracleFormat.AutoSql.OracleViewSql;
  712. break;
  713. case DataSourceType.PostgreSQL:
  714. PostgreSqlFormat = FileOperation.GetFormatConfigData<PostgreSqlFormatConfig>("PostgreSqlFormatConfig.xml");
  715. sqlName = PostgreSqlFormat.AutoSql.PostgreSqlViewName;
  716. sql = PostgreSqlFormat.AutoSql.PostgreSqlViewSql;
  717. break;
  718. case DataSourceType.SQL:
  719. SqlServerFormat = FileOperation.GetFormatConfigData<SqlServerFormatConfig>("SqlServerFormatConfig.xml");
  720. sqlName = SqlServerFormat.AutoSql.SqlServerViewName;
  721. sql = SqlServerFormat.AutoSql.SqlServerViewSql;
  722. break;
  723. case DataSourceType.Kingbase:
  724. KingbaseFormat = FileOperation.GetFormatConfigData<KingbaseFormatConfig>("KingbaseFormatConfig.xml");
  725. sqlName = KingbaseFormat.AutoSql.KingbaseViewName;
  726. sql = KingbaseFormat.AutoSql.KingbaseViewSql;
  727. break;
  728. case DataSourceType.Access:
  729. AccessFormat = FileOperation.GetFormatConfigData<AccessFormatConfig>("AccessFormatConfig.xml");
  730. sqlName = AccessFormat.AutoSql.AccessViewName;
  731. sql = AccessFormat.AutoSql.AccessViewSql;
  732. break;
  733. default:
  734. break;
  735. }
  736. //cbxInstrument.Text = ExtractTableNames(sql);
  737. cbxInstrument.Text = sqlName;
  738. if (cbxInstrument.Text == "") return -6;
  739. int returnValue = 1;
  740. //根据手动输入来源库的表名加载字段
  741. InstrumentData instrumentData = InstrumentDataFact.CreateInstrumentDataSource(currentSyncItem.SyncInstrumentDSInfo, new object[] { "", "", "" });
  742. //dictInstruTables = instrumentData.GetInstrumentData();
  743. //dictInstruTables =
  744. DataTable dataTableStruct = null;
  745. string strTableName_Instru = cbxInstrument.Text.ToString();
  746. switch (currentSyncItem.SyncInstrumentDSInfo.InstrumentDataSourceType)
  747. {
  748. case DataSourceType.MySQL:
  749. dataTableStruct = SelectTableType.MySqlsecSD(sql);
  750. break;
  751. case DataSourceType.Dm:
  752. dataTableStruct = SelectTableType.DmSqlSD(sql);
  753. break;
  754. case DataSourceType.Oracle:
  755. dataTableStruct = SelectTableType.OrcSqlSD(sql, currentSyncItem);
  756. break;
  757. case DataSourceType.PostgreSQL:
  758. dataTableStruct = SelectTableType.PostgreSqlSD(sql);
  759. break;
  760. case DataSourceType.SQL:
  761. dataTableStruct = SelectTableType.SqlserversecSD(sql, currentSyncItem);
  762. break;
  763. case DataSourceType.Kingbase:
  764. if (cbxInstrument.Text.Contains('.'))
  765. cbxInstrument.Text = cbxInstrument.Text.Split('.')[1];
  766. dataTableStruct = SelectTableType.KingSql(sql);
  767. break;
  768. case DataSourceType.Access:
  769. //根据手动输入来源库的表名加载字段
  770. dataTableStruct = SelectTableType.AccSql(currentSyncItem.SyncInstrumentDSInfo, sql);
  771. break;
  772. default:
  773. break;
  774. }
  775. DataTable dtInstruShow = new DataTable();
  776. dtInstruShow.Columns.Add("InstruFieldName");
  777. dtInstruShow.Columns.Add("InstruDataType");
  778. dtInstruShow.Columns.Add("remark");
  779. if (dataTableStruct != null)
  780. {
  781. for (int i = 0; i < dataTableStruct.Columns.Count; i++)
  782. {
  783. dtInstruShow.Rows.Add(new object[] { dataTableStruct.Columns[i].ColumnName, dataTableStruct.Columns[i].DataType });
  784. }
  785. }
  786. dgvInstruDS.DataSource = dtInstruShow;
  787. if (dataTableStruct != null && dataTableStruct.Columns.Count > 0)
  788. {
  789. dictInstruTables.Clear();
  790. dictInstruTables.Add(cbxInstrument.Text, dataTableStruct);
  791. //return 1;
  792. }
  793. else
  794. {
  795. returnValue = -7;
  796. return returnValue;
  797. }
  798. //获取CNAS配置的数据库连接信息
  799. DataTable dtCNAS = CnasDataOperationFact.CnasDataOperation().GetAllCNASTablesName(currentSyncItem.SyncTargetDBInfo);
  800. if (dtCNAS != null && dtCNAS.Rows.Count > 0)
  801. {
  802. List<string> lstCnasTables = new List<string>();
  803. foreach (DataRow dr in dtCNAS.Rows)
  804. {
  805. lstCnasTables.Add(dr["TABNAME"].ToString());
  806. }
  807. cbxCnas.DataSource = lstCnasTables;
  808. cbxCnas.ValueMember = "";
  809. if (currentSyncItem.LstSyncPramas != null && currentSyncItem.LstSyncPramas.Count > 0)
  810. {
  811. if (lstCnasTables.Contains(currentSyncItem.LstSyncPramas[0].TargetTable) || lstCnasTables.Contains(currentSyncItem.LstSyncPramas[0].TargetTable.ToUpper()) || lstCnasTables.Contains(currentSyncItem.LstSyncPramas[0].TargetTable.ToLower()))
  812. {
  813. cbxCnas.Text = currentSyncItem.LstSyncPramas[0].TargetTable;
  814. //cbxCnas_SelectedIndexChanged(null, null);
  815. }
  816. else
  817. returnValue = -5;
  818. }
  819. }
  820. else
  821. returnValue = -4;
  822. return returnValue;
  823. }
  824. public string ExtractTableNames(string sql)
  825. {
  826. // 预处理:去除注释、统一空格
  827. sql = Regex.Replace(sql, @"(--.*)|(\/\*[\s\S]*?\*\/)", "", RegexOptions.Multiline);
  828. sql = Regex.Replace(sql, @"\s+", " ");
  829. // 定义匹配模式
  830. var patterns = new Dictionary<string, string>
  831. {
  832. { "SELECT", @"(?:FROM|JOIN)\s+([\w\.]+)(?:\s+AS\s+\w+)?" },
  833. { "INSERT", @"INSERT\s+INTO\s+([\w\.]+)" },
  834. { "UPDATE", @"UPDATE\s+([\w\.]+)" },
  835. { "DELETE", @"DELETE\s+FROM\s+([\w\.]+)" }
  836. };
  837. var tables = new HashSet<string>();
  838. foreach (var pattern in patterns.Values)
  839. {
  840. var matches = Regex.Matches(sql, pattern, RegexOptions.IgnoreCase);
  841. foreach (Match match in matches)
  842. {
  843. if (match.Groups[1].Success)
  844. tables.Add(match.Groups[1].Value.Trim());
  845. }
  846. }
  847. if (tables.Count == 0)
  848. return "";
  849. else
  850. return tables.ToList()[0];
  851. }
  852. private void dgvMapping_CellValueChanged(object sender, DataGridViewCellEventArgs e)
  853. {
  854. if (dgvMapping.CurrentCell == null) return;
  855. if (dgvMapping.CurrentCell.ColumnIndex == 2) //此时修改的主健列
  856. {
  857. string strSourceField = dgvMapping.Rows[dgvMapping.CurrentCell.RowIndex].Cells["InstrumentField"].Value.ToString();
  858. string strTargetField = dgvMapping.Rows[dgvMapping.CurrentCell.RowIndex].Cells["CnasField"].Value.ToString();
  859. string strPrimaryKey = dgvMapping.Rows[dgvMapping.CurrentCell.RowIndex].Cells["PrimaryKey"].Value.ToString();
  860. var lstDelItems = currentSyncItem.LstSyncPramas.Where(s => s.SourceField == strSourceField && s.TargetField == strTargetField).ToList<SyncParamasInfo>();
  861. if (lstDelItems.Count > 0)
  862. {
  863. foreach (var item in lstDelItems)
  864. {
  865. item.IfPrimaryKey = strPrimaryKey.ToLower() == "true" ? true : false;
  866. }
  867. }
  868. }
  869. if (dgvMapping.CurrentCell.ColumnIndex == 3) //此时修改的是日期字段列
  870. {
  871. string strSourceField = dgvMapping.Rows[dgvMapping.CurrentCell.RowIndex].Cells["InstrumentField"].Value.ToString();
  872. string strTargetField = dgvMapping.Rows[dgvMapping.CurrentCell.RowIndex].Cells["CnasField"].Value.ToString();
  873. string strDateKey = dgvMapping.Rows[dgvMapping.CurrentCell.RowIndex].Cells["DateKey"].Value.ToString();
  874. var lstDelItems = currentSyncItem.LstSyncPramas.Where(s => s.SourceField == strSourceField && s.TargetField == strTargetField).ToList<SyncParamasInfo>();
  875. if (lstDelItems.Count == 1)
  876. {
  877. if (strDateKey.ToLower() == "true")
  878. {
  879. //datagridview显示列(只能允许一条数据选择true,所以要把其他行的数据都置为false)
  880. foreach (DataGridViewRow dgvRow in dgvMapping.Rows)
  881. {
  882. if (dgvRow.Cells["DateKey"].Value.ToString().ToLower() == "true")
  883. dgvRow.Cells["DateKey"].Value = false;
  884. }
  885. //内存数据源
  886. foreach (var item in currentSyncItem.LstSyncPramas)
  887. {
  888. if (item.IfDateField)
  889. item.IfDateField = false;
  890. }
  891. lstDelItems[0].IfDateField = true;
  892. }
  893. else
  894. {
  895. lstDelItems[0].IfDateField = false;
  896. }
  897. }
  898. }
  899. }
  900. private void dgvMapping_CurrentCellDirtyStateChanged(object sender, EventArgs e)
  901. {
  902. if (dgvMapping.IsCurrentCellDirty)
  903. {
  904. dgvMapping.CommitEdit(DataGridViewDataErrorContexts.Commit);
  905. }
  906. }
  907. private void btnCNASFieldConfig_Click(object sender, EventArgs e)
  908. {
  909. if (currentSyncItem == null || currentSyncItem.LstSyncPramas == null || currentSyncItem.LstSyncPramas.Count == 0)
  910. {
  911. MessageBox.Show("请先指定至少一个映射字段。");
  912. return;
  913. }
  914. frmCNASValue frmCNAS = new frmCNASValue(currentSyncItem);
  915. if (frmCNAS.ShowDialog() == DialogResult.OK)
  916. {
  917. this.currentSyncItem = frmCNAS.syncInstrument;
  918. }
  919. }
  920. private void btnSourceFilter_Click(object sender, EventArgs e)
  921. {
  922. if (currentSyncItem == null || currentSyncItem.LstSyncPramas == null || currentSyncItem.LstSyncPramas.Count == 0)
  923. {
  924. MessageBox.Show("请先指定至少一个映射字段。");
  925. return;
  926. }
  927. frmSourceFilter frm = new frmSourceFilter(currentSyncItem, strTableInfoMode);
  928. frm.sourceDataFilterHandler = delegate (SourceDataFilter dataFilter)
  929. {
  930. currentSyncItem.SourceFilter = dataFilter;
  931. };
  932. frm.ShowDialog();
  933. }
  934. private void dgvInstrument_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
  935. {
  936. if (dgvInstrument.Rows.Count <= 0) return;
  937. //当前选中单元格
  938. string strInstrumentCode = this.dgvInstrument.Rows[this.dgvInstrument.CurrentRow.Index].Cells[0].Value.ToString();
  939. frmSystemSetting frmSetting = new frmSystemSetting(lstSyncInstrument, strInstrumentCode);
  940. frmSetting.InstrumentDelegate = delegate (SyncInstrumentItemInfo Instrumentitem)
  941. {
  942. lstSyncInstrument.Add(Instrumentitem);
  943. //绑定数据
  944. dgvInstrument.DataSource = new BindingList<SyncInstrumentItemInfo>(lstSyncInstrument);
  945. dgvInstrument.CurrentCell = dgvInstrument.Rows[dgvInstrument.Rows.Count - 1].Cells[0];
  946. dgvInstrument_SelectionChanged(null, null);
  947. };
  948. frmSetting.ShowDialog();
  949. }
  950. private void cbxCNASColumn_SelectedIndexChanged(object sender, EventArgs e)
  951. {
  952. if (cbxCNASColumn.Visible)
  953. {
  954. cbxCNASColumn.Visible = false;
  955. txtInstrumentColumn.Visible = true;
  956. currentSyncItem.CnasInstrumentColumn = txtInstrumentColumn.Text = cbxCNASColumn.Text;
  957. }
  958. }
  959. /// <summary>
  960. /// 当双击textBox时,显示ComboBOX用于选择
  961. /// </summary>
  962. /// <param name="sender"></param>
  963. /// <param name="e"></param>
  964. private void txtInstrumentColumn_DoubleClick(object sender, EventArgs e)
  965. {
  966. txtInstrumentColumn.Visible = false;
  967. cbxCNASColumn.Top = txtInstrumentColumn.Top;
  968. cbxCNASColumn.Height = txtInstrumentColumn.Height;
  969. cbxCNASColumn.Width = txtInstrumentColumn.Width;
  970. cbxCNASColumn.Location = txtInstrumentColumn.Location;
  971. cbxCNASColumn.Visible = true;
  972. }
  973. private void cbxCNASColumn_Leave(object sender, EventArgs e)
  974. {
  975. if (cbxCNASColumn.Visible)
  976. {
  977. txtInstrumentColumn.Visible = true;
  978. cbxCNASColumn.Visible = false;
  979. }
  980. }
  981. private void tsmServiceSetting_Click(object sender, EventArgs e)
  982. {
  983. frmServiceConfig frmServiceConfig = new frmServiceConfig();
  984. frmServiceConfig.ShowDialog();
  985. }
  986. private void tsmSystemSetting_Click(object sender, EventArgs e)
  987. {
  988. //frmSystemSetting frmSystem = new frmSystemSetting();
  989. //frmSystem.ShowDialog();
  990. //strTableInfoMode = FileOperation.GetSystemFormatConfigData().TableInfoMode;
  991. //if (strTableInfoMode == "1")
  992. //{
  993. // cbxInstrument.DropDownStyle = ComboBoxStyle.DropDown;
  994. // //cbxCnas.DropDownStyle = ComboBoxStyle.DropDown;
  995. //}
  996. //else
  997. //{
  998. // cbxInstrument.DropDownStyle = ComboBoxStyle.DropDownList;
  999. //}
  1000. }
  1001. private void tsmSourceSetting_Click(object sender, EventArgs e)
  1002. {
  1003. frmSourceSetting frmSource = new frmSourceSetting();
  1004. frmSource.ShowDialog();
  1005. }
  1006. private void tsmHelper_Click(object sender, EventArgs e)
  1007. {
  1008. string strHelpFilePath = FileHelper.getBasePath() + @"\Helper.CHM";
  1009. //Help.ShowHelp(null, strHelpFilePath, HelpNavigator.TopicId, "1");
  1010. //Help.ShowHelpIndex(this, strHelpFilePath);
  1011. System.Diagnostics.Process.Start(strHelpFilePath);
  1012. }
  1013. /// <summary>
  1014. /// 右键事件
  1015. /// </summary>
  1016. /// <param name="sender"></param>
  1017. /// <param name="e"></param>
  1018. private void dgvInstrument_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
  1019. {
  1020. if (e.Button == MouseButtons.Right)
  1021. {
  1022. string strInstrumentCode = this.dgvInstrument.Rows[this.dgvInstrument.CurrentRow.Index].Cells[0].Value.ToString();
  1023. if (dgvInstrument.Rows.Count <= 0) return;
  1024. //当前选中单元格
  1025. if (strInstrumentCode != "")
  1026. {
  1027. // 显示上下文菜单
  1028. ContextMenuStrip contextMenu = new ContextMenuStrip();
  1029. contextMenu.Items.Add("编辑", null, new EventHandler(Option1_Click));
  1030. contextMenu.Show(dgvInstrument, new Point(e.X, e.Y));
  1031. }
  1032. }
  1033. }
  1034. }
  1035. }