DateAdd 不在迭代中更新

DateAdd is not updated in iteration

大家好,我遇到了一个问题我正在为一个项目的制造计划员工作,我有一个 TextBox1 作为开始日期,一个 TextBox4 作为卷轴数 = Ci,用户必须指定将有多少 Ci(卷轴),然后从那里开始规划制造程序。

所有这些信息都被清空到 DataGridView 中,其中我有列,其中 "Department" 是 "Section" "Operation" "End date" "Initial date"

问题是当我的代码以第 2 卷轴开始时,它为我分配了为第 1 卷轴计算的相同日期,类似这样。

Manufacturing   Channel Cut plate C1            04/07/2019  04/07/2019
Manufacturing   Channel Rolled plate C1         04/07/2019  04/07/2019
Manufacturing   Channel Longituidal welding C1  08/07/2019  09/07/2019
Manufacturing   Channel Re rolled C1            10/07/2019  11/07/2019
Manufacturing   Channel Cut plate C2            04/07/2019  04/07/2019
Manufacturing   Channel Rolled plate C2         04/07/2019  04/07/2019
Manufacturing   Channel Longituidal welding C2  08/07/2019  09/07/2019
Manufacturing   Chanel  rolled C2               10/07/2019  11/07/2019

我需要 C2 的卷轴从卷轴 1 的最后一个 activity 日期开始并保留,类似这样。

Manufacturing   Channel Cut plate C1            04/07/2019  04/07/2019
Manufacturing   Channel Rolled plate C1         05/07/2019  05/07/2019
Manufacturing   Channel Longituidal welding C1  06/07/2019  07/07/2019
Manufacturing   Channel Re rolled C1            10/07/2019  11/07/2019
Manufacturing   Channel Cut plate C2            11/07/2019  12/07/2019
Manufacturing   Channel Rolled plate C2         13/07/2019  14/07/2019
Manufacturing   Channel Longituidal welding C2  15/07/2019  16/07/2019
Manufacturing   Chanel  rolled C2               17/07/2019  18/07/2019

我正在使用的代码是下一个。

Private Sub Button1_Click (sender As Object, and As EventArgs) Handles Button1.Click
       Dim date1 As Date = CType (TextBox1.Text, Date)
        Dim numRows As Integer
        If Integer.TryParse (TextBox4.Text, numRows) Then
        If (numRows> = 1) Then
        For i As Integer = 1 To numRows
        Table.Rows.Add ("Manufacturing", "Channel", "Cut plate C" & i, DateAdd (DateInterval.Day, 1, date1), DateAdd (DateInterval.Day, 2, date1))
        Table.Rows.Add ("Manufacturing", "Channel", "Rolled plate C" & i, DateAdd (DateInterval.Day, 3, date1), DateAdd (DateInterval.Day, 4, date1))
        Table.Rows.Add ("Manufacturing", "Channel", "Longituid welding C" & i, DateAdd (DateInterval.Day, 5, date1), DateAdd (DateInterval.Day, 6, date1))
        Table.Rows.Add ("Manufacturing", "Channel", "Re rolled C" & i, DateAdd (DateInterval.Day, 7, date1), DateAdd (DateInterval.Day, 8, date1))
        Next
        Else
        MessageBox.Show ("Value:" & TextBox4.Text, "The number of rows must be greater than or equal to 1")
        End If
        Else
        MessageBox.Show ("Value:" & TextBox4.Text, "Invalid number")
        End If
End Sub

编辑后好多了post。

你说:

I need the Reel of the C2 to start from the date of the last activity of Reel 1 ...

您可以在循环底部更改 "date1" 的值,以便下一个卷轴从该日期开始:

For i As Integer = 1 To numRows
    Table.Rows.Add("Manufacturing", "Channel", "Cut plate C" & i, DateAdd(DateInterval.Day, 1, date1), DateAdd(DateInterval.Day, 2, date1))
    Table.Rows.Add("Manufacturing", "Channel", "Rolled plate C" & i, DateAdd(DateInterval.Day, 3, date1), DateAdd(DateInterval.Day, 4, date1))
    Table.Rows.Add("Manufacturing", "Channel", "Longituid welding C" & i, DateAdd(DateInterval.Day, 5, date1), DateAdd(DateInterval.Day, 6, date1))
    Table.Rows.Add("Manufacturing", "Channel", "Re rolled C" & i, DateAdd(DateInterval.Day, 7, date1), DateAdd(DateInterval.Day, 8, date1))
    date1 = DateAdd(DateInterval.Day, 8, date1)
Next