martes, 17 de julio de 2012

Leer un CSV Dynamics AX 2012 Con ADO


static void Job57(Args _args)
{
 
    System.Data.Common.DbConnection connection;
    System.Data.Common.DbCommand command;
    System.Data.SqlClient.SqlDataReader dataReader;
    System.Data.Common.DbProviderFactory factory=System.Data.Common.DbProviderFactories::GetFactory("System.Data.OleDb");
    int contar;
    ;
    new InteropPermission( InteropKind::ClrInterop ).assert();


    connection=factory.CreateConnection();
    connection.set_ConnectionString("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\AbinsaCobranza\\;Extended Properties=\"text;HDR=Yes;FMT=Delimited\"");

    command=factory.CreateCommand();
    command.set_CommandText("select * from BANREGIO.csv");
    command.set_Connection(connection);

    //executing SQL-query
    try
    {
        //open within catch, so that the object can correcly be disposed
        //all these try-catch are quite ennoying in X++, but this because
        //X++ does not know finally...
        connection.Open();
        try
        {
            //All code after the open must be in a seperate catch, so that the
            //open connection-object can correcly be disposed.
            dataReader = command.ExecuteReader();

            while(dataReader.Read())
            {
                if(contar>=10)
                {
                   // contar=dataReader.get_FieldCount();
                    //use the named columns instead of index.
                   info(int2str(contar));
                   print dataReader.get_Item(6);
                    pause;
                }
               
               
                contar++;

            }
            //Dispose ADO.Net objects ASAP
            dataReader.Dispose();
        }
        catch //should be more precise in a real-world application
        {
            //if exception occures while reading, DataReader need to be
            info(CLRInterop::getLastException().ToString());
            dataReader.Dispose();
        }
        catch(Exception::CLRError) //CLR exception need to be handled explicitely
        //otherwise they might be 'lost'. Happy copy&pasteing
        {
            //if exception occures while reading, DataReader need to be
            info(CLRInterop::getLastException().ToString());
            dataReader.Dispose();
        }
        connection.Dispose();
    }
    catch //should be more precise in a real-world application
    {
        info(CLRInterop::getLastException().ToString());
        connection.Dispose(); //disposing connection if it fails before opening it
    }
    catch(Exception::CLRError)
    {
        info(CLRInterop::getLastException().ToString());
        connection.Dispose();
    }
    command.Dispose();
    CodeAccessPermission::revertAssert();


}

lunes, 9 de julio de 2012

Crear Cliente AX 2012


CustCustomerService CustCustomerService;

    CustCustomer CustCustomer;
    //CustCustomer_DirParty CustCustomer_DirParty;
    CustCustomer_DirParty_DirOrganization dirOrg;
    CustCustomer_DirPartyPostalAddressView CustCustomer_DirPartyPostalAddressView;
    CustCustomer_DirPartyContactInfoView CustCustomer_DirPartyContactInfoView;


    CustCustomer_CustTable CustCustomer_CustTable;
;
    ////////////////////////////////////////////////////////////////7
    CustCustomerService= CustCustomerService::construct();
    CustCustomer=new CustCustomer();

    CustCustomer_CustTable=new CustCustomer_CustTable();
    dirOrg = new CustCustomer_DirParty_DirOrganization();
    ////////////////////////////////////////////////////////////////////////7
    CustCustomer_CustTable.parmAccountNum("0027");
    CustCustomer_CustTable.parmCustGroup("Empleados");
    CustCustomer_CustTable.parmGsCueCobClaveReferenciada("1234512333");
    CustCustomer_CustTable.parmTaxGroup("IVA 16");
    //CustCustomer_DirParty=new CustCustomer_DirParty();

   // CustCustomer_CustTable.parmAccountNum("prue1");


    dirOrg.parmName("MyCustomerName_OrgName");
    dirOrg.parmLanguageId("es-mx");
    CustCustomer_CustTable.createDirParty().add(dirOrg);
 
    CustCustomer_DirPartyPostalAddressView=dirOrg.createDirPartyPostalAddressView().addNew();
    CustCustomer_DirPartyPostalAddressView.parmStreet("De la villa");
    CustCustomer_DirPartyPostalAddressView.parmCountryRegionId("Mex");
    CustCustomer_DirPartyPostalAddressView.parmRoles("Business");
   
    CustCustomer_DirPartyContactInfoView=dirOrg.createDirPartyContactInfoView().addNew();
    CustCustomer_DirPartyContactInfoView.parmLocationName("Telefono");
    CustCustomer_DirPartyContactInfoView.parmLocator("000000000");
 
    CustCustomer_DirPartyContactInfoView.parmType(LogisticsElectronicAddressMethodType::Phone);
    CustCustomer_DirPartyContactInfoView.parmRoles("Business");
   
 
    CustCustomer.createCustTable().add(CustCustomer_CustTable);

    CustCustomerService.create(CustCustomer);






}