public static PXAction GetSaveAction(this PXGraph graph) { PXAction saveAction = null; Type primary = !String.IsNullOrEmpty(graph.PrimaryView) ? graph.Views[graph.PrimaryView].GetItemType() : null; foreach (PXAction action in graph.Actions.Values) { PXButtonState state = action.GetState(null) as PXButtonState; if (state != null && state.SpecialType == PXSpecialButtonType.Save) { if (primary == null || state.ItemType == null || primary == state.ItemType || primary.IsSubclassOf(state.ItemType)) { saveAction = action; break; } } } if (saveAction == null) { throw new PXException("There is not a Save action in the graph " + graph.GetType()); } return(saveAction); }
public static PXAction GetDeleteAction(this PXGraph graph) { PXAction deleteAction = null; Type primary = !String.IsNullOrEmpty(graph.PrimaryView) ? graph.Views[graph.PrimaryView].GetItemType() : null; foreach (PXAction action in graph.Actions.Values) { PXButtonState state = action.GetState(null) as PXButtonState; if (state != null && state.SpecialType == PXSpecialButtonType.Delete) { if (primary == null || state.ItemType == null || primary == state.ItemType || primary.IsSubclassOf(state.ItemType)) { deleteAction = action; break; } } } if (deleteAction == null || deleteAction.GetEnabled() == false) { throw new PXException(TX.Error.APPOINTMENT_NOT_DELETABLE); } return(deleteAction); }
public static void EnableDisableActionsByWorkflowStage(PXCache cache, FSWFStage fsWFStageRow, PXAction actionComplete, PXAction actionCancel, PXAction actionClose, PXAction actionReopen) { if (fsWFStageRow == null) { return; } if (fsWFStageRow.AllowComplete == false) { actionComplete?.SetEnabled(fsWFStageRow.AllowComplete.Value); } if (fsWFStageRow.AllowCancel == false) { actionCancel?.SetEnabled(fsWFStageRow.AllowCancel.Value); } if (fsWFStageRow.AllowClose == false) { actionClose?.SetEnabled(fsWFStageRow.AllowClose.Value); } if (fsWFStageRow.AllowReopen == false) { actionReopen?.SetEnabled(fsWFStageRow.AllowReopen.Value); } cache.AllowDelete &= (bool)fsWFStageRow.AllowDelete; }
private void AddAvailableAction(PXAction action, string shortcut, List <string> actions, List <string> actionNames, object row) { PXButtonState state = action.GetState(row) as PXButtonState; if (state == null || !state.Enabled) { return; } actions.Add(shortcut); actionNames.Add(state.DisplayName); }
public override void Initialize() { base.Initialize(); if (Base.GetType() != typeof(PXGraph) && Base.PrimaryItemType != null) { PXAction runAction = PXNamedAction.AddAction(Base, Base.PrimaryItemType, nameof(ConsoleRunAction), "Run", new PXButtonDelegate(ConsoleRunAction)); PXAction clearOutputAction = PXNamedAction.AddAction(Base, Base.PrimaryItemType, nameof(ConsoleClearOutputAction), "ConsoleClearOutput", new PXButtonDelegate(ConsoleClearOutputAction)); ConsoleView.Cache.SetValueExt <ConsoleFields.graphType>(ConsoleView.Current, PX.Api.CustomizedTypeManager.GetTypeNotCustomized(Base).FullName); //For code completion on Graph. } }
public override void Initialize() { base.Initialize(); RetainageOptions releaseRetainageOptions = ReleaseRetainageOptions.Current; PXAction action = Base.Actions["action"]; if (action != null) { action.AddMenuAction(releaseRetainage); } }
public override void Initialize() { base.Initialize(); if (!string.IsNullOrEmpty(Base.PrimaryView)) { Type primaryViewType = Base.Views[Base.PrimaryView].Cache.GetItemType(); PXAction updateInsight = PXNamedAction.AddAction(Base, primaryViewType, "Update Insight", "Update Insight", UpdateInsight); updateInsight.SetEnabled(false); updateInsight.SetVisible(false); } }
public override void Initialize() { if (!String.IsNullOrEmpty(Base.PrimaryView)) { //Add a "Test" button in the toolbar Type primaryViewItemType = Base.Views[Base.PrimaryView].Cache.GetItemType(); PXAction action = PXNamedAction.AddAction(Base, primaryViewItemType, "GlobalTest", "Global Button", TestClick); //Liste to FieldUpdating event for NoteText on primary view; we could also do it on every view that has a Note field. PXCache primaryViewCache = Base.Caches[primaryViewItemType]; if (primaryViewCache.Fields.Contains("NoteText")) { Base.FieldUpdating.AddHandler(Base.PrimaryView, "NoteText", NoteFieldUpdating); } } }
public static void EnableDisableActionsByWorkflowStage( PXCache cache, FSWFStage fsWFStageRow, PXAction actionComplete, PXAction actionCancel, PXAction actionClose, PXAction actionReopen) { if (fsWFStageRow == null) { return; } if (fsWFStageRow == null) { return; } if (actionComplete != null && fsWFStageRow.AllowComplete == false) { actionComplete.SetEnabled(false); } if (actionCancel != null && fsWFStageRow.AllowCancel == false) { actionCancel.SetEnabled(false); } if (actionClose != null && fsWFStageRow.AllowClose == false) { actionClose.SetEnabled(false); } if (actionReopen != null && fsWFStageRow.AllowReopen == false) { actionReopen.SetEnabled(false); } cache.AllowUpdate &= (bool)fsWFStageRow.AllowModify; cache.AllowDelete &= (bool)fsWFStageRow.AllowDelete; }
public static void ReverseGLVoucher(PXGraph graph, PXAction actionSave, Action baseReverse, PXCache voucherBatchView) { GLWorkBook wb = PXSelect <GLWorkBook, Where <GLWorkBook.workBookID, Equal <Required <GLVoucherBatch.workBookID> > > > .Select(graph, graph.GetContextValue <GLVoucherBatch.workBookID>()); if (wb?.ReversingWorkBookID == null) { throw new PXException(Messages.ReversingWorkbookIDisnotDefined); } GLWorkBook reversingWB = PXSelect <GLWorkBook, Where <GLWorkBook.workBookID, Equal <Required <GLVoucherBatch.workBookID> >, And <GLWorkBook.status, Equal <WorkBookStatus.active> > > > .Select(graph, wb.ReversingWorkBookID); if (reversingWB == null) { throw new PXException(Messages.ReversingWorkbookIDisnotFound); } GLVoucherBatch vb = PXSelect <GLVoucherBatch, Where <GLVoucherBatch.workBookID, Equal <Required <GLWorkBook.workBookID> >, And <GLVoucherBatch.released, Equal <False> > >, OrderBy <Asc <GLVoucherBatch.voucherBatchNbr> > > .Select(graph, reversingWB.WorkBookID); if (vb == null) { var batch = new GLVoucherBatch { WorkBookID = reversingWB.WorkBookID, Descr = Messages.ReversingVoucherBatchDesc }; vb = (GLVoucherBatch)voucherBatchView.Insert(batch); voucherBatchView.Current = batch; actionSave.Press(); } graph.contextValues[typeof(GLVoucherBatch.workBookID).FullName] = reversingWB.WorkBookID; graph.contextValues[typeof(GLVoucherBatch.voucherBatchNbr).FullName] = vb.VoucherBatchNbr; baseReverse.Invoke(); throw new PXRedirectWithinContextException(graph, graph, Messages.VoucherEdit, typeof(GLVoucherBatch.workBookID), typeof(GLVoucherBatch.voucherBatchNbr)); }
private static void ProcessValidation(ValidationFilter Filter, Contact record) { PXPrimaryGraphCollection primaryGraph = new PXPrimaryGraphCollection(new PXGraph()); PXGraph graph = primaryGraph[record]; if (graph == null) { throw new PXException(Messages.UnableToFindGraph); } PXView view = graph.Views[graph.PrimaryView]; int startRow = 0, totalRows = 0; List <object> list_contact = view.Select(null, null, new object[] { record.ContactID }, new string[] { typeof(Contact.contactID).Name }, null, null, ref startRow, 1, ref totalRows); if (list_contact == null || list_contact.Count < 1) { throw new PXException(Messages.ContactNotFound); } Contact contact = PXResult.Unwrap <Contact>(list_contact[0]); contact.DuplicateFound = true; //Find duplicates view PXView viewDuplicates = graph.Views.ToArray().First(v => v.Value.Cache.GetItemType() == typeof(CRDuplicateRecord)).Value; if (viewDuplicates == null) { throw new PXException(Messages.DuplicateViewNotFound); } viewDuplicates.Clear(); List <object> duplicates = viewDuplicates.SelectMulti(); contact = (Contact)view.Cache.CreateCopy(contact); string prevStatus = contact.DuplicateStatus; contact.DuplicateStatus = DuplicateStatusAttribute.Validated; Decimal?score = 0; contact.DuplicateFound = duplicates.Count > 0; foreach (PXResult <CRDuplicateRecord, Contact, Contact2> r in duplicates) { Contact2 duplicate = r; CRDuplicateRecord contactScore = r; int duplicateWeight = ContactMaint.GetContactWeight(duplicate); int currentWeight = ContactMaint.GetContactWeight(contact); if (duplicateWeight > currentWeight || (duplicateWeight == currentWeight && duplicate.ContactID < contact.ContactID)) { contact.DuplicateStatus = DuplicateStatusAttribute.PossibleDuplicated; if (contactScore.Score > score) { score = contactScore.Score; } } } view.Cache.Update(contact); if (contact.DuplicateStatus == DuplicateStatusAttribute.PossibleDuplicated && contact.ContactType == ContactTypesAttribute.Lead && contact.Status == LeadStatusesAttribute.New && Filter.CloseNoActivityLeads == true && score > Filter.CloseThreshold) { CRActivity activity = PXSelect <CRActivity, Where <CRActivity.contactID, Equal <Required <Contact.contactID> > > > .SelectWindowed(graph, 0, 1, contact.ContactID); if (activity == null) { PXAction action = graph.Actions["Action"]; PXAdapter adapter = new PXAdapter(view); adapter.StartRow = 0; adapter.MaximumRows = 1; adapter.Searches = new object[] { contact.ContactID }; adapter.Menu = Messages.CloseAsDuplicate; adapter.SortColumns = new[] { typeof(Contact.contactID).Name }; foreach (Contact c in action.Press(adapter)) { ; } prevStatus = null; } } view.Cache.RestoreCopy(record, view.Cache.Current); if (prevStatus != contact.DuplicateStatus) { graph.Actions.PressSave(); } }
void RenderGraph(string id) { DivGraph.Visible = true; HeaderGraph.InnerText = "Graph" + id + " members"; HtmlTableBuilder viewsBuilder = new HtmlTableBuilder(); viewsBuilder.Table = TableGraphViews; Type t = ServiceManager.GetGraphType(id); PXGraph g; try { g = (PXGraph)PXGraph.CreateInstance(t); } catch { if (this.Context.User.Identity.IsAuthenticated) { throw; } PX.Export.Authentication.FormsAuthenticationModule.RedirectToLoginPage(); return; } #region views MemberInfo[] views = ServiceManager.GetViews(t); foreach (FieldInfo view in views) { viewsBuilder.AddRow(); viewsBuilder.AddCell("View" + view.Name); PXView v = g.Views[view.Name]; Type[] items = v.GetItemTypes(); viewsBuilder.AddCell(null); foreach (Type row in items) { try { string apiName = ServiceManager.GetTableNameFromType(row); HyperLink h = new HyperLink(); h.NavigateUrl = GetUrl("row", apiName); h.Text = "[" + apiName + "]"; viewsBuilder.Cell.Controls.Add(h); continue; } catch { } HyperLink hyperLink = new HyperLink(); hyperLink.Text = row.Name; viewsBuilder.Cell.Controls.Add(hyperLink); } string strParams = ""; List <PXViewParameter> pinfo = v.EnumParameters(); List <string> list = new List <string>(); foreach (PXViewParameter p in pinfo) { string opt = ""; string type = GetParamTypeName(g, p); if (p.Bql != null && p.Bql.HasDefault) { opt = "opt "; } list.Add(String.Format("{0}{1} {2}", opt, type, p.Name)); } //var parameters = v.GetParameterNames(); if (pinfo.Count > 0) { strParams = "(" + String.Join(", ", list.ToArray()) + ")"; } viewsBuilder.AddCell(strParams); } #endregion #region actions HtmlTableBuilder actionsBuilder = new HtmlTableBuilder(); actionsBuilder.Table = TableGraphActions; string[] actions = ServiceManager.GetActions(t); foreach (string action in actions) { actionsBuilder.AddRow(); actionsBuilder.AddCell("Action" + action); PXAction a = g.Actions[action]; Type r = a.GetRowType(); string table = ServiceManager.GetTableNameFromType(r); actionsBuilder.AddCell(table); } #endregion }
public virtual IEnumerable Action( PXAdapter adapter, [PXInt] [PXIntList(new int[] { 1, 2, 3, 4, 5 }, new string[] { "Create Shipment", "Apply Assignment Rules", "Create Invoice", "Post Invoice to IN", "Create Purchase Order" })] int?actionID, [PXDate] DateTime?shipDate, [PXSelector(typeof(INSite.siteCD))] string siteCD, [SOOperation.List] string operation, [PXString()] string ActionName, Func <PXAdapter, int?, DateTime?, string, string, string, IEnumerable> baseMtd) { switch (actionID) { case 1: { if (!string.IsNullOrEmpty(ActionName)) { PXAction action = Base.Actions[ActionName]; if (action != null) { Base.Save.Press(); List <object> result = new List <object>(); foreach (object data in action.Press(adapter)) { result.Add(data); } return(result); } } List <SOOrder> list = new List <SOOrder>(); foreach (SOOrder order in adapter.Get <SOOrder>()) { list.Add(order); } if (shipDate != null) { Base.soparamfilter.Current.ShipDate = shipDate; } if (Base.soparamfilter.Current.ShipDate == null) { Base.soparamfilter.Current.ShipDate = Base.Accessinfo.BusinessDate; } if (siteCD != null) { Base.soparamfilter.Cache.SetValueExt <SOParamFilter.siteID>(Base.soparamfilter.Current, siteCD); } if (!adapter.MassProcess) { if (Base.soparamfilter.Current.SiteID == null) { Base.soparamfilter.Current.SiteID = GetPreferedSiteID(); } if (adapter.ExternalCall) { Base.soparamfilter.AskExt(true); } } if (Base.soparamfilter.Current.SiteID != null || adapter.MassProcess) { try { Base.RecalculateExternalTaxesSync = true; Base.Save.Press(); } finally { Base.RecalculateExternalTaxesSync = false; } PXAutomation.RemovePersisted(Base, typeof(SOOrder), new List <object>(list)); SOParamFilter filter = Base.soparamfilter.Current; PXLongOperation.StartOperation(Base, delegate() { bool anyfailed = false; SOShipmentEntry docgraph = PXGraph.CreateInstance <SOShipmentEntry>(); SOOrderEntry ordgraph = PXGraph.CreateInstance <SOOrderEntry>(); DocumentList <SOShipment> created = new DocumentList <SOShipment>(docgraph); //address AC-92776 for (int i = 0; i < list.Count; i++) { SOOrder order = list[i]; if (adapter.MassProcess) { PXProcessing <SOOrder> .SetCurrentItem(order); } SOOrder ordercopy = (SOOrder)Base.Caches[typeof(SOOrder)].CreateCopy(order); try { if (operation == SOOperation.Issue) { ReviewWarehouseAvailability(ordgraph, order); } } catch (SOShipmentException ex) { Base.Caches[typeof(SOOrder)].RestoreCopy(order, ordercopy); if (!adapter.MassProcess) { throw; } order.LastShipDate = filter.ShipDate; order.Status = SOOrderStatus.Shipping; //Automation will set the order to back order since no shipments were created docgraph.Clear(); var ordergraph = PXGraph.CreateInstance <SOOrderEntry>(); ordergraph.Clear(); ordergraph.Document.Cache.MarkUpdated(order); PXAutomation.CompleteSimple(ordergraph.Document.View); try { ordergraph.Save.Press(); PXAutomation.RemovePersisted(ordergraph, order); PXTrace.WriteInformation(ex); PXProcessing <SOOrder> .SetWarning(ex); } catch (Exception inner) { Base.Caches[typeof(SOOrder)].RestoreCopy(order, ordercopy); PXProcessing <SOOrder> .SetError(inner); anyfailed = true; } continue; //Stop there for this order } catch (Exception ex) { if (!adapter.MassProcess) { throw; } PXProcessing <SOOrder> .SetError(ex); anyfailed = true; continue; } List <int?> sites = new List <int?>(); if (filter.SiteID != null) { sites.Add(filter.SiteID); } else { foreach (SOShipmentPlan plan in PXSelectGroupBy <SOShipmentPlan, Where <SOShipmentPlan.orderType, Equal <Current <SOOrder.orderType> >, And <SOShipmentPlan.orderNbr, Equal <Current <SOOrder.orderNbr> > > >, Aggregate <GroupBy <SOShipmentPlan.siteID> >, OrderBy <Asc <SOShipmentPlan.siteID> > > .SelectMultiBound(docgraph, new object[] { order })) { sites.Add(plan.SiteID); } } foreach (int?SiteID in sites) { ordercopy = (SOOrder)Base.Caches[typeof(SOOrder)].CreateCopy(order); try { using (var ts = new PXTransactionScope()) { PXTimeStampScope.SetRecordComesFirst(typeof(SOOrder), true); docgraph.CreateShipment(order, SiteID, filter.ShipDate, adapter.MassProcess, operation, created, adapter.QuickProcessFlow); ts.Complete(); } if (adapter.MassProcess) { PXProcessing <SOOrder> .SetProcessed(); } } catch (SOShipmentException ex) { Base.Caches[typeof(SOOrder)].RestoreCopy(order, ordercopy); if (!adapter.MassProcess) { throw; } order.LastSiteID = SiteID; order.LastShipDate = filter.ShipDate; order.Status = SOOrderStatus.Shipping; docgraph.Clear(); var ordergraph = PXGraph.CreateInstance <SOOrderEntry>(); ordergraph.Clear(); ordergraph.Document.Cache.MarkUpdated(order); PXAutomation.CompleteSimple(ordergraph.Document.View); try { ordergraph.Save.Press(); PXAutomation.RemovePersisted(ordergraph, order); PXTrace.WriteInformation(ex); PXProcessing <SOOrder> .SetWarning(ex); } catch (Exception inner) { Base.Caches[typeof(SOOrder)].RestoreCopy(order, ordercopy); PXProcessing <SOOrder> .SetError(inner); anyfailed = true; } } catch (Exception ex) { Base.Caches[typeof(SOOrder)].RestoreCopy(order, ordercopy); docgraph.Clear(); if (!adapter.MassProcess) { throw; } PXProcessing <SOOrder> .SetError(ex); anyfailed = true; } } } if (adapter.AllowRedirect && !adapter.MassProcess && created.Count > 0) { using (new PXTimeStampScope(null)) { docgraph.Clear(); docgraph.Document.Current = docgraph.Document.Search <SOShipment.shipmentNbr>(created[0].ShipmentNbr); throw new PXRedirectRequiredException(docgraph, "Shipment"); } } if (anyfailed) { throw new PXOperationCompletedWithErrorException(ErrorMessages.SeveralItemsFailed); } }); } return(list); } default: return(baseMtd(adapter, actionID, shipDate, siteCD, operation, ActionName)); } }