zoukankan      html  css  js  c++  java
  • 利用CSV文件导入数据的例子

    void clicked()

    {

        #AviFiles

        str                                 s,tempStr;

        inventBatchId                       sBatchId;

        prodid                              sProdid;

        int                                 i,cnt,fieldCount;

        container                           c,conFilter = ["Excel Files(*.csv)", "*.csv"];

        NJ_MF_SilverModelInventory_tbl      Smi;

        SysOperationProgress                progress = new SysOperationProgress();

        TextBuffer                          textBuffer  = new TextBuffer();

        InventBatch                         IB;

        List                                l = new list(types::String);

        ListEnumerator                      le;

       // super();

        ;

        s = Winapi::getOpenFileName(0, conFilter, "","Open File", "", "");

        if(s)

        {

           // breakpoint;

            TextBuffer.fromFile(s);

            cnt = TextBuffer.numLines();

           // delete_from smi;

            //c = str2con(textBuffer.nextToken(),",");

            progress.setCaption("Data Import");

            progress.setAnimation(#AviFormLetter);

            startlengthyoperation();

            for (i=0;i<cnt;i++)

            {

                progress.setText(strfmt("Reading records %1", i));

               // textBuffer.replace(' ','');

              // textBuffer.replace('\n','');

                tempStr = textBuffer.nextToken();

                l = this.strSplit(tempstr,',');

                le = l.getEnumerator();

                //c = str2con(textBuffer.nextToken(),',');

                ttsbegin;

                //smi.ItemId = conpeek(c,1);

                le.moveNext();

                smi.ItemId = le.current();

                le.moveNext();

                //if (conpeek(c,2) == "")

                if(le.current())

                {

                    smi.ProdId = le.current();

                }

                if(!le.current())

                {

                    le.moveNext();

                    sBatchId = le.current();

                    select prodid from IB where IB.inventBatchId == sBatchId;

                    if (IB && IB.ProdId != "")

                    {

                        smi.ProdId = IB.ProdId;

                    }

                    else

                    {

                        smi.ProdId = '-';

                    }

                    smi.BatchId = le.current();

                }

                else

                {

                    le.moveNext();

                    smi.BatchId = le.current();

                }

                //smi.BatchId = conpeek(c,3);

                le.moveNext();

                if (le.current() != "")

                smi.ModelType = le.current() ;

               //tempStr = conpeek(c,4);

                //Breakpoint;

               // switch (conpeek(c,4))

               /* switch (le.current())

                {

                    case '银版':

                        smi.ModelType = NJ_MF_SilverModelType::SilverModel;

                        break;

                    case '铜版' :

                        smi.ModelType = NJ_MF_SilverModelType::CopperModel;

                        break;

                    case '外工版' :

                         smi.ModelType = NJ_MF_SilverModelType::ExternalModel;

                         break;

                    case '手造银版' :

                         smi.ModelType = NJ_MF_SilverModelType::ManualModel;

                         break;

                    case '参考版' :

                         smi.ModelType = NJ_MF_SilverModelType::RefModel;

                         break;

                    case '手造配件' :

                         smi.ModelType = NJ_MF_SilverModelType::ManualPart;

                         break;

                    case '待报废' :

                         smi.ModelType = NJ_MF_SilverModelType::UseLessModel;

                         break;

                    case '其它' :

                         smi.ModelType = NJ_MF_SilverModelType::Other;

                         break;

                }   */

                le.moveNext();

                if (le.current() != "")

                    smi.SilverWeight = any2real(le.current());

                //smi.SilverWeight = any2real(conpeek(c,5));

                le.moveNext();

                if (le.current() != "")

                smi.CabinetNum = le.current();

                //smi.CabinetNum = conpeek(c,6);

                le.moveNext();

              //  breakpoint;

              if (le.current() != "")

                smi.Layer = le.current();

               // smi.Layer = conpeek(c,7);

                le.moveNext();

                if (le.current() != "")

                smi.Qty = any2int(le.current());

                le.moveNext();

                if (le.current() != "")

                smi.Set_Qty = any2int(le.current());

                //smi.Qty = any2int(conpeek(c,8));

                le.moveNext();

                //breakpoint;

                if (le.current() != "")

                smi.ReceiveDate = str2date(le.current(),123);

                //tempStr = conpeek(c,9);

                //smi.ReceiveDate = any2date(conpeek(c,9));

                le.moveNext();

                smi.Remarks1 = le.current();

                //smi.Remarks1 = conpeek(c,10);

                le.moveNext();

                 smi.Remarks2 = le.current();

                //smi.Remarks2 = conpeek(c,11);

                fieldCount = l.elements();

                smi.Approve = noyes::Yes;     //上传的记录默认已审批

                if (fieldCount == 12)

                {

                    le.moveNext();

                    smi.CancelCause = le.current();

                }

                //smi.CancelCause = conpeek(c,12);

                le.reset();

                smi.insert();

                endlengthyoperation();

                ttscommit;

            }

        NJ_MF_SilverModelInventory_ds.research();

        box::info("导入记录条数:"+int2str(i));

        }

        super();

    }

    }

  • 相关阅读:
    select选中值传递到后台action中
    select into from 与insert into select from区别
    存储过程
    layer
    下拉框两级联动
    无限纠结——Zedboard上跑ubuntu详解
    静态时序分析SAT
    设计模式-(构型模式)
    内存断点调试的原理
    C语言中使用静态函数的好处
  • 原文地址:https://www.cnblogs.com/perock/p/2119137.html
Copyright © 2011-2022 走看看