protected void Page_Load(object sender, EventArgs e) { if (!base.IsPostBack) { if (base.Request["Id"] != null) { this.btnAdd.Visible = false; TB_Company model = this.goodSer.GetModel(Convert.ToInt32(base.Request["Id"])); txtOrderByIndex.Text = model.OrderByIndex.ToString(); this.txtComId.Text = model.ComId; this.txtComCode.Text = model.ComCode; this.txtComName.Text = model.ComName; this.txtComSimpName.Text = model.ComSimpName; this.txtZhuSuo.Text = model.ZhuSuo; this.txtLeiXing.Text = model.LeiXing; this.txtDianHua.Text = model.DianHua; this.txtChuanZhen.Text = model.ChuanZhen; this.txtXinYongCode.Text = model.XinYongCode; this.txtFaRen.Text = model.FaRen; this.txtZhuCeZiBen.Text = model.ZhuCeZiBen; this.txtCreateTime.Text = model.CreateTime.ToString("yyyy-MM-dd"); this.txtStartTime.Text = model.StartTime.ToString("yyyy-MM-dd"); this.txtEndTime.Text = model.EndTime.ToString("yyyy-MM-dd"); this.txtFanWei.Text = model.FanWei; this.txtKaiHuHang.Text = model.KaiHuHang; this.txtKaHao.Text = model.KaHao; this.txtEmail.Text = model.Email; this.txtComUrl.Text = model.ComUrl; } else { this.btnUpdate.Visible = false; } } }
protected void btnAdd_Click(object sender, EventArgs e) { if (this.FormCheck()) { try { string sqlCheck = string.Format("select count(*) from TB_Company where ComCode='{0}'", txtComCode.Text); if (Convert.ToInt32(DBHelp.ExeScalar(sqlCheck)) > 0) { base.ClientScript.RegisterStartupScript(base.GetType(), null, string.Format("<script>alert('公司代码[{0}],已经存在!');</script>", txtComCode.Text)); return; } TB_Company model = getModel(); if (this.goodSer.Add(model) > 0) { base.ClientScript.RegisterStartupScript(base.GetType(), null, "<script>alert('添加成功!');</script>"); Clear(); } else { base.ClientScript.RegisterStartupScript(base.GetType(), null, "<script>alert('添加失败!');</script>"); } } catch (Exception ex) { base.ClientScript.RegisterStartupScript(base.GetType(), null, "<script>alert('" + ex.Message + "!');</script>"); } } }