Beispiel #1
0
        public Guid?ContactsCache(string email)
        {
            if (String.IsNullOrEmpty(email))
            {
                return(null);
            }

            lock (_locker)
            {
                if (_ContactsCache == null)
                {
                    _ContactsCache = new Dictionary <string, Guid>();
                }

                Guid result;
                if (_ContactsCache.TryGetValue(email, out result))
                {
                    return(result);
                }

                using (PXDataRecord record = PXDatabase.SelectSingle <Contact>(new PXDataField <Contact.noteID>(),
                                                                               new PXDataFieldValue <Contact.eMail>(email),
                                                                               new PXDataFieldValue <Contact.contactType>(ContactTypesAttribute.Person)))
                {
                    if (record != null && record.GetGuid(0) != null)
                    {
                        _ContactsCache[email] = record.GetGuid(0).Value;
                        return(record.GetGuid(0));
                    }
                }
            }
            return(null);
        }
Beispiel #2
0
        protected virtual void ValidateINUnit(InventoryItem item)
        {
            if (item == null)
            {
                return;
            }

            using (PXDataRecord record = PXDatabase.SelectSingle <INUnit>(new PXDataField <INUnit.toUnit>(),
                                                                          new PXDataFieldValue <INUnit.unitType>(INUnitType.InventoryItem),
                                                                          new PXDataFieldValue <INUnit.inventoryID>(item.InventoryID),
                                                                          new PXDataFieldValue <INUnit.toUnit>(PXDbType.NVarChar, 6, item.BaseUnit, PXComp.NE)))
            {
                if (record != null)
                {
                    throw new PXException(Messages.WrongInventoryItemToUnitValue, record.GetString(0), item.InventoryCD, item.BaseUnit);
                }
            }

            IEnumerable <PXDataRecord> baseConversions = PXDatabase.SelectMulti <INUnit>(new PXDataField <INUnit.toUnit>(),
                                                                                         new PXDataFieldValue <INUnit.unitType>(INUnitType.InventoryItem),
                                                                                         new PXDataFieldValue <INUnit.inventoryID>(item.InventoryID),
                                                                                         new PXDataFieldValue <INUnit.fromUnit>(PXDbType.NVarChar, item.BaseUnit),
                                                                                         new PXDataFieldValue <INUnit.toUnit>(PXDbType.NVarChar, item.BaseUnit));

            if (baseConversions.Count() != 1)
            {
                throw new PXException(Messages.BaseConversionNotFound, item.BaseUnit, item.BaseUnit, item.InventoryCD);
            }
        }
    /// <summary>
    /// The tlbPath callback event handler.
    /// </summary>
    protected void tlbPath_CallBack(object sender, PXCallBackEventArgs e)
    {
        if (e.Command.Name == "AddFav" && PXSiteMap.CurrentNode != null)
        {
            Guid nodeID = PXSiteMap.CurrentNode.NodeID;
            if (!IsInFavorites(nodeID))
            {
                AddFavorite(screenTitle, nodeID);
            }
            else
            {
                PXDatabase.Delete <Favorite>(
                    new PXDataFieldRestrict("UserID", PXAccess.GetUserID()),
                    new PXDataFieldRestrict("SiteMapID", nodeID)
                    );
            }
            PXContext.Session.FavoritesExists["FavoritesExists"] = null;
            PXSiteMap.FavoritesProvider.Clear();

            // check if favorites exists
            using (PXDataRecord exist = PXDatabase.SelectSingle <Favorite>(
                       new PXDataField("UserID"), new PXDataFieldValue("UserID", PXAccess.GetUserID())))
            {
                e.Result = (exist == null) ? "0" : "1";
            }
        }
    }
    /// <summary>
    /// The tlbPath callback event handler.
    /// </summary>
    protected void tlbPath_CallBack(object sender, PXCallBackEventArgs e)
    {
        if (e.Command.Name == "AddFav" && PXSiteMap.CurrentNode != null)
        {
            var currentNode   = PXSiteMap.CurrentNode;
            var entryScreenId = GetEntryNodeId(currentNode.ScreenID);

            if (!IsInFavoritesLegacy(entryScreenId))
            {
                screenRepository.SetFavoriteForScreen(entryScreenId, true);
            }
            else
            {
                screenRepository.SetFavoriteForScreen(entryScreenId, false);
            }
            PXContext.Session.FavoritesExists["FavoritesExists"] = null;
            PXSiteMap.FavoritesProvider.Clear();

            // check if favorites exists
            using (PXDataRecord exist = PXDatabase.SelectSingle <Favorite>(
                       new PXDataField("UserID"), new PXDataFieldValue("UserID", PXAccess.GetUserID())))
            {
                e.Result = (exist == null) ? "0" : "1";
            }
        }
    }
