Imports System.Security.Cryptography

Public Class 醫生班表設定
    Private Sub Set_門診資料()
        Dim ds6 As New DataSet
        門診_dgv.DataSource = Nothing : ds6.Clear()
        門診_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        門診_dgv.ColumnHeadersHeight = 50 : 門診_dgv.AllowUserToAddRows = False
        SQL_門診資料()
        da.Fill(ds6) : 門診_dgv.DataSource = ds6.Tables(0) : conn.Close()
        門診_dgv.Columns(0).FillWeight = 70 : 門診_dgv.Columns(1).FillWeight = 50 : 門診_dgv.Columns(2).FillWeight = 40
    End Sub
    Private Sub 醫生班表設定_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Set_門診資料()
    End Sub
    Private Sub 門診_dgv_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles 門診_dgv.CellClick
        If e.RowIndex = -1 Then : Else
            中_tb.Text = 門診_dgv("中", e.RowIndex).Value.ToString : 早_tb.Text = 門診_dgv("早", e.RowIndex).Value.ToString
            星期_tb.Text = 門診_dgv("星期", e.RowIndex).Value.ToString : 診別_tb.Text = 門診_dgv("診別", e.RowIndex).Value.ToString
            晚_tb.Text = 門診_dgv("晚", e.RowIndex).Value.ToString : 日期_dtp.Value = 門診_dgv("日期", e.RowIndex).Value.ToString
        End If
    End Sub
    Private Sub 時間修改_bt_Click(sender As Object, e As EventArgs) Handles 時間修改_bt.Click
        If 星期_tb.Text = "" Or 診別_tb.Text = "" Then : MsgBox("沒有選擇修改內容") : Else
            PA = 早_tb.Text : PA1 = 中_tb.Text : PA2 = 晚_tb.Text : PA3 = 星期_tb.Text : PA4 = 診別_tb.Text : PA5 = 日期_dtp.Text
            SQL_門診修改() : Set_門診資料() : conn.Close() : MsgBox("修改完成")
        End If
    End Sub
    Private Sub 新增門診_bt_Click(sender As Object, e As EventArgs) Handles 新增門診_bt.Click
        If 星期_tb.Text = "" Or 診別_tb.Text = "" Then : MsgBox("沒有選擇新增內容") : Else
            PA = 早_tb.Text : PA1 = 中_tb.Text : PA2 = 晚_tb.Text : PA3 = 星期_tb.Text : PA4 = 診別_tb.Text : PA5 = 日期_dtp.Text
            SQL_門診資料_讀取()
            If dr.Read Then : MsgBox("已有資料，無法新增!!")
            Else : SQL_新增門診() : Set_門診資料() : conn.Close() : MsgBox("新增完成") : End If
        End If
    End Sub
    Private Sub 刪除門診_bt_Click(sender As Object, e As EventArgs) Handles 刪除門診_bt.Click
        If 星期_tb.Text = "" Or 診別_tb.Text = "" Then : MsgBox("沒有選擇刪除內容") : Else
            PA = 早_tb.Text : PA1 = 中_tb.Text : PA2 = 晚_tb.Text : PA3 = 星期_tb.Text : PA4 = 診別_tb.Text : PA5 = 日期_dtp.Text
            SQL_刪除門診() : Set_門診資料() : conn.Close() : MsgBox("刪除完成")
        End If
    End Sub
    Private Sub 門診_dgv_RowPostPaint(ByVal sender As Object, ByVal e As DataGridViewRowPostPaintEventArgs) Handles 門診_dgv.RowPostPaint
        Dim linePen As New Pen(Color.Red, 2)
        If e.RowIndex = 門診_dgv.Rows.Count - 1 Then : Exit Sub : Else
            If 門診_dgv(2, e.RowIndex).Value.ToString = "醫美" Then
                Dim startX As Integer = IIf(門診_dgv.RowHeadersVisible, 門診_dgv.RowHeadersWidth, 0) : Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
                Dim endX As Integer = startX + 門診_dgv.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - 門診_dgv.HorizontalScrollingOffset
                e.Graphics.DrawLine(linePen, startX, startY, endX, startY) : Exit Sub
            End If
        End If
    End Sub
    Private Sub 日期_dtp_ValueChanged(sender As Object, e As EventArgs) Handles 日期_dtp.ValueChanged
        Dim selectedDate As DateTime = 日期_dtp.Value : 星期_tb.Text = GetWeekDays(selectedDate)
    End Sub
    Private Function GetWeekDays(selectedDate As DateTime) As String
        Dim dayOfWeek As DayOfWeek = selectedDate.DayOfWeek : Dim weekDayString As String = ""
        Select Case dayOfWeek
            Case DayOfWeek.Sunday : weekDayString = "星期日"
            Case DayOfWeek.Monday : weekDayString = "星期一"
            Case DayOfWeek.Tuesday : weekDayString = "星期二"
            Case DayOfWeek.Wednesday : weekDayString = "星期三"
            Case DayOfWeek.Thursday : weekDayString = "星期四"
            Case DayOfWeek.Friday : weekDayString = "星期五"
            Case DayOfWeek.Saturday : weekDayString = "星期六"
        End Select
        Return weekDayString
    End Function
End Class