public static List <t_calendar_information> getCalenderInfoAllList() { NpgsqlDataReader dataReader = null; var res = new List <t_calendar_information>(); using (var dbc = new DB.DBConnect()) { dbc.npg.Open(); StringBuilder sb = new StringBuilder(); sb.Append(@"select store_code,date,notice,holiday_class "); sb.Append(@"from t_calendar_Information "); sb.Append(@"order by store_code,date"); var command = new NpgsqlCommand(sb.ToString(), dbc.npg); dataReader = command.ExecuteReader(); while (dataReader.Read()) { t_calendar_information calendar_Information = new t_calendar_information(); calendar_Information.store_code = dataReader["store_code"].ToString(); calendar_Information.date = DateTime.Parse(dataReader["date"].ToString()); calendar_Information.notice = dataReader["notice"].ToString(); calendar_Information.holiday_class = dataReader["holiday_class"].ToString(); res.Add(calendar_Information); } } return(res); }
public static t_calendar_information getSingle(string store_code, DateTime date) { t_calendar_information data = null; using (var dbc = new DB.DBConnect()) { data = dbc.t_calendar_information.SingleOrDefault(x => x.store_code == store_code & x.date == date); } return(data); }
private void setNotice(DateTime date) { var storeCode = storeList[d_tenpomei.SelectedItem.ToString()]; DB.t_calendar_information cal = DB.t_calendar_information.getSingle(storeCode, date); if (cal == null) { d_osirase.Text = ""; } else { d_osirase.Text = cal.notice; } }
private void b_regist_Click(object sender, EventArgs e) { //登録処理 //日付の特定 List <DateTime> dates = new List <DateTime>(); var interval = int.Parse(n_kankaku.Value.ToString()); var enddate = d_syuryoubi.Text.ToString() != "" ? DateTime.Parse(d_syuryoubi.Text.ToString()) : DateTime.MaxValue; //繰り返し方法により分岐 if (d_kurikaeshi.Text == "なし") { dates.Add(monthCalendar1.SelectionStart); } else if (d_kurikaeshi.Text == "毎週") { List <int> week = new List <int>(); if (c_monday.Checked == true) { week.Add(1); } if (c_tuseday.Checked == true) { week.Add(2); } if (c_wednesday.Checked == true) { week.Add(3); } if (c_thursday.Checked == true) { week.Add(4); } if (c_friday.Checked == true) { week.Add(5); } if (c_saturday.Checked == true) { week.Add(6); } if (c_sunday.Checked == true) { week.Add(0); } //日付指定、回数指定 if (r_kai.Checked == true && t_kaisu.ToString() != "") { int.TryParse(t_kaisu.Text.ToString(), out int count); dates = GetWeeks(DateTime.Parse(d_kaishibi.Text), count, week, interval); } else { dates = GetWeeks(DateTime.Parse(d_kaishibi.Text), enddate, week, interval); } } else if (d_kurikaeshi.Text == "毎月") { //日付指定、回数指定 if (r_kai.Checked == true && t_kaisu.ToString() != "") { int.TryParse(t_kaisu.Text.ToString(), out int count); dates = GetDays(DateTime.Parse(d_kaishibi.Text), count, interval); } else { dates = GetDays(DateTime.Parse(d_kaishibi.Text), enddate, interval); } } var storecode = storeCodeList.Find(x => x.store_name == d_tenpo.Text.ToString()).store_code; foreach (DateTime d in dates) { DB.t_calendar_information calendar_Information = new DB.t_calendar_information(); using (var dbc = new DB.DBConnect()) { dbc.npg.Open(); using (var transaction = dbc.npg.BeginTransaction()) { var holiday_class = d_kyujitsukubun.Text.ToString() == "営業日" ? (int)Utile.Data.休日区分.営業日 : d_kyujitsukubun.Text.ToString() == "定休日" ? (int)Utile.Data.休日区分.定休日 : (int)Utile.Data.休日区分.臨時休業; //登録処理 var data = dbc.t_calendar_information.FirstOrDefault(x => x.store_code == storecode & x.date == d.Date); if (data == null) { //新規登録 calendar_Information.store_code = storecode; calendar_Information.date = d.Date; calendar_Information.notice = t_oshirashe.Text.ToString(); calendar_Information.holiday_class = holiday_class.ToString(); calendar_Information.registration_date = DateTime.Now.Date; calendar_Information.registration_staff = MainForm.session_m_staff.staff_name; dbc.t_calendar_information.Add(calendar_Information); } else { //更新情報 data.notice = t_oshirashe.Text.ToString(); data.store_code = storecode; data.holiday_class = holiday_class.ToString(); data.update_date = DateTime.Now.Date; data.update_staff = MainForm.session_m_staff.staff_name; } try { dbc.SaveChanges(); transaction.Commit(); } catch (Exception) { transaction.Rollback(); throw; } } } } //ひとつ前に戻る MainForm.Store_calender.PageRefresh(); MainForm.backPage(this); }