/// <summary> /// ������ϵͳĬ�ϵ��� /// </summary> public int Add(int parent_id, string nav_name, string title, string link_url, int sort_id, int channel_id, string action_type) { if (parent_id < 1) { return 0; } //��ʼ��ֵ Model.navigation model = new Model.navigation(); model.nav_type = DTEnums.NavigationEnum.System.ToString(); model.name = nav_name; model.title = title; model.link_url = link_url; if (sort_id > 0) { model.sort_id = sort_id; } model.parent_id = parent_id; if (channel_id > 0) { model.channel_id = channel_id; } model.action_type = action_type; model.is_sys = 1; return Add(model); }
private bool DoAdd() { try { Model.navigation model = new Model.navigation(); BLL.navigation bll = new BLL.navigation(); model.nav_type = DTEnums.NavigationEnum.System.ToString(); model.name = txtName.Text.Trim(); model.title = txtTitle.Text.Trim(); model.sub_title = txtSubTitle.Text.Trim(); model.icon_url = txtIconUrl.Text.Trim(); model.link_url = txtLinkUrl.Text.Trim(); model.sort_id = int.Parse(txtSortId.Text.Trim()); model.is_lock = 0; if (cbIsLock.Checked == true) { model.is_lock = 1; } model.remark = txtRemark.Text.Trim(); model.parent_id = int.Parse(ddlParentId.SelectedValue); //添加操作权限类型 string action_type_str = string.Empty; for (int i = 0; i < cblActionType.Items.Count; i++) { if (cblActionType.Items[i].Selected && Utils.ActionType().ContainsKey(cblActionType.Items[i].Value)) { action_type_str += cblActionType.Items[i].Value + ","; } } model.action_type = Utils.DelLastComma(action_type_str); if (bll.Add(model) > 0) { AddAdminLog(DTEnums.ActionEnum.Add.ToString(), "添加导航菜单:" + model.title); //记录日志 return true; } } catch { return false; } return false; }
/// <summary> /// 组合成对象实体 /// </summary> private Model.navigation DataRowToModel(DataRow row) { Model.navigation model = new Model.navigation(); if (row != null) { if (row["id"] != null && row["id"].ToString() != "") { model.id = int.Parse(row["id"].ToString()); } if (row["parent_id"] != null && row["parent_id"].ToString() != "") { model.parent_id = int.Parse(row["parent_id"].ToString()); } if (row["channel_id"] != null && row["channel_id"].ToString() != "") { model.channel_id = int.Parse(row["channel_id"].ToString()); } if (row["nav_type"] != null) { model.nav_type = row["nav_type"].ToString(); } if (row["name"] != null) { model.name = row["name"].ToString(); } if (row["title"] != null) { model.title = row["title"].ToString(); } if (row["sub_title"] != null) { model.sub_title = row["sub_title"].ToString(); } if (row["icon_url"] != null) { model.icon_url = row["icon_url"].ToString(); } if (row["link_url"] != null) { model.link_url = row["link_url"].ToString(); } if (row["sort_id"] != null && row["sort_id"].ToString() != "") { model.sort_id = int.Parse(row["sort_id"].ToString()); } if (row["is_lock"] != null && row["is_lock"].ToString() != "") { model.is_lock = int.Parse(row["is_lock"].ToString()); } if (row["remark"] != null) { model.remark = row["remark"].ToString(); } if (row["action_type"] != null) { model.action_type = row["action_type"].ToString(); } if (row["is_sys"] != null && row["is_sys"].ToString() != "") { model.is_sys = int.Parse(row["is_sys"].ToString()); } } return model; }
/// <summary> /// 得到一个对象实体,带事务 /// </summary> public Model.navigation GetModel(SqlConnection conn, SqlTransaction trans, string nav_name) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id,parent_id,channel_id,nav_type,name,title,sub_title,icon_url,link_url,sort_id,is_lock,remark,action_type,is_sys"); strSql.Append(" from " + databaseprefix + "navigation "); strSql.Append(" where name=@nav_name"); SqlParameter[] parameters = { new SqlParameter("@nav_name", SqlDbType.NVarChar,50)}; parameters[0].Value = nav_name; Model.navigation model = new Model.navigation(); DataSet ds = DbHelperSQL.Query(conn, trans, strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return DataRowToModel(ds.Tables[0].Rows[0]); } else { return null; } }
/// <summary> /// 得到一个对象实体 /// </summary> public Model.navigation GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id,parent_id,channel_id,nav_type,name,title,sub_title,icon_url,link_url,sort_id,is_lock,remark,action_type,is_sys"); strSql.Append(" from " + databaseprefix + "navigation "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int,4)}; parameters[0].Value = id; Model.navigation model = new Model.navigation(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return DataRowToModel(ds.Tables[0].Rows[0]); } else { return null; } }
/// <summary> /// �õ�һ������ʵ��(���أ�������) /// </summary> public Model.navigation GetModel(SqlConnection conn, SqlTransaction trans, int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id,nav_type,name,title,sub_title,link_url,sort_id,is_lock,remark,parent_id,class_list,class_layer,channel_id,action_type,is_sys"); strSql.Append(" from " + databaseprefix + "navigation "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int,4)}; parameters[0].Value = id; Model.navigation model = new Model.navigation(); DataSet ds = DbHelperSQL.Query(conn, trans, strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["id"].ToString() != "") { model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString()); } model.nav_type = ds.Tables[0].Rows[0]["nav_type"].ToString(); model.name = ds.Tables[0].Rows[0]["name"].ToString(); model.title = ds.Tables[0].Rows[0]["title"].ToString(); model.sub_title = ds.Tables[0].Rows[0]["sub_title"].ToString(); model.link_url = ds.Tables[0].Rows[0]["link_url"].ToString(); if (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]["is_lock"].ToString() != "") { model.is_lock = int.Parse(ds.Tables[0].Rows[0]["is_lock"].ToString()); } model.remark = ds.Tables[0].Rows[0]["remark"].ToString(); if (ds.Tables[0].Rows[0]["parent_id"].ToString() != "") { model.parent_id = int.Parse(ds.Tables[0].Rows[0]["parent_id"].ToString()); } model.class_list = ds.Tables[0].Rows[0]["class_list"].ToString(); if (ds.Tables[0].Rows[0]["class_layer"].ToString() != "") { model.class_layer = int.Parse(ds.Tables[0].Rows[0]["class_layer"].ToString()); } if (ds.Tables[0].Rows[0]["channel_id"].ToString() != "") { model.channel_id = int.Parse(ds.Tables[0].Rows[0]["channel_id"].ToString()); } model.action_type = ds.Tables[0].Rows[0]["action_type"].ToString(); if (ds.Tables[0].Rows[0]["is_sys"].ToString() != "") { model.is_sys = int.Parse(ds.Tables[0].Rows[0]["is_sys"].ToString()); } return model; } else { return null; } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Model.navigation model) { return(dal.Update(model)); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Model.navigation model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update " + databaseprefix + "navigation set "); strSql.Append("parent_id=@parent_id,"); strSql.Append("channel_id=@channel_id,"); strSql.Append("nav_type=@nav_type,"); strSql.Append("name=@name,"); strSql.Append("title=@title,"); strSql.Append("sub_title=@sub_title,"); strSql.Append("icon_url=@icon_url,"); strSql.Append("link_url=@link_url,"); strSql.Append("sort_id=@sort_id,"); strSql.Append("is_lock=@is_lock,"); strSql.Append("remark=@remark,"); strSql.Append("action_type=@action_type,"); strSql.Append("is_sys=@is_sys"); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@parent_id", SqlDbType.Int, 4), new SqlParameter("@channel_id", SqlDbType.Int, 4), new SqlParameter("@nav_type", SqlDbType.NVarChar, 50), new SqlParameter("@name", SqlDbType.NVarChar, 50), new SqlParameter("@title", SqlDbType.NVarChar, 100), new SqlParameter("@sub_title", SqlDbType.NVarChar, 100), new SqlParameter("@icon_url", SqlDbType.NVarChar, 255), new SqlParameter("@link_url", SqlDbType.NVarChar, 255), new SqlParameter("@sort_id", SqlDbType.Int, 4), new SqlParameter("@is_lock", SqlDbType.TinyInt, 1), new SqlParameter("@remark", SqlDbType.NVarChar, 500), new SqlParameter("@action_type", SqlDbType.NVarChar, 500), new SqlParameter("@is_sys", SqlDbType.TinyInt, 1), new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = model.parent_id; parameters[1].Value = model.channel_id; parameters[2].Value = model.nav_type; parameters[3].Value = model.name; parameters[4].Value = model.title; parameters[5].Value = model.sub_title; parameters[6].Value = model.icon_url; parameters[7].Value = model.link_url; parameters[8].Value = model.sort_id; parameters[9].Value = model.is_lock; parameters[10].Value = model.remark; parameters[11].Value = model.action_type; parameters[12].Value = model.is_sys; parameters[13].Value = model.id; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Model.navigation model) { return(dal.Add(model)); }
/// <summary> /// 组合成对象实体 /// </summary> private Model.navigation DataRowToModel(DataRow row) { Model.navigation model = new Model.navigation(); if (row != null) { if (row["id"] != null && row["id"].ToString() != "") { model.id = int.Parse(row["id"].ToString()); } if (row["parent_id"] != null && row["parent_id"].ToString() != "") { model.parent_id = int.Parse(row["parent_id"].ToString()); } if (row["channel_id"] != null && row["channel_id"].ToString() != "") { model.channel_id = int.Parse(row["channel_id"].ToString()); } if (row["nav_type"] != null) { model.nav_type = row["nav_type"].ToString(); } if (row["name"] != null) { model.name = row["name"].ToString(); } if (row["title"] != null) { model.title = row["title"].ToString(); } if (row["sub_title"] != null) { model.sub_title = row["sub_title"].ToString(); } if (row["icon_url"] != null) { model.icon_url = row["icon_url"].ToString(); } if (row["link_url"] != null) { model.link_url = row["link_url"].ToString(); } if (row["sort_id"] != null && row["sort_id"].ToString() != "") { model.sort_id = int.Parse(row["sort_id"].ToString()); } if (row["is_lock"] != null && row["is_lock"].ToString() != "") { model.is_lock = int.Parse(row["is_lock"].ToString()); } if (row["remark"] != null) { model.remark = row["remark"].ToString(); } if (row["action_type"] != null) { model.action_type = row["action_type"].ToString(); } if (row["is_sys"] != null && row["is_sys"].ToString() != "") { model.is_sys = int.Parse(row["is_sys"].ToString()); } } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Model.navigation model) { using (SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString)) { conn.Open(); using (SqlTransaction trans = conn.BeginTransaction()) { try { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into " + databaseprefix + "navigation("); strSql.Append("nav_type,name,title,sub_title,link_url,sort_id,is_lock,remark,parent_id,class_list,class_layer,channel_id,action_type,is_sys)"); strSql.Append(" values ("); strSql.Append("@nav_type,@name,@title,@sub_title,@link_url,@sort_id,@is_lock,@remark,@parent_id,@class_list,@class_layer,@channel_id,@action_type,@is_sys)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@nav_type", SqlDbType.NVarChar, 50), new SqlParameter("@name", SqlDbType.NVarChar, 50), new SqlParameter("@title", SqlDbType.NVarChar, 100), new SqlParameter("@sub_title", SqlDbType.NVarChar, 100), new SqlParameter("@link_url", SqlDbType.NVarChar, 255), new SqlParameter("@sort_id", SqlDbType.Int, 4), new SqlParameter("@is_lock", SqlDbType.TinyInt, 1), new SqlParameter("@remark", SqlDbType.NVarChar, 500), new SqlParameter("@parent_id", SqlDbType.Int, 4), new SqlParameter("@class_list", SqlDbType.NVarChar, 500), new SqlParameter("@class_layer", SqlDbType.Int, 4), new SqlParameter("@channel_id", SqlDbType.Int, 4), new SqlParameter("@action_type", SqlDbType.NVarChar, 500), new SqlParameter("@is_sys", SqlDbType.TinyInt, 1) }; parameters[0].Value = model.nav_type; parameters[1].Value = model.name; parameters[2].Value = model.title; parameters[3].Value = model.sub_title; parameters[4].Value = model.link_url; parameters[5].Value = model.sort_id; parameters[6].Value = model.is_lock; parameters[7].Value = model.remark; parameters[8].Value = model.parent_id; parameters[9].Value = model.class_list; parameters[10].Value = model.class_layer; parameters[11].Value = model.channel_id; parameters[12].Value = model.action_type; parameters[13].Value = model.is_sys; object obj = DbHelperSQL.GetSingle(conn, trans, strSql.ToString(), parameters); //带事务 model.id = Convert.ToInt32(obj); //得到刚插入的新ID if (model.parent_id > 0) { Model.navigation model2 = GetModel(conn, trans, model.parent_id); //带事务 model.class_list = model2.class_list + model.id + ","; model.class_layer = model2.class_layer + 1; } else { model.class_list = "," + model.id + ","; model.class_layer = 1; } //修改节点列表和深度 DbHelperSQL.ExecuteSql(conn, trans, "update " + databaseprefix + "navigation set class_list='" + model.class_list + "', class_layer=" + model.class_layer + " where id=" + model.id); //带事务 //如无异常则提交事务 trans.Commit(); } catch { trans.Rollback(); return(0); } } } return(model.id); }
/// <summary> /// 得到一个对象实体(重载,带事务) /// </summary> public Model.navigation GetModel(SqlConnection conn, SqlTransaction trans, int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id,nav_type,name,title,sub_title,link_url,sort_id,is_lock,remark,parent_id,class_list,class_layer,channel_id,action_type,is_sys"); strSql.Append(" from " + databaseprefix + "navigation "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = id; Model.navigation model = new Model.navigation(); DataSet ds = DbHelperSQL.Query(conn, trans, strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["id"].ToString() != "") { model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString()); } model.nav_type = ds.Tables[0].Rows[0]["nav_type"].ToString(); model.name = ds.Tables[0].Rows[0]["name"].ToString(); model.title = ds.Tables[0].Rows[0]["title"].ToString(); model.sub_title = ds.Tables[0].Rows[0]["sub_title"].ToString(); model.link_url = ds.Tables[0].Rows[0]["link_url"].ToString(); if (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]["is_lock"].ToString() != "") { model.is_lock = int.Parse(ds.Tables[0].Rows[0]["is_lock"].ToString()); } model.remark = ds.Tables[0].Rows[0]["remark"].ToString(); if (ds.Tables[0].Rows[0]["parent_id"].ToString() != "") { model.parent_id = int.Parse(ds.Tables[0].Rows[0]["parent_id"].ToString()); } model.class_list = ds.Tables[0].Rows[0]["class_list"].ToString(); if (ds.Tables[0].Rows[0]["class_layer"].ToString() != "") { model.class_layer = int.Parse(ds.Tables[0].Rows[0]["class_layer"].ToString()); } if (ds.Tables[0].Rows[0]["channel_id"].ToString() != "") { model.channel_id = int.Parse(ds.Tables[0].Rows[0]["channel_id"].ToString()); } model.action_type = ds.Tables[0].Rows[0]["action_type"].ToString(); if (ds.Tables[0].Rows[0]["is_sys"].ToString() != "") { model.is_sys = int.Parse(ds.Tables[0].Rows[0]["is_sys"].ToString()); } return(model); } else { return(null); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Model.navigation model) { Model.navigation oldModel = GetModel(model.id); //旧的数据 using (SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString)) { conn.Open(); using (SqlTransaction trans = conn.BeginTransaction()) { try { //先判断选中的父节点是否被包含 if (IsContainNode(model.id, model.parent_id)) { //查找旧父节点数据 string class_list = "," + model.parent_id + ","; int class_layer = 1; if (oldModel.parent_id > 0) { Model.navigation oldParentModel = GetModel(conn, trans, oldModel.parent_id); //带事务 class_list = oldParentModel.class_list + model.parent_id + ","; class_layer = oldParentModel.class_layer + 1; } //先提升选中的父节点 DbHelperSQL.ExecuteSql(conn, trans, "update " + databaseprefix + "navigation set parent_id=" + oldModel.parent_id + ",class_list='" + class_list + "', class_layer=" + class_layer + " where id=" + model.parent_id); //带事务 UpdateChilds(conn, trans, model.parent_id); //带事务 } //更新子节点 if (model.parent_id > 0) { Model.navigation model2 = GetModel(conn, trans, model.parent_id); //带事务 model.class_list = model2.class_list + model.id + ","; model.class_layer = model2.class_layer + 1; } else { model.class_list = "," + model.id + ","; model.class_layer = 1; } StringBuilder strSql = new StringBuilder(); strSql.Append("update " + databaseprefix + "navigation set "); strSql.Append("nav_type=@nav_type,"); strSql.Append("name=@name,"); strSql.Append("title=@title,"); strSql.Append("sub_title=@sub_title,"); strSql.Append("link_url=@link_url,"); strSql.Append("sort_id=@sort_id,"); strSql.Append("is_lock=@is_lock,"); strSql.Append("remark=@remark,"); strSql.Append("parent_id=@parent_id,"); strSql.Append("class_list=@class_list,"); strSql.Append("class_layer=@class_layer,"); strSql.Append("channel_id=@channel_id,"); strSql.Append("action_type=@action_type,"); strSql.Append("is_sys=@is_sys"); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@nav_type", SqlDbType.NVarChar, 50), new SqlParameter("@name", SqlDbType.NVarChar, 50), new SqlParameter("@title", SqlDbType.NVarChar, 100), new SqlParameter("@sub_title", SqlDbType.NVarChar, 100), new SqlParameter("@link_url", SqlDbType.NVarChar, 255), new SqlParameter("@sort_id", SqlDbType.Int, 4), new SqlParameter("@is_lock", SqlDbType.TinyInt, 1), new SqlParameter("@remark", SqlDbType.NVarChar, 500), new SqlParameter("@parent_id", SqlDbType.Int, 4), new SqlParameter("@class_list", SqlDbType.NVarChar, 500), new SqlParameter("@class_layer", SqlDbType.Int, 4), new SqlParameter("@channel_id", SqlDbType.Int, 4), new SqlParameter("@action_type", SqlDbType.NVarChar, 500), new SqlParameter("@is_sys", SqlDbType.TinyInt, 1), new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = model.nav_type; parameters[1].Value = model.name; parameters[2].Value = model.title; parameters[3].Value = model.sub_title; parameters[4].Value = model.link_url; parameters[5].Value = model.sort_id; parameters[6].Value = model.is_lock; parameters[7].Value = model.remark; parameters[8].Value = model.parent_id; parameters[9].Value = model.class_list; parameters[10].Value = model.class_layer; parameters[11].Value = model.channel_id; parameters[12].Value = model.action_type; parameters[13].Value = model.is_sys; parameters[14].Value = model.id; DbHelperSQL.ExecuteSql(conn, trans, strSql.ToString(), parameters); //更新子节点 UpdateChilds(conn, trans, model.id); //如无发生错误则提交事务 trans.Commit(); } catch { trans.Rollback(); return(false); } } } return(true); }