รายละเอียดของการตอบ ::
ขอบคุณครับคุณต่อครับ โค๊ดหลัก กำลังเขียนได้แค่นี้ครับ ทั้งฟร์อมมีแค่นี้ครับ ไม่ได้ไม่เป็นรัยนะครับ ใช้ดักอย่างอื่นแทนยังได้อยู่ครับ
Imports System.Data.SqlClient
Public Class afrm_HR_export
Public Sub loaddata()
If cbbEmployee.Text <> String.Empty And dtpStart.Value.ToString("dd/MM/yyyy") <> String.Empty And dtpEnd.Value.ToString("dd/MM/yyyy") <> String.Empty Then
sql = "Select users_refid, name, lastname, datework, timein, statustime, timeout, statusout, timework, ot, timelad, statusleave from HR_daywork where name='" & cbbEmployee.SelectedItem & "' AND datework BETWEEN '" & dtpStart.Value.ToString("yyyy/MM/dd") & "' AND '" & dtpEnd.Value.ToString("yyyy/MM/dd") & "'"
DA = New SqlDataAdapter(sql, cn)
DS = New DataSet
DA.Fill(DS, "table")
dgvTimework.DataSource = DS.Tables("table")
End If
setupdatagrid()
End Sub
Public Sub sumcolumn()
End Sub
Public Sub setupdatagrid()
With dgvTimework
.Enabled = True
.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing
.ColumnHeadersHeight = 32
.Columns(0).HeaderText = "ไอดี"
.Columns(0).Width = 90
.Columns(1).HeaderText = "ชื่อ"
.Columns(1).Width = 95
.Columns(2).HeaderText = "นามสกุล"
.Columns(2).Width = 95
.Columns(3).HeaderText = "วันที่"
.Columns(3).Width = 90
.Columns(4).HeaderText = "เวลาเข้า"
.Columns(4).Width = 90
.Columns(5).HeaderText = "สถานะเข้า"
.Columns(5).Width = 80
.Columns(6).HeaderText = "เวลาออก"
.Columns(6).Width = 89
.Columns(7).HeaderText = "สถานะออก"
.Columns(7).Width = 90
.Columns(8).HeaderText = "เวลารวม"
.Columns(8).Width = 90
.Columns(9).HeaderText = "OT"
.Columns(9).Width = 80
.Columns(10).HeaderText = "ส่วนต่างสาย"
.Columns(10).Width = 80
.Columns(11).HeaderText = "สถานะงาน"
.Columns(11).Width = 80
.Columns(0).Visible = False
.Columns(3).DefaultCellStyle.Format = "dd/MM/yyyy"
End With
For Each col As DataGridViewColumn In dgvTimework.Columns
col.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
col.HeaderCell.Style.Font = New Font("Arial", 12.0F, FontStyle.Bold, GraphicsUnit.Pixel)
col.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
Next
With dgvTimework
.DefaultCellStyle.BackColor = Color.AliceBlue
.AlternatingRowsDefaultCellStyle.BackColor = Color.LightBlue
End With
'lblCounts.Text = "รวมลงเวลาวันนี้: " & dgvEmployee.RowCount.ToString
End Sub
Private Sub afrm_HR_export_Load(sender As Object, e As EventArgs) Handles MyBase.Load
sql = "select user_name from HR_timework"
cmd_database_to_object(cbbEmployee)
End Sub
Private Sub cbbEmployee_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cbbEmployee.SelectedIndexChanged
sql = "select users_refid from HR_timework where user_name like'" & cbbEmployee.SelectedItem & "'"
txtEmID.Text = cmd_excuteScalar().ToString
sql = "select user_name from HR_timework where user_name like'" & cbbEmployee.SelectedItem & "'"
txtName.Text = cmd_excuteScalar().ToString
sql = "select user_lastname from HR_timework where user_name like'" & cbbEmployee.SelectedItem & "'"
txtlastname.Text = cmd_excuteScalar().ToString
loaddata()
End Sub
Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
Me.Close()
End Sub
Private Sub dgvTimework_CellFormatting(sender As Object, e As DataGridViewCellFormattingEventArgs) Handles dgvTimework.CellFormatting
Dim i As Integer
Dim str1, str2, str3, str4, str5, str6, str7 As String
For i = 0 To dgvTimework.Rows.Count - 1
str1 = dgvTimework.Rows(i).Cells(5).Value
str2 = dgvTimework.Rows(i).Cells(7).Value.ToString
str3 = dgvTimework.Rows(i).Cells(5).Value.ToString
str4 = dgvTimework.Rows(i).Cells(5).Value.ToString
str5 = dgvTimework.Rows(i).Cells(5).Value.ToString
str6 = dgvTimework.Rows(i).Cells(5).Value.ToString
str7 = dgvTimework.Rows(i).Cells(5).Value.ToString
If str1 = "เข้าสาย" Then
'f Convert.ToDouble(str1) <= 50 Then
'Me.dgvEmployee.Rows(i).DefaultCellStyle.BackColor = Color.Yellow
'Me.dgvEmployee.Rows(i).DefaultCellStyle.ForeColor = Color.Red
dgvTimework(5, i).Style.ForeColor = Color.Red
dgvTimework(5, i).Style.BackColor = Color.Yellow
dgvTimework(4, i).Style.ForeColor = Color.Red
End If
If str2 = "ออกก่อนเวลา" Then
dgvTimework(7, i).Style.BackColor = Color.Yellow
dgvTimework(7, i).Style.ForeColor = Color.Red
dgvTimework(6, i).Style.ForeColor = Color.Red
End If
If str3 = "ลากิจ" Then
'f Convert.ToDouble(str1) <= 50 Then
Me.dgvTimework.Rows(i).DefaultCellStyle.BackColor = Color.Wheat
Me.dgvTimework.Rows(i).DefaultCellStyle.ForeColor = Color.Red
End If
If str4 = "ลาป่วย" Then
'f Convert.ToDouble(str1) <= 50 Then
Me.dgvTimework.Rows(i).DefaultCellStyle.BackColor = Color.Plum
Me.dgvTimework.Rows(i).DefaultCellStyle.ForeColor = Color.Red
End If
If str5 = "ลาพักร้อน" Then
'f Convert.ToDouble(str1) <= 50 Then
Me.dgvTimework.Rows(i).DefaultCellStyle.BackColor = Color.MediumSeaGreen
Me.dgvTimework.Rows(i).DefaultCellStyle.ForeColor = Color.Red
End If
If str6 = "ลาบวช" Then
'f Convert.ToDouble(str1) <= 50 Then
Me.dgvTimework.Rows(i).DefaultCellStyle.BackColor = Color.ForestGreen
Me.dgvTimework.Rows(i).DefaultCellStyle.ForeColor = Color.White
End If
If str7 = "ลาคลอด" Then
'f Convert.ToDouble(str1) <= 50 Then
Me.dgvTimework.Rows(i).DefaultCellStyle.BackColor = Color.DarkViolet
Me.dgvTimework.Rows(i).DefaultCellStyle.ForeColor = Color.White
End If
Next
End Sub
End Class
อันนี้หน้าฟร์อมครับ