D
david12king
Guest
The winform has a datetimepicker 4 regular texboxes and 2 masked texboxes and a bound datagridview.
Im using the cellformatting event of the datagridview to lookup the employees names from another datatable. To accomplish this Im using a sql statement that for the most part is working.
As it is right now it returns the employees names from different columns on the second datatable and sets them in the second column of the datagridview right after employee ID as intended.
The part that is NOT working is looking at the termination date ("FSalida" column) and returning the employees name only if it doesnt have a termination date or the selected date is earlier than the termination date. In other words if the employee has been terminated it shouldnt appear after the termination date.
The code that I have is this:
Private Sub PartePersonalDataGridView_CellFormatting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles DataGridView1.CellFormatting
This looks up the employees full name using the employee number from the ID column (first column)
Try
Dim dgvr As DataGridViewRow = DataGridView1.Rows(e.RowIndex)
If dgvr.Cells(0).Value IsNot Nothing AndAlso dgvr.Cells(0).Value IsNot DBNull.Value Then
Dim empID As Integer = CInt(dgvr.Cells(0).Value)
Dim qry = From dr As PersonalObraDataSet.PersonalObRow In PersonalObraDataSet.PersonalOb
Where (dr.cdTrabajador = empID) And (dr.FSalida = Nothing) Or (dr.FSalida <= txtDate.Text)
This returns each part of the name and joins it in the the 2nd column (name column)
DataGridView1.Rows(e.RowIndex).Cells(1).Value = (qry.First.Nombre1 & " " & qry.First.Nombre2 & " " & qry.First.Apellido1 & " " & qry.First.Apellido2)
DataGridView1.Rows(e.RowIndex).DefaultCellStyle.BackColor = DefaultBackColor
End If
If there is an exemption like the employee doesnt exists this turns the background color red and instead
of the name on the second column it shows "employee doesnt exist."
Catch ex As Exception
DataGridView1.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.Red
DataGridView1.Rows(e.RowIndex).Cells(1).Value = "ESTE EMPLEADO NO EXISTE"
Exit Sub
The part that is not working is after the "And":
Where (dr.cdTrabajador = empID) And (dr.FSalida = Nothing) Or (dr.FSalida <= txtDate.Text)
Your help fixing this would be much appreciated.
Continue reading...
Im using the cellformatting event of the datagridview to lookup the employees names from another datatable. To accomplish this Im using a sql statement that for the most part is working.
As it is right now it returns the employees names from different columns on the second datatable and sets them in the second column of the datagridview right after employee ID as intended.
The part that is NOT working is looking at the termination date ("FSalida" column) and returning the employees name only if it doesnt have a termination date or the selected date is earlier than the termination date. In other words if the employee has been terminated it shouldnt appear after the termination date.
The code that I have is this:
Private Sub PartePersonalDataGridView_CellFormatting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles DataGridView1.CellFormatting
This looks up the employees full name using the employee number from the ID column (first column)
Try
Dim dgvr As DataGridViewRow = DataGridView1.Rows(e.RowIndex)
If dgvr.Cells(0).Value IsNot Nothing AndAlso dgvr.Cells(0).Value IsNot DBNull.Value Then
Dim empID As Integer = CInt(dgvr.Cells(0).Value)
Dim qry = From dr As PersonalObraDataSet.PersonalObRow In PersonalObraDataSet.PersonalOb
Where (dr.cdTrabajador = empID) And (dr.FSalida = Nothing) Or (dr.FSalida <= txtDate.Text)
This returns each part of the name and joins it in the the 2nd column (name column)
DataGridView1.Rows(e.RowIndex).Cells(1).Value = (qry.First.Nombre1 & " " & qry.First.Nombre2 & " " & qry.First.Apellido1 & " " & qry.First.Apellido2)
DataGridView1.Rows(e.RowIndex).DefaultCellStyle.BackColor = DefaultBackColor
End If
If there is an exemption like the employee doesnt exists this turns the background color red and instead
of the name on the second column it shows "employee doesnt exist."
Catch ex As Exception
DataGridView1.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.Red
DataGridView1.Rows(e.RowIndex).Cells(1).Value = "ESTE EMPLEADO NO EXISTE"
Exit Sub
The part that is not working is after the "And":
Where (dr.cdTrabajador = empID) And (dr.FSalida = Nothing) Or (dr.FSalida <= txtDate.Text)
Your help fixing this would be much appreciated.
Continue reading...