private void MarkAsRead(PXGraph graph, CRSMEmail message) { EPView epview = PXSelect <EPView, Where <EPView.noteID, Equal <Required <CRSMEmail.noteID> >, And <EPView.userID, Equal <Required <CRSMEmail.ownerID> > > > > . Select(graph, message.NoteID, graph.Accessinfo.UserID); if (epview == null) { epview = new EPView { NoteID = message.NoteID, UserID = graph.Accessinfo.UserID, }; } else { epview = PXCache <EPView> .CreateCopy(epview); } if (epview.Status != EPViewStatusAttribute.VIEWED) { epview.Status = EPViewStatusAttribute.VIEWED; PXCache epviewCache = graph.Caches[typeof(EPView)]; epviewCache.Update(epview); } }
protected virtual void MarkAs(PXCache cache, CRActivity row, Guid UserID, int status) { if (IsImport || row.NoteID == null) { return; } var noteidType = typeof(TMaster).GetNestedType(typeof(CRActivity.noteID).Name); var ownerType = typeof(TMaster).GetNestedType(typeof(CRActivity.ownerID).Name); var select = BqlCommand.Compose( typeof(Select <,>), typeof(EPView), typeof(Where <, ,>), typeof(EPView.noteID), typeof(Equal <>), typeof(Required <>), noteidType, typeof(And <,>), typeof(EPView.userID), typeof(Equal <>), typeof(Required <>), ownerType ); EPView epview = (EPView) new PXView(this, false, BqlCommand.CreateInstance(select)).SelectSingle(row.NoteID, UserID); if (epview == null) { epview = new EPView { NoteID = row.NoteID, UserID = UserID, }; } else { epview = PXCache <EPView> .CreateCopy(epview); } if (status == EPViewStatusAttribute.VIEWED ? epview.Status != EPViewStatusAttribute.VIEWED : epview.Status == EPViewStatusAttribute.VIEWED) { epview.Status = status; EPViews.Update(epview); bool isDirty = false; foreach (PXCache c in Views.Caches.Where(t => t != typeof(EPView)).Select(t => Caches[t])) { isDirty = c.Inserted.ToArray <object>().Any() || c.Updated.ToArray <object>().Any() || c.Deleted.ToArray <object>().Any(); if (isDirty) { break; } } if (!isDirty) { using (PXTransactionScope ts = new PXTransactionScope()) { Persist(); ts.Complete(); } } EPViews.Cache.IsDirty = false; } }
protected virtual void MarkAs(PXCache cache, CRActivity row, Guid UserID, int status) { if (IsImport || row.NoteID == null) { return; } var epviewSelect = new SelectFrom <EPView> .Where <EPView.noteID.IsEqual <@P.AsGuid> .And <EPView.userID.IsEqual <@P.AsGuid> > > .View(this); EPView epview = epviewSelect .Select(row.NoteID, UserID) .FirstOrDefault(); bool dirty = EPViews.Cache.IsDirty; if (epview == null) { var epView = EPViews.Cache.Insert( new EPView { NoteID = row.NoteID, UserID = UserID, Status = status, } ); EPViews.Cache.PersistInserted(epView); epviewSelect.View.Clear(); EPViews.Cache.SetStatus(epView, PXEntryStatus.Notchanged); } else if (status != epview.Status) { epview.Status = status; EPViews.Cache.PersistUpdated(epview); } EPViews.Cache.IsDirty = dirty; }
private int RefreshTotal(string screenID, string viewName, out int read, out int unread) { read = -1; unread = -1; string actualScreenID = PXContext.GetScreenID(); using (new PXPreserveScope()) { try { PXContext.SetScreenID(screenID); PXGraph graph = CreateGraph(screenID); if (graph == null || graph.PrimaryView == null) { return(-1); } if (viewName == null) { viewName = graph.PrimaryView; } PXView view = graph.Views[viewName]; PXView viewFilters; PXFilterRow[] filters = null; if (graph.Views.TryGetValue(viewName + PXFilterableAttribute.FilterHeaderName, out viewFilters)) { foreach (FilterHeader fHeader in viewFilters.SelectMulti()) { if (fHeader.IsDefault == true) { int s = 0; int t = 0; IList f = graph.ExecuteSelect(viewName + PXFilterableAttribute.FilterRowName, new object[] { fHeader.FilterID }, null, null, null, new PXFilterRow[] { new PXFilterRow(typeof(FilterRow.isUsed).Name, PXCondition.EQ, true, null) }, ref s, 0, ref t) as IList; if (f != null && f.Count > 0) { filters = new PXFilterRow[f.Count]; PXCache frc = graph.Caches[typeof(FilterRow)]; for (int i = 0; i < f.Count; i++) { FilterRow r = (FilterRow)f[i]; var filter = new PXFilterRow(r.DataField, (PXCondition)r.Condition, frc.GetValueExt(r, "ValueSt"), frc.GetValueExt(r, "ValueSt2")); if (r.OpenBrackets != null) { filter.OpenBrackets = r.OpenBrackets.Value; } if (r.CloseBrackets != null) { filter.CloseBrackets = r.CloseBrackets.Value; } filter.OrOperator = r.Operator == 1; filters[i] = filter; } } break; } } } int start = 0; int total = 0; read = -1; unread = -1; using (var scope = new PXFieldScope(view, typeof(CRActivity.noteID), typeof(EPView.status))) foreach (object record in view.Select(null, null, null, null, null, filters, ref start, 101, ref total)) { PXResult result = record as PXResult; if (result != null) { EPView v = result.GetItem <EPView>(); if (v != null) { if (v.Status != null && v.Status == EPViewStatusAttribute.VIEWED) { read += 1; } else { unread += 1; } } } } if (read != -1 || unread != -1) { read += 1; unread += 1; } return(total); } finally { PXContext.SetScreenID(actualScreenID); } } }