/// <summary>
        /// 得到一个对象实体,带事务
        /// </summary>
        public Model.sys_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 + "sys_navigation ");
            strSql.Append(" where name=@nav_name");
            SqlParameter[] parameters =
            {
                new SqlParameter("@nav_name", SqlDbType.NVarChar, 50)
            };
            parameters[0].Value = nav_name;

            Model.sys_navigation model = new Model.sys_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.sys_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 + "sys_navigation ");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@id", SqlDbType.Int, 4)
            };
            parameters[0].Value = id;

            Model.sys_navigation model = new Model.sys_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);
            }
        }
示例#3
0
        private bool DoEdit(int _id)
        {
            try
            {
                BLL.sys_navigation   bll   = new BLL.sys_navigation();
                Model.sys_navigation model = bll.GetModel(_id);

                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();
                if (model.is_sys == 0)
                {
                    int parentId = int.Parse(ddlParentId.SelectedValue);
                    //如果选择的父ID不是自己,则更改
                    if (parentId != model.id)
                    {
                        model.parent_id = parentId;
                    }
                }

                //添加操作权限类型
                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.Update(model))
                {
                    AddAdminLog(EnumCollection.ActionEnum.Add.ToString(), "修改导航菜单:" + model.title); //记录日志
                    return(true);
                }
            }
            catch
            {
                return(false);
            }
            return(false);
        }
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Model.sys_navigation model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into " + databaseprefix + "sys_navigation(");
            strSql.Append("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(" values (");
            strSql.Append("@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(";select @@IDENTITY");
            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)
            };
            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;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
示例#5
0
        private void ShowInfo(int _id)
        {
            BLL.sys_navigation   bll   = new BLL.sys_navigation();
            Model.sys_navigation model = bll.GetModel(_id);

            ddlParentId.SelectedValue = model.parent_id.ToString();
            txtSortId.Text            = model.sort_id.ToString();
            if (model.is_lock == 1)
            {
                cbIsLock.Checked = true;
            }
            txtName.Text = model.name;
            txtName.Attributes.Add("ajaxurl", "../../tools/admin_ajax.ashx?action=navigation_validate&old_name=" + Utils.UrlEncode(model.name));
            txtName.Focus(); //设置焦点,防止JS无法提交
            if (model.is_sys == 1)
            {
                ddlParentId.Enabled = false;
                txtName.ReadOnly    = true;
            }
            txtTitle.Text    = model.title;
            txtSubTitle.Text = model.sub_title;
            txtIconUrl.Text  = model.icon_url;
            txtLinkUrl.Text  = model.link_url;
            txtRemark.Text   = model.remark;
            //赋值操作权限类型
            string[] actionTypeArr = model.action_type.Split(',');
            for (int i = 0; i < cblActionType.Items.Count; i++)
            {
                for (int n = 0; n < actionTypeArr.Length; n++)
                {
                    if (actionTypeArr[n].ToLower() == cblActionType.Items[i].Value.ToLower())
                    {
                        cblActionType.Items[i].Selected = true;
                    }
                }
            }
        }
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public bool Update(Model.sys_navigation model)
 {
     return(dal.Update(model));
 }
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public int Add(Model.sys_navigation model)
 {
     return(dal.Add(model));
 }
 /// <summary>
 /// 组合成对象实体
 /// </summary>
 private Model.sys_navigation DataRowToModel(DataRow row)
 {
     Model.sys_navigation model = new Model.sys_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 bool Update(Model.sys_navigation model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update " + databaseprefix + "sys_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);
            }
        }