【发布时间】:2016-05-27 00:16:46
【问题描述】:
我正在制作一个程序,帮助我为我目前实习的一家公司安排员工和工作。大多数事情进展顺利,但我陷入了这个特殊问题:
我有一个颜色代码,可以快速显示按时完成工作的可能性。 绿色很有可能,黄色有可能,红色 >不太可能。我希望根据在相关工作之前完成每项工作的估计时间来确定每项工作的颜色代码。我想为每项工作都这样做。
This is a picture of the list of active jobs。目前,该程序使用所有作业的总和,即在相关作业之前和之后到期的作业。我想做的唯一改变是只为相关工作之前的工作执行此操作。
这是我目前用来对“状态”列进行颜色编码的代码
编辑
现在发布更正的代码,非常感谢 vbnet3d
Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
Dim ts As TimeSpan
Dim now As Date = DateTime.Now.ToString("MM/dd/yyyy")
Dim cdout As Date
Me.JobDetailsBindingSource.Filter = String.Format("Crate_Date >= '" & now & "'")
For i As Integer = 0 To Me.Active_Jobs_List.Rows.Count - 1
Dim dayout As Date
Dim dayout1 As Date
Dim daysum As Integer = 0
For x As Integer = 0 To i
If (Date.TryParseExact(Me.Active_Jobs_List.Rows(x).Cells(6).Value, pattern, Nothing, DateTimeStyles.None, dayout)) >= (Date.TryParseExact(Me.Active_Jobs_List.Rows(i).Cells(6).Value, pattern, Nothing, DateTimeStyles.None, dayout1)) Then
daysum = daysum + Active_Jobs_List.Rows(x).Cells(45).Value
End If
Next
If Date.TryParseExact(Active_Jobs_List.Rows(i).Cells(6).Value, pattern, Nothing, DateTimeStyles.None, cdout) = True Then
ts = cdout.Subtract(now)
TextBox1.Text = Format(ts.TotalMinutes, 0) - daysum
End If
Me.Active_Jobs_List.Rows(i).Cells("Cdate_Minus_Now").Value = TextBox1.Text
If (Me.Active_Jobs_List.Rows(i).Cells("Cdate_Minus_Now").Value) <= 2880 Then
Me.Active_Jobs_List.Rows(i).Cells("Current_Status").Style.BackColor = Color.Red
ElseIf (Me.Active_Jobs_List.Rows(i).Cells("Cdate_Minus_Now").Value) <= 5760 And Me.Active_Jobs_List.Rows(i).Cells("Cdate_Minus_Now").Value > 2880 Then
Me.Active_Jobs_List.Rows(i).Cells("Current_Status").Style.BackColor = Color.Yellow
ElseIf (Me.Active_Jobs_List.Rows(i).Cells("Cdate_Minus_Now").Value) > 5760 Then
Me.Active_Jobs_List.Rows(i).Cells("Current_Status").Style.BackColor = Color.Green
End If
Next
End Sub
我是 vb.net 的初学者,所以如果您发现代码有任何其他问题,请随时提及。谢谢大家。
【问题讨论】:
-
只是一个想法……假设您实际上没有任何上限,您也许可以将
ElseIf (Me.Active_Jobs_List.Rows(i).Cells("Cdate_Minus_Now").Value) <= 999999 And Me.Active_Jobs_List.Rows(i).Cells("Cdate_Minus_Now").Value > 5760 Then缩短为ElseIf Me.Active_Jobs_List.Rows(i).Cells("Cdate_Minus_Now").Value > 5760 Then。 -
为了澄清这个问题,您想根据当前工作之前的所有工作的总和来计算工作完成的概率,对吗?
-
啊,没错,我会改的。
-
但是,是的,这就是我的目标。理想情况下,它实际上是在同一天和当前作业之前的所有作业。当前的只是程序恰好在的任何行“i”
-
你应该做一个循环,从与当前行同一天的第一条记录开始,到当前行,并将所有值相加到该点。
标签: vb.net datagridview