重构使用单个存储过程的 eConnect 方法

发布于 2024-10-05 21:55:52 字数 1612 浏览 0 评论 0原文

我正在编写一个程序来使用 eConnect 修改 GP10 中的一些发票。一些发票需要重置分配,因为由于各种其他(对于这个问题并不重要)过程,总计没有正确加起来;这是通过该计划实现的。此外,大多数发票将被移动到不同的批次(如果您不熟悉 GP,请考虑桶),也使用此程序。

这两项任务都是通过 eConnect 处理相同类型的文件来完成的。这是处理该文件的方法:

public bool PersistAllChangesInDynamics()
    {
        //instantiate the proper eConnect object for updating the invoice.
        eConnectType eConnect = new eConnectType();
        SOPTransactionType transType = new SOPTransactionType();
        transType.taSopHdrIvcInsert = this.ConvertToSopHdrIvcInsertXml();
        //Adjust fields to reset distributions.
        transType.taSopHdrIvcInsert.UpdateExisting = 1;
        transType.taSopHdrIvcInsert.CREATEDIST = 1;

        SOPTransactionType[] updateInvTypeArray = { transType };
        eConnect.SOPTransactionType = updateInvTypeArray;

        //serialize and process the document.
        XmlDocument eConnectDoc = eConnectHelper.SerializeEConnectDoc(eConnect);
        return eConnectHelper.ProcessEConnectDoc(eConnectDoc);
    }

我的问题围绕着这段代码:

    transType.taSopHdrIvcInsert.UpdateExisting = 1; //updates the batch changes
    transType.taSopHdrIvcInsert.CREATEDIST = 1; //re-creates the distributions

taSopHdrIvcInsert 是 eConnect 提供的对象,用于保存对发票的任何更改。据我所知,没有一个对象只能重新创建发行版。每当我处理文档时,eConnect 都会在 Dynamics 数据库上调用一个类似名称的存储过程来正确保存这些更改。 UpdateExisting 和 CREATEDIST 是该 SP 的可选参数。

有时,我只需要更新批次(或发票的其他部分),或者只重新创建分配,但其他时候,我需要同时执行这两项操作。重新创建分配不会导致任何不需要的更改,您始终希望每张发票的分配都是正确的。我还没有测试过一次只做一件事是否能节省时间;由于该对象正在服务器端调用 SP,因此我看不出它会在哪里花费明显不同的时间。

你们中有人认为有任何理由将其重构为 2-3 种不同的方法,以将每个所需的功能分开吗?

I'm writing a program to modify some invoices in GP10 using eConnect. Some of the invoices require the distributions to be reset because the totals do not add up correctly due to various other (not important for this question) processes; this is accomplished through this program. Additionally, most of the invoices will be moved to a different batch (think buckets if you're not familiar with GP), also using this program.

Both of these tasks are accomplished by processing the same type of file through eConnect. This is the method that processes that file:

public bool PersistAllChangesInDynamics()
    {
        //instantiate the proper eConnect object for updating the invoice.
        eConnectType eConnect = new eConnectType();
        SOPTransactionType transType = new SOPTransactionType();
        transType.taSopHdrIvcInsert = this.ConvertToSopHdrIvcInsertXml();
        //Adjust fields to reset distributions.
        transType.taSopHdrIvcInsert.UpdateExisting = 1;
        transType.taSopHdrIvcInsert.CREATEDIST = 1;

        SOPTransactionType[] updateInvTypeArray = { transType };
        eConnect.SOPTransactionType = updateInvTypeArray;

        //serialize and process the document.
        XmlDocument eConnectDoc = eConnectHelper.SerializeEConnectDoc(eConnect);
        return eConnectHelper.ProcessEConnectDoc(eConnectDoc);
    }

My question revolves around this bit of code:

    transType.taSopHdrIvcInsert.UpdateExisting = 1; //updates the batch changes
    transType.taSopHdrIvcInsert.CREATEDIST = 1; //re-creates the distributions

The taSopHdrIvcInsert is the object provided by eConnect to persist any changes to invoices. As far as I'm aware, there isn't an object that ONLY re-creates distributions. Whenever I process the document, eConnect calls a similarly named stored procedure on the Dynamics db to save those changes correctly. UpdateExisting and CREATEDIST are optional parameters for that SP.

Sometimes, I will only need to update the batch (or other parts of the invoice), or only re-create distributions, but other times, I'll need to do both. Re-creating the distributions doesn't cause any undesirable changes, you always want to distributions to be correct for every invoice. I haven't tested for any time savings between doing just one thing at a time; since the object is calling a SP on the server side, I don't see where it would take significantly different amounts of time.

Do any of you see any reason to re-factor this into 2-3 different methods to keep each desired function separate?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心作怪 2024-10-12 21:55:52

如果您所做的只是更新一两个字段,并且您知道这不会妨碍任何 GP,那么只需通过 SQL 更新字段即可。我有许多方法调用 eConnect,然后在 eConnect 完成后直接更新对象,因为没有我必须更改的字段的 eConnect 参数。

If all you are doing is updating a field or two and you know that it will not get in the way of anything GP, just update the field(s) through SQL. I have many methods that call eConnect and then secondarily directly update the object after eConnect is done with it because there aren't eConnect parameters for the fields I must change.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文