Äëÿ çàïóñêà äàííîãî ìàêðîñà íåîáõîäèìî ïåðåéòè â ðåæèì «Ïðîèçâîäñòâî»-«Ïëàí ïðîèçâîäñòâà», è âûáðàòü «Ïëàí èçãîòîâëåíèÿ».

 

Ìàêðîñ «Ðàñ÷åò ïîîïåðàöèîííîãî âðåìåíè íà÷àëà/êîíöà ðàáîò ñ ó÷åòîì ñìåííîñòè». Ïîçâîëÿåò èñïîëüçóÿ äàòû è âðåìÿ çàïóñêà ïîçèöèé ïëàíà èçãîòîâëåíèÿ è òðóäîåìêîñòè ïîðíîðìèðîâàííûå â òåõíîëîãè÷åñêèõ ïðîöåññàõ, ðàññ÷èòàòü è çàíåñòè äàòû è âðåìÿ çàïóñêà íà êàæäóþ îïåðàöèþ ÒÏ.

 

Sub FormMacro_TSTSMOperationTime(TCSActiveModule)     
'
' Âû÷èñëåíèå ïîîïåðàöèîííûõ äàò è âðåìåí íà÷àëà/îêîí÷àíèÿ ðàáîò ñ ó÷åòîì êîýôôèöèåíòà ñìåííîñòè
' ïî óïðîùåííîìó êàëåíäàðþ:
'
' 08-00  16-00  1 ñìåíà
' 16-00  24-00  2 ñìåíà
' 24-00  08-00  3 ñìåíà  
'
' Ñîîòâåòñòâåííî: 1 ñìåííàÿ ðàáîòà  8 ÷àñîâ 08-00 16-00
'                 2 ñìåííàÿ ðàáîòà 16 ÷àñîâ 08-00 24-00
'                 3 ñìåííàÿ ðàáîòà 24 ÷àñà  08-00 16-00
'
    Dim I,J,K      'Ñëóæåáíûå ïåðåìåííûå
    Dim IFirst     ' ID ïðåäûäóùåé ïîçèöèè ïëàíà 
    Dim INext      ' ID ñëåäóþùåé ïîçèöèè ïëàíà 
    Dim IFirstOP   ' ID ïðåäûäóùåé îïåðàöèè 
    Dim INextOP    ' ID ñëåäóþùåé îïåðàöèè                                      
    Dim RowsCount  'Êîëè÷åñòâî âûäåëåííûõ çàïèñåé
    Dim msBM() 'Ìàññèâ ññûëîê íà âûäåëåííûå çàïèñè
    Dim Dz           'Äàòà çàïóñêà ïðåäûäóùàÿ
    Dim Dw          'Äàòà âûïóñêà ïðåäûäóùàÿ
    Dim Tr           'Òðóäîåìêîñòü ïðåäûäóùàÿ
    Dim Dz1         'Äàòà çàïóñêà ñëåäóþùàÿ
    Dim Dw1        'Äàòà âûïóñêà ñëåäóþùàÿ
    Dim Tmo        'Ìåæîïåðàöèîííîå âðåìÿ
    Dim CTmin    'Ñëóæåáíàÿ ïåðåìåííàÿ äëÿ âû÷èñëåíèÿ âðåìåíè â ìèíóòàõ
    Dim Sostav     'Ñîñòàâ èçäåëèÿ ïî ÏÑï
    Dim Tp           'ÒÏ èç êîëëåêöèè
    Dim IStr,JStr 'Ñëóæåáíàÿ ñòðîêîâàÿ ïåðåìåííàÿ
    Dim Sm           'Êîýôôèöèåíò ñìåííîñòè (êîëè÷åñòâî ñìåí â ñóòêè)
    Dim SmD        'Ñëóæåáíàÿ ïåðåìåííàÿ (êîëè÷åñòâî ñìåí ì-äó çàïóñêîì è âûïóñêîì)
