示例#1
0
 public FactoryCalendar(ref FactoryCalendar rhs)
 {
     if (m_working_days == null)
     {
         m_working_days = new List<YearMonthDay>();
     }
     if (m_validity_start == null)
     {
         m_validity_start = rhs.m_validity_start;
     }
 }
示例#2
0
 public int get_working_day_same_or_before(YearMonthDay date)
 {
     int result = -1;
     if (m_validity_start.get_date() <= date.get_date())
     {
         result = lower_bound(m_working_days, 0, m_working_days.Count(), date);
         if ((result == 0) || (date.get_date() < m_working_days[result].get_date()))
         {
             if (m_working_days[result].get_date() != m_working_days[0].get_date())
             {
                 --result;
             }
             else
             {
                 result = -1;
             }
         }
     }
     return result;
 }
示例#3
0
        public int get_diastance_in_working_days(string factory_calendar_id, YearMonthDay start_date, YearMonthDay end_date)
        {
            int result = 0;

            try
            {
                FactoryCalendar factory_calendar = get_factory_calendar(factory_calendar_id);
                YearMonthDay start_date_iter = factory_calendar.get_working_day_same_or_later(start_date);
                YearMonthDay end_date_iter = factory_calendar.get_working_day_same_or_later(end_date);

                int start_position = factory_calendar.get_position(start_date_iter);
                int end_position = factory_calendar.get_position(end_date_iter);
                result = end_position - start_position;
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return result;
        }
示例#4
0
        public YearMonthDay get_end_date(string factory_calendar_id, YearMonthDay start_date, int working_days)
        {
            YearMonthDay result = null;
            FactoryCalendar factory_calendar = null;
            YearMonthDay start_date_iter = null;

            try
            {
                factory_calendar = get_factory_calendar(factory_calendar_id);
                start_date_iter = factory_calendar.get_working_day_same_or_later(start_date);

                if (factory_calendar.is_contained(start_date_iter, working_days))
                {
                    int idx = factory_calendar.get_position(start_date_iter);
                    result = factory_calendar.get_factory_calendar(idx + working_days - 1);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return result;
        }
示例#5
0
 public int get_position(YearMonthDay rhs)
 {
     return m_working_days.FindIndex(x => x.get_date() == rhs.get_date());
 }
示例#6
0
 public void add_working_day(YearMonthDay date)
 {
     m_working_days.Add(date);
 }
示例#7
0
 public bool LessThanOrEqualTo(YearMonthDay rhs)
 {
     bool result = (m_value <= rhs.m_value);
     return result;
 }
示例#8
0
 public bool LessThan(YearMonthDay rhs)
 {
     bool result = (m_value < rhs.m_value);
     return result;
 }
示例#9
0
        private void load_factory_calendar(string factory_calendar_id, ref FactoryCalendar factory_calendar)
        {
            string fields = "[YEAR],[MON01],[MON02],[MON03],[MON04],[MON05],[MON06],[MON07],[MON08],[MON09],[MON10],[MON11],[MON12]";
            string table = "[FCalendar]";
            string sorting = "[YEAR]";
            string query = string.Format("SELECT {0} FROM {1} ORDER BY {2}", fields, table, sorting);

            try
            {
                if (factory_calendar == null)
                {
                    factory_calendar = new FactoryCalendar();
                }

                DataSet ds = null;
                ds = GetDataSet(query);

                if (ds != null)
                {
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        int year = 0;
                        bool is_first_year = true;
                        foreach (DataRow dr in ds.Tables[0].Rows)
                        {
                            year = int.Parse(dr["YEAR"].ToString());

                            // Set first year as start of validity
                            if (is_first_year)
                            {
                                is_first_year = false;
                                YearMonthDay validity_start = new YearMonthDay(year, 1, 1);
                                factory_calendar.set_validity_start(validity_start);
                            }

                            // Add working days for each month of the year
                            for (int month = 1; month <= 12; month++)
                            {
                                add_working_days(ref factory_calendar, year, month, dr[string.Format("MON{0}", month.ToString("D2"))].ToString());
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#10
0
        private int lower_bound(List<YearMonthDay> objDate, int begin, int end, YearMonthDay date)
        {
            int index = -1;
            YearMonthDay iter = null;
            YearMonthDay iterMax = null;

            if (end > objDate.Count)
            {
                end = objDate.Count;
            }

            for (int i = begin; i < end; i++)
            {
                iter = objDate[i];
                if (iter.get_date() >= date.get_date())
                {
                    index = i;
                    return index;
                }
                iterMax = iter;
            }
            return index;
        }
示例#11
0
 public void set_validity_start(YearMonthDay validity_start)
 {
     m_validity_start = validity_start;
 }
示例#12
0
 public void process()
 {
     try
     {
         YearMonthDay start_date = new YearMonthDay(m_start_date_value);
         YearMonthDay end_date = new YearMonthDay(m_end_date_value);
         m_result = get_diastance_in_working_days(m_factory_calendar_id_value, start_date, end_date);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
示例#13
0
 public void process()
 {
     try
     {
         YearMonthDay end_date = new YearMonthDay(m_end_date_value);
         m_result = count_back_duration(m_factory_calendar_id_value, end_date, m_working_days);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
示例#14
0
 public YearMonthDay count_back_duration(string factory_calendar_id, YearMonthDay end_date, int working_days)
 {
     YearMonthDay result = null;
     return result;
 }
示例#15
0
 public YearMonthDay get_working_day_same_or_later(YearMonthDay date)
 {
     int result = 0;
     if (m_validity_start.get_date() <= date.get_date())
     {
         result = lower_bound(m_working_days, 0, m_working_days.Count(), date);
     }
     return m_working_days[result];
 }
示例#16
0
 public bool EqualTo(YearMonthDay rhs)
 {
     bool result = (m_value == rhs.m_value);
     return result;
 }
示例#17
0
        public bool is_contained(YearMonthDay day_iter, int distance)
        {
            int int_day_index = m_working_days.FindIndex(x => x.get_date() == day_iter.get_date());

            if (distance >= 0)
            {
                int distnace_to_end = m_working_days.Count - int_day_index;
                if (distance >= distnace_to_end)
                {
                    return false;
                }
            }
            else
            {
                int distance_to_begin = 0 - int_day_index;
                if (distance < distance_to_begin)
                {
                    return false;
                }
            }

            return true;
        }
示例#18
0
 private void add_working_days(ref FactoryCalendar factory_calendar, int year, int month, string day_spec)
 {
     try
     {
         for (int day_num = 0; day_num < day_spec.Length; day_num++)
         {
             int day = int.Parse(day_spec.Substring(day_num, 1));
             if (day == 1)
             {
                 YearMonthDay working_day = new YearMonthDay(year, month, day_num + 1);
                 factory_calendar.add_working_day(working_day);
             }
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }