//设置操作 protected void rptList_ItemCommand(object source, RepeaterCommandEventArgs e) { ChkAdminLevel(channel_id, ActionEnum.Edit.ToString()); //检查权限 int id = Convert.ToInt32(((HiddenField)e.Item.FindControl("hidId")).Value); BLL.download bll = new BLL.download(); Model.download model = bll.GetModel(id); switch (e.CommandName.ToLower()) { case "ibtnmsg": if (model.is_msg == 1) { bll.UpdateField(id, "is_msg=0"); } else { bll.UpdateField(id, "is_msg=1"); } break; case "ibtnred": if (model.is_red == 1) { bll.UpdateField(id, "is_red=0"); } else { bll.UpdateField(id, "is_red=1"); } break; } this.RptBind("id>0" + CombSqlTxt(this.channel_id, this.category_id, this.keywords, this.property), "sort_id asc,add_time desc"); }
//下载模块 private void digg_download_add(HttpContext context) { string channel_type = DTRequest.GetFormString("channel_type"); string digg_type = DTRequest.GetFormString("digg_type"); int id = DTRequest.GetFormInt("id"); BLL.download bll = new BLL.download(); if (!bll.Exists(id)) { context.Response.Write("{msg:0, msgbox:\"信息不存在或已删除!\"}"); return; } if (digg_type == "good") { bll.UpdateField(id, "digg_good=digg_good+1"); } else { bll.UpdateField(id, "digg_act=digg_act+1"); } Model.download model = bll.GetModel(id); context.Response.Write("{msg:1, digggood:" + model.digg_good + ", diggact:" + model.digg_act + ", msgbox:\"成功顶或踩了一下!\"}"); Utils.WriteCookie(DTKeys.COOKIE_DIGG_KEY, channel_type + id.ToString(), id.ToString(), 8640); return; }
private void ShowInfo(int _id) { BLL.download bll = new BLL.download(); Model.download model = bll.GetModel(_id); ddlCategoryId.SelectedValue = model.category_id.ToString(); txtTitle.Text = model.title; txtImgUrl.Text = model.img_url; txtLinkUrl.Text = model.link_url; if (model.is_msg == 1) { cblItem.Items[0].Selected = true; } if (model.is_red == 1) { cblItem.Items[1].Selected = true; } if (model.is_lock == 1) { cblItem.Items[2].Selected = true; } txtSortId.Text = model.sort_id.ToString(); txtClick.Text = model.click.ToString(); txtDiggGood.Text = model.digg_good.ToString(); txtDiggAct.Text = model.digg_act.ToString(); txtContent.Value = model.content; txtSeoTitle.Text = model.seo_title; txtSeoKeywords.Text = model.seo_keywords; txtSeoDescription.Text = model.seo_description; //绑定附件 rptAttach.DataSource = model.download_attachs; rptAttach.DataBind(); }
private bool DoAdd() { bool result = true; DTcms.Model.download model = new Model.download(); DTcms.BLL.download bll = new BLL.download(); model.channel_id = this.channel_id; model.title = txtTitle.Text.Trim(); model.category_id = int.Parse(ddlCategoryId.SelectedValue); model.link_url = txtLinkUrl.Text.Trim(); model.img_url = txtImgUrl.Text.Trim(); model.content = txtContent.Value; model.seo_title = txtSeoTitle.Text.Trim(); model.seo_keywords = txtSeoKeywords.Text.Trim(); model.seo_description = txtSeoDescription.Text.Trim(); model.sort_id = int.Parse(txtSortId.Text.Trim()); model.click = int.Parse(txtClick.Text.Trim()); model.is_msg = 0; model.is_red = 0; model.is_lock = 0; if (cblItem.Items[0].Selected == true) { model.is_msg = 1; } if (cblItem.Items[1].Selected == true) { model.is_red = 1; } if (cblItem.Items[2].Selected == true) { model.is_lock = 1; } //保存附件 string hidFileList = Request.Params["hidFileName"]; if (!string.IsNullOrEmpty(hidFileList)) { string[] fileListArr = hidFileList.Split(','); List<Model.download_attach> ls = new List<Model.download_attach>(); for (int i = 0; i < fileListArr.Length; i++) { string[] fileArr = fileListArr[i].Split('|'); if (fileArr.Length == 3) { int fileSize = Utils.GetFileSize(fileArr[2]); string fileExt = Utils.GetFileExt(fileArr[2]); ls.Add(new Model.download_attach { id = int.Parse(fileArr[0]), title = fileArr[1], file_path = fileArr[2], file_size = fileSize, file_ext = fileExt }); } } model.download_attachs = ls; } if (bll.Add(model) < 1) { result = false; } return result; }
/// <summary> /// 重写虚方法,此方法将在Init事件前执行 /// </summary> protected override void ShowPage() { id = DTRequest.GetQueryInt("id"); BLL.download bll = new BLL.download(); if (!bll.Exists(id)) { HttpContext.Current.Response.Redirect(config.webpath + "error.aspx?msg=" + Utils.UrlEncode("出错啦,您要浏览的页面不存在或已删除啦!")); return; } model = bll.GetModel(id); //浏览数+1 bll.UpdateField(id, "click=click+1"); //跳转URL if (model.link_url != null) model.link_url = model.link_url.Trim(); if (!string.IsNullOrEmpty(model.link_url)) { HttpContext.Current.Response.Redirect(model.link_url); } }
/// <summary> /// 重写虚方法,此方法将在Init事件前执行 /// </summary> protected override void ShowPage() { id = DTRequest.GetQueryInt("id"); BLL.download bll = new BLL.download(); if (!bll.Exists(id)) { HttpContext.Current.Response.Redirect(config.webpath + "error.aspx?msg=" + Utils.UrlEncode("出错啦,您要浏览的页面不存在或已删除啦!")); return; } model = bll.GetModel(id); //浏览数+1 bll.UpdateField(id, "click=click+1"); //跳转URL if (model.link_url != null) { model.link_url = model.link_url.Trim(); } if (!string.IsNullOrEmpty(model.link_url)) { HttpContext.Current.Response.Redirect(model.link_url); } }
private bool DoEdit(int _id) { bool result = true; BLL.download bll = new BLL.download(); Model.download model = bll.GetModel(_id); model.channel_id = this.channel_id; model.title = txtTitle.Text.Trim(); model.category_id = int.Parse(ddlCategoryId.SelectedValue); model.link_url = txtLinkUrl.Text.Trim(); model.img_url = txtImgUrl.Text.Trim(); model.content = txtContent.Value; model.seo_title = txtSeoTitle.Text.Trim(); model.seo_keywords = txtSeoKeywords.Text.Trim(); model.seo_description = txtSeoDescription.Text.Trim(); model.sort_id = int.Parse(txtSortId.Text.Trim()); model.click = int.Parse(txtClick.Text.Trim()); model.is_msg = 0; model.is_red = 0; model.is_lock = 0; if (cblItem.Items[0].Selected == true) { model.is_msg = 1; } if (cblItem.Items[1].Selected == true) { model.is_red = 1; } if (cblItem.Items[2].Selected == true) { model.is_lock = 1; } //保存附件 if (model.download_attachs != null) { model.download_attachs.Clear(); } string hidFileList = Request.Params["hidFileName"]; if (!string.IsNullOrEmpty(hidFileList)) { string[] fileListArr = hidFileList.Split(','); List <Model.download_attach> ls = new List <Model.download_attach>(); for (int i = 0; i < fileListArr.Length; i++) { string[] fileArr = fileListArr[i].Split('|'); if (fileArr.Length == 3) { int fileSize = Utils.GetFileSize(fileArr[2]); string fileExt = Utils.GetFileExt(fileArr[2]); ls.Add(new Model.download_attach { id = int.Parse(fileArr[0]), down_id = _id, title = fileArr[1], file_path = fileArr[2], file_size = fileSize, file_ext = fileExt }); } } model.download_attachs = ls; } if (!bll.Update(model)) { result = false; } return(result); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Model.download model) { return(dal.Update(model)); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Model.download model) { return(dal.Add(model)); }
/// <summary> /// 得到一个对象实体 /// </summary> public DTcms.Model.download GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id,channel_id,title,category_id,link_url,img_url,seo_title,seo_keywords,seo_description,content,sort_id,click,digg_good,digg_act,is_msg,is_red,is_lock,add_time from dt_download "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = id; Model.download model = new Model.download(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { #region 父表信息 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]["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]["click"] != null && ds.Tables[0].Rows[0]["click"].ToString() != "") { model.click = int.Parse(ds.Tables[0].Rows[0]["click"].ToString()); } if (ds.Tables[0].Rows[0]["digg_good"] != null && ds.Tables[0].Rows[0]["digg_good"].ToString() != "") { model.digg_good = int.Parse(ds.Tables[0].Rows[0]["digg_good"].ToString()); } if (ds.Tables[0].Rows[0]["digg_act"] != null && ds.Tables[0].Rows[0]["digg_act"].ToString() != "") { model.digg_act = int.Parse(ds.Tables[0].Rows[0]["digg_act"].ToString()); } if (ds.Tables[0].Rows[0]["is_msg"] != null && ds.Tables[0].Rows[0]["is_msg"].ToString() != "") { model.is_msg = int.Parse(ds.Tables[0].Rows[0]["is_msg"].ToString()); } if (ds.Tables[0].Rows[0]["is_red"] != null && ds.Tables[0].Rows[0]["is_red"].ToString() != "") { model.is_red = int.Parse(ds.Tables[0].Rows[0]["is_red"].ToString()); } if (ds.Tables[0].Rows[0]["is_lock"] != null && ds.Tables[0].Rows[0]["is_lock"].ToString() != "") { model.is_lock = int.Parse(ds.Tables[0].Rows[0]["is_lock"].ToString()); } if (ds.Tables[0].Rows[0]["add_time"] != null && ds.Tables[0].Rows[0]["add_time"].ToString() != "") { model.add_time = DateTime.Parse(ds.Tables[0].Rows[0]["add_time"].ToString()); } if (ds.Tables[0].Rows[0]["channel_id"] != null && ds.Tables[0].Rows[0]["channel_id"].ToString() != "") { model.channel_id = int.Parse(ds.Tables[0].Rows[0]["channel_id"].ToString()); } if (ds.Tables[0].Rows[0]["title"] != null && ds.Tables[0].Rows[0]["title"].ToString() != "") { model.title = ds.Tables[0].Rows[0]["title"].ToString(); } if (ds.Tables[0].Rows[0]["category_id"] != null && ds.Tables[0].Rows[0]["category_id"].ToString() != "") { model.category_id = int.Parse(ds.Tables[0].Rows[0]["category_id"].ToString()); } if (ds.Tables[0].Rows[0]["link_url"] != null && ds.Tables[0].Rows[0]["link_url"].ToString() != "") { model.link_url = ds.Tables[0].Rows[0]["link_url"].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]["seo_title"] != null && ds.Tables[0].Rows[0]["seo_title"].ToString() != "") { model.seo_title = ds.Tables[0].Rows[0]["seo_title"].ToString(); } if (ds.Tables[0].Rows[0]["seo_keywords"] != null && ds.Tables[0].Rows[0]["seo_keywords"].ToString() != "") { model.seo_keywords = ds.Tables[0].Rows[0]["seo_keywords"].ToString(); } if (ds.Tables[0].Rows[0]["seo_description"] != null && ds.Tables[0].Rows[0]["seo_description"].ToString() != "") { model.seo_description = ds.Tables[0].Rows[0]["seo_description"].ToString(); } if (ds.Tables[0].Rows[0]["content"] != null && ds.Tables[0].Rows[0]["content"].ToString() != "") { model.content = ds.Tables[0].Rows[0]["content"].ToString(); } #endregion 父表信息end #region 子表信息 StringBuilder strSql2 = new StringBuilder(); strSql2.Append("select id,down_id,title,file_path,file_ext,file_size,down_num from dt_download_attach "); strSql2.Append(" where down_id=@down_id "); SqlParameter[] parameters2 = { new SqlParameter("@down_id", SqlDbType.Int, 4) }; parameters2[0].Value = id; DataSet ds2 = DbHelperSQL.Query(strSql2.ToString(), parameters2); if (ds2.Tables[0].Rows.Count > 0) { #region 子表字段信息 int i = ds2.Tables[0].Rows.Count; List <DTcms.Model.download_attach> models = new List <DTcms.Model.download_attach>(); DTcms.Model.download_attach modelt; for (int n = 0; n < i; n++) { modelt = new DTcms.Model.download_attach(); if (ds2.Tables[0].Rows[n]["id"] != null && ds2.Tables[0].Rows[n]["id"].ToString() != "") { modelt.id = int.Parse(ds2.Tables[0].Rows[n]["id"].ToString()); } if (ds2.Tables[0].Rows[n]["down_id"] != null && ds2.Tables[0].Rows[n]["down_id"].ToString() != "") { modelt.down_id = int.Parse(ds2.Tables[0].Rows[n]["down_id"].ToString()); } if (ds2.Tables[0].Rows[n]["title"] != null && ds2.Tables[0].Rows[n]["title"].ToString() != "") { modelt.title = ds2.Tables[0].Rows[n]["title"].ToString(); } if (ds2.Tables[0].Rows[n]["file_path"] != null && ds2.Tables[0].Rows[n]["file_path"].ToString() != "") { modelt.file_path = ds2.Tables[0].Rows[n]["file_path"].ToString(); } if (ds2.Tables[0].Rows[n]["file_ext"] != null && ds2.Tables[0].Rows[n]["file_ext"].ToString() != "") { modelt.file_ext = ds2.Tables[0].Rows[n]["file_ext"].ToString(); } if (ds2.Tables[0].Rows[n]["file_size"] != null && ds2.Tables[0].Rows[n]["file_size"].ToString() != "") { modelt.file_size = int.Parse(ds2.Tables[0].Rows[n]["file_size"].ToString()); } if (ds2.Tables[0].Rows[n]["down_num"] != null && ds2.Tables[0].Rows[n]["down_num"].ToString() != "") { modelt.down_num = int.Parse(ds2.Tables[0].Rows[n]["down_num"].ToString()); } models.Add(modelt); } model.download_attachs = models; #endregion 子表字段信息end } #endregion 子表信息end return(model); } else { return(null); } }
/// <summary> /// 删除一条数据,及子表所有相关数据 /// </summary> public bool Delete(int channel_id, int id) { //取得下载MODEL List <Model.download_attach> ls = new List <Model.download_attach>(); Model.download model = GetModel(id); if (model != null) { ls = model.download_attachs; } List <CommandInfo> sqllist = new List <CommandInfo>(); StringBuilder strSql3 = new StringBuilder(); strSql3.Append("delete from dt_comment "); strSql3.Append(" where channel_id=@channel_id and content_id=@content_id"); SqlParameter[] parameters3 = { new SqlParameter("@channel_id", SqlDbType.Int, 4), new SqlParameter("@content_id", SqlDbType.Int, 4) }; parameters3[0].Value = channel_id; parameters3[1].Value = id; CommandInfo cmd = new CommandInfo(strSql3.ToString(), parameters3); sqllist.Add(cmd); StringBuilder strSql2 = new StringBuilder(); strSql2.Append("delete from dt_download_attach "); strSql2.Append(" where down_id=@down_id "); SqlParameter[] parameters2 = { new SqlParameter("@down_id", SqlDbType.Int, 4) }; parameters2[0].Value = id; cmd = new CommandInfo(strSql2.ToString(), parameters2); sqllist.Add(cmd); StringBuilder strSql = new StringBuilder(); strSql.Append("delete from dt_download "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = id; cmd = new CommandInfo(strSql.ToString(), parameters); sqllist.Add(cmd); int rowsAffected = DbHelperSQL.ExecuteSqlTran(sqllist); if (rowsAffected > 0) { DeleteAttachFile(ls); return(true); } else { return(false); } }
/// <summary> /// �õ�һ������ʵ�� /// </summary> public DTcms.Model.download GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id,channel_id,title,category_id,link_url,img_url,seo_title,seo_keywords,seo_description,content,sort_id,click,digg_good,digg_act,is_msg,is_red,is_lock,add_time from dt_download "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int,4)}; parameters[0].Value = id; Model.download model = new Model.download(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { #region ������Ϣ 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]["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]["click"] != null && ds.Tables[0].Rows[0]["click"].ToString() != "") { model.click = int.Parse(ds.Tables[0].Rows[0]["click"].ToString()); } if (ds.Tables[0].Rows[0]["digg_good"] != null && ds.Tables[0].Rows[0]["digg_good"].ToString() != "") { model.digg_good = int.Parse(ds.Tables[0].Rows[0]["digg_good"].ToString()); } if (ds.Tables[0].Rows[0]["digg_act"] != null && ds.Tables[0].Rows[0]["digg_act"].ToString() != "") { model.digg_act = int.Parse(ds.Tables[0].Rows[0]["digg_act"].ToString()); } if (ds.Tables[0].Rows[0]["is_msg"] != null && ds.Tables[0].Rows[0]["is_msg"].ToString() != "") { model.is_msg = int.Parse(ds.Tables[0].Rows[0]["is_msg"].ToString()); } if (ds.Tables[0].Rows[0]["is_red"] != null && ds.Tables[0].Rows[0]["is_red"].ToString() != "") { model.is_red = int.Parse(ds.Tables[0].Rows[0]["is_red"].ToString()); } if (ds.Tables[0].Rows[0]["is_lock"] != null && ds.Tables[0].Rows[0]["is_lock"].ToString() != "") { model.is_lock = int.Parse(ds.Tables[0].Rows[0]["is_lock"].ToString()); } if (ds.Tables[0].Rows[0]["add_time"] != null && ds.Tables[0].Rows[0]["add_time"].ToString() != "") { model.add_time = DateTime.Parse(ds.Tables[0].Rows[0]["add_time"].ToString()); } if (ds.Tables[0].Rows[0]["channel_id"] != null && ds.Tables[0].Rows[0]["channel_id"].ToString() != "") { model.channel_id = int.Parse(ds.Tables[0].Rows[0]["channel_id"].ToString()); } if (ds.Tables[0].Rows[0]["title"] != null && ds.Tables[0].Rows[0]["title"].ToString() != "") { model.title = ds.Tables[0].Rows[0]["title"].ToString(); } if (ds.Tables[0].Rows[0]["category_id"] != null && ds.Tables[0].Rows[0]["category_id"].ToString() != "") { model.category_id = int.Parse(ds.Tables[0].Rows[0]["category_id"].ToString()); } if (ds.Tables[0].Rows[0]["link_url"] != null && ds.Tables[0].Rows[0]["link_url"].ToString() != "") { model.link_url = ds.Tables[0].Rows[0]["link_url"].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]["seo_title"] != null && ds.Tables[0].Rows[0]["seo_title"].ToString() != "") { model.seo_title = ds.Tables[0].Rows[0]["seo_title"].ToString(); } if (ds.Tables[0].Rows[0]["seo_keywords"] != null && ds.Tables[0].Rows[0]["seo_keywords"].ToString() != "") { model.seo_keywords = ds.Tables[0].Rows[0]["seo_keywords"].ToString(); } if (ds.Tables[0].Rows[0]["seo_description"] != null && ds.Tables[0].Rows[0]["seo_description"].ToString() != "") { model.seo_description = ds.Tables[0].Rows[0]["seo_description"].ToString(); } if (ds.Tables[0].Rows[0]["content"] != null && ds.Tables[0].Rows[0]["content"].ToString() != "") { model.content = ds.Tables[0].Rows[0]["content"].ToString(); } #endregion ������Ϣend #region �ӱ���Ϣ StringBuilder strSql2 = new StringBuilder(); strSql2.Append("select id,down_id,title,file_path,file_ext,file_size,down_num from dt_download_attach "); strSql2.Append(" where down_id=@down_id "); SqlParameter[] parameters2 = { new SqlParameter("@down_id", SqlDbType.Int,4)}; parameters2[0].Value = id; DataSet ds2 = DbHelperSQL.Query(strSql2.ToString(), parameters2); if (ds2.Tables[0].Rows.Count > 0) { #region �ӱ��ֶ���Ϣ int i = ds2.Tables[0].Rows.Count; List<DTcms.Model.download_attach> models = new List<DTcms.Model.download_attach>(); DTcms.Model.download_attach modelt; for (int n = 0; n < i; n++) { modelt = new DTcms.Model.download_attach(); if (ds2.Tables[0].Rows[n]["id"] != null && ds2.Tables[0].Rows[n]["id"].ToString() != "") { modelt.id = int.Parse(ds2.Tables[0].Rows[n]["id"].ToString()); } if (ds2.Tables[0].Rows[n]["down_id"] != null && ds2.Tables[0].Rows[n]["down_id"].ToString() != "") { modelt.down_id = int.Parse(ds2.Tables[0].Rows[n]["down_id"].ToString()); } if (ds2.Tables[0].Rows[n]["title"] != null && ds2.Tables[0].Rows[n]["title"].ToString() != "") { modelt.title = ds2.Tables[0].Rows[n]["title"].ToString(); } if (ds2.Tables[0].Rows[n]["file_path"] != null && ds2.Tables[0].Rows[n]["file_path"].ToString() != "") { modelt.file_path = ds2.Tables[0].Rows[n]["file_path"].ToString(); } if (ds2.Tables[0].Rows[n]["file_ext"] != null && ds2.Tables[0].Rows[n]["file_ext"].ToString() != "") { modelt.file_ext = ds2.Tables[0].Rows[n]["file_ext"].ToString(); } if (ds2.Tables[0].Rows[n]["file_size"] != null && ds2.Tables[0].Rows[n]["file_size"].ToString() != "") { modelt.file_size = int.Parse(ds2.Tables[0].Rows[n]["file_size"].ToString()); } if (ds2.Tables[0].Rows[n]["down_num"] != null && ds2.Tables[0].Rows[n]["down_num"].ToString() != "") { modelt.down_num = int.Parse(ds2.Tables[0].Rows[n]["down_num"].ToString()); } models.Add(modelt); } model.download_attachs = models; #endregion �ӱ��ֶ���Ϣend } #endregion �ӱ���Ϣend return model; } else { return null; } }