public override void ProcessRequest(SubscribeRequest requestData)
 {
     if (requestData == null)
     {
         //Unsubscribe this user from *all* push notification
         PXDatabase.Delete <VXUserPushNotification>(
             new PXDataFieldRestrict <VXUserPushNotification.userID>(PXAccess.GetUserID())
             );
     }
     else
     {
         //Register endpoint. The page will always refresh its subscription on load.
         try
         {
             PXDatabase.Insert <VXUserPushNotification>(
                 new PXDataFieldAssign <VXUserPushNotification.userID>(PXAccess.GetUserID()),
                 new PXDataFieldAssign <VXUserPushNotification.endpoint>(requestData.Endpoint),
                 new PXDataFieldAssign <VXUserPushNotification.authKey>(requestData.Keys["auth"]),
                 new PXDataFieldAssign <VXUserPushNotification.receiverKey>(requestData.Keys["p256dh"]));
         }
         catch (PXDatabaseException e)
         {
             if (e.ErrorCode == PXDbExceptions.PrimaryKeyConstraintViolation)
             {
                 PXDatabase.Update <VXUserPushNotification>(
                     new PXDataFieldAssign <VXUserPushNotification.authKey>(requestData.Keys["auth"]),
                     new PXDataFieldAssign <VXUserPushNotification.receiverKey>(requestData.Keys["p256dh"]),
                     new PXDataFieldRestrict <VXUserPushNotification.userID>(PXAccess.GetUserID()),
                     new PXDataFieldRestrict <VXUserPushNotification.endpoint>(requestData.Endpoint));
             }
         }
     }
 }
Esempio n. 2
0
        public static void MarkEntityAsInUse <Table>(params object[] keys)
            where Table : IBqlTable
        {
            if (IsEntityInUse <Table>(keys))
            {
                return;
            }

            KeysCollection cacheKeys = GetCacheKeys <Table>();

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

            var fields = new PXDataFieldAssign[cacheKeys.Count];

            for (int i = 0; i < cacheKeys.Count; i++)
            {
                fields[i] = new PXDataFieldAssign(cacheKeys[i], keys[i]);
            }

            try
            {
                PXDatabase.Insert <Table>(fields);
            }
            catch (PXDatabaseException ex) when(ex.ErrorCode == PXDbExceptions.PrimaryKeyConstraintViolation)
            {
            }
        }
        private void StoreChildsValues(PXGraph processingGraph, Type childTable, IEnumerable <PXPersonalDataFieldAttribute> fields, IEnumerable <object> childs, Guid?topParentNoteID)
        {
            foreach (object child in childs)
            {
                var childNoteID = processingGraph.Caches[childTable].GetValue(child, nameof(INotable.NoteID)) as Guid?;

                // TODO: merge into single INSERT
                foreach (PXPersonalDataFieldAttribute field in fields)
                {
                    var value = processingGraph.Caches[childTable].GetValue(child, field.FieldName);
                    if (value == null)
                    {
                        continue;
                    }

                    if (field.DefaultValue != null && (!value.GetType().IsAssignableFrom(field.DefaultValue.GetType()) || value.Equals(field.DefaultValue)))
                    {
                        continue;
                    }

                    List <PXDataFieldAssign> assigns = new List <PXDataFieldAssign>();

                    assigns.Add(new PXDataFieldAssign <SMPersonalData.table>(childTable.FullName));
                    assigns.Add(new PXDataFieldAssign <SMPersonalData.field>(field.FieldName));
                    assigns.Add(new PXDataFieldAssign <SMPersonalData.entityID>(childNoteID));
                    assigns.Add(new PXDataFieldAssign <SMPersonalData.topParentNoteID>(topParentNoteID));
                    assigns.Add(new PXDataFieldAssign <SMPersonalData.value>(value));
                    assigns.Add(new PXDataFieldAssign <SMPersonalData.createdDateTime>(PXTimeZoneInfo.UtcNow));

                    PXDatabase.Insert <SMPersonalData>(assigns.ToArray());
                }

                DeleteSearchIndex(childNoteID);
            }
        }
 public virtual void RowPersisted(PXCache sender, PXRowPersistedEventArgs e)
 {
     if (e.TranStatus == PXTranStatus.Open)
     {
         List <PXDataFieldAssign> field = new List <PXDataFieldAssign>();
         PXDatabase.Insert <ARInvoiceNbr>(fields.ToArray());
     }
 }
Esempio n. 5
0
 public static bool Insert(SearchIndex record)
 {
     return(PXDatabase.Insert(typeof(SearchIndex),
                              new PXDataFieldAssign(typeof(SearchIndex.noteID).Name, PXDbType.UniqueIdentifier, record.NoteID),
                              new PXDataFieldAssign(typeof(SearchIndex.indexID).Name, PXDbType.UniqueIdentifier, record.IndexID),
                              new PXDataFieldAssign(typeof(SearchIndex.category).Name, PXDbType.Int, record.Category),
                              new PXDataFieldAssign(typeof(SearchIndex.entityType).Name, PXDbType.NVarChar, record.EntityType),
                              new PXDataFieldAssign(typeof(SearchIndex.content).Name, PXDbType.NText, record.Content)));
 }
 protected bool StoreRestorableSearchIndex(string combinedKey, string info)
 {
     return(PXDatabase.Insert <SMPersonalDataIndex>(
                new PXDataFieldAssign <SMPersonalDataIndex.combinedKey>(combinedKey),
                new PXDataFieldAssign <SMPersonalDataIndex.indexID>(Guid.NewGuid()),
                new PXDataFieldAssign <SMPersonalDataIndex.content>(info.ToString()),
                new PXDataFieldAssign <SMPersonalDataIndex.createdDateTime>(PXTimeZoneInfo.UtcNow)
                ));
 }
 protected void LogOperation(Type tableName, string combinedKey)
 {
     PXDatabase.Insert <SMPersonalDataLog>(
         new PXDataFieldAssign <SMPersonalDataLog.tableName>(tableName.FullName),
         new PXDataFieldAssign <SMPersonalDataLog.combinedKey>(combinedKey),
         new PXDataFieldAssign <SMPersonalDataLog.pseudonymizationStatus>(SetPseudonymizationStatus),
         new PXDataFieldAssign <SMPersonalDataLog.createdByID>(PXAccess.GetTrueUserID()),
         new PXDataFieldAssign <SMPersonalDataLog.createdDateTime>(PXTimeZoneInfo.UtcNow)
         );
 }
Esempio n. 8
0
        /// <summary>
        /// If the table data is empty, the database record is inserted according to each user.
        /// </summary>
        /// <param name="graph"></param>
        protected static void InsertWrkTableRecs(PXGraph graph)
        {
            string screenIDWODot = graph.Accessinfo.ScreenID.ToString().Replace(".", "");

            PXDatabase.Insert <LUMStdBomCost>(new PXDataFieldAssign <LUMStdBomCost.createdByID>(graph.Accessinfo.UserID),
                                              new PXDataFieldAssign <LUMStdBomCost.createdByScreenID>(screenIDWODot),
                                              new PXDataFieldAssign <LUMStdBomCost.createdDateTime>(graph.Accessinfo.BusinessDate),
                                              new PXDataFieldAssign <LUMStdBomCost.lastModifiedByID>(graph.Accessinfo.UserID),
                                              new PXDataFieldAssign <LUMStdBomCost.lastModifiedByScreenID>(screenIDWODot),
                                              new PXDataFieldAssign <LUMStdBomCost.lastModifiedDateTime>(graph.Accessinfo.BusinessDate),
                                              new PXDataFieldAssign <LUMStdBomCost.noteID>(Guid.NewGuid()));
        }
    public bool AddLog(int activeTime, int idleTime, string screenId, string userId,
                       string refNbr, string docType, string action)
    {
        PXDatabase.Insert <AIActivityLog>(new PXDataFieldAssign <AIActivityLog.activeTime>(activeTime),
                                          new PXDataFieldAssign <AIActivityLog.idleTime>(idleTime),
                                          new PXDataFieldAssign <AIActivityLog.screenID>(screenId),
                                          new PXDataFieldAssign <AIActivityLog.userID>(userId),
                                          new PXDataFieldAssign <AIActivityLog.refNbr>(refNbr),
                                          new PXDataFieldAssign <AIActivityLog.docType>(docType),
                                          new PXDataFieldAssign <AIActivityLog.action>(action));

        return(true);
    }
