根据DialogResult的返回值判断是否加载数据
private void btnlocate_Click(object sender, EventArgs e) { FrmKanBan kb = new FrmKanBan(); if (dgvsearch.SelectedRows.Count==0) { MessageBox.Show("未选择定位连番,请选择后再进行定位!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } if (dgvsearch.SelectedRows.Count > 1) { MessageBox.Show("只能定位一行,请重新选择!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } if (dgvsearch.SelectedRows.Count == 1) { DialogResult result= MessageBox.Show("是否确定根据表格中选择的连番信息定位?", "系统提示" ,MessageBoxButtons.YesNo); if(result==DialogResult.Yes) { string ReciveTime = dgvsearch.CurrentRow.Cells["接收时间"].Value.ToString(); string ManyNo = dgvsearch.CurrentRow.Cells["连番"].Value.ToString(); string sql = @"update T_BarKanban set ConfigOK1=2, ConfigOK2=2 where Factory=" + kb.factory + " and ConfigOK1='0' and ConfigOK2='0' and Mtime<'" + ReciveTime + "' or(Mtime='" + ReciveTime + "' and Manynumber<'" + ManyNo + "' ) "; DbHelperSQL.ExecuteSql(sql); this.DialogResult = System.Windows.Forms.DialogResult.Yes; this.Close(); } } }
当点击按钮是的时候,给DialogResult赋一个yes值,用于返回后判断。
this.DialogResult = System.Windows.Forms.DialogResult.Yes;
如果返回值是yes,则重新加载数据
private void btnAdjust_Click(object sender, EventArgs e) { Locate loc = new Locate(); loc.ShowDialog(); if(loc.DialogResult==DialogResult.Yes) { FrmKanBan_Load(sender, e); } }