Exemplo n.º 1
0
        private void GetMenuTreeTableHtml(StringBuilder sb, DataTable appDt, Guid parentID, List <Model.MenuUser> menuUsers, string orgId, Guid?userId = null)
        {
            //多语言从不同的字段读取标题
            string language = Tools.GetCurrentLanguage();
            string titleKey = language.Equals("en-US") ? "Title_en" : language.Equals("zh") ? "Title_zh" : "Title";

            DataRow[] drs = appDt.Select("ParentID='" + parentID.ToString() + "'");
            foreach (DataRow dr in drs)
            {
                if (userId != null && userId.HasValue && !userId.Value.IsEmptyGuid())
                {
                    if (!HasUse(dr["Id"].ToString().ToGuid(), userId.Value, menuUsers, out string source, out string params1))
                    {
                        continue;
                    }
                }

                var    mu          = menuUsers.Find(p => p.MenuId == dr["Id"].ToString().ToGuid() && p.Organizes.EqualsIgnoreCase(orgId));
                string menuchecked = mu != null ? " checked=\"checked\"" : "";

                sb.Append("<tr id=\"" + dr["Id"].ToString().ToUpper() + "\" data-pid=\"" + dr["ParentId"].ToString().ToUpper() + "\">");
                sb.Append("<td>" + dr[titleKey] + "</td>");
                if (!dr["Ico"].ToString().IsNullOrEmpty())
                {
                    sb.Append("<td><input type=\"hidden\" name=\"apptype\" value=\"0\"/>" + (dr["Ico"].ToString().IsFontIco() ? "<i class=\"fa " + dr["Ico"].ToString() + "\" style=\"font-size:14px;\"></i>" : "<img src=\"" + dr["Ico"] + "\" style=\"vertical-align:middle;\"/>") + "</td>");
                }
                else
                {
                    sb.Append("<td></td>");
                }
                sb.Append("<td style=\"text-align:center\"><input type=\"checkbox\" " + menuchecked + " onclick=\"appboxclick(this);\" name=\"menuid\" value=\"" + dr["Id"].ToString().ToUpper() + "\"/></td>");
                sb.Append("<td>");
                bool isAppLibrary = dr["AppLibraryId"].ToString().IsGuid();
                if (isAppLibrary)
                {
                    var buttons = new AppLibraryButton().GetListByApplibraryId(dr["AppLibraryId"].ToString().ToGuid());
                    foreach (var button in buttons.OrderBy(p => p.ShowType).ThenBy(p => p.Sort))
                    {
                        menuchecked = mu != null && mu.Buttons.ContainsIgnoreCase(button.Id.ToString())
                            ? " checked=\"checked\"" : "";
                        sb.Append("<input type=\"checkbox\" " + menuchecked + " onclick=\"buttonboxclick(this);\" style=\"vertical-align:middle;\" id=\"button_" + dr["Id"].ToString().ToUpper() + "_" + button.Id + "\" name=\"button_" + dr["Id"].ToString().ToUpper() + "\" value=\"" + button.Id.ToUpperString() + "\"/>");
                        sb.Append("<label style=\"vertical-align:middle;\" for=\"button_" + dr["Id"].ToString().ToUpper() + "_" + button.Id.ToUpperString() + "\">" + button.Name + "</label>");
                    }
                }
                sb.Append("</td>");
                if (isAppLibrary)
                {
                    sb.Append("<td><input type=\"text\" class=\"mytext\" style=\"width:95%\" value=\"" + (mu != null ? mu.Params : "") + "\" name=\"params_" + dr["Id"].ToString().ToUpper() + "\"/></td>");
                }
                else
                {
                    sb.Append("<td>&nbsp;</td>");
                }
                sb.Append("</tr>");

                GetMenuTreeTableHtml(sb, appDt, dr["Id"].ToString().ToGuid(), menuUsers, orgId, userId);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 发布一个程序设计
        /// </summary>
        /// <param name="id"></param>
        /// <param name="localizer">语言包</param>
        /// <returns></returns>
        public string Publish(Guid id, IStringLocalizer localizer = null)
        {
            string key = "ProgramRun_" + id.ToString("N");

            Cache.IO.Remove(key);
            Model.Program programModel = Get(id);
            if (null == programModel)
            {
                return(localizer == null ? "没有找到要发布的程序!" : localizer["NotFoundModel"]);
            }
            //更新状态
            programModel.Status = 1;
            Update(programModel);

            Model.ProgramRun programRunModel = GetRunModel(id);
            if (null == programRunModel)
            {
                return(localizer == null ? "没有找到要发布的程序!" : localizer["NotFoundModel"]);
            }

            #region 加入应用程序库
            AppLibrary appLibrary = new AppLibrary();
            var        appModel   = appLibrary.GetByCode(id.ToString());
            bool       isAdd      = false;
            if (null == appModel)
            {
                isAdd    = true;
                appModel = new Model.AppLibrary
                {
                    Id   = Guid.NewGuid(),
                    Code = id.ToString()
                };
            }
            appModel.Address  = "/RoadFlowCore/ProgramDesigner/Run?programid=" + id.ToString();
            appModel.OpenMode = 0;
            appModel.Title    = programRunModel.Name;
            appModel.Type     = programRunModel.Type;

            //多语言要写入不同语言的标题,这里只写一种
            appModel.Title_en = programRunModel.Name;
            appModel.Title_zh = programRunModel.Name;

            if (isAdd)
            {
                appLibrary.Add(appModel);
            }
            else
            {
                appLibrary.Update(appModel);
            }
            #endregion

            #region 加按钮到应用程序库
            AppLibraryButton appLibraryButton = new AppLibraryButton();
            var buttons        = appLibraryButton.GetListByApplibraryId(appModel.Id);
            var programButtons = new ProgramButton().GetAll(id);
            foreach (var button in programButtons)
            {
                var  model       = buttons.Find(p => p.Id == button.Id);
                bool isAddButton = false;
                if (null == model)
                {
                    isAddButton = true;
                    model       = new Model.AppLibraryButton
                    {
                        Id = button.Id
                    };
                }
                model.AppLibraryId   = appModel.Id;
                model.ButtonId       = button.ButtonId;
                model.Events         = button.ClientScript;
                model.Ico            = button.Ico;
                model.IsValidateShow = button.IsValidateShow;
                model.Name           = button.ButtonName;
                model.ShowType       = button.ShowType;
                model.Sort           = button.Sort;
                if (isAddButton)
                {
                    appLibraryButton.Add(model);
                }
                else
                {
                    appLibraryButton.Update(model);
                }
            }
            foreach (var button in buttons)
            {
                if (!programButtons.Exists(p => p.Id == button.Id))
                {
                    appLibraryButton.Delete(button.Id);
                }
            }
            #endregion
            return("1");
        }
Exemplo n.º 3
0
        /// <summary>
        /// 得到按钮HTML
        /// </summary>
        /// <param name="menuId">菜单Id</param>
        /// <param name="userId">当前用户Id</param>
        /// <returns><returns>List[0]工具栏按钮 List[1]常规按钮 List[2]列表按钮</returns></returns>
        public List <string> GetButtonHtml(string menuId, Guid userId)
        {
            StringBuilder button_toolbar = new StringBuilder();
            StringBuilder button_normal  = new StringBuilder();
            StringBuilder button_list    = new StringBuilder();

            if (!menuId.IsGuid(out Guid menuGuid))
            {
                return(new List <string>()
                {
                    "", "", ""
                });
            }
            var menuModel = Get(menuGuid);

            if (null == menuModel || !menuModel.AppLibraryId.HasValue)
            {
                return(new List <string>()
                {
                    "", "", ""
                });
            }
            List <Model.MenuUser> menuusers = new MenuUser().GetAll();

            if (!HasUse(menuGuid, userId, menuusers, out string source, out string params1))
            {
                return(new List <string>()
                {
                    "", "", ""
                });
            }
            var  buttons = new AppLibraryButton().GetListByApplibraryId(menuModel.AppLibraryId.Value).OrderBy(p => p.Sort);
            Menu menu    = new Menu();

            foreach (var button in buttons)
            {
                //检查权限
                if (true)
                {
                    if (!menu.HasUseButton(menuGuid, button.Id, userId, menuusers))
                    {
                        continue;
                    }
                }

                string funName = "fun_" + Guid.NewGuid().ToString("N");
                string butName = button.Name;
                string ico     = button.Ico;
                if (button.ShowType == 2)//工具栏按钮
                {
                    if (ico.IsFontIco())
                    {
                        button_toolbar.Append("<a href=\"javascript:void(0);\" onclick=\"" + funName + "();\">" +
                                              "<i class='fa " + ico + "'></i><label>" + butName + "</label></a>");
                    }
                    else
                    {
                        if (!ico.IsNullOrWhiteSpace())//图片图标
                        {
                            button_toolbar.Append("<a href=\"javascript:void(0);\" onclick=\"" + funName + "();\">" +
                                                  "<span style=\"background-image:url(" + ico + ");\">" + butName + "</span></a>");
                        }
                        else//没有设置图标
                        {
                            button_toolbar.Append("<a href=\"javascript:void(0);\" onclick=\"" + funName + "();\">" +
                                                  "<label>" + butName + "</label></a>");
                        }
                    }
                    button_toolbar.Append("<script type='text/javascript'>function " + funName + "(){" + Wildcard.Filter(button.Events) + "}</script>");
                }
                else if (button.ShowType == 0)//常规按钮
                {
                    button_normal.Append("<button type='button' class='mybutton' style='margin-right:8px;'");
                    button_normal.Append(" onclick=\"" + funName + "();\"");
                    button_normal.Append(">");
                    if (!ico.IsNullOrWhiteSpace())
                    {
                        if (ico.IsFontIco())//如果是字体图标
                        {
                            button_normal.Append("<i class='fa " + ico + "' style='margin-right:3px;'></i>" + butName);
                        }
                        else
                        {
                            button_normal.Append("<img src=\"" + ico + "\" style='margin-right:3px;vertical-align:middle;'/>" + butName);
                        }
                    }
                    else
                    {
                        button_normal.Append(butName);
                    }
                    button_normal.Append("</button>");
                    button_normal.Append("<script type='text/javascript'>function " + funName + "(){" + Wildcard.Filter(button.Events) + "}</script>");
                }
                else if (button.ShowType == 1)//列表按钮 不替换通配符,列表按钮涉及运行时数据,在运行时替换。
                {
                    if (ico.IsFontIco())
                    {
                        button_list.Append("<a class=\"list\" href=\"javascript:void(0);\" onclick=\"" + button.Events + "\">" +
                                           "<i class='fa " + ico + "'></i>" + butName + "</a>");
                    }
                    else
                    {
                        if (!ico.IsNullOrWhiteSpace())//图片图标
                        {
                            button_list.Append("<a class=\"list\" href=\"javascript:void(0);\" onclick=\"" + button.Events + "\">" +
                                               "<span style=\"background-image:url(" + ico + ");\">" + butName + "</span></a>");
                        }
                        else//没有设置图标
                        {
                            button_list.Append("<a href=\"javascript:void(0);\" onclick=\"" + button.Events + "\">" +
                                               "<label>" + butName + "</label></a>");
                        }
                    }
                }
            }
            return(new List <string>()
            {
                button_toolbar.ToString(), button_normal.ToString(), button_list.ToString()
            });
        }