|
- using CnasSynchronusClient;
- using CnasSynchrousModel;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
-
- namespace CNAS_DBSync
- {
- public partial class frmIfThenParams : Form
- {
- private SyncInstrumentItemInfo syncInstrument = new SyncInstrumentItemInfo();
- public CnasConditionMapValue conditionvalue = new CnasConditionMapValue();
- public frmIfThenParams(SyncInstrumentItemInfo syncInstrument, CnasConditionMapValue conditionvalue)
- {
- InitializeComponent();
-
- this.conditionvalue = conditionvalue;
- this.syncInstrument = syncInstrument;
- }
-
- private void frmIfThenParams_Load(object sender, EventArgs e)
- {
- if (conditionvalue == null) return;
-
- string strCondition = conditionvalue.Condition.ToString();
- this.groupBox1.Text = $"条件<{strCondition}>";
-
- //加载所有来源数据库的列名
- InstrumentData instrumentData = InstrumentDataFact.CreateInstrumentDataSource(syncInstrument.SyncInstrumentDSInfo, new object[] { "", "", "" });
- Dictionary<string, DataTable> dictInstruTables = instrumentData.GetInstrumentData();
-
- //来源库的表名
- if (syncInstrument.LstSyncPramas == null || syncInstrument.LstSyncPramas.Count == 0) return;
- string strSourceTableName = syncInstrument.LstSyncPramas[0].SourceTable;
- //绑定ComboBox数据
- if (!dictInstruTables.ContainsKey(strSourceTableName)) return;
- List<string> lstColumns = new List<string>();
- foreach (DataColumn dc in dictInstruTables[strSourceTableName].Columns)
- {
- lstColumns.Add(dc.ColumnName);
- }
- cbxInstrument.DataSource = lstColumns;
- cbxInstrument.ValueMember = "";
-
- //加载旧数据
- string strValue = "";
- if (conditionvalue.Value != null)
- strValue = conditionvalue.Value.ToString();
-
- if (strValue != "")
- {
- //解析字符串,创建datagridviewrow显示
- List<IFThenConditionParams> lstParams = GlobalCommonOperation.AnanlysisIFThenString(strValue);
- if (lstParams.Count > 0)
- {
- cbxInstrument.Text = lstParams[0].ConditionColumnName;
-
- foreach (var conditionparams in lstParams)
- {
- //构建datagridview行数据
- int index = this.dgvIfThen.Rows.Add();
- this.dgvIfThen.Rows[index].Cells[0].Value = conditionparams.ConditionAlgorithm;
- this.dgvIfThen.Rows[index].Cells[1].Value = conditionparams.ConditionColumnValue;
- this.dgvIfThen.Rows[index].Cells[2].Value = conditionparams.ColumnValue;
- }
- }
- }
- }
-
- private void btnAdd_Click(object sender, EventArgs e)
- {
- int index = this.dgvIfThen.Rows.Add();
- this.dgvIfThen.Rows[index].Cells[0].Value = "等于";
- }
-
- private void btnDelete_Click(object sender, EventArgs e)
- {
- this.dgvIfThen.Rows.RemoveAt(dgvIfThen.CurrentCell.RowIndex);
- }
-
- private void btnOK_Click(object sender, EventArgs e)
- {
- //if()
- string strReturnValue = "";
- string strConditionColumn = cbxInstrument.Text.ToString();
- if (strConditionColumn == "") return;
- for (int i = 0; i < dgvIfThen.Rows.Count; i++)
- {
- string strConditionType = this.dgvIfThen.Rows[i].Cells[0].Value==null?"": this.dgvIfThen.Rows[i].Cells[0].Value.ToString();
- string strConditionValue = this.dgvIfThen.Rows[i].Cells[1].Value == null ? "" : this.dgvIfThen.Rows[i].Cells[1].Value.ToString();
- string strResultValue = this.dgvIfThen.Rows[i].Cells[2].Value == null ? "" : this.dgvIfThen.Rows[i].Cells[2].Value.ToString();
-
- if (strConditionValue == "" && strResultValue == "") continue;
- if (!StringIegitimacy(strConditionValue) || !StringIegitimacy(strResultValue))
- {
- MessageBox.Show("输入值存在不被允许的字符,请重新输入。");
- break;
- }
-
- strReturnValue += "IF{" + strConditionColumn + "}{" + strConditionType + "}{" + strConditionValue + "}THEN{" + strResultValue + "};";
- }
- conditionvalue.Value = strReturnValue;
- this.DialogResult = DialogResult.OK;
- this.Close();
- }
-
- /// <summary>
- /// 字符串合法性判断(不允许输入跟解析字符串相同的字符,否则将无法正常解析)
- /// </summary>
- /// <param name="strValue"></param>
- /// <returns></returns>
- public bool StringIegitimacy(string strValue)
- {
- if (strValue.Contains('{') || strValue.Contains('}') || strValue.Contains("IF") || strValue.Contains("THEN") || strValue.Contains(';'))
- return false;
- else
- return true;
- }
- }
- }
|