protected void init_form(string ctrID)
        {
            //取得menu表
            IList<MenuEntity> menuList = DataProvider.GetInstance().GetMenuList(" 1 = 1 ");

            //获取权限表
            IList<GroupsEntity> groupList = DataProvider.GetInstance().GetGroupsList(" 1 = 1 ");

            if (!string.IsNullOrEmpty(ctrID))
            {
                _MenuEntity = DataProvider.GetInstance().GetMenuEntity(int.Parse(ctrID));

                _MenuEntity_parent = DataProvider.GetInstance().GetMenuEntity(_MenuEntity.ParentID);

                _GroupEnty = DataProvider.GetInstance().GetGroupsEntity(_MenuEntity.GroupID);
            }
            if (!IsPostBack)
            {
                //初始化父菜单
                var parentIdDataSource = from parentIdTabels in menuList where parentIdTabels.ParentID == 0 select parentIdTabels;
                DropDownList_parentId.DataSource = parentIdDataSource;
                DropDownList_parentId.DataTextField = "DisplayName";
                DropDownList_parentId.DataValueField = "ID";
                DropDownList_parentId.DataBind();
                DropDownList_parentId.Items.Insert(0, new ListItem("顶级菜单", "0"));


                DropDownList_Group.DataSource = groupList;
                DropDownList_Group.DataTextField = "GroupName";
                DropDownList_Group.DataValueField = "ID";
                DropDownList_Group.DataBind();
                DropDownList_Group.Items.Insert(0, new ListItem("选择分组", "0"));

                DropDownList_Status.DataSource = new List<Status> { new Status(0, "正常"), new Status(1, "暂停"), new Status(2, "已删除") };
                DropDownList_Status.DataTextField = "Text";
                DropDownList_Status.DataValueField = "ID";
                DropDownList_Status.DataBind();
                DropDownList_Status.Items.Insert(0, new ListItem("选择状体", "-1"));

                #region 编辑
                if (!string.IsNullOrEmpty(ctrID))
                {
                    if (_MenuEntity_parent != null)
                    {
                        DropDownList_parentId.ClearSelection();
                        DropDownList_parentId.Items.FindByText(_MenuEntity_parent.DisplayName).Selected = true;
                    }
                    TextBox_DisplayName.Text = _MenuEntity.DisplayName.ToString();
                    TextBox_DisplayIndex.Text = _MenuEntity.DisplayIndex.ToString();
                    if (_GroupEnty != null)
                    {
                        DropDownList_Group.ClearSelection();
                        DropDownList_Group.Items.FindByText(_GroupEnty.GroupName).Selected = true;
                    }
                    TextBox_LinkUrl.Text = _MenuEntity.LinkUrl.ToString();
                    TextBox_ImageUrl.Text = _MenuEntity.ImageUrl.ToString();
                    if (_MenuEntity != null)
                    {
                        DropDownList_Status.ClearSelection();
                        DropDownList_Status.Items.FindByValue(_MenuEntity.Status.ToString()).Selected = true;
                    }
                }
                #endregion
            }
        }
示例#2
0
        private MideFrameWork.Data.Entity.MenuEntity GetMenu(DataRow dr)
        {
            MideFrameWork.Data.Entity.MenuEntity info = new MideFrameWork.Data.Entity.MenuEntity();
										if(DBNull.Value==dr["ID"])
					info.ID=0;
				else
					info.ID=int.Parse(dr["ID"].ToString());
									
																						if(DBNull.Value==dr["ParentID"])
					info.ParentID=0;
				else
					info.ParentID=int.Parse(dr["ParentID"].ToString());
									
																								
						if(DBNull.Value==dr["DisplayName"])
				info.DisplayName= string.Empty;
			else	
				info.DisplayName= dr["DisplayName"].ToString();
																						if(DBNull.Value==dr["DisplayIndex"])
					info.DisplayIndex=0;
				else
					info.DisplayIndex=int.Parse(dr["DisplayIndex"].ToString());
									
																						if(DBNull.Value==dr["GroupID"])
					info.GroupID=0;
				else
					info.GroupID=int.Parse(dr["GroupID"].ToString());
									
																								
						if(DBNull.Value==dr["LinkUrl"])
				info.LinkUrl= string.Empty;
			else	
				info.LinkUrl= dr["LinkUrl"].ToString();
																								
						if(DBNull.Value==dr["ImageUrl"])
				info.ImageUrl= string.Empty;
			else	
				info.ImageUrl= dr["ImageUrl"].ToString();
																						if(DBNull.Value==dr["Status"])
					info.Status=0;
				else
					info.Status=int.Parse(dr["Status"].ToString());
									
																									if(DBNull.Value==dr["CreateDate"])
					info.CreateDate=DateTime.Now;
				else
					info.CreateDate=DateTime.Parse(dr["CreateDate"].ToString());
						
															            return info;
        }
        protected void MenuAdd()
        {
            #region 判断是否可空


            var _ParentID = DropDownList_parentId.SelectedItem.Value;
            if (string.IsNullOrEmpty(_ParentID))
            {
                Alert("[ 父节点ID ]不能为空");
                return;
            }

            var _DisplayName = Request.Form["TextBox_DisplayName"];
            if (string.IsNullOrEmpty(_DisplayName))
            {
                Alert("[ 显示名称 ]不能为空");
                return;
            }

            var _DisplayIndex = Request.Form["TextBox_DisplayIndex"];
            if (string.IsNullOrEmpty(_DisplayIndex))
            {
                //Alert("[ 显示顺序 ]不能为空");
                //return;
                _DisplayIndex = "0";
            }

            var _GroupID = DropDownList_Group.SelectedItem.Value;
            if (string.IsNullOrEmpty(_GroupID))
            {
                Alert("[ 权限组ID ]不能为空");
                return;
            }

            var _LinkUrl = Request.Form["TextBox_LinkUrl"];
            //if (string.IsNullOrEmpty(_LinkUrl))
            //{
            //    Alert("[ 链接URL ]不能为空");
            //    return;
            //}

            var _ImageUrl = Request.Form["TextBox_ImageUrl"];
            //if (string.IsNullOrEmpty(_ImageUrl))
            //{
            //    Alert("[ 图片URL ]不能为空");
            //    return;
            //}

            var _Status = DropDownList_Status.SelectedItem.Value;
            if (string.IsNullOrEmpty(_Status) || int.Parse(_Status) < 0)
            {
                Alert("[ 当前状态 ]不能为空");
                return;
            }

            #endregion

            #region 获取数据

            MenuEntity _MenuEntity = new MenuEntity();


            _MenuEntity.ParentID = Convert.ToInt32(_ParentID.ToString());


            _MenuEntity.DisplayName = Convert.ToString(_DisplayName.ToString());

            _MenuEntity.DisplayIndex = Convert.ToInt32(_DisplayIndex.ToString());

            _MenuEntity.GroupID = Convert.ToInt32(_GroupID.ToString());


            _MenuEntity.LinkUrl = Convert.ToString(_LinkUrl.ToString());


            _MenuEntity.ImageUrl = Convert.ToString(_ImageUrl.ToString());

            _MenuEntity.Status = Convert.ToInt32(_Status.ToString());

            _MenuEntity.CreateDate = DateTime.Now;
            try
            {
                DataProvider.GetInstance().AddMenu(_MenuEntity);
            }
            catch
            {
                WriteLog("MenuAdd", "添加Menu", "插入数据库时出错", Common.DailyUtility.MideSmsType.LogType.SystemLog);
                Alert("添加数据时出错,请重试");
                return;
            }
            Alert("添加Menu成功");
        }