private void ShowInfo(int _id) { BLL.good_template bll = new BLL.good_template(); Model.good_template model = bll.GetModel(_id); if (model.pics.Count > 0) { foreach (Model.good_template_pic list in model.pics) { if (list.typeId == 1) { txtPicUrl1.Text = list.picUrl; } else if (list.typeId == 2) { txtPicUrl2.Text = list.picUrl; } else if (list.typeId == 3) { txtPicUrl3.Text = list.picUrl; } else if (list.typeId == 4) { txtPicUrl4.Text = list.picUrl; } else if (list.typeId == 5) { txtPicUrl5.Text = list.picUrl; } else if (list.typeId == 6) { txtPicUrl6.Text = list.picUrl; } } } if (!string.IsNullOrEmpty(model.img_url)) { txtImgUrl.Text = model.img_url; } ddlCategoryId.SelectedValue = model.categoryId.ToString(); txtAddTime.Text = model.addTime.ToString("yyyy-MM-dd HH:mm:ss"); txtName.Text = model.name; txtRemark.Text = model.remark; txtSortId.Text = model.sort_id.ToString(); rblIsLock.SelectedValue = model.isLock.ToString(); rblIsDefault.SelectedValue = model.isDefault.ToString(); rblIsAd.SelectedValue = model.isAd.ToString(); //是广告位就显示广告位信息 if (model.isAd == 1) { this.txtSortAd.Text = model.sort_ad.ToString(); if (!string.IsNullOrEmpty(model.img_url1)) { txtImgUrl1.Text = model.img_url1; } } txtGoodId.Text = model.goodId.ToString(); }
//设置操作 protected void rptList_ItemCommand(object source, RepeaterCommandEventArgs e) { ChkAdminLevel("channel_" + this.channel_name + "_list", Vincent._DTcms.DTEnums.ActionEnum.Edit.ToString()); //检查权限 int id = Convert.ToInt32(((HiddenField)e.Item.FindControl("hidId")).Value); BLL.good_template bll = new BLL.good_template(); Model.good_template model = bll.GetModel(id); switch (e.CommandName) { case "lbtnIsAd": if (model.isAd == 1) { bll.UpdateField(id, "isAd=0"); } else { bll.UpdateField(id, "isAd=1"); } break; } this.RptBind(this.category_id, "id>0" + CombSqlTxt(this.keywords, this.islock), "sort_id asc,addTime desc,id desc"); }
private bool DoEdit(int _id) { bool result = false; BLL.good_template bll = new BLL.good_template(); Model.good_template model = bll.GetModel(_id); model.name = txtName.Text.Trim(); model.img_url = txtImgUrl.Text; model.categoryId = Vincent._DTcms.Utils.StrToInt(ddlCategoryId.SelectedValue, 0); //内容摘要提取内容前500个字符 if (!string.IsNullOrEmpty(txtRemark.Text.Trim()) && txtRemark.Text.Trim().Length > 500) { model.remark = Vincent._DTcms.Utils.DropHTML(txtRemark.Text, 500); } else { model.remark = txtRemark.Text; } model.sort_id = Vincent._DTcms.Utils.StrToInt(txtSortId.Text.Trim(), 99); model.isLock = Vincent._DTcms.Utils.StrToInt(this.rblIsLock.SelectedValue, 1); model.isDefault = Vincent._DTcms.Utils.StrToInt(this.rblIsDefault.SelectedValue, 0); #region 一主题只能有一个默认模板 if (model.isDefault == 1) { bll.UpdateField("isDefault=0", "categoryId=" + model.categoryId); } #endregion model.addTime = Vincent._DTcms.Utils.StrToDateTime(txtAddTime.Text.Trim()); model.isAd = Vincent._DTcms.Utils.StrToInt(this.rblIsAd.SelectedValue, 0); if (model.isAd == 1) { model.sort_ad = Vincent._DTcms.Utils.StrToInt(txtSortAd.Text.Trim(), 1); model.img_url1 = this.txtImgUrl1.Text; } else { model.sort_ad = 0; } model.goodId = Vincent._DTcms.Utils.StrToInt(txtGoodId.Text.Trim(), 0); #region 保存图片==================== List <Model.good_template_pic> ls = new List <Model.good_template_pic>(); int[] arry = { 0, 0, 0, 0, 0, 0 }; foreach (Model.good_template_pic m in model.pics) { int i = 1; if ((i + 1) == m.typeId) { arry[i] = m.typeId; } i++; } if (!string.IsNullOrEmpty(txtPicUrl1.Text)) { if (arry[0] > 0) { ls.Add(new Model.good_template_pic { id = ls[0].id, templateId = model.id, addTime = DateTime.Now, isLock = 0, picUrl = this.txtPicUrl1.Text, typeId = 1 }); } else { ls.Add(new Model.good_template_pic { templateId = model.id, addTime = DateTime.Now, isLock = 0, picUrl = this.txtPicUrl1.Text, typeId = 1 }); } } if (!string.IsNullOrEmpty(txtPicUrl2.Text)) { if (arry[1] > 0) { ls.Add(new Model.good_template_pic { id = ls[1].id, templateId = model.id, addTime = DateTime.Now, isLock = 0, picUrl = this.txtPicUrl2.Text, typeId = 2 }); } else { ls.Add(new Model.good_template_pic { templateId = model.id, addTime = DateTime.Now, isLock = 0, picUrl = this.txtPicUrl2.Text, typeId = 2 }); } } if (!string.IsNullOrEmpty(txtPicUrl3.Text)) { if (arry[2] > 0) { ls.Add(new Model.good_template_pic { id = ls[2].id, templateId = model.id, addTime = DateTime.Now, isLock = 0, picUrl = this.txtPicUrl3.Text, typeId = 3 }); } else { ls.Add(new Model.good_template_pic { templateId = model.id, addTime = DateTime.Now, isLock = 0, picUrl = this.txtPicUrl3.Text, typeId = 3 }); } } if (!string.IsNullOrEmpty(txtPicUrl4.Text)) { if (arry[3] > 0) { ls.Add(new Model.good_template_pic { id = ls[3].id, templateId = model.id, addTime = DateTime.Now, isLock = 0, picUrl = this.txtPicUrl4.Text, typeId = 4 }); } else { ls.Add(new Model.good_template_pic { templateId = model.id, addTime = DateTime.Now, isLock = 0, picUrl = this.txtPicUrl4.Text, typeId = 4 }); } } if (!string.IsNullOrEmpty(txtPicUrl5.Text)) { if (arry[4] > 0) { ls.Add(new Model.good_template_pic { id = ls[4].id, templateId = model.id, addTime = DateTime.Now, isLock = 0, picUrl = this.txtPicUrl5.Text, typeId = 5 }); } else { ls.Add(new Model.good_template_pic { templateId = model.id, addTime = DateTime.Now, isLock = 0, picUrl = this.txtPicUrl5.Text, typeId = 5 }); } } if (!string.IsNullOrEmpty(txtPicUrl6.Text)) { if (arry[5] > 0) { ls.Add(new Model.good_template_pic { id = ls[5].id, templateId = model.id, addTime = DateTime.Now, isLock = 0, picUrl = this.txtPicUrl6.Text, typeId = 6 }); } else { ls.Add(new Model.good_template_pic { templateId = model.id, addTime = DateTime.Now, isLock = 0, picUrl = this.txtPicUrl6.Text, typeId = 6 }); } } model.pics = ls; #endregion if (bll.Update(model)) { AddAdminLog(Vincent._DTcms.DTEnums.ActionEnum.Edit.ToString(), "修改" + this.channel_name + "频道内容:" + model.name); //记录日志 result = true; } return(result); }
private bool DoAdd() { bool result = false; Model.good_template model = new Model.good_template(); BLL.good_template bll = new BLL.good_template(); model.categoryId = Vincent._DTcms.Utils.StrToInt(ddlCategoryId.SelectedValue, 0); model.name = txtName.Text.Trim(); model.img_url = txtImgUrl.Text; //内容摘要提取内容前500个字符 if (!string.IsNullOrEmpty(txtRemark.Text.Trim()) && txtRemark.Text.Trim().Length > 500) { model.remark = Vincent._DTcms.Utils.DropHTML(txtRemark.Text, 500); } else { model.remark = txtRemark.Text; } model.sort_id = Vincent._DTcms.Utils.StrToInt(txtSortId.Text.Trim(), 99); model.isLock = Vincent._DTcms.Utils.StrToInt(this.rblIsLock.SelectedValue, 1); model.isDefault = Vincent._DTcms.Utils.StrToInt(this.rblIsDefault.SelectedValue, 0); #region 一主题只能有一个默认模板 if (model.isDefault == 1) { bll.UpdateField("isDefault=0", "categoryId=" + model.categoryId); } #endregion model.addTime = Vincent._DTcms.Utils.StrToDateTime(txtAddTime.Text.Trim()); model.isAd = Vincent._DTcms.Utils.StrToInt(this.rblIsAd.SelectedValue, 0); if (model.isAd == 1) { model.sort_ad = Vincent._DTcms.Utils.StrToInt(txtSortAd.Text.Trim(), 1); model.img_url1 = this.txtImgUrl1.Text; } else { model.sort_ad = 0; } model.goodId = Vincent._DTcms.Utils.StrToInt(txtGoodId.Text.Trim(), 0); #region 保存图片==================== List <Model.good_template_pic> ls = new List <Model.good_template_pic>(); if (!string.IsNullOrEmpty(txtPicUrl1.Text)) { ls.Add(new Model.good_template_pic { addTime = DateTime.Now, isLock = 0, picUrl = this.txtPicUrl1.Text, typeId = 1 }); } else if (!string.IsNullOrEmpty(txtPicUrl2.Text)) { ls.Add(new Model.good_template_pic { addTime = DateTime.Now, isLock = 0, picUrl = this.txtPicUrl1.Text, typeId = 2 }); } else if (!string.IsNullOrEmpty(txtPicUrl3.Text)) { ls.Add(new Model.good_template_pic { addTime = DateTime.Now, isLock = 0, picUrl = this.txtPicUrl1.Text, typeId = 3 }); } else if (!string.IsNullOrEmpty(txtPicUrl4.Text)) { ls.Add(new Model.good_template_pic { addTime = DateTime.Now, isLock = 0, picUrl = this.txtPicUrl1.Text, typeId = 4 }); } else if (!string.IsNullOrEmpty(txtPicUrl5.Text)) { ls.Add(new Model.good_template_pic { addTime = DateTime.Now, isLock = 0, picUrl = this.txtPicUrl1.Text, typeId = 5 }); } else if (!string.IsNullOrEmpty(txtPicUrl6.Text)) { ls.Add(new Model.good_template_pic { addTime = DateTime.Now, isLock = 0, picUrl = this.txtPicUrl1.Text, typeId = 6 }); } model.pics = ls; #endregion if (bll.Add(model) > 0) { AddAdminLog(Vincent._DTcms.DTEnums.ActionEnum.Add.ToString(), "添加" + this.channel_name + "频道内容:" + model.name); //记录日志 result = true; } return(result); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Model.good_template model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into " + databaseprefix + "good_template("); strSql.Append("goodId,categoryId,name,remark,sort_id,addTime,isLock,isDefault,img_url,isAd,sort_ad,img_url1)"); strSql.Append(" values ("); strSql.Append("@goodId,@categoryId,@name,@remark,@sort_id,@addTime,@isLock,@isDefault,@img_url,@isAd,@sort_ad,@img_url1)"); strSql.Append(";set @ReturnValue= @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@goodId", SqlDbType.Int, 4), new SqlParameter("@categoryId", SqlDbType.Int, 4), new SqlParameter("@name", SqlDbType.NVarChar, 50), new SqlParameter("@remark", SqlDbType.NVarChar, 500), new SqlParameter("@sort_id", SqlDbType.Int, 4), new SqlParameter("@addTime", SqlDbType.DateTime), new SqlParameter("@isLock", SqlDbType.Int, 4), new SqlParameter("@isDefault", SqlDbType.Int, 4), new SqlParameter("@img_url", SqlDbType.NVarChar, 255), new SqlParameter("@isAd", SqlDbType.Int, 4), new SqlParameter("@sort_ad", SqlDbType.Int, 4), new SqlParameter("@img_url1", SqlDbType.NVarChar, 255), new SqlParameter("@ReturnValue", SqlDbType.Int) }; parameters[0].Value = model.goodId; parameters[1].Value = model.categoryId; parameters[2].Value = model.name; parameters[3].Value = model.remark; parameters[4].Value = model.sort_id; parameters[5].Value = model.addTime; parameters[6].Value = model.isLock; parameters[7].Value = model.isDefault; parameters[8].Value = model.img_url; parameters[9].Value = model.isAd; parameters[10].Value = model.sort_ad; parameters[11].Value = model.img_url1; parameters[12].Direction = ParameterDirection.Output; List <CommandInfo> sqllist = new List <CommandInfo>(); CommandInfo cmd = new CommandInfo(strSql.ToString(), parameters); sqllist.Add(cmd); //模板图片 if (model.pics != null) { StringBuilder strSql2; foreach (Model.good_template_pic modelt in model.pics) { strSql2 = new StringBuilder(); strSql2.Append("insert into " + databaseprefix + "good_template_pic("); strSql2.Append("templateId,typeId,picUrl,smallPicUrl,addTime,isLock)"); strSql2.Append(" values ("); strSql2.Append("@templateId,@typeId,@picUrl,@smallPicUrl,@addTime,@isLock)"); SqlParameter[] parameters2 = { new SqlParameter("@templateId", SqlDbType.Int, 4), new SqlParameter("@typeId", SqlDbType.Int, 4), new SqlParameter("@picUrl", SqlDbType.NVarChar, 100), new SqlParameter("@smallPicUrl", SqlDbType.NVarChar, 100), new SqlParameter("@addTime", SqlDbType.DateTime), new SqlParameter("@isLock", SqlDbType.Int, 4) }; parameters2[0].Direction = ParameterDirection.InputOutput; parameters2[1].Value = modelt.typeId; parameters2[2].Value = modelt.picUrl; parameters2[3].Value = modelt.smallPicUrl; parameters2[4].Value = modelt.addTime; parameters2[5].Value = modelt.isLock; cmd = new CommandInfo(strSql2.ToString(), parameters2); sqllist.Add(cmd); } } DbHelperSQL.ExecuteSqlTranWithIndentity(sqllist); return((int)parameters[12].Value); }
/// <summary> /// 得到一个对象实体(重载,带事务) /// </summary> public Model.good_template GetModel(SqlConnection conn, SqlTransaction trans, int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id,goodId,categoryId,name,remark,sort_id,addTime,isLock,isDefault,img_url,isAd,sort_ad,img_url1 from " + databaseprefix + "good_template "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = id; Model.good_template model = new Model.good_template(); DataSet ds = DbHelperSQL.Query(conn, trans, strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["id"] != null && ds.Tables[0].Rows[0]["id"].ToString() != "") { model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString()); } if (ds.Tables[0].Rows[0]["goodId"] != null && ds.Tables[0].Rows[0]["goodId"].ToString() != "") { model.goodId = int.Parse(ds.Tables[0].Rows[0]["goodId"].ToString()); } if (ds.Tables[0].Rows[0]["categoryId"] != null && ds.Tables[0].Rows[0]["categoryId"].ToString() != "") { model.categoryId = int.Parse(ds.Tables[0].Rows[0]["categoryId"].ToString()); } if (ds.Tables[0].Rows[0]["name"] != null && ds.Tables[0].Rows[0]["name"].ToString() != "") { model.name = ds.Tables[0].Rows[0]["name"].ToString(); } if (ds.Tables[0].Rows[0]["remark"] != null && ds.Tables[0].Rows[0]["remark"].ToString() != "") { model.remark = ds.Tables[0].Rows[0]["remark"].ToString(); } if (ds.Tables[0].Rows[0]["sort_id"] != null && ds.Tables[0].Rows[0]["sort_id"].ToString() != "") { model.sort_id = int.Parse(ds.Tables[0].Rows[0]["sort_id"].ToString()); } if (ds.Tables[0].Rows[0]["addTime"].ToString() != "") { model.addTime = DateTime.Parse(ds.Tables[0].Rows[0]["addTime"].ToString()); } if (ds.Tables[0].Rows[0]["isLock"] != null && ds.Tables[0].Rows[0]["isLock"].ToString() != "") { model.isLock = int.Parse(ds.Tables[0].Rows[0]["isLock"].ToString()); } if (ds.Tables[0].Rows[0]["isDefault"] != null && ds.Tables[0].Rows[0]["isDefault"].ToString() != "") { model.isDefault = int.Parse(ds.Tables[0].Rows[0]["isDefault"].ToString()); } if (ds.Tables[0].Rows[0]["img_url"] != null && ds.Tables[0].Rows[0]["img_url"].ToString() != "") { model.img_url = ds.Tables[0].Rows[0]["img_url"].ToString(); } if (ds.Tables[0].Rows[0]["isAd"] != null && ds.Tables[0].Rows[0]["isAd"].ToString() != "") { model.isAd = int.Parse(ds.Tables[0].Rows[0]["isAd"].ToString()); } if (ds.Tables[0].Rows[0]["sort_ad"] != null && ds.Tables[0].Rows[0]["sort_ad"].ToString() != "") { model.sort_ad = int.Parse(ds.Tables[0].Rows[0]["sort_ad"].ToString()); } if (ds.Tables[0].Rows[0]["img_url1"] != null && ds.Tables[0].Rows[0]["img_url1"].ToString() != "") { model.img_url1 = ds.Tables[0].Rows[0]["img_url1"].ToString(); } return(model); } else { return(null); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Model.good_template model) { using (SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString)) { conn.Open(); using (SqlTransaction trans = conn.BeginTransaction()) { try { StringBuilder strSql = new StringBuilder(); strSql.Append("update " + databaseprefix + "good_template set "); strSql.Append("goodId=@goodId,"); strSql.Append("categoryId=@categoryId,"); strSql.Append("name=@name,"); strSql.Append("remark=@remark,"); strSql.Append("sort_id=@sort_id,"); strSql.Append("addTime=@addTime,"); strSql.Append("isLock=@isLock,"); strSql.Append("isDefault=@isDefault,"); strSql.Append("img_url=@img_url,"); strSql.Append("isAd=@isAd,"); strSql.Append("sort_ad=@sort_ad,"); strSql.Append("img_url1=@img_url1"); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@goodId", SqlDbType.Int, 4), new SqlParameter("@categoryId", SqlDbType.Int, 4), new SqlParameter("@name", SqlDbType.NVarChar, 50), new SqlParameter("@remark", SqlDbType.NVarChar, 500), new SqlParameter("@sort_id", SqlDbType.Int, 4), new SqlParameter("@addTime", SqlDbType.DateTime), new SqlParameter("@isLock", SqlDbType.Int, 4), new SqlParameter("@isDefault", SqlDbType.Int, 4), new SqlParameter("@img_url", SqlDbType.NVarChar, 255), new SqlParameter("@isAd", SqlDbType.Int, 4), new SqlParameter("@sort_ad", SqlDbType.Int, 4), new SqlParameter("@img_url1", SqlDbType.NVarChar, 255), new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = model.goodId; parameters[1].Value = model.categoryId; parameters[2].Value = model.name; parameters[3].Value = model.remark; parameters[4].Value = model.sort_id; parameters[5].Value = model.addTime; parameters[6].Value = model.isLock; parameters[7].Value = model.isDefault; parameters[8].Value = model.img_url; parameters[9].Value = model.isAd; parameters[10].Value = model.sort_ad; parameters[11].Value = model.img_url1; parameters[12].Value = model.id; DbHelperSQL.ExecuteSql(conn, trans, strSql.ToString(), parameters); //删除已删除的图片 new good_template_pic(databaseprefix).DeleteList(conn, trans, model.pics, model.id); //添加/修改图片 if (model.pics != null) { StringBuilder strSql3; foreach (Model.good_template_pic modelt in model.pics) { strSql3 = new StringBuilder(); if (modelt.id > 0) { strSql3.Append("update " + databaseprefix + "good_template_pic set "); strSql3.Append("templateId=@templateId,"); strSql3.Append("typeId=@typeId,"); strSql3.Append("picUrl=@picUrl,"); strSql3.Append("smallPicUrl=@smallPicUrl,"); strSql3.Append("addTime=@addTime,"); strSql3.Append("isLock=@isLock"); strSql3.Append(" where id=@id"); SqlParameter[] parameters3 = { new SqlParameter("@templateId", SqlDbType.Int, 4), new SqlParameter("@typeId", SqlDbType.Int, 4), new SqlParameter("@picUrl", SqlDbType.NVarChar, 100), new SqlParameter("@smallPicUrl", SqlDbType.NVarChar, 100), new SqlParameter("@addTime", SqlDbType.DateTime), new SqlParameter("@isLock", SqlDbType.Int, 4), new SqlParameter("@id", SqlDbType.Int, 4) }; parameters3[0].Value = modelt.templateId; parameters3[1].Value = modelt.typeId; parameters3[2].Value = modelt.picUrl; parameters3[3].Value = modelt.smallPicUrl; parameters3[4].Value = modelt.addTime; parameters3[5].Value = modelt.isLock; parameters3[6].Value = modelt.id; DbHelperSQL.ExecuteSql(conn, trans, strSql3.ToString(), parameters3); } else { strSql3.Append("insert into " + databaseprefix + "good_template_pic("); strSql3.Append("templateId,typeId,picUrl,smallPicUrl,addTime,isLock)"); strSql3.Append(" values ("); strSql3.Append("@templateId,@typeId,@picUrl,@smallPicUrl,@addTime,@isLock)"); SqlParameter[] parameters3 = { new SqlParameter("@templateId", SqlDbType.Int, 4), new SqlParameter("@typeId", SqlDbType.Int, 4), new SqlParameter("@picUrl", SqlDbType.NVarChar, 100), new SqlParameter("@smallPicUrl", SqlDbType.NVarChar, 100), new SqlParameter("@addTime", SqlDbType.DateTime), new SqlParameter("@isLock", SqlDbType.Int, 4) }; parameters3[0].Value = modelt.templateId; parameters3[1].Value = modelt.typeId; parameters3[2].Value = modelt.picUrl; parameters3[3].Value = modelt.smallPicUrl; parameters3[4].Value = modelt.addTime; parameters3[5].Value = modelt.isLock; DbHelperSQL.ExecuteSql(conn, trans, strSql3.ToString(), parameters3); } } } trans.Commit(); } catch { trans.Rollback(); return(false); } } } return(true); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Model.good_template model) { return(dal.Update(model)); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Model.good_template model) { return(dal.Add(model)); }