protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (Request.QueryString["NicheID"] != null) { if (Request.QueryString["NicheID"].ToString() != "") { int nicheid = int.Parse(Request.QueryString["NicheID"].ToString()); Maticsoft.BLL.NicheInfo nichebll = new Maticsoft.BLL.NicheInfo(); Maticsoft.Model.NicheInfo nichemodel = nichebll.GetModel(nicheid); Maticsoft.BLL.NicheTypeInfo typebll = new Maticsoft.BLL.NicheTypeInfo(); Maticsoft.Model.NicheTypeInfo typemodel = typebll.GetModel(int.Parse(nichemodel.NicheTypeID.ToString())); lblFatime.Text = Convert.ToDateTime(nichemodel.Fatime.ToString()).ToString("yyyy-MM-dd"); lblNicheContent.Text = nichemodel.NicheContent; lblNicheTitle.Text = nichemodel.NicheTitle; lblNicheTypeTitle.Text = typemodel.NicheTypeTitle; lblWrite.Text = nichemodel.Write; } else { Response.Redirect("NicheList.aspx"); } } else { Response.Redirect("NicheList.aspx"); } } }
protected void datamess_ItemDataBound(object sender, DataListItemEventArgs e) { int index = int.Parse(datamess.DataKeys[e.Item.ItemIndex].ToString()); Maticsoft.BLL.NicheInfo nichebll = new Maticsoft.BLL.NicheInfo(); Maticsoft.Model.NicheInfo nichemodel = nichebll.GetModel(index); Maticsoft.BLL.NicheTypeInfo typebll = new Maticsoft.BLL.NicheTypeInfo(); Maticsoft.Model.NicheTypeInfo typemodel = typebll.GetModel(int.Parse(nichemodel.NicheTypeID.ToString())); ((Label)e.Item.FindControl("lbltype")).Text = typemodel.NicheTypeTitle; }
private void bind() { Maticsoft.BLL.NicheInfo nichebll = new Maticsoft.BLL.NicheInfo(); int index = int.Parse(Request.QueryString["NicheID"].ToString()); Maticsoft.Model.NicheInfo nichemodel = nichebll.GetModel(index); txtfatime.Text = Convert.ToDateTime(nichemodel.Fatime.ToString()).ToString("yyyy-MM-dd"); Image1.ImageUrl = nichemodel.ImageURL; txtKeyword.Text = nichemodel.NicheKey; txtNichecontent.Text = nichemodel.NicheContent; txtNichetitle.Text = nichemodel.NicheTitle; txtwrote.Text = nichemodel.Write; drpNicheType.SelectedValue = nichemodel.NicheTypeID.ToString(); }
private void ShowInfo(int NicheID) { Maticsoft.BLL.NicheInfo bll = new Maticsoft.BLL.NicheInfo(); Maticsoft.Model.NicheInfo model = bll.GetModel(NicheID); this.lblNicheID.Text = model.NicheID.ToString(); this.lblNicheTitle.Text = model.NicheTitle; this.lblNicheKey.Text = model.NicheKey; this.lblFatime.Text = model.Fatime.ToString(); this.lblWrite.Text = model.Write; this.lblImageURL.Text = model.ImageURL; this.lblNicheTypeID.Text = model.NicheTypeID.ToString(); this.lblHitNum.Text = model.HitNum.ToString(); this.lblNicheContent.Text = model.NicheContent; }
protected void btnok_Click(object sender, EventArgs e) { Maticsoft.BLL.NicheInfo nichebll = new Maticsoft.BLL.NicheInfo(); Maticsoft.Model.NicheInfo nichemodel = new Maticsoft.Model.NicheInfo(); if (txtNichetitle.Text.Trim() == "") { lblNicheTitle.Text = "请填写行业标题"; return; } nichemodel.NicheTitle = txtNichetitle.Text.Trim(); lblNicheTitle.Text = ""; if (txtKeyword.Text.Trim() == "") { lblKeyword.Text = "请填写关键词"; return; } nichemodel.NicheKey = txtKeyword.Text.Trim(); lblKeyword.Text = ""; try { nichemodel.NicheTypeID = int.Parse(drpNicheType.SelectedValue); } catch (Exception e1) { } if (txtwrote.Text.Trim() == "") { lblNichewrite.Text = "请填写发布人"; return; } nichemodel.Write = txtwrote.Text.Trim(); lblNichewrite.Text = ""; if (txtfatime.Text.Trim() == "") { lblfatime.Text = "请填写发布时间"; } nichemodel.Fatime = Convert.ToDateTime(txtfatime.Text.Trim()); lblfatime.Text = ""; nichemodel.ImageURL = Image1.ImageUrl; nichemodel.NicheContent = txtNichecontent.Text.Trim(); nichebll.Add(nichemodel); Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('信息添加成功!')</script>"); txtfatime.Text = string.Empty; txtKeyword.Text = string.Empty; txtNichecontent.Text = string.Empty; txtNichetitle.Text = string.Empty; txtwrote.Text = string.Empty; }
private void bind() { Maticsoft.BLL.NicheInfo nichebll = new Maticsoft.BLL.NicheInfo(); int index = int.Parse(Request.QueryString["NicheID"].ToString()); Maticsoft.Model.NicheInfo nichemodel = nichebll.GetModel(index); Maticsoft.BLL.NicheTypeInfo typebll = new Maticsoft.BLL.NicheTypeInfo(); Maticsoft.Model.NicheTypeInfo typemodel = typebll.GetModel(int.Parse(nichemodel.NicheTypeID.ToString())); lbldatime.Text = Convert.ToDateTime(nichemodel.Fatime.ToString()).ToString("yyyy-MM-dd"); lblkey.Text = nichemodel.NicheKey; lblNichetitle.Text = nichemodel.NicheTitle; lbltype.Text = typemodel.NicheTypeTitle; lblwrite.Text = nichemodel.Write; Image1.ImageUrl = nichemodel.ImageURL; txtcontent.Text = nichemodel.NicheContent; }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Maticsoft.Model.NicheInfo model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update NicheInfo set "); strSql.Append("NicheTitle=@NicheTitle,"); strSql.Append("NicheKey=@NicheKey,"); strSql.Append("Fatime=@Fatime,"); strSql.Append("Write=@Write,"); strSql.Append("ImageURL=@ImageURL,"); strSql.Append("NicheTypeID=@NicheTypeID,"); strSql.Append("HitNum=@HitNum,"); strSql.Append("NicheContent=@NicheContent"); strSql.Append(" where NicheID=@NicheID"); SqlParameter[] parameters = { new SqlParameter("@NicheID", SqlDbType.Int, 4), new SqlParameter("@NicheTitle", SqlDbType.VarChar, 200), new SqlParameter("@NicheKey", SqlDbType.VarChar, 200), new SqlParameter("@Fatime", SqlDbType.DateTime), new SqlParameter("@Write", SqlDbType.VarChar, 200), new SqlParameter("@ImageURL", SqlDbType.Text), new SqlParameter("@NicheTypeID", SqlDbType.Int, 4), new SqlParameter("@HitNum", SqlDbType.Int, 4), new SqlParameter("@NicheContent", SqlDbType.Text) }; parameters[0].Value = model.NicheID; parameters[1].Value = model.NicheTitle; parameters[2].Value = model.NicheKey; parameters[3].Value = model.Fatime; parameters[4].Value = model.Write; parameters[5].Value = model.ImageURL; parameters[6].Value = model.NicheTypeID; parameters[7].Value = model.HitNum; parameters[8].Value = model.NicheContent; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.NicheInfo GetModel(int NicheID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 NicheID,NicheTitle,NicheKey,Fatime,Write,ImageURL,NicheTypeID,HitNum,NicheContent from NicheInfo "); strSql.Append(" where NicheID=@NicheID"); SqlParameter[] parameters = { new SqlParameter("@NicheID", SqlDbType.Int, 4) }; parameters[0].Value = NicheID; Maticsoft.Model.NicheInfo model = new Maticsoft.Model.NicheInfo(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["NicheID"].ToString() != "") { model.NicheID = int.Parse(ds.Tables[0].Rows[0]["NicheID"].ToString()); } model.NicheTitle = ds.Tables[0].Rows[0]["NicheTitle"].ToString(); model.NicheKey = ds.Tables[0].Rows[0]["NicheKey"].ToString(); if (ds.Tables[0].Rows[0]["Fatime"].ToString() != "") { model.Fatime = DateTime.Parse(ds.Tables[0].Rows[0]["Fatime"].ToString()); } model.Write = ds.Tables[0].Rows[0]["Write"].ToString(); model.ImageURL = ds.Tables[0].Rows[0]["ImageURL"].ToString(); if (ds.Tables[0].Rows[0]["NicheTypeID"].ToString() != "") { model.NicheTypeID = int.Parse(ds.Tables[0].Rows[0]["NicheTypeID"].ToString()); } if (ds.Tables[0].Rows[0]["HitNum"].ToString() != "") { model.HitNum = int.Parse(ds.Tables[0].Rows[0]["HitNum"].ToString()); } model.NicheContent = ds.Tables[0].Rows[0]["NicheContent"].ToString(); return(model); } else { return(null); } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Maticsoft.Model.NicheInfo model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into NicheInfo("); strSql.Append("NicheTitle,NicheKey,Fatime,Write,ImageURL,NicheTypeID,HitNum,NicheContent)"); strSql.Append(" values ("); strSql.Append("@NicheTitle,@NicheKey,@Fatime,@Write,@ImageURL,@NicheTypeID,@HitNum,@NicheContent)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@NicheTitle", SqlDbType.VarChar, 200), new SqlParameter("@NicheKey", SqlDbType.VarChar, 200), new SqlParameter("@Fatime", SqlDbType.DateTime), new SqlParameter("@Write", SqlDbType.VarChar, 200), new SqlParameter("@ImageURL", SqlDbType.Text), new SqlParameter("@NicheTypeID", SqlDbType.Int, 4), new SqlParameter("@HitNum", SqlDbType.Int, 4), new SqlParameter("@NicheContent", SqlDbType.Text) }; parameters[0].Value = model.NicheTitle; parameters[1].Value = model.NicheKey; parameters[2].Value = model.Fatime; parameters[3].Value = model.Write; parameters[4].Value = model.ImageURL; parameters[5].Value = model.NicheTypeID; parameters[6].Value = model.HitNum; parameters[7].Value = model.NicheContent; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
protected void btnSave_Click(object sender, EventArgs e) { string strErr = ""; if (this.txtNicheTitle.Text.Trim().Length == 0) { strErr += "NicheTitle不能为空!\\n"; } if (this.txtNicheKey.Text.Trim().Length == 0) { strErr += "NicheKey不能为空!\\n"; } if (!PageValidate.IsDateTime(txtFatime.Text)) { strErr += "Fatime格式错误!\\n"; } if (this.txtWrite.Text.Trim().Length == 0) { strErr += "Write不能为空!\\n"; } if (this.txtImageURL.Text.Trim().Length == 0) { strErr += "ImageURL不能为空!\\n"; } if (!PageValidate.IsNumber(txtNicheTypeID.Text)) { strErr += "NicheTypeID格式错误!\\n"; } if (!PageValidate.IsNumber(txtHitNum.Text)) { strErr += "HitNum格式错误!\\n"; } if (this.txtNicheContent.Text.Trim().Length == 0) { strErr += "NicheContent不能为空!\\n"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } string NicheTitle = this.txtNicheTitle.Text; string NicheKey = this.txtNicheKey.Text; DateTime Fatime = DateTime.Parse(this.txtFatime.Text); string Write = this.txtWrite.Text; string ImageURL = this.txtImageURL.Text; int NicheTypeID = int.Parse(this.txtNicheTypeID.Text); int HitNum = int.Parse(this.txtHitNum.Text); string NicheContent = this.txtNicheContent.Text; Maticsoft.Model.NicheInfo model = new Maticsoft.Model.NicheInfo(); model.NicheTitle = NicheTitle; model.NicheKey = NicheKey; model.Fatime = Fatime; model.Write = Write; model.ImageURL = ImageURL; model.NicheTypeID = NicheTypeID; model.HitNum = HitNum; model.NicheContent = NicheContent; Maticsoft.BLL.NicheInfo bll = new Maticsoft.BLL.NicheInfo(); bll.Add(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "add.aspx"); }