Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to add multiple detail records to Timecard using XAPI and .Net 1

Status
Not open for further replies.

NAF7

Programmer
Jun 21, 2005
4
CA
A similar thread already exists: thread631-526541
In fact, I am the person who works on changing the code made by Dave to .Net.

Now, I have a question. I translated the code in that thread to C#, and this is what I got:

object oArray;
AccpacCOMAPI.AccpacView[] arArray;

AccpacCOMAPI.AccpacView CPTIMECARD1header = null;
AccpacCOMAPI.AccpacViewFields CPTIMECARD1headerFields;
mDBLinkCmpRW.OpenView("CP0031", out CPTIMECARD1header);
CPTIMECARD1headerFields = CPTIMECARD1header.Fields;
// ##
AccpacCOMAPI.AccpacView CPTIMECARD1detail = null;
AccpacCOMAPI.AccpacViewFields CPTIMECARD1detailFields;
mDBLinkCmpRW.OpenView("CP0032", out CPTIMECARD1detail);
CPTIMECARD1detailFields = CPTIMECARD1detail.Fields;
// ##
// added
arArray = new AccpacCOMAPI.AccpacView[] { CPTIMECARD1detail };
oArray = arArray;
CPTIMECARD1header.Compose(ref oArray);

arArray = new AccpacCOMAPI.AccpacView[] { CPTIMECARD1header };
oArray = arArray;
CPTIMECARD1detail.Compose(ref oArray);


AccpacCOMAPI.AccpacView CPEMASTER3header = null;
AccpacCOMAPI.AccpacViewFields CPEMASTER3headerFields;
mDBLinkCmpRW.OpenView("CP0014", out CPEMASTER3header);
CPEMASTER3headerFields = CPEMASTER3header.Fields;
// ##
AccpacCOMAPI.AccpacView CPEMASTER3detail1 = null;
AccpacCOMAPI.AccpacViewFields CPEMASTER3detail1Fields;
mDBLinkCmpRW.OpenView("CP0008", out CPEMASTER3detail1);
CPEMASTER3detail1Fields = CPEMASTER3detail1.Fields;
// ##
AccpacCOMAPI.AccpacView CPEMASTER3detail2 = null;
AccpacCOMAPI.AccpacViewFields CPEMASTER3detail2Fields;
mDBLinkCmpRW.OpenView("CP0010", out CPEMASTER3detail2);
CPEMASTER3detail2Fields = CPEMASTER3detail2.Fields;

AccpacCOMAPI.AccpacView CPEMASTER3detail3 = null;
AccpacCOMAPI.AccpacViewFields CPEMASTER3detail3Fields;
mDBLinkCmpRW.OpenView("CP0053", out CPEMASTER3detail3);
CPEMASTER3detail3Fields = CPEMASTER3detail3.Fields;
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

arArray = new AccpacCOMAPI.AccpacView[] { CPEMASTER3detail1, CPEMASTER3detail2, CPEMASTER3detail3 };
oArray = arArray;
CPEMASTER3header.Compose(ref oArray);

arArray = new AccpacCOMAPI.AccpacView[] { CPEMASTER3header };
oArray = arArray;
CPEMASTER3detail1.Compose(ref oArray);

arArray = new AccpacCOMAPI.AccpacView[] { CPEMASTER3header, null };
oArray = arArray;
CPEMASTER3detail2.Compose(ref oArray);

arArray = new AccpacCOMAPI.AccpacView[] { CPEMASTER3header };
oArray = arArray;
CPEMASTER3detail3.Compose(ref oArray);

// begins insert
CPTIMECARD1detail.Init();

object oValue = (object)"1";
CPTIMECARD1detailFields.get_FieldByName("ENTRYTYPE").set_Value(ref oValue); // Entry Type

// employee start
CPTIMECARD1detail.Order = 0;
oValue = (object)EmployeeID;
// FAILS HERE:------\/\/
CPTIMECARD1headerFields.get_FieldByName("EMPLOYEE").set_Value(ref oValue); // Employee
oValue = (object)timecard;
CPTIMECARD1headerFields.get_FieldByName("TIMECARD").set_Value(ref oValue);
oValue = (object)PeriodEnd;
CPTIMECARD1headerFields.get_FieldByName("PEREND").set_Value(ref oValue); // Period end date


CPTIMECARD1detail.Init();
CPTIMECARD1detail.Order = 0;

for (int i = 0; i <= ChargeType.Length; i++)
{
CPTIMECARD1detail.Init();
CPTIMECARD1detail.Init();

oValue = (object)ChargeType;
CPTIMECARD1detailFields.get_FieldByName("EARNDED").PutWithoutVerification(ref oValue); // Earnings/Deduction
oValue = (object)Amount;
CPTIMECARD1detailFields.get_FieldByName("RATE").set_Value(ref oValue); // E/D/Tax Rate/Amt/Percent

CPTIMECARD1detail.Insert();
}

CPTIMECARD1detail.Order = 0;
CPTIMECARD1header.Insert();


CPTIMECARD1header.Read();
// employee ends
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

CPTIMECARD1detail.Init();
CPTIMECARD1detail.Order = 0;
}



the place where it fails is marked. There is no error messahe or anthing, is simply crashes (well, OK, it sayd something like "..the COM component returned the error message: E_FAIL...", which obviously doesn not help.

Could someone point out any errors I have in my code?

Thanks a bunch.

 
You are missing a CPTIMECARD1header.Init();
When you have header and detail views composed you need to Init the header first and then the detail.
I have not worked with CP timecards, but I have done many UP timecards and I assume it is the same process.
Record a macro in Accpac while you enter a timecard, this will give you the correct sequence of events, which you then need to translate to C#.
 
Thanks for the quick reply.
I'll try adding the Init line. Compared the code to the original VB6, and well, that line is definitely missing in my .Net translation. Has to work now. Thanks, ettienne!

Heh, ever notice how it is always the easy things that mess up the programs? Oh, those missing braces in places where they shouldve been, or an omitted line that looks just like everything else...*sigh*

 
Eeek, a bit too quick with the judgement there, heheh.
Still no joy. just gives the same error :/
As for the macro, well, Im really not too sure where the timcard thing is located in AccPac, so...might take a while to figure out, heh.

And also, in the original VB6 code, the .Init line actually DOESNT exist. When I said it does, I just looked at the reply from the other post.
Can anyone see anything else wrong with that code up there?

Thanks in advance for any help.

 
Nevermind that. I found the error - I the Employee Id that I was passing just didnt exist in the AccPac database, so I changed that and it works.
Thanks for the try, ettienne

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top