2012年5月20日星期日

How to changed Chinese date and Solar Date


display str 100 ChineseDateTime()
{
    str 100    name;
    str 100 SolarCalendarToChinese(TransDateTime    CalendarDateTime)
    {
        int         years,month,day,leapMonth,Weekday;
        Container   J  = ['甲',"乙",'丙','丁','戊','己','庚','辛','壬','癸'];
        Container   z  = ["子","丑","寅","卯","巳","午","未","申","酉","戌","亥"];
        Container   s  = ["鼠","牛","虎","兔","龙","蛇","马","羊","猴","鸡","狗","猪"];
        Container   w  = ["无","正","二","三","四","五","六","七","八","九","十","冬","腊"];
        Container   c  = ["初","十","廿","三"];
        Container   r  = ["日","一","二","三","四","五","六","七","八","九"];
        Container   wd = ['日',"一","二","三","四","五","六"];
        Str 20      jj,zz,ss,ww,cc,rr,rn,ry,wkday;
        Str 100     ChineseStr;
        System.Globalization.ChineseLunisolarCalendar clc;
        boolean     isleapMonth,IsLeapYear;
    ;
        clc         = new System.Globalization.ChineseLunisolarCalendar();
        years       = clc.GetYear(CalendarDateTime);
        month       = clc.GetMonth(CalendarDateTime);
        day         = clc.GetDayOfMonth(CalendarDateTime);
        leapMonth   = clc.GetLeapMonth(years);
        Weekday     = clc.GetDayOfWeek(CalendarDateTime);
        IsLeapYear  = clc.IsLeapYear(years);
        jj = Conpeek(J,(years - 4) MOD 10 + 1);
        zz = Conpeek(Z,(years - 4) MOD 12 + 1);
        SS = Conpeek(S,(years - 4) MOD 12 + 1);
        //wkday = '星期' + Conpeek(wd,Weekday + 1);
        wkday = dayname(Weekday);
        if (leapMonth > 0)
        {
            if (leapMonth == month) //闰月
            {
                isleapMonth = true;
                ry          = '闰月';
                month       = month - 1;
            }
            else if (month > leapMonth)
            {
                month       = month - 1;
            }
        }
        WW = Conpeek(W,month + 1);
        cc = ConPeek(C,day / 10 + 1);
        rr = ConPeek(R,day mod 10 + 1);
        if(leapMonth)
            ry = '润';
        else
            ry = '平';
        if(IsLeapYear)
            rn = '润';
        else
            rn = '平';
        //ChineseStr = strfmt("%1%2%3(%8)年(%4)%5月 %6%7日" ,JJ,ZZ,ss,ry,WW,cc,rr,rn)+ wkday;
        //return ChineseStr +  strfmt("  %1年 %2月 %3日",years,month,day);
        return  "[ " + strfmt("%1%2%3 (%8) %9 年(%4) %5 月 %6%7 日 " ,JJ,ZZ,ss,ry,WW,cc,rr,rn,years) + "]";
    }
    str 100 ChineseToSolarCalendar(TransDateTime  ChineseDate)
    {
        int             years,month,day,hour,minutes,second;
        TransDateTime   CalendarStr;
        System.Globalization.ChineseLunisolarCalendar clc = new System.Globalization.ChineseLunisolarCalendar();
    ;
        years   = datetimeutil::year(ChineseDate);
        Month   = datetimeutil::month(ChineseDate);
        day     = datetimeutil::day(ChineseDate);
        hour    = datetimeutil::hour(ChineseDate);
        minutes = datetimeutil::minute(ChineseDate);
        second  = datetimeutil::second(ChineseDate);
        CalendarStr = clc.ToDateTime(years,Month,day,hour,minutes,second,0);
        return  strfmt("农历 : %1;公历:%2",ChineseDate,CalendarStr);
    }
;
    name = strfmt("%1 %2",datetimeutil::applyTimeZoneOffset(datetimeutil::utcNow(),datetimeutil::getCompanyTimeZone()),
                          dayname(dayOfWk(today())));
    name += " " + SolarCalendarToChinese(datetimeutil::newDateTime(systemdateget(),0,0));
    DateTimeStr.text(name);
    if(Loop.value())
        this.setTimeOut(identifierstr(ChineseDateTime), 500, true);
    return  name;
}
-------------
阳历转农历
static TransDate solarDateToChineseDate(TransDate _TransDate)
{
/**公历转换成农历*/
    System.Globalization.ChineseLunisolarCalendar cCalendar = new System.Globalization.ChineseLunisolarCalendar();
    TransDate GetChineseDateTime(Date datetime)
    {
        int lyear   = cCalendar.GetYear(datetime);
        int lmonth  = cCalendar.GetMonth(datetime);
        int lday    = cCalendar.GetDayOfMonth(datetime);
        //获取闰月, 0 则表示没有闰月
        int leapMonth = cCalendar.GetLeapMonth(lyear);
        boolean isleap = false;
        if (leapMonth > 0)
        {
            if (leapMonth == lmonth)
            {
                //闰月
                isleap = true;
                lmonth--;
            }
            else if (lmonth > leapMonth)
            {
                lmonth--;
            }
        }
        //return strfmt("%1年%2月%3日",lyear,lmonth,lday);
        return mkdate(lday,lmonth,lyear);
    }
;
   return  GetChineseDateTime(_TransDate);
}
-------------------------
农历转阳历
static TransDate ChineseDateToSolarDate(TransDate ChineseDate)
{
/**农历转换成公历*/
    System.Globalization.ChineseLunisolarCalendar clc = new System.Globalization.ChineseLunisolarCalendar();
    int             years,month,day,hour,minutes,second;
    TransDate       transDate;
;
    years   = year(ChineseDate);
    Month   = mthofyr(ChineseDate);
    day     = dayofmth(ChineseDate);
//      hour    = datetimeutil::hour(ChineseDate);
//      minutes = datetimeutil::minute(ChineseDate);
//      second  = datetimeutil::second(ChineseDate);
    transDate = clc.ToDateTime(years,Month,day,hour,minutes,second,0);
    return  transDate;//strfmt("农历 : %1;公历:%2",ChineseDate,CalendarStr);
}

