private void contentsSaveAndDisplay()
        {
            DBManager.Contents.data contents = new DBManager.Contents.data();

            // 新規登録
            if (bNewEntry)
            {
                setToContents(contents);
                insert(contents);
                contentsList.Add(contents);
            }
            // 更新
            else
            {
                lock (contentsList)
                {
                    // 対象のコンテンツ一覧から検索取得
                    DBManager.Contents.data data = contentsList.SelectId(id);
                    if (data != null)
                    {
                        contents = data;
                    }
                    setToContents(contents);
                }
                update(contents);
            }
            resetInputFields();

            // オーナフォーム(カレンダ)再表示
            parentForm.setCalendar();
        }
Beispiel #2
0
        private void btnCreate_Click(object sender, EventArgs e)
        {
            string    year         = dtpHolidayYear.Value.ToString("yyyy");
            int       intYear      = int.Parse(year);
            ArrayList holidayList  = new ArrayList();
            ArrayList holidayList2 = new ArrayList();
            ArrayList holidayList3 = new ArrayList();

            // 警告メッセージ
            if (MessageBox.Show(this, "この処理を実行すると一旦当該年度の祝祭日を消去し作り直します。\r\n手動設定の情報は削除されます。実行してよろしいですか?", "警告", MessageBoxButtons.YesNo) == DialogResult.No)
            {
                return;
            }

            string strSQL = "select count(*) from holiday_list where strftime('%Y', holiday_date) = '" + year + "' ";

            // 祝祭日DBに該当年のデータがあるかどうか確認
            SQLiteDataReader result = sqliteAccess.select(strSQL);

            if (result != null && result.Read())
            {
                if (result.GetInt32(0) > 0)
                {
                    sqliteAccess.readerClose();
                    strSQL = "delete from holiday_list where strftime('%Y', holiday_date) = '" + year + "' ";
                    sqliteAccess.update(strSQL);
                }
            }
            sqliteAccess.readerClose();

            // 祝祭日マスタ読込
            strSQL = "select * from holiday_master order by id";
            result = sqliteAccess.select(strSQL);
            if (result != null)
            {
                masterList.Clear();
                while (result.Read())
                {
                    holidayMaster hm = new holidayMaster();

                    hm.id           = result.GetInt32(0);
                    hm.holiday_type = result.GetInt32(1);
                    hm.holiday_name = result.GetString(2);
                    hm.third        = result.GetInt32(3);
                    hm.fourth       = result.GetInt32(4);
                    hm.fifth        = result.GetInt32(5);
                    hm.sixth        = result.GetInt32(6);
                    hm.seventh      = result.GetInt32(7);

                    masterList.Add(hm);
                }
                sqliteAccess.readerClose();

                foreach (holidayMaster hm in masterList)
                {
                    DateTime date      = DateTime.Today;
                    int      weekCount = 0;
                    bool     effective = true;

                    // 有効期日指定があるなら
                    if (hm.seventh != -1)
                    {
                        int effectiveYear = hm.sixth;
                        effective = false;

                        // 判定方法分岐
                        switch (hm.seventh)
                        {
                        case 0:         // <
                            if (intYear < effectiveYear)
                            {
                                effective = true;
                            }
                            break;

                        case 1:         // >
                            if (intYear > effectiveYear)
                            {
                                effective = true;
                            }
                            break;

                        case 2:         // <=
                            if (intYear <= effectiveYear)
                            {
                                effective = true;
                            }
                            break;

                        case 3:         // >=
                            if (intYear >= effectiveYear)
                            {
                                effective = true;
                            }
                            break;

                        case 4:         // ==
                            if (effectiveYear == intYear)
                            {
                                effective = true;
                            }
                            break;

                        case 5:         // ><
                            if (effectiveYear != intYear)
                            {
                                effective = true;
                            }
                            break;
                        }
                    }

                    if (effective == false)
                    {
                        continue;
                    }
                    switch (hm.holiday_type)
                    {
                    case 0:         // 固定休日
                        date = DateTime.Parse(year + "/" + (hm.third + 1).ToString("00") + "/" + (hm.fourth + 1).ToString("00"));
                        break;

                    case 1:         // 週指定
                        date = DateTime.Parse(year + "/" + (hm.third + 1).ToString("00") + "/01");
                        for (int i = 0; i < 32; i++)
                        {
                            // 曜日が一致したら
                            if (hm.fifth == (int)dayOfWeekToNumber[date.DayOfWeek])
                            {
                                // 何週目かをカウント
                                weekCount++;
                            }
                            // 週カウンタが週指定に一致したら
                            if (weekCount == (hm.fourth + 1))
                            {
                                break;
                            }
                            date = date.AddDays(1);
                        }
                        break;

                    case 2:         // 春分・秋分の日
                        // 春分の日(3月)
                        if ((hm.third + 1) == 3)
                        {
                            double dDay = 20.69115;         // 春分日の10進法換算値
                            int    day  = 0;                // 春分日の10進法換算値
                            double diff = 0.242194;         // 年間移動量

                            double move = ((double)(intYear - 2000) * diff) - ((intYear - 2000) / 4);
                            day = (int)(dDay + move);

                            date = DateTime.Parse(year + "/" + (hm.third + 1).ToString("00") + "/" + day.ToString("00"));
                        }
                        else if ((hm.third + 1) == 9)
                        {
                            double dDay = 23.09;            // 春分日の10進法換算値
                            int    day  = 0;                // 春分日の10進法換算値
                            double diff = 0.242194;         // 年間移動量

                            double move = ((double)(intYear - 2000) * diff) - ((intYear - 2000) / 4);
                            day = (int)(dDay + move);

                            date = DateTime.Parse(year + "/" + (hm.third + 1).ToString("00") + "/" + day.ToString("00"));
                        }
                        break;
                    }

                    holidays holiday = new holidays();
                    holiday.date = new DateTime(date.Year, date.Month, date.Day);
                    holiday.type = hm.holiday_type;
                    holiday.name = hm.holiday_name;
                    holidayList.Add(holiday);
                }

                holidayList2.Clear();
                bool     alternative    = false;
                DateTime alternativeDay = new DateTime(intYear, 1, 1);
                foreach (holidays hd in holidayList)
                {
                    // 対象日付が俗称"改定振り替え休日"施行日以降なら
                    // (”祝日が日曜にあたるときは、その日後において、その日に最も近い「国民の祝日」でない日を休日”)
                    if (int.Parse(hd.date.ToString("yyyy")) >= 2007)
                    {
                        // 振り替え判定が行われていたら
                        if (alternative == true)
                        {
                            // 次の休日にかぶっていないかを判定
                            if (alternativeDay < hd.date)
                            {
                                // かぶっていなければ振替休日を設定
                                holidays holiday = new holidays();
                                holiday.date = new DateTime(alternativeDay.Year, alternativeDay.Month, alternativeDay.Day);
                                holiday.type = 0;
                                holiday.name = "国民の休日";
                                holidayList2.Add(holiday);
                                alternative = false;
                            }
                            else
                            {
                                // かぶっていたら、さらに翌日送り
                                alternativeDay = hd.date.AddDays(1);
                            }
                        }
                        if (hd.date.DayOfWeek == DayOfWeek.Sunday)
                        {
                            alternative    = true;
                            alternativeDay = hd.date.AddDays(1);
                        }
                    }
                    // 対象日付が俗称"振り替え休日"施行日以降なら
                    // (祝日が日曜にあたるときは、その翌日を休日”)
                    else if (hd.date >= DateTime.Parse("1973/04/12"))
                    {
                        // 振り替え判定が行われていたら
                        if (alternative == true)
                        {
                            // 次の休日にかぶっていないかを判定
                            if (alternativeDay < hd.date)
                            {
                                holidays holiday = new holidays();
                                holiday.date = new DateTime(alternativeDay.Year, alternativeDay.Month, alternativeDay.Day);
                                holiday.type = 0;
                                holiday.name = "国民の休日";
                                holidayList2.Add(holiday);
                                alternative = false;
                            }
                            else
                            {
                                // かぶっていたら、その振替休日はなかったことに(涙)
                                alternative = false;
                            }
                        }
                        if (hd.date.DayOfWeek == DayOfWeek.Sunday)
                        {
                            alternative    = true;
                            alternativeDay = hd.date.AddDays(1);
                        }
                    }
                    holidayList2.Add(hd);
                }

                holidayList3.Clear();
                DateTime beforeDate = new DateTime(intYear, 1, 1);
                foreach (holidays hd in holidayList2)
                {
                    // 直前休日と今回休日が一日飛ばしの場合で
                    if (hd.date.Subtract(beforeDate).Days == 2)
                    {
                        beforeDate = beforeDate.AddDays(1);
                        if (beforeDate.DayOfWeek != DayOfWeek.Sunday)
                        {
                            holidays holiday = new holidays();
                            holiday.date = new DateTime(beforeDate.Year, beforeDate.Month, beforeDate.Day);
                            holiday.type = 0;
                            holiday.name = "国民の休日";
                            holidayList3.Add(holiday);
                        }
                    }
                    beforeDate = hd.date;
                    holidayList3.Add(hd);
                }

                foreach (holidays holiday in holidayList3)
                {
                    strSQL = "insert into holiday_list ("
                             + "holiday_date"
                             + ", holiday_type"
                             + ", holiday_name"
                             + ") values ( "
                             + "datetime('" + holiday.date.ToString("yyyy-MM-dd 00:00:00") + "')"
                             + ", " + holiday.type
                             + ", '" + holiday.name + "' )";

                    sqliteAccess.insert(strSQL, null);
                }
                sqliteAccess.readerClose();
            }
            loadYearyHoliday();

            // オーナフォーム(カレンダ)再表示
            parentForm.setCalendar();
        }