'3. 点击查询按钮,信息列表查询表V_Trans_Fac_JobTypeInv,条件:工序系统等于选择'工序系统
'And SendJobTypeName='二检' And IsAffirm=1(已确认) And日期>=起始日期 And日期<=结束日期。
'表V_Trans_Fac_JobTypeInv
'TransNo   Trans_Fac_JobTypeInv.TransNo 移交单号    0
'Date      Trans_Fac_JobTypeInv.Date 发放日期       1
'Res   Trans_Fac_JobTypeInv.Res 备注        2
'IsAffirm  Trans_Fac_JobTypeInv.IsAffirm            3
'AffirmDate    Trans_Fac_JobTypeInv.AffirmDate       4
'ProductName   Trans_Fac_JobTypeInv_Item.ProductName  5
'AddNo         Trans_Fac_JobTypeInv_Item.AddNo        6
'Type          Trans_Fac_JobTypeInv_Item.Type         7
'Quantity      Trans_Fac_JobTypeInv_Item.Quantity     8
'ReceiveJobTypeName   Trans_Fac_JobTypeInv.ReceiveJobTypeName  9
'SendJobTypeName      Trans_Fac_JobTypeInv.SendJobTypeName   10
'SystemNo      Trans_Fac_JobTypeInv.SystemNo   11
'IsReturn     varchar(2)    12
'RProductName  Trans_Fac_JobTypeInv_Item.RProductName 13
'RAddNo        Trans_Fac_JobTypeInv_Item.RAddNo    14
'MSHFlexGrid2.FormatString = "|品番|附加号|是否悬垂|单重达到|总重|单价|总价|"'4. 点击统计按钮,对查询结果进行统计:是否悬垂、单重达到、单价取自二检的定额,表Pay_Stand_QMJob,
'条件:JobName='二检'。总重:按"二检"定额设定的分类标准,对查询结果中的产品重量统计。
'总价 = 单价×总重?
'表Pay_Stand_QMJob
'ID    VARCHAR(1)  自动编号          0                  key
'JobName   VARCHAR(8)  工序名称包括:二检、三检、音速、探伤     1
'IsOverhang   Char (1)              2
'Weight    NUMERIC(6, 2)  最小重量,一些特殊的重量表示特殊的标识 
'Uweight                 最大重量        3
'ProductName    VARCHAR(512)    多个品番,品番中间用顿号隔开。(也可以不输人品番只用重量和是否悬垂来标示)        4
'unitprice    NUMERIC(6, 4)   单价           5
'Unit    VARCHAR(2)  单价的单位:吨或件          6Dim rsMSHF, rsMSHF1, rsMSHF2, rsMSHF3 As ADODB.Recordset
Dim rs As ADODB.RecordsetDim intMshfRows As Integer
Dim sumweight1, unitprice1, sumweight2, unitprice2 As Double
Dim sumprice As DoubleSet rsMSHF = Gconn.Execute("select ProductName,sum(Quantity),IsOverhang,RoughWeight from V_Trans_Fac_JobTypeInv_TwoPay where SystemNo='" & Trim(Combo1.Text) _
& "' and  SendJobTypeName like '%二%检%' and IsAffirm=1 and Date1>='" & Trim(DTPicker1.Value) _
& "' and Date1<='" & Trim(DTPicker2.Value) & "' group by ProductName,IsOverhang,RoughWeight")
   While Not rsMSHF.EOF
          intMshfRows = MSHFlexGrid2.Rows
          If intMshfRows = 2 And MSHFlexGrid2.TextMatrix(1, 1) = "" Then
          intMshfRows = 1
          Else
          MSHFlexGrid2.Rows = intMshfRows + 1
          End If
         MSHFlexGrid2.TextMatrix(intMshfRows, 1) = rsMSHF.Fields(0)
         MSHFlexGrid2.TextMatrix(intMshfRows, 3) = rsMSHF.Fields(3)
         MSHFlexGrid2.TextMatrix(intMshfRows, 4) = rsMSHF.Fields(1) * rsMSHF.Fields(3)
         'Set rsMSHF1 = Gconn.Execute("select RoughWeight from Con_fac_Product where ProductName='" & rsMSHF.Fields(0) & "' and IsOverhang='1'")
         'If Not rsMSHF1.EOF Then
          'MSHFlexGrid2.FormatString = "|品番|是否悬垂|单重|总重|单价|总价|"
          'If rsmshf.fields(3) = "" Then
          '  rsmshf.fields(3) = "0"
          'End If
          'MsgBox rsmshf.fields(3)
          If rsMSHF.Fields(2) = "1" Then
          MSHFlexGrid2.TextMatrix(intMshfRows, 2) = "是"
        
          '取单价:
          Set rsMSHF3 = Gconn.Execute("select Weight,Uweight,UnitPrice from Pay_Stand_QMJob where JobName='二检' and IsOverhang='是'")'是悬锤的情况下不用输入品番
          While Not rsMSHF3.EOF
           If rsMSHF3.Fields(1) = "" Then'如果最大重量为空
               If Val(rsMSHF.Fields(3)) >= Val(rsMSHF3.Fields(0)) Then'判断品番重量是否大于最小重量
                 MSHFlexGrid2.TextMatrix(intMshfRows, 5) = rsMSHF3.Fields(2)
               End If
           Else
              '              MsgBox rsmshf.fields(3)
               '  MsgBox rsMSHF3.Fields(1)
                 If Val(rsMSHF.Fields(3)) >= Val(rsMSHF3.Fields(0)) And Val(rsMSHF.Fields(3)) < Val(rsMSHF3.Fields(1)) Then
                     MSHFlexGrid2.TextMatrix(intMshfRows, 5) = rsMSHF3.Fields(2)
                 End If                     '              MsgBox Val(rsmshf.fields(3)) > Val(rsMSHF3.Fields(0)) And Val(rsmshf.fields(3)) < Val(rsMSHF3.Fields(1))           End If
          
          rsMSHF3.MoveNext
          Wend
          rsMSHF3.Close
          Set rsMSHF3 = Nothing
          
       
         End If
         'rsMSHF1.Close
         'Set rsMSHF1 = Nothing
      ' MsgBox "select * from Pay_Stand_QMJob where ProductName='" & rsMSHF.Fields(0) & "' and IsOverhang='0' and JobName='二检'"

