/// <summary>
        /// 添加新菜单,及授权信息
        /// </summary>
        /// <param name="menu"></param>
        /// <param name="isForced">是否强制覆盖具有相同基本URL菜单的授权</param>
        /// <returns>
        /// 0: 正常操作
        /// 1: 当前应用的父分类不存在
        /// 2: 当前应用中的URL已经被添加
        /// 3:  授权冲突,已存在相应基本URL的授权
        /// 4: 授权类型不正确
        /// 5: 输入的URL有错误
        /// 6:  当前应用不存在
        ///</returns>
        public override int AddMenuItem(AspnetMenuItem menu, bool isForced)
        {
            string    spname = "aspnet_Menu_Add";
            Database  db     = DatabaseFactory.CreateDatabase(_connectionStringName);
            DbCommand comm   = db.GetStoredProcCommand(spname);

            db.AddParameter(comm, "@ReturnValue", DbType.Int32, ParameterDirection.ReturnValue,
                            String.Empty, DataRowVersion.Default, null);
            db.AddInParameter(comm, "@ApplicationName", DbType.String, _applicationName);
            db.AddInParameter(comm, "@Url", DbType.String, menu.Url);
            db.AddInParameter(comm, "@Title", DbType.String, menu.Title);
            db.AddInParameter(comm, "@FatherId", DbType.String, menu.FatherId);
            db.AddInParameter(comm, "@ItemType", DbType.String, menu.ItemType);
            db.AddInParameter(comm, "@Description", DbType.String, menu.Description);
            db.AddInParameter(comm, "@Keywords", DbType.String, menu.Keywords);
            db.AddInParameter(comm, "@AuthType", DbType.Int16, menu.AuthType);
            db.AddInParameter(comm, "@Roles", DbType.String, String.Join(",", menu.Roles));
            db.AddInParameter(comm, "@IsForced", DbType.Int16, isForced?1:0);
            db.AddOutParameter(comm, "@MenuId", DbType.Int32, 4);
            db.ExecuteNonQuery(comm);
            int result = (int)db.GetParameterValue(comm, "@ReturnValue");

            if (result == 0)
            {
                menu.MenuId = (int)db.GetParameterValue(comm, "@MenuId");
            }
            return(result);
        }
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public override AspnetMenuItem GetMenuItem(int MenuId)
        {
            string    spname = "aspnet_Menu_GetModel";
            Database  db     = DatabaseFactory.CreateDatabase(_connectionStringName);
            DbCommand comm   = db.GetStoredProcCommand(spname);

            db.AddParameter(comm, "@ReturnValue", DbType.Int32, ParameterDirection.ReturnValue,
                            String.Empty, DataRowVersion.Default, null);
            db.AddInParameter(comm, "@MenuId", DbType.Int32, MenuId);
            DataSet ds = db.ExecuteDataSet(comm);

            AspnetMenuItem model = new AspnetMenuItem();

            model.MenuId = MenuId;
            if (ds.Tables[0].Rows.Count > 0)
            {
                model.Url   = ds.Tables[0].Rows[0]["Url"].ToString();
                model.Title = ds.Tables[0].Rows[0]["Title"].ToString();
                if (ds.Tables[0].Rows[0]["FatherId"].ToString() != "")
                {
                    model.FatherId = int.Parse(ds.Tables[0].Rows[0]["FatherId"].ToString());
                }
                model.Path = ds.Tables[0].Rows[0]["Path"].ToString();
                if (ds.Tables[0].Rows[0]["ItemType"].ToString() != "")
                {
                    model.ItemType = int.Parse(ds.Tables[0].Rows[0]["ItemType"].ToString());
                }
                model.Description = ds.Tables[0].Rows[0]["Description"].ToString();
                model.Keywords    = ds.Tables[0].Rows[0]["Keywords"].ToString();
                if (ds.Tables[0].Rows[0]["AuthType"].ToString() != "")
                {
                    model.AuthType = int.Parse(ds.Tables[0].Rows[0]["AuthType"].ToString());
                }
                model.Roles = ds.Tables[0].Rows[0]["Roles"].ToString().Split(',');
                return(model);
            }
            else
            {
                return(null);
            }
        }
 /// <summary>
 /// ����²˵�������Ȩ��Ϣ
 /// </summary>
 /// <param name="menu"></param>
 /// <param name="isForced">�Ƿ�ǿ�Ƹ��Ǿ�����ͬ����URL�˵�����Ȩ</param>
 /// <returns>
 /// 0�� ��������
 /// 1�� ��ǰӦ�õĸ����಻����
 /// 2�� ��ǰӦ���е�URL�Ѿ������
 /// 3��  ��Ȩ��ͻ���Ѵ�����Ӧ����URL����Ȩ
 /// 4�� ��Ȩ���Ͳ���ȷ
 /// 5�� �����URL���
 /// 6��  ��ǰӦ�ò����� 
 ///</returns>
 public override int AddMenuItem(AspnetMenuItem menu,bool isForced)
 {
     string spname = "aspnet_Menu_Add";
     Database db = DatabaseFactory.CreateDatabase(_connectionStringName);
     DbCommand comm = db.GetStoredProcCommand(spname);
     db.AddParameter(comm, "@ReturnValue", DbType.Int32, ParameterDirection.ReturnValue,
         String.Empty, DataRowVersion.Default, null);
     db.AddInParameter(comm, "@ApplicationName", DbType.String, _applicationName);
     db.AddInParameter(comm, "@Url", DbType.String, menu.Url);
     db.AddInParameter(comm, "@Title", DbType.String, menu.Title);
     db.AddInParameter(comm, "@FatherId", DbType.String, menu.FatherId);
     db.AddInParameter(comm, "@ItemType", DbType.String, menu.ItemType);
     db.AddInParameter(comm, "@Description", DbType.String, menu.Description);
     db.AddInParameter(comm, "@Keywords", DbType.String, menu.Keywords);
     db.AddInParameter(comm,"@AuthType",DbType.Int16,menu.AuthType);
     db.AddInParameter(comm,"@Roles",DbType.String,String.Join(",",menu.Roles));
     db.AddInParameter(comm,"@IsForced",DbType.Int16,isForced?1:0);
     db.AddOutParameter(comm, "@MenuId", DbType.Int32, 4);
     db.ExecuteNonQuery(comm);
     int result = (int)db.GetParameterValue(comm, "@ReturnValue");
     if (result == 0)
     {
         menu.MenuId = (int)db.GetParameterValue(comm, "@MenuId");
     }
     return result;
 }
 /// <summary>
 /// ����µIJ˵���
 /// </summary>
 public static int AddMenuItem(AspnetMenuItem menu,bool isForced)
 {
     return  _provider.AddMenuItem(menu, isForced);
 }
 /// <summary>
 /// 更新菜单授权信息
 /// </summary>
 /// <param name="menu"></param>
 /// <param name="isForced">是否强制覆盖具有相同基本URL菜单的授权</param>
 /// <returns></returns>
 public abstract int UpdateMenuItem(AspnetMenuItem menu, bool isForced);
        /// <summary>
        /// �õ�һ������ʵ��
        /// </summary>
        public override AspnetMenuItem GetMenuItem(int MenuId)
        {
            string spname = "aspnet_Menu_GetModel";
            Database db = DatabaseFactory.CreateDatabase(_connectionStringName);
            DbCommand comm = db.GetStoredProcCommand(spname);
            db.AddParameter(comm, "@ReturnValue", DbType.Int32, ParameterDirection.ReturnValue,
               String.Empty, DataRowVersion.Default, null);
            db.AddInParameter(comm, "@MenuId", DbType.Int32, MenuId);
            DataSet ds = db.ExecuteDataSet(comm);

            AspnetMenuItem model = new AspnetMenuItem();

            model.MenuId = MenuId;
            if (ds.Tables[0].Rows.Count > 0)
            {
                model.Url = ds.Tables[0].Rows[0]["Url"].ToString();
                model.Title = ds.Tables[0].Rows[0]["Title"].ToString();
                if (ds.Tables[0].Rows[0]["FatherId"].ToString() != "")
                {
                    model.FatherId = int.Parse(ds.Tables[0].Rows[0]["FatherId"].ToString());
                }
                model.Path = ds.Tables[0].Rows[0]["Path"].ToString();
                if (ds.Tables[0].Rows[0]["ItemType"].ToString() != "")
                {
                    model.ItemType = int.Parse(ds.Tables[0].Rows[0]["ItemType"].ToString());
                }
                model.Description = ds.Tables[0].Rows[0]["Description"].ToString();
                model.Keywords = ds.Tables[0].Rows[0]["Keywords"].ToString();
                if (ds.Tables[0].Rows[0]["AuthType"].ToString() != "")
                {
                    model.AuthType = int.Parse(ds.Tables[0].Rows[0]["AuthType"].ToString());
                }
                model.Roles = ds.Tables[0].Rows[0]["Roles"].ToString().Split(',');
                return model;
            }
            else
            {
                return null;
            }
        }
 /// <summary>
 /// 添加新菜单,及授权信息
 /// </summary>
 /// <param name="menu"></param>
 /// <param name="isForced">是否强制覆盖具有相同基本URL菜单的授权</param>
 /// <returns></returns>
 public abstract int AddMenuItem(AspnetMenuItem menu, bool isForced);
        /// <summary>
        /// ����˵��ڵ�
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            int result = -1;
            bool isForced = chkIsForced.Checked;

            AspnetMenuItem item = new AspnetMenuItem();
            if (lblMenuId.Text != "")
            {
                item.MenuId = int.Parse(lblMenuId.Text);
            }

            if (lblFatherId.Text == "")
                item.FatherId = 0;
            else
                item.FatherId = int.Parse(lblFatherId.Text);

            item.Title = txtMenuName.Text;
            item.Description = txtdescription.Text.Trim();
            item.Keywords = txtMenuKeys.Text.Trim();
            item.Url = txtUrl.Text.Trim();
            item.ItemType = int.Parse(rblItemType.SelectedValue);
            item.AuthType = int.Parse(rblAuthType.SelectedValue);

            if (item.AuthType == 3)
            {
                List<string> roles = new List<string>();
                foreach (ListItem ritem in chkRoles.Items)
                {
                    if (ritem.Selected)
                        roles.Add(ritem.Text);
                }
                item.Roles = roles.ToArray();
            }
            else
            {
                item.Roles = new string[0];
            }

            if (item.MenuId > 0)
            {
                result = AspnetMenu.UpdateMenuItem(item, isForced);
            }
            else
            {
                result = AspnetMenu.AddMenuItem(item, isForced);
            }

                /*
                    0�� ��������
                    1�� ��ǰӦ�õĸ����಻����
                    2�� ��ǰӦ���е�URL�Ѿ������
                    3��  ��Ȩ��ͻ���Ѵ�����Ӧ����URL����Ȩ
                    4�� ��Ȩ���Ͳ���ȷ
                    5�� �����URL���
                    6��  ��ǰӦ�ò�����
                 * */
            switch (result)
            {
                case 0:
                    lblResult.Text = "�����ɹ�";
                    break;
                case 1:
                    lblResult.Text = "��ǰӦ�õĸ����಻����";
                    break;
                case 2:
                    lblResult.Text = "��ǰӦ���е�URL�Ѿ�����ӣ�����ͨ����Ӳ�������֤url����ͻ";
                    break;
                case 3:
                    lblResult.Text = "��Ȩ��ͻ���Ѵ�����Ӧ����URL����Ȩ";
                    break;
                case 4:
                    lblResult.Text = "��Ȩ���Ͳ���ȷ";
                    break;
                case 5:
                    lblResult.Text = "�����URL���";
                    break;
                case 6:
                    lblResult.Text = "��ǰӦ�ò�����";
                    break;
                default:
                    lblResult.Text = "������ȷ������";
                    break;
            }
            BindMenuTreeView();
        }
Exemple #9
0
 /// <summary>
 /// 保存菜单项
 /// </summary>
 public static int UpdateMenuItem(AspnetMenuItem menu, bool isForced)
 {
     return(_provider.UpdateMenuItem(menu, isForced));
 }
 /// <summary>
 /// ����²˵�������Ȩ��Ϣ
 /// </summary>
 /// <param name="menu"></param>
 /// <param name="isForced">�Ƿ�ǿ�Ƹ��Ǿ�����ͬ����URL�˵�����Ȩ</param>
 /// <returns></returns>
 public abstract int AddMenuItem(AspnetMenuItem menu, bool isForced);
 /// <summary>
 /// ���²˵���Ȩ��Ϣ
 /// </summary>
 /// <param name="menu"></param>
 /// <param name="isForced">�Ƿ�ǿ�Ƹ��Ǿ�����ͬ����URL�˵�����Ȩ</param>
 /// <returns></returns>
 public abstract int UpdateMenuItem(AspnetMenuItem menu, bool isForced);