将 RefNbr 插入/发送到 Acumatica ERP 系统中的另一个数据库

Insert / Send RefNbr to another database in Acumatica ERP System

我已经在 Acumatica 屏幕的“支票和付款”屏幕中创建了一个付款并发布了它。请参考以下截图。

我已经创建了以下代码来提供它。

  protected virtual void APPayment_RowPersisted(PXCache sender, PXRowPersistedEventArgs e)
  {
      string serverJade, dbJade, userJade, passJade;
      serverJade = Properties.Settings.Default.serverJade;
      dbJade = Properties.Settings.Default.dbJade;
      userJade = Properties.Settings.Default.userJade;
      passJade = Properties.Settings.Default.passJade;


      APPayment app = (APPayment)e.Row;
      if (e.Operation == PXDBOperation.Update && e.TranStatus == PXTranStatus.Completed)
      {
          if (app.DocType == APPaymentType.Check || app.DocType == APPaymentType.Prepayment)
          {
              if (app.RefNbr != null)
              {

                  using (SqlConnection con = new SqlConnection("server = " + serverJade + "; database = " + dbJade + "; user = " + userJade + "; password = " + passJade + ""))
                  {
                      con.Open();
                      //---- query to update a field in the table of another database -------//
                      string query = "Update EVMaster set AcuRefNo = '" + app.RefNbr + "' where VchNo = 'DD02/16-VIII/12206-VCH-01'";
                      using (SqlCommand com = new SqlCommand(query, con))
                      {
                          SqlDataReader sdr = com.ExecuteReader();
                          sdr.Close();
                      }
                      con.Close();
                  }
              }
          }
      }
  }

我已经尝试调试此代码,但没有成功。然后我尝试使用下面的代码。

    protected virtual void APPayment_RowPersisted(PXCache sender, PXRowPersistedEventArgs e)
  {
      string serverJade, dbJade, userJade, passJade;
      serverJade = Properties.Settings.Default.serverJade;
      dbJade = Properties.Settings.Default.dbJade;
      userJade = Properties.Settings.Default.userJade;
      passJade = Properties.Settings.Default.passJade;


      APPayment app = (APPayment)e.Row;
          if (app.DocType == APPaymentType.Check || app.DocType == APPaymentType.Prepayment)
          {
              if (app.RefNbr != null)
              {

                  using (SqlConnection con = new SqlConnection("server = " + serverJade + "; database = " + dbJade + "; user = " + userJade + "; password = " + passJade + ""))
                  {
                      con.Open();
                      //---- query to update a field in the table of another database -------//
                      string query = "Update EVMaster set AcuRefNo = '" + app.RefNbr + "' where VchNo = 'DD02/16-VIII/12206-VCH-01'";
                      using (SqlCommand com = new SqlCommand(query, con))
                      {
                          SqlDataReader sdr = com.ExecuteReader();
                          sdr.Close();
                      }
                      con.Close();
                  }
              }
          }
  }

上面的代码是有效的,我只是删除了 if 条件 (if (e.Operation == PXDBOperation.Update && e.TranStatus == PXTranStatus.Completed) {}).

但这不是我的目标,我只需要从文档中过滤 Doc Status = 'printed' 的文档,单击 'Release' 按钮时将执行此过程。

还有知道如何获取当前文档的 APAdjust 中的所有记录吗?因为我需要根据 adjgrefnbr (apadjust) = refnbr (apinvoice) 比较 apadjust 中的 adjgrefnbr 和 APInvoice 中的 refnbr。因此,我还可以根据 refnbr (APinvoice) = ajgrefnbr (current apadjust) 获取 APinvoice 的所有记录。此条件用于使查询的 'where' 条件不必硬编码,我将使用变量来提供它。

有什么解决这个问题的建议吗?

下面的示例显示了如何扩展检查的发布过程并订阅 APRegister DAC 的 RowPersisted 处理程序以将发布的文档 RefNbr 保存到另一个数据库:

public class APPaymentEntryExt : PXGraphExtension<APPaymentEntry>
{
    public PXAction<APPayment> release;

    [PXUIField(DisplayName = "Release", MapEnableRights = PXCacheRights.Update, MapViewRights = PXCacheRights.Update)]
    [PXProcessButton]
    public IEnumerable Release(PXAdapter adapter)
    {
        PXGraph.InstanceCreated.AddHandler<APReleaseProcess>((graph) =>
        {
            graph.RowPersisted.AddHandler<APRegister>(APReleaseCheckProcess.APPaymentRowPersisted);
        });

        return Base.release.Press(adapter);
    }
}

public class APReleaseChecksExt : PXGraphExtension<APReleaseChecks>
{
    protected virtual void ReleaseChecksFilter_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
    {
        var row = e.Row as ReleaseChecksFilter;
        if (row == null) return;

        Base.APPaymentList.SetProcessDelegate(list =>
        {
            PXGraph.InstanceCreated.AddHandler<APReleaseProcess>((graph) =>
            {
                graph.RowPersisted.AddHandler<APRegister>(APReleaseCheckProcess.APPaymentRowPersisted);
            });

            APReleaseChecks.ReleasePayments(list, row.Action);
        });
    }
}

通过执行非常简单的 BQL 查询,您可以在 RowPersisted 事件的处理程序中访问与已发布检查关联的 APAdjust 记录:

public static class APReleaseCheckProcess
{
    public static void APPaymentRowPersisted(PXCache sender, PXRowPersistedEventArgs e)
    {
        if (e.TranStatus == PXTranStatus.Completed && e.Operation == PXDBOperation.Update)
        {
            var doc = e.Row as APPayment;
            if (doc != null && doc.Released == true)
            {
                // save RefNbr to another database

                foreach (APAdjust oldadj in PXSelect<APAdjust,
                    Where<
                        APAdjust.adjgDocType, Equal<Required<APPayment.docType>>,
                            And<APAdjust.adjgRefNbr, Equal<Required<APPayment.refNbr>>,
                            And<APAdjust.adjNbr, Less<Required<APPayment.lineCntr>>>>>>
                    .Select(sender.Graph, doc.DocType, doc.RefNbr, doc.LineCntr))
                {

                }
            }
        }
    }
}