D365 CSV导入
class KKC_ImportTestData extends RunBase { str gMessage; str fileUrl; FileName gFileName; Dialog dialog; DialogField gDialogFile; public Object dialog() { FormBuildButtonControl buttonControl; DialogGroup dlgGroup; FormBuildGroupControl buttonGroup; ; dialog = super(); dlgGroup = dialog.addGroup(''); buttonGroup = dialog.formBuildDesign().control(dlgGroup.formBuildGroup().id()); buttonControl = buttonGroup.addControl(FormControlType::Button, 'Upload'); buttonControl.text("@KKC00160"); buttonControl.registerOverrideMethod(methodStr(FormButtonControl, clicked), methodStr(KKC_ImportTestData, uploadClickedEvent), this); return dialog; } private void uploadClickedEvent(FormButtonControl _formButtonControl) { FileUploadTemporaryStorageResult result = File::GetFileFromUser() as FileUploadTemporaryStorageResult; if (result && result.getUploadStatus()) { result.getFileContentType(); fileUrl = result.getDownloadUrl(); } } public static KKC_ImportTestData construct() { return new KKC_ImportTestData(); } public static void main(Args _args) { KKC_ImportTestData testData = KKC_ImportTestData::construct(); if (testData.prompt()) { testData.run(); } } public void run() { KKC_IFPostDataTable postDataTable; KKC_PostingStatus postingStatus; KKC_TransType transType; KKC_Partner partner; container conFields; CommaTextStreamIo localStream; int i, first; #File ; localStream = CommaTextStreamIo::constructForRead(File::UseFileFromURL(fileUrl)); if (localStream.status() == IO_Status::Ok) { localStream.inFieldDelimiter("\,"); localStream.inRecordDelimiter(#delimiterCRLF); conFields = localStream.read(); if (first == 0) { conFields = localStream.read(); first++; } if (conFields != conNull()) { while(conFields) { postDataTable.clear(); postDataTable.PurchId = conPeek(conFields, 1); postDataTable.TransType = str2Enum(transType, conPeek(conFields, 2)); postDataTable.Partner = conPeek(conFields, 3); postDataTable.Quantity = str2Num(conPeek(conFields, 4)); postDataTable.InventBatchExpDate = str2Date(conPeek(conFields, 5), DateSeparator::Slash); postDataTable.insert(); conFields = localStream.read(); } } } } public static Container textIO2Con(FilePath _filePath, boolean _includeTitle = false, str _fieldDelimiter = '\t', str _recordDelimiter = '\r\n') { TextIo textIO; container conFile, conLine; int i, j; #File ; textIO = new textIO(_filePath, "r"); textIO.inFieldDelimiter(_fieldDelimiter);//#delimiterTab); textIO.inRecordDelimiter(_recordDelimiter);//#delimiterCRLF); conFile = conNull(); while (textIO.status() == IO_Status::Ok) { i++; conLine = textIO.read(); if (!_includeTitle && i == 1) { continue; } if (conLine != conNull()) { j++; conFile = conIns(conFile, j, conLine); } } return conFile; } }