Example #1
0
        public IHttpActionResult Delete(HolidayType holidayType, string salesAreaName)
        {
            if (string.IsNullOrEmpty(salesAreaName) || !ModelState.IsValid)
            {
                return(this.Error().InvalidParameters());
            }

            var salesArea = _salesAreaRepository.FindByName(salesAreaName);

            if (salesArea == null)
            {
                return(NotFound());
            }

            switch (holidayType)
            {
            case HolidayType.PublicHoliday:
                salesArea.PublicHolidays.Clear();
                break;

            case HolidayType.SchoolHoliday:
                salesArea.SchoolHolidays.Clear();
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(holidayType), holidayType, null);
            }
            _salesAreaRepository.Update(salesArea);
            return(Ok());
        }
Example #2
0
        public void PostHoliday()
        {
            //Admin Login
            var login = new EmployeeViewModel()
            {
                Email = "*****@*****.**", Password = "******"
            };
            //Team Leader Login
            //var login = new EmployeeViewModel() { Email = "*****@*****.**", Password = "******" };
            //Employee Login
            //var login = new EmployeeViewModel() { Email = "*****@*****.**", Password = "******" };
            var loginJson   = JsonConvert.SerializeObject(login);
            var loginResult = client.PostAsync("Account/Login", new StringContent(loginJson, Encoding.UTF8, "application/json")).Result;


            //var holiday = new HolidayType { Date = DateTime.Now, Name = "blah" };
            var holiday = new HolidayType {
                Name = null
            };
            var holidayJson     = JsonConvert.SerializeObject(holiday);
            var response        = client.PostAsync("api/HolidayType", new StringContent(holidayJson, Encoding.UTF8, "application/Json")).Result;
            var responseContent = response.Content.ReadAsStringAsync().Result;
            var returnedHoliday = JsonConvert.DeserializeObject <HolidayType>(responseContent);

            Assert.AreNotEqual(0, returnedHoliday.Id);
        }
Example #3
0
        private RuleHoliday(Guid?id, EntityStatus status, ActionType action, Guid?userId, Guid countryId, Guid?stateId, string countryIsoCode, string stateIsoCode, string cityCode, string cityName, HolidayType holidayType, string nativeHolidayName, string englishHolidayName, int?month, int?day, bool optional, string bussinessRule, string comments) : base(id, status, action, userId)
        {
            CountryId          = countryId;
            StateId            = stateId;
            CountryIsoCode     = countryIsoCode.HasValue() ? countryIsoCode.Trim().ToUpper() : countryIsoCode;
            StateIsoCode       = stateIsoCode.HasValue() ? stateIsoCode.Trim().ToUpper() : stateIsoCode;
            CityId             = cityName.HasValue() ? cityName.ToMD5HashString() : cityName;
            CityCode           = cityCode.HasValue() ? cityCode.Trim() : cityCode;
            CityName           = cityName.HasValue() ? cityName.Replace("  ", " ").Trim() : cityName;
            HolidayType        = holidayType;
            NativeHolidayName  = nativeHolidayName.HasValue() ? nativeHolidayName.Replace("  ", " ").Trim() : nativeHolidayName;
            EnglishHolidayName = englishHolidayName.HasValue() ? englishHolidayName.Replace("  ", " ").Trim() : englishHolidayName;
            Month         = month;
            Day           = day;
            Optional      = optional;
            BussinessRule = bussinessRule.HasValue() ? bussinessRule.Replace(" ", "").Trim().ToLower() : bussinessRule;
            Comments      = comments.HasValue() ? comments.Replace("  ", " ").Trim() : comments;

            var baseKey = CountryIsoCode + StateIsoCode + CityId + HolidayType.Key.ToString() + NativeHolidayName + BussinessRule;

            if (Month.HasValue)
            {
                baseKey += Month.Value.ToString();
            }
            if (Day.HasValue)
            {
                baseKey += Day.Value.ToString();
            }

            ComposeKey = baseKey.ToMD5HashString();
        }
Example #4
0
 /// <summary>
 /// インスタンスを生成します。
 /// </summary>
 /// <param name="holidayType">祝祭日の日付パターン</param>
 /// <param name="name">祝祭日名</param>
 /// <param name="substituteFlg">振替休日フラグ</param>
 /// <param name="nationalHolidayFlg">国民の休日フラグ</param>
 protected Holiday(HolidayType holidayType, string name = null, bool substituteFlg = true, bool nationalHolidayFlg = true)
 {
     this.holidayType = holidayType;
     this.name = name;
     this.substituteFlg = substituteFlg;
     this.nationalHolidayFlg = nationalHolidayFlg;
 }
