private void ToolBar1_ButtonClick(System.Object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e) { switch (ToolBar1.Buttons.IndexOf(e.Button)) { case 0: //添加数据 Button2_Click(sender, e); if (!Panel1.Visible) { Label3.Text = "添加记录"; TextBox1.Text = ""; TextBox2.Text = ""; NumericUpDown1.Value = 0; NumericUpDown2.Value = 0; NumericUpDown3.Value = 0; CheckBox1.Checked = false; dgSuitFood.Height = dgSuitFood.Height - Panel1.Height - 5; Panel1.Visible = true; this.AcceptButton = Button1; this.CancelButton = Button2; TextBox1.Focus(); } break; case 1: //修改数据 if (!(dgSuitFood.CurrentRowIndex < 0)) { Button2_Click(sender, e); if (!Panel1.Visible) { Label3.Text = "修改记录"; TextBox1.Text = dgSuitFood[dgSuitFood.CurrentRowIndex, 0].ToString(); oldcode = TextBox1.Text; TextBox2.Text = dgSuitFood[dgSuitFood.CurrentRowIndex, 1].ToString(); NumericUpDown1.Text = dgSuitFood[dgSuitFood.CurrentRowIndex, 2].ToString(); NumericUpDown2.Text = dgSuitFood[dgSuitFood.CurrentRowIndex, 3].ToString(); NumericUpDown3.Text = dgSuitFood[dgSuitFood.CurrentRowIndex, 4].ToString(); CheckBox1.Checked = dgSuitFood[dgSuitFood.CurrentRowIndex, 5].ToString() == "1" ? true : false; dgSuitFood.Height = dgSuitFood.Height - Panel1.Height - 5; Panel1.Visible = true; this.AcceptButton = Button1; this.CancelButton = Button2; TextBox1.Focus(); } } break; case 2: //删除当前数据 if (!(dgSuitFood.CurrentRowIndex < 0)) { if (MessageBox.Show("确定要删除当前选中的编号为 " + dgSuitFood[dgSuitFood.CurrentRowIndex, 0].ToString().Trim() + " 的套餐吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes) { //删除操作 if (DelSuit(dgSuitFood[dgSuitFood.CurrentRowIndex, 0].ToString())) { LoadSuitsList(); } } } break; case 4: if (!(dgSuitFood.CurrentRowIndex < 0)) { frmAddSuitFood frmaddsf = new frmAddSuitFood(); frmaddsf.Label1.Text = "套餐名称:" + dgSuitFood[dgSuitFood.CurrentRowIndex, 1] + " " + "套餐金额:" + dgSuitFood[dgSuitFood.CurrentRowIndex, 4].ToString(); frmaddsf.suitcode = dgSuitFood[dgSuitFood.CurrentRowIndex, 0].ToString(); frmaddsf.suitprice = System.Convert.ToDouble(dgSuitFood[dgSuitFood.CurrentRowIndex, 4]); frmaddsf.ShowDialog(); } break; case 6: this.Close(); break; } }
private void ToolBar1_ButtonClick(System.Object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e) { switch (ToolBar1.Buttons.IndexOf(e.Button)) { case 0: //添加数据 Button2_Click(sender, e); if (! Panel1.Visible) { Label3.Text = "添加记录"; TextBox1.Text = ""; TextBox2.Text = ""; NumericUpDown1.Value = 0; NumericUpDown2.Value = 0; NumericUpDown3.Value = 0; CheckBox1.Checked = false; dgSuitFood.Height = dgSuitFood.Height - Panel1.Height - 5; Panel1.Visible = true; this.AcceptButton = Button1; this.CancelButton = Button2; TextBox1.Focus(); } break; case 1: //修改数据 if (! (dgSuitFood.CurrentRowIndex < 0)) { Button2_Click(sender, e); if (! Panel1.Visible) { Label3.Text = "修改记录"; TextBox1.Text = dgSuitFood[dgSuitFood.CurrentRowIndex, 0].ToString(); oldcode = TextBox1.Text; TextBox2.Text = dgSuitFood[dgSuitFood.CurrentRowIndex, 1].ToString(); NumericUpDown1.Text = dgSuitFood[dgSuitFood.CurrentRowIndex, 2].ToString(); NumericUpDown2.Text = dgSuitFood[dgSuitFood.CurrentRowIndex, 3].ToString(); NumericUpDown3.Text = dgSuitFood[dgSuitFood.CurrentRowIndex, 4].ToString(); CheckBox1.Checked = dgSuitFood[dgSuitFood.CurrentRowIndex, 5].ToString() == "1" ? true : false; dgSuitFood.Height = dgSuitFood.Height - Panel1.Height - 5; Panel1.Visible = true; this.AcceptButton = Button1; this.CancelButton = Button2; TextBox1.Focus(); } } break; case 2: //删除当前数据 if (! (dgSuitFood.CurrentRowIndex < 0)) { if (MessageBox.Show("确定要删除当前选中的编号为 " + dgSuitFood[dgSuitFood.CurrentRowIndex, 0].ToString().Trim() + " 的套餐吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes) { //删除操作 if (DelSuit(dgSuitFood[dgSuitFood.CurrentRowIndex, 0].ToString())) { LoadSuitsList(); } } } break; case 4: if (! (dgSuitFood.CurrentRowIndex < 0)) { frmAddSuitFood frmaddsf = new frmAddSuitFood(); frmaddsf.Label1.Text = "套餐名称:" + dgSuitFood[dgSuitFood.CurrentRowIndex, 1] + " " + "套餐金额:" + dgSuitFood[dgSuitFood.CurrentRowIndex, 4].ToString(); frmaddsf.suitcode = dgSuitFood[dgSuitFood.CurrentRowIndex, 0].ToString(); frmaddsf.suitprice = System.Convert.ToDouble(dgSuitFood[dgSuitFood.CurrentRowIndex, 4]); frmaddsf.ShowDialog(); } break; case 6: this.Close(); break; } }