private void InitData() { if (!string.IsNullOrEmpty(Request.QueryString["id"])) { int id = Int32.Parse(Request.QueryString["id"]); CMS.Model.CMS_Product model = new CMS.Model.CMS_Product(); CMS.DAL.CMS_Product dal = new CMS.DAL.CMS_Product(); model = dal.GetModel(id); string ProductImg = model.CMS_ProductImg; string ProductName = model.CMS_ProductName; StringBuilder str = new StringBuilder(); str.Append("<a href='" + ProductImg + "' title=\"" + ProductName + "\">"); str.Append("<img alt=\"" + ProductName + "\" src=\"" + ProductImg + "\" Width=\"300\" Height=\"300\" class=\"photo\"/>"); str.Append("</a>"); this.lblimgproduct.Text = str.ToString(); this.lblProductName.Text = model.CMS_ProductName; this.lblProductClass.Text = model.CMS_ProductClassID.ToString(); this.lblContent.Text = model.CMS_ProductContent; } }
protected void lbtnDel_Click(object sender, EventArgs e) { CMS.DAL.CMS_Product dal = new CMS.DAL.CMS_Product(); CMS.Model.CMS_Product model = new CMS.Model.CMS_Product(); for (int i = 0; i < gvdataList.Rows.Count; i++) { Label label = (Label)gvdataList.Rows[i].FindControl("lb_id"); int id = Convert.ToInt32(label.Text); CheckBox cb = (CheckBox)gvdataList.Rows[i].FindControl("cb_id"); if (cb.Checked) { model = dal.GetModel(id); //删除图片 DeleteFile(model.CMS_ProductImg); //保存日志 // SaveLogs("[资讯模块]删除文章:" + model.Title); //删除记录 //bll.Delete(kindId, id); dal.Delete(id); } } JscriptPrint("批量删除成功啦!", "ProductsList.aspx", "Success"); }
protected void btnSave_Click(object sender, EventArgs e) { int ID = int.Parse(this.hdfid.Value); string CMS_ProductName = this.txtProductName.Text; int CMS_ProductClassID = int.Parse(this.ddlProductClass.SelectedValue); string CMS_ProductContent = this.txtContent.Value; string CMS_ProductImg = this.txtProductImg.Text; DateTime CMS_AddTime = DateTime.Now; ; string CMS_Puter = this.txtPuter.Text; int CMS_IsSlide = (cbxIsSlide.Checked)?1:0; CMS.Model.CMS_Product model = new CMS.Model.CMS_Product(); model.ID = ID; model.CMS_ProductName = CMS_ProductName; model.CMS_ProductClassID = CMS_ProductClassID; model.CMS_ProductContent = CMS_ProductContent; model.CMS_ProductImg = CMS_ProductImg; model.CMS_AddTime = CMS_AddTime; model.CMS_Puter = CMS_Puter; model.CMS_IsSlide = CMS_IsSlide; CMS.DAL.CMS_Product bll = new CMS.DAL.CMS_Product(); bll.Update(model); JscriptPrint("产品信息修改成功!", "ProductsList.aspx", "Success"); }
/// <summary> /// 得到一个对象实体 /// </summary> public CMS.Model.CMS_Product DataRowToModel(DataRow row) { CMS.Model.CMS_Product model = new CMS.Model.CMS_Product(); if (row != null) { if (row["ID"] != null && row["ID"].ToString() != "") { model.ID = int.Parse(row["ID"].ToString()); } if (row["CMS_ProductName"] != null) { model.CMS_ProductName = row["CMS_ProductName"].ToString(); } if (row["CMS_ProductClassID"] != null && row["CMS_ProductClassID"].ToString() != "") { model.CMS_ProductClassID = int.Parse(row["CMS_ProductClassID"].ToString()); } if (row["CMS_ProductContent"] != null) { model.CMS_ProductContent = row["CMS_ProductContent"].ToString(); } if (row["CMS_ProductImg"] != null) { model.CMS_ProductImg = row["CMS_ProductImg"].ToString(); } if (row["CMS_AddTime"] != null && row["CMS_AddTime"].ToString() != "") { model.CMS_AddTime = DateTime.Parse(row["CMS_AddTime"].ToString()); } if (row["CMS_Puter"] != null) { model.CMS_Puter = row["CMS_Puter"].ToString(); } if (row["CMS_IsSlide"] != null && row["CMS_IsSlide"].ToString() != "") { model.CMS_IsSlide = int.Parse(row["CMS_IsSlide"].ToString()); } } return model; }
/// <summary> /// 得到一个对象实体 /// </summary> public CMS.Model.CMS_Product GetModel(int ID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 "); strSql.Append(" ID,CMS_ProductName,CMS_ProductClassID,CMS_ProductContent,CMS_ProductImg,CMS_AddTime,CMS_Puter,CMS_IsSlide "); strSql.Append(" from CMS_Product "); strSql.Append(" where ID=" + ID + ""); CMS.Model.CMS_Product model = new CMS.Model.CMS_Product(); DataSet ds = DbHelperSQL.Query(strSql.ToString()); if (ds.Tables[0].Rows.Count > 0) { return DataRowToModel(ds.Tables[0].Rows[0]); } else { return null; } }