'      
    RowsCount = TCSActiveModule.SelectedRowsCount                   ' Çàïîìíèòü êîëè÷åñòâî âûäåëåííûõ çàïèñåé
    If RowsCount > 0 Then                                           ' Åñëè âûäåëåííûå çàïèñè åñòü, òî 
    Sm=1                                                            ' Çàäàòü ïî óìîë÷àíèþ îäíó ñìåíó 
    Sm=TCSApp.InputBox("Ââåäèòå êîýôôèöèåíò ñìåííîñòè","(1,2,3)",Sm)' Ââåñòè êîýôôèöèåíò ñìåííîñòè
    If Sm=1 Or Sm=2 Or Sm=3 Then                                    ' Åñëè êîýôôèöèåíò ñìåííîñòè ââåäåí ïðàâèëüíî, òî
        Redim msBM( RowsCount - 1 )                                 ' Îïðåäåëèòü íåîáõîäèìûé ðàçìàð ìàññèâà äëÿ çàïîìèíàíèÿ ññûëîê
                                                                    '
        For I = 0 To RowsCount - 1                                  ' Ïåðåáðàòü âûäåëåííûå çàïèñè ñïåöèôèêàöèè
            If TCSActiveModule.GotoSelectedRow(I) Then              ' Âñòàòü íà î÷åðåäíóþ âûäåëåííóþ çàïèñü
                msBM( I ) = TCSActiveModule.GetBookmark             ' È çàïîìíèòü åå â ìàññèâå
            End If                                                  '
        Next                                                        '
        TCSActiveModule.Refresh                                     ' Cáðîñèòü âûäåëåíèå  
        Call TCSActiveModule.GotoBookmark( msBM( 0 ) )              ' Ïîçèöèîíèðîâàòüñÿ íà ïåðâóþ çàïèñü âûäåëåíèÿ
'
' Îïðåäåëåíèå âðåìåíè íà÷àëà ðàáîò (äëÿ ïåðâîé çàïèñè)
'            
                If TCSActiveModule.Properties("WorkStart").IsNull Then        ' Åñëè òåêóùàÿ äàòà çàïóñêà íå çàíåñåíà  
                    Set Sostav = TCSApp.Manufacturing.ProductionBOMStructure( TCSActiveModule.Properties("PRODUCTIONBOM_ID").AsInteger, -1, TCSActiveModule.Properties("PRODBOM_STRUCTUREITEM_ID").AsInteger )'Âçÿòü ÏÑï
                   '   LogObject.ShowPropExplorer(Sostav)
                    Set Tp = Sostav.Properties("ProductionBOMProcess").AsIDispatch ' Âçÿòü ÒÏ ïîçèöèè ñîñòàâà ÏÑï
                      If Sostav.Properties("SCHEDULE_LAUNCH_DATE").IsNull Then     ' Åñëè ïëàíîâîé äàòû çàïóñêà íåò â ÏÑï
                        If Sostav.Properties("CALC_LAUNCH_DATE").IsNull Then       ' Ïîïûòàòüñÿ âçÿòü åå èç ðàñ÷åòíîé äàòû 
                           II = Tp.Locate( "ID", TCSActiveModule.Properties("PRODBOM_MNFPROCESSITEM_ID").AsInteger,0 )' Ïåðåéòè ê ñîîòâåòñòâóþùåé îïåðàöèè
                           IStr=" Îïåðàöèÿ: " + Tp.Properties("OPERATION_NUMBER").AsSafeString + " " + Tp.Properties("OPERATION_NOTE").AsSafeString + " " + Tp.Properties("OPERATION_NAME").AsSafeString
                           Dz=TCSApp.InputBox("Ââåäèòå äàòó çàïóñêà äëÿ",IStr,Dz)  ' Ââåñòè äàòó çàïóñêà âðó÷íóþ
                        Else                                                       '
                           Dz=Sostav.Properties("CALC_LAUNCH_DATE").AsDate         ' Âçÿòü èç ðàñ÷åòíîé äàòû      
                        End If                                                     '
                      Else                                                         '
                       Dz=Sostav.Properties("SCHEDULE_LAUNCH_DATE").AsDate         ' Âçÿòü èç ïëàíîâîé äàòû 
                      End If                                                       '
                    Set Sostav = Nothing                                      ' Îñâîáîäèòü îáúåêò
                    Set Tp = Nothing                                          ' Îñâîáîäèòü îáúåêò
                    Call TCSActiveModule.Edit                                 ' Áåðåì çàïèñü íà ðåäàêòèðîâàíèå
                 TCSActiveModule.Properties("WorkStart").AsDate=Dz            ' Çàíåñòè òåêóùóþ äàòó
                 Call TCSActiveModule.SaveChanges                             ' Ñîõðàíèì, è åñëè ïðîèçîøëà
                 Call TCSActiveModule.CancelChanges                           ' îøèáêà, îòìåíèì âñå èçìåíåíèÿ
                Else                                                          '
                Dz=TCSActiveModule.Properties("WorkStart").AsDate             ' Âçÿòü òåêóùóþ äàòó çàïóñêà
                End If    
