暫無描述
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

加班申請資料.vb 14KB

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