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

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