解决方案 »

  1.   


    '******************************************************************************************************************************************************
             'Set rsMSHF1 = Gconn.Execute("select RoughWeight from Con_fac_Product where ProductName='" & rsMSHF.Fields(0) & "' and IsOverhang='0'")
             'If Not rsMSHF1.EOF Then
              'MSHFlexGrid1.FormatString = "|||是否悬垂|单重达到|总量|单价|总价|"
              If rsMSHF.Fields(2) = "0" Then
              MSHFlexGrid2.TextMatrix(intMshfRows, 2) = "否"
              
               '取单价:
              Set rsMSHF2 = Gconn.Execute("select Productname from Pay_Stand_QMJob where JobName='二检' and IsOverhang='否'")
                If Not rsMSHF2.EOF Then
                
                       If rsMSHF2.Fields(0) = "" Then
                        
                        
              Set rsMSHF3 = Gconn.Execute("select Weight,Uweight,UnitPrice from Pay_Stand_QMJob where JobName='二检' and IsOverhang='否'")
              'MsgBox "select Weight,Uweight,UnitPrice from Pay_Stand_QMJob where JobName='二检' and IsOverhang='否' and ProductName like '%" & Trim(MSHFlexGrid2.TextMatrix(intMshfRows, 1)) & "%'"
              While Not rsMSHF3.EOF
               If rsMSHF3.Fields(1) = "" Then
                   If Val(rsMSHF.Fields(3)) >= Val(rsMSHF3.Fields(0)) Then
                     MSHFlexGrid2.TextMatrix(intMshfRows, 5) = rsMSHF3.Fields(2)
                       Else
                   If rsMSHF3.Fields(0) = "" Then
                        MSHFlexGrid2.TextMatrix(intMshfRows, 5) = rsMSHF3.Fields(2)
                   End If
           
                   End If
               Else
                     If Val(rsMSHF.Fields(3)) >= Val(rsMSHF3.Fields(0)) And Val(rsMSHF.Fields(3)) <= Val(rsMSHF3.Fields(1)) Then
                         MSHFlexGrid2.TextMatrix(intMshfRows, 5) = rsMSHF3.Fields(2)
                     End If
                   
               End If
              
              rsMSHF3.MoveNext
              Wend
              rsMSHF3.Close
              Set rsMSHF3 = Nothing
              
                        
                        Else
                 
              Set rsMSHF3 = Gconn.Execute("select Weight,Uweight,UnitPrice from Pay_Stand_QMJob where JobName='二检' and IsOverhang='否' and ProductName like '%" & Trim(MSHFlexGrid2.TextMatrix(intMshfRows, 1)) & "%'")
              'MsgBox "select Weight,Uweight,UnitPrice from Pay_Stand_QMJob where JobName='二检' and IsOverhang='否' and ProductName like '%" & Trim(MSHFlexGrid2.TextMatrix(intMshfRows, 1)) & "%'"
              While Not rsMSHF3.EOF
               If rsMSHF3.Fields(1) = "" Then
                   If Val(rsMSHF.Fields(3)) >= Val(rsMSHF3.Fields(0)) Then
                     MSHFlexGrid2.TextMatrix(intMshfRows, 5) = rsMSHF3.Fields(2)
                       Else
                   If rsMSHF3.Fields(0) = "" Then
                        MSHFlexGrid2.TextMatrix(intMshfRows, 5) = rsMSHF3.Fields(2)
                   End If
           
                   End If
               Else
                     If Val(rsMSHF.Fields(3)) >= Val(rsMSHF3.Fields(0)) And Val(rsMSHF.Fields(3)) < Val(rsMSHF3.Fields(1)) Then
                         MSHFlexGrid2.TextMatrix(intMshfRows, 5) = rsMSHF3.Fields(2)
                     End If
                   
               End If
              
              rsMSHF3.MoveNext
              Wend
              rsMSHF3.Close
              Set rsMSHF3 = Nothing
              
                      End If
              End If
              
              rsMSHF2.Close
              Set rsMSHF2 = Nothing
            End If
             'rsMSHF1.Close
             'Set rsMSHF1 = Nothing
             
            MSHFlexGrid2.TextMatrix(intMshfRows, 6) = Val(MSHFlexGrid2.TextMatrix(intMshfRows, 5)) * Val(MSHFlexGrid2.TextMatrix(intMshfRows, 4)) / 1000
            
             sumprice = sumprice + Val(MSHFlexGrid2.TextMatrix(intMshfRows, 6))
       rsMSHF.MoveNext
       Wend
       rsMSHF.Close
       Set rsMSHF = Nothing
    Text5.Text = CStr(sumprice) '统计列表中的总价之和
    Call Text6_GotFocus
    Call Text7_Change