private void btnSave_Click(object sender, EventArgs e) { string strSql = null; PayType pt = new PayType(); if (String.IsNullOrEmpty(txtPayTypeName.Text.Trim())) { MessageBox.Show("支付方式不许为空!", "软件提示"); txtPayTypeName.Focus(); return; } SetParametersValue(); if (this.Tag.ToString() == "Add") { strSql = "INSERT INTO PayType(PayTypeCode,PayTypeName) "; strSql += "VALUES(@PayTypeCode,@PayTypeName)"; if (pt.Insert(dal, strSql)) { formPayType.dgvPayType.DataSource = pt.GetDataTable("PayType", ""); if (MessageBox.Show("保存成功,是否继续添加?", "软件提示", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes) { txtPayTypeCode.Text = useful.BuildCode("PayType", "", "PayTypeCode", "", 2); txtPayTypeName.Text = ""; txtPayTypeName.Focus(); } else { this.Close(); } } else { MessageBox.Show("保存失败!", "软件提示"); } } if (this.Tag.ToString() == "Edit") { strSql = "Update PayType Set PayTypeName = @PayTypeName Where PayTypeCode = @PayTypeCode"; if (pt.Update(dal, strSql)) { formPayType.dgvPayType.DataSource = pt.GetDataTable("PayType", ""); MessageBox.Show("保存成功!", "软件提示"); this.Close(); } else { MessageBox.Show("保存失败!", "软件提示"); } } }
private void FormPayType_Load(object sender, EventArgs e) { dgvPayType.DataSource = pt.GetDataTable("PayType", ""); }