Esempio n. 10
0
            public bool PersistGrams(Contact contact, bool requireRecreate = false)
            {
                try
                {
                    if (track == null)
                    {
                        track = DateTime.Now;
                    }
                    if (graph.Caches[contact.GetType()].GetStatus(contact) == PXEntryStatus.Deleted)
                    {
                        PXDatabase.Delete <CRGrams>(new PXDataFieldRestrict("EntityID", PXDbType.Int, 4, contact.ContactID, PXComp.EQ));
                        return(false);
                    }

                    if (!requireRecreate && GrammSourceUpdated(contact))
                    {
                        return(false);
                    }

                    PXDatabase.Delete <CRGrams>(new PXDataFieldRestrict("EntityID", PXDbType.Int, 4, contact.ContactID, PXComp.EQ));
                    foreach (CRGrams gram in DoCreateGramms(contact))
                    {
                        PXDatabase.Insert <CRGrams>(
                            new PXDataFieldAssign(typeof(CRGrams.entityID).Name, PXDbType.Int, 4, contact.ContactID),
                            new PXDataFieldAssign(typeof(CRGrams.fieldName).Name, PXDbType.NVarChar, 60, gram.FieldName),
                            new PXDataFieldAssign(typeof(CRGrams.fieldValue).Name, PXDbType.NVarChar, 60, gram.FieldValue),
                            new PXDataFieldAssign(typeof(CRGrams.score).Name, PXDbType.Decimal, 8, gram.Score),
                            new PXDataFieldAssign(typeof(CRGrams.validationType).Name, PXDbType.NVarChar, 2, gram.ValidationType)
                            );
                        //CRGrams row = (CRGrams)graph.Caches[typeof(CRGrams)].Insert(gram);
                        //graph.Caches[typeof(CRGrams)].PersistInserted(row);
                    }
                    contact.GrammValidationDateTime = PXTimeZoneInfo.Now;
                    PXDatabase.Update <Contact>
                    (
                        new PXDataFieldAssign(typeof(Contact.grammValidationDateTime).Name, PXTimeZoneInfo.ConvertTimeToUtc(contact.GrammValidationDateTime.Value, LocaleInfo.GetTimeZone())),
                        new PXDataFieldRestrict(typeof(Contact.contactID).Name, contact.ContactID)
                    );
                    processedItems += 1;
                    return(true);
                }
                finally
                {
                    if (processedItems % 100 == 0)
                    {
                        TimeSpan taken = DateTime.Now - (DateTime)track;
                        System.Diagnostics.Debug.WriteLine("Items count:{0}, increment taken {1}", processedItems, taken);
                        track = DateTime.Now;
                    }
                }
            }
Esempio n. 11
0
        protected void SaveEvent(PXExchangeEvent occasion)
        {
            if (occasion == null)
            {
                return;
            }

            PXDatabase.Insert <EMailSyncLog>(
                new PXDataFieldAssign <EMailSyncLog.serverID>(Account.AccountID),
                new PXDataFieldAssign <EMailSyncLog.address>(occasion.Address),
                new PXDataFieldAssign <EMailSyncLog.level>((byte)occasion.Level),
                new PXDataFieldAssign <EMailSyncLog.date>(occasion.Date),
                new PXDataFieldAssign <EMailSyncLog.message>(occasion.Message),
                new PXDataFieldAssign <EMailSyncLog.details>(occasion.Details == null ? null : String.Join(Environment.NewLine, occasion.Details)));
        }
Esempio n. 12
0
        public bool PersistGrams(DuplicateDocument document, bool requireRecreate = false)
        {
            if (graph.Caches[document.GetType()].GetStatus(document) == PXEntryStatus.Deleted)
            {
                PXDatabase.Delete <CRGrams>(new PXDataFieldRestrict <CRGrams.entityID>(PXDbType.Int, 4, document.ContactID, PXComp.EQ));

                return(false);
            }

            if (!requireRecreate && GrammSourceUpdated(document))
            {
                return(false);
            }

            PXDatabase.Delete <CRGrams>(new PXDataFieldRestrict <CRGrams.entityID>(PXDbType.Int, 4, document.ContactID, PXComp.EQ));

            foreach (CRGrams gram in DoCreateGramms(document))
            {
                PXDatabase.Insert <CRGrams>(
                    new PXDataFieldAssign(typeof(CRGrams.entityID).Name, PXDbType.Int, 4, document.ContactID),
                    new PXDataFieldAssign(typeof(CRGrams.fieldName).Name, PXDbType.NVarChar, 60, gram.FieldName),
                    new PXDataFieldAssign(typeof(CRGrams.fieldValue).Name, PXDbType.NVarChar, 60, gram.FieldValue),
                    new PXDataFieldAssign(typeof(CRGrams.score).Name, PXDbType.Decimal, 8, gram.Score),
                    new PXDataFieldAssign(typeof(CRGrams.validationType).Name, PXDbType.NVarChar, 2, gram.ValidationType)
                    );
            }

            document.DuplicateStatus         = DuplicateStatusAttribute.NotValidated;
            document.GrammValidationDateTime = PXTimeZoneInfo.Now;

            PXDatabase.Update <Contact>(
                new PXDataFieldAssign <Contact.duplicateStatus>(PXDbType.NVarChar, document.DuplicateStatus),
                new PXDataFieldAssign <Contact.grammValidationDateTime>(PXDbType.DateTime, PXTimeZoneInfo.ConvertTimeToUtc(document.GrammValidationDateTime.Value, LocaleInfo.GetTimeZone())),
                new PXDataFieldRestrict <Contact.contactID>(PXDbType.Int, document.ContactID)
                );

            return(true);
        }
Esempio n. 13
0
    /// <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));
            }
        }
    }
