示例#1
0
        private List <CalendarCellInfo> CreateCalendarCellInfoList_Calendar(PageCaller PG, string StrCellInfoList)
        {
            List <CalendarCellInfo> CalendarCellInfoList = new List <CalendarCellInfo>();

            string[] ArStrDateShiftList         = StrCellInfoList.Split(new char[] { '%' });
            string   TempArStrDateShiftListPart = string.Empty;

            foreach (string ArStrDateShiftListPart in ArStrDateShiftList)
            {
                if (ArStrDateShiftListPart != string.Empty && ArStrDateShiftListPart.Contains("SID"))
                {
                    TempArStrDateShiftListPart = ArStrDateShiftListPart.Replace("SID=", string.Empty).Replace("M=", string.Empty).Replace("D=", string.Empty);
                    string[] ArDateShift = TempArStrDateShiftListPart.Split(new char[] { '#' });
                    int      month       = int.Parse(ArDateShift[0]);
                    int      day         = int.Parse(ArDateShift[1]);

                    CalendarCellInfo calendarCellInfo = new CalendarCellInfo();
                    calendarCellInfo.Month = month;
                    calendarCellInfo.Day   = day;
                    if (PG == PageCaller.WorkGroups)
                    {
                        decimal shiftID = decimal.Parse(ArDateShift[2]);
                        calendarCellInfo.ShiftID = shiftID;
                    }

                    CalendarCellInfoList.Add(calendarCellInfo);
                }
            }
            return(CalendarCellInfoList);
        }
示例#2
0
        /// <summary>
        /// باتوجه به سال و گروه کاری مشخص شده لیستی از اطلاعات جزیات انتساب شیفت به گروه کاری را برمیگرداند
        /// </summary>
        /// <param name="workGroupId"></param>
        /// <param name="year"></param>
        /// <returns></returns>
        public IList <CalendarCellInfo> GetAll(decimal workGroupId, int year)
        {
            try
            {
                DateTime minDate = new DateTime();
                DateTime maxDate = new DateTime();

                if (sysLangruage == SysLanguageResource.Parsi)
                {
                    minDate = Utility.ToMildiDate(String.Format("{0}/01/01", year));
                    maxDate = Utility.ToMildiDate(String.Format("{0}/01/01", year + 1));
                }
                else if (sysLangruage == SysLanguageResource.English)
                {
                    minDate = new DateTime(year, 1, 1);
                    maxDate = new DateTime(year + 1, 1, 1);
                }

                IList <CalendarCellInfo> result = new List <CalendarCellInfo>();

                IList <WorkGroupDetail> list =
                    wGDRepository.GetByCriteria(new CriteriaStruct(Utility.GetPropertyName(() => new WorkGroupDetail().WorkGroup), new WorkGroup()
                {
                    ID = workGroupId
                }),
                                                new CriteriaStruct(Utility.GetPropertyName(() => new WorkGroupDetail().Date), minDate, CriteriaOperation.GreaterEqThan),
                                                new CriteriaStruct(Utility.GetPropertyName(() => new WorkGroupDetail().Date), maxDate, CriteriaOperation.LessThan));

                list = list.OrderBy(x => x.Date).ToList();
                foreach (WorkGroupDetail wgd in list)
                {
                    CalendarCellInfo cellInfo = new CalendarCellInfo();

                    if (sysLangruage == SysLanguageResource.Parsi)
                    {
                        PersianDateTime persianDateTime = new PersianDateTime(wgd.Date);
                        cellInfo.Day     = persianDateTime.Day;
                        cellInfo.Month   = persianDateTime.Month;
                        cellInfo.ShiftID = wgd.Shift.ID;
                    }
                    else if (sysLangruage == SysLanguageResource.English)
                    {
                        cellInfo.Day   = wgd.Date.Day;
                        cellInfo.Month = wgd.Date.Month;
                    }
                    cellInfo.Title = wgd.Shift.Name;
                    cellInfo.Color = wgd.Shift.Color;

                    result.Add(cellInfo);
                }
                return(result);
            }
            catch (Exception ex)
            {
                LogException(ex, "BWorkGroupCalendar", "GetAll");
                throw ex;
            }
        }
