コード例 #1
0
        /// <summary>
        /// Create 12 Periods On the basis of User's Choice If User select March-15 then it creates (March-15 to Feb-16).
        /// Creates also Period Control from DocType.
        /// See DocumentTypeVerify#createPeriodControls(Ctx, int, SvrProcess, String)
        /// </summary>
        /// <param name="Month_ID">Month_ID</param>
        /// <returns>true if created</returns>
        //public Boolean CreateStdPeriods(string Month_ID)
        #region Create Custom Periods
        public Boolean CreateCustomPeriods(string Month_ID)
        {
            if (Month_ID == null)
            {
                return(false);
            }

            Int32 Mnth_ID = Convert.ToInt32(Month_ID);
            Int32 count   = 1;

            String[] months = null;
            try
            {
                months = DateTimeFormatInfo.CurrentInfo.MonthNames;

                //DateFormatSymbols symbols = new DateFormatSymbols(locale);
                //months = symbols.getShortMonths();
            }
            catch (Exception e)
            {
                months = new String[] { "Jan", "Feb", "Nar",
                                        "Apr", "May", "Jun",
                                        "Jul", "Aug", "Sep",
                                        "Oct", "Nov", "Dec" };
            }
            //
            int year = GetYearAsInt();

            //CultureInfo info = Thread.CurrentThread.CurrentCulture;
            //System.Globalization.GregorianCalendar cal = new System.Globalization.GregorianCalendar(System.Globalization.GregorianCalendarTypes.Localized);
            //
            for (int month = Mnth_ID; month < 13; month++)
            {
                DateTime start = new DateTime(year, month, 1).Date;
                String   name  = months[month - 1] + "-" + GetYY();
                //
                int      day = TimeUtil.GetMonthLastDay(new DateTime(year, month, 1)).Day;
                DateTime end = new DateTime(year, month, day).Date;
                //

                MPeriod period = new MPeriod(this, count, name, start, end);
                if (!period.Save(Get_TrxName())) // Creates Period Control
                {
                    return(false);
                }
                count++;
            }
            for (int month = 1; month < Mnth_ID; month++)
            {
                DateTime start    = new DateTime(year + 1, month, 1).Date;
                string   yearname = Convert.ToString(Convert.ToInt32(GetYY()) + 1);
                String   name     = months[month - 1] + "-" + yearname;
                //
                int      day = TimeUtil.GetMonthLastDay(new DateTime(year + 1, month, 1)).Day;
                DateTime end = new DateTime(year + 1, month, day).Date;
                //
                MPeriod period = new MPeriod(this, count, name, start, end);
                if (!period.Save(Get_TrxName())) // Creates Period Control
                {
                    return(false);
                }
                count++;
            }
            return(true);
        }
コード例 #2
0
        /// <summary>
        /// Create 12 Standard (Jan-Dec) Periods.
        /// Creates also Period Control from DocType.
        /// See DocumentTypeVerify#createPeriodControls(Ctx, int, SvrProcess, String)
        /// </summary>
        /// <param name="locale">locale</param>
        /// <returns>true if created</returns>
        //public Boolean CreateStdPeriods(Locale locale)
        public Boolean CreateStdPeriods(CultureInfo locale)
        {
            if (locale == null)
            {
                //MClient client = MClient.Get(GetCtx());
                //locale = client.getLocale();

                locale = Thread.CurrentThread.CurrentCulture;
            }

            //if (locale == null && Language.getLoginLanguage() != null)
            //    locale = Language.getLoginLanguage().getLocale();
            //if (locale == null)
            //    locale = Env.getLanguage(GetCtx()).getLocale();
            //
            String[] months = null;
            try
            {
                months = DateTimeFormatInfo.CurrentInfo.MonthNames;

                //DateFormatSymbols symbols = new DateFormatSymbols(locale);
                //months = symbols.getShortMonths();
            }
            catch
            {
                months = new String[] { "Jan", "Feb", "Nar",
                                        "Apr", "May", "Jun",
                                        "Jul", "Aug", "Sep",
                                        "Oct", "Nov", "Dec" };
            }
            //
            int year = GetYearAsInt();

            //CultureInfo info = Thread.CurrentThread.CurrentCulture;
            //System.Globalization.GregorianCalendar cal = new System.Globalization.GregorianCalendar(System.Globalization.GregorianCalendarTypes.Localized);
            //
            for (int month = 1; month < 13; month++)
            {
                DateTime start = new DateTime(year, month, 1).Date;
                String   name  = months[month - 1] + "-" + GetYY();
                //
                int      day = TimeUtil.GetMonthLastDay(new DateTime(year, month, 1)).Day;
                DateTime end = new DateTime(year, month, day).Date;
                //
                MPeriod period = new MPeriod(this, month, name, start, end);
                if (!period.Save(Get_TrxName()))        //	Creates Period Control
                {
                    return(false);
                }
            }

            //GregorianCalendar cal = new GregorianCalendar(locale);
            //cal.set(Calendar.HOUR_OF_DAY, 0);
            //cal.set(Calendar.MINUTE, 0);
            //cal.set(Calendar.SECOND, 0);
            //cal.set(Calendar.MILLISECOND, 0);
            ////
            //for (int month = 0; month < 12; month++)
            //{
            //    cal.set(Calendar.YEAR, year);
            //    cal.set(Calendar.MONTH, month);
            //    cal.set(Calendar.DAY_OF_MONTH, 1);
            //    DateTime start = new Timestamp(cal.getTimeInMillis());
            //    String name = months[month] + "-" + getYY();
            //    //
            //    cal.add(Calendar.MONTH, 1);
            //    cal.add(Calendar.DAY_OF_YEAR, -1);
            //    Timestamp end = new Timestamp(cal.getTimeInMillis());
            //    //
            //    MPeriod period = new MPeriod(this, month + 1, name, start, end);
            //    if (!period.Save(Get_TrxName()))	//	Creates Period Control
            //        return false;
            //}
            return(true);
        }