2012年5月8日星期二

How to get onhand quantity and value with x++ code

display qty OnHand()
{
    InventDim           inventDimCriteria;
    InventDimParm       inventDimParm;
    InventOnhand        inventOnhand = new InventOnhand();
    qty                 qty;
    ;
    //inventDimCriteria = inventDim;
    inventDimCriteria.InventLocationId  = inventDim.InventLocationId;
    inventDimCriteria.configId          = inventDim.configId;
    inventDimParm.initFromInventDim(inventDimCriteria);
    inventOnhand.parmInventDim(inventDimCriteria);
    inventOnhand.parmInventDimParm(inventDimParm);
    inventOnhand.parmItemId(inventTable.ItemId);
    Qty = inventOnhand.physicalInvent();
    OnHandQty = qty;
    return qty;
}

2012年5月5日星期六

How to removing the resservation on the Form

//Removing the Reservation
//remark ProdTable is current prodTable record on the prodTable
clicked()
{
    ProdTable               ProdTable;
    InventUpd_Reservation   res;
    InventMovement          movement;
    InventDimParm           inventDimParmFixed;
    InventDimParm           inventDimParm;
    Salesline               Salesline = Salesline::findInventTransId(ProdTable.inventRefTransId,true);
    InventDim               inventDim = inventDim::find(Salesline.inventDimId);
    Inventtrans             Inventtrans;
;
    if(Custtable::find(Salesline.CustAccount))
    {
        Inventtrans = InventTrans::findTransId(Salesline.inventtransId);
        if(Inventtrans.StatusIssue == StatusIssue::ReservPhysical)
        {
            movement = Inventtrans.inventmovement(true);
            res      = InventUpd_Reservation::newInventDim( movement,
                                                            inventTrans.inventDim(),
                                                            Salesline.SalesQty,
                                                            true
                                                           );
            res.updatenow();
        }
    }
}

How to fixed a bug in class RunBaseReport.

