public override void RowPersisting(PXCache sender, PXRowPersistingEventArgs e) { object key; if (IsTopLevel && (key = sender.GetValue(e.Row, FieldName)) != null) { PXCache cache = sender.Graph.Caches[typeof(CurrencyInfo)]; CurrencyInfo info = (CurrencyInfo)cache.Locate(new CurrencyInfo { CuryInfoID = Convert.ToInt64(key) }); PXEntryStatus status = PXEntryStatus.Notchanged; if (info != null && ((status = cache.GetStatus(info)) == PXEntryStatus.Inserted)) { cache.PersistInserted(info); } else if (status == PXEntryStatus.Updated) { cache.PersistUpdated(info); } else if (status == PXEntryStatus.Deleted) { cache.PersistDeleted(info); } } base.RowPersisting(sender, e); }
protected void Filltables() { Guid currentwikipage = new Guid(pageid); PXGraph article = PXGraph.CreateInstance(typeof(KBArticleMaint)); PXCache response = article.Caches[typeof(KBResponse)]; PXCache responsesummary = article.Caches[typeof(KBResponseSummary)]; PXResult <WikiPage, WikiPageLanguage> result = (PXResult <WikiPage, WikiPageLanguage>) PXSelectJoin <WikiPage, InnerJoin <WikiPageLanguage, On <WikiPageLanguage.pageID, Equal <WikiPage.pageID> > >, Where <WikiPage.pageID, Equal <Required <WikiPage.pageID> > >, OrderBy <Desc <WikiRevision.pageRevisionID> > > .SelectWindowed(new PXGraph(), 0, 1, currentwikipage); Guid userId = PXAccess.GetUserID(); PXResult <KBResponseSummary> resultsummary = (PXResult <KBResponseSummary>) PXSelect <KBResponseSummary, Where <KBResponseSummary.pageID, Equal <Required <KBResponseSummary.pageID> > > > . SelectWindowed(article, 0, 1, currentwikipage); PXResult <KBResponse> resnonse = (PXResult <KBResponse>) PXSelect <KBResponse, Where <KBResponse.userID, Equal <Required <KBResponse.userID> >, And <KBResponse.pageID, Equal <Required <KBResponse.pageID> > > > > . SelectWindowed(article, 0, 1, userId, currentwikipage); if (result != null) { WikiPage wp = result[typeof(WikiPage)] as WikiPage; WikiPageLanguage wpl = result[typeof(WikiPageLanguage)] as WikiPageLanguage; KBResponse newresnonse = response.CreateInstance() as KBResponse; if (resnonse != null) { newresnonse = resnonse[typeof(KBResponse)] as KBResponse; if (wp != null && wpl != null) { Int16 res; if (Int16.TryParse(Rate.Value.ToString(), out res)) { newresnonse.PageID = currentwikipage; newresnonse.RevisionID = 1; newresnonse.NewMark = res; newresnonse.Date = PXTimeZoneInfo.Now; newresnonse.Summary = ""; newresnonse.CreatedByID = wp.CreatedByID; newresnonse.CreatedByScreenID = "WP00000"; newresnonse.CreatedDateTime = wp.CreatedDateTime; newresnonse.LastModifiedByID = wp.LastModifiedByID; newresnonse.LastModifiedByScreenID = "WP00000"; newresnonse.LastModifiedDateTime = wp.LastModifiedDateTime; response.Update(newresnonse); response.PersistUpdated(newresnonse); response.Clear(); } } } } }
protected virtual void ARInvoice_RowPersisting(PXCache sender, PXRowPersistingEventArgs e) { sender.Persist(e.Row, PXDBOperation.Normal); sender.PersistInserted(e.Row); sender.PersistUpdated(e.Row); sender.PersistDeleted(e.Row); }
protected virtual string GetNewNumber(PXCache sender, Type setupType) { if (_LastNumberCommand == null) { CreateLastNumberCommand(); } PXView view = new PXView(sender.Graph, false, _LastNumberCommand); object row = view.SelectSingle(); if (row == null) { return(null); } string lastNumber = (string)view.Cache.GetValue(row, LastNumberField.Name); char[] symbols = lastNumber.ToCharArray(); for (int i = symbols.Length - 1; i >= 0; i--) { if (!char.IsDigit(symbols[i])) { break; } if (symbols[i] < '9') { symbols[i]++; break; } symbols[i] = '0'; } lastNumber = new string(symbols); view.Cache.SetValue(row, LastNumberField.Name, lastNumber); PXCache setupCache = sender.Graph.Caches[setupType]; setupCache.Update(row); setupCache.PersistUpdated(row); if (!string.IsNullOrEmpty(Prefix)) { lastNumber = Prefix + lastNumber; } return(lastNumber); }
public static void ReleasePayments(List <APPayment> list, string Action) { APReleaseChecks releaseChecksGraph = CreateInstance <APReleaseChecks>(); APPaymentEntry pe = CreateInstance <APPaymentEntry>(); CABatchEntry be = CreateInstance <CABatchEntry>(); bool failed = false; bool successed = false; List <APRegister> docs = new List <APRegister>(list.Count); foreach (APPayment payment in list) { if (payment.Passed == true) { releaseChecksGraph.TimeStamp = pe.TimeStamp = payment.tstamp; } switch (Action) { case ReleaseChecksFilter.action.ReleaseChecks: payment.Printed = true; break; case ReleaseChecksFilter.action.ReprintChecks: case ReleaseChecksFilter.action.VoidAndReprintChecks: payment.ExtRefNbr = null; payment.Printed = false; break; default: continue; } PXProcessing <APPayment> .SetCurrentItem(payment); if (Action == ReleaseChecksFilter.action.ReleaseChecks) { try { pe.Document.Current = pe.Document.Search <APPayment.refNbr>(payment.RefNbr, payment.DocType); if (pe.Document.Current?.ExtRefNbr != payment.ExtRefNbr) { APPayment payment_copy = PXCache <APPayment> .CreateCopy(pe.Document.Current); payment_copy.ExtRefNbr = payment.ExtRefNbr; pe.Document.Update(payment_copy); } if (PaymentRefAttribute.PaymentRefMustBeUnique(pe.paymenttype.Current) && string.IsNullOrEmpty(payment.ExtRefNbr)) { throw new PXException(ErrorMessages.FieldIsEmpty, typeof(APPayment.extRefNbr).Name); } payment.IsReleaseCheckProcess = true; APPrintChecks.AssignNumbersWithNoAdditionalProcessing(pe, payment); pe.Save.Press(); object[] persisted = PXTimeStampScope.GetPersisted(pe.Document.Cache, pe.Document.Current); if (persisted == null || persisted.Length == 0) { //preserve timestamp which will be @@dbts after last record committed to db on previous Persist(). //otherwise another process updated APAdjust. docs.Add(payment); } else { if (payment.Passed == true) { pe.Document.Current.Passed = true; } docs.Add(pe.Document.Current); } successed = true; } catch (PXException e) { PXProcessing <APPayment> .SetError(e); docs.Add(null); failed = true; } } if (Action == ReleaseChecksFilter.action.ReprintChecks || Action == ReleaseChecksFilter.action.VoidAndReprintChecks) { try { payment.IsPrintingProcess = true; using (PXTransactionScope transactionScope = new PXTransactionScope()) { #region Update CABatch if ReprintChecks CABatch caBatch = PXSelectJoin <CABatch, InnerJoin <CABatchDetail, On <CABatch.batchNbr, Equal <CABatchDetail.batchNbr> > >, Where <CABatchDetail.origModule, Equal <Required <APPayment.origModule> >, And <CABatchDetail.origDocType, Equal <Required <APPayment.docType> >, And <CABatchDetail.origRefNbr, Equal <Required <APPayment.refNbr> > > > > > . Select(be, payment.OrigModule, payment.DocType, payment.RefNbr); if (caBatch != null) { be.Document.Current = caBatch; int DetailCount = be.Details.Select().Count; // load CABatchDetail detail = be.Details.Locate(new CABatchDetail() { BatchNbr = be.Document.Current.BatchNbr, OrigModule = payment.OrigModule, OrigDocType = payment.DocType, OrigRefNbr = payment.RefNbr, OrigLineNbr = CABatchDetail.origLineNbr.DefaultValue, }); if (detail != null) { // payment.Status is recalculated in CABatchEntry.Delete if (DetailCount == 1) { be.Document.Delete(be.Document.Current); // Details will delete by PXParent } else { be.Details.Delete(detail); // recalculated batch totals } } be.Save.Press(); } else { PXCache cacheAPPayment = releaseChecksGraph.APPaymentList.Cache; cacheAPPayment.SetValueExt <APPayment.printed>(payment, false); cacheAPPayment.SetValueExt <APPayment.hold>(payment, false); cacheAPPayment.SetValueExt <APPayment.extRefNbr>(payment, null); // APPayment.Status is recalculated by SetStatusCheckAttribute cacheAPPayment.MarkUpdated(payment); cacheAPPayment.PersistUpdated(payment); cacheAPPayment.Persisted(false); } #endregion // TODO: Need to rework. Use legal CRUD methods of caches! releaseChecksGraph.TimeStamp = PXDatabase.SelectTimeStamp(); // delete check numbers only if Reprint (not Void and Reprint) PaymentMethod pm = pe.paymenttype.Select(payment.PaymentMethodID); if (pm.APPrintChecks == true && Action == ReleaseChecksFilter.action.ReprintChecks) { APPayment doc = payment; new HashSet <string>(pe.Adjustments_Raw.Select(doc.DocType, doc.RefNbr) .RowCast <APAdjust>() .Select(adj => adj.StubNbr)) .ForEach(nbr => PaymentRefAttribute.DeleteCheck((int)doc.CashAccountID, doc.PaymentMethodID, nbr)); // sync PaymentMethodAccount.APLastRefNbr with actual last CashAccountCheck number PaymentMethodAccount det = releaseChecksGraph.cashaccountdetail.SelectSingle(payment.CashAccountID, payment.PaymentMethodID); PaymentRefAttribute.LastCashAccountCheckSelect.Clear(releaseChecksGraph); CashAccountCheck cacheck = PaymentRefAttribute.LastCashAccountCheckSelect.SelectSingleBound(releaseChecksGraph, new object[] { det }); det.APLastRefNbr = cacheck?.CheckNbr; releaseChecksGraph.cashaccountdetail.Cache.PersistUpdated(det); releaseChecksGraph.cashaccountdetail.Cache.Persisted(false); } // END TODO if (string.IsNullOrEmpty(payment.ExtRefNbr)) { //try to get next number releaseChecksGraph.APPaymentList.Cache.SetDefaultExt <APPayment.extRefNbr>(payment); } transactionScope.Complete(); } } catch (PXException e) { PXProcessing <APPayment> .SetError(e); } docs.Add(null); } } if (successed) { APDocumentRelease.ReleaseDoc(docs, true); } if (failed) { throw new PXOperationCompletedWithErrorException(GL.Messages.DocumentsNotReleased); } }
protected void ViewCount() { if (pageid != null) { Guid currentwikipage = new Guid(pageid); PXGraph article = PXGraph.CreateInstance(typeof(KBArticleMaint)); PXCache responsesummary = article.Caches[typeof(KBResponseSummary)]; PXCache responses = article.Caches[typeof(KBResponse)]; PXResult <WikiPage, WikiPageLanguage, WikiRevision> result = (PXResult <WikiPage, WikiPageLanguage, WikiRevision>) PXSelectJoin <WikiPage, InnerJoin <WikiPageLanguage, On <WikiPageLanguage.pageID, Equal <WikiPage.pageID> >, InnerJoin <WikiRevision, On <WikiRevision.pageID, Equal <WikiPage.pageID> > > >, Where <WikiPage.pageID, Equal <Required <WikiPage.pageID> > > > .SelectWindowed(new PXGraph(), 0, 1, currentwikipage); Guid userId = PXAccess.GetUserID(); PXResult <KBResponseSummary> resultsummary = (PXResult <KBResponseSummary>) PXSelect <KBResponseSummary, Where <KBResponseSummary.pageID, Equal <Required <KBResponseSummary.pageID> > > > .SelectWindowed(article, 0, 1, currentwikipage); PXResult <KBResponse> resnonse = (PXResult <KBResponse>) PXSelect <KBResponse, Where <KBResponse.userID, Equal <Required <KBResponse.userID> >, And <KBResponse.pageID, Equal <Required <KBResponse.pageID> > > > > .SelectWindowed(article, 0, 1, userId, currentwikipage); if (result != null) { WikiPage wp = result[typeof(WikiPage)] as WikiPage; WikiPageLanguage wpl = result[typeof(WikiPageLanguage)] as WikiPageLanguage; KBResponseSummary kbrs = responsesummary.CreateInstance() as KBResponseSummary; KBResponse newresnonse = responses.CreateInstance() as KBResponse; if (resultsummary != null) { kbrs = resultsummary[typeof(KBResponseSummary)] as KBResponseSummary; } if (resnonse != null) { newresnonse = resnonse[typeof(KBResponse)] as KBResponse; } if (wp != null && wpl != null) { if (kbrs == null || kbrs.PageID == null) { kbrs.PageID = currentwikipage; kbrs.Views = 1; kbrs.Markcount = 0; kbrs.Marksummary = 0; kbrs.CreatedByID = wp.CreatedByID; kbrs.CreatedByScreenID = "WP00000"; kbrs.CreatedDateTime = wp.CreatedDateTime; kbrs.LastModifiedByID = wp.LastModifiedByID; kbrs.LastModifiedByScreenID = "WP00000"; kbrs.LastModifiedDateTime = wp.LastModifiedDateTime; kbrs.tstamp = wp.tstamp; responsesummary.Insert(kbrs); responsesummary.PersistInserted(kbrs); responsesummary.Clear(); } else { kbrs.Views++; responsesummary.Update(kbrs); responsesummary.PersistUpdated(kbrs); responsesummary.Clear(); } if (newresnonse == null || newresnonse.PageID == null) { newresnonse.PageID = currentwikipage; newresnonse.RevisionID = 1; newresnonse.OldMark = 0; newresnonse.NewMark = 0; newresnonse.Date = PXTimeZoneInfo.Now; newresnonse.UserID = userId; newresnonse.Summary = ""; newresnonse.CreatedByID = wp.CreatedByID; newresnonse.CreatedByScreenID = "WP00000"; newresnonse.CreatedDateTime = wp.CreatedDateTime; newresnonse.LastModifiedByID = wp.LastModifiedByID; newresnonse.LastModifiedByScreenID = "WP00000"; newresnonse.LastModifiedDateTime = wp.LastModifiedDateTime; newresnonse.tstamp = wp.tstamp; responses.Insert(newresnonse); responses.PersistInserted(newresnonse); responses.Clear(); } } } } }
protected void Rate_PageRate(object sender, EventArgs e) { Filltables(); Guid currentwikipage = new Guid(pageid); PXGraph article = PXGraph.CreateInstance(typeof(KBArticleMaint)); PXCache response = article.Caches[typeof(KBResponse)]; PXCache responsesummary = article.Caches[typeof(KBResponseSummary)]; PXResult <WikiPage, WikiPageLanguage, WikiRevision> result = (PXResult <WikiPage, WikiPageLanguage, WikiRevision>) PXSelectJoin <WikiPage, InnerJoin <WikiPageLanguage, On <WikiPageLanguage.pageID, Equal <WikiPage.pageID> >, InnerJoin <WikiRevision, On <WikiRevision.pageID, Equal <WikiPage.pageID> > > >, Where <WikiPage.pageID, Equal <Required <WikiPage.pageID> > >, OrderBy <Desc <WikiRevision.pageRevisionID> > > .SelectWindowed(new PXGraph(), 0, 1, currentwikipage); Guid userId = PXAccess.GetUserID(); PXResult <KBResponseSummary> resultsummary = (PXResult <KBResponseSummary>) PXSelect <KBResponseSummary, Where <KBResponseSummary.pageID, Equal <Required <KBResponseSummary.pageID> > > > .SelectWindowed(article, 0, 1, currentwikipage); PXResult <KBResponse> resnonse = (PXResult <KBResponse>) PXSelect <KBResponse, Where <KBResponse.userID, Equal <Required <KBResponse.userID> >, And <KBResponse.pageID, Equal <Required <KBResponse.pageID> > > > > .SelectWindowed(article, 0, 1, userId, currentwikipage); if (result != null) { WikiPage wp = result[typeof(WikiPage)] as WikiPage; WikiPageLanguage wpl = result[typeof(WikiPageLanguage)] as WikiPageLanguage; KBResponseSummary kbrs = responsesummary.CreateInstance() as KBResponseSummary; KBResponse newresnonse = response.CreateInstance() as KBResponse; if (resultsummary != null) { kbrs = resultsummary[typeof(KBResponseSummary)] as KBResponseSummary; } if (resnonse != null) { newresnonse = resnonse[typeof(KBResponse)] as KBResponse; if (wp != null && wpl != null && newresnonse.NewMark != null) { if (newresnonse.OldMark != 0) { kbrs.Marksummary = kbrs.Marksummary - newresnonse.OldMark; kbrs.Marksummary = kbrs.Marksummary + newresnonse.NewMark; } else { kbrs.Markcount = kbrs.Markcount + 1; kbrs.Marksummary = kbrs.Marksummary + newresnonse.NewMark; } int AvRate = (int)((int)kbrs.Marksummary / (int)kbrs.Markcount); Int32 Marksummary = (int)kbrs.Marksummary; Int32 Markcount = (int)kbrs.Markcount; double dAvRate = (double)Marksummary / (double)Markcount; kbrs.AvRate = dAvRate; responsesummary.Update(kbrs); responsesummary.PersistUpdated(kbrs); responsesummary.Clear(); newresnonse.PageID = currentwikipage; newresnonse.RevisionID = 1; newresnonse.OldMark = newresnonse.NewMark; newresnonse.Date = PXTimeZoneInfo.Now; newresnonse.Summary = ""; newresnonse.CreatedByID = wp.CreatedByID; newresnonse.CreatedByScreenID = "WP00000"; newresnonse.CreatedDateTime = wp.CreatedDateTime; newresnonse.LastModifiedByID = wp.LastModifiedByID; newresnonse.LastModifiedByScreenID = "WP00000"; newresnonse.LastModifiedDateTime = wp.LastModifiedDateTime; response.Update(newresnonse); response.PersistUpdated(newresnonse); response.Clear(); } } else { if (wp != null && wpl != null && newresnonse.NewMark != null) { newresnonse.PageID = currentwikipage; newresnonse.RevisionID = 1; newresnonse.OldMark = newresnonse.NewMark; newresnonse.Date = PXTimeZoneInfo.Now; newresnonse.UserID = userId; newresnonse.Summary = ""; newresnonse.CreatedByID = wp.CreatedByID; newresnonse.CreatedByScreenID = "WP00000"; newresnonse.CreatedDateTime = wp.CreatedDateTime; newresnonse.LastModifiedByID = wp.LastModifiedByID; newresnonse.LastModifiedByScreenID = "WP00000"; newresnonse.LastModifiedDateTime = wp.LastModifiedDateTime; if (kbrs == null || kbrs.PageID == null) { kbrs.PageID = currentwikipage; kbrs.CreatedByID = wp.CreatedByID; kbrs.CreatedByScreenID = "WP00000"; kbrs.CreatedDateTime = wp.CreatedDateTime; kbrs.LastModifiedByID = wp.LastModifiedByID; kbrs.LastModifiedByScreenID = "WP00000"; kbrs.LastModifiedDateTime = wp.LastModifiedDateTime; kbrs.Markcount = 1; kbrs.Marksummary = newresnonse.NewMark; int AvRate = (int)((int)kbrs.Marksummary / (int)kbrs.Markcount); Int32 Marksummary = (int)kbrs.Marksummary; Int32 Markcount = (int)kbrs.Markcount; double dAvRate = (double)Marksummary / (double)Markcount; kbrs.AvRate = dAvRate; responsesummary.Insert(kbrs); responsesummary.PersistInserted(kbrs); responsesummary.Clear(); } else { kbrs.Markcount = kbrs.Markcount + 1; kbrs.Marksummary = kbrs.Marksummary + newresnonse.NewMark; responsesummary.Update(kbrs); responsesummary.PersistUpdated(kbrs); responsesummary.Clear(); } response.Insert(newresnonse); response.PersistInserted(newresnonse); response.Clear(); } } string path = PXUrl.SiteUrlWithPath(); path += path.EndsWith("/") ? "" : "/"; var url = string.Format("{0}Wiki/{1}?pageid={2}", path, this.ResolveClientUrl("~/Wiki/ShowWiki.aspx"), pageid); url = url + "&rateid=" + Rate.Value; throw new Exception("Redirect0:" + url); } }
public virtual void RowPersisting(PXCache sender, PXRowPersistingEventArgs e) { object key = sender.GetValue(e.Row, _FieldOrdinal); PXCache cache = sender.Graph.Caches[typeof(CATran)]; CATran info = null; if (key != null) { //do not read cached record in release processes if ((info = PXSelectReadonly <CATran, Where <CATran.tranID, Equal <Required <CATran.tranID> > > > .Select(sender.Graph, key)) != null) { CATran cached = (CATran)cache.Locate(info); if (cached != null) { if ((cached.OrigModule != null && info.OrigModule != null && cached.OrigModule != info.OrigModule) || (cached.OrigRefNbr != null && info.OrigRefNbr != null && cached.OrigRefNbr != info.OrigRefNbr) || (cached.OrigTranType != null && info.OrigTranType != null && cached.OrigTranType != info.OrigTranType)) { // TO Be removed after solving CATran issue (check JIRA item AC-57875 for details) throw new PXException(Messages.CouldNotInsertCATran); } if (cache.GetStatus(cached) == PXEntryStatus.Notchanged) { PXCache <CATran> .RestoreCopy(cached, info); } info = cached; } else { cache.SetStatus(info, PXEntryStatus.Notchanged); } } if ((long)key < 0L && info == null) { info = new CATran(); info.TranID = (long)key; info = (CATran)cache.Locate(info); } if (info == null) { key = null; sender.SetValue(e.Row, _FieldOrdinal, null); } } if ((e.Operation & PXDBOperation.Command) == PXDBOperation.Delete) { if (info != null) { cache.Delete(info); cache.PersistDeleted(info); } } else if (info == null) { if (!this.NeedPreventCashTransactionCreation(sender, e.Row)) { info = DefaultValues(sender, new CATran(), e.Row); if (info != null) { info = (CATran)cache.Insert(info); if (!(info.TranID < 0L)) { throw new PXException(Messages.CouldNotInsertCATran); } // TO Be removed after solving CATran issue (check JIRA item AC-57875 for details) sender.SetValue(e.Row, _FieldOrdinal, info.TranID); _KeyToAbort = info.TranID; cache.PersistInserted(info); long id = info.TranID ?? 0; if (id == 0 || id < 0) { throw new PXException(Messages.CATranNotSaved, sender.GetItemType().Name); } sender.SetValue(e.Row, _FieldOrdinal, id); info.TranID = id; cache.Normalize(); } } } else if (info.TranID < 0L) { info = DefaultValues(sender, PXCache <CATran> .CreateCopy(info), e.Row); if (info != null) { info = (CATran)cache.Update(info); sender.SetValue(e.Row, _FieldOrdinal, info.TranID); _KeyToAbort = info.TranID; cache.PersistInserted(info); long id = info.TranID ?? 0; if (id == 0 || id < 0) { throw new PXException(Messages.CATranNotSaved, sender.GetItemType().Name); } sender.SetValue(e.Row, _FieldOrdinal, id); info.TranID = id; cache.Normalize(); } } else { CATran copy = PXCache <CATran> .CreateCopy(info); copy = DefaultValues(sender, copy, e.Row); if (copy != null) { if ((copy.OrigModule != null && info.OrigModule != null && copy.OrigModule != info.OrigModule) || (copy.OrigRefNbr != null && info.OrigRefNbr != null && copy.OrigRefNbr != info.OrigRefNbr) || (copy.OrigTranType != null && info.OrigTranType != null && copy.OrigTranType != info.OrigTranType)) { // TO Be removed after solving CATran issue (check JIRA item AC-57875 for details) throw new PXException(Messages.CouldNotInsertCATran); } info = (CATran)cache.Update(copy); //to avoid another process updated DefaultValues will return null for Released docs, except for GLTran cache.PersistUpdated(info); } //JournalEntry is usually persisted prior to ReleaseGraph to obtain BatchNbr reference, read info should contain set Released flag else if (info.Released == false) { key = null; sender.SetValue(e.Row, _FieldOrdinal, null); cache.Delete(info); } } foreach (CATran toDelete in cache.Deleted) { cache.PersistDeleted(toDelete); } }
protected virtual void ARInvoice_RowUpdated(PXCache sender, PXRowUpdatedEventArgs e) { sender.PersistUpdated(e.Row); }