CNAS取数仪器端升级
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

587 linhas
27KB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using CnasSynchronusClient;
  10. using CnasSynchrousModel;
  11. namespace CNAS_DBSync
  12. {
  13. public partial class frmCNASValue : Form
  14. {
  15. public SyncInstrumentItemInfo syncInstrument;
  16. private ComboBox cbxConditionValue;
  17. private List<string> lstConditionValueType = new List<string>() { "等于", "连接", "若...则...", "截取", "除以", "乘以", "小数位数","数值相加(减)","截断开头(结尾)","位数截取" };
  18. public frmCNASValue(SyncInstrumentItemInfo syncInstrument)
  19. {
  20. InitializeComponent();
  21. this.syncInstrument = syncInstrument;
  22. }
  23. private void frmCNASValue_Load(object sender, EventArgs e)
  24. {
  25. if (syncInstrument == null || syncInstrument.LstSyncPramas == null|| syncInstrument.LstSyncPramas.Count==0)
  26. {
  27. MessageBox.Show("请先指定至少一个映射字段。");
  28. return;
  29. }
  30. //初始化ComBobox
  31. InnitalComboBox();
  32. //加载数据
  33. LoadShowData();
  34. }
  35. private void InnitalComboBox()
  36. {
  37. cbxConditionValue = new ComboBox();
  38. cbxConditionValue.SelectedIndexChanged += new EventHandler(cbxConditionValue_SelectedIndexChanged);
  39. cbxConditionValue.SelectionChangeCommitted += new EventHandler(cbxConditionValue_SelectionChangedCommitted);
  40. cbxConditionValue.Visible = false;
  41. cbxConditionValue.DataSource = lstConditionValueType;
  42. }
  43. private void cbxConditionValue_SelectionChangedCommitted(object sender, EventArgs e)
  44. {
  45. cbxConditionValue.Visible = false;
  46. }
  47. private void cbxConditionValue_SelectedIndexChanged(object sender, EventArgs e)
  48. {
  49. //当前选中单元格的值将随之发生更改
  50. if (dgvCnas.CurrentCell == null) return;
  51. dgvCnas.Rows[dgvCnas.CurrentCell.RowIndex].Cells["condition"].Value = cbxConditionValue.Text;
  52. }
  53. private void LoadShowData()
  54. {
  55. //1.根据映射表中的表名,获取该表所有字段,全部显示
  56. string strTableName = syncInstrument.LstSyncPramas[0].TargetTable;
  57. DataTable dtTableStruct = CnasDataOperationFact.CnasDataOperation().GetCNASTablesStruct(strTableName, syncInstrument.SyncTargetDBInfo);
  58. if (dtTableStruct != null)
  59. {
  60. DataTable dtCnasShow = new DataTable();
  61. dtCnasShow.Columns.Add("CnasTableName");
  62. dtCnasShow.Columns.Add("CnasFieldName");
  63. dtCnasShow.Columns.Add("CnasDataType");
  64. foreach (DataColumn dc in dtTableStruct.Columns)
  65. {
  66. if (dc.ColumnName.ToUpper() == "ID") continue;
  67. dtCnasShow.Rows.Add(new object[] { strTableName,dc.ColumnName, dc.DataType });
  68. }
  69. dgvCnas.DataSource = dtCnasShow;
  70. }
  71. //2.根据已存储数据,匹配后填充到datagridview中
  72. if (syncInstrument.lstFixedValue == null)
  73. syncInstrument.lstFixedValue = new List<CnasConditionMapValue>();
  74. if (syncInstrument.lstFixedValue.Count == 0) return;
  75. foreach (DataGridViewRow dgvRow in dgvCnas.Rows)
  76. {
  77. string strCurrentTable = dgvRow.Cells["TableName"].Value.ToString();
  78. string strCurrentColumn = dgvRow.Cells["TableColumn"].Value.ToString();
  79. if (strCurrentTable == "" || strCurrentColumn == "") continue;
  80. var query=syncInstrument.lstFixedValue.Where(s => s.TableName == strCurrentTable && s.ColumnName == strCurrentColumn).ToList<CnasConditionMapValue>();
  81. if (query.Count == 1)
  82. {
  83. dgvRow.Cells["Value"].Value = query[0].Value;
  84. dgvRow.Cells["Condition"].Value = GiveShowByCondition(query[0]);
  85. }
  86. }
  87. }
  88. private void btnOK_Click(object sender, EventArgs e)
  89. {
  90. this.DialogResult = DialogResult.OK;
  91. this.Close();
  92. }
  93. private void dgvCnas_CellEndEdit(object sender, DataGridViewCellEventArgs e)
  94. {
  95. if (e.ColumnIndex == 1) //此时是“值”列
  96. {
  97. //如果没有指定条件,无法存储结果
  98. if (dgvCnas.Rows[e.RowIndex].Cells["condition"].Value == null) return;
  99. //当前列名
  100. string strCurrentTable = dgvCnas.Rows[e.RowIndex].Cells["TableName"].Value.ToString();
  101. string strCurrentColumn = dgvCnas.Rows[e.RowIndex].Cells["TableColumn"].Value.ToString();
  102. string strCurrentType = dgvCnas.Rows[e.RowIndex].Cells["DataType"].Value.ToString();
  103. string strCurrentCondition= dgvCnas.Rows[e.RowIndex].Cells["condition"].Value.ToString();
  104. if (dgvCnas.CurrentCell.Value == null)
  105. {
  106. syncInstrument.lstFixedValue.RemoveAll(s => s.TableName == strCurrentTable && s.ColumnName == strCurrentColumn);
  107. return;
  108. }
  109. string strInputValue = dgvCnas.CurrentCell.Value.ToString();
  110. //检查合法性
  111. if (strCurrentColumn == "ID")
  112. {
  113. MessageBox.Show("该列不能指定固定值。");
  114. return;
  115. }
  116. bool bIfSuccess = true;
  117. switch (strCurrentType)
  118. {
  119. case "System.Decimal":
  120. decimal defaultdecimal = 0;
  121. if (!decimal.TryParse(strInputValue, out defaultdecimal))
  122. bIfSuccess = false;
  123. break;
  124. case "System.Int":
  125. int defaultint = 0;
  126. if (!int.TryParse(strInputValue, out defaultint))
  127. bIfSuccess = false;
  128. break;
  129. case "System.String":
  130. default:
  131. break;
  132. }
  133. if (!bIfSuccess)
  134. {
  135. MessageBox.Show("输入格式不正确,请重新输入。");
  136. return;
  137. }
  138. if (GetBytesOfString(strInputValue) > 20)
  139. {
  140. MessageBox.Show("输入内容超出限制,请重新输入。");
  141. dgvCnas.CurrentCell.Value = "";
  142. return;
  143. }
  144. //将数据插入到数据源中
  145. var query = syncInstrument.lstFixedValue.Where(s => s.TableName == strCurrentTable && s.ColumnName == strCurrentColumn).ToList<CnasConditionMapValue>();
  146. if (query.Count >= 1)
  147. {
  148. GiveConditionByShow(query[0],strCurrentCondition);
  149. //query[0].Condition = strCurrentCondition == "Sub" ? MapCondition.Sub : (strCurrentCondition == "IFThen" ? MapCondition.IFThen: MapCondition.Equal);
  150. query[0].Value = strInputValue;
  151. }
  152. else
  153. {
  154. CnasConditionMapValue cnasFixed = new CnasConditionMapValue();
  155. cnasFixed.TableName = strCurrentTable;
  156. cnasFixed.ColumnName = strCurrentColumn;
  157. cnasFixed.Value = strInputValue;
  158. //cnasFixed.Condition= strCurrentCondition == "Sub" ? MapCondition.Sub : (strCurrentCondition == "IFThen" ? MapCondition.IFThen : MapCondition.Equal);
  159. GiveConditionByShow(cnasFixed, strCurrentCondition);
  160. syncInstrument.lstFixedValue.Add(cnasFixed);
  161. }
  162. }
  163. }
  164. public int GetBytesOfString(string Text)
  165. {
  166. int nByte = 0;
  167. byte[] bytes = Encoding.Unicode.GetBytes(Text);
  168. for (int i = 0; i < bytes.GetLength(0); i++)
  169. {
  170. // 偶数位置,如0、2、4等,为UCS2编码中两个字节的第一个字节
  171. if (i % 2 == 0)
  172. {
  173. nByte++; // 在UCS2第一个字节时n加1
  174. }
  175. else
  176. {
  177. // 当UCS2编码的第二个字节大于0时,该UCS2字符为汉字,一个汉字算两个字节
  178. if (bytes[i] > 0)
  179. {
  180. nByte++;
  181. }
  182. }
  183. }
  184. return nByte;
  185. }
  186. public void GiveConditionByShow(CnasConditionMapValue cnasFixed,string strCurrentCondition)
  187. {
  188. switch (strCurrentCondition)
  189. {
  190. case "连接":
  191. cnasFixed.Condition = MapCondition.Sub;
  192. break;
  193. case "若...则...":
  194. cnasFixed.Condition = MapCondition.IFThen;
  195. break;
  196. case "截取":
  197. cnasFixed.Condition = MapCondition.Split;
  198. break;
  199. case "位数截取":
  200. cnasFixed.Condition = MapCondition.SubString;
  201. break;
  202. case "除以":
  203. cnasFixed.Condition = MapCondition.Divided;
  204. break;
  205. case "乘以":
  206. cnasFixed.Condition = MapCondition.Multiplied;
  207. break;
  208. case "小数位数":
  209. cnasFixed.Condition = MapCondition.DecimalDigits;
  210. break;
  211. case "等于":
  212. cnasFixed.Condition = MapCondition.Equal;
  213. break;
  214. case "数值相加(减)":
  215. cnasFixed.Condition = MapCondition.AddSubtract;
  216. break;
  217. case "截断开头(结尾)":
  218. cnasFixed.Condition = MapCondition.SubstringStartEnd;
  219. break;
  220. default:
  221. break;
  222. }
  223. }
  224. public string GiveShowByCondition(CnasConditionMapValue cnasFixed)
  225. {
  226. string strCurrentCondition = "";
  227. switch (cnasFixed.Condition)
  228. {
  229. case MapCondition.Equal:
  230. strCurrentCondition = "等于";
  231. break;
  232. case MapCondition.Sub:
  233. strCurrentCondition = "连接";
  234. break;
  235. case MapCondition.IFThen:
  236. strCurrentCondition = "若...则...";
  237. break;
  238. case MapCondition.Divided:
  239. strCurrentCondition = "除以";
  240. break;
  241. case MapCondition.Multiplied:
  242. strCurrentCondition = "乘以";
  243. break;
  244. case MapCondition.Split:
  245. strCurrentCondition = "截取";
  246. break;
  247. case MapCondition.SubString:
  248. strCurrentCondition = "位数截取";
  249. break;
  250. case MapCondition.DecimalDigits:
  251. strCurrentCondition = "小数位数";
  252. break;
  253. case MapCondition.AddSubtract:
  254. strCurrentCondition = "数值相加(减)";
  255. break;
  256. case MapCondition.SubstringStartEnd:
  257. strCurrentCondition = "截断开头(结尾)";
  258. break;
  259. }
  260. return strCurrentCondition;
  261. }
  262. private void dgvCnas_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
  263. {
  264. Rectangle rectangle = new Rectangle(e.RowBounds.Location.X,
  265. e.RowBounds.Location.Y,
  266. dgvCnas.RowHeadersWidth - 4,
  267. e.RowBounds.Height);
  268. TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(),
  269. dgvCnas.RowHeadersDefaultCellStyle.Font,
  270. rectangle,
  271. dgvCnas.RowHeadersDefaultCellStyle.ForeColor,
  272. TextFormatFlags.VerticalCenter | TextFormatFlags.Right);
  273. }
  274. private void dgvCnas_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
  275. {
  276. if (e.ColumnIndex == 0) //如果此时是“条件”列
  277. {
  278. ShowConditionValue();
  279. }
  280. if (e.ColumnIndex == 1)//如果此时是“值”列
  281. {
  282. if (dgvCnas.Rows[e.RowIndex].Cells["condition"].Value == null) return;
  283. if (dgvCnas.Rows[e.RowIndex].Cells["condition"].Value.ToString() == "连接")
  284. {
  285. CnasConditionMapValue cnasFixed = new CnasConditionMapValue
  286. {
  287. TableName = dgvCnas.Rows[e.RowIndex].Cells["TableName"].Value.ToString(),
  288. ColumnName = dgvCnas.Rows[e.RowIndex].Cells["TableColumn"].Value.ToString(),
  289. Condition = MapCondition.Sub
  290. };
  291. if (dgvCnas.Rows[e.RowIndex].Cells["Value"].Value!=null)
  292. cnasFixed.Value= dgvCnas.Rows[e.RowIndex].Cells["Value"].Value.ToString();
  293. frmConditionParam frmCondition = new frmConditionParam(syncInstrument, cnasFixed);
  294. if (frmCondition.ShowDialog() == DialogResult.OK)
  295. {
  296. if (frmCondition.conditionvalue.Value != null&& frmCondition.conditionvalue.Value.ToString()!="")
  297. {
  298. dgvCnas.Rows[e.RowIndex].Cells["Value"].Value = frmCondition.conditionvalue.Value;
  299. //将数据插入到数据源中
  300. var query = syncInstrument.lstFixedValue.Where(s => s.TableName == cnasFixed.TableName && s.ColumnName == cnasFixed.ColumnName).ToList<CnasConditionMapValue>();
  301. if (query.Count >= 1)
  302. {
  303. query[0].Condition = cnasFixed.Condition;
  304. query[0].Value = frmCondition.conditionvalue.Value;
  305. }
  306. else
  307. {
  308. cnasFixed.Value = frmCondition.conditionvalue.Value;
  309. syncInstrument.lstFixedValue.Add(cnasFixed);
  310. }
  311. }
  312. }
  313. }
  314. if (dgvCnas.Rows[e.RowIndex].Cells["condition"].Value.ToString() == "若...则...")
  315. {
  316. CnasConditionMapValue cnasFixed = new CnasConditionMapValue
  317. {
  318. TableName = dgvCnas.Rows[e.RowIndex].Cells["TableName"].Value.ToString(),
  319. ColumnName = dgvCnas.Rows[e.RowIndex].Cells["TableColumn"].Value.ToString(),
  320. Condition = MapCondition.IFThen
  321. };
  322. if (dgvCnas.Rows[e.RowIndex].Cells["Value"].Value != null)
  323. cnasFixed.Value = dgvCnas.Rows[e.RowIndex].Cells["Value"].Value.ToString();
  324. frmIfThenParams frmIfThen = new frmIfThenParams(syncInstrument, cnasFixed);
  325. if (frmIfThen.ShowDialog() == DialogResult.OK)
  326. {
  327. if (frmIfThen.conditionvalue.Value != null && frmIfThen.conditionvalue.Value.ToString() != "")
  328. {
  329. dgvCnas.Rows[e.RowIndex].Cells["Value"].Value = frmIfThen.conditionvalue.Value;
  330. //将数据插入到数据源中
  331. var query = syncInstrument.lstFixedValue.Where(s => s.TableName == cnasFixed.TableName && s.ColumnName == cnasFixed.ColumnName).ToList<CnasConditionMapValue>();
  332. if (query.Count >= 1)
  333. {
  334. query[0].Condition = cnasFixed.Condition;
  335. query[0].Value = frmIfThen.conditionvalue.Value;
  336. }
  337. else
  338. {
  339. cnasFixed.Value = frmIfThen.conditionvalue.Value;
  340. syncInstrument.lstFixedValue.Add(cnasFixed);
  341. }
  342. }
  343. }
  344. }
  345. if (dgvCnas.Rows[e.RowIndex].Cells["condition"].Value.ToString() == "截取")
  346. {
  347. CnasConditionMapValue cnasFixed = new CnasConditionMapValue
  348. {
  349. TableName = dgvCnas.Rows[e.RowIndex].Cells["TableName"].Value.ToString(),
  350. ColumnName = dgvCnas.Rows[e.RowIndex].Cells["TableColumn"].Value.ToString(),
  351. Condition = MapCondition.Split
  352. };
  353. if (dgvCnas.Rows[e.RowIndex].Cells["Value"].Value != null)
  354. cnasFixed.Value = dgvCnas.Rows[e.RowIndex].Cells["Value"].Value.ToString();
  355. frmSplitParam frmSplitParam = new frmSplitParam(cnasFixed);
  356. if (frmSplitParam.ShowDialog() == DialogResult.OK)
  357. {
  358. if (frmSplitParam.conditionvalue.Value != null && frmSplitParam.conditionvalue.Value.ToString() != "")
  359. {
  360. dgvCnas.Rows[e.RowIndex].Cells["Value"].Value = frmSplitParam.conditionvalue.Value;
  361. //将数据插入到数据源中
  362. var query = syncInstrument.lstFixedValue.Where(s => s.TableName == cnasFixed.TableName && s.ColumnName == cnasFixed.ColumnName).ToList<CnasConditionMapValue>();
  363. if (query.Count >= 1)
  364. {
  365. query[0].Condition = cnasFixed.Condition;
  366. query[0].Value = frmSplitParam.conditionvalue.Value;
  367. }
  368. else
  369. {
  370. cnasFixed.Value = frmSplitParam.conditionvalue.Value;
  371. syncInstrument.lstFixedValue.Add(cnasFixed);
  372. }
  373. }
  374. }
  375. }
  376. if (dgvCnas.Rows[e.RowIndex].Cells["condition"].Value.ToString() == "位数截取")
  377. {
  378. CnasConditionMapValue cnasFixed = new CnasConditionMapValue
  379. {
  380. TableName = dgvCnas.Rows[e.RowIndex].Cells["TableName"].Value.ToString(),
  381. ColumnName = dgvCnas.Rows[e.RowIndex].Cells["TableColumn"].Value.ToString(),
  382. Condition = MapCondition.SubString
  383. };
  384. if (dgvCnas.Rows[e.RowIndex].Cells["Value"].Value != null)
  385. cnasFixed.Value = dgvCnas.Rows[e.RowIndex].Cells["Value"].Value.ToString();
  386. frmSplitParamnew frmSplitParam = new frmSplitParamnew(cnasFixed);
  387. if (frmSplitParam.ShowDialog() == DialogResult.OK)
  388. {
  389. if (frmSplitParam.conditionvalue.Value != null && frmSplitParam.conditionvalue.Value.ToString() != "")
  390. {
  391. dgvCnas.Rows[e.RowIndex].Cells["Value"].Value = frmSplitParam.conditionvalue.Value;
  392. //将数据插入到数据源中
  393. var query = syncInstrument.lstFixedValue.Where(s => s.TableName == cnasFixed.TableName && s.ColumnName == cnasFixed.ColumnName).ToList<CnasConditionMapValue>();
  394. if (query.Count >= 1)
  395. {
  396. query[0].Condition = cnasFixed.Condition;
  397. query[0].Value = frmSplitParam.conditionvalue.Value;
  398. }
  399. else
  400. {
  401. cnasFixed.Value = frmSplitParam.conditionvalue.Value;
  402. syncInstrument.lstFixedValue.Add(cnasFixed);
  403. }
  404. }
  405. }
  406. }
  407. if (dgvCnas.Rows[e.RowIndex].Cells["condition"].Value.ToString() == "截断开头(结尾)")
  408. {
  409. CnasConditionMapValue cnasFixed = new CnasConditionMapValue
  410. {
  411. TableName = dgvCnas.Rows[e.RowIndex].Cells["TableName"].Value.ToString(),
  412. ColumnName = dgvCnas.Rows[e.RowIndex].Cells["TableColumn"].Value.ToString(),
  413. Condition = MapCondition.SubstringStartEnd
  414. };
  415. if (dgvCnas.Rows[e.RowIndex].Cells["Value"].Value != null)
  416. cnasFixed.Value = dgvCnas.Rows[e.RowIndex].Cells["Value"].Value.ToString();
  417. frmSubstring frmStartEnd = new frmSubstring(cnasFixed);
  418. if (frmStartEnd.ShowDialog() == DialogResult.OK)
  419. {
  420. if (frmStartEnd.conditionvalue.Value != null && frmStartEnd.conditionvalue.Value.ToString() != "")
  421. {
  422. dgvCnas.Rows[e.RowIndex].Cells["Value"].Value = frmStartEnd.conditionvalue.Value;
  423. //将数据插入到数据源中
  424. var query = syncInstrument.lstFixedValue.Where(s => s.TableName == cnasFixed.TableName && s.ColumnName == cnasFixed.ColumnName).ToList<CnasConditionMapValue>();
  425. if (query.Count >= 1)
  426. {
  427. query[0].Condition = cnasFixed.Condition;
  428. query[0].Value = frmStartEnd.conditionvalue.Value;
  429. }
  430. else
  431. {
  432. cnasFixed.Value = frmStartEnd.conditionvalue.Value;
  433. syncInstrument.lstFixedValue.Add(cnasFixed);
  434. }
  435. }
  436. }
  437. }
  438. if (dgvCnas.Rows[e.RowIndex].Cells["condition"].Value.ToString() == "数值相加(减)")
  439. {
  440. CnasConditionMapValue cnasFixed = new CnasConditionMapValue
  441. {
  442. TableName = dgvCnas.Rows[e.RowIndex].Cells["TableName"].Value.ToString(),
  443. ColumnName = dgvCnas.Rows[e.RowIndex].Cells["TableColumn"].Value.ToString(),
  444. Condition = MapCondition.AddSubtract
  445. };
  446. if (dgvCnas.Rows[e.RowIndex].Cells["Value"].Value != null)
  447. cnasFixed.Value = dgvCnas.Rows[e.RowIndex].Cells["Value"].Value.ToString();
  448. frmAddSubtract frmAddSubtract = new frmAddSubtract(syncInstrument, cnasFixed);
  449. if (frmAddSubtract.ShowDialog() == DialogResult.OK)
  450. {
  451. if (frmAddSubtract.conditionvalue.Value != null && frmAddSubtract.conditionvalue.Value.ToString() != "")
  452. {
  453. dgvCnas.Rows[e.RowIndex].Cells["Value"].Value = frmAddSubtract.conditionvalue.Value;
  454. //将数据插入到数据源中
  455. var query = syncInstrument.lstFixedValue.Where(s => s.TableName == cnasFixed.TableName && s.ColumnName == cnasFixed.ColumnName).ToList<CnasConditionMapValue>();
  456. if (query.Count >= 1)
  457. {
  458. query[0].Condition = cnasFixed.Condition;
  459. query[0].Value = frmAddSubtract.conditionvalue.Value;
  460. }
  461. else
  462. {
  463. cnasFixed.Value = frmAddSubtract.conditionvalue.Value;
  464. syncInstrument.lstFixedValue.Add(cnasFixed);
  465. }
  466. }
  467. }
  468. }
  469. dgvCnas.EndEdit();
  470. }
  471. }
  472. private void btnDelete_Click(object sender, EventArgs e)
  473. {
  474. if (syncInstrument == null) return;
  475. if (syncInstrument.lstFixedValue == null) return;
  476. if (dgvCnas == null) return;
  477. if (dgvCnas.Rows.Count <= 0) return;
  478. foreach (DataGridViewRow dr in dgvCnas.Rows)
  479. {
  480. dr.Cells["condition"].Value = "";
  481. dr.Cells["Value"].Value = "";
  482. }
  483. syncInstrument.lstFixedValue.Clear();
  484. }
  485. private void dgvCnas_CellValueChanged(object sender, DataGridViewCellEventArgs e)
  486. {
  487. if (e.RowIndex <= 0) return;
  488. if (e.ColumnIndex == 0) //此时是“条件”列
  489. {
  490. if (dgvCnas.Rows[e.RowIndex].Cells["TableName"].Value == null) return;
  491. if (dgvCnas.Rows[e.RowIndex].Cells["TableColumn"].Value == null) return;
  492. if (dgvCnas.Rows[e.RowIndex].Cells["DataType"].Value == null) return;
  493. if (dgvCnas.Rows[e.RowIndex].Cells["Condition"].Value == null) return;
  494. //当前列名
  495. string strCurrentTable = dgvCnas.Rows[e.RowIndex].Cells["TableName"].Value.ToString();
  496. string strCurrentColumn = dgvCnas.Rows[e.RowIndex].Cells["TableColumn"].Value.ToString();
  497. string strCurrentType = dgvCnas.Rows[e.RowIndex].Cells["DataType"].Value.ToString();
  498. string strCurrentCondition = dgvCnas.Rows[e.RowIndex].Cells["Condition"].Value.ToString();
  499. string strCurrentValue = dgvCnas.Rows[e.RowIndex].Cells["Value"].Value == null ? "" : dgvCnas.Rows[e.RowIndex].Cells["Value"].Value.ToString();
  500. //将数据插入到数据源中
  501. var query = syncInstrument.lstFixedValue.Where(s => s.TableName == strCurrentTable && s.ColumnName == strCurrentColumn).ToList<CnasConditionMapValue>();
  502. if (query.Count >= 1)
  503. {
  504. GiveConditionByShow(query[0], strCurrentCondition);
  505. }
  506. else
  507. {
  508. CnasConditionMapValue cnasFixed = new CnasConditionMapValue();
  509. cnasFixed.TableName = strCurrentTable;
  510. cnasFixed.ColumnName = strCurrentColumn;
  511. cnasFixed.Value = strCurrentValue;
  512. GiveConditionByShow(cnasFixed, strCurrentCondition);
  513. syncInstrument.lstFixedValue.Add(cnasFixed);
  514. }
  515. }
  516. }
  517. private void dgvCnas_CellClick(object sender, DataGridViewCellEventArgs e)
  518. {
  519. cbxConditionValue.Visible = false;
  520. }
  521. private void ShowConditionValue()
  522. {
  523. Rectangle TmpRect = dgvCnas.GetCellDisplayRectangle(dgvCnas.CurrentCell.ColumnIndex, dgvCnas.CurrentCell.RowIndex, true);
  524. cbxConditionValue.Size = TmpRect.Size;
  525. cbxConditionValue.Top = TmpRect.Top;
  526. cbxConditionValue.Left = TmpRect.Left;
  527. cbxConditionValue.DropDownStyle = ComboBoxStyle.DropDownList;
  528. cbxConditionValue.FormattingEnabled = true;
  529. cbxConditionValue.Visible = true;
  530. if (!this.dgvCnas.Controls.Contains(cbxConditionValue))
  531. this.dgvCnas.Controls.Add(cbxConditionValue);
  532. }
  533. }
  534. }