protected void btnSave_Click(object sender, EventArgs e) { try { Spread.BLL.Messages bll = new Spread.BLL.Messages(); Spread.Model.Messages model = new Spread.Model.Messages(); model.Subject = ddlSubject.Value; model.FullName = txtFullName.Value; model.Mail = txtMail.Value; model.Address = txtAddress.Value; model.ZipCode = txtZipCode.Value; model.Province = hdProv.Value; model.City = hdCity.Value; model.Phone = txtPhone.Value; model.Fax = txtFax.Value; model.Question = txtQuestion.Value; model.Type ="中文"; bll.Add(model); //如果没有就如下代码 this.Page.ClientScript.RegisterStartupScript(this.Page.GetType(), "", "<script>alert('提交成功');</script>", true); } catch { this.Page.ClientScript.RegisterStartupScript(this.Page.GetType(), "", "<script>alert('提交失败');</script>", true); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Spread.Model.Messages GetModel(int Id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 Id,Subject,FullName,Mail,Address,ZipCode,Province,City,Phone,Fax,Type,Question,AddTime from Messages "); strSql.Append(" where Id=@Id "); SqlParameter[] parameters = { new SqlParameter("@Id", SqlDbType.Int,4)}; parameters[0].Value = Id; Spread.Model.Messages model = new Spread.Model.Messages(); DataSet ds = DbHelper.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["Id"].ToString() != "") { model.Id = int.Parse(ds.Tables[0].Rows[0]["Id"].ToString()); } model.Subject = ds.Tables[0].Rows[0]["Subject"].ToString(); model.FullName = ds.Tables[0].Rows[0]["FullName"].ToString(); model.Mail = ds.Tables[0].Rows[0]["Mail"].ToString(); model.Address = ds.Tables[0].Rows[0]["Address"].ToString(); model.ZipCode = ds.Tables[0].Rows[0]["ZipCode"].ToString(); model.Province = ds.Tables[0].Rows[0]["Province"].ToString(); model.City = ds.Tables[0].Rows[0]["City"].ToString(); model.Phone = ds.Tables[0].Rows[0]["Phone"].ToString(); model.Fax = ds.Tables[0].Rows[0]["Fax"].ToString(); model.Type = ds.Tables[0].Rows[0]["Type"].ToString(); model.Question = ds.Tables[0].Rows[0]["Question"].ToString(); if (ds.Tables[0].Rows[0]["AddTime"].ToString() != "") { model.AddTime = DateTime.Parse(ds.Tables[0].Rows[0]["AddTime"].ToString()); } return model; } else { return null; } }