Script menusune otomatik query oluşturan bir kod eklemek

Merhaba

Daha önce ax editörunda bulunan script menusune nasıl ekleme yapılacağından bahsetmiştik. Ben kendi işlerimde kullanmak üzere bir çok ekleme yaptım bir tanesini sizinle paylaşacağım.

İki tablo ismi  ve join tipini soran ve bu bilgilere göre query hazırlayan kod örneğimiz şöyle:

Öncelikle EditorScripts sınıfımıza şu metodu ekliyoruz.


public void FD_Query(Editor editor)
{
    xppSource       xppSource       = new xppSource();
    Dialog          dialog          = new Dialog("Query oluştur");

    DialogField     dlgTablename    = dialog.addField(typeid(TableName));
    DialogField     dlgTablename2   = dialog.addField(typeid(TableName));
    DialogField     dlgExtTypeName  = dialog.addField(typeid(joinMode));
    Source          template;
;
    if (dialog.run())
    {
        template = xppSource.Query2Method(dlgTablename.value() ,
        dlgTablename2.value(),dlgExtTypeName.value() );

        editor.insertLines(template);
    }
}

Sonra xppSource sınıfımıza şu metodu ekliyoruz.


Source Query2Method(
    TableName         tableName,
    TableName         tableName2,
    JoinMode          joinmode  )
{
    ;
    indentLevel = 4;
    source +=this.indent()+ strfmt("%1               %1;", tableName)             +#newline;
    source +=this.indent()+ strfmt("%1               %1;", tableName2)            +#newline+#newline;
    source +=this.indent()+ strfmt("Query                   q;")                  +#newline;
    source +=this.indent()+ strfmt("QueryRun                qRun;")               +#newline;
    source +=this.indent()+ strfmt("QueryBuildRange         qbr;")                +#newline;
    source +=this.indent()+ strfmt("QueryBuildDataSource    qbds%1;",tableName)   +#newline;
    source +=this.indent()+ strfmt("QueryBuildDataSource    qbds%1;",tableName2)  +#newline+#newline;
    source +=this.indent()+ strfmt(";")                                           +#newline+#newline;
    source +=this.indent()+ strfmt("q       = new Query();")                      +#newline;
    source +=this.indent()+ strfmt("qbds%1    = q.addDataSource(TableNum(%1));",tableName)  +#newline;
    source +=this.indent()+ strfmt("qbds%1    = qbds%2.addDataSource(TableNum(%1));",
                                                            tableName2 ,tableName)+#newline;
    source +=this.indent()+ strfmt("qbds%1.relations(true);",tableName2)          +#newline;
    source +=this.indent()+ strfmt("//qbds%1.addLink(tablenum(%2 , fieldname),tablenum(%1 , fieldName));",
                                        tableName2, tableName)+#newline;
    source +=this.indent()+ strfmt("qbds%1.joinMode(joinMode::%2);",tableName2,joinmode) +#newline;
    source +=this.indent()+ strfmt("qRun    = new QueryRun(q);")                  +#newline;
    source +=this.indent()+ strfmt("while(qRun.next())")                          +#newline;
    this.beginBlock();
    source +=this.indent()+strfmt("    %1 = qRun.get(TableNum(%1));",tableName )  +#newline;
    source +=this.indent()+strfmt("    %1 = qRun.get(TableNum(%1));",tableName2 ) +#newline;
    this.endBlock();

    return source;
}

Kod editorunden script menusune tıklarsanız FD ve  Query menusunu göreceksiniz. Oluşturup bakın istediğiniz gibi değiştirebilir farklı metodlar ekleyebilirsiniz.

Selamlar. 

 

 
  • Trackback are closed
  • Comments (2)
    • Ali Fuat
    • Aralık 2nd, 2011 6:24pm

    iş kolaylaştırıcı bir script olmuş, ellerine sağlık

    • mesut
    • Şubat 15th, 2012 12:51pm

    güzel olmuş

Comment are closed.