'                
'  Öèêë ïî çàïèñÿì ïîçèöèé ïëàíà
'                                                                    '
            IFirst=TCSActiveModule.Properties("PRODBOM_STRUCTUREITEM_ID").AsInteger   ' Ïðåäûäóùàÿ ïîçèöèÿ
            IFirstOP=TCSActiveModule.Properties("PRODBOM_MNFPROCESSITEM_ID").AsInteger' Ïðåäûäóùàÿ îïåðàöèÿ
            K=0                                                               ' Ñ÷åò÷èê èçìåíåííûõ ýàïèñåé 
            M=0                                                              ' Ñ÷åò÷èê ýàïèñåé äëÿ ïðîãðåññáàðà
        For I = 0 To RowsCount - 1                                            ' Èäòè ïî ìàññèâó ññûëîê
           Call TCSActiveModule.GotoBookmark( msBM( I ) )                     ' Ïîçèöèîíèðîâàòüñÿ íà òåêóùóþ çàïèñü 
           INext=TCSActiveModule.Properties("PRODBOM_STRUCTUREITEM_ID").AsInteger     ' Ñëåäóþùàÿ ïîçèöèÿ 
           INextOP=TCSActiveModule.Properties("PRODBOM_MNFPROCESSITEM_ID").AsInteger  ' Ñëåäóþùàÿ îïåðàöèÿ 
'
'  Ðàñ÷åò òðóäîåìêîñòè è çàíåñåíèå åå â ïëàí  LaborIntensity = Òïç + Òøò*Êîë-âî(ïî ïëàíó) + Òìî
'                                                                             '
               If TCSActiveModule.Properties("LaborIntensity").AsFloat=0 Then ' Åñëè òðóäîåìêîñòü íå çàíåñåíà
                 Set Sostav = TCSApp.Manufacturing.ProductionBOMStructure( TCSActiveModule.Properties("PRODUCTIONBOM_ID").AsInteger, -1, TCSActiveModule.Properties("PRODBOM_STRUCTUREITEM_ID").AsInteger )'Âçÿòü ÏÑï 
                 Set Tp = Sostav.Properties("ProductionBOMProcess").AsIDispatch ' Âçÿòü ÒÏ ïîçèöèè ñîñòàâà ÏÑï            
                 II = Tp.Locate( "ID", TCSActiveModule.Properties("PRODBOM_MNFPROCESSITEM_ID").AsInteger,0 )' Ïåðåéòè ê ñîîòâåòñòâóþùåé îïåðàöèè
                 Tr=Tp.Properties("SetupTime").AsFloat                        ' Òïç   
                 Tr=Tr+(Tp.Properties("TimePerPiece").AsFloat * TCSActiveModule.Properties("QUANTITY").AsFloat)' Òøò*Êîë-âî(ïî ïëàíó)
                 Tr=Tr+Tp.Properties("InterOperationTime").AsFloat            ' Òìî
                 Call TCSActiveModule.Edit                                    ' Áåðåì çàïèñü íà ðåäàêòèðîâàíèå
                 TCSActiveModule.Properties("LaborIntensity").AsFloat=Tr      ' Âçÿòü òåêóùóþ òðóäîåìêîñòü â ÷àñàõ
                 Call TCSActiveModule.SaveChanges                             'Ñîõðàíèì, è åñëè ïðîèçîøëà
                 Call TCSActiveModule.CancelChanges                           'îøèáêà, îòìåíèì âñå èçìåíåíèÿ
               Else                                                           ' Åñëè çàíåñåíà
                Tr=TCSActiveModule.Properties("LaborIntensity").AsFloat       ' Âçÿòü òåêóùóþ òðóäîåìêîñòü â ÷àñàõ
               End If                                                         '
