分类管理模块-新增新的新闻分类(简单版本)
2012-05-22 23:40
337 查看
这个管理分类模块式是为了做新闻模块的一个前奏,给新闻模块提供必要的新闻分类。
设计界面:
数据库:
三个麻烦点:
1. 页面加载的时候,要做一个树形结构,把所有的分类显示在左侧。
2. 点击树的时候,分类的名称会自动显示到其父类。
3. 提交添加新的新闻分类。
HTML代码
CS文件:
BLL层:
DAL层:
设计界面:
数据库:
三个麻烦点:
1. 页面加载的时候,要做一个树形结构,把所有的分类显示在左侧。
2. 点击树的时候,分类的名称会自动显示到其父类。
3. 提交添加新的新闻分类。
HTML代码
<form id="form1" runat="server"> <table cellpadding="0" cellspacing="0" width="100%"> <tr> <td style="width: 164px"> 添加新闻分类</td> <td colspan="2"> </td> </tr> <tr> <td rowspan="6" style="width: 164px"> <asp:TreeView ID="TreeView1" runat="server" ImageSet="Arrows" onselectednodechanged="TreeView1_SelectedNodeChanged"> <ParentNodeStyle Font-Bold="False" /> <HoverNodeStyle Font-Underline="True" ForeColor="#5555DD" /> <SelectedNodeStyle Font-Underline="True" ForeColor="#5555DD" HorizontalPadding="0px" VerticalPadding="0px" /> <NodeStyle Font-Names="Tahoma" Font-Size="10pt" ForeColor="Black" HorizontalPadding="5px" NodeSpacing="0px" VerticalPadding="0px" /> </asp:TreeView> </td> <td colspan="2" style="text-align: center"> <asp:Label ID="lblMessage" runat="server"></asp:Label> </td> </tr> <tr> <td style="width: 166px"> 所属父类:</td> <td> <asp:TextBox ID="txtClassID" runat="server" Enabled="False" ToolTip="请点击左边的导航树,选择需要的编辑">新闻</asp:TextBox> <input type="hidden" id="hidClassID" value="1" runat="server" style="width: 60px" /> </td> </tr> <tr> <td style="width: 166px"> 分类名称:</td> <td> <asp:TextBox ID="txtClassName" runat="server"></asp:TextBox> </td> </tr> <tr> <td style="width: 166px"> 是否有子类:</td> <td> <asp:RadioButtonList ID="rbl" runat="server" Height="20px" RepeatDirection="Horizontal" Width="228px"> <asp:ListItem Value="1">是</asp:ListItem> <asp:ListItem Selected="True" Value="0">否</asp:ListItem> </asp:RadioButtonList> </td> </tr> <tr> <td style="width: 166px"> 备注</td> <td> <asp:TextBox ID="txtExample" runat="server" Height="126px" TextMode="MultiLine" Width="183px"></asp:TextBox> </td> </tr> <tr> <td style="width: 166px"> </td> <td> <asp:Button ID="btnSubmit" runat="server" onclick="btnSubmit_Click" Text="提交" /> </td> </tr> </table> <div> </div> </form>
CS文件:
protected void Page_Load(object sender, EventArgs e) { this.TreeView1.Nodes.Clear(); BindTree(this.TreeView1.Nodes, 0); } private void BindTree(TreeNodeCollection treecol, int parentID) //解决第一个问题 { CategoryBLL classsystem = new CategoryBLL();//调动业务层获取分类方法 List<Category> arrayList = classsystem.GetClassDataID(parentID); TreeNode node;//创建新的节点 foreach (Category classData in arrayList)//遍历所有分类,并添加到树的节点下 { node = new TreeNode(); node.Text = classData.ClassName + "(" + classData.Child + ")";//树的名称赋值 node.Value = classData.ClassId.ToString();//树的值赋值 treecol.Add(node);//新增节点 BindTree(node.ChildNodes, int.Parse(node.Value));//递归子节点 } } protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e) //解决第二个问题 { int id = int.Parse(this.TreeView1.SelectedNode.Value); Category classData = new Category(); classData = (new CategoryBLL()).GetclassID(id); this.txtClassID.Text = classData.ClassName;//获取分类的父类名称 this.hidClassID.Value = classData.ClassId.ToString();//获取分类父类ID,隐藏域 } protected void btnSubmit_Click(object sender, EventArgs e) //解决第三个问题 { Category classdata = new Category();//创建一个新的实体 classdata.ClassName = this.txtClassName.Text.Trim();//为实体的各个属性赋值 classdata.ParentId = int.Parse(this.hidClassID.Value.ToString().Trim()); classdata.LastNode = int.Parse(this.rbl.SelectedValue.ToString()); classdata.Example = this.txtExample.Text.ToString(); CategoryDAL classSystem = new CategoryDAL();//调用业务层的添加方法 classSystem.AddClass(classdata); this.ClientScript.RegisterStartupScript(this.GetType(), "succeed", "<script>alert('添加成功!')</script>"); this.txtClassName.Text = ""; this.rbl.Items[0].Selected = true; this.txtExample.Text = "";//重新绑定数据到tree中 this.TreeView1.Nodes.Clear(); BindTree(this.TreeView1.Nodes, 0); Response.Redirect("Admin_ClassAdd.aspx"); }
BLL层:
/// <summary> /// 新增分类 /// </summary> /// <param name="classData"></param> public void AddClass(Category classData) { CategoryDAL cdal = new CategoryDAL(); cdal.AddClass(classData); } /// <summary> /// 通过ID号获取信息 /// </summary> /// <param name="parentID"></param> /// <returns></returns> public List<Category> GetClassDataID(int parentID) { return (new CategoryDAL()).GetClassData(parentID); } //根据classID来返回信息 //需要返回参数 public Category GetclassID(int classID) { return (new CategoryDAL()).GetClassID(classID); }
DAL层:
public void AddClass(Category classData) { DataClassesDataContext db = new DataClassesDataContext();//创建数据上下文 db.Category.InsertOnSubmit(classData); //添加新数据到数据实体 db.SubmitChanges();//提交数据更改 } /// <summary> /// 根据parentID号获取一组信息 /// </summary> /// <param name="parentID"></param> /// <returns></returns> public List<Category> GetClassData(int parentID) { DataClassesDataContext db = new DataClassesDataContext();//创建数据上下文 List<Category> mylist = db.Category.Where(c => c.ParentId == parentID).ToList();//返回所有的分类 return mylist; } /// <summary> /// 通过classID来获取信息 /// </summary> /// <param name="classID"></param> /// <returns></returns> public Category GetClassID(int classID) { DataClassesDataContext db = new DataClassesDataContext(); Category classresult = new Category(); try { classresult = db.Category.Where(c => c.ClassId == classID).First(); } catch { } return classresult; }
相关文章推荐
- 分类管理模块-修改新闻分类(简单版本)
- 分类管理模块-删除新闻分类(简单版本)
- RDIFramework.NET ━ .NET快速信息化系统开发框架 V3.2->Web版本模块管理界面新增模块排序功能
- RDIFramework.NET ━ .NET快速信息化系统开发框架 V3.2->Web版本模块管理界面新增模块排序功能
- DNN新闻管理模块使用指南(版本:1.01.03)
- 会员管理模块 - 会员登录功能(简单版本)
- RDIFramework.NET ━ .NET快速信息化系统开发框架 V3.2->Web版本模块管理界面新增模块排序功能
- RDIFramework.NET ━ .NET快速信息化系统开发框架 V3.2->用户管理模块新增“重置用户密码”功能
- npm node 模块管理、简单的dos命令
- eclipse中的maven管理之聚合与继承和版本的简单管理(三)
- ERP基础档案管理模块中实现多级分类档案ID号自动编码技术(V1.0)
- node.js+express+mysql+js分页+bootstrap+文件上传+基本新闻管理模块
- .NET快速信息化系统开发框架 V3.2->Web版本新增“文件管理中心”集上传、下载、文件共享等一身,非常实用的功能
- 实现用户管理模块和新闻类别管理模块
- 关于其它模块的设计,有非常多须要自己去构建和完毕,在这里就简单地举几个样例来看看其它模块的设计。我们要做的就是有更改password模块,客户选择模块和关于本软件模块。更改password模块用来更改管理员的password,客户选择对话框模块用来选择已加入的客户,关于本软件模块用来说明客户管理系统的一些必要信息和制作人的信息。
- RDIFramework.NET ━ .NET快速信息化系统开发框架 V3.2->新增模块管理界面导出功能(可按条件导出)
- SVN版本管理的简单操作
- node.js 中的npm模块版本管理
- smarty实现简单新闻管理系统
- Java语言实现简单FTP软件------>连接管理模块的实现:主机与服务器之间的连接与关闭操作(八)