English 中文(简体)
Refactoring an eConnect method that uses a single stored procedure
原标题:

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?

问题回答

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.





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签