示例#3
0
        /// <summary>
        /// لیست تقویم را برمیگرداند
        /// اگر نوع تقویم رسمی و آیتم های آن در دیتابیس خالی باشد آنگاه تعطیلات تقویم پیشفرض را از دیتابیس بارگزاری میکند
        /// </summary>
        /// <param name="year"></param>
        /// <param name="calendarTypeID"></param>
        /// <param name="CalendarTypeCustomId">اگر رسمی باشد تعطلات سال برگردانده میشود</param>
        /// <returns></returns>
        public IList <CalendarCellInfo> GetCalendarList(int year, decimal calendarTypeID)
        {
            DateTime yearStart, yearEnd;

            if (BLanguage.CurrentSystemLanguage == LanguagesName.Parsi)
            {
                string date = String.Format("{0}/01/01", year);
                yearStart = Utility.ToMildiDate(date);
                date      = String.Format("{0}/12/{1}", year, Utility.GetEndOfPersianMonth(year, 12));
                yearEnd   = Utility.ToMildiDate(date);
            }
            else
            {
                yearStart = new DateTime(year, 1, 1);
                yearEnd   = new DateTime(year, 12, Utility.GetEndOfMiladiMonth(year, 12));
            }

            IList <Calendar> calendarList = calendarRepository.GetByCriteria(new CriteriaStruct(Utility.GetPropertyName(() => new Calendar().CalendarType), new CalendarType()
            {
                ID = calendarTypeID
            }),
                                                                             new CriteriaStruct(Utility.GetPropertyName(() => new HolidaysTemplate().Date), yearStart, CriteriaOperation.GreaterEqThan),
                                                                             new CriteriaStruct(Utility.GetPropertyName(() => new HolidaysTemplate().Date), yearEnd, CriteriaOperation.LessEqThan));

            IList <CalendarCellInfo> resultList   = new List <CalendarCellInfo>();
            CalendarType             calendarType = base.GetByID(calendarTypeID);

            if (calendarList.Count == 0 && calendarType.HolidayTemplateList != null)
            {
                ///load default Holidays
                IList <HolidaysTemplate> holidays = calendarType.HolidayTemplateList;

                holidays = holidays.Where(x => x.Date >= yearStart && x.Date <= yearEnd)
                           .ToList <HolidaysTemplate>();

                foreach (HolidaysTemplate holiday in holidays)
                {
                    Calendar cal = new Calendar();
                    cal.CalendarType = new CalendarType()
                    {
                        ID = calendarTypeID
                    };
                    cal.Date = holiday.Date;
                    CalendarCellInfo cell = new CalendarCellInfo(cal);
                    calendarList.Add(cal);
                }
            }
            var result = from calendar in calendarList
                         select new CalendarCellInfo(calendar);

            resultList = result.ToList <CalendarCellInfo>();
            return(resultList);
        }
