Exemplo n.º 1
0
        private static PxMenuBase GetPxMenuAndItem(string dbid, string nodeId, string lang, out PCAxis.Menu.Item currentItem)
        {
            //Get menu-file
            DatabaseInfo currentdb = PXWeb.Settings.Current.General.Databases.GetPxDatabase(dbid);

            if (currentdb != null)
            {
                StringBuilder sb = new StringBuilder(PXWeb.Settings.Current.General.Paths.PxDatabasesPath);
                sb.Append("/");
                sb.Append(currentdb.Id);
                sb.Append("/");
                sb.Append(PXWeb.Settings.Current.General.Databases.PxDatabaseFilename);
                //string _xmlFile = HttpContext.Current.Server.MapPath(sb.ToString());
                string  _xmlFile = System.Web.Hosting.HostingEnvironment.MapPath(sb.ToString());
                XmlMenu menu     = new XmlMenu(XDocument.Load(_xmlFile), lang,
                                               m =>
                {
                    m.Restriction = item =>
                    {
                        return(true);
                    };
                });

                ItemSelection cid = PathHandlerFactory.Create(PCAxis.Web.Core.Enums.DatabaseType.PX).GetSelection(nodeId);
                menu.SetCurrentItemBySelection(cid.Menu, cid.Selection);
                currentItem = menu.CurrentItem;
                return(menu);
            }
            currentItem = null;
            return(null);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Get Menu + current item
        /// </summary>
        /// <param name="dbid">Database id</param>
        /// <param name="node">Database node</param>
        /// <param name="lang">Language</param>
        /// <param name="currentItem">Current item (out parameter)</param>
        /// <returns></returns>
        public static PxMenuBase GetMenuAndItem(string dbid, ItemSelection node, string lang, out PCAxis.Menu.Item currentItem)
        {
            DatabaseInfo dbi = PXWeb.Settings.Current.General.Databases.GetDatabase(dbid);

            PCAxis.Menu.Item menuItem = null;
            PxMenuBase       menu     = null;

            try
            {
                if (dbi != null)
                {
                    string nodeId = PathHandlerFactory.Create(dbi.Type).GetPathString(node);

                    if (dbi.Type == PCAxis.Web.Core.Enums.DatabaseType.PX)
                    {
                        menu = GetPxMenuAndItem(dbid, nodeId, lang, out menuItem);
                    }
                    else if (dbi.Type == PCAxis.Web.Core.Enums.DatabaseType.CNMM)
                    {
                        menu = GetCnmmMenuAndItem(dbid, nodeId, lang, out menuItem);
                    }
                }
                currentItem = menuItem;
                return(menu);
            }
            catch (Exception)
            {
                currentItem = null;
                return(null);
            }
        }
Exemplo n.º 3
0
        private static PxMenuBase GetCnmmMenuAndItem(string dbid, string nodeId, string lang, out PCAxis.Menu.Item currentItem)
        {
            //Get selected language in PX-Web
            //string pxLang = PCAxis.Web.Core.Management.LocalizationManager.GetTwoLetterLanguageCode();
            //string dbLang = PxContext.GetCnmmDbLanguage(dbid, pxLang);
            string    dbLang = PxContext.GetCnmmDbLanguage(dbid, lang);
            TableLink tblFix = null;

            //Create database object to return
            DatamodelMenu menu = ConfigDatamodelMenu.Create(
                dbLang,
                PCAxis.Sql.DbConfig.SqlDbConfigsStatic.DataBases[dbid],
                m =>
            {
                m.RootSelection          = string.IsNullOrEmpty(nodeId) ? new ItemSelection() : PathHandlerFactory.Create(PCAxis.Web.Core.Enums.DatabaseType.CNMM).GetSelection(nodeId);
                m.AlterItemBeforeStorage = item =>
                {
                    if (item is PCAxis.Menu.Url)
                    {
                        PCAxis.Menu.Url url = (PCAxis.Menu.Url)item;
                    }

                    if (item is TableLink)
                    {
                        TableLink tbl = (TableLink)item;
                        string tblId  = tbl.ID.Selection;
                        if (!string.IsNullOrEmpty(dbid))
                        {
                            tbl.ID = new ItemSelection(item.ID.Menu, dbid + ":" + tbl.ID.Selection);             // Hantering av flera databaser!
                        }

                        CustomizeTableTitle(tbl, false);

                        if (tbl.Published.HasValue)
                        {
                            // Store date in the PC-Axis date format
                            tbl.SetAttribute("modified", tbl.Published.Value.ToString(PCAxis.Paxiom.PXConstant.PXDATEFORMAT));
                        }
                        if (string.Compare(tblId + item.ID.Menu, PathHandlerFactory.Create(PCAxis.Web.Core.Enums.DatabaseType.CNMM).GetSelection(nodeId).Selection + PathHandlerFactory.Create(PCAxis.Web.Core.Enums.DatabaseType.CNMM).GetSelection(nodeId).Menu, true) == 0)
                        {
                            tblFix = tbl;
                        }
                    }

                    if (String.IsNullOrEmpty(item.SortCode))
                    {
                        item.SortCode = item.Text;
                    }
                };
                m.Restriction = item =>
                {
                    return(true);
                };
            });

            if (tblFix != null)
            {
                currentItem = tblFix;
            }
            else
            {
                currentItem = menu.CurrentItem;
            }

            menu.RootItem.Sort();

            return(menu);
        }