首页 > 代码库 > ERP数据通用存储过程封装(三)
ERP数据通用存储过程封装(三)
引用:DAL;System.Data.SqlClient;System.Data;
namespace CommTool{ public class SqlComm { /// <summary> /// 根据指定条件,删除指定的表里面的数据 /// </summary> /// <param name="tableName">指定表名</param> /// <param name="condition">指定条件 需要Where</param> /// <returns>bool</returns> public static bool DeleteTableByCondition(string tableName, string condition) { SqlParameter[] pars = new SqlParameter[]{ new SqlParameter("@tableName",tableName), new SqlParameter("@condition",condition) }; int count= DataBaseHelper.ExcuteSqlReturnInt("DeleteTableByCondition", CommandType.StoredProcedure, pars); if (count > 0) { return true; } else { return false; } } /// <summary> /// 通用的修改方法 /// </summary> /// <param name="tableName">指定表名</param> /// <param name="columns">要修改的列 如" username=‘张三‘,pwd=‘123‘ "</param> /// <param name="conditions">修改的条件,不需要where</param> /// <returns>bool</returns> public static bool UpdateTableByCondition(string tableName, string columns, string conditions) { SqlParameter[] pars = new SqlParameter[]{ new SqlParameter("@tableName",tableName), new SqlParameter("@columns",columns), new SqlParameter("@conditions",conditions) }; int count = DataBaseHelper.ExcuteSqlReturnInt("UpdateTableByCondition", CommandType.StoredProcedure, pars); if (count > 0) { return true; } else { return false; } } /// <summary> /// 通用的添加功能存储过程 /// </summary> /// <param name="tbName">指定要添加的表名</param> /// <param name="fldName">指定要添加哪些列 如username,pwd,departmentid</param> /// <param name="fldValue">指定哪些列对应的值 如‘张三‘,‘123‘,1</param> /// <returns>bool</returns> public static bool CommInsertTable(string tbName, string fldName, string fldValue) { SqlParameter[] pars = new SqlParameter[]{ new SqlParameter("@tbName",tbName), new SqlParameter("@fldName",fldName), new SqlParameter("@fldValue",fldValue) }; int count= DataBaseHelper.ExcuteSqlReturnInt("CommonInsertProc", CommandType.StoredProcedure, pars); if (count > 0) { return true; } else { return false; } } /// <summary> /// 根据表名查询数据 /// </summary> /// <param name="tableName">要查询的表</param> /// <returns>dataset</returns> public static DataSet GetDataByTableName(string tableName) { SqlParameter[] pars = new SqlParameter[]{ new SqlParameter("@tableName",tableName) }; return DataBaseHelper.SelectSQLReturnDataSet("GetDataByTableName", CommandType.StoredProcedure, pars); } /// <summary> /// 查询指定表,指定列所有数据 /// </summary> /// <param name="tableName">指定表名</param> /// <param name="columns">指定列名</param> /// <returns>DataSet</returns> public static DataSet GetDataByTableNameValue(string tableName, string columns) { SqlParameter[] pars = new SqlParameter[]{ new SqlParameter("@tableName",tableName), new SqlParameter("@columns",columns) }; return DataBaseHelper.SelectSQLReturnDataSet("getDataByTableNameValue", CommandType.StoredProcedure, pars); } /// <summary> /// 查询指定列,指定表,指定条件的数据 /// </summary> /// <param name="tableName">指定的表名</param> /// <param name="columns">指定列名</param> /// <param name="condition">指定的条件 不需要写where,直接跟条件</param> /// <returns>DataSet</returns> public static DataSet GetDataByCondition(string tableName, string columns, string condition) { SqlParameter[] pars = new SqlParameter[]{ new SqlParameter("@tableName",tableName), new SqlParameter("@columns",columns), new SqlParameter("@condition",condition) }; return DataBaseHelper.SelectSQLReturnDataSet("GetDataByCondition", CommandType.StoredProcedure, pars); } /// <summary> /// 通用的分页方法 /// </summary> /// <param name="table">要查询的表或视图</param> /// <param name="coumlns">要查询的列</param> /// <param name="pk">主键</param> /// <param name="condition">查询的条件</param> /// <param name="pageindex">页码</param> /// <param name="pagesize">每页显示条数</param> /// <returns>DataTable</returns> public static DataTable getDataByPageIndex(string table, string coumlns, string pk, string condition, int pageindex, int pagesize) { SqlParameter[] pars = new SqlParameter[]{ new SqlParameter("@table",table), new SqlParameter("@coumlns",coumlns), new SqlParameter("@pk",pk), new SqlParameter("@condition",condition), new SqlParameter("@pageindex",pageindex), new SqlParameter("@pagesize",pagesize) }; return DataBaseHelper.SelectSQLReturnTable("getDataByPageIndex", CommandType.StoredProcedure, pars); } }}
二:后台管理系统中常用的导航菜单设计
1.通过静态的Ul,li标签设计
2.通过XML文件进行配置,绑定到TREEVIEW控件
3.通过数据库设计,绑定到TREEVIEW控件
三:树形菜单的设计原理:
1.查询顶级节点菜单
2.遍历顶级菜单至树形控件
3.查询下一级菜单绑定至顶级菜单
四:TreeView控件的用法
1.TreeNode:TreeView 节点对象
2.NavigateUrl:导航
3.ChildNodes:子节点对象
具体的代码:
一:添加导航
效果:(当然有很多样式,可以自行修改)
数据库的设计:
代码:
public partial class MenuLeft : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { CreateTreeVeiw(); } } DataSet ds; DataTable dt; private void CreateTreeView() { ds = SqlComm.GetDataByTableName("TreeMenu"); } private void CreateTreeVeiw() { ds = SqlComm.GetDataByTableName("TreeMenu"); dt = new DataTable(); //取出第一个值 dt = ds.Tables[0]; //数据视图 在dt中选择想要的数据 DataView dv = new DataView(dt, "ParentId=0", "NodeId", DataViewRowState.CurrentRows); //遍历父节点 foreach (DataRowView d in dv) { //创建一个TreeNode对象 TreeNode n = new TreeNode(d["Text"].ToString(), d["Url"].ToString()); //指定相应的属性 n.NavigateUrl = d["Url"].ToString(); n.ImageToolTip = dt.TableName; //给树形菜单赋值 TreeView1.Nodes.Add(n); //根据父节点筛选出对应的子节点 dv = new DataView(dt, "ParentId=‘" + d["NodeId"] + "‘", "NodeId", DataViewRowState.CurrentRows); if (dv.Count>0) { CreateSubTreeView(n, dv); } } } /// <summary> /// 添加子项 /// </summary> /// <param name="n"></param> /// <param name="dv"></param> private void CreateSubTreeView(TreeNode n, DataView dv) { foreach (DataRowView d in dv) { TreeNode cn = new TreeNode(d["Text"].ToString(), d["Url"].ToString()); cn.NavigateUrl = d["Url"].ToString(); n.ChildNodes.Add(cn); DataView sdv = new DataView(dt, "ParentId=‘" + d["NodeId"] + "‘", "NodeId", DataViewRowState.CurrentRows); if (sdv.Count > 0) { //实现了递归 CreateSubTreeView(cn, sdv); } } } }
ERP数据通用存储过程封装(三)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。