示例#4
0
        /// <summary>
        /// تکرار دوره
        /// </summary>
        /// <param name="year"></param>
        /// <param name="startMonth"></param>
        /// <param name="startDay"></param>
        /// <param name="endMonth"></param>
        /// <param name="endDay"></param>
        /// <param name="holidayTypes"></param>
        /// <param name="cellInfoList"></param>
        public IList <CalendarCellInfo> RepetitionPeriod(int year, int startMonth, int startDay, int endMonth, int endDay, IList <decimal> holidayTypes, IList <CalendarCellInfo> cellInfoList)
        {
            try
            {
                DateTime startDate, endDate, endOfYear;
                if (sysLangruage == SysLanguageResource.Parsi)
                {
                    startDate = Utility.ToMildiDate(String.Format("{0}/{1}/{2}", year, startMonth, startDay));
                    endDate   = Utility.ToMildiDate(String.Format("{0}/{1}/{2}", year, endMonth, endDay));
                    endOfYear = Utility.ToMildiDate(String.Format("{0}/{1}/{2}", year, 12, Utility.GetEndOfPersianMonth(year, 12)));
                }
                else
                {
                    startDate = new DateTime(year, startMonth, startDay);
                    endDate   = new DateTime(year, endMonth, endDay);
                    endOfYear = new DateTime(year, 12, DateTime.DaysInMonth(year, 12));
                }
                if (startDate > endDate)
                {
                    UIValidationExceptions exception = new UIValidationExceptions();
                    exception.Add(ExceptionResourceKeys.WorkGroupCalendarPriodDateIsNotValid, "تاریخ ابتدا از انتها بزرگتر است", ExceptionSrc);
                    throw exception;
                }
                IList <CalendarCellInfo> list      = new List <CalendarCellInfo>();
                IList <CalendarCellInfo> cells     = new List <CalendarCellInfo>();
                IList <CalendarCellInfo> result    = new List <CalendarCellInfo>();
                IList <Shift>            shiftList = new BShift().GetAll();
                //looking for item in parameter list by date
                for (DateTime date = startDate; date <= endDate; date = date.AddDays(1))
                {
                    int day = 0, month = 0;
                    if (sysLangruage == SysLanguageResource.Parsi)
                    {
                        day   = new PersianDateTime(date).Day;
                        month = new PersianDateTime(date).Month;
                    }
                    else
                    {
                        day   = date.Day;
                        month = date.Month;
                    }
                    CalendarCellInfo info = cellInfoList.Where(x => x.Day == day && x.Month == month).FirstOrDefault();
                    if (info != null)
                    {
                        list.Add(info);
                    }
                    else
                    {
                        list.Add(null);
                    }
                }

                if (list.Count == 0 || list.Where(x => x != null).Count() == 0)
                {
                    UIValidationExceptions exception = new UIValidationExceptions();
                    exception.Add(ExceptionResourceKeys.WorkGroupCalendarPriodIsEmpty, "در بازه زمانی مشخص شده شیفتی انتساب دهده نشده است", ExceptionSrc);
                    throw exception;
                }

                for (DateTime index = startDate; index <= endOfYear; index = index.AddDays(list.Count))
                {
                    for (int i = 0; i < list.Count && index.AddDays(i) <= endOfYear; i++)
                    {
                        if (list[i] != null)
                        {
                            CalendarCellInfo info = new CalendarCellInfo();
                            info.ShiftID = list[i].ShiftID;
                            Shift shift = shiftList.Where(x => x.ID == list[i].ShiftID).FirstOrDefault();
                            info.Color = shift != null ? shift.Color : "";
                            info.Title = list[i].Title;
                            if (sysLangruage == SysLanguageResource.Parsi)
                            {
                                info.Day   = new PersianDateTime(index.AddDays(i)).Day;
                                info.Month = new PersianDateTime(index.AddDays(i)).Month;
                            }
                            else
                            {
                                info.Day   = index.AddDays(i).Day;
                                info.Month = index.AddDays(i).Month;
                            }
                            cells.Add(info);
                        }
                    }
                }
                //apply holidays
                List <CalendarCellInfo> holidays = new List <CalendarCellInfo>();
                if (holidayTypes != null)
                {
                    foreach (decimal id in holidayTypes)
                    {
                        holidays.AddRange(new BCalendarType().GetCalendarList(year, id));
                    }
                }
                foreach (CalendarCellInfo cell in cells)
                {
                    if (holidays.Where(x => x.Day == cell.Day && x.Month == cell.Month).Count() == 0)
                    {
                        result.Add(cell);
                    }
                }
                return(result);
            }
            catch (Exception ex)
            {
                LogException(ex, "BWorkGroupCalendar", "RepetitionPeriod");
                throw ex;
            }
        }