以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  [求助]平均分配时间  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=93932)

--  作者:xvkewen
--  发布时间:2016/12/10 23:47:00
--  [求助]平均分配时间

原本以为自己可以搞定的,愣是折腾了两天也没有搞的所以然出来,只能请各位大神不吝赐教了,小弟不胜感激~

 

上传了了个小例子,大神以办单号为“BR1611-00001”,办房部位为“侧翼”帮帮忙给做个例子,谢谢;

 

总体思路:以“办单号”与“办房部位”两个字段作为筛选条件,如果此两个字段完全相同,做如下功能及录入控制;

1、如果只找到一条数据,则什么都不用处理;

2、如果只找到两条或以上数据,那么在录入“要求完成时间”时必须要先录入第一道工序的要求完成时间;(工艺序号为1的做为第一道工序)

3、再录入后续工序的要求完成时间时,以工艺序号的大小作为工艺顺序,后面录入的工艺要求完成时间不可以早于前面的要求完成时间;

4、当至少录入两道工序的完成时间,且这两道工序不是相邻的,那么系统将根据前、后工序判断时间间隔,以等分时间的方法自动补充这两道工序之间的其他工序的要求完成时间;

5、每天的22:00后到第二天的8:00前这段时间不计入到“等分时间”里面;并且在录入要求完成时间时也不可以被录入到系统中去;


图片点击可在新窗口打开查看此主题相关图片如下:qq截图20161210233003.jpg
图片点击可在新窗口打开查看

 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:平均分配时间.table


[此贴子已经被作者于2016/12/10 23:47:52编辑过]

--  作者:有点色
--  发布时间:2016/12/11 10:42:00
--  

dataColChanged事件

 

If e.DataCol.Name = "要求完成时间" AndAlso e.DataRow.Isnull("要求完成时间") = False Then
    If e.DataRow.IsNull("办单号") OrElse e.DataRow.IsNull("办房部位") Then
        msgbox("请先输入数据")
    Else
        If e.DataRow("工艺序号") <> 1 Then
            Dim fdrFirst As DataRow = e.DataTable.Find("办单号 = \'" & e.DataRow("办单号") & "\' and 办房部位 = \'" & e.DataRow("办房部位") & "\'", "工艺序号")
            If fdrFirst IsNot Nothing Then
                If fdrFirst.isnull("要求完成时间") Then
                    e.DataRow("要求完成时间") = Nothing
                    msgbox("请先输入第一道工序时间")
                Else
                    Dim fdr As DataRow = e.DataTable.Find("办单号 = \'" & e.DataRow("办单号") & "\' and 办房部位 = \'" & e.DataRow("办房部位") & "\' and 要求完成时间 is not null and 工艺序号 < " & e.DataRow("工艺序号"), "工艺序号 desc")
                    If fdr IsNot Nothing Then
                        Dim num1 As Integer = fdr("工艺序号")
                        Dim num2 As Integer = e.DataRow("工艺序号")
                        If num2-num1 > 1 Then
                            Dim stime As Date = fdr("要求完成时间")
                            Dim etime As Date = e.DataRow("要求完成时间")
                            Dim seconds As Double = 0
                            If Format(etime, "yyyyMMdd") = Format(stime, "yyyyMMdd") Then
                                seconds = (etime-stime).TotalSeconds
                            Else
                                seconds = (new Date(stime.Year, stime.Month, stime.Day, 22, 0, 0) - stime).TotalSeconds
                                seconds += 14 * 3600 * (etime.Day - stime.Day - 1)
                                seconds += (etime-new Date(etime.Year, etime.Month, etime.Day, 8, 0, 0)).TotalSeconds
                            End If
                           
                            Dim second As Double = seconds / (num2-num1)
                            Dim temp As Date = stime
                            systemready = False
                            For i As Integer = num1+1 To num2-1
                                fdr = e.DataTable.Find("办单号 = \'" & e.DataRow("办单号") & "\' and 办房部位 = \'" & e.DataRow("办房部位") & "\' and 工艺序号 = " & i)
                                Dim t As Date = temp.AddSeconds(second)
                                If Format(temp, "yyyyMMdd") <> Format(t, "yyyyMMdd") OrElse t.Hour >= 22 Then
                                    temp = t.AddHours(10 * math.Ceiling((t-temp).Totaldays))
                                Else
                                    temp = t
                                End If
                                fdr("要求完成时间") = temp
                            Next
                            systemready = True
                        End If
                    End If
                End If
            End If
        End If
    End If
End If

 


--  作者:客人
--  发布时间:2016/12/11 23:05:00
--  
感谢你“有点色”老师,你的代码虽然没能完全解决我的问题,那却给我新的思路,我将继续努力攻克这个难关;

另外,以下代码我有点理解不透,尤其是最后那两句,“+=”是什么意思,好像没有这个运算符呀,还希望麻烦您再帮忙给解释一下;非常感谢;

                                seconds = (new Date(stime.Year, stime.Month, stime.Day, 22, 0, 0) - stime).TotalSeconds
                                seconds += 14 * 3600 * (etime.Day - stime.Day - 1)
                                seconds += (etime-new Date(etime.Year, etime.Month, etime.Day, 8, 0, 0)).TotalSeconds

--  作者:xvkewen
--  发布时间:2016/12/11 23:05:00
--  
感谢你“有点色”老师,你的代码虽然没能完全解决我的问题,那却给我新的思路,我将继续努力攻克这个难关;

另外,以下代码我有点理解不透,尤其是最后那两句,“+=”是什么意思,好像没有这个运算符呀,还希望麻烦您再帮忙给解释一下;非常感谢;

                                seconds = (new Date(stime.Year, stime.Month, stime.Day, 22, 0, 0) - stime).TotalSeconds
                                seconds += 14 * 3600 * (etime.Day - stime.Day - 1)
                                seconds += (etime-new Date(etime.Year, etime.Month, etime.Day, 8, 0, 0)).TotalSeconds

--  作者:有点蓝
--  发布时间:2016/12/12 8:34:00
--  
“+=”是累加的意思,等效下面的语法

seconds = seconds + 14 * 3600 * (etime.Day - stime.Day - 1)

--  作者:有点色
--  发布时间:2016/12/12 9:58:00
--  

\'如果不是同一天,就执行下面代码

seconds = (new Date(stime.Year, stime.Month, stime.Day, 22, 0, 0) - stime).TotalSeconds \'得到第一天的时间 22时 减去 开始时间

seconds += 14 * 3600 * (etime.Day - stime.Day - 1)   \'中间的时间等于14(22-8)乘以天数
seconds += (etime-new Date(etime.Year, etime.Month, etime.Day, 8, 0, 0)).TotalSeconds \'得到最后一天的时间
 
\'最后得到间隔的时间,平均给中间的每一行

--  作者:xvkewen
--  发布时间:2016/12/12 12:02:00
--  
"+="符号是什么意思?
--  作者:有点蓝
--  发布时间:2016/12/12 12:05:00
--  
看5楼