/// <summary>编辑 /// /// </summary> private void DoEdit() { string strMsg = CheckSelect("修改"); if (strMsg != string.Empty) { MessageBox.Show(strMsg); return; } DataGridViewRow drRowEdit = grdData.SelectedRows[0]; CacheTables model = drRowEdit.Tag as CacheTables; if (model == null) { int intKeyID = int.Parse(drRowEdit.Cells[gridmrzId.Name].Value.ToString()); model = m_CacheTablesDAL.GetModel(intKeyID); } if (model != null) { FrmCacheTablesSimpleDialog frmDialog = new FrmCacheTablesSimpleDialog(model, m_lstCacheTables); if (frmDialog.ShowDialog() == DialogResult.OK) { m_lstCacheTables = frmDialog.ListCacheTables; grdData.DataSource = m_lstCacheTables; grdData.Refresh(); } } }
private void btnSave_Click(object sender, EventArgs e) { string strReturnMsg = CheckInput(); if (strReturnMsg != string.Empty) { MessageBox.Show(strReturnMsg); return; } //新增 if (m_CacheTables == null) { string strTableNameValueNew = txtEditTableName.Text.Trim(); if (m_CacheTablesDAL.CalcCount("TableName='" + strTableNameValueNew + "'") > 0) { MessageBox.Show(@"表名已经存在"); return; } CacheTables model = EntityOperateManager.AddEntity <CacheTables>(this.tabPage); int intReturn = m_CacheTablesDAL.Add(model); if (intReturn > 0) { MessageBox.Show(@"添加成功"); model.Id = intReturn; m_lstCacheTables.Add(model); ListCacheTables = m_lstCacheTables; this.DialogResult = DialogResult.OK; } else { MessageBox.Show(@"添加失败"); } } //修改 else { string strTableNameValueEdit = txtEditTableName.Text.Trim(); if (m_CacheTablesDAL.CalcCount(" Id !=" + m_CacheTables.Id + " and TableName='" + strTableNameValueEdit + "'") > 0) { MessageBox.Show(@"表名已经存在"); return; } m_CacheTables = EntityOperateManager.EditEntity(this.tabPage, m_CacheTables); bool blnReturn = m_CacheTablesDAL.Update(m_CacheTables); if (blnReturn) { MessageBox.Show(@"修改成功"); ListCacheTables = m_lstCacheTables; this.DialogResult = DialogResult.OK; } else { MessageBox.Show(@"修改失败"); } } }
private void dataNavigator_PositionChanged(object sender, EventArgs e) { if (dataNavigator.ListInfo == null) { return; } m_CacheTables = m_lstCacheTables [this.dataNavigator.CurrentIndex]; DisplayData(m_CacheTables); }
/// <summary>构造函数 /// /// </summary> /// <param name=model" CacheTables">对象</param> /// <param name="lstCacheTables">对象集合</param> public FrmCacheTablesSimpleDialog(CacheTables modelCacheTables, List <CacheTables> lstCacheTables) { InitializeComponent(); DoInitData(); m_lstCacheTables = lstCacheTables ?? new List <CacheTables>(); m_CacheTablesDAL = GlobalHelp.GetResolve <IBseDAL <CacheTables> >(); this.dataNavigator.Visible = false; if (modelCacheTables != null) { this.dataNavigator.Visible = true; m_CacheTables = modelCacheTables; this.dataNavigator.ListInfo = lstCacheTables.Select(t => t.Id.ToString()).ToList(); m_strIndex = lstCacheTables.FindIndex(t => t.Id == m_CacheTables.Id).ToString(); this.dataNavigator.CurrentIndex = int.Parse(m_strIndex); } }
/// <summary>实体对象值显示至控件 /// /// </summary> /// <param name="model">model</param> private void DisplayData(CacheTables model) { EntityOperateManager.BindAll(this.tabPage, model); }