Axapta : Job เช็ค Item Id 12 หลักและแปลงหลักสุดท้ายให้ถูก
- static void CheckItemId12(Args _args)
- {
- AsciiIO myFile;
- AsciiIO ItemFileConvert;
- AsciiIO ErrorFile;
- container RecData;
- container contTmp;
- ItemId myItemId;
- ItemId myItemIdConverted;
- int r = 1;
- int a,b,c,d,e,f,g,h,i,j,k,l;
- int a3,b3,c3,d3,e3,f3,g3,h3,i3,j3,k3,l3;
- int a4,b4,c4,d4,e4,f4,g4,h4,i4,j4,k4,l4;
- ;
- myFile=new AsciiIO("C:\\Item\\ItemCheckConvert.csv","r");
- myfile.inFieldDelimiter("|");
- while(myFile.status() == IO_Status::Ok)
- RecData += myFile.read();
- myFile = null;
- ItemFileConvert=new AsciiIO("C:\\Item\\ItemFileConvert.txt","a");
- ErrorFile=new AsciiIO("C:\\Item\\ErrorFile.txt","a");
- for(r=1; r <= conlen(RecData); r++){
- myItemId = conpeek(RecData, r);
- if(strlen(myItemId) == 12){
- a = str2int(substr(myItemId,1,1));
- b = str2int(substr(myItemId,2,1));
- c = str2int(substr(myItemId,3,1));
- d = str2int(substr(myItemId,4,1));
- e = str2int(substr(myItemId,5,1));
- f = str2int(substr(myItemId,6,1));
- g = str2int(substr(myItemId,7,1));
- h = str2int(substr(myItemId,8,1));
- i = str2int(substr(myItemId,9,1));
- j = str2int(substr(myItemId,10,1));
- k = str2int(substr(myItemId,11,1));
- l = str2int(substr(myItemId,12,1));
- a3 = (a * 2);
- b3 = b;
- c3 = (c * 2);
- d3 = d;
- e3 = (e * 2);
- f3 = f;
- g3 = (g * 2);
- h3 = h;
- i3 = (i * 2);
- j3 = j;
- k3 = (k * 2);
- a4 = (a3>9) ? str2int(substr(int2str(a3),1,1)) + str2int(substr(int2str(a3),2,1)) : a3;
- b4 = (b3>9) ? str2int(substr(int2str(b3),1,1)) + str2int(substr(int2str(b3),2,1)) : b3;
- c4 = (c3>9) ? str2int(substr(int2str(c3),1,1)) + str2int(substr(int2str(c3),2,1)) : c3;
- d4 = (d3>9) ? str2int(substr(int2str(d3),1,1)) + str2int(substr(int2str(d3),2,1)) : d3;
- e4 = (e3>9) ? str2int(substr(int2str(e3),1,1)) + str2int(substr(int2str(e3),2,1)) : e3;
- f4 = (f3>9) ? str2int(substr(int2str(f3),1,1)) + str2int(substr(int2str(f3),2,1)) : f3;
- g4 = (g3>9) ? str2int(substr(int2str(g3),1,1)) + str2int(substr(int2str(g3),2,1)) : g3;
- h4 = (h3>9) ? str2int(substr(int2str(h3),1,1)) + str2int(substr(int2str(h3),2,1)) : h3;
- i4 = (i3>9) ? str2int(substr(int2str(i3),1,1)) + str2int(substr(int2str(i3),2,1)) : i3;
- j4 = (j3>9) ? str2int(substr(int2str(j3),1,1)) + str2int(substr(int2str(j3),2,1)) : j3;
- k4 = (k3>9) ? str2int(substr(int2str(k3),1,1)) + str2int(substr(int2str(k3),2,1)) : k3;
- l4 = 10 -((a4 + b4 + c4 + d4 + e4 + f4 + g4 + h4 + i4 + j4 + k4) mod 10);
- l4 =( l4 == 10 ) ? 0 : l4;
- if(l4 != l){
- //Converted
- myItemIdConverted = strfmt("%1%2%3%4%5%6%7%8%9%10%11%12",a,b,c,d,e,f,g,h,i,j,k,l4);
- Print(strfmt("%1 : %2 \t Coverted", r, myItemid));
- ItemFileConvert.write(strfmt("%1|%2", myItemId, myItemIdConverted));
- } else {
- //Not Convert
- Print(strfmt("%1 : %2 \t Not Convert", r, myItemid));
- ItemFileConvert.write(strfmt("%1|%2", myItemId, myItemId));
- }//Close Else.
- } else {
- Print(strfmt("%1 : %2 \t Error", r, myItemid));
- ErrorFile.write(strfmt("%1",myItemId));
- }//Close Else.
- }//Close for.
- ItemFileConvert = null;
- ItemFileConvert = null;
- box::info("Complete","Converted");
- }
No comments:
Post a Comment