6 Ocak 2014 Pazartesi

AX 2012 - SSRS rapor ile PDF çıktısı alma

AX 2012 ile PDF rapor oluşturma için Martin Drab'ın blog sayfasını kullandım:

void CreatePDF(Str60 _Subject,Notes _Body)
{
MYReportPurchController          controller;
MYReportPurchContract            rdpContract = new MyReportPurchContract();
SRSPrintDestinationSettings settings;
Args                        args = new args();
str                         fileName;

args.record(this);
controller = MYReportPurchController::construct(args);
// Define report and report design to use
controller.parmReportName(ssrsReportStr(EtgPurchOrderForm,PrecisionDesign1));
// Use execution mode appropriate to your situation
controller.parmExecutionMode(SysOperationExecutionMode::Synchronous);
// Suppress report dialog

// Explicitly provide all required parameters
controller.parmReportContract().parmRdpContract(rdpContract);
    //rdpContract.
// Change print settings as needed
settings = controller.parmReportContract().parmPrintSettings();
settings.overwriteFile(true);
settings.printMediumType(SRSPrintMediumType::File);
settings.fileFormat(SRSReportFileFormat::PDF);
//settings.

    #WinAPI

  fileName = WinApi::getTempPath() +this.PurchOrderDocNum+".PDF";
settings.fileName(fileName);
// Execute the report
    controller.parmShowDialog(false);
    controller.startOperation();
}

AXAPTA - Email gönderme

private void SendMail2(str _FileName,Str60 _Subject,Notes _Body)
{

   str Toaddress;
   System.Net.Mail.MailMessage Msg =  new System.Net.Mail.MailMessage();
   System.Net.Mail.MailAddress fromMail;
   System.Net.Mail.MailAddressCollection toadrr;
   System.Net.Mail.SmtpClient smCL = new System.Net.Mail.SmtpClient();
   System.Net.NetworkCredential credential;
   str          bodygrd,sSmtpServer;
   CLRObject   exc;
   CLRObject   innerExc;
   CLRObject   clrExcMessage;
   str         strError;
   SysEmailParameters EmailParm;
   str pass;
   System.Net.Mail.AttachmentCollection  mailAttachementCollection;
   System.Net.Mail.Attachment            mailAttachment;
;

toaddress="test@hotmail.com";


    EmailParm = SysEmailParameters::find();
    pass = SysEmailParameters::password();
    credential = new System.Net.NetworkCredential(EmailParm.SMTPUserName,pass);
    fromMail = new System.Net.Mail.MailAddress(EmailParm.SMTPUserName);
    new InteropPermission(InteropKind::ClrInterop).assert();
  try
  {
    Msg.set_From(fromMail);
    toadrr = Msg.get_To();
    toadrr.Add(new System.Net.Mail.MailAddress(toaddress));
    Msg.set_Subject(_Subject);
    Msg.set_Body(_body);
    Msg.set_IsBodyHtml(true);
    sSmtpServer =  EmailParm.SMTPRelayServerName;
    smCL.set_Host(sSmtpServer);
    mailAttachementCollection = msg.get_Attachments();
        mailAttachment = new System.Net.Mail.Attachment(_fileName);
        mailAttachementCollection.Add(mailAttachment);
    smCL.set_Port(EmailParm.SMTPPortNumber);
    smCL.set_EnableSsl(true);
    smCL.set_Credentials(credential);
    smCL.Send(Msg);
  }     catch( Exception::CLRError )
                   {
                        exc = CLRInterop::getLastException();
                        if( exc )
                        {
                           clrExcMessage = exc.get_Message();
                           innerExc = exc.get_InnerException();
                           while(innerExc != null)
                           {
                              clrExcMessage = innerExc.get_Message();
                              innerExc = innerExc.get_InnerException();
                           }
                           strError = CLRInterop::getAnyTypeForObject( clrExcMessage );
                           throw error(strError);
                        }
                   }
}

3 Ocak 2014 Cuma

