본문 바로가기
VB.net

MonthCalendar를 이용해 주말 체크 로직

by 호야호잇 2018. 12. 17.

      If DBread.Read() Then

            일수 = DBread.GetValue(2)

        End If

        DBread.Close()

        mySqlCommAND.Dispose()

        DBConn.Close()


        Dim 시작날짜 As Date = MonthCalendar1.SelectionStart

        Dim 종료날짜 As Date = 시작날짜.AddDays(+일수)


        '토요일, 일요일 수 구하기


        Dim 제외날짜 As Integer = 0

        Dim 제외날짜2 As Integer = 0

        Dim saturdays As Integer = CInt(DateDiff(DateInterval.WeekOfYear, 시작날짜, 종료날짜, FirstDayOfWeek.Saturday))

        Dim sundays As Integer = CInt(DateDiff(DateInterval.WeekOfYear, 시작날짜, 종료날짜, FirstDayOfWeek.Sunday))

        제외날짜 = saturdays + sundays


        Dim saturdays2 As Integer = CInt(DateDiff(DateInterval.WeekOfYear, 시작날짜, 종료날짜.AddDays(+제외날짜), FirstDayOfWeek.Saturday))

        Dim sundays2 As Integer = CInt(DateDiff(DateInterval.WeekOfYear, 시작날짜, 종료날짜.AddDays(+제외날짜), FirstDayOfWeek.Sunday))

        제외날짜2 = saturdays2 + sundays2


        '시작일부터 종료일까지  Selection  재설정

        MonthCalendar1.SelectionStart = MonthCalendar1.SelectionStart

        MonthCalendar1.SelectionEnd = MonthCalendar1.SelectionEnd.AddDays(+제외날짜2)




        Dim 공휴일 As Integer = 0

        For k = 0 To ListBox1.Items.Count - 1

            If Int(Format(MonthCalendar1.SelectionStart, "yyyyMMdd")) <= Int(Replace(ListBox1.Items(k), "-", "")) And

                Int(Format(MonthCalendar1.SelectionEnd, "yyyyMMdd")) >= Int(Replace(ListBox1.Items(k), "-", "")) Then

                공휴일 += 1

            End If

        Next


        '시작일부터 종료일까지  Selection  재설정

        MonthCalendar1.SelectionStart = MonthCalendar1.SelectionStart

        MonthCalendar1.SelectionEnd = MonthCalendar1.SelectionEnd.AddDays(+공휴일)


        TextBox1.Text = Format(MonthCalendar1.SelectionEnd, "yyyy-MM-dd")

        TextBox2.Text = Format(MonthCalendar1.SelectionEnd, "ddd")

        변경종료날짜 = MonthCalendar1.SelectionEnd