'                                                                             
'   Îïðåäåëåíèå âðåìåíè íà÷àëà è îêîí÷àíèÿ ðàáîò
'          
           If INext=IFirst Then                                                  ' Åñëè íîìåíêëàòóðà ïðåæíÿÿ
               If INextOP=IFirstOP Then                                          ' Åñëè îïåðàöèÿ ïåðâàÿ
                If TCSActiveModule.Properties("WorkStart").IsNull Then        ' Åñëè òåêóùàÿ äàòà íà÷àëà ðàáîò íå çàíåñåíà  
                        Set Sostav = TCSApp.Manufacturing.ProductionBOMStructure( TCSActiveModule.Properties("PRODUCTIONBOM_ID").AsInteger, -1, TCSActiveModule.Properties("PRODBOM_STRUCTUREITEM_ID").AsInteger )'Âçÿòü ÏÑï
                        Set Tp = Sostav.Properties("ProductionBOMProcess").AsIDispatch ' Âçÿòü ÒÏ ïîçèöèè ñîñòàâà ÏÑï
                          If Sostav.Properties("SCHEDULE_LAUNCH_DATE").IsNull Then     ' Åñëè ïëàíîâîé äàòû çàïóñêà íåò â ÏÑï
                            If Sostav.Properties("CALC_LAUNCH_DATE").IsNull Then       ' Ïîïûòàòüñÿ âçÿòü åå èç ðàñ÷åòíîé äàòû 
                           II = Tp.Locate( "ID", TCSActiveModule.Properties("PRODBOM_MNFPROCESSITEM_ID").AsInteger,0 )' Ïåðåéòè ê ñîîòâåòñòâóþùåé îïåðàöèè
                           IStr=" Îïåðàöèÿ: " + Tp.Properties("OPERATION_NUMBER").AsSafeString + " " + Tp.Properties("OPERATION_NOTE").AsSafeString + " " + Tp.Properties("OPERATION_NAME").AsSafeString
                           Dz1=TCSApp.InputBox("Ââåäèòå äàòó çàïóñêà äëÿ",IStr,Dz)     ' Ââåñòè äàòó çàïóñêà âðó÷íóþ
                            Else                                                       ' 
                           Dz1=Sostav.Properties("CALC_LAUNCH_DATE").AsDate            ' Âçÿòü èç ðàñ÷åòíîé äàòû      
                            End If                                                     '
                          Else                                                         '
                           Dz1=Sostav.Properties("SCHEDULE_LAUNCH_DATE").AsDate        ' Âçÿòü èç ïëàíîâîé äàòû 
                          End If                                                       '
                    Set Sostav = Nothing                                      ' Îñâîáîäèòü îáúåêò
                    Set Tp = Nothing                                          ' Îñâîáîäèòü îáúåêò
                Else                                                          '
                Dz1=TCSActiveModule.Properties("WorkStart").AsDate             ' Âçÿòü òåêóùóþ äàòó çàïóñêà
                End If    
                  CTmin=Tr*60                                 ' Òðóäîåìêîñòü â ìèíóòàõ
                  Dw1=DateAdd ("n",CTmin,Dz1)                 ' Äàòà âûïóñêà
               Else                                           ' Åñëè îïåðàöèÿ ñëåäóþùàÿ     
                  Dz1=Dw                  ' Ñëåäóþùàÿ äàòà(âðåìÿ) çàïóñêà=ïðåä.äàòà(âðåìÿ)âûïóñêà.Ìåæîïåðàöèîííîå âðåìÿ ó÷òåíî â òðóäîåìêîñòè
                  CTmin=Tr*60                                 ' Òðóäîåìêîñòü â ìèíóòàõ
                  Dw1=DateAdd ("n",CTmin,Dz1)                 ' Ñëåäóþùàÿ äàòà(âðåìÿ) âûïóñêà=äàòà(âðåìÿ)çàïóñêà+òðóäîåìêîñòü
               End If                                         '
           Else                                               ' Åñëè ñìåíèëàñü íîìåíêëàòóðà
               IFirst=INext                                   ' Ïåðâàÿ çàïèñü íîìåíêëàòóðû
               IFirstOP=INextOP                               ' Ïåðâàÿ îïåðàöèÿ
                If TCSActiveModule.Properties("WorkStart").IsNull Then                 ' Åñëè òåêóùàÿ äàòà íà÷àëà ðàáîò íå çàíåñåíà  
                        Set Sostav = TCSApp.Manufacturing.ProductionBOMStructure( TCSActiveModule.Properties("PRODUCTIONBOM_ID").AsInteger, -1, TCSActiveModule.Properties("PRODBOM_STRUCTUREITEM_ID").AsInteger )'Âçÿòü ÏÑï
                        Set Tp = Sostav.Properties("ProductionBOMProcess").AsIDispatch ' Âçÿòü ÒÏ ïîçèöèè ñîñòàâà ÏÑï
                          If Sostav.Properties("SCHEDULE_LAUNCH_DATE").IsNull Then     ' Åñëè ïëàíîâîé äàòû çàïóñêà íåò â ÏÑï
                            If Sostav.Properties("CALC_LAUNCH_DATE").IsNull Then       ' Ïîïûòàòüñÿ âçÿòü åå èç ðàñ÷åòíîé äàòû 
                           II = Tp.Locate( "ID", TCSActiveModule.Properties("PRODBOM_MNFPROCESSITEM_ID").AsInteger,0 )' Ïåðåéòè ê ñîîòâåòñòâóþùåé îïåðàöèè
                           IStr=" Îïåðàöèÿ: " + Tp.Properties("OPERATION_NUMBER").AsSafeString + " " + Tp.Properties("OPERATION_NOTE").AsSafeString + " " + Tp.Properties("OPERATION_NAME").AsSafeString
                           Dz1=TCSApp.InputBox("Ââåäèòå äàòó çàïóñêà äëÿ",IStr,Dz)     ' Ââåñòè äàòó çàïóñêà âðó÷íóþ
                            Else                                                       ' 
                           Dz1=Sostav.Properties("CALC_LAUNCH_DATE").AsDate            ' Âçÿòü èç ðàñ÷åòíîé äàòû      
                            End If                                                   '
                          Else                                                         '
                           Dz1=Sostav.Properties("SCHEDULE_LAUNCH_DATE").AsDate        ' Âçÿòü èç ïëàíîâîé äàòû 
                          End If                                                      '
                    Set Sostav = Nothing                                    ' Îñâîáîäèòü îáúåêò
                    Set Tp = Nothing                                          ' Îñâîáîäèòü îáúåêò
                Else                                                                    '    
                Dz1=TCSActiveModule.Properties("WorkStart").AsDate                     ' Âçÿòü òåêóùóþ äàòó çàïóñêà
                End If                                                                '
               CTmin=Tr*60                                                   ' Òðóäîåìêîñòü â ìèíóòàõ
               Dw1=DateAdd ("n",CTmin,Dz1)                       ' Äàòà âûïóñêà
           End If                                                                      '
