Ejemplo n.º 1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            //判断是添加还是修改!但是无论是添加还是修改,都要进行对象封装
            DishTypeInfo dti = new DishTypeInfo();

            dti.DTitle = txtTitle.Text;

            if (txtId.Text == "添加时无编号")
            {
                //添加
                if (bll.Add(dti))
                {
                    MessageBox.Show("添加成功!");
                }
                else
                {
                    MessageBox.Show("添加失败!请稍后重试");
                }
            }
            else
            {
                //修改
                dti.DId = Convert.ToInt32(txtId.Text);
                if (bll.Exit(dti))
                {
                    MessageBox.Show("修改成功!");
                }
                else
                {
                    MessageBox.Show("修改失败!请稍后重试");
                }
            }

            LoadList();
            btnSave.Text  = "添加";
            txtId.Text    = "添加时无编号";
            txtTitle.Text = "";
        }