/// <summary>
 /// 初始化功能
 /// </summary>
 /// <param name="code"></param>
 public static void InItFunc(string code)
 {
     string[] curd     = new[] { "新增", "修改", "删除" };
     string[] curdCode = new[] { "Add", "Update", "Delete" };
     using (var conn = DataHelper.GetConnection())
     {
         for (int i = 0; i < curd.Length; i++)
         {
             var             name   = curd[i];
             var             incode = curdCode[i];
             BA_FunctionAuth bA     = new BA_FunctionAuth
             {
                 Code        = incode,
                 Description = name,
                 MenuCode    = code,
                 InIdCode    = code.CombineCode(incode),
                 FuncName    = name
             };
             conn.Insert(bA);
         }
     }
 }
Пример #2
0
        private void btn_save_Click(object sender, EventArgs e)
        {
            var Id       = this.txt_id.Value;             //id
            var MenuCode = this.txt_menuCode.Text.Trim(); //菜单编号
            var InIdCode = this.txt_InIdCode.Text.Trim(); //功能唯一标识码
            var Code     = this.txt_code.Text.Trim();     //功能编号

            if (IsSuccess(Code, "功能编码不能为空!"))
            {
                return;
            }
            var FuncName = this.txt_name.Text;//功能名称

            if (IsSuccess(FuncName, "功能名称不能为空!"))
            {
                return;
            }
            var  Descrition = this.txt_description.Text.Trim();                                //功能描述
            var  icon       = this.txt_icon.Text.Trim();                                       //图标
            var  isbyte     = byte.TryParse(this.txt_iconType.Text.Trim(), out byte iconType); //图标类型
            var  iconColor  = this.txt_iconColor.Text.Trim();                                  //图标颜色
            bool isEdit     = this.cbk_isEdit.Checked;

            try
            {
                using (var conn = DataHelper.GetConnection())
                {
                    var func = new BA_FunctionAuth
                    {
                        Code        = Code,
                        Description = Descrition,
                        FuncIcon    = icon,
                        FuncName    = FuncName,
                        IconColor   = iconColor,
                        IconType    = iconType,
                        InIdCode    = MenuCode.CombineCode(Code),
                        MenuCode    = MenuCode
                    };
                    if (isEdit)
                    {
                        func.Id = Id;
                        conn.Update(func);
                    }
                    else
                    {
                        var info = conn.QueryFirstOrDefault <BA_FunctionAuth>("select * from BA_FunctionAuth where MenuCode=@MenuCode and Code=@Code", new { MenuCode, Code });
                        if (IsSuccess(info, "该功能编码已存在,请重新输入!"))
                        {
                            return;
                        }
                        conn.Insert(func);
                    }
                    MessageBox.Show("操作成功");
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }
        }
Пример #3
0
        private void btn_save_Click(object sender, EventArgs e)
        {
            string Code = txt_code.Text.Trim();//编码

            if (IsSuccess(Code, "编码标识不能为空!"))
            {
                return;
            }
            string CodeParent = txt_codeParent.Text.Trim(); //父级编码
            string Name       = txt_name.Text.Trim();       //名称

            if (IsSuccess(Name, "名称不能为空!"))
            {
                return;
            }
            string Description = txt_description.Text.Trim();//描述

            if (IsSuccess(Description, "描述不能为空!"))
            {
                return;
            }
            string url          = txt_url.Text;                                                    //跳转url
            bool?  IsSysDefined = ckb_isSysDefined.Checked;                                        //是否系统预置
            bool   IsVisibled   = ckb_isvisible.Checked;                                           //是否可见
            bool   IsEndGrade   = ckb_isEnd.Checked;                                               //是否末级
            bool   IsAuthority  = ckb_IsAuthority.Checked;                                         //是否权限控制
            short? Order        = (short)this.txt_order.Value;                                     //排序
            byte   MenuType     = (byte)this.cb_menuType.SelectedIndex;                            //菜单类型
            bool   isByte       = byte.TryParse(this.txt_icontype.Text.Trim(), out byte IconType); //图标类型
            string IconColor    = this.txt_iconColor.Text.Trim();                                  //图标颜色
            string icon         = this.txt_icon.Text.Trim();                                       //图标
            var    menu         = new BA_SysMenu
            {
                BaseMenuCode    = Code,
                BaseCodeParent  = CodeParent.IsNull(),
                BaseDescription = Description,
                BaseIcon        = icon,
                BaseIconColor   = IconColor,
                BaseIconType    = IconType,
                BaseMenuName    = Name,
                CreateTime      = DateTime.Now,
                IsAuthority     = IsAuthority,
                IsEndGrade      = IsEndGrade,
                IsSysDefine     = IsSysDefined,
                IsVisibled      = IsVisibled,
                MenuOrder       = Order,
                MenuType        = MenuType,
                Url             = url
            };

            try
            {
                using (var conn = DataHelper.GetConnection())
                {
                    conn.Open();
                    if (this.ckb_isEdit.Checked)
                    {
                        DataHelper.Update(menu, conn);
                        MessageBox.Show("修改成功");
                    }
                    else
                    {
                        var info = conn.QueryFirstOrDefault <BA_SysMenu>("select * from BA_SysMenu where Code=@Code", new { Code });
                        if (IsSuccess(info, "编码标识已存在!"))
                        {
                            return;
                        }
                        DataHelper.Insert(menu, conn);
                        //初始化菜单权限
                        var func = new BA_FunctionAuth()
                        {
                            Code     = "Read",
                            FuncName = "查看",
                            InIdCode = Code.CombineCode("Read"),
                            MenuCode = Code
                        };

                        DataHelper.Insert(func, conn);
                        MessageBox.Show("新增成功");
                    }
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }