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; using Stone.WinBiz.BasicData; using Stone.Common; namespace Stone.WinModule.BasicData { public partial class frmBaseMainDetail : Form { public F_Base m_Base = null; public DataRow drData = null; public int type = 1; public frmBaseMainDetail() { InitializeComponent(); } public DialogResult ShowAdd() { type = 1; //新增 this.Text = m_Base.name + "_新增"; return this.ShowDialog(); } public DialogResult ShowAddCopy(int ID) { type = 1; //复制新增 this.Text = m_Base.name + "_新增"; drData = m_Base.GetData(ID); if (drData == null) { throw new Exception("复制的记录不存在,或已经被其他用户删除!"); } SetData(); return this.ShowDialog(); } public DialogResult ShowEdit(int ID) { type = 2; //修改 this.Text = m_Base.name + "_修改"; this.btnAddNewLine.Visible = false; drData = m_Base.GetData(ID); if (drData == null) { throw new Exception("修改的记录不存在,或已经被其他用户删除!"); } SetData(); return this.ShowDialog(); } private void frmBaseMainDetail_Load(object sender, EventArgs e) { } private void btnAddNewLine_Click(object sender, EventArgs e) { try { if (GetData()) { m_Base.Add(drData); Clear(); } } catch (Exception ex) { MyMessageBox.ShowErrorMessage("新增记录失败!详细原因为:" + ex.Message); } } private void btnOK_Click(object sender, EventArgs e) { try { if (GetData()) { if (type == 1) //新增 { m_Base.Add(drData); } else //修改 { m_Base.Edit(drData); } //操作完成后关闭窗口,并返回一个OK信息 this.DialogResult = DialogResult.OK; this.Close(); } } catch (Exception ex) { MyMessageBox.ShowErrorMessage(ex.Message); } } private void btnClose_Click(object sender, EventArgs e) { this.Close(); } #region 继承需要覆写的方法 /// /// 清除所有填写控件中的值(覆写用) /// public virtual void Clear() { } /// /// 为窗口中的控件赋值(覆写用) /// public virtual bool SetData() { if (drData == null) { return false; } else { return true; } } /// /// 取得窗口中控件的值(覆写用) /// public virtual bool GetData() { if (type == 1) { drData = m_Base.dsMain.Tables["Table"].NewRow(); } return true; } #endregion } }