Esempio n. 14
0
        //This method executed after customization was published and website was restarted.
        public override void UpdateDatabase()
        {
            #region T200Data

            RSSVRepairServiceMaint repairServiceGraph = PXGraph.CreateInstance <RSSVRepairServiceMaint>();

            #region RSSVRepairService

            RSSVRepairService repairService = SelectFrom <RSSVRepairService> .View.ReadOnly.Select(repairServiceGraph);

            if (repairService == null)
            {
                using (StreamReader file = new StreamReader(AppDomain.CurrentDomain.BaseDirectory + "InputData\\RSSVRepairService.csv"))
                {
                    string header = file.ReadLine();
                    if (header != null)
                    {
                        string[] headerParts = header.Split(';');
                        while (true)
                        {
                            string line = file.ReadLine();
                            if (line != null)
                            {
                                string[] lineParts = line.Split(';');
                                IDictionary <string, string> dic     = headerParts.Select((k, i) => new { k, v = lineParts[i] }).ToDictionary(x => x.k, x => x.v);
                                RSSVRepairService            service = new RSSVRepairService
                                {
                                    ServiceCD        = dic["ServiceCD"],
                                    Description      = dic["Description"],
                                    Active           = Convert.ToBoolean(Convert.ToInt32(dic["Active"])),
                                    WalkInService    = Convert.ToBoolean(Convert.ToInt32(dic["WalkInService"])),
                                    Prepayment       = Convert.ToBoolean(Convert.ToInt32(dic["Prepayment"])),
                                    PreliminaryCheck = Convert.ToBoolean(Convert.ToInt32(dic["PreliminaryCheck"]))
                                };
                                repairServiceGraph.RepairService.Insert(service);
                                repairServiceGraph.Actions.PressSave();
                                repairServiceGraph.Clear();
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                    this.WriteLog("RSSVRepairService updated");
                }
            }
            #endregion

            RSSVDeviceMaint deviceGraph = PXGraph.CreateInstance <RSSVDeviceMaint>();

            #region RSSVDevice

            RSSVDevice servDevice = SelectFrom <RSSVDevice> .View.ReadOnly.Select(deviceGraph);

            if (servDevice == null)
            {
                using (StreamReader file = new StreamReader(AppDomain.CurrentDomain.BaseDirectory + "InputData\\RSSVDevice.csv"))
                {
                    string header = file.ReadLine();
                    if (header != null)
                    {
                        string[] headerParts = header.Split(';');
                        while (true)
                        {
                            string line = file.ReadLine();
                            if (line != null)
                            {
                                string[] lineParts = line.Split(';');
                                IDictionary <string, string> dic = headerParts.Select((k, i) => new { k, v = lineParts[i] }).ToDictionary(x => x.k, x => x.v);
                                RSSVDevice device = new RSSVDevice
                                {
                                    DeviceCD              = dic["DeviceCD"],
                                    Description           = dic["Description"],
                                    Active                = Convert.ToBoolean(Convert.ToInt32(dic["Active"])),
                                    AvgComplexityOfRepair = dic["AvgComplexityOfRepair"]
                                };
                                deviceGraph.ServDevices.Insert(device);
                                deviceGraph.Actions.PressSave();
                                deviceGraph.Clear();
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                    this.WriteLog("RSSVDevice updated");
                }
            }
            #endregion

            #endregion


            #region T210Data
            var iiEntry = PXGraph.CreateInstance <InventoryItemMaint>();
            #region InventoryItem
            //Add data to InventoryItem

            //InventoryItem invItem = SelectFrom<InventoryItem>.Where<InventoryItemExt.usrRepairItem.IsEqual<True>>.View.ReadOnly.Select(iiEntry);
            //if (invItem == null)
            //{
            using (StreamReader file = new StreamReader(AppDomain.CurrentDomain.BaseDirectory + "InputData\\InventoryItem.csv"))
            {
                string header = file.ReadLine();
                if (header != null)
                {
                    string[] headerParts = header.Split(';');
                    while (true)
                    {
                        string line = file.ReadLine();
                        if (line != null)
                        {
                            string[] lineParts = line.Split(';');
                            IDictionary <string, string> dic = headerParts.Select((k, i) => new { k, v = lineParts[i] }).ToDictionary(x => x.k, x => x.v);
                            InventoryItem invItem            = SelectFrom <InventoryItem> .Where <InventoryItem.inventoryID.IsEqual <@P.AsInt> > .View.ReadOnly.Select(iiEntry, Convert.ToInt32(dic["InventoryID"]));

                            if (invItem == null)
                            {
                                var iItem = new InventoryItem
                                {
                                    InventoryCD = dic["InventoryCD"],
                                    ItemClassID = Convert.ToInt32(dic["ItemClassID"])
                                };
                                iItem = PXCache <InventoryItem> .CreateCopy(iiEntry.Item.Insert(iItem));

                                iItem.Descr     = dic["Descr"];
                                iItem.BasePrice = Convert.ToDecimal(dic["BasePrice"]);
                                iItem           = PXCache <InventoryItem> .CreateCopy(iiEntry.Item.Update(iItem));

                                iItem.DfltSiteID = Convert.ToInt32(dic["DfltSiteID"]);
                                iItem            = PXCache <InventoryItem> .CreateCopy(iiEntry.Item.Update(iItem));

                                //var extItem = PXCache<InventoryItem>.GetExtension<InventoryItemExt>(iItem);
                                //extItem.UsrRepairItem = true;
                                //extItem.UsrRepairItemType = dic["UsrRepairItemType"];
                                //iItem = PXCache<InventoryItem>.CreateCopy(iiEntry.Item.Update(iItem));
                                iiEntry.Actions.PressSave();
                                iiEntry.Clear();
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                this.WriteLog("InventoryItem updated");
            }
            //}
            #endregion

            var repairPriceGraph = PXGraph.CreateInstance <RSSVRepairPriceMaint>();

            #region RSSVRepairPrice
            //Add data to RSSVRepairPrice
            RSSVRepairPrice repairPrice = SelectFrom <RSSVRepairPrice> .View.ReadOnly.Select(repairPriceGraph);

            if (repairPrice == null)
            {
                using (StreamReader file = new StreamReader(AppDomain.CurrentDomain.BaseDirectory + "InputData\\RSSVRepairPrice.csv"))
                {
                    string header = file.ReadLine();
                    if (header != null)
                    {
                        string[] headerParts = header.Split(';');
                        while (true)
                        {
                            string line = file.ReadLine();
                            if (line != null)
                            {
                                string[] lineParts = line.Split(';');
                                IDictionary <string, string> dic = headerParts.Select((k, i) => new { k, v = lineParts[i] }).ToDictionary(x => x.k, x => x.v);
                                RSSVRepairPrice price            = new RSSVRepairPrice
                                {
                                    DeviceID           = Convert.ToInt32(dic["DeviceID"]),
                                    ServiceID          = Convert.ToInt32(dic["ServiceID"]),
                                    Price              = Convert.ToDecimal(dic["Price"]),
                                    RepairItemLineCntr = Convert.ToInt32(dic["RepairItemLineCntr"])
                                };
                                repairPriceGraph.RepairPrices.Insert(price);
                                repairPriceGraph.Actions.PressSave();
                                repairPriceGraph.Clear();
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                    this.WriteLog("RSSVRepairPrice updated");
                }
            }
            #endregion

            #region RSSVRepairItem
            //Add data to RSSVRepairItem
            RSSVRepairItem repairItem = SelectFrom <RSSVRepairItem> .View.ReadOnly.Select(repairPriceGraph);

            if (repairItem == null)
            {
                using (StreamReader file = new StreamReader(AppDomain.CurrentDomain.BaseDirectory + "InputData\\RSSVRepairItem.csv"))
                {
                    string header = file.ReadLine();
                    if (header != null)
                    {
                        string[] headerParts = header.Split(';');
                        while (true)
                        {
                            string line = file.ReadLine();
                            if (line != null)
                            {
                                string[] lineParts = line.Split(';');
                                IDictionary <string, string> dic = headerParts.Select((k, i) => new { k, v = lineParts[i] }).ToDictionary(x => x.k, x => x.v);
                                RSSVRepairItem item = new RSSVRepairItem
                                {
                                    ServiceID      = Convert.ToInt32(dic["ServiceID"]),
                                    DeviceID       = Convert.ToInt32(dic["DeviceID"]),
                                    LineNbr        = Convert.ToInt32(dic["LineNbr"]),
                                    RepairItemType = Convert.ToString(dic["RepairItemType"]),
                                    InventoryID    = Convert.ToInt32(dic["InventoryID"]),
                                    Required       = Convert.ToBoolean(Convert.ToInt32(dic["Required"])),
                                    IsDefault      = Convert.ToBoolean(Convert.ToInt32(dic["IsDefault"])),
                                    BasePrice      = Convert.ToDecimal(dic["BasePrice"])
                                };
                                repairPriceGraph.RepairItems.Insert(item);
                                repairPriceGraph.Actions.PressSave();
                                repairPriceGraph.Clear();
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                    this.WriteLog("RSSVRepairItem updated");
                }
            }
            #endregion

            #region RSSVLabor
            //Add data to RSSVLabor
            RSSVLabor labor = SelectFrom <RSSVLabor> .View.ReadOnly.Select(repairPriceGraph);

            if (labor == null)
            {
                using (StreamReader file = new StreamReader(AppDomain.CurrentDomain.BaseDirectory + "InputData\\RSSVLabor.csv"))
                {
                    string header = file.ReadLine();
                    if (header != null)
                    {
                        string[] headerParts = header.Split(';');
                        while (true)
                        {
                            string line = file.ReadLine();
                            if (line != null)
                            {
                                string[] lineParts = line.Split(';');
                                IDictionary <string, string> dic = headerParts.Select((k, i) => new { k, v = lineParts[i] }).ToDictionary(x => x.k, x => x.v);
                                RSSVLabor priceLabor             = new RSSVLabor
                                {
                                    InventoryID  = Convert.ToInt32(dic["InventoryID"]),
                                    DeviceID     = Convert.ToInt32(dic["DeviceID"]),
                                    ServiceID    = Convert.ToInt32(dic["ServiceID"]),
                                    DefaultPrice = Convert.ToDecimal(dic["DefaultPrice"]),
                                    Quantity     = Convert.ToDecimal(dic["Quantity"]),
                                    ExtPrice     = Convert.ToDecimal(dic["ExtPrice"])
                                };
                                repairPriceGraph.Labor.Insert(priceLabor);
                                repairPriceGraph.Actions.PressSave();
                                repairPriceGraph.Clear();
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                    this.WriteLog("RSSVLabor updated");
                }
            }
            #endregion

            #region RSSVWarranty
            //Add data to RSSVWarranty
            RSSVWarranty warranty = SelectFrom <RSSVWarranty> .View.ReadOnly.Select(repairPriceGraph);

            if (warranty == null)
            {
                using (StreamReader file = new StreamReader(AppDomain.CurrentDomain.BaseDirectory + "InputData\\RSSVWarranty.csv"))
                {
                    string header = file.ReadLine();
                    if (header != null)
                    {
                        string[] headerParts = header.Split(';');
                        while (true)
                        {
                            string line = file.ReadLine();
                            if (line != null)
                            {
                                string[] lineParts = line.Split(';');
                                IDictionary <string, string> dic = headerParts.Select((k, i) => new { k, v = lineParts[i] }).ToDictionary(x => x.k, x => x.v);
                                RSSVWarranty priceWarranty       = new RSSVWarranty
                                {
                                    ContractID      = Convert.ToInt32(dic["ContractID"]),
                                    DeviceID        = Convert.ToInt32(dic["DeviceID"]),
                                    ServiceID       = Convert.ToInt32(dic["ServiceID"]),
                                    DefaultWarranty = Convert.ToBoolean(Convert.ToInt32(dic["DefaultWarranty"]))
                                };
                                repairPriceGraph.Warranty.Insert(priceWarranty);
                                repairPriceGraph.Actions.PressSave();
                                repairPriceGraph.Clear();
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                    this.WriteLog("RSSVWarranty updated");
                }
            }
            #endregion

            #endregion

            #region T220Data & T240Data

            var setupGraph = PXGraph.CreateInstance <RSSVSetupMaint>();

            #region RSSVSetup
            //Add data to RSSVSetup
            RSSVSetup setup = SelectFrom <RSSVSetup> .View.ReadOnly.Select(setupGraph);

            if (setup == null)
            {
                using (StreamReader file = new StreamReader(AppDomain.CurrentDomain.BaseDirectory + "InputData\\RSSVSetup.csv"))
                {
                    string header = file.ReadLine();
                    if (header != null)
                    {
                        string[] headerParts = header.Split(';');
                        while (true)
                        {
                            string line = file.ReadLine();
                            if (line != null)
                            {
                                string[] lineParts = line.Split(';');
                                IDictionary <string, string> dic = headerParts.Select((k, i) => new { k, v = lineParts[i] }).ToDictionary(x => x.k, x => x.v);

                                RSSVSetup settings = new RSSVSetup
                                {
                                    NumberingID       = dic["NumberingID"],
                                    WalkInCustomerID  = Convert.ToInt32(dic["WalkInCustomerID"]),
                                    DefaultEmployee   = Guid.Parse(dic["DefaultEmployee"]),
                                    PrepaymentPercent = Convert.ToDecimal(dic["PrepaymentPercent"])
                                };
                                setupGraph.Setup.Insert(settings);
                                setupGraph.Actions.PressSave();
                                setupGraph.Clear();
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                    this.WriteLog("RSSVSetup updated");
                }
            }
            #endregion

            var workOrderGraph = PXGraph.CreateInstance <RSSVWorkOrderEntry>();

            #region RSSVWorkOrder
            //Add data to RSSVWorkOrder
            RSSVWorkOrder workOrder = SelectFrom <RSSVWorkOrder> .View.ReadOnly.Select(workOrderGraph);

            if (workOrder == null)
            {
                using (StreamReader file = new StreamReader(AppDomain.CurrentDomain.BaseDirectory + "InputData\\RSSVWorkOrder.csv"))
                {
                    string header = file.ReadLine();
                    if (header != null)
                    {
                        string[] headerParts = header.Split(';');
                        while (true)
                        {
                            string line = file.ReadLine();
                            if (line != null)
                            {
                                string[] lineParts = line.Split(';');
                                IDictionary <string, string> dic = headerParts.Select((k, i) => new { k, v = lineParts[i] }).ToDictionary(x => x.k, x => x.v);
                                RSSVWorkOrder order = new RSSVWorkOrder
                                {
                                    OrderNbr    = dic["OrderNbr"],
                                    CustomerID  = Convert.ToInt32(dic["CustomerID"]),
                                    DateCreated = Convert.ToDateTime(dic["DateCreated"]),
                                    Status      = dic["Status"],
                                    Hold        = Convert.ToBoolean(Convert.ToInt32(dic["Hold"])),
                                    Description = dic["Description"],
                                    DeviceID    = Convert.ToInt32(dic["DeviceID"]),
                                    ServiceID   = Convert.ToInt32(dic["ServiceID"]),
                                    //OrderTotal = Convert.ToDecimal(dic["OrderTotal"]),
                                    RepairItemLineCntr = Convert.ToInt32(dic["RepairItemLineCntr"]),
                                    Priority           = dic["Priority"]
                                };
                                if (dic["DateCompleted"] != "NULL")
                                {
                                    order.DateCompleted = Convert.ToDateTime(dic["DateCompleted"]);
                                }
                                //if (dic["InvoiceNbr"] != "NULL") order.InvoiceNbr = dic["InvoiceNbr"];
                                if (dic["Assignee"] != "NULL")
                                {
                                    order.Assignee = Guid.Parse(dic["Assignee"]);
                                }
                                workOrderGraph.WorkOrders.Insert(order);
                                workOrderGraph.Actions.PressSave();
                                workOrderGraph.Clear();
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                    this.WriteLog("RSSVWorkOrder updated");
                }
            }
            #endregion

            #region RSSVWorkOrderItem
            //Add data to RSSVWorkOrderItem
            RSSVWorkOrderItem workOrderItem = SelectFrom <RSSVWorkOrderItem> .View.ReadOnly.Select(workOrderGraph);

            if (workOrderItem == null)
            {
                using (StreamReader file = new StreamReader(AppDomain.CurrentDomain.BaseDirectory + "InputData\\RSSVWorkOrderItem.csv"))
                {
                    string header = file.ReadLine();
                    if (header != null)
                    {
                        string[] headerParts = header.Split(';');
                        while (true)
                        {
                            string line = file.ReadLine();
                            if (line != null)
                            {
                                string[] lineParts = line.Split(';');
                                IDictionary <string, string> dic       = headerParts.Select((k, i) => new { k, v = lineParts[i] }).ToDictionary(x => x.k, x => x.v);                                                         //workOrderGraph.WorkOrders.Current = workOrderGraph.WorkOrders.Search<RSSVWorkOrder.orderNbr>(dic["OrderNbr"]);
                                RSSVWorkOrderItem            orderItem = new RSSVWorkOrderItem
                                {
                                    OrderNbr       = dic["OrderNbr"],
                                    LineNbr        = Convert.ToInt32(dic["LineNbr"]),
                                    RepairItemType = dic["RepairItemType"],
                                    InventoryID    = Convert.ToInt32(dic["InventoryID"]),
                                    BasePrice      = Convert.ToDecimal(dic["BasePrice"])
                                };
                                workOrderGraph.RepairItems.Insert(orderItem);
                                workOrderGraph.Actions.PressSave();
                                workOrderGraph.Clear();
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                    this.WriteLog("RSSVWorkOrderItem updated");
                }
            }
            #endregion

            #region RSSVWorkOrderLabor
            //Add data to RSSVWorkOrderLabor
            RSSVWorkOrderLabor workOrderLabor = SelectFrom <RSSVWorkOrderLabor> .View.ReadOnly.Select(workOrderGraph);

            if (workOrderLabor == null)
            {
                using (StreamReader file = new StreamReader(AppDomain.CurrentDomain.BaseDirectory + "InputData\\RSSVWorkOrderLabor.csv"))
                {
                    string header = file.ReadLine();
                    if (header != null)
                    {
                        string[] headerParts = header.Split(';');
                        while (true)
                        {
                            string line = file.ReadLine();
                            if (line != null)
                            {
                                string[] lineParts = line.Split(';');
                                IDictionary <string, string> dic       = headerParts.Select((k, i) => new { k, v = lineParts[i] }).ToDictionary(x => x.k, x => x.v);
                                RSSVWorkOrderLabor           laborItem = new RSSVWorkOrderLabor
                                {
                                    OrderNbr     = dic["OrderNbr"],
                                    InventoryID  = Convert.ToInt32(dic["InventoryID"]),
                                    DefaultPrice = Convert.ToDecimal(dic["DefaultPrice"]),
                                    Quantity     = Convert.ToDecimal(dic["Quantity"]),
                                    ExtPrice     = Convert.ToDecimal(dic["ExtPrice"])
                                };
                                workOrderGraph.Labor.Insert(laborItem);
                                workOrderGraph.Actions.PressSave();
                                workOrderGraph.Clear();
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                    this.WriteLog("RSSVWorkOrderLabor updated");
                }
            }
            #endregion



            #endregion

            #region T240Data
            #region RSSVEmployeeWorkOrderQty
            //Add data to RSSVEmployeeWorkOrderQty
            RSSVEmployeeWorkOrderQty qty = SelectFrom <RSSVEmployeeWorkOrderQty> .View.ReadOnly.Select(workOrderGraph);

            if (qty == null)
            {
                using (StreamReader file = new StreamReader(AppDomain.CurrentDomain.BaseDirectory + "InputData\\RSSVEmployeeWorkOrderQty.csv"))
                {
                    string header = file.ReadLine();
                    if (header != null)
                    {
                        string[] headerParts = header.Split(';');
                        while (true)
                        {
                            string line = file.ReadLine();
                            if (line != null)
                            {
                                string[] lineParts = line.Split(';');
                                IDictionary <string, string> dic = headerParts.Select((k, i) => new { k, v = lineParts[i] }).ToDictionary(x => x.k, x => x.v);
                                //we skip graph logic for RSSVEmployeeWorkOrderQty because there is a PXAccumulator attribute for its field
                                PXDatabase.Insert <RSSVEmployeeWorkOrderQty>(
                                    new PXDataFieldAssign <RSSVEmployeeWorkOrderQty.userid>(Guid.Parse(dic["UserID"])),
                                    new PXDataFieldAssign <RSSVEmployeeWorkOrderQty.nbrOfAssignedOrders>(Convert.ToInt32(dic["NbrOfAssignedOrders"])),
                                    new PXDataFieldAssign <RSSVWorkOrder.lastModifiedDateTime>(workOrderGraph.Accessinfo.BusinessDate)
                                    );
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                    this.WriteLog("RSSVEmployeeWorkOrderQty updated");
                }
            }
            #endregion
            #endregion
        }
Esempio n. 15
0
        public override void UpdateDatabase()
        {
            ProjectList graph = PXGraph.CreateInstance <ProjectList>();

            try
            {
                SOThrottleConstants records = PXSelectReadonly <SOThrottleConstants> .Select(graph);

                if (records != null)
                {
                    PXDatabase.Delete <SOThrottleConstants>();
                }
                PXDatabase.Insert <SOThrottleConstants>(
                    new PXDataFieldAssign <SOThrottleConstants.apiname>(SOConstants.apiListOrders),
                    new PXDataFieldAssign <SOThrottleConstants.delayTime>("30000"),
                    new PXDataFieldAssign <SOThrottleConstants.createdDateTime>(PXTimeZoneInfo.Now),
                    new PXDataFieldAssign <SOThrottleConstants.lastModifiedDateTime>(PXTimeZoneInfo.Now),
                    new PXDataFieldAssign <SOThrottleConstants.createdByID>(graph.Accessinfo.UserID),
                    new PXDataFieldAssign <SOThrottleConstants.lastModifiedByID>(graph.Accessinfo.UserID)
                    );

                PXDatabase.Insert <SOThrottleConstants>(
                    new PXDataFieldAssign <SOThrottleConstants.apiname>(SOConstants.apiListOrdersByNextToken),
                    new PXDataFieldAssign <SOThrottleConstants.delayTime>("30000"),
                    new PXDataFieldAssign <SOThrottleConstants.createdDateTime>(PXTimeZoneInfo.Now),
                    new PXDataFieldAssign <SOThrottleConstants.lastModifiedDateTime>(PXTimeZoneInfo.Now),
                    new PXDataFieldAssign <SOThrottleConstants.createdByID>(graph.Accessinfo.UserID),
                    new PXDataFieldAssign <SOThrottleConstants.lastModifiedByID>(graph.Accessinfo.UserID));

                PXDatabase.Insert <SOThrottleConstants>(
                    new PXDataFieldAssign <SOThrottleConstants.apiname>(SOConstants.apiGetOrder),
                    new PXDataFieldAssign <SOThrottleConstants.delayTime>("30000"),
                    new PXDataFieldAssign <SOThrottleConstants.createdDateTime>(PXTimeZoneInfo.Now),
                    new PXDataFieldAssign <SOThrottleConstants.lastModifiedDateTime>(PXTimeZoneInfo.Now),
                    new PXDataFieldAssign <SOThrottleConstants.createdByID>(graph.Accessinfo.UserID),
                    new PXDataFieldAssign <SOThrottleConstants.lastModifiedByID>(graph.Accessinfo.UserID));

                PXDatabase.Insert <SOThrottleConstants>(
                    new PXDataFieldAssign <SOThrottleConstants.apiname>(SOConstants.apiGetListOrderItems),
                    new PXDataFieldAssign <SOThrottleConstants.delayTime>("10000"),
                    new PXDataFieldAssign <SOThrottleConstants.createdDateTime>(PXTimeZoneInfo.Now),
                    new PXDataFieldAssign <SOThrottleConstants.lastModifiedDateTime>(PXTimeZoneInfo.Now),
                    new PXDataFieldAssign <SOThrottleConstants.createdByID>(graph.Accessinfo.UserID),
                    new PXDataFieldAssign <SOThrottleConstants.lastModifiedByID>(graph.Accessinfo.UserID));

                PXDatabase.Insert <SOThrottleConstants>(
                    new PXDataFieldAssign <SOThrottleConstants.apiname>(SOConstants.apiSubmitFeed),
                    new PXDataFieldAssign <SOThrottleConstants.delayTime>("20000"),
                    new PXDataFieldAssign <SOThrottleConstants.createdDateTime>(PXTimeZoneInfo.Now),
                    new PXDataFieldAssign <SOThrottleConstants.lastModifiedDateTime>(PXTimeZoneInfo.Now),
                    new PXDataFieldAssign <SOThrottleConstants.createdByID>(graph.Accessinfo.UserID),
                    new PXDataFieldAssign <SOThrottleConstants.lastModifiedByID>(graph.Accessinfo.UserID));

                PXDatabase.Insert <SOThrottleConstants>(
                    new PXDataFieldAssign <SOThrottleConstants.apiname>(SOConstants.apiGetFeedSubmissionResult),
                    new PXDataFieldAssign <SOThrottleConstants.delayTime>("20000"),
                    new PXDataFieldAssign <SOThrottleConstants.createdDateTime>(PXTimeZoneInfo.Now),
                    new PXDataFieldAssign <SOThrottleConstants.lastModifiedDateTime>(PXTimeZoneInfo.Now),
                    new PXDataFieldAssign <SOThrottleConstants.createdByID>(graph.Accessinfo.UserID),
                    new PXDataFieldAssign <SOThrottleConstants.lastModifiedByID>(graph.Accessinfo.UserID));

                PXDatabase.Insert <SOThrottleConstants>(
                    new PXDataFieldAssign <SOThrottleConstants.apiname>(SOConstants.apiRequestReport),
                    new PXDataFieldAssign <SOThrottleConstants.delayTime>("10000"),
                    new PXDataFieldAssign <SOThrottleConstants.createdDateTime>(PXTimeZoneInfo.Now),
                    new PXDataFieldAssign <SOThrottleConstants.lastModifiedDateTime>(PXTimeZoneInfo.Now),
                    new PXDataFieldAssign <SOThrottleConstants.createdByID>(graph.Accessinfo.UserID),
                    new PXDataFieldAssign <SOThrottleConstants.lastModifiedByID>(graph.Accessinfo.UserID));

                PXDatabase.Insert <SOThrottleConstants>(
                    new PXDataFieldAssign <SOThrottleConstants.apiname>(SOConstants.apiGetRequestReportList),
                    new PXDataFieldAssign <SOThrottleConstants.delayTime>("30000"),
                    new PXDataFieldAssign <SOThrottleConstants.createdDateTime>(PXTimeZoneInfo.Now),
                    new PXDataFieldAssign <SOThrottleConstants.lastModifiedDateTime>(PXTimeZoneInfo.Now),
                    new PXDataFieldAssign <SOThrottleConstants.createdByID>(graph.Accessinfo.UserID),
                    new PXDataFieldAssign <SOThrottleConstants.lastModifiedByID>(graph.Accessinfo.UserID));

                PXDatabase.Insert <SOThrottleConstants>(
                    new PXDataFieldAssign <SOThrottleConstants.apiname>(SOConstants.getGeneratedReportID),
                    new PXDataFieldAssign <SOThrottleConstants.delayTime>("30000"),
                    new PXDataFieldAssign <SOThrottleConstants.createdDateTime>(PXTimeZoneInfo.Now),
                    new PXDataFieldAssign <SOThrottleConstants.lastModifiedDateTime>(PXTimeZoneInfo.Now),
                    new PXDataFieldAssign <SOThrottleConstants.createdByID>(graph.Accessinfo.UserID),
                    new PXDataFieldAssign <SOThrottleConstants.lastModifiedByID>(graph.Accessinfo.UserID));

                PXDatabase.Insert <SOThrottleConstants>(
                    new PXDataFieldAssign <SOThrottleConstants.apiname>(SOConstants.apiGetReport),
                    new PXDataFieldAssign <SOThrottleConstants.delayTime>("20000"),
                    new PXDataFieldAssign <SOThrottleConstants.createdDateTime>(PXTimeZoneInfo.Now),
                    new PXDataFieldAssign <SOThrottleConstants.lastModifiedDateTime>(PXTimeZoneInfo.Now),
                    new PXDataFieldAssign <SOThrottleConstants.createdByID>(graph.Accessinfo.UserID),
                    new PXDataFieldAssign <SOThrottleConstants.lastModifiedByID>(graph.Accessinfo.UserID));

                PXDatabase.Insert <SOThrottleConstants>(
                    new PXDataFieldAssign <SOThrottleConstants.apiname>(SOConstants.apiFeedResultWaiting),
                    new PXDataFieldAssign <SOThrottleConstants.delayTime>("20000"),
                    new PXDataFieldAssign <SOThrottleConstants.createdDateTime>(PXTimeZoneInfo.Now),
                    new PXDataFieldAssign <SOThrottleConstants.lastModifiedDateTime>(PXTimeZoneInfo.Now),
                    new PXDataFieldAssign <SOThrottleConstants.createdByID>(graph.Accessinfo.UserID),
                    new PXDataFieldAssign <SOThrottleConstants.lastModifiedByID>(graph.Accessinfo.UserID));
            }
            catch (Exception ex)
            {
                PXTrace.WriteInformation(ex.Message);
            }
        }
        private static void RunPerformanceTest(int numberOfIterations, bool cachingOfGraph = true)
        {
            //Initially create instance of graph with old BQL with usage of BQL
            //Then create instance of graph with F-BQL and with usage of BQL for

            //Right now in Acumatica sales demo following SQL:
            //select * from Contact where LEN(DisplayName ) > 0
            //gives 872 rows
            //I plan to create some amount of

            StringBuilder sb = new StringBuilder();

            int numberOfNotNull = 872;

            Random rand = new Random();

            var sw = new Stopwatch();

            sw.Start();

            var graph0 = PXGraph.CreateInstance <FBQLStudent1>();

            for (int i = 0; i < numberOfIterations; i++)
            {
                int startIdx = rand.Next(numberOfNotNull);

                if (cachingOfGraph)
                {
                    graph0 = PXGraph.CreateInstance <FBQLStudent1>();
                }

                var contact = PXSelect <Contact, Where <Contact.displayName, IsNotNull, And <Contact.displayName, Contains <Required <Contact.displayName> > > > > .SelectWindowed(graph0, startIdx, 1, ' ').First();

                var firstName  = contact.GetItem <Contact>().DisplayName.Split(' ')[0];
                var secondName = contact.GetItem <Contact>().DisplayName.Split(' ')[1];
                graph0.Clear();

                var student = new Student1();
                student.StudentCD = firstName.ToUpper() + secondName.ToUpper();
                student           = graph0.Students.Insert(student);

                student.FirstName = firstName;
                student.LastName  = secondName;
                graph0.Students.Update(student);
                graph0.Persist();
            }
            sw.Stop();
            sb.Append($"Classical way took {sw.ElapsedMilliseconds} milliseconds on {numberOfIterations} of iterations");

            var sw1 = new Stopwatch();

            sw1.Start();

            var graph1 = PXGraph.CreateInstance <FBQLStudent2>();

            for (int i = 0; i < numberOfIterations; i++)
            {
                int startIdx = rand.Next(numberOfNotNull);

                if (cachingOfGraph)
                {
                    graph1 = PXGraph.CreateInstance <FBQLStudent2>();
                }

                //var contact = PXSelect<Contact, Where<Contact.displayName, IsNotNull, And<Contact.displayName, Contains<Required<Contact.displayName>>>>>.SelectWindowed(graph, startIdx, 1, ' ').First();
                var contact = SelectFrom <Contact> .Where <Contact.displayName.IsNotNull.And <Contact.displayName.Contains <@P.AsString> > > .View.SelectWindowed(graph1, startIdx, 1, ' ').First();


                var firstName  = contact.GetItem <Contact>().DisplayName.Split(' ')[0];
                var secondName = contact.GetItem <Contact>().DisplayName.Split(' ')[1];
                graph1.Clear();

                var student = new Student2();
                student.StudentCD = firstName.ToUpper() + secondName.ToUpper();
                student           = graph1.Students.Insert(student);

                student.FirstName = firstName;
                student.LastName  = secondName;
                graph1.Students.Update(student);
                graph1.Persist();
            }
            sw1.Stop();
            sb.Append($"Performance Persist");
            sb.Append(Guid.NewGuid().ToString());

            PXDatabase.Insert <LogMessage>(
                new PXDataFieldAssign <LogMessage.message>(sb.ToString()),
                new PXDataFieldAssign <LogMessage.millisecondsB>(sw.ElapsedMilliseconds),
                new PXDataFieldAssign <LogMessage.millisecondsF>(sw1.ElapsedMilliseconds),
                new PXDataFieldAssign <LogMessage.iterations>(numberOfIterations),
                new PXDataFieldAssign <LogMessage.asImportScenario>(cachingOfGraph)
                );
        }
        private static void RunPerformanceSelect(int numberOfIterations, bool cachingOfGraph = true)
        {
            StringBuilder sb = new StringBuilder();

            int numberOfNotNull = 872;

            Random rand = new Random();

            var sw = new Stopwatch();

            sw.Start();
            var graph0 = PXGraph.CreateInstance <FBQLStudent1>();

            for (int i = 0; i < numberOfIterations; i++)
            {
                int startIdx = rand.Next(numberOfNotNull);

                if (cachingOfGraph)
                {
                    graph0 = PXGraph.CreateInstance <FBQLStudent1>();
                }

                var contact = PXSelect <Contact, Where <Contact.displayName, IsNotNull, And <Contact.displayName, Contains <Required <Contact.displayName> > > > > .SelectWindowed(graph0, startIdx, 1, ' ').First();

                var firstName  = contact.GetItem <Contact>().DisplayName.Split(' ')[0];
                var secondName = contact.GetItem <Contact>().DisplayName.Split(' ')[1];
            }
            sw.Stop();
            sb.Append($"Classical select took {sw.ElapsedMilliseconds} milliseconds on {numberOfIterations} of iterations");

            var sw1 = new Stopwatch();

            sw1.Start();

            var graph1 = PXGraph.CreateInstance <FBQLStudent2>();

            for (int i = 0; i < numberOfIterations; i++)
            {
                int startIdx = rand.Next(numberOfNotNull);

                if (cachingOfGraph)
                {
                    graph1 = PXGraph.CreateInstance <FBQLStudent2>();
                }


                //var contact = PXSelect<Contact, Where<Contact.displayName, IsNotNull, And<Contact.displayName, Contains<Required<Contact.displayName>>>>>.SelectWindowed(graph, startIdx, 1, ' ').First();
                var contact = SelectFrom <Contact> .Where <Contact.displayName.IsNotNull.And <Contact.displayName.Contains <@P.AsString> > > .View.SelectWindowed(graph1, startIdx, 1, ' ').First();

                var firstName  = contact.GetItem <Contact>().DisplayName.Split(' ')[0];
                var secondName = contact.GetItem <Contact>().DisplayName.Split(' ')[1];
            }
            sw1.Stop();
            sb.Append($"Performance Select");
            sb.Append(Guid.NewGuid().ToString());

            PXDatabase.Insert <LogMessage>(
                new PXDataFieldAssign <LogMessage.message>(sb.ToString()),
                new PXDataFieldAssign <LogMessage.millisecondsB>(sw.ElapsedMilliseconds),
                new PXDataFieldAssign <LogMessage.millisecondsF>(sw1.ElapsedMilliseconds),
                new PXDataFieldAssign <LogMessage.iterations>(numberOfIterations),
                new PXDataFieldAssign <LogMessage.asImportScenario>(cachingOfGraph)
                );
        }
Esempio n. 18
0
        public virtual void UpdateDiscount(string discountID, string discountSequenceID, DateTime?filterDate)
        {
            using (PXConnectionScope cs = new PXConnectionScope())
            {
                using (PXTransactionScope ts = new PXTransactionScope())
                {
                    foreach (DiscountSequenceDetail detail in PXSelect <DiscountSequenceDetail, Where <DiscountSequenceDetail.discountID, Equal <Required <DiscountSequenceDetail.discountID> >,
                                                                                                       And <DiscountSequenceDetail.discountSequenceID, Equal <Required <DiscountSequenceDetail.discountSequenceID> >, And <DiscountSequenceDetail.isLast, Equal <False> > > > > .Select(this, discountID, discountSequenceID))
                    {
                        if (detail.PendingDate != null && detail.PendingDate.Value <= filterDate.Value)
                        {
                            if (!PXDatabase.Update <DiscountSequenceDetail>(
                                    new PXDataFieldAssign("IsActive", PXDbType.Bit, detail.IsActive),
                                    new PXDataFieldAssign("Amount", PXDbType.Decimal, detail.Amount),
                                    new PXDataFieldAssign("AmountTo", PXDbType.Decimal, detail.AmountTo),
                                    new PXDataFieldAssign("Quantity", PXDbType.Decimal, detail.Quantity),
                                    new PXDataFieldAssign("QuantityTo", PXDbType.Decimal, detail.QuantityTo),
                                    new PXDataFieldAssign("Discount", PXDbType.Decimal, detail.Discount),
                                    new PXDataFieldAssign("FreeItemQty", PXDbType.Decimal, detail.FreeItemQty),
                                    new PXDataFieldAssign("LastDate", PXDbType.DateTime, detail.PendingDate),
                                    new PXDataFieldAssign("PendingAmount", PXDbType.Decimal, null),
                                    new PXDataFieldAssign("PendingQuantity", PXDbType.Decimal, 0m),
                                    new PXDataFieldAssign("PendingDiscount", PXDbType.Decimal, null),
                                    new PXDataFieldAssign("PendingFreeItemQty", PXDbType.Decimal, 0m),
                                    new PXDataFieldAssign("PendingDate", PXDbType.DateTime, null),
                                    new PXDataFieldRestrict("DiscountID", PXDbType.NVarChar, detail.DiscountID),
                                    new PXDataFieldRestrict("DiscountSequenceID", PXDbType.NVarChar, detail.DiscountSequenceID),
                                    new PXDataFieldRestrict("LineNbr", PXDbType.Int, detail.LineNbr),
                                    new PXDataFieldRestrict("IsLast", PXDbType.Bit, 1)
                                    ))
                            {
                                PXDatabase.Insert <DiscountSequenceDetail>(
                                    new PXDataFieldAssign("DiscountID", PXDbType.NVarChar, detail.DiscountID),
                                    new PXDataFieldAssign("DiscountSequenceID", PXDbType.NVarChar, detail.DiscountSequenceID),
                                    new PXDataFieldAssign("LineNbr", PXDbType.Int, detail.LineNbr),
                                    new PXDataFieldAssign("IsActive", PXDbType.Bit, detail.IsActive),
                                    new PXDataFieldAssign("IsLast", PXDbType.Bit, 1),
                                    new PXDataFieldAssign("Amount", PXDbType.Decimal, detail.Amount),
                                    new PXDataFieldAssign("AmountTo", PXDbType.Decimal, detail.AmountTo),
                                    new PXDataFieldAssign("Quantity", PXDbType.Decimal, detail.Quantity),
                                    new PXDataFieldAssign("QuantityTo", PXDbType.Decimal, detail.QuantityTo),
                                    new PXDataFieldAssign("Discount", PXDbType.Decimal, detail.Discount),
                                    new PXDataFieldAssign("FreeItemQty", PXDbType.Decimal, detail.FreeItemQty),
                                    new PXDataFieldAssign("LastDate", PXDbType.DateTime, detail.PendingDate),
                                    new PXDataFieldAssign("PendingAmount", PXDbType.Decimal, null),
                                    new PXDataFieldAssign("PendingQuantity", PXDbType.Decimal, 0m),
                                    new PXDataFieldAssign("PendingDiscount", PXDbType.Decimal, null),
                                    new PXDataFieldAssign("PendingFreeItemQty", PXDbType.Decimal, 0m),
                                    new PXDataFieldAssign("PendingDate", PXDbType.DateTime, null),
                                    new PXDataFieldAssign("CreatedByID", PXDbType.UniqueIdentifier, 16, detail.CreatedByID),
                                    new PXDataFieldAssign("CreatedByScreenID", PXDbType.Char, 8, detail.CreatedByScreenID),
                                    new PXDataFieldAssign("CreatedDateTime", PXDbType.DateTime, 8, detail.CreatedDateTime),
                                    new PXDataFieldAssign("LastModifiedByID", PXDbType.UniqueIdentifier, 16, detail.LastModifiedByID),
                                    new PXDataFieldAssign("LastModifiedByScreenID", PXDbType.Char, 8, detail.LastModifiedByScreenID),
                                    new PXDataFieldAssign("LastModifiedDateTime", PXDbType.DateTime, 8, detail.LastModifiedDateTime)
                                    );
                            }



                            PXDatabase.Update <DiscountSequenceDetail>(
                                new PXDataFieldAssign("Amount", PXDbType.DirectExpression, "PendingAmount"),
                                new PXDataFieldAssign("Quantity", PXDbType.DirectExpression, "PendingQuantity"),
                                new PXDataFieldAssign("Discount", PXDbType.DirectExpression, "PendingDiscount"),
                                new PXDataFieldAssign("FreeItemQty", PXDbType.DirectExpression, "PendingFreeItemQty"),
                                new PXDataFieldAssign("LastDate", PXDbType.DirectExpression, "PendingDate"),
                                new PXDataFieldAssign("PendingAmount", PXDbType.Decimal, null),
                                new PXDataFieldAssign("PendingQuantity", PXDbType.Decimal, 0m),
                                new PXDataFieldAssign("PendingDiscount", PXDbType.Decimal, null),
                                new PXDataFieldAssign("PendingFreeItemQty", PXDbType.Decimal, 0m),
                                new PXDataFieldAssign("PendingDate", PXDbType.DateTime, null),
                                new PXDataFieldRestrict("DiscountID", PXDbType.NVarChar, detail.DiscountID),
                                new PXDataFieldRestrict("DiscountSequenceID", PXDbType.NVarChar, detail.DiscountSequenceID),
                                new PXDataFieldRestrict("LineNbr", PXDbType.Int, detail.LineNbr),
                                new PXDataFieldRestrict("IsLast", PXDbType.Bit, 0)
                                );
                        }
                    }

                    foreach (DiscountSequenceDetail detail in PXSelectReadonly <DiscountSequenceDetail, Where <DiscountSequenceDetail.discountID, Equal <Required <DiscountSequenceDetail.discountID> >,
                                                                                                               And <DiscountSequenceDetail.discountSequenceID, Equal <Required <DiscountSequenceDetail.discountSequenceID> > > > > .Select(this, discountID, discountSequenceID))
                    {
                        DiscountSequenceDetail amonextval = PXSelectReadonly <DiscountSequenceDetail, Where <DiscountSequenceDetail.discountID, Equal <Required <DiscountSequenceDetail.discountID> >,
                                                                                                             And <DiscountSequenceDetail.discountSequenceID, Equal <Required <DiscountSequenceDetail.discountSequenceID> >, And <DiscountSequenceDetail.amount, Greater <Required <DiscountSequenceDetail.amount> >, And <DiscountSequenceDetail.isLast, Equal <Required <DiscountSequenceDetail.isLast> >, And <DiscountSequenceDetail.isActive, Equal <True> > > > > >,
                                                                              OrderBy <Asc <DiscountSequenceDetail.amount> > > .SelectWindowed(this, 0, 1, discountID, discountSequenceID, detail.Amount, detail.IsLast);

                        DiscountSequenceDetail qtynextval = PXSelectReadonly <DiscountSequenceDetail, Where <DiscountSequenceDetail.discountID, Equal <Required <DiscountSequenceDetail.discountID> >,
                                                                                                             And <DiscountSequenceDetail.discountSequenceID, Equal <Required <DiscountSequenceDetail.discountSequenceID> >, And <DiscountSequenceDetail.quantity, Greater <Required <DiscountSequenceDetail.quantity> >, And <DiscountSequenceDetail.isLast, Equal <Required <DiscountSequenceDetail.isLast> >, And <DiscountSequenceDetail.isActive, Equal <True> > > > > >,
                                                                              OrderBy <Asc <DiscountSequenceDetail.quantity> > > .SelectWindowed(this, 0, 1, discountID, discountSequenceID, detail.Quantity, detail.IsLast);

                        PXDatabase.Update <DiscountSequenceDetail>(
                            new PXDataFieldAssign("AmountTo", PXDbType.Decimal, (amonextval == null ? null : amonextval.Amount)),
                            new PXDataFieldAssign("QuantityTo", PXDbType.Decimal, (qtynextval == null ? null : qtynextval.Quantity)),
                            new PXDataFieldRestrict("DiscountDetailsID", PXDbType.Int, detail.DiscountDetailsID)
                            );
                    }


                    DiscountSequence sequence = PXSelect <DiscountSequence,
                                                          Where <DiscountSequence.discountID, Equal <Required <DiscountSequence.discountID> >,
                                                                 And <DiscountSequence.discountSequenceID, Equal <Required <DiscountSequence.discountSequenceID> > > > > .Select(this, discountID, discountSequenceID);

                    if (sequence != null && sequence.StartDate != null && sequence.PendingFreeItemID != null)
                    {
                        PXDatabase.Update <DiscountSequence>(
                            new PXDataFieldAssign("LastFreeItemID", PXDbType.DirectExpression, "FreeItemID"),
                            new PXDataFieldAssign("FreeItemID", PXDbType.DirectExpression, "PendingFreeItemID"),
                            new PXDataFieldAssign("PendingFreeItemID", PXDbType.Int, null),
                            new PXDataFieldAssign("UpdateDate", PXDbType.DateTime, filterDate.Value),
                            //new PXDataFieldAssign("StartDate", PXDbType.DateTime, null),
                            new PXDataFieldRestrict("DiscountID", PXDbType.VarChar, discountID),
                            new PXDataFieldRestrict("DiscountSequenceID", PXDbType.VarChar, discountSequenceID)
                            );
                    }
                    else if (sequence != null && sequence.StartDate != null)
                    {
                        PXDatabase.Update <DiscountSequence>(
                            new PXDataFieldAssign("UpdateDate", PXDbType.DateTime, filterDate.Value),
                            new PXDataFieldRestrict("DiscountID", PXDbType.VarChar, discountID),
                            new PXDataFieldRestrict("DiscountSequenceID", PXDbType.VarChar, discountSequenceID)
                            );
                    }
                    ts.Complete();
                }
            }
        }
Esempio n. 19
0
        protected virtual void InsertNumber(PXCache sender)
        {
            List <PXDataFieldAssign> field = new List <PXDataFieldAssign>();

            PXDatabase.Insert <ARInvoiceNbr>(fields.ToArray());
        }