// Changed on 05 五月 2012 at 21:40:07 by Jimmy
/*
When you create a class that extends from RunBaseReport and you try to modify the printer preferences
it won’t have any effect. This small bug can be fixed very easy.
Edit the class RunBaseReportDialog, method main and check lines 14 and 15:
*/
static void main(Args args)
{
    RunBaseReportDialog reportDialog = new RunBaseReportDialog(args.caller());
    RunBaseReport       runBaseReport = args.caller().runbase();
    ReportRun           reportRun = runBaseReport.reportRun();
    Report              report = reportRun.report();
    boolean             oldInteractive;
    boolean             res;
    Dialog              dialog;
;
    // We must invoke the SysPrintForm via the report object so that we honor an prompt overrides.
    oldInteractive = report.interactive();
    report.interactive(true);
   
    /* Original
    res = reportRun.prompt(); // commented
    */
    // Changed on 05 五月 2012 at 21:40:07 by Jimmy Begin
    if (SysReportRun::hasMethod(reportRun.name(), 'prompt'))
    {
        res = reportRun.prompt();
    }
    else
    {
        res = reportDialog.prompt();
    }
    // Changed on 05 五月 2012 at 21:40:07 by Jimmy End
    report.interactive(oldInteractive);
    if (!res)
        return;
    dialog = Dialog::getDialogFromCaller(args.caller());
    if (dialog)
    {
        dialog.updateServer();
    }
    runBaseReport.dialogUpdatePrinterSettings(dialog);
    reportDialog.run();
}

How to delete Identical Objects

static void THK_FindAndDeleteIdenticalObjects(Args _args)
{
/*
Delete Identical Objects
Job to remove the identical copy from VAR layer.   
For some unknown reason, some AOT objects are touched in VAR layer but actually are identical copy.
When the developer compared the VAR layer object with the one in lower layer (BUS, SYS etc.),
AX showed it was an identical copy.Here is the example on how you can remove the identical copy in X++ code:
*/
    SysTreeNode     comparable1, comparable2;
    TreeNode        curLevelTreeNode, upperLevelTreeNode;
    UtilIdElements  utilElements, joinUtilElements;
;
    if(!box::yesNo("Are you sure delete Identical Objects",dialogbutton::No,"delete Identical Objects"))
        return;
       
    while select UtilElements
        where   UtilElements.utilLevel        == UtilEntryLevel::var &&
                (
                UtilElements.recordType     == UtilElementType::Form            ||
                Utilelements.recordType     == UtilElementType::Report          ||
                Utilelements.recordType     == UtilElementType::Table           ||
                Utilelements.recordType     == UtilElementType::Class           ||
                Utilelements.recordType     == UtilElementType::Enum            ||
                Utilelements.recordType     == UtilElementType::ExtendedType
                )
    {  
        //Should use join if for a normal table, but not applicable for UtilElements
        //Performance hit if use exists join           
        select firstonly recid from joinUtilElements               
            where   joinUtilElements.utilLevel          != UtilElements.utilLevel       &&
                    joinUtilElements.name               == UtilElements.name            &&
                    joinUtilElements.recordType         == UtilElements.recordType;
        if (joinUtilElements.RecId)
        {
            curLevelTreeNode    = SysTreeNode::findNodeInLayer( UtilElements.recordType,
                                                                UtilElements.name,
                                                                UtilElements.parentId,
                                                                UtilElements.utilLevel);                   
            upperLevelTreeNode  = SysTreeNode::getLayeredNode(curLevelTreenode, 1);
            comparable1         = SysTreeNode::newTreeNode(curLevelTreeNode);
            comparable2         = SysTreeNode::newTreeNode(upperLevelTreeNode);
            if(SysCompare::silentCompare(comparable1, comparable2))
            {
                info(strFmt("Element name: %1, Element type: %2",
                        UtilElements.name,
                        enum2str(UtilElements.recordType)));                   
                //Remove the node
              
                //curLevelTreeNode.AOTdelete();
            }
        }
    }
}

How to selection multi line on dialog

static void THK_dialogSelectionMultiLine(Args _args)
{
    Dialog              dialog = new Dialog();
    DialogField         dlg;
    str                 vendAccount;
    boolean             retValue;
    ;
   
    dlg = dialog.addField(typeId(VendAccount));
    dlg.fieldControl().displayLength(100);
    dlg.fieldControl().LimitText(500);
    dlg.fieldControl().LookupButton(2);
    dlg.fieldControl().replaceOnLookup(Noyes::No);
    dlg.fieldControl().mandatory(true);
    //dlg.THK_mandatory(true);
    //dlg.THK_replaceOnLookup(false);
    retValue = dialog.run();
   
    if(retValue)
    {
        vendAccount = dlg.value();
        //do something else
        info(vendAccount);
    }
}