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 月之前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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_DBSync
  12. {
  13. public partial class frmIfThenParams : Form
  14. {
  15. private SyncInstrumentItemInfo syncInstrument = new SyncInstrumentItemInfo();
  16. public CnasConditionMapValue conditionvalue = new CnasConditionMapValue();
  17. public frmIfThenParams(SyncInstrumentItemInfo syncInstrument, CnasConditionMapValue conditionvalue)
  18. {
  19. InitializeComponent();
  20. this.conditionvalue = conditionvalue;
  21. this.syncInstrument = syncInstrument;
  22. }
  23. private void frmIfThenParams_Load(object sender, EventArgs e)
  24. {
  25. if (conditionvalue == null) return;
  26. string strCondition = conditionvalue.Condition.ToString();
  27. this.groupBox1.Text = $"条件<{strCondition}>";
  28. //加载所有来源数据库的列名
  29. InstrumentData instrumentData = InstrumentDataFact.CreateInstrumentDataSource(syncInstrument.SyncInstrumentDSInfo, new object[] { "", "", "" });
  30. Dictionary<string, DataTable> dictInstruTables = instrumentData.GetInstrumentData();
  31. //来源库的表名
  32. if (syncInstrument.LstSyncPramas == null || syncInstrument.LstSyncPramas.Count == 0) return;
  33. string strSourceTableName = syncInstrument.LstSyncPramas[0].SourceTable;
  34. //绑定ComboBox数据
  35. if (!dictInstruTables.ContainsKey(strSourceTableName)) return;
  36. List<string> lstColumns = new List<string>();
  37. foreach (DataColumn dc in dictInstruTables[strSourceTableName].Columns)
  38. {
  39. lstColumns.Add(dc.ColumnName);
  40. }
  41. cbxInstrument.DataSource = lstColumns;
  42. cbxInstrument.ValueMember = "";
  43. //加载旧数据
  44. string strValue = "";
  45. if (conditionvalue.Value != null)
  46. strValue = conditionvalue.Value.ToString();
  47. if (strValue != "")
  48. {
  49. //解析字符串,创建datagridviewrow显示
  50. List<IFThenConditionParams> lstParams = GlobalCommonOperation.AnanlysisIFThenString(strValue);
  51. if (lstParams.Count > 0)
  52. {
  53. cbxInstrument.Text = lstParams[0].ConditionColumnName;
  54. foreach (var conditionparams in lstParams)
  55. {
  56. //构建datagridview行数据
  57. int index = this.dgvIfThen.Rows.Add();
  58. this.dgvIfThen.Rows[index].Cells[0].Value = conditionparams.ConditionAlgorithm;
  59. this.dgvIfThen.Rows[index].Cells[1].Value = conditionparams.ConditionColumnValue;
  60. this.dgvIfThen.Rows[index].Cells[2].Value = conditionparams.ColumnValue;
  61. }
  62. }
  63. }
  64. }
  65. private void btnAdd_Click(object sender, EventArgs e)
  66. {
  67. int index = this.dgvIfThen.Rows.Add();
  68. this.dgvIfThen.Rows[index].Cells[0].Value = "等于";
  69. }
  70. private void btnDelete_Click(object sender, EventArgs e)
  71. {
  72. this.dgvIfThen.Rows.RemoveAt(dgvIfThen.CurrentCell.RowIndex);
  73. }
  74. private void btnOK_Click(object sender, EventArgs e)
  75. {
  76. //if()
  77. string strReturnValue = "";
  78. string strConditionColumn = cbxInstrument.Text.ToString();
  79. if (strConditionColumn == "") return;
  80. for (int i = 0; i < dgvIfThen.Rows.Count; i++)
  81. {
  82. string strConditionType = this.dgvIfThen.Rows[i].Cells[0].Value==null?"": this.dgvIfThen.Rows[i].Cells[0].Value.ToString();
  83. string strConditionValue = this.dgvIfThen.Rows[i].Cells[1].Value == null ? "" : this.dgvIfThen.Rows[i].Cells[1].Value.ToString();
  84. string strResultValue = this.dgvIfThen.Rows[i].Cells[2].Value == null ? "" : this.dgvIfThen.Rows[i].Cells[2].Value.ToString();
  85. if (strConditionValue == "" && strResultValue == "") continue;
  86. if (!StringIegitimacy(strConditionValue) || !StringIegitimacy(strResultValue))
  87. {
  88. MessageBox.Show("输入值存在不被允许的字符,请重新输入。");
  89. break;
  90. }
  91. strReturnValue += "IF{" + strConditionColumn + "}{" + strConditionType + "}{" + strConditionValue + "}THEN{" + strResultValue + "};";
  92. }
  93. conditionvalue.Value = strReturnValue;
  94. this.DialogResult = DialogResult.OK;
  95. this.Close();
  96. }
  97. /// <summary>
  98. /// 字符串合法性判断(不允许输入跟解析字符串相同的字符,否则将无法正常解析)
  99. /// </summary>
  100. /// <param name="strValue"></param>
  101. /// <returns></returns>
  102. public bool StringIegitimacy(string strValue)
  103. {
  104. if (strValue.Contains('{') || strValue.Contains('}') || strValue.Contains("IF") || strValue.Contains("THEN") || strValue.Contains(';'))
  105. return false;
  106. else
  107. return true;
  108. }
  109. }
  110. }