private void button1_Click(object sender, EventArgs e) { if (textBox1.Text.Trim().Length <= 0) { new Warning("请输入类型名称", 图标.Erro).Show(); return; } try { //执行添加 if (type == 1) { this.Text = "添加商品类型"; ProductTypeMDL p = new ProductTypeMDL(); p.PTName = textBox1.Text; int count = ProductTypeBLL.AddProductType(p); if (count > 0) { this.Close(); } } //执行修改 else { this.Text = "修改商品类型"; ProductTypeMDL p = new ProductTypeMDL(); p.PTName = textBox1.Text; p.PTID = Convert.ToInt32(Product.ID); int count = ProductTypeBLL.AlterProductType(p); if (count > 0) { this.Close(); } } } catch (Exception) { MessageBox.Show("发生未只的异常,请联系开发者", "未知异常", MessageBoxButtons.OK, MessageBoxIcon.Error); } }