zoukankan      html  css  js  c++  java
  • Using X++ find out all of the table field with special EDT from dictionary

    Sometimes, I want to find all the table field and modify or remove data with the EDT from AOT - > dictionary.

     

     

    static void Jimmy_FindEDTFromDictionary(Args _args)
    {
         
    int        i,counter;
         
    int        numberOfFields;
         Dictionary Dictionary 
    = new Dictionary();
         DictField  DictField;
         DictTable  DictTable;
         
    //Common     Common;
         fieldId    fieldId01,fieldId02,fieldId03;
         name       name01,name02,name03;
         str        Remark;
         
    int        time;
         test       insertTest,upTest;
         name       tableName,fieldName,tablePnames;
         
    int        tableId,fieldId,tempStartTime;
         Dialog         dlg         
    = new Dialog("Please enter the EDT");
         dialogField    dlgEDT      
    = dlg.addField(typeId(ExtendedDataTypeName));
         dialogField    dlgUpData   
    = dlg.addField(typeId(Noyes),"Clear EDT data");

         DialogField    dlgQVS      
    = dlg.addField(typeId(Noyes),"QVS");
         DialogField    dlgNEW      
    = dlg.addField(typeId(Noyes),"NEW");
         DialogField    dlgQCN      
    = dlg.addField(typeId(Noyes),"QCN");
         DialogField    dlgQHK      
    = dlg.addField(typeId(Noyes),"QHK");
         DialogField    dlgQUS      
    = dlg.addField(typeId(Noyes),"QUS");

         extendedTypeId edt;
         Noyes          updateData;
         Noyes          qcn,qhk,qus,qvs,news;
    void ClearData()
    {
        Common  Common;
    ;
        Common 
    = DictTable.makeRecord();
        
    if(edt == extendedTypeNum(Dimension))
        {
            ttsbegin;
            Common.selectForUpdate(
    true);
            
    while select  Common
                
    where Common.(fieldId2Ext(DictField.id(),1)) != "" ||
                      Common.(fieldId2Ext(DictField.id(),
    3)) != ""
            {
                fieldId01 
    = fieldId2Ext(DictField.id(),1);
                
    //fieldId02 = fieldId2Ext(DictField.id(),2);
                fieldId03 = fieldId2Ext(DictField.id(),3);
                name01 
    = Common.(fieldId01);
                
    //name02 = Common.(fieldId02);
                name03 = Common.(fieldId03);
                
    if(name01 || name03)
                {
                    
    /*
                    info(strfmt("%1 , %2 , %3 ,%4, %5",Common.(fieldnum(CustInvoiceTrans,SalesId)),
                    Common.(fieldnum(CustInvoiceTrans,ItemId)),name01,name02,name03));
                    
    */
                    Common.(fieldId01) 
    = "";
                    
    //Common.(fieldId02) = "";Cost center 不做变更
                    Common.(fieldId03) = "";
                    Common.doupdate();
                }
            }
            ttscommit;
        }
        
    else
        {
            ttsbegin;
            Common.selectForUpdate(
    true);
            
    while select  Common
                
    where Common.(DictField.id()) != ""
            {
                name01 
    = Common.(DictField.id());
                
    if(name01)
                {
                    Common.(DictField.id()) 
    = "";
                    Common.doupdate();
                }
            }
            ttscommit;
        }
    }
    ;
        dlg.doInit();
        dlgEDT.value(
    "Dimension");
        dlgQCN.value(
    1);
        dlgQHK.value(
    1);
        dlgQUS.value(
    1);
        dlgQVS.value(
    1);
        dlgNEW.value(
    1);

        
    if(!dlg.run())
            
    return;
        edt 
    = global::extendedTypeName2Id(dlgEDT.value());
        qcn 
    = dlgQCN.value();
        qhk 
    = dlgQHK.value();
        qus 
    = dlgQUS.value();
        qvs 
    = dlgQVS.value();
        news
    = dlgNEW.value();

        updateData 
    = dlgUpData.value();
        
    //if(!Box::yesNo("Are you sure update?",DialogButton::No,"Clear EDT from Dictionary!"))
        IF(!dlgEDT.value())
            
    return;


        delete_from insertTest;
        time 
    = timeNow();

        tableId 
    = Dictionary.tableNext(0);
        setprefix(strfmt(
    "%1 - %2",curext(),CuruserId()));
        
    while(tableId)
        {
            DictTable 
    = new DictTable(tableId);
            
    if(DictTable.id() == 50356)
                tableId 
    = tableId;

            
    if(!DictTable.isMap() && !DictTable.isView() && !DictTable.isTmp() && DictTable.rights() >= AccessType::Edit)
            {
                numberOfFields 
    = DictTable.fieldCnt();
                
    for (i = 1; i <= numberOfFields; i++)
                {
                    DictField 
    = new DictField(DictTable.id(),DictTable.fieldCnt2Id(i));

                    
    if(DictField && DictField.typeId() == edt)
                    {
                        counter 
    ++;

                        tableName   
    = DictTable.name();
                        fieldName   
    = DictField.name();
                        fieldId     
    = DictField.id();
                        tablePnames 
    = tableId2PName(DictTable.id());

                        tempStartTime   
    = timeNow();
                        insertTest.Id         
    = counter;
                        insertTest.Price01    
    = tableId;
                        insertTest.Price02    
    = fieldId;
                        insertTest.ItemId     
    = tableName;
                        insertTest.Name       
    = tablePnames;
                        insertTest.VendName   
    = fieldName;
                        insertTest.BomId      
    = fieldid2pname(tableId,fieldId);
                        insertTest.doInsert();

                        info(strfmt(
    "%5.[%6] Table: %1,%2 ;field: %3,%4",tableId,tableName,fieldId,fieldName,counter,tablePnames));

                        
    if(updateData)
                        {
                            
    if(QCN)
                            {
                                changecompany(
    "QCN")
                                {
                                    ClearData();
                                }
                            }
                            
    if(QHK)
                            {
                                changecompany(
    "QHK")
                                {
                                    ClearData();
                                }
                            }
                            
    if(QUS)
                            {
                                changecompany(
    "QUS")
                                {
                                    ClearData();
                                }
                            }
                            
    if(QVS)
                            {
                                changecompany(
    "QVS")
                                {
                                    ClearData();
                                }
                            }
                            
    if(NEWS)
                            {
                                changecompany(
    "NEW")
                                {
                                    ClearData();
                                }
                            }
                        }
                        
    if(!Remark)
                            Remark  
    = tableName;
                        
    else
                            Remark 
    += "," + tableName;

                        ttsbegin;
                        upTest 
    = test::find(insertTest.ItemId,insertTest.VendName,true);
                        
    if(UpTest)
                        {
                            upTest.CustName   
    = strlrtrim(global::time2StrHMS(timeNow() - tempStartTime));
                            upTest.doUpdate();
                        }
                        ttscommit;
                    }
                }
            }
            tableId 
    = Dictionary.tableNext(tableId);
        }
        info(Remark);
        info(strfmt(
    "total took time %1",global::time2StrHMS(timenow() - time)));
    /**
    select ID,PRICE01,ItemId,NAME,PRICE02, VENDNAME,BomId,CUSTNAME from TEST a
    where a.DATAAREAID = 'qvs' and a.CUSTNAME != '0:00:00'
    order by CUSTNAME desc
    go
    */
    }
  • 相关阅读:
    ios 封装sqllite3接口
    ios7与ios6UI风格区别
    C/C++面试题
    单链表反转
    字符串倒序输出
    简单选择排序
    插入排序
    冒泡
    快速排序
    C++ new delete(二)
  • 原文地址:https://www.cnblogs.com/Fandyx/p/2135460.html
Copyright © 2011-2022 走看看