'           
'   Êîððåêòèðîâêà äàòû ñ ó÷åòîì êîýôôèöèåíòà ñìåííîñòè        
'           
         If Sm=1 Or Sm=2 Then                                 ' Êîððåêòèðîâêà äàòû âûïóñêà â çàâèñèìîñòè îò ñìåííîñòè
         CTmin=DateDiff("n",Dz1,Dw1)                          ' Âçÿòü ðàçíîñòü ì-äó äàòàìè âûïóñêà è çàïóñêà â ìèíóòàõ
         SmD=INT(CTmin/(480))                                 ' Êîëè÷åñòâî öåëûõ ñìåí ì-äó äàòàìè âûïóñêà è çàïóñêà
         L=INT(SmD/Sm)                                        ' Êîëè÷åñòâî öåëûõ äíåé ñ ó÷åòîì êîýôôèöèåíòà ñìåííîñòè
         CTmin=(L*1440)+ (CTmin-(L*Sm)*480)                   ' Äîáàâî÷íûå ìèíóòû=Êîëè÷åñòâî ìèíóò â öåëûõ äíÿõ + îñòàâøååñÿ âðåìÿ â ñëåäóþùåé ñìåíå
         Dw1=DateAdd ("n",CTmin,Dz1)                          ' Ñëåäóþùàÿ äàòà(âðåìÿ) âûïóñêà=äàòà(âðåìÿ)çàïóñêà + Äîáàâî÷íûå ìèíóòû
         End If                                               '
