public JsonResult AddHoliday(string date, string narration) { HolidaySP spHoliday = new HolidaySP(); try { HolidayInfo infoHoliday = new HolidayInfo(); { DateTime curdate = Convert.ToDateTime(date); infoHoliday.Date = curdate; if (narration != null) { infoHoliday.Narration = narration.Trim(); } else { infoHoliday.Narration = string.Empty; } infoHoliday.HolidayName = string.Empty; infoHoliday.Extra1 = string.Empty; infoHoliday.Extra2 = string.Empty; spHoliday.HolidayAddWithIdentity(infoHoliday); } HolidaySettingsDate(date); } catch (Exception ex) { return(Json(new { error = "failed" })); } return(Json(new { error = "success" })); }
/// <summary> /// 判断是否为农历节假日,包括节气 /// </summary> /// <param name="currentDayInfo"></param> /// <returns></returns> private bool IsLunarHoliday(ref DayInfo currentDayInfo) { bool result = false; if (currentDayInfo.term != null) { if (currentDayInfo.term.Contains("清明")) { return(true); } } HolidayInfo info = new HolidayInfo(); foreach (string cHoliday in lunarHolidays) { info = GetHoliday(2, cHoliday); if (currentDayInfo.lunarM == info.month && currentDayInfo.lunarD == info.day) { currentDayInfo.lunarHoliday = info.name.Replace("*", "") + "\n"; if (info.name.Contains("*")) { result = true; } } } return(result); }
private async void NewAddHoliday() { var holiday = new HolidayInfo() { HolidayDate = HolidayDate.Date, Description = Description.Trim(), Aph = "Holiday", }; try { using (var da = new DataAccess()) { da.Insert(holiday); await dialogService.ShowMessage("Success", "Insert Data Successfully...!!!"); await navigationService.Back(); Clear(); } } catch (Exception ex) { await dialogService.ShowMessage("Error", ex.Message); } }
private HolidayInfo GetItemFromInput() { HolidayInfo info; if (UpdatingItem == null) { info = new HolidayInfo(); } else { info = UpdatingItem as HolidayInfo; } info.StartDate = this.dtStartDate.Value.Date; info.EndDate = this.dtEndDate.Value.Date; info.WeekenToWorkDayInterval.Clear(); if (checkBox1.Checked) { DatetimeInterval di = new DatetimeInterval(); di.Begin = dtWorkday1StartDate.Value; DateTime dt = dtWorkday1EndDate.Value; di.End = new DateTime(dt.Year, dt.Month, dt.Day, 23, 59, 59); info.WeekenToWorkDayInterval.Add(di); } if (checkBox2.Checked) { DatetimeInterval di = new DatetimeInterval(); di.Begin = dtWorkday2StartDate.Value; DateTime dt = dtWorkday2EndDate.Value; di.End = new DateTime(dt.Year, dt.Month, dt.Day, 23, 59, 59); info.WeekenToWorkDayInterval.Add(di); } return(info); }
public Task <HolidayWrap> GetHoliday(string Month, int Year) { return(Task.Run(() => { string s = Year + "-" + Month; DateTime dt = DateTime.ParseExact(s, "yyyy-MMM", CultureInfo.InvariantCulture); using (MIUEntities db = new MIUEntities()) { HolidayWrap holidayWrap = new HolidayWrap(); List <HolidayInfo> HolidayInfos = new List <HolidayInfo>(); List <Holiday> holiday = db.Holidays.Where(x => x.Date.Year == dt.Year && x.Date.Month == dt.Month).OrderBy(x => x.Date).ToList(); foreach (var data in holiday) { HolidayInfo info = new HolidayInfo(); PropertyCopier <Holiday, HolidayInfo> .Copy(data, info); info.Week = data.Date.ToString("ddd"); info.Day = data.Date.Day.ToString(); HolidayInfos.Add(info); } holidayWrap.HolidayInfo = HolidayInfos; holidayWrap.TotalHoliday = HolidayInfos.Count; return holidayWrap; } })); }
public bool IsExisted(HolidayInfo info) { String query = "select count(*) from Holiday " + " where HolidayDate = @HolidayDate "; var obj = (List <int>)db.Query <int>(query, info, this.transaction); return(obj[0] > 0); }
/// <summary> /// Function to Update values in Holiday Table /// </summary> /// <param name="holidayinfo"></param> public void HolidayEdit(HolidayInfo holidayinfo) { try { SPHoliday.HolidayEdit(holidayinfo); } catch (Exception ex) { MessageBox.Show("HSBll2:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
public bool DeleteHoliday(HolidayInfo model) { bool result = false; if (model.Id != 0) { using (var da = new DataAccess()) { da.Delete(model); } result = true; } return(result); }
/// <summary> /// Function to insert values to Holiday table and return Id /// </summary> /// <param name="holidayinfo"></param> /// <returns></returns> public bool HolidayAddWithIdentity(HolidayInfo holidayinfo) { bool isSave = true; try { isSave = SPHoliday.HolidayAddWithIdentity(holidayinfo); } catch (Exception ex) { MessageBox.Show("HSBll8:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information); } return(isSave); }
public void Update(HolidayInfo info) { string query = " UPDATE [dbo].[Holiday] SET " + " [EngDesc] = @EngDesc " + ", [ChiDesc] = @ChiDesc " + ", [LastModifyDate] = @LastModifyDate " + ", [LastModifyUser] = @LastModifyUser " + ", [CreateDate] = @CreateDate " + ", [CreateUser] = @CreateUser " + " where HolidayDate = @HolidayDate "; db.Execute(query, info, this.transaction); }
/// <summary> /// Function to get particular values from Holiday table based on the parameter /// </summary> /// <param name="holidayId"></param> /// <returns></returns> public HolidayInfo HolidayView(decimal holidayId) { HolidayInfo holidayinfo = new HolidayInfo(); try { holidayinfo = SPHoliday.HolidayView(holidayId); } catch (Exception ex) { MessageBox.Show("HSBll4:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information); } return(holidayinfo); }
public bool HolidayAddWithIdentity(HolidayInfo holidayinfo) { bool isStatus = false; try { isStatus = spHoliday.HolidayAddWithIdentity(holidayinfo); } catch (Exception ex) { MessageBox.Show("SB3:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information); } return(isStatus); }
private void btnOk_Click(object sender, EventArgs e) { if (CheckInput()) { HolidayInfo info = GetItemFromInput(); if (IsAdding && ItemAdded != null) { ItemAdded(this, new ItemAddedEventArgs(info)); } else if (ItemUpdated != null) { ItemUpdated(this, new ItemUpdatedEventArgs(info)); } } }
public JsonResult SaveAllHoliday(string cur_month, string tableData) { HolidaySP spHoliday = new HolidaySP(); try { List <Dictionary <string, object> > items = JsonConvert.DeserializeObject <List <Dictionary <string, object> > >(tableData); if (cur_month == null) { cur_month = Convert.ToString(DateTime.Now); } DateTime curdate = Convert.ToDateTime(cur_month); string strMonth = curdate.ToString("MMMMyyyy"); string dtpMonth = strMonth.Substring(0, 3); string dtpYear = curdate.Year.ToString(); spHoliday.HolidaySettingsDeleteByMonth(dtpMonth.ToString(), dtpYear.ToString()); HolidayInfo infoHoliday = new HolidayInfo(); int inrowcount = items.Count; for (int i = 0; i < inrowcount; i++) { DateTime date = Convert.ToDateTime(items[i]["date"]); infoHoliday.Date = date; if (items[i]["narration"] != null) { string strNarration = Convert.ToString(items[i]["narration"]); infoHoliday.Narration = strNarration.Trim(); } else { infoHoliday.Narration = string.Empty; } infoHoliday.HolidayName = string.Empty; infoHoliday.Extra1 = string.Empty; infoHoliday.Extra2 = string.Empty; spHoliday.HolidayAddWithIdentity(infoHoliday); } HolidaySettingsDate(cur_month); } catch (Exception ex) { return(Json(new { error = "failed" })); } return(Json(new { error = "success" })); }
private void GenerateFile(List <HolidayInfo> holiday) { string title = "HolidayDate\tMarketId\tMarketName\tComment"; string[] data = new string[holiday.Count]; for (int i = 0; i < holiday.Count; i++) { HolidayInfo item = holiday[i]; string content = string.Format("{0}\t{1}\t{2}\t{3}", item.HolidayDate, item.MarketId, (MarketIdEnum)item.MarketId, item.Comment); data[i] = content; } string filePath = string.Format("{0}\\{1}_HOLIDAY.txt", GetOutputFilePath(), configObj.MarketId); FileUtil.WriteOutputFile(filePath, data, title, WriteMode.Overwrite); TaskResultList.Add(new TaskResultEntry("HOLIDAY File", "HOLIDAY File", filePath)); }
public ActionResult HolidayInfo(int id) { try { Holiday holidayById = unitofwork.HolidayRepo.GetById(id); HolidayInfo holidayinfo = new HolidayInfo() { holiday = holidayById, number = 0 }; return(View(holidayinfo)); } catch { return(HttpNotFound()); } }
/// <summary> /// Function to insert values to Holiday table and return Id /// </summary> /// <param name="holidayinfo"></param> /// <returns></returns> public bool HolidayAddWithIdentity(HolidayInfo holidayinfo) { bool isSave = true; try { if (sqlcon.State == ConnectionState.Closed) { sqlcon.Open(); } SqlCommand sccmd = new SqlCommand("HolidayAddWithIdentity", sqlcon); sccmd.CommandType = CommandType.StoredProcedure; SqlParameter sprmparam = new SqlParameter(); sprmparam = sccmd.Parameters.Add("@date", SqlDbType.DateTime); sprmparam.Value = holidayinfo.Date; sprmparam = sccmd.Parameters.Add("@holidayName", SqlDbType.VarChar); sprmparam.Value = holidayinfo.HolidayName; sprmparam = sccmd.Parameters.Add("@narration", SqlDbType.VarChar); sprmparam.Value = holidayinfo.Narration; sprmparam = sccmd.Parameters.Add("@extra1", SqlDbType.VarChar); sprmparam.Value = holidayinfo.Extra1; sprmparam = sccmd.Parameters.Add("@extra2", SqlDbType.VarChar); sprmparam.Value = holidayinfo.Extra2; int inAffected = sccmd.ExecuteNonQuery(); if (inAffected > 0) { isSave = true; } else { isSave = false; } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { sqlcon.Close(); } return(isSave); }
public void TestHoliday() { HolidaySetting hs = new HolidaySetting(); hs.SaturdayIsRest = true; hs.SundayIsRest = true; //2011-4-2 2011-4-3为周六日 Assert.IsTrue(hs.IsInHoliday(new DateTime(2011, 4, 2, 1, 20, 15), new DateTime(2011, 4, 2, 12, 50, 50))); Assert.IsTrue(hs.IsInHoliday(new DateTime(2011, 4, 3, 1, 20, 15), new DateTime(2011, 4, 3, 12, 50, 50))); Assert.IsTrue(hs.IsInHoliday(new DateTime(2011, 4, 2, 1, 20, 15), new DateTime(2011, 4, 3, 12, 50, 50))); Assert.IsTrue(hs.IsInHoliday(new DateTime(2011, 4, 2, 0, 0, 0), new DateTime(2011, 4, 4, 0, 0, 0))); Assert.IsFalse(hs.IsInHoliday(new DateTime(2011, 4, 2, 0, 0, 0), new DateTime(2011, 4, 4, 1, 0, 0))); Assert.IsFalse(hs.IsInHoliday(new DateTime(2011, 4, 1, 23, 59, 59), new DateTime(2011, 4, 3, 12, 0, 0))); Assert.IsFalse(hs.IsInHoliday(new DateTime(2011, 4, 1, 11, 59, 59), new DateTime(2011, 4, 3, 12, 0, 0))); hs.SaturdayIsRest = false; hs.SundayIsRest = true; //2011-4-2 2011-4-3为周六日 Assert.IsFalse(hs.IsInHoliday(new DateTime(2011, 4, 2, 1, 20, 15), new DateTime(2011, 4, 2, 12, 50, 50))); Assert.IsTrue(hs.IsInHoliday(new DateTime(2011, 4, 3, 1, 20, 15), new DateTime(2011, 4, 3, 12, 50, 50))); Assert.IsFalse(hs.IsInHoliday(new DateTime(2011, 4, 2, 1, 20, 15), new DateTime(2011, 4, 3, 12, 50, 50))); Assert.IsFalse(hs.IsInHoliday(new DateTime(2011, 4, 2, 0, 0, 0), new DateTime(2011, 4, 4, 0, 0, 0))); Assert.IsFalse(hs.IsInHoliday(new DateTime(2011, 4, 2, 0, 0, 0), new DateTime(2011, 4, 4, 1, 0, 0))); hs.SaturdayIsRest = true; hs.SundayIsRest = false; //2011-4-2 2011-4-3为周六日 Assert.IsTrue(hs.IsInHoliday(new DateTime(2011, 4, 2, 1, 20, 15), new DateTime(2011, 4, 2, 12, 50, 50))); Assert.IsFalse(hs.IsInHoliday(new DateTime(2011, 4, 3, 1, 20, 15), new DateTime(2011, 4, 3, 12, 50, 50))); Assert.IsFalse(hs.IsInHoliday(new DateTime(2011, 4, 2, 1, 20, 15), new DateTime(2011, 4, 3, 12, 50, 50))); HolidayInfo holiday = new HolidayInfo(); //2011-4-3 到2011-4-5节假日 holiday.StartDate = new DateTime(2011, 4, 3); holiday.EndDate = new DateTime(2011, 4, 5); hs.Holidays.Add(holiday); Assert.IsTrue(hs.IsInHoliday(new DateTime(2011, 4, 3), new DateTime(2011, 4, 5))); Assert.IsTrue(hs.IsInHoliday(new DateTime(2011, 4, 3, 12, 4, 1), new DateTime(2011, 4, 5, 15, 0, 0))); Assert.IsTrue(hs.IsInHoliday(new DateTime(2011, 4, 3), new DateTime(2011, 4, 6))); Assert.IsFalse(hs.IsInHoliday(new DateTime(2011, 4, 3), new DateTime(2011, 4, 6, 0, 1, 0))); }
private void ShowHoliday(HolidayInfo info) { this.dtStartDate.Value = info.StartDate.Date; this.dtEndDate.Value = info.EndDate.Date; if (info.WeekenToWorkDayInterval != null) { if (info.WeekenToWorkDayInterval.Count > 0) { checkBox1.Checked = true; dtWorkday1StartDate.Value = info.WeekenToWorkDayInterval[0].Begin; dtWorkday1EndDate.Value = info.WeekenToWorkDayInterval[0].End; } if (info.WeekenToWorkDayInterval.Count > 1) { checkBox2.Checked = true; dtWorkday2StartDate.Value = info.WeekenToWorkDayInterval[1].Begin; dtWorkday2EndDate.Value = info.WeekenToWorkDayInterval[1].End; } } }
public JsonResult EditHoliday(string date, string narration) { HolidaySP spHoliday = new HolidaySP(); try { HolidayInfo infoHoliday = new HolidayInfo(); { DateTime curdate = Convert.ToDateTime(date); string strMonth = curdate.ToString("MMMMyyyydd"); string dtpMonth = strMonth.Substring(0, 3); string dtpYear = curdate.Year.ToString(); string dtpDay = strMonth.Substring(strMonth.Length - 2, 2); decimal id = spHoliday.HolidaySettingsSearchByDate(dtpMonth, dtpYear, dtpDay).HolidayId; infoHoliday.HolidayId = id; infoHoliday.Date = curdate; if (narration != null) { infoHoliday.Narration = narration.Trim(); } else { infoHoliday.Narration = string.Empty; } infoHoliday.HolidayName = string.Empty; infoHoliday.ExtraDate = DateTime.Now; infoHoliday.Extra1 = string.Empty; infoHoliday.Extra2 = string.Empty; spHoliday.HolidayEdit(infoHoliday); } HolidaySettingsDate(date); } catch (Exception ex) { return(Json(new { error = "failed" })); } return(Json(new { error = "success" })); }
public ActionResult Index(HolidayInfo iHolidayInfo) { if (string.IsNullOrWhiteSpace(Convert.ToString(iHolidayInfo.HolidayName))) { ModelState.AddModelError("HolidayName", "Please enter holiday name"); } if (string.IsNullOrWhiteSpace(Convert.ToString(iHolidayInfo.HolidayDate))) { ModelState.AddModelError("HolidayDate", "Please enter date"); } if (!ModelState.IsValid) { return(View()); } try { using (var client = new HttpClient()) { iHolidayInfo.iMode = 115; iHolidayInfo.PreApproved = 1; client.BaseAddress = new Uri(Utility.BaseURL); var response = client.PostAsJsonAsync("HolidayDetails", iHolidayInfo).Result; Status status = response.Content.ReadAsAsync <Status>().Result; if (status.Errors == null) { return(RedirectToAction("Index")); } else { return(View("Index")); } } } catch { return(View("Index")); } }
//Holidayinfo modelini Holidays tablosu ve Country bilgileriyle doldurdum. public HolidayInfo Holidays(int CountryId) { var holidays = _context.Holidays.Where(h => h.Country.ContryId == CountryId).Select(h => h.DayOfYearFor2017).ToList(); var dayLength = _context.Holidays.Where(h => h.Country.ContryId == CountryId).Select(h => h.HolidayLength).ToList(); var weekEnds = _context.Countries.Where(c => c.ContryId == CountryId).Select(c => c.Weekends).First(); var currenct = _context.Countries.Where(c => c.ContryId == CountryId).Select(c => c.Money).First(); var penaltyAmount = _context.Countries.Where(c => c.ContryId == CountryId).Select(c => c.Penalty).First(); var HolidayInfo = new HolidayInfo { Days = holidays, HolidayDayLength = dayLength, weekEnds = weekEnds, currenct = currenct, penaltyAmount = penaltyAmount }; return(HolidayInfo); }
/// <summary> /// Function to get particular values from Holiday table based on the parameter /// </summary> /// <param name="holidayId"></param> /// <returns></returns> public HolidayInfo HolidayView(decimal holidayId) { HolidayInfo holidayinfo = new HolidayInfo(); SqlDataReader sdrreader = null; try { if (sqlcon.State == ConnectionState.Closed) { sqlcon.Open(); } SqlCommand sccmd = new SqlCommand("HolidayView", sqlcon); sccmd.CommandType = CommandType.StoredProcedure; SqlParameter sprmparam = new SqlParameter(); sprmparam = sccmd.Parameters.Add("@holidayId", SqlDbType.Decimal); sprmparam.Value = holidayId; sdrreader = sccmd.ExecuteReader(); while (sdrreader.Read()) { holidayinfo.HolidayId = decimal.Parse(sdrreader[0].ToString()); holidayinfo.Date = DateTime.Parse(sdrreader[1].ToString()); holidayinfo.HolidayName = sdrreader[2].ToString(); holidayinfo.Narration = sdrreader[3].ToString(); holidayinfo.ExtraDate = DateTime.Parse(sdrreader[4].ToString()); holidayinfo.Extra1 = sdrreader[5].ToString(); holidayinfo.Extra2 = sdrreader[6].ToString(); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { sdrreader.Close(); sqlcon.Close(); } return(holidayinfo); }
public void Insert(HolidayInfo info) { string query = "INSERT INTO [dbo].[Holiday] ( [HolidayDate] " + ",[EngDesc] " + ",[ChiDesc] " + ",[LastModifyDate] " + ",[LastModifyUser] " + ",[CreateDate] " + ",[CreateUser] " + ") " + "VALUES ( @HolidayDate " + ",@EngDesc " + ",@ChiDesc " + ",@LastModifyDate " + ",@LastModifyUser " + ",@CreateDate " + ",@CreateUser " + ") "; db.Execute(query, info, this.transaction); }
public bool LoadHolidayInfo(string fileName = "holidays.json") { var configFile = AppDomain.CurrentDomain.BaseDirectory + fileName; if (!File.Exists(configFile)) { HolidayInfo = new HolidayInfo(); return true; } string jsonStr = string.Empty; try { jsonStr = File.ReadAllText(configFile); HolidayInfo = JsonHelper.DeserializeJsonToObject<HolidayInfo>(jsonStr); return true; } catch (Exception) { return false; } }
/// <summary> /// 拆解Holiday,type种类:1.阳历固定;2.农历固定;3.某月第几个星期几; /// </summary> /// <param name="currentDayInfo"></param> /// <returns></returns> private HolidayInfo GetHoliday(int type, string holiday) { HolidayInfo info = new HolidayInfo(); string[] tempStr = holiday.Split(" ".ToCharArray()); switch (type) { case 3: info.name = tempStr[1]; info.month = Convert.ToInt32(tempStr[0].Substring(0, 2)); info.count = Convert.ToInt32(tempStr[0].Substring(2, 1)); info.day = Convert.ToInt32(tempStr[0].Substring(3, 1)); break; default: info.name = tempStr[1]; info.month = Convert.ToInt32(tempStr[0].Substring(0, 2)); info.day = Convert.ToInt32(tempStr[0].Substring(2, 2)); break; } return(info); }
public HolidayInfo HolidaySettingsSearchByDate(string strMonth, string strYear, string strDay) { HolidayInfo infoHoliday = new HolidayInfo(); SqlDataReader sqldr = null; try { if (sqlcon.State == ConnectionState.Closed) { sqlcon.Open(); } SqlCommand sqlcmd = new SqlCommand("HolidaySettingsSearchByDate", sqlcon); sqlcmd.CommandType = CommandType.StoredProcedure; SqlParameter sprmparam = new SqlParameter(); sprmparam = sqlcmd.Parameters.Add("@Month", SqlDbType.VarChar); sprmparam.Value = strMonth; sprmparam = sqlcmd.Parameters.Add("@Year", SqlDbType.VarChar); sprmparam.Value = strYear; sprmparam = sqlcmd.Parameters.Add("@Day", SqlDbType.VarChar); sprmparam.Value = strDay; sqldr = sqlcmd.ExecuteReader(); while (sqldr.Read()) { infoHoliday.HolidayId = Convert.ToDecimal(sqldr["holidayId"].ToString()); infoHoliday.Narration = Convert.ToString(sqldr["narration"].ToString()); } } catch (Exception ex) { ////Messages.ErrorMessage(ex.ToString()); } finally { sqldr.Close(); sqlcon.Close(); } return(infoHoliday); }
/// <summary> /// Function to Update values in Holiday Table /// </summary> /// <param name="holidayinfo"></param> public void HolidayEdit(HolidayInfo holidayinfo) { try { if (sqlcon.State == ConnectionState.Closed) { sqlcon.Open(); } SqlCommand sccmd = new SqlCommand("HolidayEdit", sqlcon); sccmd.CommandType = CommandType.StoredProcedure; SqlParameter sprmparam = new SqlParameter(); sprmparam = sccmd.Parameters.Add("@holidayId", SqlDbType.Decimal); sprmparam.Value = holidayinfo.HolidayId; sprmparam = sccmd.Parameters.Add("@date", SqlDbType.DateTime); sprmparam.Value = holidayinfo.Date; sprmparam = sccmd.Parameters.Add("@holidayName", SqlDbType.VarChar); sprmparam.Value = holidayinfo.HolidayName; sprmparam = sccmd.Parameters.Add("@narration", SqlDbType.VarChar); sprmparam.Value = holidayinfo.Narration; sprmparam = sccmd.Parameters.Add("@extraDate", SqlDbType.DateTime); sprmparam.Value = holidayinfo.ExtraDate; sprmparam = sccmd.Parameters.Add("@extra1", SqlDbType.VarChar); sprmparam.Value = holidayinfo.Extra1; sprmparam = sccmd.Parameters.Add("@extra2", SqlDbType.VarChar); sprmparam.Value = holidayinfo.Extra2; sccmd.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { sqlcon.Close(); } }
private static readonly DateTime FURIKAE = new DateTime(1973, 07, 12); // 振替休日制度の開始日 // その日が何かを調べるメソッド public static HolidayInfo Holiday(DateTime t) { int yy = t.Year; int mm = t.Month; int dd = t.Day; DayOfWeek ww = t.DayOfWeek; HolidayInfo result = new HolidayInfo(); result.week = ww; result.holiday = HolidayInfo.HOLIDAY.WEEKDAY; // 祝日法施行以前 if (t < SYUKUJITSU) { return(result); } switch (mm) { // 1月 // case 1: if (dd == 1) { result.holiday = HolidayInfo.HOLIDAY.SYUKUJITSU; result.name = "元日"; // 07/5/28 祝日名が '元旦' になっていたのを修正 } else if (dd == 2) { result.name = "1月2日"; } else if (dd == 3) { result.name = "1月3日"; } else { if (yy >= 2000) { if (((int)((dd - 1) / 7) == 1) && (ww == DayOfWeek.Monday)) { result.holiday = HolidayInfo.HOLIDAY.SYUKUJITSU; result.name = "成人の日"; } } else { if (dd == 15) { result.holiday = HolidayInfo.HOLIDAY.SYUKUJITSU; result.name = "成人の日"; } } } break; // 2月 // case 2: if (dd == 11) { if (yy >= 1967) { result.holiday = HolidayInfo.HOLIDAY.SYUKUJITSU; result.name = "建国記念の日"; } } else if ((yy == 1989) && (dd == 24)) { result.holiday = HolidayInfo.HOLIDAY.SYUKUJITSU; result.name = "昭和天皇の大喪の礼"; } break; // 3月 // case 3: if (dd == Syunbun(yy)) { result.holiday = HolidayInfo.HOLIDAY.SYUKUJITSU; result.name = "春分の日"; } break; // 4月 // case 4: if (dd == 29) { if (yy >= 2007) { result.holiday = HolidayInfo.HOLIDAY.SYUKUJITSU; result.name = "昭和の日"; } else if (yy >= 1989) { result.holiday = HolidayInfo.HOLIDAY.SYUKUJITSU; result.name = "みどりの日"; } else { result.holiday = HolidayInfo.HOLIDAY.SYUKUJITSU; result.name = "天皇誕生日"; } } else if ((yy == 1959) && (dd == 10)) { result.holiday = HolidayInfo.HOLIDAY.SYUKUJITSU; result.name = "皇太子明仁親王の結婚の儀"; } break; // 5月 // case 5: if (dd == 3) { result.holiday = HolidayInfo.HOLIDAY.SYUKUJITSU; result.name = "憲法記念日"; } else if (dd == 4) { if (yy >= 2007) { result.holiday = HolidayInfo.HOLIDAY.SYUKUJITSU; result.name = "みどりの日"; } else if (yy >= 1986) { /* 5/4が日曜日は『只の日曜』、月曜日は『憲法記念日の振替休日』(~2006年)*/ if (ww > DayOfWeek.Monday) { result.holiday = HolidayInfo.HOLIDAY.HOLIDAY; result.name = "国民の休日"; } } } else if (dd == 5) { result.holiday = HolidayInfo.HOLIDAY.SYUKUJITSU; result.name = "こどもの日"; } else if (dd == 6) { /* 07/11/21 [Wednesday or Thursday] → [Tuesday or Wednesday] に訂正 */ /* [5/3,5/4が日曜]ケースのみ、ここで判定 */ if ((yy >= 2007) && ((ww == DayOfWeek.Tuesday) || (ww == DayOfWeek.Wednesday))) { result.holiday = HolidayInfo.HOLIDAY.C_HOLIDAY; result.name = "振替休日"; } } break; // 6月 // case 6: if ((yy == 1993) && (dd == 9)) { result.holiday = HolidayInfo.HOLIDAY.SYUKUJITSU; result.name = "皇太子徳仁親王の結婚の儀"; } break; // 7月 // case 7: if (yy >= 2003) { if (((int)((dd - 1) / 7) == 2) && (ww == DayOfWeek.Monday)) { result.holiday = HolidayInfo.HOLIDAY.SYUKUJITSU; result.name = "海の日"; } } else if (yy >= 1996) { if (dd == 20) { result.holiday = HolidayInfo.HOLIDAY.SYUKUJITSU; result.name = "海の日"; } } break; // 8月 // case 8: break; // 9月 // case 9: if (dd == Syubun(yy)) { result.holiday = HolidayInfo.HOLIDAY.SYUKUJITSU; result.name = "秋分の日"; } else { if (yy >= 2003) { if (((int)((dd - 1) / 7) == 2) && (ww == DayOfWeek.Monday)) { result.holiday = HolidayInfo.HOLIDAY.SYUKUJITSU; result.name = "敬老の日"; } else if (ww == DayOfWeek.Tuesday) { if (dd == Syubun(yy) - 1) { result.holiday = HolidayInfo.HOLIDAY.HOLIDAY; result.name = "国民の休日"; } } } else if (yy >= 1966) { if (dd == 15) { result.holiday = HolidayInfo.HOLIDAY.SYUKUJITSU; result.name = "敬老の日"; } } } break; // 10月 // case 10: if (yy >= 2000) { if (((int)((dd - 1) / 7) == 1) && (ww == DayOfWeek.Monday)) { result.holiday = HolidayInfo.HOLIDAY.SYUKUJITSU; result.name = "体育の日"; } } else if (yy >= 1966) { if (dd == 10) { result.holiday = HolidayInfo.HOLIDAY.SYUKUJITSU; result.name = "体育の日"; } } break; // 11月 // case 11: if (dd == 3) { result.holiday = HolidayInfo.HOLIDAY.SYUKUJITSU; result.name = "文化の日"; } else if (dd == 23) { result.holiday = HolidayInfo.HOLIDAY.SYUKUJITSU; result.name = "勤労感謝の日"; } else if ((yy == 1990) && (dd == 12)) { result.holiday = HolidayInfo.HOLIDAY.SYUKUJITSU; result.name = "即位礼正殿の儀"; } break; // 12月 // case 12: if (dd == 23) { if (yy >= 1989) { result.holiday = HolidayInfo.HOLIDAY.SYUKUJITSU; result.name = "天皇誕生日"; } } else if (dd == 31) { result.name = "12月31日"; } break; default: break; } if ((result.holiday == HolidayInfo.HOLIDAY.WEEKDAY || result.holiday == HolidayInfo.HOLIDAY.HOLIDAY) && (ww == DayOfWeek.Monday)) { /*月曜以外は振替休日判定不要 * 5/6(火,水)の判定は上記ステップで処理済 * 5/6(月)はここで判定する */ if (t >= FURIKAE) { if (Holiday(t.AddDays(-1)).holiday == HolidayInfo.HOLIDAY.SYUKUJITSU) /* 再帰呼出 */ { result.holiday = HolidayInfo.HOLIDAY.C_HOLIDAY; result.name = "振替休日"; } } } return(result); }
private List <HolidayInfo> GetHolidayInfoFromGats() { GatsUtil gats = new GatsUtil(); string response = gats.GetGatsResponse(configObj.QueryCommand.ToUpper(), ""); if (string.IsNullOrEmpty(response)) { string msg = "Can't get holiday information, please check your command."; Logger.Log(msg, Logger.LogType.Error); throw new Exception(msg); } Logger.Log("Get holiday information by GATS. OK!"); //TaskResultList.Add(new TaskResultEntry("Holiday Infomation", "Holiday Infomation", outputPath)); List <HolidayInfo> holiday = new List <HolidayInfo>(); //string[] content = File.ReadAllLines(outputPath); string[] content = response.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); string year = string.Empty; int startLine = 0; for (int i = 0; i < content.Length; i++) { string row = content[i]; if (row.Contains("DATES") && row.Contains("MARKET HOLIDAY")) { year = Regex.Match(row, @"\d{4}").Value; startLine = i + 1; break; } } for (int i = startLine; i < content.Length; i++) { List <string> dateList = FindHolidayInfo(content[i]);//content[i].Substring(42, 6).Trim(); if (dateList == null || dateList.Count == 0) { continue; } foreach (string dateStr in dateList) { string date = dateStr.Replace(" ", "-"); string month = date.Split('-')[1]; date = date + "-" + year; DateTime dt; if (!DateTime.TryParse(date, out dt)) { break; } string comment = content[i].Substring(content[i].IndexOf(month) + month.Length).TrimStart(); int blankIndex = comment.IndexOf(" "); if (blankIndex != -1) { comment = comment.Substring(0, blankIndex); } HolidayInfo item = new HolidayInfo(); item.HolidayDate = date; item.MarketId = (int)configObj.MarketId; item.Comment = comment; if (item.Comment.ToLower().Contains("half day") && configObj.MarketId.Equals(MarketIdEnum.Japan)) { continue; } holiday.Add(item); } } return(holiday); }
/// <summary> /// 拆解Holiday,type种类:1.阳历固定;2.农历固定;3.某月第几个星期几; /// </summary> /// <param name="currentDayInfo"></param> /// <returns></returns> private HolidayInfo GetHoliday(int type,string holiday) { HolidayInfo info = new HolidayInfo(); string[] tempStr = holiday.Split(" ".ToCharArray()); switch (type) { case 3: info.name=tempStr[1]; info.month = Convert.ToInt32(tempStr[0].Substring(0, 2)); info.count = Convert.ToInt32(tempStr[0].Substring(2, 1)); info.day = Convert.ToInt32(tempStr[0].Substring(3, 1)); break; default: info.name = tempStr[1]; info.month = Convert.ToInt32(tempStr[0].Substring(0, 2)); info.day = Convert.ToInt32(tempStr[0].Substring(2, 2)); break; } return info; }
/// <summary> /// 判断是否为阳历的节假日,包括周末 /// </summary> /// <param name="currentDayInfo"></param> /// <returns></returns> private bool IsHoliday(ref DayInfo currentDayInfo) { bool result = false; if (currentDayInfo.date.DayOfWeek == DayOfWeek.Saturday || currentDayInfo.date.DayOfWeek == DayOfWeek.Sunday) { result = true; } HolidayInfo info=new HolidayInfo(); foreach (string cHoliday in holidays) { info = GetHoliday(1, cHoliday); if (info.month==currentDayInfo.date.Month && info.day ==currentDayInfo.date.Day) { currentDayInfo.holiday += info.name.Replace("*", "") + "\n"; if (info.name.Contains("*")) { result = true; } } } foreach (string cHoliday in nDayHolidays) { info = GetHoliday(3, cHoliday); if (info.month != currentDayInfo.date.Month) { continue; } if (Convert.ToInt32(currentDayInfo.date.DayOfWeek)!=info.day) { continue; } else { DateTime tmpDate = currentDayInfo.date; int count = 0; if (info.count==5) { do { tmpDate = tmpDate.AddDays(7); if (tmpDate.Month != currentDayInfo.date.Month) { break; } count++; } while (true); if (count == 0) { currentDayInfo.holiday += info.name.Replace("*", "") + "\n"; if (info.name.Contains("*")) { result = true; } } return result; } do { count++; tmpDate = tmpDate.AddDays(-7); } while (tmpDate.Month == displayDate.Month); if (count==info.count) { currentDayInfo.holiday += info.name.Replace("*", "") + "\n"; if (info.name.Contains("*")) { result = true; } } } } return result; }
/// <summary> /// 判断是否为农历节假日,包括节气 /// </summary> /// <param name="currentDayInfo"></param> /// <returns></returns> private bool IsLunarHoliday(ref DayInfo currentDayInfo) { bool result = false; if (currentDayInfo.term!=null) { if (currentDayInfo.term.Contains("清明")) { return true; } } HolidayInfo info = new HolidayInfo(); foreach (string cHoliday in lunarHolidays) { info = GetHoliday(2, cHoliday); if (currentDayInfo.lunarM==info.month && currentDayInfo.lunarD==info.day) { currentDayInfo.lunarHoliday = info.name.Replace("*", "") + "\n"; if (info.name.Contains("*")) { result = true; } } } return result; }
private static readonly DateTime SYUKUJITSU = new DateTime(1948, 7, 20); // 祝日法施行日 #endregion Fields #region Methods // その日が何かを調べるメソッド public static HolidayInfo Holiday(DateTime t) { int yy = t.Year; int mm = t.Month; int dd = t.Day; DayOfWeek ww = t.DayOfWeek; HolidayInfo result = new HolidayInfo(); result.week = ww; result.holiday = HolidayInfo.HOLIDAY.WEEKDAY; // 祝日法施行以前 if (t < SYUKUJITSU) return result; switch (mm) { // 1月 // case 1: if (dd == 1) { result.holiday = HolidayInfo.HOLIDAY.SYUKUJITSU; result.name = "元日"; } else { if (yy >= 2000) { if (((int)((dd - 1) / 7) == 1) && (ww == DayOfWeek.Monday)) { result.holiday = HolidayInfo.HOLIDAY.SYUKUJITSU; result.name = "成人の日"; } } else { if (dd == 15) { result.holiday = HolidayInfo.HOLIDAY.SYUKUJITSU; result.name = "成人の日"; } } } break; // 2月 // case 2: if (dd == 11) { if (yy >= 1967) { result.holiday = HolidayInfo.HOLIDAY.SYUKUJITSU; result.name = "建国記念の日"; } } else if ((yy == 1989) && (dd == 24)) { result.holiday = HolidayInfo.HOLIDAY.SYUKUJITSU; result.name = "昭和天皇の大喪の礼"; } break; // 3月 // case 3: if (dd == Syunbun(yy)) { result.holiday = HolidayInfo.HOLIDAY.SYUKUJITSU; result.name = "春分の日"; } break; // 4月 // case 4: if (dd == 29) { if (yy >= 2007) { result.holiday = HolidayInfo.HOLIDAY.SYUKUJITSU; result.name = "昭和の日"; } else if (yy >= 1989) { result.holiday = HolidayInfo.HOLIDAY.SYUKUJITSU; result.name = "みどりの日"; } else { result.holiday = HolidayInfo.HOLIDAY.SYUKUJITSU; result.name = "天皇誕生日"; } } else if ((yy == 1959) && (dd == 10)) { result.holiday = HolidayInfo.HOLIDAY.SYUKUJITSU; result.name = "皇太子明仁親王の結婚の儀"; } break; // 5月 // case 5: if (dd == 3) { result.holiday = HolidayInfo.HOLIDAY.SYUKUJITSU; result.name = "憲法記念日"; } else if (dd == 4) { if (yy >= 2007) { result.holiday = HolidayInfo.HOLIDAY.SYUKUJITSU; result.name = "みどりの日"; } else if (yy >= 1986) { /* 5/4が日曜日は『只の日曜』、月曜日は『憲法記念日の振替休日』(~2006年)*/ if (ww > DayOfWeek.Monday) { result.holiday = HolidayInfo.HOLIDAY.HOLIDAY; result.name = "国民の休日"; } } } else if (dd == 5) { result.holiday = HolidayInfo.HOLIDAY.SYUKUJITSU; result.name = "こどもの日"; } else if (dd == 6) { /* [5/3,5/4が日曜]ケースのみ、ここで判定 */ if ((yy >= 2007) && ((ww == DayOfWeek.Tuesday) || (ww == DayOfWeek.Wednesday))) { result.holiday = HolidayInfo.HOLIDAY.C_HOLIDAY; result.name = "振替休日"; } } break; // 6月 // case 6: if ((yy == 1993) && (dd == 9)) { result.holiday = HolidayInfo.HOLIDAY.SYUKUJITSU; result.name = "皇太子徳仁親王の結婚の儀"; } break; // 7月 // case 7: if (yy >= 2003) { if (((int)((dd - 1) / 7) == 2) && (ww == DayOfWeek.Monday)) { result.holiday = HolidayInfo.HOLIDAY.SYUKUJITSU; result.name = "海の日"; } } else if (yy >= 1996) { if (dd == 20) { result.holiday = HolidayInfo.HOLIDAY.SYUKUJITSU; result.name = "海の日"; } } break; // 8月 // case 8: if (dd == 11) { if (yy >= 2016) { result.holiday = HolidayInfo.HOLIDAY.SYUKUJITSU; result.name = "山の日"; } } break; // 9月 // case 9: if (dd == Syubun(yy)) { result.holiday = HolidayInfo.HOLIDAY.SYUKUJITSU; result.name = "秋分の日"; } else { if (yy >= 2003) { if (((int)((dd - 1) / 7) == 2) && (ww == DayOfWeek.Monday)) { result.holiday = HolidayInfo.HOLIDAY.SYUKUJITSU; result.name = "敬老の日"; } else if (ww == DayOfWeek.Tuesday) { if (dd == Syubun(yy) - 1) { result.holiday = HolidayInfo.HOLIDAY.HOLIDAY; result.name = "国民の休日"; } } } else if (yy >= 1966) { if (dd == 15) { result.holiday = HolidayInfo.HOLIDAY.SYUKUJITSU; result.name = "敬老の日"; } } } break; // 10月 // case 10: if (yy >= 2000) { if (((int)((dd - 1) / 7) == 1) && (ww == DayOfWeek.Monday)) { result.holiday = HolidayInfo.HOLIDAY.SYUKUJITSU; result.name = "体育の日"; } } else if (yy >= 1966) { if (dd == 10) { result.holiday = HolidayInfo.HOLIDAY.SYUKUJITSU; result.name = "体育の日"; } } break; // 11月 // case 11: if (dd == 3) { result.holiday = HolidayInfo.HOLIDAY.SYUKUJITSU; result.name = "文化の日"; } else if (dd == 23) { result.holiday = HolidayInfo.HOLIDAY.SYUKUJITSU; result.name = "勤労感謝の日"; } else if ((yy == 1990) && (dd == 12)) { result.holiday = HolidayInfo.HOLIDAY.SYUKUJITSU; result.name = "即位礼正殿の儀"; } break; // 12月 // case 12: if (dd == 23) { if (yy >= 1989) { result.holiday = HolidayInfo.HOLIDAY.SYUKUJITSU; result.name = "天皇誕生日"; } } break; default: break; } if ((result.holiday == HolidayInfo.HOLIDAY.WEEKDAY || result.holiday == HolidayInfo.HOLIDAY.HOLIDAY) && (ww == DayOfWeek.Monday)) { /*月曜以外は振替休日判定不要 5/6(火,水)の判定は上記ステップで処理済 5/6(月)はここで判定する */ if (t >= FURIKAE) { if (Holiday(t.AddDays(-1)).holiday == HolidayInfo.HOLIDAY.SYUKUJITSU) { /* 再帰呼出 */ result.holiday = HolidayInfo.HOLIDAY.C_HOLIDAY; result.name = "振替休日"; } } } return result; }
//Tatil Gunu Hesaplamasi public double CalculateDays(DateTime BookCheckInDate, DateTime BookChectOutDate, HolidayInfo HolidayInfo) { double totalHolidayCount = 0; for (DateTime k = BookCheckInDate; k < BookChectOutDate;) { var weekends = HolidayInfo.weekEnds.Split('/').Select(Int32.Parse).ToList(); if (weekends.Contains((int)k.DayOfWeek)) { totalHolidayCount += 1; //eger haftasonu ise devam et k = k.AddDays(1); continue; } if (HolidayInfo.Days.Contains(k.DayOfYear)) { var index = HolidayInfo.Days.IndexOf(k.DayOfYear); totalHolidayCount += HolidayInfo.HolidayDayLength.ElementAt(index) * 1; } k = k.AddDays(1); } return(totalHolidayCount); }