/// <summary> /// 插入新的数据 /// </summary> /// <param name="vip"></param> /// <returns></returns> public int Insert(VIPTypeInfo vip) { string sql = "insert into membertypeinfo(mtitle,mdiscount,misdelete) values(@title,@discount,0)"; SQLiteParameter[] sp = { new SQLiteParameter("@title",vip.MTitle), new SQLiteParameter("@discount",vip.MDiscount) }; return SqliteHelper.ExcuteNoQuery(sql, sp); }
/// <summary> /// 修改数据 /// </summary> /// <param name="vip"></param> /// <returns></returns> public int Update(VIPTypeInfo vip) { string sql = "update membertypeinfo set mtitle=@title,mdiscount=@discount where mid=@id"; SQLiteParameter[] sp = { new SQLiteParameter("@id",vip.MId), new SQLiteParameter("@title",vip.MTitle), new SQLiteParameter("@discount",vip.MDiscount), }; return SqliteHelper.ExcuteNoQuery(sql, sp); }
private void btnSave_Click(object sender, EventArgs e) { VIPTypeInfo vip = new VIPTypeInfo(); vip.MTitle = txtTitle.Text; vip.MDiscount = Convert.ToDecimal(txtDiscount.Text); if (txtId.Text == "添加时无编号") { //添加功能 btnSave.Text = "添加"; if (bll.Add(vip)) { MessageBox.Show("添加成功!"); Refresh(); } else { MessageBox.Show("添加失败,请稍后重试!"); Refresh(); } } else { //修改功能 vip.MId = Convert.ToInt32(txtId.Text); if (bll.Edit(vip)) { MessageBox.Show("修改成功!"); Refresh(); } else { MessageBox.Show("修改失败!请稍后重试"); Refresh(); } } }
public Boolean Edit(VIPTypeInfo vip) { return(dal.Update(vip) > 0); }
public Boolean Add(VIPTypeInfo vip) { return(dal.Insert(vip) > 0); }