⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bas_createdayplan.bas

📁 生产计划管理等信息 可以查询计划完成情况等
💻 BAS
字号:
Attribute VB_Name = "Bas_CreateDayPlan"
'模拟生成计划安排模块
'【 结束时间 = 开始时间 + 总共需要时间 + 休息时间 】
'【 开始时间 = 上道开始时间 + 休息时间 + 接受延时 】

'单个计划单的预安排  ==================================================================================================================================================================================================

Public Sub SimulationDayPlan(Flex As MSFlexGrid, TimeType As String, TaskPlan_9 As String, FirstDayTime As Date, AllMeterNumber As Variant)  '模拟生成
'模拟生成计划安排表
Dim SBumen, SBanzu, SMeterType

SQL = "Select * from 计划信息 where 计划单号='" & Mid(TaskPlan_9, 1, 7) & "' and 批次号='" & Mid(TaskPlan_9, 8, 2) & "' "
If rs.State = 1 Then rs.Close
rs.Open SQL, DBConn, adOpenKeyset, adLockOptimistic, adCmdText
If Not rs.EOF Then
  SBumen = CStr(rs.Fields("部门名称").Value)
  SMeterType = CStr(rs.Fields("表计类型").Value)
End If

Dim BeginTime, EndTime As Date
Dim SD_EndTime As Date

BeginTime = FirstDayTime
EndTime = BeginTime
SD_EndTime = BeginTime

Dim i
Dim usetime As Variant
For i = 1 To Flex.Rows - 1
   SBanzu = Flex.TextMatrix(i, 0)
   
   '开始时间 的设计原理:接受延时=0顺序下去,接受延时<>0使用公式
   Select Case GetDelayTime(TaskPlan_9, CStr(SBanzu))
     Case "0"
        BeginTime = EndTime
     Case Else
        BeginTime = BeginTime + ConvertTime(GetDelayTime(TaskPlan_9, CStr(SBanzu)))
   End Select
   
   usetime = CalculationTime(CStr(SBumen), CStr(SBanzu), CStr(SMeterType), AllMeterNumber)
   EndTime = BeginTime + ConvertTime(CStr(usetime)) + ConvertTime(Str(AssertTime(CStr(BeginTime), usetime, TimeType)))
   If EndTime <= SD_EndTime Then EndTime = SD_EndTime + ConvertTime(GetDelayTime(TaskPlan_9, CStr(SBanzu)))

   Flex.TextMatrix(i, 1) = Mid(Format(BeginTime, "yyyy-mm-dd hh:mm"), 1, 10)
   Flex.TextMatrix(i, 2) = Mid(Format(BeginTime, "yyyy-mm-dd hh:mm"), 12, 5)
   Flex.TextMatrix(i, 3) = Mid(Format(EndTime, "yyyy-mm-dd hh:mm"), 1, 10)
   Flex.TextMatrix(i, 4) = Mid(Format(EndTime, "yyyy-mm-dd hh:mm"), 12, 5)
   
   SD_EndTime = EndTime

Next i

End Sub

'==========================================================================================================================================================================================================================================================

Public Sub IniFlex(Flex As MSFlexGrid, TaskPlan_9 As String)
'在MSFlexGrid中导入计划单的工序配置
   Flex.Row = 1
   SQL = "Select * from 工序配置,计划信息 where 计划单号='" & Mid(TaskPlan_9, 1, 7) & "' and 批次号='" & Mid(TaskPlan_9, 8, 2) & "' and 计划信息.部门名称=工序配置.部门名称 and 计划信息.表计类型=工序配置.表计类型 order by 顺序编号"
   'Debug.Print SQL
   If rs.State = 1 Then rs.Close
   rs.Open SQL, DBConn, adOpenKeyset, adLockOptimistic, adCmdText
   If Not rs.EOF Then
      Dim i
      Flex.Rows = rs.RecordCount + 1
      For i = 1 To rs.RecordCount
        Flex.TextMatrix(i, 0) = rs.Fields("工序名称").Value
        rs.MoveNext
      Next i
   End If
End Sub

Private Function CalculationTime(Bumen As String, BanZu As String, MeterType As String, AllNumber As Variant) As Variant
'计算出总共需要多少时间
'AllNumber:总需要完成的数量
'MeterType:表计类型
  Dim Alltime As Variant
  Alltime = 0
  SQL = "Select * from 生产周期 where 部门名称='" & Bumen & "' and 班组名称='" & BanZu & "' and 表计类型='" & MeterType & "'"
  If rstmp.State = 1 Then rstmp.Close
  rstmp.Open SQL, DBConn, adOpenKeyset, adLockOptimistic, adCmdText
  If Not rstmp.EOF Then
     If rstmp.Fields("加时累计").Value = True Then
       Alltime = AllNumber * Val(rstmp.Fields("生产周期").Value) / Val(rstmp.Fields("生产单位").Value) '计算总共需要多少时间
     Else
       If AllNumber <> 0 Then Alltime = Val(rstmp.Fields("生产周期").Value)
     End If
  Else
     Alltime = 0
  End If

  CalculationTime = Alltime
  Debug.Print "Bumen:" & Bumen & "  Banzu:" & BanZu & "  MeterType:" & MeterType & "  CalculationTime:" & CalculationTime

End Function

Public Function AssertTime(BeginTime As String, usetime As Variant, TimeType As String) As Variant
'判断时间间隔中是否存在 休息时间,不存在=0
'TimeType:时制方案
  AssertTime = 0
  SQL = "Select * from 休息时间 where 方案='" & TimeType & "'"
  If rstmp.State = 1 Then rstmp.Close
  rstmp.Open SQL, DBConn, adOpenKeyset, adLockOptimistic, adCmdText
  Do While Not rstmp.EOF '反复加上休息的时间
     If CDate(rstmp.Fields("时间起始").Value) - CDate(Format(BeginTime, "hh:mm")) >= 0 And CDate(Format(BeginTime, "hh:mm")) + ConvertTime(CStr(usetime)) - CDate(rstmp.Fields("时间起始").Value) >= 0 Then
        AssertTime = AssertTime + Val(rstmp.Fields("间隔时间").Value)
     End If
     rstmp.MoveNext
  Loop
End Function

Private Function ConvertTime(STime As String) As Date
'时间换算 1.5h = 1:30:00
   STime = Format(STime, "##0.0#")
   Dim S As Integer
   S = InStr(1, CStr(STime), ".")
'   Debug.Print Mid(CStr(STime), 1, s - 1) & "." & 60 * Val("0." & Mid(CStr(STime), s + 1, Len(CStr(STime)) - s))
   ConvertTime = CDate(Mid(CStr(STime), 1, S - 1) & "." & 60 * Val("0." & Mid(CStr(STime), S + 1, Len(CStr(STime)) - S)))
End Function

Private Function GetDelayTime(TaskPlan_9 As String, BanZu As String) As String
'获取接收延时
  GetDelayTime = 0
  GetDelayTime = Format(GetDelayTime, "#0.0#")
  SQL = "Select * from 生产周期,计划信息 where 计划单号='" & Mid(TaskPlan_9, 1, 7) & "' and 批次号='" & Mid(TaskPlan_9, 8, 2) & "' and  计划信息.部门名称=生产周期.部门名称 and 计划信息.表计类型=生产周期.表计类型 and  生产周期.班组名称='" & BanZu & "'"
  If rstmp.State = 1 Then rstmp.Close
  rstmp.Open SQL, DBConn, adOpenKeyset, adLockOptimistic, adCmdText
  If Not rstmp.EOF Then GetDelayTime = rstmp.Fields("接收延时").Value
End Function











⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -