private void btnSave_Click(object sender, EventArgs e) { GoodsType gt = new GoodsType(); string strSql = null; if (String.IsNullOrEmpty(txtGoodsTypeName.Text.Trim())) { MessageBox.Show("类别名称不许为空!", "软件提示"); txtGoodsTypeName.Focus(); return; } SetParametersValue(); if (this.Tag.ToString() == "Add") { strSql = "INSERT INTO GoodsType(GoodsTypeCode,GoodsTypeName) "; strSql += "VALUES(@GoodsTypeCode,@GoodsTypeName)"; if (gt.Insert(dal, strSql) == true) { formGoodsType.dgvGoodsType.DataSource = gt.GetDataTable("GoodsType", ""); if (MessageBox.Show("保存成功,是否继续添加?", "软件提示", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes) { txtGoodsTypeCode.Text = useful.BuildCode("GoodsType", "", "GoodsTypeCode", "", 2); txtGoodsTypeName.Text = ""; txtGoodsTypeName.Focus(); } else { this.Close(); } } else { MessageBox.Show("保存失败!", "软件提示"); } } if (this.Tag.ToString() == "Edit") { strSql = "Update GoodsType Set GoodsTypeName = @GoodsTypeName Where GoodsTypeCode = @GoodsTypeCode"; if (gt.Update(dal, strSql) == true) { formGoodsType.dgvGoodsType.DataSource = gt.GetDataTable("GoodsType", ""); MessageBox.Show("保存成功!", "软件提示"); this.Close(); } else { MessageBox.Show("保存失败!", "软件提示"); } } }
private void FormGoodsType_Load(object sender, EventArgs e) { dgvGoodsType.DataSource = gt.GetDataTable("GoodsType", ""); }