'
'   Çàíåñåíèå âðåìåí â ïëàí
' 
         Call TCSActiveModule.Edit                            'Áåðåì çàïèñü íà ðåäàêòèðîâàíèå
         If TCSActiveModule.Properties("WorkEnd").IsNull Then ' Åñëè äàòà âûïóñêà âîîáùå íå çàäàíà  
           TCSActiveModule.Properties("WorkEnd").AsDate=TCSApp.StringToDate(Dw1)
           TCSActiveModule.Properties("WorkStart").AsDate=TCSApp.StringToDate(Dz1)
           K=K+1                                              '
         Else                                                 '
           If Dz1 > TCSActiveModule.Properties("WorkEnd").AsDate Then 'Åñëè ïîëó÷èëàñü äàòà çàïóñêà > òåêóùåé äàòû âûïóñêà  
           TCSActiveModule.Properties("WorkEnd").AsDate=TCSApp.StringToDate(Dw1)
           TCSActiveModule.Properties("WorkStart").AsDate=TCSApp.StringToDate(Dz1)
           K=K+1
           Else                                               ' Åñëè ïîëó÷èëàñü äàòà çàïóñêà <= òåêóùåé äàòû âûïóñêà 
           TCSActiveModule.Properties("WorkStart").AsDate=TCSApp.StringToDate(Dz1)
           TCSActiveModule.Properties("WorkEnd").AsDate=TCSApp.StringToDate(Dw1)
           K=K+1
           End If                                             ' ×òîáû äàòû çàíîñèëèñü ïðàâèëüíî
         End If
         Call TCSActiveModule.SaveChanges                     'Ñîõðàíèì äàííûå, è åñëè ïðîèçîøëà
         Call TCSActiveModule.CancelChanges                   'îøèáêà, îòìåíèì âñå èçìåíåíèÿ
           Dz=Dz1                                             ' Ñäåëàòü òåêóùóþ äàòó çàïóñêà ïðåäûäóùåé
           Dw=Dw1                                             ' Ñäåëàòü òåêóùóþ äàòó âûïóñêà ïðåäûäóùåé
              If M=0 Then IStr="|"                            '
              If M=10 Then IStr="/"                            ' Îòðèñîâàòü
              If M=20 Then IStr="--"                           ' êðàñèâûé 
              If M=30 Then                                     ' ïðîãðåññ
                  IStr="\"                                    '
                  M=0                                         '
              End If                                          '
              M=M+1                                           '
           JStr="Ñòðîêà " & CStr(I + 1) & " èç " & CStr(RowsCount)
           Call TCSApp.ShowProgressMessage(JStr, IStr)        '
        Next                                                  ' Âçÿòü íîâóþ çàïèñü
           Call TCSApp.HideProgressMessage                    ' Ñêðûòü ïðîãðåñc
        For I = 0 To RowsCount - 1                            ' Èäòè ïî ìàññèâó ññûëîê
            Call TCSActiveModule.GotoBookmark( msBM( I ) )    ' Ïîçèöèîíèðîâàòüñÿ íà òåêóùóþ çàïèñü
            TCSActiveModule.CurrentRowSelected = True         ' Âåðíóòü âûäåëåíèå ñòðîêè
        Next                                                  '
        Call TCSApp.ShowMessageBox("Ñîîáùåíèå", "Äàòû ðàññ÷èòàíû äëÿ " + Cstr(K) + " çàïèñåé")
        If K=0 Then
          Call TCSApp.ShowMessageBox("Ñîîáùåíèå", "Ëèáî ðàñ÷åò óæå áûë ñäåëàí, ëèáî ïåðåêëþ÷èòåñü â ðåæèì, ïîçâîëÿþùèé ðåäàêòèðîâàíèå")
        End If
    Else  
        Call TCSApp.ShowMessageBox("Ñîîáùåíèå", "Ââåäèòå ïðàâèëüíûé êîýôôèöèåíò ñìåííîñòè: 1,2,3 ! ")
    End If    
    Else                                                      ' Åñëè âûäåëåííûõ çàïèñåé íåò
        Call TCSApp.ShowMessageBox("Ñîîáùåíèå", "Âûäåëèòå çàïèñè äëÿ êîòîðûõ íåîáõîäèìî âû÷èñëèòü äàòû")
    End If                                                    '
End Sub                                                       '

 

! Ñì. òàêæå:

18.3 Â ðåæèìå «Ïðîèçâîäñòâî»