protected void btnUpdate_Click(object sender, EventArgs e) { if (this.FormCheck()) { try { string sqlCheck = string.Format("select count(*) from TB_CarInfo where CarNo='{0}' AND ID<>{1}", txtCarNo.Text, Request["Id"]); if (Convert.ToInt32(DBHelp.ExeScalar(sqlCheck)) > 0) { base.ClientScript.RegisterStartupScript(base.GetType(), null, string.Format("<script>alert('车牌号[{0}],已经存在!');</script>", txtCarNo.Text)); return; } TB_CarInfo model = getModel(); if (this.caiInfoSer.Update(model)) { base.ClientScript.RegisterStartupScript(base.GetType(), null, "<script>alert('修改成功!');</script>"); } else { base.ClientScript.RegisterStartupScript(base.GetType(), null, "<script>alert('修改失败!');</script>"); } } catch (Exception ex) { base.ClientScript.RegisterStartupScript(base.GetType(), null, "<script>alert('" + ex.Message + "!');</script>"); } } }
protected void Page_Load(object sender, EventArgs e) { if (!base.IsPostBack) { if (base.Request["Id"] != null) { this.btnAdd.Visible = false; TB_CarInfo model = this.caiInfoSer.GetModel(Convert.ToInt32(base.Request["Id"])); if (model.Baoxian.HasValue) { txtBaoxian.Text = model.Baoxian.Value.ToString("yyyy-MM-dd"); } if (model.NianJian.HasValue) { txtNianJian.Text = model.NianJian.Value.ToString("yyyy-MM-dd"); } txtCaiXingShiNo.Text = model.CaiXingShiNo; txtCarEngine.Text = model.CarEngine; txtCarJiaNo.Text = model.CarJiaNo; txtCarModel.Text = model.CarModel; txtCarNo.Text = model.CarNo; txtCarShiBieNO.Text = model.CarShiBieNO; txtOilNumber.Text = model.OilNumber.ToString(); this.ddlIsStop.Text = model.IsStop ? "1" : "0"; } else { this.btnUpdate.Visible = false; } } }
public TB_CarInfo getModel() { TB_CarInfo model = new TB_CarInfo(); if (!string.IsNullOrEmpty(txtBaoxian.Text)) { model.Baoxian = Convert.ToDateTime(txtBaoxian.Text); } if (!string.IsNullOrEmpty(txtNianJian.Text)) { model.NianJian = Convert.ToDateTime(txtNianJian.Text); } model.IsStop = ddlIsStop.Text == "0" ? false : true; model.CaiXingShiNo = txtCaiXingShiNo.Text; model.CarEngine = txtCarEngine.Text; model.CarJiaNo = txtCarJiaNo.Text; model.CarModel = txtCarModel.Text; model.CarNo = txtCarNo.Text; model.CarShiBieNO = txtCarShiBieNO.Text; model.OilNumber = Convert.ToDecimal(txtOilNumber.Text); if (Request["Id"] != null) { model.id = Convert.ToInt32(Request["Id"]); } return(model); }
private void UpdateCarInfo() { TB_CarInfo model = new TB_CarInfo(); model.CarNo = ddlCarNo.Text; if (txtBaoxian.Text != "") { model.Baoxian = Convert.ToDateTime(txtBaoxian.Text); } if (txtNianJian.Text != "") { model.NianJian = Convert.ToDateTime(txtNianJian.Text); } TB_CarInfoService carSer = new TB_CarInfoService(); carSer.UpdateDate(model); }