Exemple #1
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(SysMenuEntity model)
        {
            int iExecute = 0;
            try
            {
                StringBuilder strSql = new StringBuilder();
                strSql.Append("insert into Sys_Menu(");
                strSql.Append("MenuName,MenuLinkRoute,MenuTarget,ParentId)");
                strSql.Append(" values (");
                strSql.Append("@MenuName,@MenuLinkRoute,@MenuTarget,@ParentId)");
                strSql.Append(";select @@IDENTITY");
                SqlParameter[] parameters = {
                    new SqlParameter("@MenuName", SqlDbType.NVarChar,30),
                    new SqlParameter("@MenuLinkRoute", SqlDbType.NVarChar,100),
                    new SqlParameter("@MenuTarget", SqlDbType.NVarChar,30),
                    new SqlParameter("@ParentId", SqlDbType.Int,4)};
                parameters[0].Value = model.menuName;
                parameters[1].Value = model.menuLinkRoute;
                parameters[2].Value = model.menuTarget;
                parameters[3].Value = model.parentID;

                object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
                if (obj != null)
                {
                    iExecute = Convert.ToInt32(obj);
                }
            }
            catch (Exception e)
            {
                Log4Net.LogWrite("err", "SysAccessData.SysManage.SysMenuManage\\DacMenuInfo\\Add" + e.Message);
            }
            return iExecute;
        }
Exemple #2
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            Ctrl_Sys_Menu dacMenuInfo = new Ctrl_Sys_Menu();

            int iMenuId = int.Parse(hdMenuId.Value.ToString());
            SysMenuEntity menuEntity = new SysMenuEntity();
            menuEntity.menuID = iMenuId;
            menuEntity.menuLinkRoute = txtLinkRoute.Text;
            menuEntity.menuName = txtMenuName.Text;
            menuEntity.menuTarget = txtShowTarget.Text;
            menuEntity.parentID = int.Parse(drpParentMenu.SelectedValue);

            if (hdMenuId.Value == "0")
            {
                if (dacMenuInfo.Add(menuEntity) > 0)
                {
                    MessageBox.ShowAndRedirect(this, "成功添加一条数据!", "MenuInfoList.aspx");
                }
                else
                {
                    MessageBox.Show(this, "添加数据失败,请与管理员联系!");
                }
            }
            else
            {
                if (drpParentMenu.SelectedValue == hdMenuId.Value)
                {
                    MessageBox.Show(this, "不允许选择自身,自为父菜单!");
                }

                if (dacMenuInfo.Update(menuEntity))
                {
                    MessageBox.ShowAndRedirect(this, "成功修改一条数据!", "MenuInfoList.aspx");
                }
                else
                {
                    MessageBox.Show(this, "修改数据失败,请与管理员联系!");
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(SysMenuEntity model)
        {
            bool iExecute = false;
            try
            {
                StringBuilder strSql = new StringBuilder();
                strSql.Append("update Sys_Menu set ");
                strSql.Append("MenuName=@MenuName,");
                strSql.Append("MenuLinkRoute=@MenuLinkRoute,");
                strSql.Append("MenuTarget=@MenuTarget,");
                strSql.Append("ParentId=@ParentId");
                strSql.Append(" where Id=@menuID");
                SqlParameter[] parameters = {
                    new SqlParameter("@menuName", SqlDbType.NVarChar,30),
                    new SqlParameter("@menuLinkRoute", SqlDbType.NVarChar,100),
                    new SqlParameter("@menuTarget", SqlDbType.NVarChar,30),
                    new SqlParameter("@parentID", SqlDbType.Int,4),
                    new SqlParameter("@menuID", SqlDbType.Int,4)};
                parameters[0].Value = model.menuName;
                parameters[1].Value = model.menuLinkRoute;
                parameters[2].Value = model.menuTarget;
                parameters[3].Value = model.parentID;
                parameters[4].Value = model.menuID;

                int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
                if (rows > 0)
                {
                    iExecute = true;
                }
            }
            catch (Exception e)
            {
                Log4Net.LogWrite("err", "SysAccessData.SysManage.SysMenuManage\\DacMenuInfo\\Update" + e.Message);
            }
            return iExecute;
        }
Exemple #4
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public SysMenuEntity GetModel(int menuID)
        {
            SysMenuEntity model = null;
            try
            {
                StringBuilder strSql = new StringBuilder();
                strSql.Append("select  top 1 MenuName,MenuLinkRoute,MenuTarget,Id as menuID,ParentId from Sys_Menu ");
                strSql.Append(" where Id=@menuID");
                SqlParameter[] parameters = {
                    new SqlParameter("@menuID", SqlDbType.Int,4)
            };
                parameters[0].Value = menuID;

                model = new SysMenuEntity();
                DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
                if (ds.Tables[0].Rows.Count > 0)
                {
                    if (ds.Tables[0].Rows[0]["MenuName"] != null && ds.Tables[0].Rows[0]["MenuName"].ToString() != "")
                    {
                        model.menuName = ds.Tables[0].Rows[0]["MenuName"].ToString();
                    }
                    if (ds.Tables[0].Rows[0]["MenuLinkRoute"] != null && ds.Tables[0].Rows[0]["MenuLinkRoute"].ToString() != "")
                    {
                        model.menuLinkRoute = ds.Tables[0].Rows[0]["MenuLinkRoute"].ToString();
                    }
                    if (ds.Tables[0].Rows[0]["MenuTarget"] != null && ds.Tables[0].Rows[0]["MenuTarget"].ToString() != "")
                    {
                        model.menuTarget = ds.Tables[0].Rows[0]["MenuTarget"].ToString();
                    }
                    if (ds.Tables[0].Rows[0]["menuID"] != null && ds.Tables[0].Rows[0]["menuID"].ToString() != "")
                    {
                        model.menuID = int.Parse(ds.Tables[0].Rows[0]["menuID"].ToString());
                    }
                    if (ds.Tables[0].Rows[0]["ParentId"] != null && ds.Tables[0].Rows[0]["ParentId"].ToString() != "")
                    {
                        model.parentID = int.Parse(ds.Tables[0].Rows[0]["ParentId"].ToString());
                    }
                }
            }
            catch (Exception e)
            {
                Log4Net.LogWrite("err", "SysAccessData.SysManage.SysMenuManage\\DacMenuInfo\\GetModel" + e.Message);
            }
            return model;
        }