Beispiel #5
0
    protected void Page_Init(object sender, EventArgs e)
    {
        this.usrCaption.CustomizationAvailable = false;
        this.ds.ReportCode = this.Request.QueryString["ID"];
        if (!String.IsNullOrEmpty(this.ds.ReportCode) && this.ds.ReportCode.Contains(".rpx"))
        {
            this.ds.ReportCode = this.ds.ReportCode.Replace(".rpx", "");
        }
        string screenID = null;
        object date     = PX.Common.PXContext.GetBusinessDate();

        PX.Common.PXContext.SetBusinessDate((DateTime?)date);
        if (PXSiteMap.CurrentNode != null)
        {
            this.Title = PXSiteMap.CurrentNode.Title;
            screenID   = PXSiteMap.CurrentNode.ScreenID;
        }
        else
        {
            string        url  = (Request.ApplicationPath != "/" ? Request.Path.Replace(Request.ApplicationPath, "~") : "~" + Request.Path) + "?id=" + this.ds.ReportCode + ".rpx";
            PXSiteMapNode node = SiteMap.Provider.FindSiteMapNode(url) as PXSiteMapNode;
            if (node != null)
            {
                this.Title = node.Title;
                this.usrCaption.ScreenTitle = node.Title;
                this.usrCaption.ScreenID    = PX.Common.Mask.Format("CC.CC.CC.CC", node.ScreenID);
                screenID = node.ScreenID;
            }
            else
            {
                using (PXDataRecord record = PXDatabase.SelectSingle <PX.SM.SiteMap>(
                           new PXDataField("ScreenID"),
                           new PXDataFieldValue("Url", PXDbType.VarChar, 512, url)
                           ))
                {
                    if (record != null)
                    {
                        screenID = record.GetString(0);
                        if (!String.IsNullOrEmpty(screenID) && !PXAccess.VerifyRights(screenID))
                        {
                            throw new PXSetPropertyException(ErrorMessages.NotEnoughRights, this.ds.ReportCode);
                        }
                    }
                }
            }
        }
        if (String.IsNullOrEmpty(PX.Common.PXContext.GetScreenID()) && !String.IsNullOrEmpty(screenID))
        {
            PX.Common.PXContext.SetScreenID(PX.Common.Mask.Format(">CC.CC.CC.CC", screenID));
        }
        if (_canSendEmail)
        {
            viewer.EmailSend += new PXReportViewer.EmailSendHandler(viewer_EmailSend);
        }
        else
        {
            viewer.AllowSendEmails = false;
        }
    }
 /// <summary>
 /// Check if current node in Favorites.
 /// </summary>
 private bool IsInFavoritesLegacy(Guid nodeId)
 {
     using (PXDataRecord exist = PXDatabase.SelectSingle <Favorite>(
                new PXDataField("SiteMapID"), new PXDataFieldValue("SiteMapID", nodeId),
                new PXDataFieldValue("UserID", PXAccess.GetUserID())))
     {
         return(exist != null);
     }
 }
Beispiel #7
0
 /// <summary>
 /// Check if current node in Favorites.
 /// </summary>
 private bool IsInFavorites(Guid nodeId)
 {
     using (PXDataRecord exist = PXDatabase.SelectSingle <MUIFavoriteScreen>(
                new PXDataField("NodeID"), new PXDataFieldValue("NodeID", nodeId),
                new PXDataFieldValue("IsPortal", PXSiteMap.IsPortal),
                new PXDataFieldValue("Username", PXAccess.GetUserLogin())))
     {
         return(exist != null);
     }
 }
 public void Prefetch()
 {
     using (PXDataRecord rec = PXDatabase.SelectSingle <PreferencesSecurity>(new PXDataField <PreferencesSecurityExt.usrApplyWorkgroupRestrictions>()))
     {
         if (rec != null)
         {
             Enabled = rec.GetBoolean(0) ?? false;
         }
     }
 }
Beispiel #9
0
        private static bool HasPaymentMethod(int?pMInstanceID)
        {
            if (pMInstanceID == null)
            {
                return(false);
            }

            return(PXDatabase.SelectSingle <CustomerPaymentMethod>(
                       new PXDataField <CustomerPaymentMethod.cCProcessingCenterID>(),
                       new PXDataFieldRestrict <CustomerPaymentMethod.pMInstanceID>(pMInstanceID)) != null);
        }
    /// <summary>
    /// Check if current node in Favorites.
    /// </summary>
    private bool IsInFavorites(Guid?siteId)
    {
        Guid nodeID = siteId.HasValue ? siteId.Value : PXSiteMap.CurrentNode.NodeID;

        using (PXDataRecord exist = PXDatabase.SelectSingle <Favorite>(
                   new PXDataField("SiteMapID"), new PXDataFieldValue("SiteMapID", nodeID),
                   new PXDataFieldValue("UserID", PXAccess.GetUserID())))
        {
            return(exist != null);
        }
    }
