|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830 |
- using CnasSynchronousCommon;
- using CnasSynchronusClient;
- using CnasSynchrousModel;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.Xml.Linq;
- using System.Xml.Serialization;
-
- namespace CNAS_DBSync
- {
- public delegate void ReferenceChangeSyncParamHanlder(SyncInstrumentItemInfo syncInstrumentItem);
- public partial class frmSyncParams : Form
- {
- public List<SyncInstrumentItemInfo> lstSyncInstrument = new List<SyncInstrumentItemInfo>(); //本地存储的仪器数据源
- public SyncInstrumentItemInfo currentSyncItem = new SyncInstrumentItemInfo(); //当前正在操作的仪器项
- public Dictionary<string, DataTable> dictInstruTables = new Dictionary<string, DataTable>(); //当前仪器项的来源表结构
- private SyncInstrumentItemInfo syncInstrumentItem; //其他调用传递的仪器项
- public ReferenceChangeSyncParamHanlder ParamsChangedDelegate; //传递仪器参数委托
-
- private string strMode = "";
- private string strTableInfoMode = ""; //获取所有表信息的方式;0为自动获取,1为手动输入
-
- public frmSyncParams(SyncInstrumentItemInfo syncInstrumentItem=null)
- {
- InitializeComponent();
-
- dgvInstrument.AutoGenerateColumns = false;
- dgvInstrument.RowHeadersVisible = false;
-
- dgvInstruDS.AutoGenerateColumns = false;
- dgvInstruDS.RowHeadersVisible = false;
-
- dgvCnas.AutoGenerateColumns = false;
- dgvCnas.RowHeadersVisible = false;
-
- dgvMapping.AutoGenerateColumns = false;
- dgvMapping.RowHeadersVisible = false;
-
- if (syncInstrumentItem != null)
- {
- strMode = "Reference";
- this.syncInstrumentItem = syncInstrumentItem;
-
- this.btnAdd.Visible = false;
- this.btnDel.Visible = false;
- }
-
-
- }
-
- private void frmSyncParams_Load(object sender, EventArgs e)
- {
- if (syncInstrumentItem == null)
- {
- lstSyncInstrument = FileOperation.GetLocalSyncInStrumentData();
- }
- else
- {
- lstSyncInstrument = new List<SyncInstrumentItemInfo>() { syncInstrumentItem };
- }
-
- //绑定数据源,填写相关内容
- if(lstSyncInstrument.Count!=0)
- dgvInstrument.DataSource = new BindingList<SyncInstrumentItemInfo>(lstSyncInstrument);
- }
-
- /// <summary>
- /// 保存当前设置到本地
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnSave_Click(object sender, EventArgs e)
- {
- //将配置好的信息存储到本地文件中
- try
- {
- bool bIfSaveSuccess = true;
- if (strMode == "Reference")
- {
- if (!CheckIfHaveDateField(new List<SyncInstrumentItemInfo>() { currentSyncItem }))
- {
- MessageBox.Show("日期字段不允许为空!");
- return;
- }
- if (!CheckIfHaveKeyPrimaryField(lstSyncInstrument))
- {
- MessageBox.Show("关键字段不允许为空!");
- return;
- }
- //1.先加载所有数据 2.替换当前数据 3.重新保存
- List<SyncInstrumentItemInfo> lstDB = FileOperation.GetLocalSyncInStrumentData();
- var item = lstDB.Where(p => p.GUID == currentSyncItem.GUID).SingleOrDefault();
- if (item != null)
- {
- lstDB.Remove(item);
- lstDB.Add(currentSyncItem);
- }
- else
- {
- lstDB.Add(currentSyncItem);
- }
- //重新保存信息
- bIfSaveSuccess=FileOperation.SaveLocalSyncInStrumentData(lstDB);
- //委托发送参数
- this.ParamsChangedDelegate(syncInstrumentItem);
- }
- else
- {
- if (!CheckIfHaveDateField(lstSyncInstrument))
- {
- MessageBox.Show("日期字段不允许为空!");
- return;
- }
- if (!CheckIfHaveKeyPrimaryField(lstSyncInstrument))
- {
- MessageBox.Show("关键字段不允许为空!");
- return;
- }
- bIfSaveSuccess =FileOperation.SaveLocalSyncInStrumentData(lstSyncInstrument);
- }
- if(bIfSaveSuccess)
- MessageBox.Show("保存成功!");
- else
- MessageBox.Show("保存失败!");
- }
- catch (Exception ex)
- {
- MessageBox.Show("保存失败!错误信息为:"+ex.Message.ToString());
- AppLog.Error(ex.Message);
- }
- }
- private bool CheckIfHaveDateField(List<SyncInstrumentItemInfo> lstSyncInstrument)
- {
- bool bIfHave = true;
- foreach (var item in lstSyncInstrument)
- {
- if (item.LstSyncPramas == null) continue;
- if (item.LstSyncPramas.Count <=0) continue;
- if (item.LstSyncPramas.Where(s => s.IfDateField == true).Count() != 1)
- {
- bIfHave = false;
- break;
- }
- }
- return bIfHave;
- }
- private bool CheckIfHaveKeyPrimaryField(List<SyncInstrumentItemInfo> lstSyncInstrument)
- {
- bool bIfHave = true;
- foreach (var item in lstSyncInstrument)
- {
- if (item.LstSyncPramas == null) continue;
- if (item.LstSyncPramas.Count <= 0) continue;
- if (item.LstSyncPramas.Where(s => s.IfPrimaryKey == true).Count() <= 0)
- {
- bIfHave = false;
- break;
- }
- }
- return bIfHave;
- }
- /// <summary>
- /// 新增仪器
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnAdd_Click(object sender, EventArgs e)
- {
- frmSystemSetting frmSetting = new frmSystemSetting(lstSyncInstrument);
-
- frmInstrumentCode frmCode = new frmInstrumentCode(lstSyncInstrument);
- frmSetting.InstrumentDelegate = delegate(SyncInstrumentItemInfo Instrumentitem)
- {
- lstSyncInstrument.Add(Instrumentitem);
-
- //绑定数据
- dgvInstrument.DataSource = new BindingList<SyncInstrumentItemInfo>(lstSyncInstrument);
- dgvInstrument.CurrentCell = dgvInstrument.Rows[dgvInstrument.Rows.Count - 1].Cells[0];
-
- dgvInstrument_SelectionChanged(null, null);
- };
- frmSetting.ShowDialog();
- }
-
-
- /// <summary>
- /// 删除仪器
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnDel_Click(object sender, EventArgs e)
- {
- if (dgvInstrument.Rows.Count <= 0) return;
-
- //当前选中行
- string strInstrumentCode = this.dgvInstrument.Rows[this.dgvInstrument.CurrentRow.Index].Cells[0].Value.ToString();
-
- //找到数据源中数据,删除
- var lstitem = lstSyncInstrument.Where(s => s.Code == strInstrumentCode).ToList<SyncInstrumentItemInfo>();
- if (lstitem == null)
- return;
- else if (lstitem.Count >= 1)
- {
- foreach (var item in lstitem)
- {
- lstSyncInstrument.Remove(item);
- }
- }
-
- //绑定数据
- dgvInstrument.DataSource = new BindingList<SyncInstrumentItemInfo>();
- dgvInstrument.DataSource = new BindingList<SyncInstrumentItemInfo>(lstSyncInstrument);
-
- //dgvInstrument.dgvInstrument_SelectionChanged()
- if (lstSyncInstrument.Count > 0)
- dgvInstrument_SelectionChanged(null, null);
- else
- {
- currentSyncItem = new SyncInstrumentItemInfo();
- dictInstruTables.Clear();
-
- cbxCnas.DataSource = null;
- cbxCnas.Items.Clear();
- cbxInstrument.DataSource = null;
- dgvInstruDS.DataSource = null;
- dgvCnas.DataSource = null;
- dgvMapping.DataSource = new BindingList<SyncParamasInfo>();
- }
- }
-
-
-
- private void dgvInstrument_SelectionChanged(object sender, EventArgs e)
- {
- if (dgvInstrument.Rows.Count <= 0|| dgvInstrument.Rows[dgvInstrument.CurrentRow.Index].Cells[0].Value == null)
- {
- currentSyncItem = new SyncInstrumentItemInfo();
- return;
- }
-
- //清空绑定
- cbxCnas.DataSource = null;
- cbxInstrument.DataSource = null;
- dgvInstruDS.DataSource = null;
- dgvCnas.DataSource = null;
-
- //当前选中单元格
- string strInstrumentCode = this.dgvInstrument.Rows[this.dgvInstrument.CurrentRow.Index].Cells[0].Value.ToString();
- var lstInstrument = lstSyncInstrument.Where(s => s.Code == strInstrumentCode).ToList<SyncInstrumentItemInfo>();
- if (lstInstrument.Count == 1)
- {
- currentSyncItem = lstInstrument[0];
-
- if (!string.IsNullOrWhiteSpace(currentSyncItem.CnasInstrumentColumn))
- txtInstrumentColumn.Text = currentSyncItem.CnasInstrumentColumn;
- else
- txtInstrumentColumn.Text = "";
-
- if (currentSyncItem.SyncInstrumentDSInfo != null&& currentSyncItem.SyncInstrumentDSInfo.InstrumentDataSourceType!=DataSourceType.None)
- {
- dgvMapping.DataSource = new BindingList<SyncParamasInfo>(currentSyncItem.LstSyncPramas);
- if(currentSyncItem.SyncInstrumentDSInfo.ServerName!="")
- btnLoadDBData_Click(sender, e);
- }
- else
- {
- dgvMapping.DataSource = new BindingList<SyncParamasInfo>();
- }
- }
- else
- {
- dgvMapping.DataSource =new BindingList<SyncParamasInfo>();
- }
- }
- /// <summary>
- /// 切换选中表时发生
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void cbxInstrument_SelectedIndexChanged(object sender, EventArgs e)
- {
- if (cbxInstrument.Text == null) return;
-
- string strTableName_Instru = cbxInstrument.Text.ToString();
- if (dictInstruTables.ContainsKey(strTableName_Instru))
- {
- DataTable dt = dictInstruTables[strTableName_Instru];
- if (dt != null)
- {
- DataTable dtInstruShow = new DataTable();
- dtInstruShow.Columns.Add("InstruFieldName");
- dtInstruShow.Columns.Add("InstruDataType");
-
- foreach (DataColumn dc in dt.Columns)
- {
- dtInstruShow.Rows.Add(new object[] { dc.ColumnName,dc.DataType});
- }
-
- dgvInstruDS.DataSource = dtInstruShow;
- }
- }
- }
-
- /// <summary>
- /// 切换表时发生
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void cbxCnas_SelectedIndexChanged(object sender, EventArgs e)
- {
- if (cbxCnas.Text == null) return;
-
- string strTableName_Cnas = cbxCnas.Text.ToString();
-
- //if (currentSyncItem.CnasInstrumentColumn != null && currentSyncItem.CnasInstrumentColumn != "")
- //{
- // DialogResult dr = MessageBox.Show("已存在配置完成的CNAS仪器对应列,切换表将导致该配置失效,是否继续?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
- // if (dr == DialogResult.No)
- // {
- // return;
- // }
- //}
-
- //从数据库中加载数据表结构
- DataTable dtTableStruct = CnasDataOperationFact.CnasDataOperation().GetCNASTablesStruct(strTableName_Cnas,currentSyncItem.SyncTargetDBInfo);
- if (dtTableStruct != null)
- {
- DataTable dtCnasShow = new DataTable();
- dtCnasShow.Columns.Add("CnasFieldName");
- dtCnasShow.Columns.Add("CnasDataType");
- foreach (DataColumn dc in dtTableStruct.Columns)
- {
- dtCnasShow.Rows.Add(new object[] { dc.ColumnName ,dc.DataType});
- }
-
- dgvCnas.DataSource = dtCnasShow;
-
-
- //绑定数据
- cbxCNASColumn.DataSource = dtCnasShow.Copy();
- cbxCNASColumn.DisplayMember = "CnasFieldName";
- cbxCNASColumn.ValueMember = "CnasFieldName";
-
- if (dtTableStruct.Columns.Count > 0)
- {
- if (!string.IsNullOrWhiteSpace(currentSyncItem.CnasInstrumentColumn)&&dtTableStruct.Columns.Contains(currentSyncItem.CnasInstrumentColumn))
- {
- cbxCNASColumn.Text = this.txtInstrumentColumn.Text = currentSyncItem.CnasInstrumentColumn;
- }
- else
- {
- cbxCNASColumn.Text = this.txtInstrumentColumn.Text = "";
- }
- }
- }
- }
-
- //增加映射
- private void btnAddMapping_Click(object sender, EventArgs e)
- {
- if (cbxInstrument.Text == null) return;
- if (cbxCnas.Text == null) return;
- if (dgvInstruDS.Rows.Count <= 0) return;
- if (dgvCnas.Rows.Count <= 0) return;
-
- SyncParamasInfo syncParamas = new SyncParamasInfo();
- if (currentSyncItem.LstSyncPramas == null) currentSyncItem.LstSyncPramas = new List<SyncParamasInfo>();
-
- if (dgvCnas.Rows[dgvCnas.CurrentCell.RowIndex].Cells[0].Value.ToString().ToUpper() == "ID")
- {
- MessageBox.Show("该字段为CNAS数据库保留字段,不允许插入数据,请重新选择!");
- return;
- }
-
- //仪器表名和选中行
- syncParamas.SourceTable = cbxInstrument.Text.ToString().ToUpper();
- syncParamas.SourceField = dgvInstruDS.Rows[dgvInstruDS.CurrentCell.RowIndex].Cells[0].Value.ToString().ToUpper();
- syncParamas.DataType = dgvInstruDS.Rows[dgvInstruDS.CurrentCell.RowIndex].Cells[1].Value.ToString().ToUpper();
- //CNAS表名和选中行
- syncParamas.TargetTable = cbxCnas.Text.ToString().ToUpper();
- syncParamas.TargetField = dgvCnas.Rows[dgvCnas.CurrentCell.RowIndex].Cells[0].Value.ToString().ToUpper();
-
- //验证数据合法性
- SyncParamsOperation paramsOperation = new SyncParamsOperation();
- if (paramsOperation.CheckTableIfRepeat(currentSyncItem.LstSyncPramas, syncParamas.SourceTable, syncParamas.TargetTable))
- {
- MessageBox.Show("已存在不同表单映射数据,无法添加!");
- return;
- }
- //if (paramsOperation.CheckSourceFieldRepeat(currentSyncItem.LstSyncPramas, syncParamas.SourceTable, syncParamas.SourceField))
- //{
- // MessageBox.Show("仪器数据源字段已分配,请重新选择!");
- // return;
- //}
- if (paramsOperation.CheckTargetFieldRepeat(currentSyncItem.LstSyncPramas, syncParamas.TargetTable, syncParamas.TargetField))
- {
- MessageBox.Show("CNAS端数据字段已分配,请重新选择!");
- return;
- }
- if (paramsOperation.CheckTargetKeepField(syncParamas.TargetField))
- {
- MessageBox.Show("CNAS端数据字段为保留字段,请重新选择!");
- return;
- }
-
- //绑定数据
- currentSyncItem.LstSyncPramas.Add(syncParamas);
- dgvMapping.DataSource= new BindingList<SyncParamasInfo>(currentSyncItem.LstSyncPramas);
- //选中最后一行
- dgvMapping.CurrentCell = dgvMapping.Rows[dgvMapping.Rows.Count-1].Cells[0];
- }
-
- /// <summary>
- /// 删除映射
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnDelMap_Click(object sender, EventArgs e)
- {
- //当前选中项
- if (dgvMapping.CurrentCell == null) return;
- string strSourceField = dgvMapping.Rows[dgvMapping.CurrentCell.RowIndex].Cells["InstrumentField"].Value.ToString();
- string strTargetField = dgvMapping.Rows[dgvMapping.CurrentCell.RowIndex].Cells["CnasField"].Value.ToString();
-
- var lstDelItems = currentSyncItem.LstSyncPramas.Where(s => s.SourceField == strSourceField && s.TargetField == strTargetField).ToList<SyncParamasInfo>();
- if (lstDelItems.Count > 0)
- {
- foreach (var item in lstDelItems)
- {
- currentSyncItem.LstSyncPramas.Remove(item);
- }
-
- dgvMapping.DataSource = new BindingList<SyncParamasInfo>(currentSyncItem.LstSyncPramas);
- }
- }
- /// <summary>
- /// 配置数据库界面
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnDatabaseConfig_Click(object sender, EventArgs e)
- {
- frmDatabaseParams frmDatabase = new frmDatabaseParams(currentSyncItem);
- frmDatabase.InstrumentDelegate = delegate (SyncInstrumentItemInfo Instrumentitem)
- {
- this.currentSyncItem = Instrumentitem;
- };
- frmDatabase.InstrumentItemData = delegate (Dictionary<string, DataTable> dict)
- {
- //this.dictInstruTables = dict;
- };
- frmDatabase.ShowDialog();
-
- //加载数据
- if ((currentSyncItem.SyncInstrumentDSInfo.Host!=null&& currentSyncItem.SyncInstrumentDSInfo.Host.Length>0) || (currentSyncItem.SyncInstrumentDSInfo.Path!=null&& currentSyncItem.SyncInstrumentDSInfo.Path.Length>0))
- btnLoadDBData_Click(null, null);
- }
-
- private void btnLoadDBData_Click(object sender, EventArgs e)
- {
-
- string strInstrumentCode = this.dgvInstrument.Rows[this.dgvInstrument.CurrentRow.Index].Cells[0].Value.ToString();
-
- strTableInfoMode = FileOperation.GetSystemFormatConfigData(strInstrumentCode).TableInfoMode;
- if (strTableInfoMode == "1")
- {
- cbxInstrument.DropDownStyle = ComboBoxStyle.DropDown;
- //cbxCnas.DropDownStyle = ComboBoxStyle.DropDown;
- }
- int iReturn = 0;
- if (strTableInfoMode=="0")
- iReturn=LoadSourceAndTargetData(true);
- else
- iReturn= LoadSourceAndTargetData();
- switch (iReturn)
- {
- case -1:
- MessageBox.Show("未能成功获取设备数据库配置信息,请配置后重试!");
- break;
- case -2:
- MessageBox.Show("未能成功获取CNAS数据库配置信息,请配置后重试!");
- break;
- case -3:
- MessageBox.Show("未能成功获取仪器数据信息,请配置后重试!");
- break;
- case -4:
- MessageBox.Show("未能成功获取CNAS数据信息,请配置后重试!");
- break;
- case -5:
- DialogResult dr = MessageBox.Show("检测到数据连接配置已经修改,是否全部删除已经分配的字段映射?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
- if (dr == DialogResult.Yes)
- {
- //此时将全部删除已经分配的映射字段
- currentSyncItem.LstSyncPramas.Clear();
- currentSyncItem.lstFixedValue.Clear();
-
- dgvMapping.DataSource = new BindingList<SyncParamasInfo>();
- }
- break;
- case -6:
- MessageBox.Show("请先手动输入表名");
- break;
- default:
- break;
- }
- }
-
- /// <summary>
- /// 加载来源和目标数据的数据结构
- /// </summary>
- /// <param name="bIfLoading"></param>
- /// <returns></returns>
- public int LoadSourceAndTargetData(bool bIfLoading=false)
- {
- //检查配置信息
- if (currentSyncItem.SyncInstrumentDSInfo == null) return -1;
- if (currentSyncItem.SyncTargetDBInfo == null) return -2;
- bool bIfSameTable = true;
-
- //是否需要重新加载来源库
- if (bIfLoading)
- {
- InstrumentData instrumentData = InstrumentDataFact.CreateInstrumentDataSource(currentSyncItem.SyncInstrumentDSInfo, new object[] { "", "", "" });
- dictInstruTables = instrumentData.GetInstrumentData();
- }
- if (dictInstruTables.Count <= 0) return -3;
-
- //绑定ComboBox
- List<string> lstTableName = new List<string>();
- foreach (var item in dictInstruTables)
- {
- lstTableName.Add(item.Key);
- }
-
- cbxInstrument.DataSource = lstTableName;
- cbxInstrument.ValueMember = "";
-
- if (currentSyncItem.LstSyncPramas != null && currentSyncItem.LstSyncPramas.Count > 0)
- {
- if (lstTableName.Contains(currentSyncItem.LstSyncPramas[0].SourceTable) || lstTableName.Contains(currentSyncItem.LstSyncPramas[0].SourceTable.ToUpper()) || lstTableName.Contains(currentSyncItem.LstSyncPramas[0].SourceTable.ToLower()))
- cbxInstrument.Text = currentSyncItem.LstSyncPramas[0].SourceTable;
- else
- bIfSameTable = false;
- }
-
- //获取CNAS配置的数据库连接信息
- DataTable dtCNAS = CnasDataOperationFact.CnasDataOperation().GetAllCNASTablesName(currentSyncItem.SyncTargetDBInfo);
- if (dtCNAS != null && dtCNAS.Rows.Count > 0)
- {
- List<string> lstCnasTables = new List<string>();
- foreach (DataRow dr in dtCNAS.Rows)
- {
- if (dtCNAS.Columns.Contains("TABNAME"))
- lstCnasTables.Add(dr["TABNAME"].ToString());
- else if (dtCNAS.Columns.Contains("table_name"))
- lstCnasTables.Add(dr["table_name"].ToString());
- }
-
- cbxCnas.DataSource = lstCnasTables;
- cbxCnas.ValueMember = "";
-
- if (currentSyncItem.LstSyncPramas != null && currentSyncItem.LstSyncPramas.Count > 0)
- {
- if (lstCnasTables.Contains(currentSyncItem.LstSyncPramas[0].TargetTable) || lstCnasTables.Contains(currentSyncItem.LstSyncPramas[0].TargetTable.ToUpper()) || lstCnasTables.Contains(currentSyncItem.LstSyncPramas[0].TargetTable.ToLower()))
- {
- cbxCnas.Text = currentSyncItem.LstSyncPramas[0].TargetTable;
- //cbxCnas_SelectedIndexChanged(null, null);
- }
- else
- bIfSameTable = false;
- }
- }
- else
- return -4;
-
- if (!bIfSameTable)
- {
- return -5;
- }
-
- return 1;
- }
-
- /// <summary>
- /// 手动输入表名时,获取该表的表信息
- /// </summary>
- /// <returns></returns>
- public int LoadSourceAndTargetData()
- {
- if (currentSyncItem.SyncInstrumentDSInfo == null) return -1;
- if (currentSyncItem.SyncTargetDBInfo == null) return -2;
- if (cbxInstrument.Text == "") return -6;
-
- int returnValue = 1;
-
- //根据手动输入来源库的表名加载字段
- InstrumentData instrumentData = InstrumentDataFact.CreateInstrumentDataSource(currentSyncItem.SyncInstrumentDSInfo, new object[] { cbxInstrument.Text, "", "" });
- DataTable dataTableStruct = instrumentData.GetInstrumentDataStruct();
- if (dataTableStruct != null && dataTableStruct.Columns.Count > 0)
- {
- dictInstruTables.Clear();
- dictInstruTables.Add(cbxInstrument.Text, dataTableStruct);
- cbxInstrument_SelectedIndexChanged(null, null);
-
- //return 1;
- }
- else
- {
- returnValue = -3;
- return returnValue;
- }
-
- //获取CNAS配置的数据库连接信息
- DataTable dtCNAS = CnasDataOperationFact.CnasDataOperation().GetAllCNASTablesName(currentSyncItem.SyncTargetDBInfo);
- if (dtCNAS != null && dtCNAS.Rows.Count > 0)
- {
- List<string> lstCnasTables = new List<string>();
- foreach (DataRow dr in dtCNAS.Rows)
- {
- lstCnasTables.Add(dr["TABNAME"].ToString());
- }
-
- cbxCnas.DataSource = lstCnasTables;
- cbxCnas.ValueMember = "";
-
- if (currentSyncItem.LstSyncPramas != null && currentSyncItem.LstSyncPramas.Count > 0)
- {
- if (lstCnasTables.Contains(currentSyncItem.LstSyncPramas[0].TargetTable) || lstCnasTables.Contains(currentSyncItem.LstSyncPramas[0].TargetTable.ToUpper()) || lstCnasTables.Contains(currentSyncItem.LstSyncPramas[0].TargetTable.ToLower()))
- {
- cbxCnas.Text = currentSyncItem.LstSyncPramas[0].TargetTable;
- //cbxCnas_SelectedIndexChanged(null, null);
- }
- else
- returnValue = -5;
- }
- }
- else
- returnValue = -4;
-
- return returnValue;
- }
-
- private void dgvMapping_CellValueChanged(object sender, DataGridViewCellEventArgs e)
- {
- if (dgvMapping.CurrentCell == null) return;
- if (dgvMapping.CurrentCell.ColumnIndex == 2) //此时修改的主健列
- {
- string strSourceField = dgvMapping.Rows[dgvMapping.CurrentCell.RowIndex].Cells["InstrumentField"].Value.ToString();
- string strTargetField = dgvMapping.Rows[dgvMapping.CurrentCell.RowIndex].Cells["CnasField"].Value.ToString();
- string strPrimaryKey = dgvMapping.Rows[dgvMapping.CurrentCell.RowIndex].Cells["PrimaryKey"].Value.ToString();
-
- var lstDelItems = currentSyncItem.LstSyncPramas.Where(s => s.SourceField == strSourceField && s.TargetField == strTargetField).ToList<SyncParamasInfo>();
- if (lstDelItems.Count > 0)
- {
- foreach (var item in lstDelItems)
- {
- item.IfPrimaryKey = strPrimaryKey.ToLower() == "true" ? true : false;
- }
- }
- }
- if (dgvMapping.CurrentCell.ColumnIndex == 3) //此时修改的是日期字段列
- {
- string strSourceField = dgvMapping.Rows[dgvMapping.CurrentCell.RowIndex].Cells["InstrumentField"].Value.ToString();
- string strTargetField = dgvMapping.Rows[dgvMapping.CurrentCell.RowIndex].Cells["CnasField"].Value.ToString();
- string strDateKey = dgvMapping.Rows[dgvMapping.CurrentCell.RowIndex].Cells["DateKey"].Value.ToString();
-
- var lstDelItems = currentSyncItem.LstSyncPramas.Where(s => s.SourceField == strSourceField && s.TargetField == strTargetField).ToList<SyncParamasInfo>();
- if (lstDelItems.Count == 1)
- {
- if (strDateKey.ToLower() == "true")
- {
- //datagridview显示列(只能允许一条数据选择true,所以要把其他行的数据都置为false)
- foreach (DataGridViewRow dgvRow in dgvMapping.Rows)
- {
- if (dgvRow.Cells["DateKey"].Value.ToString().ToLower() == "true")
- dgvRow.Cells["DateKey"].Value = false;
- }
- //内存数据源
- foreach (var item in currentSyncItem.LstSyncPramas)
- {
- if (item.IfDateField)
- item.IfDateField = false;
- }
- lstDelItems[0].IfDateField = true;
- }
- else
- {
- lstDelItems[0].IfDateField = false;
- }
- }
- }
- }
-
- private void dgvMapping_CurrentCellDirtyStateChanged(object sender, EventArgs e)
- {
- if (dgvMapping.IsCurrentCellDirty)
- {
- dgvMapping.CommitEdit(DataGridViewDataErrorContexts.Commit);
- }
- }
-
- private void btnCNASFieldConfig_Click(object sender, EventArgs e)
- {
- if (currentSyncItem == null || currentSyncItem.LstSyncPramas == null || currentSyncItem.LstSyncPramas.Count == 0)
- {
- MessageBox.Show("请先指定至少一个映射字段。");
- return;
- }
- frmCNASValue frmCNAS = new frmCNASValue(currentSyncItem);
- if (frmCNAS.ShowDialog() == DialogResult.OK)
- {
- this.currentSyncItem = frmCNAS.syncInstrument;
- }
- }
-
- private void btnSourceFilter_Click(object sender, EventArgs e)
- {
- if (currentSyncItem == null || currentSyncItem.LstSyncPramas == null || currentSyncItem.LstSyncPramas.Count == 0)
- {
- MessageBox.Show("请先指定至少一个映射字段。");
- return;
- }
- frmSourceFilter frm = new frmSourceFilter(currentSyncItem,strTableInfoMode);
- frm.sourceDataFilterHandler = delegate (SourceDataFilter dataFilter)
- {
- currentSyncItem.SourceFilter = dataFilter;
- };
- frm.ShowDialog();
- }
-
- private void dgvInstrument_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
- {
- if (dgvInstrument.Rows.Count <= 0) return;
- //当前选中单元格
- string strInstrumentCode = this.dgvInstrument.Rows[this.dgvInstrument.CurrentRow.Index].Cells[0].Value.ToString();
-
- frmSystemSetting frmSetting = new frmSystemSetting(lstSyncInstrument, strInstrumentCode);
- frmSetting.InstrumentDelegate = delegate (SyncInstrumentItemInfo Instrumentitem)
- {
- lstSyncInstrument.Add(Instrumentitem);
- //绑定数据
- dgvInstrument.DataSource = new BindingList<SyncInstrumentItemInfo>(lstSyncInstrument);
- dgvInstrument.CurrentCell = dgvInstrument.Rows[dgvInstrument.Rows.Count - 1].Cells[0];
- dgvInstrument_SelectionChanged(null, null);
- };
- frmSetting.ShowDialog();
- }
-
- private void cbxCNASColumn_SelectedIndexChanged(object sender, EventArgs e)
- {
- if (cbxCNASColumn.Visible)
- {
- cbxCNASColumn.Visible = false;
- txtInstrumentColumn.Visible = true;
-
- currentSyncItem.CnasInstrumentColumn = txtInstrumentColumn.Text = cbxCNASColumn.Text;
- }
- }
-
- /// <summary>
- /// 当双击textBox时,显示ComboBOX用于选择
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void txtInstrumentColumn_DoubleClick(object sender, EventArgs e)
- {
- txtInstrumentColumn.Visible = false;
-
- cbxCNASColumn.Top = txtInstrumentColumn.Top;
- cbxCNASColumn.Height = txtInstrumentColumn.Height;
- cbxCNASColumn.Width = txtInstrumentColumn.Width;
- cbxCNASColumn.Location= txtInstrumentColumn.Location;
-
- cbxCNASColumn.Visible = true;
- }
-
- private void cbxCNASColumn_Leave(object sender, EventArgs e)
- {
- if (cbxCNASColumn.Visible)
- {
- txtInstrumentColumn.Visible = true;
- cbxCNASColumn.Visible = false;
- }
- }
-
- private void tsmServiceSetting_Click(object sender, EventArgs e)
- {
- frmServiceConfig frmServiceConfig = new frmServiceConfig();
- frmServiceConfig.ShowDialog();
- }
-
- private void tsmSystemSetting_Click(object sender, EventArgs e)
- {
- //frmSystemSetting frmSystem = new frmSystemSetting();
- //frmSystem.ShowDialog();
-
- //strTableInfoMode = FileOperation.GetSystemFormatConfigData().TableInfoMode;
- //if (strTableInfoMode == "1")
- //{
- // cbxInstrument.DropDownStyle = ComboBoxStyle.DropDown;
- // //cbxCnas.DropDownStyle = ComboBoxStyle.DropDown;
- //}
- //else
- //{
- // cbxInstrument.DropDownStyle = ComboBoxStyle.DropDownList;
- //}
- }
-
- private void tsmSourceSetting_Click(object sender, EventArgs e)
- {
- frmSourceSetting frmSource = new frmSourceSetting();
- frmSource.ShowDialog();
- }
-
- private void tsmHelper_Click(object sender, EventArgs e)
- {
- string strHelpFilePath = FileHelper.getBasePath()+ @"\Helper.CHM";
- //Help.ShowHelp(null, strHelpFilePath, HelpNavigator.TopicId, "1");
- //Help.ShowHelpIndex(this, strHelpFilePath);
- System.Diagnostics.Process.Start(strHelpFilePath);
- }
- }
- }
|