public DepartmentTimeline Add(DepartmentTimeline data)
 {
     DepartmentTimelineDAO.Add(data);
     return data;
 }
 public void Delete(DepartmentTimeline data)
 {
     DepartmentTimelineDAO.Delete(data);
 }
 public void Update(DepartmentTimeline data)
 {
     DepartmentTimelineDAO.Update(data);
 }
        public void ProcessPeriod(bool isSubmitPeriod)
        {
            // Save the end of period
            // select 5 day nearest
            //IList departmentTimelineList = new ArrayList();
            ObjectCriteria crit = new ObjectCriteria();
            crit.AddOrder("EndTime", false);
            crit.MaxResult = 5;
            IList list = DepartmentTimelineDAO.FindAll(crit);
            DateTime startTime = DateUtility.ZeroTime(DateTime.Now);
            if (list != null && list.Count > 0)
            {
                // update end time of nearest 5 timeline for sure transparency
                DepartmentTimeline departmentTimeline = (DepartmentTimeline) list[0];
                DateTime lastSubmitEndTime = departmentTimeline.EndTime;

                // get days which customer do not submit period
                TimeSpan timeSpan = DateUtility.ZeroTime(DateTime.Now).Subtract(DateUtility.ZeroTime(lastSubmitEndTime));
                // fix those days in order we can sync for today.

                startTime = lastSubmitEndTime.AddSeconds(1);
                for (int i = 0; i < timeSpan.Days - 1; i++)
                {
                    DateTime nextDateTime = lastSubmitEndTime.AddDays(i + 1);
                    DepartmentTimeline fixTimeline = new DepartmentTimeline();
                    fixTimeline.WorkingDay = DateUtility.ZeroTime(nextDateTime);
                    fixTimeline.CreateDate = DateUtility.MaxTime(nextDateTime);
                    fixTimeline.UpdateDate = DateUtility.MaxTime(nextDateTime);
                    fixTimeline.CreateId = ClientInfo.getInstance().LoggedUser.Name;
                    fixTimeline.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                    fixTimeline.StartTime = startTime;
                    fixTimeline.EndTime = DateUtility.MaxTime(nextDateTime);
                    DepartmentTimelinePK fixTimelinePK = new DepartmentTimelinePK
                                                             {
                                                                 DepartmentId = CurrentDepartment.Get().DepartmentId,
                                                                 Period = nextDateTime.DayOfYear
                                                             };

                    fixTimeline.DepartmentTimelinePK = fixTimelinePK;
                    DepartmentTimelineDAO.Add(fixTimeline);
                    startTime = fixTimeline.EndTime.AddSeconds(1);
                }

            }
            // If submit period ( ket so ) then we ' ket so '
            DepartmentTimeline timeline = null;
            if (isSubmitPeriod)
            {
                timeline = new DepartmentTimeline();
                timeline.WorkingDay = DateUtility.ZeroTime(DateTime.Now);
                timeline.CreateDate = DateTime.Now;
                timeline.UpdateDate = DateTime.Now;
                timeline.CreateId = ClientInfo.getInstance().LoggedUser.Name;
                timeline.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                timeline.StartTime = startTime;
                timeline.EndTime = DateTime.Now;
                DepartmentTimelinePK timelinePK = new DepartmentTimelinePK
                                                  {
                                                      DepartmentId = CurrentDepartment.Get().DepartmentId,
                                                      Period = DateTime.Now.DayOfYear
                                                  };
                var dbTimeline = DepartmentTimelineDAO.FindById(timelinePK);
                if (dbTimeline != null)
                {
                    throw new BusinessException("Ngày hôm nay đã kết sổ");
                }
                timeline.DepartmentTimelinePK = timelinePK;
                DepartmentTimelineDAO.Add(timeline);

                //departmentTimelineList.Add(timeline);
            }
        }
 /// <summary>
 /// Delete DepartmentTimeline from database.
 /// </summary>
 /// <param name="data"></param>
 /// <returns></returns>
 public void Delete(DepartmentTimeline data)
 {
     HibernateTemplate.Delete(data);
 }
 /// <summary>
 /// Add DepartmentTimeline to database.
 /// </summary>
 /// <param name="data"></param>
 /// <returns></returns>
 public DepartmentTimeline Add(DepartmentTimeline data)
 {
     HibernateTemplate.Save(data);
     return data;
 }
 /// <summary>
 /// Update DepartmentTimeline to database.
 /// </summary>
 /// <param name="data"></param>
 /// <returns></returns>
 public void Update(DepartmentTimeline data)
 {
     HibernateTemplate.Update(data);
 }