Beispiel #11
0
 public void Prefetch()
 {
     using (PXDataRecord arSetup = PXDatabase.SelectSingle <ARSetup>(
                new PXDataField <ARSetup.migrationMode>()))
     {
         if (arSetup != null)
         {
             isMigrationModeEnabled = (bool)arSetup.GetBoolean(0);
         }
     }
 }
Beispiel #12
0
 public void Prefetch()
 {
     using (PXConnectionScope s = new PXConnectionScope())
     {
         using (PXDataRecord record = PXDatabase.SelectSingle<Contract>(
             new PXDataField<Contract.contractID>(),
             new PXDataFieldValue<Contract.nonProject>(1)))
         {
             ID = record.GetInt32(0) ?? 0;
         }
     }
 }
Beispiel #13
0
 protected int?getDefaultSiteID()
 {
     using (PXDataRecord record = PXDatabase.SelectSingle <INSite>(
                new PXDataField <INSite.siteID>(),
                new PXDataFieldOrder <INSite.siteID>()))
     {
         if (record != null)
         {
             return(record.GetInt32(0));
         }
     }
     return(null);
 }
        public static void OnPublished(USCustomizationPlugin plugin, ref List <Tuple <string, object[]> > errors)
        {
            string companyName = PXAccess.GetCompanyName();

            plugin.WriteLog(PXLocalizer.LocalizeFormatWithKey(USMessages.SomePluginRunning, typeof(USMessages).FullName, companyName));

            //Select an Account that is Active
            PXDataRecord record = PXDatabase.SelectSingle <Account>(new PXDataFieldValue <Account.active>(PXDbType.Bit, true));

            if (record == null)
            {
                errors.Add(new Tuple <string, object[]>(USMessages.NoActiveAccounts, new object[] { companyName }));
            }
        }
Beispiel #15
0
 public void Prefetch()
 {
     using (new PXConnectionScope())
     {
         using (PXDataRecord prefGeneral = PXDatabase.SelectSingle <EPSetup>(
                    new PXDataField(typeof(EPSetup.firstDayOfWeek).Name)))
         {
             if (prefGeneral != null)
             {
                 var firstDayValue = prefGeneral.GetInt32(0);
                 _firstDayOfWeek = firstDayValue == null ? DayOfWeek.Sunday : (DayOfWeek)firstDayValue;
             }
         }
     }
 }
Beispiel #16
0
        protected virtual void ARInvoice_RowSelecting(PXCache sender, PXRowSelectingEventArgs e)
        {
            ARInvoice row = (ARInvoice)e.Row;

            if (row != null && !String.IsNullOrEmpty(row.DocType) &&
                !String.IsNullOrEmpty(row.RefNbr))
            {
                row.IsCCPayment = false;
                if (PXDatabase.SelectSingle <CustomerPaymentMethod>(
                        new PXDataField <CustomerPaymentMethod.cCProcessingCenterID>(),
                        new PXDataFieldRestrict <CustomerPaymentMethod.pMInstanceID>(row.pMInstanceID)) != null)
                {
                    row.IsCCPayment = true;
                }
            }
        }
Beispiel #17
0
            private TimeZoneInfo.AdjustmentRule Initialize(DefinitionParameters parameter)
            {
                DaylightShift row  = null;
                var           id   = parameter.Id;
                var           year = parameter.Year;

                using (new PXConnectionScope())
                    using (PXDataRecord rec = PXDatabase.SelectSingle <DaylightShift>
                                              (
                               new PXDataField(typeof(DaylightShift.fromDate).Name),
                               new PXDataField(typeof(DaylightShift.toDate).Name),
                               new PXDataField(typeof(DaylightShift.shift).Name),
                               new PXDataFieldValue(typeof(DaylightShift.isActive).Name, PXDbType.Bit, 1),
                               new PXDataFieldValue(typeof(DaylightShift.year).Name, PXDbType.Int, year),
                               new PXDataFieldValue(typeof(DaylightShift.timeZone).Name, PXDbType.VarChar, id)
                                              ))
                    {
                        if (rec != null)
                        {
                            row          = new DaylightShift();
                            row.IsActive = true;
                            row.Year     = year;
                            row.TimeZone = id;
                            row.FromDate = rec.GetDateTime(0);
                            row.ToDate   = rec.GetDateTime(1);
                            row.Shift    = rec.GetInt32(2);
                        }
                    }

                if (row == null || string.IsNullOrEmpty(row.TimeZone))
                {
                    return(_systemProvider.FindTimeRegionByTimeZone(id).With(_ => _.GetAdjustmentRule(year)));
                }

                var start     = new DateTime(year, 1, 1);
                var end       = new DateTime(year, 12, 31);
                var delta     = TimeSpan.FromMinutes(row.Shift ?? 0);
                var tranStart = GetTransitionTime((DateTime)row.FromDate);
                var tranEnd   = GetTransitionTime((DateTime)row.ToDate);

                return(TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule(start, end, delta, tranStart, tranEnd));
            }
Beispiel #18
0
            public void Prefetch(PXDatabaseUSProvider provider)
            {
                PXDataRecord record = PXDatabase.SelectSingle <USSetup>(new PXDataField <USSetup.enableInAP>(), new PXDataField <USSetup.simpleNumberingID>());

                if (record == null)
                {
                    _featureActive = false;
                }
                else
                {
                    if (record.GetBoolean(0) ?? false)
                    {
                        _featureActive = true;
                    }
                    else
                    {
                        _featureActive = false;
                    }
                }
            }
    /// <summary>
    /// The tlbPath callback event handler.
    /// </summary>
    protected void tlbPath_CallBack(object sender, PXCallBackEventArgs e)
    {
        if (e.Command.Name == "AddFav" && PXSiteMap.CurrentNode != null)
        {
            Guid nodeID = PXSiteMap.CurrentNode.NodeID;
            if (!IsInFavorites(nodeID))
            {
                AddFavorite(screenTitle, nodeID);
            }
            else
            {
                PXDatabase.Delete <Favorite>(
                    new PXDataFieldRestrict("UserID", PXAccess.GetUserID()),
                    new PXDataFieldRestrict("SiteMapID", nodeID)
                    );
            }
            PXContext.Session.FavoritesExists["FavoritesExists"] = null;
            PXSiteMap.FavoritesProvider.Clear();

            // check if favorites exists
            using (PXDataRecord exist = PXDatabase.SelectSingle <Favorite>(
                       new PXDataField("UserID"), new PXDataFieldValue("UserID", PXAccess.GetUserID())))
            {
                e.Result = (exist == null) ? "0" : "1";
            }
        }
        else if (e.Command.Name == "ClearFilter")
        {
            var ds = PXPage.GetDefaultDataSource(this.Page);
            if (ds != null)
            {
                var action = ds.DataGraph.Actions[clearFilterCommand];
                if (action != null)
                {
                    action.Press();
                }
            }
            PXCallbackManager.RegisterJavaScript(
                "if (window['__px_alls'] && __px_alls(this) && __px_alls(this)['tlbPath'])__px_alls(this)['tlbPath'].items['clearFilter'].setVisible(false);");
        }
    }