AXAPTA - Birden fazla alış siparişinin bazı satırlarını birleştirip PurchEditLines formunda göstermek

    Args                    args = new Args();
    PurchFormLetter         purchFormLetter;
    purchTable              purchTable;
    VendReceiptsListTrans   ListTrans;
    PurchParmLine           purchParmLine;
    PurchParmTable          purchParmTable;
    Object                  dialog;
    vendReceiptsListJour    Jour;
    boolean                 err;
    VendPackingSlipTrans    PackingTrans;
    ;
    select purchTable where purchTable.PurchId == this.PurchId; //select first purchtable record
    //-------------- prepare purchformletter class -----
    purchFormLetter = PurchFormLetter::construct(DocumentStatus::PackingSlip);
    purchFormLetter.parmSourceTable(purchTable);
    purchFormLetter.initLinesQuery();
    purchformletter.createParmUpdate();
    purchFormLetter.transDate(this.PackingSlipDate);
//    purchformletter.documentNum(
    purchformletter.chooseLines();
    //--------------- add other purchtable records -----
    while select OrigpurchId from ListTrans
        group by ListTrans.OrigPurchId
        where ListTrans.ReceiptsListId == this.ReceiptsListId && ListTrans.OrigPurchId != this.PurchId
    {
       select purchTable where purchTable.PurchId == ListTrans.OrigPurchId;
        purchformletter.updateQueryAndChooseLines(purchTable);
    }
    //---------------- delete unnecessary purchase lines --------------------
    select firstonly forupdate purchParmLine
        where purchParmLine.ParmId == purchformletter.parmId();
    if (purchParmLine.RecId == 0)
    {
        box::stop("There isn't any purchline applicable");
        return;
    }
//    box::warning("111");
    ttsbegin;
    while select forupdate purchParmLine
        where purchParmLine.ParmId == purchformletter.parmId()
    {
        select firstonly ListTrans where ListTrans.ReceiptsListId == this.ReceiptsListId && ListTrans.OrigPurchId == purchParmLine.OrigPurchId &&
                ListTrans.ItemId == purchParmLine.ItemId && purchParmLine.InventTransId == ListTrans.InventTransId;
       // info(strfmt("%1 %2",purchparmline.ItemId,listtrans.ItemId));
        //---eğer bu sipariş satırı giriş listesinde yoksa sil-------------
        if (ListTrans.RecId == 0)
        {
//            info("---sil---");
            purchParmLine.delete();
            continue;
        }
       //----miktarı giriş listesinden al----------------------------------
            purchParmLine.ReceiveNow = ListTrans.PurchQty;
            purchParmLine.InventNow  = ListTrans.PurchQty;
//            purchParmLine.modifiedReceiveNow();
            purchParmLine.setQty(DocumentStatus::PackingSlip, false, true);
            purchParmLine.setLineAmount();
            purchParmLine.update();
     }
    update_recordset purchParmTable setting num = this.packingSlipId,
                                            TransDate = this.PackingSlipDate,
                                            DocumentDate = this.PackingSlipDate
    where purchParmTable.ParmId == purchformletter.parmId();
    ttscommit;
    if (this.packingSlipId)
        purchformletter.reArrange(true); //------------ merge purchases like push rearrange button at purcheditlines form ----
    dialog = purchformletter.dialog();
    dialog.run() ;
    dialog.wait();
    if (dialog.closedOk())
    {
            purchFormLetter.proforma(false);
            purchFormLetter.printFormLetter(true);
            purchFormLetter.specQty(PurchUpdate::ReceiveNow);
            purchFormLetter.progressHide();
            purchformletter.run();
            select firstonly PackingTrans join ListTrans
                where PackingTrans.purchId == ListTrans.OrigPurchId &&
                    ListTrans.ReceiptsListId == this.ReceiptsListId;
        if (PackingTrans.RecId != 0)
        {
            ttsbegin;
            update_recordset Jour setting VendReceiptsListJourStatus = DTVendReceiptsListJourStatus::PackingSlip
                where Jour.RecId == this.RecId;
            ttscommit;
        }
    }