private void GetNewsTypeName(HttpContext context) { //int type_id=0; //string result = "未分类"; //try //{ // type_id = int.Parse(context.Request.Params["news_type"]); //} // catch //{ // type_id = 0; //} //Model.CCOM.News_type model = new BLL.CCOM.News_type().GetModel(type_id); //if(model!=null) //{ // result = model.News_type_name; //} //context.Response.Write(result); var news_type = new BLL.CCOM.News_type().GetAllList().Tables[0]; if (news_type != null && news_type.Rows.Count > 0) { string result = ToJson(news_type); context.Response.Write(result); } }
//单个删除 protected void lbtSingleDelete_Click(object sender, EventArgs e) { var lbtn = sender as LinkButton; BLL.CCOM.News_type bll = new BLL.CCOM.News_type(); BLL.CCOM.News news_bll = new BLL.CCOM.News(); if (lbtn != null) { bool result = false; int newsTypeId = Int32.Parse(DESEncrypt.Decrypt(lbtn.ToolTip.ToString())); if (newsTypeId > 0) { Model.CCOM.News_type model = bll.GetModel(newsTypeId); if (model.News_type_creator_id == GetAdminInfo_CCOM().User_id) { news_bll.Delete(" News_type_id=" + newsTypeId); result = bll.Delete(newsTypeId); } int page = MyRequest.GetQueryInt("page", 1); if (result) { JscriptMsg("删除成功!", Utils.CombUrlTxt("News_type_manage.aspx", "&keywords={0}&page={1}&fun_id={2}", keywords, page.ToString(), DESEncrypt.Encrypt(this.fun_id)), "Success"); } } } }
private void InitialNewsType() { var news_type_list = new BLL.CCOM.News_type().GetModelList(""); if (news_type_list != null && news_type_list.Count > 0) { StringBuilder sb = new StringBuilder(); var className = "btn btn-success"; //添加全部一栏 sb.Append("<input type=\"hidden\" name=\"typeId\" value='" + DESEncrypt.Encrypt("0") + "' />"); sb.Append("<a href=\"javascript:;\" class='" + className + "' onclick='newsTypeTabs(\"#newsList\",\"" + DESEncrypt.Encrypt("0") + "\",this)'>"); sb.Append("全部</a> "); int index = 0; for (int i = 0; i < news_type_list.Count; i++) { var className1 = "btn"; sb.Append("<input type=\"hidden\" name=\"typeId\" value='" + DESEncrypt.Encrypt(news_type_list[i].News_type_id.ToString()) + "' />"); sb.Append("<a href=\"javascript:;\" class='" + className1 + "' onclick='newsTypeTabs(\"#newsList\",\"" + DESEncrypt.Encrypt(news_type_list[i].News_type_id.ToString()) + "\",this)'>"); sb.Append(news_type_list[i].News_type_name + "</a> "); index++; } this.divNewsType.InnerHtml = sb.ToString(); } }
protected string GetNewsType(string newsTypeId) { int id = int.Parse(newsTypeId); var model = new BLL.CCOM.News_type().GetModel(id); if (model == null) { return("未分类"); } return(model.News_type_name); }
private void bindNewsType() { var news_type_list = new BLL.CCOM.News_type().GetModelList(""); if (news_type_list != null && news_type_list.Count > 0) { StringBuilder sb = new StringBuilder(); var className = "btn btn-success"; var className1 = "btn"; string newsTypeId = MyRequest.GetQueryString("news_type_id"); if (newsTypeId == null || newsTypeId.Length == 0) { //添加全部一栏 sb.Append("<a href=\"News_list_manager.aspx?news_type_id=" + DESEncrypt.Encrypt("0") + "&fun_id=" + DESEncrypt.Encrypt(this.fun_id) + "\" class='" + className + "'>"); sb.Append("全部</a> "); for (int i = 0; i < news_type_list.Count; i++) { sb.Append("<a href=\"News_list_manager.aspx?news_type_id=" + DESEncrypt.Encrypt(news_type_list[i].News_type_id.ToString()) + "&fun_id=" + DESEncrypt.Encrypt(this.fun_id) + "\" class='" + className1 + "'>"); sb.Append(news_type_list[i].News_type_name + "</a> "); } this.NewsTypeDiv.InnerHtml = sb.ToString(); } else { int typeId = int.Parse(DESEncrypt.Decrypt(newsTypeId)); if (typeId == 0) { sb.Append("<a href=\"News_list_manager.aspx?news_type_id=" + DESEncrypt.Encrypt("0") + "&fun_id=" + DESEncrypt.Encrypt(this.fun_id) + "\" class='" + className + "'>"); } else { sb.Append("<a href=\"News_list_manager.aspx?news_type_id=" + DESEncrypt.Encrypt("0") + "&fun_id=" + DESEncrypt.Encrypt(this.fun_id) + "\" class='" + className1 + "'>"); } sb.Append("全部</a> "); for (int i = 0; i < news_type_list.Count; i++) { if (typeId == news_type_list[i].News_type_id) { sb.Append("<a href=\"News_list_manager.aspx?news_type_id=" + DESEncrypt.Encrypt(news_type_list[i].News_type_id.ToString()) + "&fun_id=" + DESEncrypt.Encrypt(this.fun_id) + "\" class='" + className + "'>"); } else { sb.Append("<a href=\"News_list_manager.aspx?news_type_id=" + DESEncrypt.Encrypt(news_type_list[i].News_type_id.ToString()) + "&fun_id=" + DESEncrypt.Encrypt(this.fun_id) + "\" class='" + className1 + "'>"); } sb.Append(news_type_list[i].News_type_name + "</a> "); } this.NewsTypeDiv.InnerHtml = sb.ToString(); } } }
//批量删除 protected void btnDelete_Click(object sender, EventArgs e) { BLL.CCOM.News_type bll = new BLL.CCOM.News_type(); int count = 0; bool result = false; for (int i = 0; i < this.rptList.Items.Count; i++) { System.Web.UI.WebControls.CheckBox cb = (System.Web.UI.WebControls.CheckBox)rptList.Items[i].FindControl("chkId"); if (!cb.Checked) { continue; } else { int newsTypeId = Convert.ToInt32(((HiddenField)rptList.Items[i].FindControl("hidId")).Value); if (newsTypeId > 0) { Model.CCOM.News_type model = bll.GetModel(newsTypeId); if (model.News_type_creator_id == GetAdminInfo_CCOM().User_id) { result = bll.Delete(newsTypeId); } if (result) { count++; } } } } if (count < 1) { JscriptMsg("请您选择需要删除的资讯类别!", "", "Error"); return; } string keywords = MyRequest.GetQueryString("keywords"); int page = MyRequest.GetQueryInt("page", 1); if (result == true) { JscriptMsg("批量删除成功!", Utils.CombUrlTxt("News_type_manage.aspx", "&keywords={0}&page={1}&fun_id={2}", keywords, page.ToString(), DESEncrypt.Encrypt(this.fun_id)), "Success"); } else { JscriptMsg("批量删除失败!", Utils.CombUrlTxt("News_type_manage.aspx", "keywords={0}&page={1}&fun_id={2}", keywords, page.ToString(), DESEncrypt.Encrypt(this.fun_id)), "Error"); } }
private string ToJson(DataTable dt) { if (dt != null && dt.Rows.Count > 0) { JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer(); javaScriptSerializer.MaxJsonLength = Int32.MaxValue; //取得最大数值 ArrayList arrayList = new ArrayList(); int news_type = 0; foreach (DataRow dr in dt.Rows) { Dictionary <string, object> dictionary = new Dictionary <string, object>(); //实例化一个参数集合 foreach (DataColumn dc in dt.Columns) { dictionary.Add(dc.ColumnName, dr[dc.ColumnName].ToString()); string colname = dc.ColumnName; if (dc.ColumnName == "News_type_id") { news_type = int.Parse(dr[dc.ColumnName].ToString()); } } //扩展News_type_name到新表 var model = new BLL.CCOM.News_type().GetModel(news_type); if (model != null) { dictionary.Add("News_type_name", model.News_type_name); } else { dictionary.Add("News_type_name", "未分类"); } arrayList.Add(dictionary); //ArrayList集合中添加键值 } return(javaScriptSerializer.Serialize(arrayList)); //返回一个json字符串 } else { return(null); } }
private void bindData() { BLL.CCOM.News_type bll = new BLL.CCOM.News_type(); string strWhere = string.Empty; int pageSize = GetPageSize(10); //每页数量 int page = MyRequest.GetQueryInt("page", 1); keywords = MyRequest.GetQueryString("keywords"); if (keywords != null && keywords.Length > 0) { if (strWhere != "") { strWhere = strWhere + " and News_type_name '%" + keywords + "%' "; } else { strWhere = " News_type_name like '%" + keywords + "%' "; } } int start_index = pageSize * (page - 1) + 1; int end_index = pageSize * page; //计算数量 int totalCount = bll.GetRecordCount(""); //绑定当页 this.rptList.DataSource = bll.GetListByPage(strWhere, " News_type_date DESC ", start_index, end_index); this.rptList.DataBind(); //绑定页码 this.txtPageNum.Text = pageSize.ToString(); string pageUrl = Utils.CombUrlTxt("News_type_manage.aspx", "keywords={0}&page={1}&fun_id={2}", keywords, "__id__", DESEncrypt.Encrypt(this.fun_id)); this.PageContent.InnerHtml = Utils.OutPageList(pageSize, page, totalCount, pageUrl, 8, true); }
/// <summary> /// 添加通知类别 /// </summary> /// <param name="context"></param> private void AddPushType(HttpContext context) { if (!IsAdminLogin()) { FlushResponse(context, JsonConvert.SerializeObject(new ReturnObject() { Result = ERROR, Msg = "error" })); return; } String typeName = MyRequest.GetString("t").Trim(); if (!Common.Utils.IsSafeSqlString(typeName) || typeName == "") { FlushResponse(context, JsonConvert.SerializeObject(new ReturnObject() { Result = ERROR, Msg = "参数不合法!" })); return; } //添加通知类别 var typeBll = new BLL.CCOM.News_type(); var userId = GetAdminInfo().User_id; string strWhere = " News_type_name='" + typeName + "'"; if (typeBll.GetModelList(strWhere).Count == 0) { var typeModel = new Model.CCOM.News_type() { News_type_name = typeName, News_type_creator_id = (int)userId, News_type_date = DateTime.Now }; var typeId = typeBll.Add(typeModel); //添加成功,返回typeId和typeName if (typeId > 0) { FlushResponse(context, JsonConvert.SerializeObject(new ReturnType() { Result = OK, Msg = "资讯类别添加成功!", id = DESEncrypt.Encrypt(typeId.ToString()), name = typeName })); } else { FlushResponse(context, JsonConvert.SerializeObject(new ReturnObject() { Result = ERROR, Msg = "资讯类别添加失败!" })); } } else { FlushResponse(context, JsonConvert.SerializeObject(new ReturnObject() { Result = ERROR, Msg = "该资讯类别已存在!" })); } }
private void EditNewsType(HttpContext context) { string news_type_name = context.Request.Params["t"].Trim(); if (!Common.Utils.IsSafeSqlString(news_type_name) || news_type_name == "") { FlushResponse(context, JsonConvert.SerializeObject(new ReturnObject() { Result = ERROR, Msg = "参数不合法!" })); return; } string news_type_id = context.Request.Params["news_type_id"]; if (!string.IsNullOrEmpty(news_type_id)) { int _id = 0; try { _id = int.Parse(DESEncrypt.Decrypt(news_type_id)); } catch { FlushResponse(context, JsonConvert.SerializeObject(new ReturnObject() { Result = ERROR, Msg = "参数不合法!" })); return; } var bll = new BLL.CCOM.News_type(); var model = bll.GetModel(_id); if (model != null) { model.News_type_name = news_type_name; bool result = bll.Update(model); if (result) { FlushResponse(context, JsonConvert.SerializeObject(new ReturnType() { Result = OK, Msg = "资讯类别修改成功!", id = DESEncrypt.Encrypt(model.News_type_id.ToString()), name = news_type_name })); } else { FlushResponse(context, JsonConvert.SerializeObject(new ReturnObject() { Result = ERROR, Msg = "资讯类别修改失败!" })); } } else { FlushResponse(context, JsonConvert.SerializeObject(new ReturnObject() { Result = ERROR, Msg = "参数不合法!" })); } } else { FlushResponse(context, JsonConvert.SerializeObject(new ReturnObject() { Result = ERROR, Msg = "参数不合法!" })); } }
/// <summary> /// 初始化资讯类别 /// </summary> private void InitialNewsType() { var news_type_list = new BLL.CCOM.News_type().GetModelList(""); StringBuilder sb = new StringBuilder(); if (news_type_list != null && news_type_list.Count > 0) { string news_id = MyRequest.GetQueryString("id"); var className = "btn btn-success"; var className1 = "btn"; if (news_id != null && news_id.Length > 0)//编辑 { Model.CCOM.News model = new BLL.CCOM.News().GetModel(int.Parse(DESEncrypt.Decrypt(news_id))); if (model != null) { int news_type_id = model.News_type_id; if (news_type_id != 0) { sb.Append("<a href=\"javascript:;\" class='btn' onclick='newsTypeTabs(\"" + DESEncrypt.Encrypt("0") + "\",this)'>未分类</a> "); for (int i = 0; i < news_type_list.Count; i++) { if (news_type_list[i].News_type_id == news_type_id) { sb.Append("<a href=\"javascript:;\" class='" + className + "' onclick='newsTypeTabs(\"" + DESEncrypt.Encrypt(news_type_list[i].News_type_id.ToString()) + "\",this)'>"); this.hidNewsType.Value = DESEncrypt.Encrypt(news_type_list[i].News_type_id.ToString()); } else { sb.Append("<a href=\"javascript:;\" class='" + className1 + "' onclick='newsTypeTabs(\"" + DESEncrypt.Encrypt(news_type_list[i].News_type_id.ToString()) + "\",this)'>"); } sb.Append(news_type_list[i].News_type_name + "</a> "); } } else { this.hidNewsType.Value = DESEncrypt.Encrypt("0"); sb.Append("<a href=\"javascript:;\" class='btn btn-success' onclick='newsTypeTabs(\"" + DESEncrypt.Encrypt("0") + "\",this)'>未分类</a> "); for (int i = 0; i < news_type_list.Count; i++) { sb.Append("<a href=\"javascript:;\" class='" + className1 + "' onclick='newsTypeTabs(\"" + DESEncrypt.Encrypt(news_type_list[i].News_type_id.ToString()) + "\",this)'>"); sb.Append(news_type_list[i].News_type_name + "</a> "); } } } } else//发布 { this.hidNewsType.Value = DESEncrypt.Encrypt("0"); sb.Append("<a href=\"javascript:;\" class='btn btn-success' onclick='newsTypeTabs(\"" + DESEncrypt.Encrypt("0") + "\",this)'>未分类</a> "); for (int i = 0; i < news_type_list.Count; i++) { sb.Append("<a href=\"javascript:;\" class='" + className1 + "' onclick='newsTypeTabs(\"" + DESEncrypt.Encrypt(news_type_list[i].News_type_id.ToString()) + "\",this)'>"); sb.Append(news_type_list[i].News_type_name + "</a> "); } } } else { sb.Append("<a href=\"javascript:;\" class='btn btn-success' onclick='newsTypeTabs(\"" + DESEncrypt.Encrypt("0") + "\",this)'>未分类</a> "); this.hidNewsType.Value = DESEncrypt.Encrypt("0"); } sb.Append("<a href=\"javascript:;\" class='btn' style='font-size: 18px;' onclick='addPushType()'><i class=\"icon-plus\"></i></a>"); this.NewsTypeDiv.InnerHtml = sb.ToString(); }