Beispiel #20
0
        public static bool IsEntityInUse <Table>(params object[] keys)
            where Table : IBqlTable
        {
            if (Attribute.IsDefined(typeof(Table), typeof(EntityInUseDBSlotOnAttribute)))
            {
                var slot = PXDatabase.GetSlot <EntityInUseDefinition <Table> >(typeof(EntityInUseDefinition <Table>).FullName, typeof(Table));
                return(keys.Length != 0
                                        ? slot.EntitiesInUse.Contains(GetHash <Table>(keys))
                                        : slot.EntitiesInUse.Any());
            }
            else
            {
                KeysCollection cacheKeys = GetCacheKeys <Table>();

                if (keys.Length != 0 && cacheKeys.Count() != keys.Length)
                {
                    throw new PXArgumentException(nameof(keys));
                }

                var fields = new PXDataField[cacheKeys.Count * (keys.Length != 0 ? 2 : 1)];

                for (int i = 0; i < cacheKeys.Count; i++)
                {
                    string cacheKey = cacheKeys[i];
                    fields[i] = new PXDataField(cacheKey);

                    if (keys.Length != 0)
                    {
                        fields[cacheKeys.Count + i] = new PXDataFieldValue(cacheKey, keys[i]);
                    }
                }

                using (PXDataRecord record = PXDatabase.SelectSingle <Table>(fields))
                {
                    return(record != null);
                }
            }
        }
    /// <summary>
    /// Append node with specified tutle to favorites.
    /// </summary>
    private void AddFavorite(string title, Guid?siteId)
    {
        if (String.IsNullOrEmpty(title) && siteId == null)
        {
            return;
        }

        Guid   folderID = PXSiteMap.RootNode.NodeID;
        string neutralTitle;

        using (PXDataRecord record = PXDatabase.SelectSingle <PX.SM.SiteMap>(new PXDataField("Title"),
                                                                             new PXDataFieldValue("NodeID", siteId)))
        {
            neutralTitle = record.GetString(0);
        }

        if (!string.IsNullOrEmpty(neutralTitle))
        {
            using (PXDataRecord rec_id = PXDatabase.SelectSingle <Favorite>(
                       new PXDataField("Max(Position)+1"),
                       new PXDataFieldValue("UserID", PXAccess.GetUserID())))
            {
                int pos = 1;
                if (rec_id != null)
                {
                    pos = rec_id.GetInt32(0) ?? 1;
                }
                PXDatabase.Insert <Favorite>(
                    new PXDataFieldAssign("UserID", PXAccess.GetUserID()),
                    new PXDataFieldAssign("NodeID", Guid.NewGuid()),
                    new PXDataFieldAssign("Title", neutralTitle),
                    new PXDataFieldAssign("ParentID", folderID),
                    new PXDataFieldAssign("Position", pos),
                    new PXDataFieldAssign("SiteMapID", siteId));
            }
        }
    }
    protected void Page_Init(object sender, EventArgs e)
    {
        // remove unum parameter
        PropertyInfo isreadonly = typeof(System.Collections.Specialized.NameValueCollection).GetProperty("IsReadOnly", BindingFlags.Instance | BindingFlags.NonPublic);

        // make collection editable
        isreadonly.SetValue(this.Request.QueryString, false, null);
        this.Request.QueryString.Remove(PXUrl.UNum);
        isreadonly.SetValue(this.Request.QueryString, true, null);

        this.usrCaption.CustomizationAvailable = false;

        var date = PXContext.GetBusinessDate();

        PX.Common.PXContext.SetBusinessDate((DateTime?)date);

        if ((this.viewer.SchemaUrl = this.Request.QueryString["ID"]) == null)
        {
            this.viewer.SchemaUrl = ReportID;
        }

        if (SiteMap.CurrentNode != null)
        {
            this.Title = PXSiteMap.CurrentNode.Title;
            _screenID  = PXSiteMap.CurrentNode.ScreenID;
        }
        else
        {
            string url;
            if (Request.ApplicationPath != "/")
            {
                url = Request.Path.Replace(Request.ApplicationPath, "~") + "?ID=" + this.viewer.SchemaUrl;
            }
            else if (Request.Path.StartsWith("/"))
            {
                url = "~" + Request.Path;
            }
            else
            {
                url = Request.Path;
            }
            PXSiteMapNode node = SiteMap.Provider.FindSiteMapNode(url) as PXSiteMapNode;
            if (node != null)
            {
                this.Title = node.Title;
                this.usrCaption.ScreenTitle = node.Title;
                this.usrCaption.ScreenID    = PX.Common.Mask.Format(">CC.CC.CC.CC", node.ScreenID);
                _screenID = node.ScreenID;
            }
            else
            {
                using (PXDataRecord record = PXDatabase.SelectSingle <PX.SM.SiteMap>(
                           new PXDataField("ScreenID"),
                           new PXDataFieldValue("Url", PXDbType.VarChar, 512, url)
                           ))
                {
                    if (record != null)
                    {
                        _screenID = record.GetString(0);
                        if (!String.IsNullOrEmpty(_screenID) && !PXAccess.VerifyRights(_screenID))
                        {
                            throw new PXSetPropertyException(ErrorMessages.NotEnoughRights, this.viewer.SchemaUrl);
                        }
                    }
                }
            }
        }
        if (String.IsNullOrEmpty(PX.Common.PXContext.GetScreenID()))
        {
            if (String.IsNullOrEmpty(_screenID) && !String.IsNullOrEmpty(this.viewer.SchemaUrl))
            {
                string schema = this.viewer.SchemaUrl;
                if (schema.EndsWith(".rpx", StringComparison.OrdinalIgnoreCase))
                {
                    schema = schema.Substring(0, schema.Length - 4);
                }
                if (schema.Length == 8)
                {
                    _screenID = schema;
                }
            }
            if (!String.IsNullOrEmpty(_screenID))
            {
                PX.Common.PXContext.SetScreenID(PX.Common.Mask.Format(">CC.CC.CC.CC", _screenID));
            }
        }
        if (_canSendEmail)
        {
            viewer.EmailSend += new PXReportViewer.EmailSendHandler(viewer_EmailSend);
        }
        else
        {
            viewer.AllowSendEmails = false;
        }
    }