protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { var bll = new BLL.BLLBase(); var chtb = bll.Select(ctx, new Channel() { ID = Convert.ToInt32(Request.QueryString["id"]), State = 0 }); if (chtb != null && chtb.Rows.Count > 0) { channel = chtb.ToList<Model.Channel>()[0]; img_1.ImgUrls = channel.ImageUrl; var tb = ctx.ExecuteDataTable( "Select * From Channel where State<>255 and ParentId=0 and [Type] in (1,2)"); ddlParentId.Items.Add(new ListItem("顶级栏目", "0")); if (tb != null && tb.Rows.Count > 0) { var channels = tb.ToList<Model.Channel>(); foreach (var pchannel in channels) { var item = new ListItem(pchannel.Name, pchannel.ID.ToString()); item.Attributes.Add("type", pchannel.Type.ToString()); ddlParentId.Items.Add(item); if (pchannel.ID == channel.ParentId) { item.Selected = true; } } } ddlType.Items.Add(new ListItem("栏目列表页", "2")); ddlType.Items.Add(new ListItem("内容列表页", "1")); ddlType.Items.Add(new ListItem("单独内容页", "0")); } } else { AjaxResult response = null; var id = Request.Form["id"]; var txtParentId = Request.Form["ctl00$ContentPlaceHolder1$ddlParentId"]; var txtName = Request.Form["txtName"]; var txtCode = Request.Form["txtCode"]; var txtType = Request.Form["ctl00$ContentPlaceHolder1$ddlType"]; var sltContentType = Request.Form["sltContentType"]; var txtState = Request.Form["sltState"]; var txtRemark = Request.Form["txtRemark"]; var txtSort = Request.Form["txtSort"]; var imageUrl = !string.IsNullOrEmpty(Request.Form["hifShowImage"]) ? common.Common.UploadImagePath + Request.Form["hifShowImage"] : ""; if (string.IsNullOrEmpty(txtCode)) { response = new AjaxResult() { Success = 0, Message = "代号不能为空!" }; this.Response.Write(common.Common.GetJSMsgBox(response.Message)); return; } if (string.IsNullOrEmpty(txtType)) { response = new AjaxResult() { Success = 0, Message = "类别不能为空。" }; this.Response.Write(common.Common.GetJSMsgBox(response.Message)); return; } if (string.IsNullOrEmpty(sltContentType)) { response = new AjaxResult() { Success = 0, Message = "内容类型不能为空。" }; this.Response.Write(common.Common.GetJSMsgBox(response.Message)); return; } if (string.IsNullOrEmpty(txtName)) { response = new AjaxResult() { Success = 0, Message = "用户名不能为空。" }; this.Response.Write(common.Common.GetJSMsgBox(response.Message)); return; } var dt = new Model.Channel() { ID = Convert.ToInt32(id), Type = Convert.ToInt16(txtType), Code = txtCode, ModifyDate = DateTime.Now, Name = txtName, ContentType = Convert.ToInt16(sltContentType), ModifiedBy = (Session["LoginAdmin"] as Model.Admin).ID, Remark = txtRemark, ImageUrl = imageUrl, ParentId = Convert.ToInt16(txtParentId), State = Convert.ToInt16(txtState), Sort = Convert.ToInt16(txtSort), }; ctx.BeginTransaction(); try { var bll = new BLL.BLLBase(); bll.Update(ctx, dt); ctx.CommitTransaction(); response = new AjaxResult() { Success = 1, Message = "操作成功", Data = id }; } catch (Exception exception) { ctx.RollBackTransaction(); response = new AjaxResult() { Success = 0, Message = "操作失败:" + exception.Message, Data = 0 }; } finally { ctx.CloseConnection(); } this.Response.Write(common.Common.GetJSMsgBox(response.Message)); } }
protected void Page_Load(object sender, EventArgs e) { var id = Request.QueryString["CID"]; var sid = Request.QueryString["SID"]; var pid = Request.QueryString["Pid"]; if (id == null) { Response.Redirect("/Default.aspx"); return; } var ctx = new DataContext(); var bll = new BLL.BLLBase(); Config = bll.Select(ctx, new GlobeConfig() { Code = "SiteName" }).ToList <Model.GlobeConfig>()[0]; var channelTB = bll.Select(ctx, new Model.Channel() { ID = Convert.ToInt32(id), State = 0 }); if (channelTB != null && channelTB.Rows.Count > 0) { channel = channelTB.ToList <Model.Channel>()[0]; } subChannels = bll.Select(ctx, new Model.Channel() { ParentId = Convert.ToInt16(id), State = 0 }) .ToList <Model.Channel>() .OrderBy(c => c.Sort) .ToList(); subChannels = subChannels ?? new List <Model.Channel>(); if (pid != null) //单独网页 { var tb = bll.Select(ctx, new Model.Content() { ID = Convert.ToInt32(pid), State = 0 }); if (tb != null && tb.Rows.Count > 0) { Contents = tb.ToList <Model.Content>(); } } else if (sid != null) //单独栏目 { var channel = subChannels.Find(ch => ch.ID == Convert.ToInt32(sid)); if (channel != null) { //0--单独内容页,1--内容列表页 if (channel.Type == 0) { var tb = ctx.ExecuteDataTable( "Select top 1 * From Content where State!=255 and ChannelID=" + channel.ID + " Order by ID desc"); if (tb != null) { Contents = tb.ToList <Model.Content>(); } } else { //内容列表页 Contents = new List <Model.Content>(); var models = new BLL.Content().GetChannelContentList(ctx, channel.ID); if (models != null && models.Count > 0) { Contents.AddRange(models); } } } } else //顶级栏目 { //若为独立页面栏目 if (channel.Type == 0) { var content = new BLL.Content().GetSinplePageChannelContent(ctx, channel.ID); if (content != null) { Contents = new List <Model.Content> { content }; } } else //内容列表栏目或栏目列表页 { //默认取第一栏目的内容 if (subChannels.Count > 0) { var subChannel = subChannels[0]; if (subChannel.Type == 0) //内容页 { var content = new BLL.Content().GetSinplePageChannelContent(ctx, subChannel.ID); if (content != null) { Contents = new List <Model.Content> { content }; } } else //内容列表页 { Contents = new List <Model.Content>(); var models = new BLL.Content().GetChannelContentList(ctx, subChannel.ID); if (models != null && models.Count > 0) { Contents.AddRange(models); } } } } } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { var bll = new BLL.BLLBase(); var chtb = bll.Select(ctx, new Channel() { ID = Convert.ToInt32(Request.QueryString["id"]), State = 0 }); if (chtb != null && chtb.Rows.Count > 0) { channel = chtb.ToList <Model.Channel>()[0]; img_1.ImgUrls = channel.ImageUrl; var tb = ctx.ExecuteDataTable( "Select * From Channel where State<>255 and ParentId=0 and [Type] in (1,2)"); ddlParentId.Items.Add(new ListItem("顶级栏目", "0")); if (tb != null && tb.Rows.Count > 0) { var channels = tb.ToList <Model.Channel>(); foreach (var pchannel in channels) { var item = new ListItem(pchannel.Name, pchannel.ID.ToString()); item.Attributes.Add("type", pchannel.Type.ToString()); ddlParentId.Items.Add(item); if (pchannel.ID == channel.ParentId) { item.Selected = true; } } } ddlType.Items.Add(new ListItem("栏目列表页", "2")); ddlType.Items.Add(new ListItem("内容列表页", "1")); ddlType.Items.Add(new ListItem("单独内容页", "0")); } } else { AjaxResult response = null; var id = Request.Form["id"]; var txtParentId = Request.Form["ctl00$ContentPlaceHolder1$ddlParentId"]; var txtName = Request.Form["txtName"]; var txtCode = Request.Form["txtCode"]; var txtType = Request.Form["ctl00$ContentPlaceHolder1$ddlType"]; var sltContentType = Request.Form["sltContentType"]; var txtState = Request.Form["sltState"]; var txtRemark = Request.Form["txtRemark"]; var txtSort = Request.Form["txtSort"]; var imageUrl = !string.IsNullOrEmpty(Request.Form["hifShowImage"]) ? common.Common.UploadImagePath + Request.Form["hifShowImage"] : ""; if (string.IsNullOrEmpty(txtCode)) { response = new AjaxResult() { Success = 0, Message = "代号不能为空!" }; this.Response.Write(common.Common.GetJSMsgBox(response.Message)); return; } if (string.IsNullOrEmpty(txtType)) { response = new AjaxResult() { Success = 0, Message = "类别不能为空。" }; this.Response.Write(common.Common.GetJSMsgBox(response.Message)); return; } if (string.IsNullOrEmpty(sltContentType)) { response = new AjaxResult() { Success = 0, Message = "内容类型不能为空。" }; this.Response.Write(common.Common.GetJSMsgBox(response.Message)); return; } if (string.IsNullOrEmpty(txtName)) { response = new AjaxResult() { Success = 0, Message = "用户名不能为空。" }; this.Response.Write(common.Common.GetJSMsgBox(response.Message)); return; } var dt = new Model.Channel() { ID = Convert.ToInt32(id), Type = Convert.ToInt16(txtType), Code = txtCode, ModifyDate = DateTime.Now, Name = txtName, ContentType = Convert.ToInt16(sltContentType), ModifiedBy = (Session["LoginAdmin"] as Model.Admin).ID, Remark = txtRemark, ImageUrl = imageUrl, ParentId = Convert.ToInt16(txtParentId), State = Convert.ToInt16(txtState), Sort = Convert.ToInt16(txtSort), }; ctx.BeginTransaction(); try { var bll = new BLL.BLLBase(); bll.Update(ctx, dt); ctx.CommitTransaction(); response = new AjaxResult() { Success = 1, Message = "操作成功", Data = id }; } catch (Exception exception) { ctx.RollBackTransaction(); response = new AjaxResult() { Success = 0, Message = "操作失败:" + exception.Message, Data = 0 }; } finally { ctx.CloseConnection(); } this.Response.Write(common.Common.GetJSMsgBox(response.Message)); } }