Nenhuma descrição
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

休假歷史紀錄.vb 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. Imports System.IO
  2. Imports Microsoft.Office.Interop.Excel.XlUnderlineStyle
  3. Imports Microsoft.Office.Interop.Excel.Constants
  4. Imports Microsoft.Office.Interop.Excel.XlBordersIndex
  5. Imports Microsoft.Office.Interop.Excel.XlLineStyle
  6. Imports Microsoft.Office.Interop.Excel.XlBorderWeight
  7. Imports Microsoft.Office.Interop.Excel.XlThemeFont
  8. Imports Microsoft.Office.Interop.Excel.XlThemeColor
  9. Imports Microsoft.Office.Interop.Excel.XlWindowState
  10. Imports Microsoft.Office.Interop.Excel.XlPageOrientation
  11. Imports Microsoft.Office.Interop.Excel
  12. Public Class 休假歷史紀錄
  13. ReadOnly ds, ds1 As New DataSet : Dim 剛開啟 As Boolean : Dim 位置1 As Integer
  14. Dim xlApp As Application : Dim xlBook As Workbook : Dim xlSheet As Worksheet
  15. Private Sub 讀取人員資料表()
  16. 人員_dgv.DataSource = Nothing : ds.Clear()
  17. 人員_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
  18. 人員_dgv.ColumnHeadersHeight = 25
  19. 人員_dgv.AllowUserToAddRows = False
  20. SQL_考勤明細表_人員()
  21. da.Fill(ds) : 人員_dgv.DataSource = ds.Tables(0) : conn.Close()
  22. 人員_dgv.Columns(0).FillWeight = 70 : 人員_dgv.Columns(1).FillWeight = 80 : 人員_dgv.Columns(2).FillWeight = 100 : 人員_dgv.Columns(3).Visible = False
  23. 人員_dgv.Columns(4).Visible = False : 人員_dgv.Columns(5).Visible = False : 人員_dgv.Columns(6).Visible = False : 人員_dgv.Columns(7).Visible = False
  24. 人員_dgv.Columns(8).Visible = False : 人員_dgv.Columns(9).Visible = False : 人員_dgv.Columns("到職日").Visible = False
  25. For i As Integer = 0 To 人員_dgv.Rows.Count - 1
  26. 人員_dgv.Rows(i).Cells("No.").Value = i + 1
  27. Next
  28. End Sub
  29. Private Sub 年份_下拉表單資料載入()
  30. SQL_考勤明細表_年份_下拉()
  31. 年份_cb.Items.Clear()
  32. While (dr.Read()) : 年份_cb.Items.Add(dr("年份")) : End While
  33. conn.Close()
  34. End Sub
  35. Private Sub Set_考勤明細()
  36. 月清單_DGV.DataSource = Nothing : ds1.Clear()
  37. 月清單_DGV.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
  38. 月清單_DGV.ColumnHeadersHeight = 40
  39. 月清單_DGV.AllowUserToAddRows = False
  40. PA = 員工編號_tb.Text : SQL_休假清單() 'PA = 年份_cb.Text & "/" & 月份_cb.Text :
  41. da.Fill(ds1) : 月清單_DGV.DataSource = ds1.Tables(0) : conn.Close()
  42. 月清單_DGV.Columns(0).FillWeight = 80 : 月清單_DGV.Columns(1).FillWeight = 40 : 月清單_DGV.Columns(2).FillWeight = 90 : 月清單_DGV.Columns(3).FillWeight = 65
  43. 月清單_DGV.Columns(4).FillWeight = 55 : 月清單_DGV.Columns(5).FillWeight = 150 : 月清單_DGV.Columns(6).FillWeight = 60 : 月清單_DGV.Columns(7).FillWeight = 80
  44. 月清單_DGV.Columns(8).FillWeight = 80 : 月清單_DGV.Columns("圖片資料庫").Visible = False : 月清單_DGV.Columns("圖片編號").Visible = False
  45. 月清單_DGV.Columns("申請時數").FillWeight = 50
  46. If 月清單_DGV.Rows.Count > 0 Then
  47. 請假日期_tb.Text = 月清單_DGV("日期", 0).Value.ToString : Set_假期統計()
  48. Else
  49. 假期統計_dgv.DataSource = Nothing
  50. End If
  51. End Sub
  52. Private Sub Set_假期統計()
  53. Dim ds As New DataSet
  54. 假期統計_dgv.DataSource = Nothing : ds.Clear()
  55. 假期統計_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
  56. 假期統計_dgv.ColumnHeadersHeight = 25
  57. 假期統計_dgv.AllowUserToAddRows = False
  58. PA = 員工編號_tb.Text : PA1 = 請假日期_tb.Text : SQL_休假統計()
  59. da.Fill(ds) : 假期統計_dgv.DataSource = ds.Tables(0) : conn.Close()
  60. End Sub
  61. Private Sub 歷史休假紀錄_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  62. 剛開啟 = True : 年份_下拉表單資料載入()
  63. 年份_cb.Text = Year(Today) : 月份_cb.SelectedIndex = Month(Today) - 1 : 請假類別_cb.SelectedIndex = 0
  64. PA1 = 年份_cb.Text : PA2 = 月份_cb.Text
  65. 讀取人員資料表() : Set_考勤明細() : 剛開啟 = False
  66. If gUserName = "*系統管理者" Then : 刪除_tb.Visible = True : Else : 刪除_tb.Visible = False : End If
  67. End Sub
  68. Private Sub 人員_dgv_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles 人員_dgv.CellClick
  69. If e.RowIndex = -1 Then : Else
  70. 員工編號_tb.Text = 人員_dgv("編號", e.RowIndex).Value.ToString : 申請人_tb.Text = 人員_dgv("姓名", e.RowIndex).Value.ToString
  71. Set_考勤明細() : 請假日期_tb.Text = 年份_cb.Text & "/" & 月份_cb.Text : Set_假期統計()
  72. End If
  73. End Sub
  74. Private Sub 月清單_DGV_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles 月清單_DGV.CellClick
  75. If e.RowIndex = -1 Then : Else
  76. If 月清單_DGV.Rows(e.RowIndex).Cells("星期").Value.ToString = "星期六" Or 月清單_DGV.Rows(e.RowIndex).Cells("星期").Value.ToString = "星期日" Or
  77. 月清單_DGV.Rows(e.RowIndex).Cells("請假類別").Value.ToString = "國定假日" Then
  78. MsgBox("星期六/星期日或國定假日不可以申請特休!!")
  79. 請假日期_tb.Text = ""
  80. 事由_tb.Text = ""
  81. Else
  82. 員工編號_tb.Text = 月清單_DGV("編號", e.RowIndex).Value.ToString : 申請人_tb.Text = 月清單_DGV("姓名", e.RowIndex).Value.ToString
  83. 請假日期_tb.Text = 月清單_DGV("日期", e.RowIndex).Value.ToString : 事由_tb.Text = 月清單_DGV("事由", e.RowIndex).Value.ToString
  84. 請假類別_cb.Text = 月清單_DGV("請假類別", e.RowIndex).Value.ToString
  85. 資料指定圖庫_tb.Text = 月清單_DGV("圖片資料庫", e.RowIndex).Value.ToString : 圖片流水號_tb.Text = 月清單_DGV("圖片編號", e.RowIndex).Value.ToString
  86. '------------驗貨報告讀取--------------------------------------------------------------------------------------------
  87. If 資料指定圖庫_tb.Text <> "" And 圖片流水號_tb.Text <> "" Then
  88. 圖片庫 = 資料指定圖庫_tb.Text : SQL_連線字串_圖片資料庫() : PA2 = 圖片流水號_tb.Text
  89. SQL_請假圖() : PictureBox2.Image = Nothing
  90. While dr.Read() = True
  91. Dim unused As Byte() = New Byte(-1) {} : Dim bytes As Byte() = DirectCast(dr.Item("圖片"), Byte())
  92. Dim oStream As New MemoryStream(bytes) : PictureBox2.Image = Bitmap.FromStream(oStream)
  93. End While : conn.Close() : PictureBox2.SizeMode = 4
  94. Else
  95. PictureBox2.Image = Nothing
  96. End If
  97. End If
  98. End If
  99. End Sub
  100. Private Sub 月清單_DGV_RowPostPaint(ByVal sender As Object, ByVal e As DataGridViewRowPostPaintEventArgs) Handles 月清單_DGV.RowPostPaint
  101. Dim linePen As New Pen(Color.Blue, 2)
  102. If e.RowIndex = 月清單_DGV.Rows.Count - 1 Then : Exit Sub : Else
  103. If Strings.Left(月清單_DGV("日期", e.RowIndex).Value.ToString, 7) <> Strings.Left(月清單_DGV("日期", e.RowIndex + 1).Value.ToString, 7) Then
  104. Dim startX As Integer = IIf(月清單_DGV.RowHeadersVisible, 月清單_DGV.RowHeadersWidth, 0) : Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
  105. Dim endX As Integer = startX + 月清單_DGV.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - 月清單_DGV.HorizontalScrollingOffset
  106. e.Graphics.DrawLine(linePen, startX, startY, endX, startY) : Exit Sub
  107. End If
  108. End If
  109. End Sub
  110. Private Sub 月份_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 月份_cb.SelectedIndexChanged
  111. If 剛開啟 = False Then : Set_考勤明細() : End If
  112. End Sub
  113. Private Sub 年份_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 年份_cb.SelectedIndexChanged
  114. If 剛開啟 = False Then : Set_考勤明細() : End If
  115. End Sub
  116. Private Sub 刪除_tb_Click(sender As Object, e As EventArgs) Handles 刪除_tb.Click
  117. If 請假日期_tb.Text = "" And 員工編號_tb.Text = "" Then : MsgBox("沒有選擇資料!!!") : Else : SQL_休假申請明細_刪除() : Set_考勤明細() : MsgBox("刪除完成!!!") : End If
  118. End Sub
  119. Private Sub PictureBox2_Click(sender As Object, e As EventArgs) Handles PictureBox2.Click
  120. 圖片傳遞 = PictureBox2.Image : 圖片放大視窗.ShowDialog()
  121. End Sub
  122. Private Sub 列印_bt_Click(sender As Object, e As EventArgs) Handles 列印_bt.Click
  123. xlApp = CType(CreateObject("Excel.Application"), Application)
  124. xlBook = xlApp.Workbooks.Add
  125. xlApp.DisplayAlerts = True
  126. xlApp.Visible = True
  127. xlApp.Application.WindowState = xlMaximized
  128. xlSheet = NewMethod(xlBook) : xlApp.Sheets(1).Select
  129. xlApp.Sheets(1).Name = "請休假申請資料" : xlBook.Activate() : xlSheet.Activate()
  130. xlSheet.Cells(1, 1) = "黃柏翰皮膚科診所請休假資料" : xlSheet.Cells(2, 1) = CInt(年份_cb.Text) - 1911 & "年" & 月份_cb.Text & "月 - 全月"
  131. xlSheet.Cells(3, 1) = "項" : xlSheet.Cells(3, 2) = "姓名" : xlSheet.Cells(3, 3) = "日期" : xlSheet.Cells(3, 4) = "星期"
  132. xlSheet.Cells(3, 5) = "假別" : xlSheet.Cells(3, 6) = "事由" : xlSheet.Cells(3, 7) = "時數"
  133. For i As Integer = 0 To 月清單_DGV.Rows.Count - 1
  134. xlSheet.Cells(4 + i, 1) = i + 1 : xlSheet.Cells(4 + i, 2) = 月清單_DGV("姓名", i).Value.ToString
  135. xlSheet.Cells(4 + i, 3) = 月清單_DGV("日期", i).Value.ToString : xlSheet.Cells(4 + i, 4) = 月清單_DGV("星期", i).Value.ToString
  136. xlSheet.Cells(4 + i, 5) = 月清單_DGV("請假類別", i).Value.ToString : xlSheet.Cells(4 + i, 6) = 月清單_DGV("事由", i).Value.ToString
  137. xlSheet.Cells(4 + i, 7) = 月清單_DGV("申請時數", i).Value.ToString
  138. Next : 位置1 = 4 + 月清單_DGV.Rows.Count - 1 : AA(xlApp, xlSheet)
  139. xlSheet.PageSetup.PrintArea = "" : xlApp.Cells.Select() : xlSheet.Range("B1").Select() : xlApp.Application.WindowState = xlMinimized : MsgBox("列印完成")
  140. End Sub
  141. Private Shared Function NewMethod(xlBook As Workbook) As Worksheet
  142. Return CType(xlBook.Worksheets.Add, Worksheet)
  143. End Function
  144. Private Sub AA(ByVal myExcel As Microsoft.Office.Interop.Excel.Application, ByVal xlSheet As Microsoft.Office.Interop.Excel.Worksheet)
  145. xlSheet.Cells.Select()
  146. With myExcel.Selection.Font : .Name = "微軟正黑體" : .Size = 12 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False
  147. .Shadow = False : .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone : End With
  148. xlSheet.Columns("A:A").Select : myExcel.Selection.ColumnWidth = 4
  149. xlSheet.Columns("A:G").Select
  150. With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  151. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With
  152. xlSheet.Range("F4:F" & 位置1).Select()
  153. With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  154. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With
  155. xlSheet.Columns("B:G").Select : myExcel.Columns("B:F").EntireColumn.AutoFit
  156. xlSheet.Rows("4:4").Select : myExcel.ActiveWindow.FreezePanes = True
  157. xlSheet.Range("B3:G3").Select() : myExcel.Selection.AutoFilter
  158. xlSheet.Rows("3:3").Select : myExcel.Selection.RowHeight = 35
  159. With myExcel.Selection : .VerticalAlignment = xlTop : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 : .ShrinkToFit = False
  160. .ReadingOrder = xlContext : .MergeCells = False : End With
  161. xlSheet.Range("A3:G" & 位置1).Select()
  162. myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  163. With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  164. With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  165. With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  166. With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  167. With myExcel.Selection.Borders(xlInsideVertical) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  168. With myExcel.Selection.Borders(xlInsideHorizontal) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  169. myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  170. With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With
  171. With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With
  172. With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With
  173. With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With
  174. With myExcel.Selection.Borders(xlInsideVertical) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  175. xlSheet.Range("A2:G2").Select()
  176. With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  177. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
  178. With myExcel.Selection.Font : .Name = "微軟正黑體" : .Size = 12 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False
  179. .Shadow = False : .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone : End With
  180. myExcel.Selection.Font.Bold = True
  181. xlSheet.Range("A1:G1").Select()
  182. With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  183. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
  184. With myExcel.Selection.Font : .Name = "微軟正黑體" : .Size = 16 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False
  185. .Shadow = False : .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone : End With
  186. myExcel.Selection.Font.Bold = True
  187. xlSheet.Range("A3:G3").Select()
  188. With myExcel.Selection.Interior : .Pattern = xlSolid : .PatternColorIndex = xlAutomatic : .ThemeColor = xlThemeColorAccent1 : .TintAndShade = 0.799981688894314
  189. .PatternTintAndShade = 0 : End With
  190. xlSheet.Range("F4").Select()
  191. myExcel.ActiveWindow.DisplayGridlines = False
  192. End Sub
  193. End Class