private void RedirectToBatch(GLVoucherBatch batch, GLVoucher voucher = null) { if (batch != null) { GLWorkBook wb = PXSelect <GLWorkBook, Where <GLWorkBook.workBookID, Equal <Required <GLWorkBook.workBookID> > > > .Select(this, batch.WorkBookID); if (wb == null || wb.VoucherEditScreen == null) { throw new PXException(Messages.GLWorkBookIsInvalidOrVoucherEditScreenIsNotConfiguredForIt, batch.WorkBookID); } PXGraph target = null; PXSiteMapNode sm = PXSiteMap.Provider.FindSiteMapNodeFromKey((Guid)wb.VoucherEditScreen); if (sm == null) { throw new PXException(Messages.CannotFindSitemapNode); } Type graphType = System.Web.Compilation.BuildManager.GetType(sm.GraphType, true); Type parentGraphType = GLWorkBookMaint.GetGraphByDocType(batch.Module, wb.DocType); if (parentGraphType != null && parentGraphType.IsAssignableFrom(graphType)) { target = PXGraph.CreateInstance(graphType); } else { throw new PXException(Messages.GLVoucherEditGraphMayNotBeAssignedToTheBasedDocumentGraph, graphType, parentGraphType); } if (voucher == null) { voucher = PXSelect <GLVoucher, Where <GLVoucher.workBookID, Equal <Required <GLVoucher.workBookID> >, And <GLVoucher.voucherBatchNbr, Equal <Required <GLVoucher.voucherBatchNbr> > > >, OrderBy <Desc <GLVoucher.refNbr> > > .Select(this, batch.WorkBookID, batch.VoucherBatchNbr); } else { voucher = PXSelect <GLVoucher, Where <GLVoucher.workBookID, Equal <Required <GLVoucher.workBookID> >, And <GLVoucher.voucherBatchNbr, Equal <Required <GLVoucher.voucherBatchNbr> >, And <GLVoucher.refNbr, Equal <Required <GLVoucher.refNbr> > > > >, OrderBy <Desc <GLVoucher.refNbr> > > .Select(this, batch.WorkBookID, batch.VoucherBatchNbr, voucher.RefNbr); } SetVoucherAsCurrent(target, voucher); throw new PXRedirectWithinContextException(this, target, Messages.VoucherEdit, typeof(GLVoucherBatch.workBookID), typeof(GLVoucherBatch.voucherBatchNbr)); } }
public void DeleteBatchProc(GLVoucherBatch aBatch, Dictionary <string, Dictionary <Guid, CAMessage> > errorList) { this.Clear(); this.Document.Current = aBatch; Dictionary <Guid, CAMessage> errorLog = null; if (!errorList.ContainsKey(aBatch.VoucherBatchNbr)) { errorList.Add(aBatch.VoucherBatchNbr, new Dictionary <Guid, CAMessage>()); } errorLog = errorList[aBatch.VoucherBatchNbr]; try { using (PXTransactionScope ts = new PXTransactionScope()) { List <Guid> failed = new List <Guid>(); Dictionary <string, List <GLVoucher> > processQueue = new Dictionary <string, List <GLVoucher> >(); foreach (GLVoucher voucher in Details.Select()) { if (!processQueue.ContainsKey(voucher.Module + voucher.DocType)) { processQueue.Add(voucher.Module + voucher.DocType, new List <GLVoucher>()); } processQueue[voucher.Module + voucher.DocType].Add(voucher); } foreach (KeyValuePair <string, List <GLVoucher> > pair in processQueue) { string module = pair.Value[0].Module; string docType = pair.Value[0].DocType; Type graphType = GLWorkBookMaint.GetGraphByDocType(module, docType); if (graphType == null) { throw new PXException(GL.Messages.ModuleDocTypeIsNotSupported, module, docType); } PXGraph deletegraph = PXGraph.CreateInstance(graphType); if (!(deletegraph is IVoucherEntry)) { throw new PXException(GL.Messages.ModuleDocTypeIsNotSupported, module, docType); } foreach (GLVoucher voucher in pair.Value) { Guid key = voucher.RefNoteID.Value; try { deletegraph.Clear(); GLVoucherBatchEntry.SetVoucherAsCurrent(this, deletegraph, voucher); (deletegraph as IVoucherEntry).DeleteButton.Press(); } catch (Exception ex) { failed.Add(key); errorLog.Add(key, FormatError(ex)); throw new PXException(Messages.DeletingFailed); } } } this.Document.Delete(aBatch); this.Save.Press(); ts.Complete(this); } } catch (PXException ex) { errorLog.Add(Guid.Empty, FormatError(ex)); throw ex; } }