In axapta, there is a basic type of iner, which is really useful in some cases. axapta has many existing systems, such as runbase pack () and unpack () the method is implemented by combining the iner with the macro.
The container can be regarded as a non-type dynamic growth array, which is basically equivalent to the arraylist in C. however, the container cannot store objects (table objects can still be stored). In addition, the container can be used as a database field type and converted to the IMG type in the database. It can be seen that the container serializes the data.
In addition, because the elements stored by the container can be container, the functions similar to two-dimensional arrays can be implemented. today, we have a requirement to make a customer (supplier) statement, because the domestic finance needs to be summarized on a monthly basis, and the query time entered by the user may be cross-month, in addition, it may not end from the first day to the end of the month. For example, you can enter the following time periods for query.
2006-05-27
In this way, according to the domestic financial requirements, it needs to be divided into the following time periods:
1.2006-03-13 ~~~ 2006-03-31
2.2006-04-01 ~~~ 2006-04-40
3.2006-05-01 ~~~ 2006-05-27
Calculate the transaction information of the preceding three paragraphs and summarize them separately. In this way, we need to break down any period of time on a monthly basis. Of course, there are many ways to do this, however, it is quite convenient to use container to implement this small function, Code As follows: Static Container getdateperiod (transdate fromdate, transdate todate)
{
Container cperiod, cperiodforonemonth;
Int I;
Int Day;
Transdate;
Int Gyearpart, gmonthpart;
// Returns the number of days in a month.
Int Getday ( Int Yearpart, Int Monthpart)
{
Switch (Monthpart)
{
Case 1 :
Case 3 :
Case 5 :
Case 7 :
Case 8 :
Case 10 :
Case 12 :
{
Day= 31;
Break;
}
Case 4 :
Case 6 :
Case 9 :
Case 11 :
{
Day= 30;
Break;
}
Case 2 :
{
If ( ! (Yearpart mod 4 ))
Day = 29 ;
Else
Day = 28 ;
Break ;
}
Default :
Throw Error ( " Error input month! " );
Break ;
}
}
// Get the start and end dates of the complete month.
Container getperiodforonemonth ( Int Yearpart, Int Monthpart)
{
;
Getday (yearpart, monthpart );
Return [Str2date (int2str (yearpart) + " - " + Int2str (monthpart) + " -01 " , 321 ),
Str2date (int2str (yearpart) + " - " + Int2str (monthpart) + " - " + Int2str (day ), 321 )];
} ;
// Insert the complete month between the start and end dates
For (I = Mthofyr (fromdate) + 1 ; I < Mthofyr (todate); I ++ )
{
Cperiod=Conins (cperiod, conlen (cperiod)+1, Getperiodforonemonth (Year (todate), I ));
}
// Insert start month
Getday (Year (fromdate), mthofyr (fromdate ));
Gyearpart = Year (fromdate );
Gmonthpart = Mthofyr (fromdate );
Transdate = Str2date (int2str (gyearpart) + " - " + Int2str (gmonthpart) + " - " + Int2str (day ), 321 );
Cperiod = Conins (cperiod, 1 , [Fromdate, transdate]);
// Insert end month
If (Mthofyr (fromdate) ! = Mthofyr (todate ))
{
Gyearpart = Year (todate );
Gmonthpart = Mthofyr (todate );
Transdate = Str2date (int2str (gyearpart) + " - " + Int2str (gmonthpart) + " -01 " , 321 );
Cperiod = Conins (cperiod, conlen (cperiod) + 1 , [Transdate, todate]);
}
Return Cperiod;
}
The call code is as follows: Static Void Main (ARGs Arg)
{
Container C, cperiod;
Transdate fromdate;
Transdate todate;
Int I;
;
Fromdate = Str2date ( " 2006-02-06 " , 321 );
Todate = Str2date ( " 2006-09-30 " , 321 );
C = Class2: getdateperiod (fromdate, todate );
For (I = 1 ; I <= Conlen (c); I ++ )
{
Cperiod = Conpeek (C, I );
Fromdate = Conpeek (cperiod, 1 );
Todate = Conpeek (cperiod, 2 );
Print date2strxpp (fromdate) + " --- " + Date2strxpp (todate );
}
Pause;
}
Of course, because the account table needs to calculate the annual settlement balance, the query date entered by the user is generally not allowed across the year, so thisProgramThe cross-year period has not been processed.