void Button1Click(object sender, EventArgs e) { //根据是修改还是新增确定操作 if (this.Text == "货品类别-新增") { //确定关闭窗口,将数据保存到数据库中 //FormGoodTypeBLL tt = new FormGoodTypeBLL(); GoodsType gt = new GoodsType(); gt.GoodsTypeName = textBox1.Text.Trim(); if (gt.GoodsTypeName == "") { MessageBox.Show("未输入类别名称!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } int i_Pid = Int32.Parse(comboBoxTreeView1.Tag.ToString()); if (i_Pid == 0) { gt.GoodsTypePID = 1; } else { gt.GoodsTypePID = i_Pid; } GoodsTypeBLL.AddGoodType(gt); this.Close(); } else { //确定关闭窗口,将数据修改后保存到数据库中 //FormGoodTypeBLL tt = new FormGoodTypeBLL(); GoodsType gt = new GoodsType(); gt.GoodsTypeName = textBox1.Text; gt.GoodsTypePID = Int32.Parse(comboBoxTreeView1.Tag.ToString()); gt.GoodsTypeID = GoodsTypeID; GoodsTypeBLL.ModifyGoodType(gt); this.Close(); } }