protected void btn_OK_Click(object sender, EventArgs e) { if (btn_OK.Text == "编辑") { AllTxtCanWrite(); btn_OK.Text = "确定"; lbl_Type.Text = "编辑"; } else { #region 当按钮文字为“确定”时,执行添加或编辑操作 Entity.Car.Car entity = new Entity.Car.Car(); entity.CarNO = txt_CarNO.Text.Trim(); entity.CreateUser = Request.Cookies["Cookies"].Values["u_id"].ToString(); entity.CreateDate = DateTime.Now; entity.Num = txt_Num.Text.Trim(); //添加新纪录 if (lbl_Type.Text == "添加") { int retstr = carobj.add(entity); switch (retstr.ToString()) { case "1": ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "click", "hiddenDetail();alert('数据添加成功!');", true); break; case "0": ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "click", "hiddenDetail();alert('数据添加失败!');", true); break; case "2": ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "click", "alert('车牌号不能重复!');", true); break; } } //编辑记录 else if (lbl_Type.Text == "编辑") { entity.ID = strSelectedId; entity.UpdateUser = Request.Cookies["Cookies"].Values["u_id"].ToString(); entity.UpdateDate = DateTime.Now; int retstr = carobj.update(entity); switch (retstr.ToString()) { case "1": ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "click", "hiddenDetail();alert('数据编辑成功!');", true); break; case "0": ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "click", "alert('数据编辑失败!');", true); break; case "2": ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "click", "alert('车牌号不能重复!');", true); break; } } Query(); #endregion } }
public int update(Entity.Car.Car entity) { if (!car.IsExist(entity, "1")) { if (car.update(entity)) { return(1);//成功 } else { return(0);//失败 } } else { return(2);//已经存在 } }
public int add(Entity.Car.Car entity) { if (!car.IsExist(entity, "0")) { if (car.add(entity)) { return(1);//成功 } else { return(0);//失败 } } else { return(2);//已经存在 } }