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 lstSyncInstrument = new List(); //本地存储的仪器数据源 public SyncInstrumentItemInfo currentSyncItem = new SyncInstrumentItemInfo(); //当前正在操作的仪器项 public Dictionary dictInstruTables = new Dictionary(); //当前仪器项的来源表结构 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() { syncInstrumentItem }; } //绑定数据源,填写相关内容 if(lstSyncInstrument.Count!=0) dgvInstrument.DataSource = new BindingList(lstSyncInstrument); } /// /// 保存当前设置到本地 /// /// /// private void btnSave_Click(object sender, EventArgs e) { //将配置好的信息存储到本地文件中 try { bool bIfSaveSuccess = true; if (strMode == "Reference") { if (!CheckIfHaveDateField(new List() { currentSyncItem })) { MessageBox.Show("日期字段不允许为空!"); return; } if (!CheckIfHaveKeyPrimaryField(lstSyncInstrument)) { MessageBox.Show("关键字段不允许为空!"); return; } //1.先加载所有数据 2.替换当前数据 3.重新保存 List 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 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 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; } /// /// 新增仪器 /// /// /// 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(lstSyncInstrument); dgvInstrument.CurrentCell = dgvInstrument.Rows[dgvInstrument.Rows.Count - 1].Cells[0]; dgvInstrument_SelectionChanged(null, null); }; frmSetting.ShowDialog(); } /// /// 删除仪器 /// /// /// 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(); if (lstitem == null) return; else if (lstitem.Count >= 1) { foreach (var item in lstitem) { lstSyncInstrument.Remove(item); } } //绑定数据 dgvInstrument.DataSource = new BindingList(); dgvInstrument.DataSource = new BindingList(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(); } } 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(); 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(currentSyncItem.LstSyncPramas); if(currentSyncItem.SyncInstrumentDSInfo.ServerName!="") btnLoadDBData_Click(sender, e); } else { dgvMapping.DataSource = new BindingList(); } } else { dgvMapping.DataSource =new BindingList(); } } /// /// 切换选中表时发生 /// /// /// 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; } } } /// /// 切换表时发生 /// /// /// 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(); 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(currentSyncItem.LstSyncPramas); //选中最后一行 dgvMapping.CurrentCell = dgvMapping.Rows[dgvMapping.Rows.Count-1].Cells[0]; } /// /// 删除映射 /// /// /// 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(); if (lstDelItems.Count > 0) { foreach (var item in lstDelItems) { currentSyncItem.LstSyncPramas.Remove(item); } dgvMapping.DataSource = new BindingList(currentSyncItem.LstSyncPramas); } } /// /// 配置数据库界面 /// /// /// 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 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(); } break; case -6: MessageBox.Show("请先手动输入表名"); break; default: break; } } /// /// 加载来源和目标数据的数据结构 /// /// /// 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 lstTableName = new List(); 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 lstCnasTables = new List(); 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; } /// /// 手动输入表名时,获取该表的表信息 /// /// 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 lstCnasTables = new List(); 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(); 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(); 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(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; } } /// /// 当双击textBox时,显示ComboBOX用于选择 /// /// /// 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); } } }