zoukankan      html  css  js  c++  java
  • Dynamic 365中读取CSV文件

     

     

     

    Dynamic 365开发中对于读取CSV文件与2012略有不同。Dynamic 365中,对于文件的处理是先上传,后下载的过程。需要通过FileUpload control Upload strategy class FileUploadTemporaryStorageStrategy类来实现对于文件的读取和下载。

    以下是一个简单的例子可供参考:

    Dilaog窗体,读取文件上传到本地服务器中,以URL方式可以查看

     

     Public Object dialog()
        {
            DialogGroup      dialogGroup;
            FormBuildControl formBuildControl;
            FileUploadBuild  dialogFileUpload;
            #file
            ;
           
            dialog = super();
            dialogGroup = dialog.addGroup("File path");
            formBuildControl = dialog.formBuildDesign().control(dialogGroup.name());
            dialogFileUpload = formBuildControl.addControlEx(classstr(FileUpload), "dialogFileUpload");
            dialogFileUpload.style(FileUploadStyle::MinimalWithFilename);
            dialogFileUpload.baseFileUploadStrategyClassName(classstr(FileUploadTemporaryStorageStrategy));
            dialogFileUpload.fileTypesAccepted(".csv");
            dialogFileUpload.fileNameLabel("Select a file to upload");
           
            return dialog;
        }

     

    得到控件名:

       protected FormControl getFormControl(DialogRunbase _dialog, str _controlName)
         {
              return _dialog.formRun().control(_dialog.formRun().controlId( _controlName));
         }

    获取文件:

    public boolean getFromDialog(  
        {
            boolean ret;
            ;
            ret = super();
            FileUpload     fileupload;
            fileupload  =   this.getFormControl(dialog, "dialogFileUpload");

            fileName      = fileupload.fileName();
            if (fileName == '')
            {
                checkFailed("File name empty");
            }

            return ret;
        }

    读取数据:

     private void readData()
        {

      int                               startpos;
            int                              fieldCSVPos;
            container                   conData ;
            SysDictTable             sysDictTable;
            container                   currentLine;
            int                              totalOfLines;

            CommaTextStreamIo           localStream;


            FileUpload fileUploadControl = this.getFormControl(dialog,  “dialogFileUpload”);
           
            FileUploadTemporaryStorageResult fileUploadResult = fileUploadControl.getFileUploadResult();
           
            if (fileUploadResult != null && fileUploadResult.getUploadStatus())
            {
                fileName = fileUploadResult.getDownloadUrl();
            }
           
            localStream = CommaTextStreamIo::constructForRead(File::UseFileFromURL(fileName));
          
             
            if (localStream.status() != IO_Status::Ok)
            {
                throw error(strfmt('Is not possible to open the file. Error %1',enum2str(localStream.status())));
            }


            localStream.inFieldDelimiter("\,");
            localStream.inRecordDelimiter(" ");
       
            currentLine = localStream.read();

      startpos = 1;//定义读取数据的开始行标

            ttsbegin;
          
            while (currentLine)
            {

                if ( currentLine == connull() ) continue ;

                row++ ;

                if ( row  < startpos ) continue ;

               this.writeData(currentLine) ;
               //  info(strFmt('%1',conPeek(currentLine,2)));

                currentLine = localStream.read();
            }
            ttscommit;

        }

      欢迎大家讨论,一起学习。

    想了解更多,可参考 https://community.dynamics.com/ax/b/365operationswithsukrut/archive/2017/09/28/d365fo-use-of-fileupload-control-to-read-csv-file

  • 相关阅读:
    C语言程序设计I—第四周教学
    C语言程序设计I—第三周教学
    C语言程序设计I—第一周教学
    软工实践(四)——热词统计
    软工实践(三)——结对第一次作业(原型设计)
    软工实践(二)——构建之法读后感
    软工实践(一)——目标和规划
    庄子修身养性哲学
    $Matrix-Tree$定理-题目
    $Matrix-Tree$定理-理论
  • 原文地址:https://www.cnblogs.com/sunny-technology/p/9280737.html
Copyright © 2011-2022 走看看