Example #5
0
        public void CreateHoliday_MustCreateInstaceOfHoliday(string id, string status, string typeProcess, string user, string country, string state, string date, string type, bool optional, string nativeDescription, string alternativeDescription, string countryCode, string stateCode, string cityName, string cityCode)
        {
            // Arrange
            Holiday      holiday;
            Guid         entityId     = string.IsNullOrEmpty(id) ? Guid.Empty : Guid.Parse(id);
            EntityStatus entityStatus = EntityStatus.GetByName(status);
            ActionType   action       = ActionType.GetByName(typeProcess);
            Guid         userId       = string.IsNullOrEmpty(user) ? Guid.Empty : Guid.Parse(user);
            Guid         countryId    = string.IsNullOrEmpty(country) ? Guid.Empty : Guid.Parse(country);
            Guid         stateId      = string.IsNullOrEmpty(state) ? Guid.Empty : Guid.Parse(state);
            DateTime     holidayDate  = DateTime.Parse(date);
            HolidayType  holidayType  = HolidayType.GetByName(type);

            // Act
            holiday = Holiday.CreateHoliday(entityId, entityStatus, action, userId, countryId, stateId, holidayDate, holidayType, optional, nativeDescription, alternativeDescription, countryCode, stateCode, cityName, cityCode);

            // Assert
            Assert.NotNull(holiday);
            Assert.True(holiday.Id != entityId &&
                        holiday.Status == entityStatus &&
                        holiday.Action == action &&
                        (holiday.RegisteredBy == userId || holiday.ModifiedBy == userId) &&
                        holiday.CountryId == countryId &&
                        holiday.StateId == stateId &&
                        holiday.HolidayDate == holidayDate &&
                        holiday.HolidayType == holidayType &&
                        holiday.Optional == optional &&
                        holiday.NativeDescription == nativeDescription &&
                        holiday.AlternativeDescription == alternativeDescription &&
                        holiday.CountryCode == countryCode &&
                        holiday.StateCode == stateCode &&
                        holiday.CityName == cityName &&
                        holiday.CityCode == cityCode);
        }
        public async Task <IActionResult> Edit(int id, [Bind("HolidayTypeID,Type")] HolidayType holidayType)
        {
            if (id != holidayType.HolidayTypeID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(holidayType);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!HolidayTypeExists(holidayType.HolidayTypeID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(holidayType));
        }
Example #7
0
        public void PutHoliday()
        {
            //Admin Login
            //var login = new EmployeeViewModel() { Email = "*****@*****.**", Password = "******" };
            //Team Leader Login
            var login = new EmployeeViewModel()
            {
                Email = "*****@*****.**", Password = "******"
            };
            //Employee Login
            //var login = new EmployeeViewModel() { Email = "*****@*****.**", Password = "******" };
            var loginJson   = JsonConvert.SerializeObject(login);
            var loginResult = client.PostAsync("Account/Login", new StringContent(loginJson, Encoding.UTF8, "application/json")).Result;


            var holiday = client.GetAsync("api/HolidayType/13").Result;
            var content = holiday.Content.ReadAsStringAsync().Result;
            var update  = JsonConvert.DeserializeObject <HolidayType>(content);


            var editedHoliday = new HolidayType {
                Id = 13, Date = DateTime.Now, Name = "ABCD", CreatedOn = update.CreatedOn
            };

            var editedHolidayJson = JsonConvert.SerializeObject(editedHoliday);

            var response = client.PutAsync("api/HolidayType/13", new StringContent(editedHolidayJson, Encoding.UTF8, "application/Json")).Result;

            var responseContent = response.Content.ReadAsStringAsync().Result;

            var returnedEditedHoliday = JsonConvert.DeserializeObject <HolidayType>(responseContent);


            Assert.AreEqual("ABCD", returnedEditedHoliday.Name);
        }
Example #8
0
        /// <summary>
        /// 获得分页列表,无论是否是缓存实体都从数据库直接拿取数据
        /// </summary>
        /// <param name="pPageIndex">页数</param>
        /// <param name="pPageSize">每页列表</param>
        /// <param name="pOrderBy">排序</param>
        /// <param name="pSortExpression">排序字段</param>
        /// <param name="pRecordCount">列表行数</param>
        /// <returns>数据分页</returns>
        public static List <HolidayTypeInfo> GetPagedList(int pPageIndex, int pPageSize, SortDirection pOrderBy, string pSortExpression, out int pRecordCount)
        {
            if (pPageIndex <= 1)
            {
                pPageIndex = 1;
            }
            List <HolidayTypeInfo> list = new List <HolidayTypeInfo>();

            Query q = HolidayType.CreateQuery();

            q.PageIndex = pPageIndex;
            q.PageSize  = pPageSize;
            q.ORDER_BY(pSortExpression, pOrderBy.ToString());
            HolidayTypeCollection collection = new  HolidayTypeCollection();

            collection.LoadAndCloseReader(q.ExecuteReader());

            foreach (HolidayType holidayType  in collection)
            {
                HolidayTypeInfo holidayTypeInfo = new HolidayTypeInfo();
                LoadFromDAL(holidayTypeInfo, holidayType);
                list.Add(holidayTypeInfo);
            }
            pRecordCount = q.GetRecordCount();

            return(list);
        }
Example #9
0
        //数据持久化
        internal static void  SaveToDb(HolidayTypeInfo pHolidayTypeInfo, HolidayType pHolidayType, bool pIsNew)
        {
            pHolidayType.HolidayTypeId   = pHolidayTypeInfo.holidayTypeId;
            pHolidayType.HolidayTypeName = pHolidayTypeInfo.holidayTypeName;
            pHolidayType.IsNew           = pIsNew;
            string UserName = SubsonicHelper.GetUserName();

            try
            {
                pHolidayType.Save(UserName);
            }
            catch (Exception ex)
            {
                LogManager.getInstance().getLogger(typeof(HolidayTypeInfo)).Error(ex);
                if (ex.Message.Contains("插入重复键"))               //违反了唯一键
                {
                    throw new AppException("此对象已经存在");          //此处等待优化可以从唯一约束中直接取出提示来,如果没有的话,默认为原始的出错提示
                }
                throw new AppException("保存失败");
            }
            pHolidayTypeInfo.holidayTypeId = pHolidayType.HolidayTypeId;
            //如果缓存存在,更新缓存
            if (CachedEntityCommander.IsTypeRegistered(typeof(HolidayTypeInfo)))
            {
                ResetCache();
            }
        }
 /// <summary>Gets the holidays for a specific year as a collection of <see cref="DateInfo"/> instances, where
 /// in general the language depending name of the holiday is given too.
 /// </summary>
 /// <param name="year">The year.</param>
 /// <param name="holidaySet">A set of <see cref="DateInfo"/> instances to add the holidays of the <paramref name="year"/> (output).</param>
 /// <param name="holidayType">The type of the holidays to take into account.</param>
 /// <exception cref="NullReferenceException">Thrown, if <paramref name="holidaySet"/> is <c>null</c>.</exception>
 public void GetHolidays(int year, HashSet <DateInfo> holidaySet, HolidayType holidayType = HolidayType.PublicHolidays)
 {
     if (holidaySet == null)
     {
         throw new ArgumentNullException("holidaySet");
     }
     // nothing to do, no holidays available
 }
        /// <summary>Gets the holidays for a specific year as a collection of <see cref="DateInfo"/> instances, where
        /// in general the language depending name of the holiday is given too.
        /// </summary>
        /// <param name="year">The year.</param>
        /// <param name="holidaySet">A set of <see cref="DateInfo"/> instances to add the holidays of the <paramref name="year"/> (output).</param>
        /// <param name="holidayType">The type of the holidays to take into account.</param>
        /// <exception cref="NullReferenceException">Thrown, if <paramref name="holidaySet"/> is <c>null</c>.</exception>
        public void GetHolidays(int year, HashSet <DateInfo> holidaySet, HolidayType holidayType = HolidayType.PublicHolidays)
        {
            /* 1. insert weekends into the holiday table: */
            if ((holidayType & HolidayType.Weekends) == HolidayType.Weekends)
            {
                WeekendRepresentation.GetWeekendDateInfos(year, holidaySet);
            }
            /* 2.) insert public holidays into the holiday table: */
            if ((holidayType & HolidayType.PublicHolidays) == HolidayType.PublicHolidays)
            {
                SortedList <DateTime, IHoliday> rollingHolidaysOnWeekend = new SortedList <DateTime, IHoliday>();

                /* we assume, that the holidays are pairwise distinct:
                 * A. step: insert the (public) holidays which are not on saturday/sunday and remember the holidays
                 *           which are on a saturday/sunday if this holiday will move to another day.
                 */
                foreach (IHoliday holiday in HolidayCollection)
                {
                    DateInfo holidayDateInfo;
                    if (holiday.TryGetValue(year, out holidayDateInfo))
                    {
                        if ((holidayDateInfo.DayOfWeek != DayOfWeek.Saturday) && (holidayDateInfo.DayOfWeek != DayOfWeek.Sunday))
                        {
                            holidaySet.Add(holidayDateInfo);
                        }
                        else
                        {
                            /* replace the saturday/sunday by this holiday - this is just for presentation reason */
                            if (holidaySet.Contains(holidayDateInfo))
                            {
                                holidaySet.Remove(holidayDateInfo);                         // this is a trick, 'Remove' checkes the date-component only!
                            }
                            holidaySet.Add(holidayDateInfo);                                // the string component changes only!

                            if (holiday.HolidayRollingType != HolidayRollingType.NoRolling) /* one holiday on some weekend day and the holiday 'moves' */
                            {
                                rollingHolidaysOnWeekend.Add(holidayDateInfo.Date, holiday);
                            }
                        }
                    }
                }

                /* B. step: move holidays which are on some saturday/sunday and the rolling-flag is set to the next or previous
                 *          non-holiday. This will be done iterative because of the case when two holidays are one after the other.*/
                while (rollingHolidaysOnWeekend.Count != 0)
                {
                    DateTime holidayDate = rollingHolidaysOnWeekend.Keys[0];

                    int numberOfDaysToAdd = (int)rollingHolidaysOnWeekend.Values[0].HolidayRollingType;  // = 1 for 'forward' and -1 for 'backward'
                    while ((holidayDate.DayOfWeek == DayOfWeek.Saturday) || (holidayDate.DayOfWeek == DayOfWeek.Sunday) || (holidaySet.Contains(new DateInfo(holidayDate))))
                    {
                        holidayDate = holidayDate.AddDays(numberOfDaysToAdd);
                    }
                    holidaySet.Add(new DateInfo(holidayDate, rollingHolidaysOnWeekend.Values[0].Name + "*"));
                    rollingHolidaysOnWeekend.RemoveAt(0);
                }
            }
        }
Example #12
0
 public Holiday(string section, string uid, HolidayType type, string name, TravelType travel, Country country)
 {
     this.Type = type;
     this.LongName = name;
     this.Travel = travel;
     this.Country = country;
     this.Uid = uid;
     Holiday.Section = section;
 }
Example #13
0
 public Holiday(string section, string uid, HolidayType type, string name, TravelType travel, Country country)
 {
     this.Type       = type;
     this.LongName   = name;
     this.Travel     = travel;
     this.Country    = country;
     this.Uid        = uid;
     Holiday.Section = section;
 }
Example #14
0
 public Holiday(string section, string uid, HolidayType type, string name, TravelType travel, Country country)
 {
     Type = type;
     LongName = name;
     Travel = travel;
     Country = country;
     Uid = uid;
     Section = section;
 }
        public override int GetHashCode()
        {
            int hash = 1;

            if (HolidayType != 0)
            {
                hash ^= HolidayType.GetHashCode();
            }
            hash ^= dropItem_.GetHashCode();
            return(hash);
        }
        public async Task <IActionResult> Create([Bind("HolidayTypeID,Type")] HolidayType holidayType)
        {
            if (ModelState.IsValid)
            {
                _context.Add(holidayType);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(holidayType));
        }
Example #17
0
 private Holiday CreateHoliday(HolidayType type, int year, string status, string dates)
 {
     if (type.HolidayTypeId != 0)
     {
         return(new Holiday {
             HolidayTypeId = type.HolidayTypeId, Year = year, Status = status, Dates = dates
         });
     }
     return(new Holiday {
         HolidayType = type, Year = year, Status = status, Dates = dates
     });
 }
 /// <summary>Gets the holiday table for a specific year as a collection of <see cref="DateInfo"/> objects, where in general the language depending name of the holiday is given too.
 /// </summary>
 /// <param name="year">The year.</param>
 /// <param name="holidaySet">A set of <see cref="DateInfo"/> object that represents the holidays (output).</param>
 /// <param name="holidayType">The type of the holidays to take into account.</param>
 /// <exception cref="NullReferenceException">Thrown, if <paramref name="holidaySet"/> is <c>null</c>.</exception>
 public override void GetHolidays(int year, HashSet <DateInfo> holidaySet, HolidayType holidayType = HolidayType.PublicHolidays)
 {
     if (holidaySet == null)
     {
         throw new ArgumentNullException("holidaySet");
     }
     /* just the union, i.e. add the holidays (and weekend dates): */
     foreach (IHolidayCalendar holidayCalendar in m_HolidayCalendars)
     {
         holidayCalendar.GetHolidays(year, holidaySet, holidayType);
     }
 }
Example #19
0
 private static string TypeToLithuanian(HolidayType typeToTranslate, FileTypeEnum holidayDocumentType)
 {
     return(typeToTranslate switch
     {
         HolidayType.Annual => (holidayDocumentType == FileTypeEnum.Order ? "kasmetines atostogas" : "išleisti mane kasmetinių atostogų"),
         HolidayType.DayForChildren => (holidayDocumentType == FileTypeEnum.Order
             ? "papildomą poilsio dieną"
             : "suteikti man papildomą poilsio dieną vaikų priežiūrai"),
         HolidayType.Science => (holidayDocumentType == FileTypeEnum.Order ? "mokslo atostogas" : "išleisti mane mokslo atostogų"),
         HolidayType.Unpaid => (holidayDocumentType == FileTypeEnum.Order ? "neapmokamas atostogas" : "išleisti mane neapmokamų atostogų"),
         _ => "",
     });
Example #20
0
 /// <summary>Gets the holidays for a specific year as a collection of <see cref="DateInfo"/> instances, where
 /// in general the language depending name of the holiday is given too.
 /// </summary>
 /// <param name="year">The year.</param>
 /// <param name="holidaySet">A set of <see cref="DateInfo"/> instances to add the holidays of the <paramref name="year"/> (output).</param>
 /// <param name="holidayType">The type of the holidays to take into account.</param>
 /// <exception cref="NullReferenceException">Thrown, if <paramref name="holidaySet"/> is <c>null</c>.</exception>
 public void GetHolidays(int year, HashSet <DateInfo> holidaySet, HolidayType holidayType = HolidayType.PublicHolidays)
 {
     if (holidaySet == null)
     {
         throw new ArgumentNullException("holidaySet");
     }
     /* insert weekends into the holiday table, if desired: */
     if ((holidayType & HolidayType.Weekends) == HolidayType.Weekends)
     {
         WeekendFactory.StandardWeekend.GetWeekendDateInfos(year, holidaySet);
     }
 }
Example #21
0
 /// <summary>
 /// 保存
 /// </summary>
 public override void Save()
 {
     if (!m_Loaded)           //新增
     {
         HolidayType holidayType = new HolidayType();
         SaveToDb(this, holidayType, true);
     }
     else            //修改
     {
         HolidayType holidayType = new HolidayType(holidayTypeId);
         if (holidayType.IsNew)
         {
             throw new AppException("该数据已经不存在了");
         }
         SaveToDb(this, holidayType, false);
     }
 }
Example #22
0
        private Holiday(Guid?id, EntityStatus status, ActionType action, Guid?userId, Guid countryId, Guid?stateId, DateTime holidayDate, HolidayType holidayType, bool optional, string nativeDescription, string alternativeDescription, string countryCode, string stateCode, string cityName, string cityCode) : base(id, status, action, userId)
        {
            CountryId              = countryId;
            StateId                = stateId;
            HolidayDate            = holidayDate;
            HolidayType            = holidayType;
            Optional               = optional;
            NativeDescription      = nativeDescription;
            AlternativeDescription = alternativeDescription;
            CountryCode            = countryCode;
            StateCode              = stateCode;
            CityName               = cityName;
            CityCode               = cityCode;

            GenerateCityId();
            GenerateComposeKey();
        }
Example #23
0
        /// <summary>
        /// 删除
        /// </summary>
        /// <returns>是否成功</returns>
        public override void Delete()
        {
            if (!m_Loaded)
            {
                throw new AppException("尚未初始化");
            }
            bool result = (HolidayType.Delete(HolidayTypeId) == 1);

            //更新缓存
            if (result && CachedEntityCommander.IsTypeRegistered(typeof(HolidayTypeInfo)))
            {
                ResetCache();
            }
            if (!result)
            {
                throw new AppException("删除失败,数据可能被删除");
            }
        }
Example #24
0
 public IHttpActionResult EditHoliday(HolidayType holiday)
 {
     if (holiday == null)
     {
         return(NotFound());
     }
     try
     {
         if (ModelState.IsValid)
         {
             _holidayRepository.UpdateHoliday(holiday);
         }
         return(Ok(holiday));
     }
     catch (Exception)
     {
         return(BadRequest());
     }
 }
Example #25
0
 public IHttpActionResult AddNewHoliday(HolidayType holiday)
 {
     //if (holiday == null)
     //{
     //    return NotFound();
     //}
     try
     {
         if (ModelState.IsValid)
         {
             _holidayRepository.AddHoliday(holiday);
         }
         return(Ok(holiday));
     }
     catch (Exception)
     {
         return(BadRequest());
     }
 }
Example #26
0
        private static HolidayType SetHolidayType(string holidayType, string cityName, string stateCode)
        {
            HolidayType type = HolidayType.National;

            if (holidayType == "Not A Public Holiday")
            {
                type = HolidayType.Observance;
            }
            else if (cityName.HasValue())
            {
                type = HolidayType.Local;
            }
            else if (!cityName.HasValue() && stateCode.HasValue())
            {
                type = HolidayType.Regional;
            }

            return(type);
        }
Example #27
0
        private void button_Click(object sender, RoutedEventArgs e)
        {
            //try
            //{
            using (var db = new DMSIPayrollEntities())
            {
                if (tbIncomeTypeCode.Text == "" || tbMultiplier.Text == "" || tbDescription.Text == "")
                {
                    MessageBox.Show("Required fields cannot be empty.", "System Warning!", MessageBoxButton.OK, MessageBoxImage.Warning);
                    return;
                }

                if (mode == 1)
                {
                    HolidayType holidayType = new HolidayType();
                    holidayType.HolidayCode = tbIncomeTypeCode.Text;
                    holidayType.Description = tbDescription.Text;
                    holidayType.Multiplier  = Decimal.Parse(tbMultiplier.Text);
                    db.HolidayTypes.Add(holidayType);
                    db.SaveChanges();
                    MessageBox.Show("Add Succesful", "System Succes!", MessageBoxButton.OK, MessageBoxImage.Information);
                    clear();
                }
                else if (mode == 2)
                {
                    var holidayType = db.HolidayTypes.Where(m => m.HolidayTypeID == holidaytypeid).FirstOrDefault();
                    holidayType.HolidayCode = tbIncomeTypeCode.Text;
                    holidayType.Description = tbDescription.Text;
                    holidayType.Multiplier  = Decimal.Parse(tbMultiplier.Text);
                    db.SaveChanges();
                    MessageBox.Show("Update Succesful", "System Succes!", MessageBoxButton.OK, MessageBoxImage.Information);
                }
            }
            //}
            //catch (Exception)
            //{

            //    MessageBox.Show("Something went wrong.", "System Error!", MessageBoxButton.OK, MessageBoxImage.Error);

            //}
        }
Example #28
0
 private void LoadFromId(int holidayTypeId)
 {
     if (CachedEntityCommander.IsTypeRegistered(typeof(HolidayTypeInfo)))
     {
         HolidayTypeInfo holidayTypeInfo = Find(GetList(), holidayTypeId);
         if (holidayTypeInfo == null)
         {
             throw new AppException("未能在缓存中找到相应的键值对象");
         }
         Copy(holidayTypeInfo, this);
     }
     else
     {
         HolidayType holidayType = new HolidayType(holidayTypeId);
         if (holidayType.IsNew)
         {
             throw new AppException("尚未初始化");
         }
         LoadFromDAL(this, holidayType);
     }
 }
Example #29
0
        /// <summary>Gets the holiday table for a specific year as a collection of <see cref="DateInfo"/> objects, where in general the language depending name of the holiday is given too.
        /// </summary>
        /// <param name="year">The year.</param>
        /// <param name="holidaySet">A set of <see cref="DateInfo"/> object that represents the holidays (output).</param>
        /// <param name="holidayType">The type of the holidays to take into account.</param>
        /// <exception cref="NullReferenceException">Thrown, if <paramref name="holidaySet"/> is <c>null</c>.</exception>
        public override void GetHolidays(int year, HashSet <DateInfo> holidaySet, HolidayType holidayType = HolidayType.PublicHolidays)
        {
            if (holidaySet == null)
            {
                throw new ArgumentNullException("holidaySet");
            }

            /* the holidays (i.e. public holidays as well as weekend days) are the intersection of the holidays: */
            HashSet <DateInfo> intersectionHolidays = new HashSet <DateInfo>();

            m_HolidayCalendars.First <IHolidayCalendar>().GetHolidays(year, intersectionHolidays, holidayType);

            HashSet <DateInfo> oneStepHolidays = new HashSet <DateInfo>();

            foreach (IHolidayCalendar holidayCalendar in m_HolidayCalendars)
            {
                holidayCalendar.GetHolidays(year, oneStepHolidays, holidayType);
                intersectionHolidays.IntersectWith(oneStepHolidays);
                oneStepHolidays.Clear();
            }
            holidaySet.UnionWith(intersectionHolidays);
        }
        /// <summary>Gets the holidays for a specific year as a collection of <see cref="DateInfo"/> instances, where
        /// in general the language depending name of the holiday is given too.
        /// </summary>
        /// <param name="year">The year.</param>
        /// <param name="holidaySet">A set of <see cref="DateInfo"/> instances to add the holidays of the <paramref name="year"/> (output).</param>
        /// <param name="holidayType">The type of the holidays to take into account.</param>
        /// <exception cref="NullReferenceException">Thrown, if <paramref name="holidaySet"/> is <c>null</c>.</exception>
        public void GetHolidays(int year, HashSet <DateInfo> holidaySet, HolidayType holidayType = HolidayType.PublicHolidays)
        {
            if ((year >= FirstDate.Year) && (year <= LastDate.Year))
            {
                /* 1.) add holidays (!= saturday/sunday - for the 'standard' weekend) into the list: */
                if ((holidayType & HolidayType.PublicHolidays) == HolidayType.PublicHolidays)
                {
                    if (m_ListOfHolidays.ContainsKey(year))
                    {
                        foreach (DateInfo date in m_ListOfHolidays[year])
                        {
                            holidaySet.Add(date);
                        }
                    }
                }

                /* 2.) add saturdays/sundays (in the case of the 'standard' weekend) into the list, if desired: */
                if ((holidayType & HolidayType.Weekends) == HolidayType.Weekends)
                {
                    m_WeekendRepresentation.GetWeekendDateInfos(year, holidaySet);
                }
            }
        }
Example #31
0
        private void Add(SalesArea salesArea, List <DateRange> newDateRanges, HolidayType holidayType)
        {
            var data = new List <ImagineCommunications.GamePlan.Domain.Generic.Types.Ranges.DateRange>();

            switch (holidayType)
            {
            case HolidayType.PublicHoliday:
                data = salesArea.PublicHolidays = salesArea.PublicHolidays ?? new List <GamePlan.Domain.Generic.Types.Ranges.DateRange>();
                break;

            case HolidayType.SchoolHoliday:
                data = salesArea.SchoolHolidays = salesArea.SchoolHolidays ?? new List <GamePlan.Domain.Generic.Types.Ranges.DateRange>();
                break;

            default:
                throw new Exception("Invalid holiday type");
            }

            if (data.Any())
            {
                foreach (var item in newDateRanges.Where(item => !data.Any(c => c.End == item.End && c.Start == item.Start)))
                {
                    data.Add(new GamePlan.Domain.Generic.Types.Ranges.DateRange()
                    {
                        End   = item.End,
                        Start = item.Start
                    });
                }
            }
            else
            {
                data.AddRange(newDateRanges.Select(item => new GamePlan.Domain.Generic.Types.Ranges.DateRange()
                {
                    End = item.End, Start = item.Start
                }));
            }
        }
Example #32
0
        public void CreateRule_MustCreateInstaceOfRule(string id, string status, string typeProcess, string user, string country, string state, string countryIsoCode, string stateIsoCode, string cityCode, string cityName, string holidayType, string nativeHolidayName, string englishHolidayName, int month, int day, bool optional, string bussinessRule, string comments)
        {
            // Arrange
            RuleHoliday  ruleHoliday;
            Guid         entityId     = string.IsNullOrEmpty(id) ? Guid.Empty : Guid.Parse(id);
            EntityStatus entityStatus = EntityStatus.GetByName(status);
            ActionType   action       = ActionType.GetByName(typeProcess);
            HolidayType  type         = HolidayType.GetByName(holidayType);
            Guid         userId       = string.IsNullOrEmpty(user) ? Guid.Empty : Guid.Parse(user);
            Guid         countryId    = string.IsNullOrEmpty(country) ? Guid.Empty : Guid.Parse(country);
            Guid         stateId      = string.IsNullOrEmpty(state) ? Guid.Empty : Guid.Parse(state);

            // Act
            ruleHoliday = RuleHoliday.CreateRuleHoliday(entityId, entityStatus, action, userId, countryId, stateId, countryIsoCode, stateIsoCode, cityCode, cityName, type, nativeHolidayName, englishHolidayName, month, day, optional, bussinessRule, comments);

            // Assert
            Assert.NotNull(ruleHoliday);
            Assert.True(ruleHoliday.Id != entityId &&
                        ruleHoliday.Status == entityStatus &&
                        ruleHoliday.Action == action &&
                        (ruleHoliday.RegisteredBy == userId || ruleHoliday.ModifiedBy == userId) &&
                        ruleHoliday.CountryId == countryId &&
                        ruleHoliday.StateId == stateId &&
                        ruleHoliday.CountryIsoCode == countryIsoCode &&
                        ruleHoliday.StateIsoCode == stateIsoCode &&
                        ruleHoliday.CityCode == cityCode &&
                        ruleHoliday.CityName == cityName &&
                        ruleHoliday.HolidayType == type &&
                        ruleHoliday.NativeHolidayName == nativeHolidayName &&
                        ruleHoliday.EnglishHolidayName == englishHolidayName &&
                        (ruleHoliday.Month == month || ruleHoliday.Month == null) &&
                        (ruleHoliday.Day == day || ruleHoliday.Day == null) &&
                        ruleHoliday.Optional == optional &&
                        ruleHoliday.BussinessRule == bussinessRule.Replace(" ", "").Trim().ToLower() &&
                        ruleHoliday.Comments == comments);
        }
 /// <summary>
 /// Filter as...
 /// </summary>
 /// <param name="holidayInfos"></param>
 /// <param name="type"></param>
 /// <returns></returns>
 public static IEnumerable <IHolidayInfo> Filter(this IEnumerable <IHolidayInfo> holidayInfos, HolidayType type)
 {
     return(holidayInfos?.Where(x => x.Type == type));
 }
Example #34
0
 public HolidayEvent(HolidayType Holiday, Boolean Today)
 {
     _Holiday = Holiday;
     _Today = Today;
 }
Example #35
0
 public Holiday(DateTime	date, string name)
 {
     _type = HolidayType.Date;
     _date = date;
     _name = name;
 }
Example #36
0
 private void LoadFromId(int holidayTypeId)
 {
     if (CachedEntityCommander.IsTypeRegistered(typeof(HolidayTypeInfo)))
     {
         HolidayTypeInfo holidayTypeInfo=Find(GetList(), holidayTypeId);
         if(holidayTypeInfo==null)
             throw new AppException("未能在缓存中找到相应的键值对象");
         Copy(holidayTypeInfo, this);
     }
     else
     {	HolidayType holidayType=new HolidayType( holidayTypeId);
         if(holidayType.IsNew)
         throw new AppException("尚未初始化");
        	LoadFromDAL(this, holidayType);
     }
 }
Example #37
0
 //数据持久化
 internal static void SaveToDb(HolidayTypeInfo pHolidayTypeInfo, HolidayType  pHolidayType,bool pIsNew)
 {
     pHolidayType.HolidayTypeId = pHolidayTypeInfo.holidayTypeId;
      		pHolidayType.HolidayTypeName = pHolidayTypeInfo.holidayTypeName;
     pHolidayType.IsNew=pIsNew;
     string UserName = SubsonicHelper.GetUserName();
     try
     {
         pHolidayType.Save(UserName);
     }
     catch(Exception ex)
     {
         LogManager.getInstance().getLogger(typeof(HolidayTypeInfo)).Error(ex);
         if(ex.Message.Contains("插入重复键"))//违反了唯一键
         {
             throw new AppException("此对象已经存在");//此处等待优化可以从唯一约束中直接取出提示来,如果没有的话,默认为原始的出错提示
         }
         throw new AppException("保存失败");
     }
     pHolidayTypeInfo.holidayTypeId = pHolidayType.HolidayTypeId;
     //如果缓存存在,更新缓存
     if (CachedEntityCommander.IsTypeRegistered(typeof(HolidayTypeInfo)))
     {
         ResetCache();
     }
 }
Example #38
0
 //从后台获取数据
 internal static void LoadFromDAL(HolidayTypeInfo pHolidayTypeInfo, HolidayType  pHolidayType)
 {
     pHolidayTypeInfo.holidayTypeId = pHolidayType.HolidayTypeId;
      		pHolidayTypeInfo.holidayTypeName = pHolidayType.HolidayTypeName;
     pHolidayTypeInfo.Loaded=true;
 }
Example #39
0
 /// <summary>
 /// 保存
 /// </summary>
 public override void Save()
 {
     if(!m_Loaded)//新增
     {
         HolidayType holidayType=new HolidayType();
         SaveToDb(this, holidayType,true);
     }
     else//修改
     {
         HolidayType holidayType=new HolidayType(holidayTypeId);
         if(holidayType.IsNew)
             throw new AppException("该数据已经不存在了");
         SaveToDb(this, holidayType,false);
     }
 }
Example #40
0
 public void Change(DayOfWeek	dayOfWeek)
 {
     _type = HolidayType.DayOfWeek;
     _dayOfWeek = dayOfWeek;
 }
Example #41
0
 public void Change(DateTime		date)
 {
     _type = HolidayType.Date;
     _date = date;
 }
Example #42
0
 public Holiday(DayOfWeek dayOfWeek, string name)
 {
     _type = HolidayType.DayOfWeek;
     _dayOfWeek = dayOfWeek;
     _name = name;
 }
Example #43
0
            public List<HolidayType> ToList()
            {
                List<HolidayType> HolidayTypes = new List<HolidayType>();

                for (int i = 0; i < _DisplayName.Length; i++)
                {
                    HolidayType holidayType = new HolidayType();
                    holidayType.DisplayName = _DisplayName[i];
                    holidayType.name = _Name[i];
                    HolidayTypes.Add(holidayType);
                }

                return HolidayTypes;
            }