上传用户:zhpu1995
上传日期:2013-09-06
资源大小:61151k
文件大小:83k
源码类别:

企业管理

开发平台:

Visual Basic

  1. VERSION 5.00
  2. Begin VB.Form Cg_FrmPlanUnitType 
  3.    BackColor       =   &H8000000A&
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "合并生成采购计划方式"
  6.    ClientHeight    =   2130
  7.    ClientLeft      =   45
  8.    ClientTop       =   330
  9.    ClientWidth     =   3570
  10.    Icon            =   "采购系统_采购计划生成条件.frx":0000
  11.    LinkTopic       =   "Form1"
  12.    MaxButton       =   0   'False
  13.    MinButton       =   0   'False
  14.    ScaleHeight     =   2130
  15.    ScaleWidth      =   3570
  16.    StartUpPosition =   1  '所有者中心
  17.    Begin VB.CommandButton Cmd_Cancel 
  18.       Caption         =   "取消(&C)"
  19.       Height          =   300
  20.       Left            =   2370
  21.       TabIndex        =   9
  22.       Top             =   1740
  23.       Width           =   1120
  24.    End
  25.    Begin VB.CommandButton Cmd_OK 
  26.       Caption         =   "确定(&O)"
  27.       Height          =   300
  28.       Left            =   1170
  29.       TabIndex        =   8
  30.       Top             =   1740
  31.       Width           =   1120
  32.    End
  33.    Begin VB.Frame Frame1 
  34.       Height          =   1605
  35.       Left            =   90
  36.       TabIndex        =   0
  37.       Top             =   30
  38.       Width           =   3390
  39.       Begin VB.OptionButton Opt_CreateType 
  40.          Caption         =   "物料编码"
  41.          Height          =   240
  42.          Index           =   6
  43.          Left            =   165
  44.          TabIndex        =   7
  45.          Top             =   1170
  46.          Width           =   2175
  47.       End
  48.       Begin VB.OptionButton Opt_CreateType 
  49.          Caption         =   "供应商"
  50.          Height          =   240
  51.          Index           =   5
  52.          Left            =   1860
  53.          TabIndex        =   6
  54.          Top             =   850
  55.          Width           =   1215
  56.       End
  57.       Begin VB.OptionButton Opt_CreateType 
  58.          Caption         =   "计划日期"
  59.          Height          =   240
  60.          Index           =   4
  61.          Left            =   165
  62.          TabIndex        =   5
  63.          Top             =   850
  64.          Width           =   2175
  65.       End
  66.       Begin VB.OptionButton Opt_CreateType 
  67.          Caption         =   "计划到货日期"
  68.          Height          =   240
  69.          Index           =   3
  70.          Left            =   1860
  71.          TabIndex        =   4
  72.          Top             =   530
  73.          Width           =   1425
  74.       End
  75.       Begin VB.OptionButton Opt_CreateType 
  76.          Caption         =   "库存物料分类"
  77.          Height          =   240
  78.          Index           =   2
  79.          Left            =   165
  80.          TabIndex        =   3
  81.          Top             =   530
  82.          Width           =   1425
  83.       End
  84.       Begin VB.OptionButton Opt_CreateType 
  85.          Caption         =   "采购物料分类"
  86.          Height          =   240
  87.          Index           =   1
  88.          Left            =   1860
  89.          TabIndex        =   2
  90.          Top             =   210
  91.          Width           =   1425
  92.       End
  93.       Begin VB.OptionButton Opt_CreateType 
  94.          Caption         =   "供应商+物料"
  95.          Height          =   240
  96.          Index           =   0
  97.          Left            =   165
  98.          TabIndex        =   1
  99.          Top             =   210
  100.          Value           =   -1  'True
  101.          Width           =   1455
  102.       End
  103.    End
  104. End
  105. Attribute VB_Name = "Cg_FrmPlanUnitType"
  106. Attribute VB_GlobalNameSpace = False
  107. Attribute VB_Creatable = False
  108. Attribute VB_PredeclaredId = True
  109. Attribute VB_Exposed = False
  110. '*********************************************************************************************************
  111. '*    模 块 名 称 :采购计划合并
  112. '*    功 能 描 述 :此功能模块主要完成采购计划的合并
  113. '*    程序员姓名  : 李海祥
  114. '*    最后修改人  : 李海祥
  115. '*    最后修改时间:2001/07/19
  116. '*    备        注:程序中所有依实际情况自定义部分均用[>>  <<]括起
  117. '*
  118. '*
  119. '*********************************************************************************************************
  120. Dim iType As Integer                     '合并方式
  121. Dim GridStr()  As String                 '网格列信息(字符型)
  122. Dim Szzls As Integer                     '数组总列数(网格列数-1)
  123. Private Sub Cmd_Cancel_Click()
  124.   Unload Me
  125.   Xtfhcs = "0"
  126. End Sub
  127. Private Sub Cmd_OK_Click()
  128.     Dim str_SQLSelectT1 As String  'select & from 语句
  129.     Dim str_SQLSelectT2 As String
  130.     Dim str_SQLSelectT As String
  131.     Dim str_SQLGroupT1 As String   'group 语句
  132.     Dim str_SQLGroupT2 As String
  133.     Dim str_sqlTemp As String
  134.     Dim str_SQLTempDis1 As String
  135.     Dim str_SQLTempDis2 As String
  136.     Dim str_SQLPurBillDet As String '采购计划从表
  137.     Dim str_SQLWhereT As String '临时where语句
  138.     Dim str_SQLWhere As String  '经过查询得到的WHERE语句
  139.     Dim autojsq As Integer
  140.     Dim Rs_Hbpc As New ADODB.Recordset   '合并批次查询记录集
  141.     Dim Hbpc As Long         '合并的批次
  142.     Dim str_SQLSelectTmp As String
  143.     Dim str_SQLGroupTmp As String
  144.     Dim str_SQLWhereTmp As String
  145.     Dim str_Insert As String
  146.     Dim str_Update As String
  147.     Dim str_SQLWhereTmp1 As String
  148.     Dim Rs_SQLWhereTmp As New ADODB.Recordset   '查询child_id记录集
  149.     Dim str_SQLAssi As String                   '查询计划辅表语句
  150.     Dim rs_SQLAssi As New ADODB.Recordset       '计划辅表记录集
  151.     Dim j As Integer
  152.     Dim i As Integer
  153.     Dim rs_CreatePurBillPri As New ADODB.Recordset
  154.     Dim rs_CreatePurBillDet As New ADODB.Recordset
  155.     Dim rs_TempDis1 As New ADODB.Recordset
  156.     Dim rs_TempDis2 As New ADODB.Recordset
  157.     Set Rs_Hbpc = Cw_DataEnvi.DataConnect.Execute("select max(SplitUniteNum) as m_SplitUniteNum from Cg_PurPlanMain")
  158.     Hbpc = Rs_Hbpc.Fields("m_SplitUniteNum") + 1
  159.     Set Rs_Hbpc = Nothing
  160.     
  161.   
  162.     str_SQLWhere = str_SQLAutoid
  163.   
  164.     Set rs_Temp = Cw_DataEnvi.DataConnect.Execute("select distinct KjYear,Period from Cg_V_PlanBill " & str_SQLWhere)
  165.     If rs_Temp.RecordCount <> 1 Then
  166.         Call Xtxxts("应为同一会计年度和会计月份,请重新选择采购计划!", 0, 4)
  167.         Set rs_Temp = Nothing
  168.         Exit Sub
  169.     Else
  170.         Set rs_Temp = Nothing
  171.     End If
  172.     Set rs_Temp = Cw_DataEnvi.DataConnect.Execute("select distinct ExigenceFlag from Cg_V_PlanBill " & str_SQLWhere)
  173.     If rs_Temp.RecordCount <> 1 Then
  174.         Call Xtxxts("普通计划和紧急计划不能合并,请重新选择采购计划!", 0, 4)
  175.         Set rs_Temp = Nothing
  176.         Exit Sub
  177.     Else
  178.         Set rs_Temp = Nothing
  179.     End If
  180.   
  181.   
  182.     For i = 0 To Me.Opt_CreateType.count - 1
  183.         If Me.Opt_CreateType(i).Value = True Then
  184.             Exit For
  185.         End If
  186.     Next i
  187.     iType = i
  188.     Unload Me
  189.   
  190.     Xt_Wait.Show
  191.     Xt_Wait.Refresh
  192.     str_SQLPurBillDet = "select * from Cg_PurPlanSub where 1=2"
  193.     rs_CreatePurBillDet.Open str_SQLPurBillDet, Cw_DataEnvi.DataConnect, adOpenDynamic, adLockPessimistic
  194.     str_sqlTemp = "select * from Cg_PurPlanMain where 1=2"
  195.     rs_CreatePurBillPri.Open str_sqlTemp, Cw_DataEnvi.DataConnect, adOpenDynamic, adLockPessimistic
  196.   
  197.     Cw_DataEnvi.DataConnect.BeginTrans
  198.   
  199.     On Error GoTo Err_Ctrl
  200.     Select Case iType
  201.         Case 0  '供应商+物料编码
  202.             str_SQLSelectT1 = "select ExigenceFlag,KjYear,Period,SupplierCode,MNumber,sum(Quantity) as SumQuantity from Cg_V_PlanBill "
  203.             str_SQLGroupT1 = " Group by ExigenceFlag,KjYear,Period ,SupplierCode,MNumber "
  204.             str_SQLSelectT2 = "select ExigenceFlag,ProcFactory,KjYear,Period,SupplierCode,MNumber,sum(Quantity) as SumQuantity from Cg_V_PlanBill "
  205.             str_SQLGroupT2 = " Group by ExigenceFlag,KjYear,Period ,SupplierCode,MNumber,ProcFactory "
  206.             str_SQLSelectTmp = "select PurPlanMainID,PurPlanSubID,KjYear,Period ,SupplierCode,MNumber from Cg_V_PlanBill "
  207.             str_SQLGroupTmp = " Group by KjYear,Period ,PurPlanMainID,PurPlanSubID,SupplierCode,MNumber "
  208.             '没有生产厂家的计划合并
  209.             str_SQLTempDis1 = str_SQLSelectT1 & str_SQLWhere & " and ProcFactory='' " & str_SQLGroupT1
  210.             Set rs_TempDis1 = Cw_DataEnvi.DataConnect.Execute(str_SQLTempDis1)
  211.             Do While Not rs_TempDis1.EOF()
  212.                 str_SQLWhereT = ""
  213.                 If IsNull(rs_TempDis1.Fields("SupplierCode")) Then
  214.                     str_SQLWhereT = str_SQLWhere & " and SupplierCode is null and MNumber='" & Trim(rs_TempDis1.Fields("MNumber") & "") & "'"
  215.                 Else
  216.                     str_SQLWhereT = str_SQLWhere & " and SupplierCode='" & Trim(rs_TempDis1.Fields("SupplierCode") & "") & "' and MNumber='" & Trim(rs_TempDis1.Fields("MNumber") & "") & "'"
  217.                 End If
  218.                 str_SQLWhereT = str_SQLWhereT & " and ProcFactory='' "
  219.                 str_SQLSupplierCodeT = str_SQLSelectT1 & str_SQLWhereT & str_SQLGroupT1
  220.                 Set rs_suppliercodet = Nothing
  221.                 Set rs_suppliercodet = Cw_DataEnvi.DataConnect.Execute(str_SQLSupplierCodeT)
  222.                 If Not rs_suppliercodet.EOF() Then
  223.                     With rs_CreatePurBillPri
  224.                         .AddNew
  225.                         .Fields("PurPlanMainID") = CreatBillID("1101")                  '单据ID
  226.                         .Fields("PurPlanNum") = CreatBillCode("1101", True)             '单据号
  227.                         .Fields("PurPlanDate") = Format(Xtrq, "yyyy-mm-dd")             '计划日期
  228.                         .Fields("KjYear") = Trim(rs_TempDis1.Fields("KjYear"))          '会计年
  229.                         .Fields("Period") = Trim(rs_TempDis1.Fields("Period"))          '会计期间
  230.                         .Fields("SupplierCode") = rs_TempDis1.Fields("SupplierCode")    '供应商
  231.                         .Fields("PurPlanType") = "合并生成"                             '计划类型
  232.                         .Fields("Maker") = Xtczy                                        '制单人
  233.                         .Fields("PurPlanStyle") = "2"                                   '不能被生产系统调用                          '不能被生产系统调用
  234.                         .Fields("SplitUniteNum") = Hbpc                                 '拆合过程号
  235.                         .Fields("SplitUniteFlag") = 0                                   '拆合标志
  236.                         .Fields("ExigenceFlag") = rs_TempDis1.Fields("ExigenceFlag")    '紧急标志
  237.                         .Fields("Checker") = Xtczy                                      '审核人
  238.                         .Fields("FinishFlag") = 0                                       '完成标志
  239.                         .Fields("Transmitter") = ""                                     '下达人置空
  240.                         .UpdateBatch
  241.                     End With
  242.                     With rs_CreatePurBillDet
  243.                         j = 1
  244.                         Do While Not rs_suppliercodet.EOF()
  245.                             .AddNew
  246.                             .Fields("PurPlanSubID") = j                                                     '子表ID
  247.                             .Fields("PurPlanMainID") = rs_CreatePurBillPri.Fields("PurPlanMainID") + 0      '单据ID
  248.                             .Fields("MNumber") = Trim(rs_suppliercodet.Fields("MNumber") & "")              '物料编码
  249.                             .Fields("Quantity") = S2N(rs_suppliercodet.Fields("SumQuantity") & "")          '数量
  250.                             .Fields("ProcFactory") = ""                                                     '生产厂家
  251.                             .Fields("Remark") = ""                                                          '备注
  252.                             .UpdateBatch
  253.                             '更新计划拆合跟踪表
  254.                             str_SQLWhereTmp = str_SQLSelectTmp & str_SQLWhereT & str_SQLGroupTmp
  255.                             Set Rs_SQLWhereTmp = Nothing
  256.                             Set Rs_SQLWhereTmp = Cw_DataEnvi.DataConnect.Execute(str_SQLWhereTmp)
  257.                             Do While Not Rs_SQLWhereTmp.EOF()
  258.                                 str_Insert = "insert into Cg_SplitUnite(SplitUniteNum,NewPurPlanMainID,NewPurPlanSubID,PurPlanMainID,PurPlanSubID)" & "values( " & Hbpc & "," & rs_CreatePurBillPri.Fields("PurPlanMainID") & " ," & rs_CreatePurBillDet.Fields("PurPlanSubID") & "," & Rs_SQLWhereTmp.Fields("PurPlanMainID") & "," & Rs_SQLWhereTmp.Fields("PurPlanSubID") & ")"
  259.                                 Cw_DataEnvi.DataConnect.Execute (str_Insert)
  260.                                 Rs_SQLWhereTmp.MoveNext
  261.                             Loop
  262.                             '更新结束
  263.                             rs_suppliercodet.MoveNext
  264.                             j = j + 1
  265.                         Loop
  266.                     End With
  267.                 End If
  268.                 rs_TempDis1.MoveNext
  269.             Loop
  270.             '有生产厂家计划合并
  271.             str_SQLSelectTmp = "select PurPlanMainID,PurPlanSubID,KjYear,Period ,SupplierCode,MNumber from Cg_V_PlanBill "
  272.             str_SQLGroupTmp = " Group by KjYear,Period ,PurPlanMainID,PurPlanSubID,SupplierCode,MNumber "
  273.             str_SQLTempDis2 = str_SQLSelectT2 & str_SQLWhere & " and ProcFactory<>'' " & str_SQLGroupT2
  274.             Set rs_TempDis2 = Cw_DataEnvi.DataConnect.Execute(str_SQLTempDis2)
  275.             Do While Not rs_TempDis2.EOF()
  276.                 str_SQLWhereT = ""
  277.                 If IsNull(rs_TempDis1.Fields("SupplierCode")) Then
  278.                     str_SQLWhereT = str_SQLWhere & " and SupplierCode is null and MNumber='" & Trim(rs_TempDis2.Fields("MNumber") & "") & "'"
  279.                 Else
  280.                     str_SQLWhereT = str_SQLWhere & " and SupplierCode='" & Trim(rs_TempDis2.Fields("SupplierCode") & "") & "' and MNumber='" & Trim(rs_TempDis2.Fields("MNumber") & "") & "'"
  281.                 End If
  282.                 str_SQLWhereT = str_SQLWhereT & " and ProcFactory<>'' "
  283.                 str_SQLSupplierCodeT = str_SQLSelectT2 & str_SQLWhereT & str_SQLGroupT2
  284.                 Set rs_suppliercodet = Nothing
  285.                 Set rs_suppliercodet = Cw_DataEnvi.DataConnect.Execute(str_SQLSupplierCodeT)
  286.                 If Not rs_suppliercodet.EOF() Then
  287.                     With rs_CreatePurBillPri
  288.                         .AddNew
  289.                         .Fields("PurPlanMainID") = CreatBillID("1101")                  '单据ID
  290.                         .Fields("PurPlanNum") = CreatBillCode("1101", True)             '单据号
  291.                         .Fields("PurPlanDate") = Format(Xtrq, "yyyy-mm-dd")             '计划日期
  292.                         .Fields("KjYear") = Trim(rs_TempDis2.Fields("KjYear"))          '会计年
  293.                         .Fields("Period") = Trim(rs_TempDis2.Fields("Period"))          '会计期间
  294.                         .Fields("SupplierCode") = rs_TempDis2.Fields("SupplierCode")    '供应商
  295.                         .Fields("PurPlanType") = "合并生成"                             '计划类型
  296.                         .Fields("Maker") = Xtczy                                        '制单人
  297.                         .Fields("PurPlanStyle") = "2"                                   '不能被生产系统调用                          '不能被生产系统调用
  298.                         .Fields("SplitUniteNum") = Hbpc                                 '拆合过程号
  299.                         .Fields("SplitUniteFlag") = 0                                   '拆合标志
  300.                         .Fields("ExigenceFlag") = rs_TempDis2.Fields("ExigenceFlag")    '紧急标志
  301.                         .Fields("Checker") = Xtczy                                      '审核人
  302.                         .Fields("FinishFlag") = 0                                       '完成标志
  303.                         .Fields("Transmitter") = ""                                     '下达人置空
  304.                         .UpdateBatch
  305.                     End With
  306.                     With rs_CreatePurBillDet
  307.                         j = 1
  308.                         Do While Not rs_suppliercodet.EOF()
  309.                             .AddNew
  310.                             .Fields("PurPlanSubID") = j                                                 '子表ID
  311.                             .Fields("PurPlanMainID") = rs_CreatePurBillPri.Fields("PurPlanMainID") + 0  '单据ID
  312.                             .Fields("MNumber") = Trim(rs_suppliercodet.Fields("MNumber") & "")          '物料编码
  313.                             .Fields("Quantity") = S2N(rs_suppliercodet.Fields("SumQuantity") & "")      '数量
  314.                             .Fields("ProcFactory") = Trim(rs_suppliercodet.Fields("ProcFactory"))       '生产厂家
  315.                             .Fields("Remark") = ""                                                      '备注
  316.                             .UpdateBatch
  317.                             '更新计划拆合跟踪表
  318.                             str_SQLWhereTmp = str_SQLSelectTmp & str_SQLWhereT & str_SQLGroupTmp
  319.                             Set Rs_SQLWhereTmp = Nothing
  320.                             Set Rs_SQLWhereTmp = Cw_DataEnvi.DataConnect.Execute(str_SQLWhereTmp)
  321.                             Do While Not Rs_SQLWhereTmp.EOF()
  322.                                 str_Insert = "insert into Cg_SplitUnite(SplitUniteNum,NewPurPlanMainID,NewPurPlanSubID,PurPlanMainID,PurPlanSubID)" & "values( " & Hbpc & "," & rs_CreatePurBillPri.Fields("PurPlanMainID") & " ," & rs_CreatePurBillDet.Fields("PurPlanSubID") & "," & Rs_SQLWhereTmp.Fields("PurPlanMainID") & "," & Rs_SQLWhereTmp.Fields("PurPlanSubID") & ")"
  323.                                 Cw_DataEnvi.DataConnect.Execute (str_Insert)
  324.                                 Rs_SQLWhereTmp.MoveNext
  325.                             Loop
  326.                             '更新结束
  327.                             rs_suppliercodet.MoveNext
  328.                             j = j + 1
  329.                         Loop
  330.                     End With
  331.                 End If
  332.                 rs_TempDis2.MoveNext
  333.             Loop
  334.         Case 1    '采购物料分类
  335.             '没有生产厂家的计划合并
  336.             str_SQLSelectT = "select distinct KjYear,Period,PurSortCode,ExigenceFlag from Cg_V_PlanBill "
  337.             
  338.             str_SQLTempDis1 = str_SQLSelectT & str_SQLWhere & " and ProcFactory='' "
  339.             Set rs_TempDis1 = Cw_DataEnvi.DataConnect.Execute(str_SQLTempDis1)
  340.             Do While Not rs_TempDis1.EOF()
  341.                 str_SQLWhereT = ""
  342.                 If str_SQLWhere <> "" Then
  343.                     str_SQLWhereT = str_SQLWhere & " and PurSortCode = '" & Trim(rs_TempDis1.Fields("PurSortCode") & "") & "'"
  344.                 Else
  345.                     str_SQLWhereT = " where PurSortCode = '" & Trim(rs_TempDis1.Fields("PurSortCode") & "") & "'"
  346.                 End If
  347.                 str_SQLWhereT = str_SQLWhereT & " and ProcFactory='' "
  348.                 str_SQLSelectT = "select  KjYear,Period,PurSortCode,MNumber,sum(Quantity) as SumQuantity from Cg_V_PlanBill "
  349.                 str_SQLGroupT = " Group by KjYear,Period ,PurSortCode,MNumber "
  350.                 str_SQLSelectTmp = "select  PurPlanMainID,PurPlanSubID,KjYear,Period,PurSortCode,MNumber,sum(Quantity) from Cg_V_PlanBill "
  351.                 str_SQLGroupTmp = " Group by KjYear,Period ,PurPlanMainID,PurPlanSubID,PurSortCode,MNumber "
  352.                 str_SQLSupplierCodeT = str_SQLSelectT & str_SQLWhereT & str_SQLGroupT
  353.                 Set rs_suppliercodet = Nothing
  354.                 Set rs_suppliercodet = Cw_DataEnvi.DataConnect.Execute(str_SQLSupplierCodeT)
  355.                 '写记录
  356.                 If Not rs_suppliercodet.EOF() Then
  357.                     With rs_CreatePurBillPri
  358.                         .AddNew
  359.                         .Fields("PurPlanMainID") = CreatBillID("1101")                  '单据ID
  360.                         .Fields("PurPlanNum") = CreatBillCode("1101", True)             '单据号
  361.                         .Fields("PurPlanDate") = Format(Xtrq, "yyyy-mm-dd")             '计划日期
  362.                         .Fields("KjYear") = Trim(rs_TempDis1.Fields("KjYear"))          '会计年
  363.                         .Fields("Period") = Trim(rs_TempDis1.Fields("Period"))          '会计期间
  364.                         .Fields("PurPlanType") = "合并生成"                             '计划类型
  365.                         .Fields("Maker") = Xtczy                                        '制单人
  366.                         .Fields("PurPlanStyle") = "2"                                   '不能被生产系统调用
  367.                         .Fields("SplitUniteNum") = Hbpc                                 '拆合过程号
  368.                         .Fields("SplitUniteFlag") = 0                                   '拆合标志
  369.                         .Fields("ExigenceFlag") = rs_TempDis1.Fields("ExigenceFlag")    '紧急标志
  370.                         .Fields("Checker") = Xtczy                                      '审核人
  371.                         .Fields("FinishFlag") = 0                                       '完成标志
  372.                         .Fields("Transmitter") = ""                                     '下达人置空
  373.                         .UpdateBatch
  374.                     End With
  375.                     With rs_CreatePurBillDet
  376.                         j = 1
  377.                         Do While Not rs_suppliercodet.EOF()
  378.                             .AddNew
  379.                             .Fields("PurPlanSubID") = j                                                 '子表ID
  380.                             .Fields("PurPlanMainID") = rs_CreatePurBillPri.Fields("PurPlanMainID") + 0  '单据ID
  381.                             .Fields("MNumber") = Trim(rs_suppliercodet.Fields("MNumber") & "")          '物料编码
  382.                             .Fields("Quantity") = Trim(rs_suppliercodet.Fields("SumQuantity") & "")     '数量
  383.                             .Fields("ProcFactory") = ""                                                 '生产厂家
  384.                             .Fields("Remark") = ""                                                      '备注
  385.                             .UpdateBatch
  386.                             '更新计划拆合跟踪表
  387.                             str_SQLWhereTmp = str_SQLSelectTmp & str_SQLWhereT & str_SQLGroupTmp
  388.                             Set Rs_SQLWhereTmp = Nothing
  389.                             Set Rs_SQLWhereTmp = Cw_DataEnvi.DataConnect.Execute(str_SQLWhereTmp)
  390.                             Do While Not Rs_SQLWhereTmp.EOF()
  391.                                 str_Insert = "insert into Cg_SplitUnite(SplitUniteNum,NewPurPlanMainID,NewPurPlanSubID,PurPlanMainID,PurPlanSubID)" & "values( " & Hbpc & "," & rs_CreatePurBillPri.Fields("PurPlanMainID") & " ," & rs_CreatePurBillDet.Fields("PurPlanSubID") & "," & Rs_SQLWhereTmp.Fields("PurPlanMainID") & "," & Rs_SQLWhereTmp.Fields("PurPlanSubID") & ")"
  392.                                 Cw_DataEnvi.DataConnect.Execute (str_Insert)
  393.                                 Rs_SQLWhereTmp.MoveNext
  394.                             Loop
  395.                             '更新结束
  396.                             rs_suppliercodet.MoveNext
  397.                             j = j + 1
  398.                         Loop
  399.                     End With
  400.                 End If
  401.                 rs_TempDis1.MoveNext
  402.             Loop
  403.             '有生产厂家的计划合并
  404.             str_SQLSelectT = "select distinct KjYear,Period,PurSortCode,ExigenceFlag from Cg_V_PlanBill "
  405.             str_SQLTempDis2 = str_SQLSelectT & str_SQLWhere & " and ProcFactory<>'' "
  406.             Set rs_TempDis2 = Cw_DataEnvi.DataConnect.Execute(str_SQLTempDis2)
  407.             Do While Not rs_TempDis2.EOF()
  408.                 str_SQLWhereT = ""
  409.                 If str_SQLWhere <> "" Then
  410.                     str_SQLWhereT = str_SQLWhere & " and PurSortCode = '" & Trim(rs_TempDis2.Fields("PurSortCode") & "") & "'"
  411.                 Else
  412.                     str_SQLWhereT = " where PurSortCode = '" & Trim(rs_TempDis2.Fields("PurSortCode") & "") & "'"
  413.                 End If
  414.                 str_SQLWhereT = str_SQLWhereT & " and ProcFactory<>'' "
  415.                 str_SQLSelectT = "select  ProcFactory,KjYear,Period,PurSortCode,MNumber,sum(Quantity) as SumQuantity from Cg_V_PlanBill "
  416.                 str_SQLGroupT = " Group by KjYear,Period ,PurSortCode,ProcFactory,MNumber "
  417.                 str_SQLSelectTmp = "select  PurPlanMainID,PurPlanSubID,KjYear,Period,PurSortCode,MNumber,sum(Quantity),ProcFactory from Cg_V_PlanBill "
  418.                 str_SQLGroupTmp = " Group by KjYear,Period ,PurPlanMainID,PurPlanSubID,PurSortCode,MNumber,ProcFactory "
  419.                 str_SQLSupplierCodeT = str_SQLSelectT & str_SQLWhereT & str_SQLGroupT
  420.                 Set rs_suppliercodet = Nothing
  421.                 Set rs_suppliercodet = Cw_DataEnvi.DataConnect.Execute(str_SQLSupplierCodeT)
  422.                 '写记录
  423.                 If Not rs_suppliercodet.EOF() Then
  424.                     With rs_CreatePurBillPri
  425.                         .AddNew
  426.                         .Fields("PurPlanMainID") = CreatBillID("1101")                  '单据ID
  427.                         .Fields("PurPlanNum") = CreatBillCode("1101", True)             '单据号
  428.                         .Fields("PurPlanDate") = Format(Xtrq, "yyyy-mm-dd")             '计划日期
  429.                         .Fields("KjYear") = Trim(rs_TempDis2.Fields("KjYear"))          '会计年
  430.                         .Fields("Period") = Trim(rs_TempDis2.Fields("Period"))          '会计期间
  431.                         .Fields("PurPlanType") = "合并生成"                             '计划类型
  432.                         .Fields("Maker") = Xtczy                                        '制单人
  433.                         .Fields("PurPlanStyle") = "2"                                   '不能被生产系统调用
  434.                         .Fields("SplitUniteNum") = Hbpc                                 '拆合过程号
  435.                         .Fields("SplitUniteFlag") = 0                                   '拆合标志
  436.                         .Fields("ExigenceFlag") = rs_TempDis2.Fields("ExigenceFlag")    '紧急标志
  437.                         .Fields("Checker") = Xtczy                                      '审核人
  438.                         .Fields("FinishFlag") = 0                                       '完成标志
  439.                         .Fields("Transmitter") = ""                                     '下达人置空
  440.                         .UpdateBatch
  441.                     End With
  442.                     With rs_CreatePurBillDet
  443.                         j = 1
  444.                         Do While Not rs_suppliercodet.EOF()
  445.                             .AddNew
  446.                             .Fields("PurPlanSubID") = j                                                 '子表ID
  447.                             .Fields("PurPlanMainID") = rs_CreatePurBillPri.Fields("PurPlanMainID") + 0  '单据ID
  448.                             .Fields("MNumber") = Trim(rs_suppliercodet.Fields("MNumber") & "")          '物料编码
  449.                             .Fields("Quantity") = Trim(rs_suppliercodet.Fields("SumQuantity") & "")     '数量
  450.                             .Fields("ProcFactory") = Trim(rs_suppliercodet.Fields("ProcFactory"))       '生产厂家
  451.                             .Fields("Remark") = ""                                                      '备注
  452.                             .UpdateBatch
  453.                             '更新计划拆合跟踪表
  454.                             str_SQLWhereTmp = str_SQLSelectTmp & str_SQLWhereT & str_SQLGroupTmp
  455.                             Set Rs_SQLWhereTmp = Nothing
  456.                             Set Rs_SQLWhereTmp = Cw_DataEnvi.DataConnect.Execute(str_SQLWhereTmp)
  457.                             Do While Not Rs_SQLWhereTmp.EOF()
  458.                                 str_Insert = "insert into Cg_SplitUnite(SplitUniteNum,NewPurPlanMainID,NewPurPlanSubID,PurPlanMainID,PurPlanSubID)" & "values( " & Hbpc & "," & rs_CreatePurBillPri.Fields("PurPlanMainID") & " ," & rs_CreatePurBillDet.Fields("PurPlanSubID") & "," & Rs_SQLWhereTmp.Fields("PurPlanMainID") & "," & Rs_SQLWhereTmp.Fields("PurPlanSubID") & ")"
  459.                                 Cw_DataEnvi.DataConnect.Execute (str_Insert)
  460.                                 Rs_SQLWhereTmp.MoveNext
  461.                             Loop
  462.                             '更新结束
  463.                             rs_suppliercodet.MoveNext
  464.                             j = j + 1
  465.                         Loop
  466.                     End With
  467.                 End If
  468.                 rs_TempDis2.MoveNext
  469.             Loop
  470.         Case 2  '库存物料分类
  471.             '没有生产厂家的计划合并
  472.             str_SQLSelectT = "select distinct KjYear,Period,InvSortCode,ExigenceFlag from Cg_V_PlanBill "
  473.             str_SQLTempDis1 = str_SQLSelectT & str_SQLWhere & " and ProcFactory='' "
  474.             Set rs_TempDis1 = Cw_DataEnvi.DataConnect.Execute(str_SQLTempDis1)
  475.             Do While Not rs_TempDis1.EOF()
  476.                 str_SQLWhereT = ""
  477.                 If str_SQLWhere <> "" Then
  478.                     str_SQLWhereT = str_SQLWhere & " and InvSortCode = '" & Trim(rs_TempDis1.Fields("InvSortCode") & "") & "'"
  479.                 Else
  480.                     str_SQLWhereT = " where InvSortCode = '" & Trim(rs_TempDis1.Fields("InvSortCode") & "") & "'"
  481.                 End If
  482.                 str_SQLWhereT = str_SQLWhereT & " and ProcFactory='' "
  483.                 str_SQLSelectT = "select  KjYear,Period,InvSortCode,MNumber,sum(Quantity) as SumQuantity from Cg_V_PlanBill "
  484.                 str_SQLGroupT = " Group by KjYear,Period ,InvSortCode,MNumber "
  485.                 str_SQLSelectTmp = "select  PurPlanMainID,PurPlanSubID,KjYear,Period,InvSortCode,MNumber,sum(Quantity) from Cg_V_PlanBill "
  486.                 str_SQLGroupTmp = " Group by KjYear,Period ,PurPlanMainID,PurPlanSubID,InvSortCode,MNumber "
  487.                 str_SQLSupplierCodeT = str_SQLSelectT & str_SQLWhereT & str_SQLGroupT
  488.                 Set rs_suppliercodet = Nothing
  489.                 Set rs_suppliercodet = Cw_DataEnvi.DataConnect.Execute(str_SQLSupplierCodeT)
  490.                 '写记录
  491.                 If Not rs_suppliercodet.EOF() Then
  492.                     With rs_CreatePurBillPri
  493.                         .AddNew
  494.                         .Fields("PurPlanMainID") = CreatBillID("1101")                  '单据ID
  495.                         .Fields("PurPlanNum") = CreatBillCode("1101", True)             '单据号
  496.                         .Fields("PurPlanDate") = Format(Xtrq, "yyyy-mm-dd")             '计划日期
  497.                         .Fields("KjYear") = Trim(rs_TempDis1.Fields("KjYear"))          '会计年
  498.                         .Fields("Period") = Trim(rs_TempDis1.Fields("Period"))          '会计期间
  499.                         .Fields("PurPlanType") = "合并生成"                             '计划类型
  500.                         .Fields("Maker") = Xtczy                                        '制单人
  501.                         .Fields("PurPlanStyle") = "2"                                   '不能被生产系统调用
  502.                         .Fields("SplitUniteNum") = Hbpc                                 '拆合过程号
  503.                         .Fields("SplitUniteFlag") = 0                                   '拆合标志
  504.                         .Fields("ExigenceFlag") = rs_TempDis1.Fields("ExigenceFlag")    '紧急标志
  505.                         .Fields("Checker") = Xtczy                                      '审核人
  506.                         .Fields("FinishFlag") = 0                                       '完成标志
  507.                         .Fields("Transmitter") = ""                                     '下达人置空
  508.                         .UpdateBatch
  509.                     End With
  510.                     With rs_CreatePurBillDet
  511.                         j = 1
  512.                         Do While Not rs_suppliercodet.EOF()
  513.                             .AddNew
  514.                             .Fields("PurPlanSubID") = j                                                 '子表ID
  515.                             .Fields("PurPlanMainID") = rs_CreatePurBillPri.Fields("PurPlanMainID") + 0  '单据ID
  516.                             .Fields("MNumber") = Trim(rs_suppliercodet.Fields("MNumber") & "")          '物料编码
  517.                             .Fields("Quantity") = Trim(rs_suppliercodet.Fields("SumQuantity") & "")     '数量
  518.                             .Fields("ProcFactory") = ""                                                 '生产厂家
  519.                             .Fields("Remark") = ""                                                      '备注
  520.                             .UpdateBatch
  521.                             '更新计划拆合跟踪表
  522.                             str_SQLWhereTmp = str_SQLSelectTmp & str_SQLWhereT & str_SQLGroupTmp
  523.                             Set Rs_SQLWhereTmp = Nothing
  524.                             Set Rs_SQLWhereTmp = Cw_DataEnvi.DataConnect.Execute(str_SQLWhereTmp)
  525.                             Do While Not Rs_SQLWhereTmp.EOF()
  526.                                 str_Insert = "insert into Cg_SplitUnite(SplitUniteNum,NewPurPlanMainID,NewPurPlanSubID,PurPlanMainID,PurPlanSubID)" & "values( " & Hbpc & "," & rs_CreatePurBillPri.Fields("PurPlanMainID") & " ," & rs_CreatePurBillDet.Fields("PurPlanSubID") & "," & Rs_SQLWhereTmp.Fields("PurPlanMainID") & "," & Rs_SQLWhereTmp.Fields("PurPlanSubID") & ")"
  527.                                 Cw_DataEnvi.DataConnect.Execute (str_Insert)
  528.                                 Rs_SQLWhereTmp.MoveNext
  529.                             Loop
  530.                             '更新结束
  531.                             rs_suppliercodet.MoveNext
  532.                             j = j + 1
  533.                         Loop
  534.                     End With
  535.                 End If
  536.                 rs_TempDis1.MoveNext
  537.             Loop
  538.             '有生产厂家的计划合并
  539.             str_SQLSelectT = "select distinct KjYear,Period,InvSortCode,ExigenceFlag from Cg_V_PlanBill "
  540.             str_SQLTempDis2 = str_SQLSelectT & str_SQLWhere & " and ProcFactory<>'' "
  541.             Set rs_TempDis2 = Cw_DataEnvi.DataConnect.Execute(str_SQLTempDis2)
  542.             Do While Not rs_TempDis2.EOF()
  543.                 str_SQLWhereT = ""
  544.                 If str_SQLWhere <> "" Then
  545.                     str_SQLWhereT = str_SQLWhere & " and InvSortCode = '" & Trim(rs_TempDis2.Fields("InvSortCode") & "") & "'"
  546.                 Else
  547.                     str_SQLWhereT = " where InvSortCode = '" & Trim(rs_TempDis2.Fields("InvSortCode") & "") & "'"
  548.                 End If
  549.                 str_SQLWhereT = str_SQLWhereT & " and ProcFactory<>'' "
  550.                 str_SQLSelectT = "select  KjYear,Period,ProcFactory,InvSortCode,MNumber,sum(Quantity) as SumQuantity from Cg_V_PlanBill "
  551.                 str_SQLGroupT = " Group by KjYear,Period ,ProcFactory,InvSortCode,MNumber "
  552.                 str_SQLSelectTmp = "select  PurPlanMainID,PurPlanSubID,KjYear,Period,InvSortCode,MNumber,sum(Quantity),ProcFactory from Cg_V_PlanBill "
  553.                 str_SQLGroupTmp = " Group by KjYear,Period ,PurPlanMainID,PurPlanSubID,InvSortCode,MNumber,ProcFactory "
  554.                 str_SQLSupplierCodeT = str_SQLSelectT & str_SQLWhereT & str_SQLGroupT
  555.                 Set rs_suppliercodet = Nothing
  556.                 Set rs_suppliercodet = Cw_DataEnvi.DataConnect.Execute(str_SQLSupplierCodeT)
  557.                 '写记录
  558.                 If Not rs_suppliercodet.EOF() Then
  559.                     With rs_CreatePurBillPri
  560.                         .AddNew
  561.                         .Fields("PurPlanMainID") = CreatBillID("1101")                  '单据ID
  562.                         .Fields("PurPlanNum") = CreatBillCode("1101", True)             '单据号
  563.                         .Fields("PurPlanDate") = Format(Xtrq, "yyyy-mm-dd")             '计划日期
  564.                         .Fields("KjYear") = Trim(rs_TempDis2.Fields("KjYear"))          '会计年
  565.                         .Fields("Period") = Trim(rs_TempDis2.Fields("Period"))          '会计期间
  566.                         .Fields("PurPlanType") = "合并生成"                             '计划类型
  567.                         .Fields("Maker") = Xtczy                                        '制单人
  568.                         .Fields("PurPlanStyle") = "2"                                   '不能被生产系统调用
  569.                         .Fields("SplitUniteNum") = Hbpc                                 '拆合过程号
  570.                         .Fields("SplitUniteFlag") = 0                                   '拆合标志
  571.                         .Fields("ExigenceFlag") = rs_TempDis2.Fields("ExigenceFlag")    '紧急标志
  572.                         .Fields("Checker") = Xtczy                                      '审核人
  573.                         .Fields("FinishFlag") = 0                                       '完成标志
  574.                         .Fields("Transmitter") = ""                                     '下达人置空
  575.                         .UpdateBatch
  576.                     End With
  577.                     With rs_CreatePurBillDet
  578.                         j = 1
  579.                         Do While Not rs_suppliercodet.EOF()
  580.                             .AddNew
  581.                             .Fields("PurPlanSubID") = j                                                 '子表ID
  582.                             .Fields("PurPlanMainID") = rs_CreatePurBillPri.Fields("PurPlanMainID") + 0  '单据ID
  583.                             .Fields("MNumber") = Trim(rs_suppliercodet.Fields("MNumber") & "")          '物料编码
  584.                             .Fields("Quantity") = Trim(rs_suppliercodet.Fields("SumQuantity") & "")     '数量
  585.                             .Fields("ProcFactory") = Trim(rs_suppliercodet.Fields("ProcFactory"))       '生产厂家
  586.                             .Fields("Remark") = ""                                                      '备注
  587.                             .UpdateBatch
  588.                             '更新计划拆合跟踪表
  589.                             str_SQLWhereTmp = str_SQLSelectTmp & str_SQLWhereT & str_SQLGroupTmp
  590.                             Set Rs_SQLWhereTmp = Nothing
  591.                             Set Rs_SQLWhereTmp = Cw_DataEnvi.DataConnect.Execute(str_SQLWhereTmp)
  592.                             Do While Not Rs_SQLWhereTmp.EOF()
  593.                                 str_Insert = "insert into Cg_SplitUnite(SplitUniteNum,NewPurPlanMainID,NewPurPlanSubID,PurPlanMainID,PurPlanSubID)" & "values( " & Hbpc & "," & rs_CreatePurBillPri.Fields("PurPlanMainID") & " ," & rs_CreatePurBillDet.Fields("PurPlanSubID") & "," & Rs_SQLWhereTmp.Fields("PurPlanMainID") & "," & Rs_SQLWhereTmp.Fields("PurPlanSubID") & ")"
  594.                                 Cw_DataEnvi.DataConnect.Execute (str_Insert)
  595.                                 Rs_SQLWhereTmp.MoveNext
  596.                             Loop
  597.                             '更新结束
  598.                             rs_suppliercodet.MoveNext
  599.                             j = j + 1
  600.                         Loop
  601.                     End With
  602.                 End If
  603.                 rs_TempDis2.MoveNext
  604.             Loop
  605.         Case 3  '计划到货日期
  606.             str_SQLSelectT = "select distinct KjYear,Period,PlanArriveDate,ExigenceFlag from Cg_V_PlanBill "
  607.             str_SQLTempDis1 = str_SQLSelectT & str_SQLWhere & " and ProcFactory='' "
  608.             Set rs_TempDis1 = Cw_DataEnvi.DataConnect.Execute(str_SQLTempDis1)
  609.             Do While Not rs_TempDis1.EOF()
  610.                 str_SQLWhereT = ""
  611.                 If str_SQLWhere <> "" Then
  612.                     If IsNull(rs_TempDis1.Fields("PlanArriveDate")) Or Trim(rs_TempDis1.Fields("PlanArriveDate") & "") = "" Then
  613.                         str_SQLWhereT = str_SQLWhere & " and (PlanArriveDate is null  or PlanArriveDate='') "
  614.                     Else
  615.                         str_SQLWhereT = str_SQLWhere & " and PlanArriveDate = '" & Trim(rs_TempDis1.Fields("PlanArriveDate") & "") & "'"
  616.                     End If
  617.                 Else
  618.                     If IsNull(rs_TempDis1.Fields("PlanArriveDate")) Or Trim(rs_TempDis1.Fields("PlanArriveDate") & "") = "" Then
  619.                         str_SQLWhereT = " where  (PlanArriveDate is null  or PlanArriveDate='') "
  620.                     Else
  621.                         str_SQLWhereT = " where PlanArriveDate ='" & Trim(rs_TempDis1.Fields("PlanArriveDate") & "") & "'"
  622.                     End If
  623.                 End If
  624.                 str_SQLWhereT = str_SQLWhereT & " and ProcFactory=''"
  625.                 str_SQLSelectT = "select  KjYear,Period,PlanArriveDate,MNumber,sum(Quantity) as SumQuantity from Cg_V_PlanBill "
  626.                 str_SQLGroupT = " Group by KjYear,Period ,PlanArriveDate,MNumber "
  627.                 str_SQLSelectTmp = "select  PurPlanMainID,PurPlanSubID,KjYear,Period,PlanArriveDate,MNumber,sum(Quantity) from Cg_V_PlanBill "
  628.                 str_SQLGroupTmp = " Group by KjYear,Period ,PurPlanMainID,PurPlanSubID,PlanArriveDate,MNumber "
  629.                 str_SQLSupplierCodeT = str_SQLSelectT & str_SQLWhereT & str_SQLGroupT
  630.                 Set rs_suppliercodet = Nothing
  631.                 Set rs_suppliercodet = Cw_DataEnvi.DataConnect.Execute(str_SQLSupplierCodeT)
  632.                 '写记录
  633.                 If Not rs_suppliercodet.EOF() Then
  634.                     With rs_CreatePurBillPri
  635.                         .AddNew
  636.                         .Fields("PurPlanMainID") = CreatBillID("1101")                  '单据ID
  637.                         .Fields("PurPlanNum") = CreatBillCode("1101", True)             '单据号
  638.                         .Fields("PurPlanDate") = Format(Xtrq, "yyyy-mm-dd")             '计划日期
  639.                         .Fields("KjYear") = Trim(rs_TempDis1.Fields("KjYear"))          '会计年
  640.                         .Fields("Period") = Trim(rs_TempDis1.Fields("Period"))          '会计期间
  641.                         .Fields("PurPlanType") = "合并生成"                             '计划类型
  642.                         .Fields("Maker") = Xtczy                                        '制单人
  643.                         .Fields("PurPlanStyle") = "2"                                   '不能被生产系统调用
  644.                         .Fields("SplitUniteNum") = Hbpc                                 '拆合过程号
  645.                         .Fields("SplitUniteFlag") = 0                                   '拆合标志
  646.                         .Fields("ExigenceFlag") = rs_TempDis1.Fields("ExigenceFlag")    '紧急标志
  647.                         .Fields("Checker") = Xtczy                                      '审核人
  648.                         .Fields("FinishFlag") = 0                                       '完成标志
  649.                         .Fields("Transmitter") = ""                                     '下达人置空
  650.                         .UpdateBatch
  651.                     End With
  652.                     With rs_CreatePurBillDet
  653.                         j = 1
  654.                         Do While Not rs_suppliercodet.EOF()
  655.                             .AddNew
  656.                             .Fields("PurPlanSubID") = j                                                 '子表ID
  657.                             .Fields("PurPlanMainID") = rs_CreatePurBillPri.Fields("PurPlanMainID") + 0  '单据ID
  658.                             .Fields("MNumber") = Trim(rs_suppliercodet.Fields("MNumber") & "")          '物料编码
  659.                             .Fields("Quantity") = Trim(rs_suppliercodet.Fields("SumQuantity") & "")     '数量
  660.                             .Fields("ProcFactory") = ""                                                 '生产厂家
  661.                             .Fields("PlanArriveDate") = rs_TempDis1.Fields("PlanArriveDate")            '计划到货日期
  662.                             .Fields("Remark") = ""                                                      '备注
  663.                             .UpdateBatch
  664.                             '更新计划拆合跟踪表
  665.                             str_SQLWhereTmp = str_SQLSelectTmp & str_SQLWhereT & str_SQLGroupTmp
  666.                             Set Rs_SQLWhereTmp = Nothing
  667.                             Set Rs_SQLWhereTmp = Cw_DataEnvi.DataConnect.Execute(str_SQLWhereTmp)
  668.                             Do While Not Rs_SQLWhereTmp.EOF()
  669.                                 str_Insert = "insert into Cg_SplitUnite(SplitUniteNum,NewPurPlanMainID,NewPurPlanSubID,PurPlanMainID,PurPlanSubID)" & "values( " & Hbpc & "," & rs_CreatePurBillPri.Fields("PurPlanMainID") & " ," & rs_CreatePurBillDet.Fields("PurPlanSubID") & "," & Rs_SQLWhereTmp.Fields("PurPlanMainID") & "," & Rs_SQLWhereTmp.Fields("PurPlanSubID") & ")"
  670.                                 Cw_DataEnvi.DataConnect.Execute (str_Insert)
  671.                                 Rs_SQLWhereTmp.MoveNext
  672.                             Loop
  673.                             '更新结束
  674.                             rs_suppliercodet.MoveNext
  675.                             j = j + 1
  676.                         Loop
  677.                     End With
  678.                 End If
  679.                 rs_TempDis1.MoveNext
  680.             Loop
  681.             '有生产厂家的计划合并
  682.             str_SQLSelectT = "select distinct KjYear,Period,PlanArriveDate,ExigenceFlag from Cg_V_PlanBill "
  683.             str_SQLTempDis2 = str_SQLSelectT & str_SQLWhere & " and ProcFactory<>'' "
  684.             Set rs_TempDis2 = Cw_DataEnvi.DataConnect.Execute(str_SQLTempDis2)
  685.             Do While Not rs_TempDis2.EOF()
  686.                 str_SQLWhereT = ""
  687.                 If str_SQLWhere <> "" Then
  688.                     If IsNull(rs_TempDis2.Fields("PlanArriveDate")) Or Trim(rs_TempDis2.Fields("PlanArriveDate") & "") = "" Then
  689.                         str_SQLWhereT = str_SQLWhere & " and (PlanArriveDate is null  or PlanArriveDate='') "
  690.                     Else
  691.                         str_SQLWhereT = str_SQLWhere & " and PlanArriveDate = '" & Trim(rs_TempDis2.Fields("PlanArriveDate") & "") & "'"
  692.                     End If
  693.                 Else
  694.                     If IsNull(rs_TempDis2.Fields("PlanArriveDate")) Or Trim(rs_TempDis2.Fields("PlanArriveDate") & "") = "" Then
  695.                         str_SQLWhereT = " where  (PlanArriveDate is null  or PlanArriveDate='') "
  696.                     Else
  697.                         str_SQLWhereT = " where PlanArriveDate ='" & Trim(rs_TempDis2.Fields("PlanArriveDate") & "") & "'"
  698.                     End If
  699.                 End If
  700.                 str_SQLWhereT = str_SQLWhereT & " and ProcFactory<>''"
  701.                 str_SQLSelectT = "select  ProcFactory,KjYear,Period,PlanArriveDate,MNumber,sum(Quantity) as SumQuantity from Cg_V_PlanBill "
  702.                 str_SQLGroupT = " Group by ProcFactory,KjYear,Period ,PlanArriveDate,MNumber "
  703.                 str_SQLSelectTmp = "select  PurPlanMainID,PurPlanSubID,KjYear,Period,PlanArriveDate,MNumber,sum(Quantity),ProcFactory from Cg_V_PlanBill "
  704.                 str_SQLGroupTmp = " Group by KjYear,Period ,PurPlanMainID,PurPlanSubID,PlanArriveDate,MNumber,ProcFactory "
  705.                 str_SQLSupplierCodeT = str_SQLSelectT & str_SQLWhereT & str_SQLGroupT
  706.                 Set rs_suppliercodet = Nothing
  707.                 Set rs_suppliercodet = Cw_DataEnvi.DataConnect.Execute(str_SQLSupplierCodeT)
  708.                 '写记录
  709.                 If Not rs_suppliercodet.EOF() Then
  710.                     With rs_CreatePurBillPri
  711.                         .AddNew
  712.                         .Fields("PurPlanMainID") = CreatBillID("1101")                  '单据ID
  713.                         .Fields("PurPlanNum") = CreatBillCode("1101", True)             '单据号
  714.                         .Fields("PurPlanDate") = Format(Xtrq, "yyyy-mm-dd")             '计划日期
  715.                         .Fields("KjYear") = Trim(rs_TempDis2.Fields("KjYear"))          '会计年
  716.                         .Fields("Period") = Trim(rs_TempDis2.Fields("Period"))          '会计期间
  717.                         .Fields("PurPlanType") = "合并生成"                             '计划类型
  718.                         .Fields("Maker") = Xtczy                                        '制单人
  719.                         .Fields("PurPlanStyle") = "2"                                   '不能被生产系统调用
  720.                         .Fields("SplitUniteNum") = Hbpc                                 '拆合过程号
  721.                         .Fields("SplitUniteFlag") = 0                                   '拆合标志
  722.                         .Fields("ExigenceFlag") = rs_TempDis2.Fields("ExigenceFlag")    '紧急标志
  723.                         .Fields("Checker") = Xtczy                                      '审核人
  724.                         .Fields("FinishFlag") = 0                                       '完成标志
  725.                         .Fields("Transmitter") = ""                                     '下达人置空
  726.                         .UpdateBatch
  727.                     End With
  728.                     With rs_CreatePurBillDet
  729.                         j = 1
  730.                         Do While Not rs_suppliercodet.EOF()
  731.                             .AddNew
  732.                             .Fields("PurPlanSubID") = j                                                 '子表ID
  733.                             .Fields("PurPlanMainID") = rs_CreatePurBillPri.Fields("PurPlanMainID") + 0  '单据ID
  734.                             .Fields("MNumber") = Trim(rs_suppliercodet.Fields("MNumber") & "")          '物料编码
  735.                             .Fields("Quantity") = Trim(rs_suppliercodet.Fields("SumQuantity") & "")     '数量
  736.                             .Fields("ProcFactory") = Trim(rs_suppliercodet.Fields("ProcFactory"))       '生产厂家
  737.                             .Fields("PlanArriveDate") = rs_TempDis2.Fields("PlanArriveDate")            '计划到货日期
  738.                             .Fields("Remark") = ""                                                      '备注
  739.                             .UpdateBatch
  740.                             '更新计划拆合跟踪表
  741.                             str_SQLWhereTmp = str_SQLSelectTmp & str_SQLWhereT & str_SQLGroupTmp
  742.                             Set Rs_SQLWhereTmp = Nothing
  743.                             Set Rs_SQLWhereTmp = Cw_DataEnvi.DataConnect.Execute(str_SQLWhereTmp)
  744.                             Do While Not Rs_SQLWhereTmp.EOF()
  745.                                 str_Insert = "insert into Cg_SplitUnite(SplitUniteNum,NewPurPlanMainID,NewPurPlanSubID,PurPlanMainID,PurPlanSubID)" & "values( " & Hbpc & "," & rs_CreatePurBillPri.Fields("PurPlanMainID") & " ," & rs_CreatePurBillDet.Fields("PurPlanSubID") & "," & Rs_SQLWhereTmp.Fields("PurPlanMainID") & "," & Rs_SQLWhereTmp.Fields("PurPlanSubID") & ")"
  746.                                 Cw_DataEnvi.DataConnect.Execute (str_Insert)
  747.                                 Rs_SQLWhereTmp.MoveNext
  748.                             Loop
  749.                             '更新结束
  750.                             rs_suppliercodet.MoveNext
  751.                             j = j + 1
  752.                         Loop
  753.                     End With
  754.                 End If
  755.                 rs_TempDis2.MoveNext
  756.             Loop
  757.         Case 4  '计划日期
  758.             str_SQLSelectT = "select distinct KjYear,Period,PurPlanDate,ExigenceFlag from Cg_V_PlanBill "
  759.             str_SQLTempDis1 = str_SQLSelectT & str_SQLWhere & " and ProcFactory='' "
  760.             Set rs_TempDis1 = Cw_DataEnvi.DataConnect.Execute(str_SQLTempDis1)
  761.             Do While Not rs_TempDis1.EOF()
  762.                 str_SQLWhereT = ""
  763.                 If str_SQLWhere <> "" Then
  764.                     If IsNull(rs_TempDis1.Fields("PurPlanDate")) Or Trim(rs_TempDis1.Fields("PurPlanDate") & "") = "" Then
  765.                         str_SQLWhereT = str_SQLWhere & " and (PurPlanDate is null  or PurPlanDate='') "
  766.                     Else
  767.                         str_SQLWhereT = str_SQLWhere & " and PurPlanDate = '" & Trim(rs_TempDis1.Fields("PurPlanDate") & "") & "'"
  768.                     End If
  769.                 Else
  770.                     If IsNull(rs_TempDis1.Fields("PurPlanDate")) Or Trim(rs_TempDis1.Fields("PurPlanDate") & "") = "" Then
  771.                         str_SQLWhereT = " where  (PurPlanDate is null  or PurPlanDate='') "
  772.                     Else
  773.                         str_SQLWhereT = " where PurPlanDate ='" & Trim(rs_TempDis1.Fields("PurPlanDate") & "") & "'"
  774.                     End If
  775.                 End If
  776.                 str_SQLWhereT = str_SQLWhereT & " and ProcFactory=''"
  777.                 str_SQLSelectT = "select  KjYear,Period,PurPlanDate,MNumber,sum(Quantity) as SumQuantity from Cg_V_PlanBill "
  778.                 str_SQLGroupT = " Group by KjYear,Period ,PurPlanDate,MNumber "
  779.                 str_SQLSelectTmp = "select  PurPlanMainID,PurPlanSubID,KjYear,Period,PlanArriveDate,MNumber,sum(Quantity) from Cg_V_PlanBill "
  780.                 str_SQLGroupTmp = " Group by KjYear,Period ,PurPlanMainID,PurPlanSubID,PlanArriveDate,MNumber "
  781.                 str_SQLSupplierCodeT = str_SQLSelectT & str_SQLWhereT & str_SQLGroupT
  782.                 Set rs_suppliercodet = Nothing
  783.                 Set rs_suppliercodet = Cw_DataEnvi.DataConnect.Execute(str_SQLSupplierCodeT)
  784.                 '写记录
  785.                 If Not rs_suppliercodet.EOF() Then
  786.                     With rs_CreatePurBillPri
  787.                         .AddNew
  788.                         .Fields("PurPlanMainID") = CreatBillID("1101")                  '单据ID
  789.                         .Fields("PurPlanNum") = CreatBillCode("1101", True)             '单据号
  790.                         .Fields("PurPlanDate") = rs_TempDis1.Fields("PurPlanDate")      '计划日期
  791.                         .Fields("KjYear") = Trim(rs_TempDis1.Fields("KjYear"))          '会计年
  792.                         .Fields("Period") = Trim(rs_TempDis1.Fields("Period"))          '会计期间
  793.                         .Fields("PurPlanType") = "合并生成"                             '计划类型
  794.                         .Fields("Maker") = Xtczy                                        '制单人
  795.                         .Fields("PurPlanStyle") = "2"                                   '不能被生产系统调用
  796.                         .Fields("SplitUniteNum") = Hbpc                                 '拆合过程号
  797.                         .Fields("SplitUniteFlag") = 0                                   '拆合标志
  798.                         .Fields("ExigenceFlag") = rs_TempDis1.Fields("ExigenceFlag")    '紧急标志
  799.                         .Fields("Checker") = Xtczy                                      '审核人
  800.                         .Fields("FinishFlag") = 0                                       '完成标志
  801.                         .Fields("Transmitter") = ""                                     '下达人置空
  802.                         .UpdateBatch
  803.                     End With
  804.                     With rs_CreatePurBillDet
  805.                         j = 1
  806.                         Do While Not rs_suppliercodet.EOF()
  807.                             .AddNew
  808.                             .Fields("PurPlanSubID") = j                                                 '子表ID
  809.                             .Fields("PurPlanMainID") = rs_CreatePurBillPri.Fields("PurPlanMainID") + 0  '单据ID
  810.                             .Fields("MNumber") = Trim(rs_suppliercodet.Fields("MNumber") & "")          '物料编码
  811.                             .Fields("Quantity") = Trim(rs_suppliercodet.Fields("SumQuantity") & "")     '数量
  812.                             .Fields("ProcFactory") = ""                                                 '生产厂家
  813.                             .Fields("Remark") = ""                                                      '备注
  814.                             .UpdateBatch
  815.                             '更新计划拆合跟踪表
  816.                             str_SQLWhereTmp = str_SQLSelectTmp & str_SQLWhereT & str_SQLGroupTmp
  817.                             Set Rs_SQLWhereTmp = Nothing
  818.                             Set Rs_SQLWhereTmp = Cw_DataEnvi.DataConnect.Execute(str_SQLWhereTmp)
  819.                             Do While Not Rs_SQLWhereTmp.EOF()
  820.                                 str_Insert = "insert into Cg_SplitUnite(SplitUniteNum,NewPurPlanMainID,NewPurPlanSubID,PurPlanMainID,PurPlanSubID)" & "values( " & Hbpc & "," & rs_CreatePurBillPri.Fields("PurPlanMainID") & " ," & rs_CreatePurBillDet.Fields("PurPlanSubID") & "," & Rs_SQLWhereTmp.Fields("PurPlanMainID") & "," & Rs_SQLWhereTmp.Fields("PurPlanSubID") & ")"
  821.                                 Cw_DataEnvi.DataConnect.Execute (str_Insert)
  822.                                 Rs_SQLWhereTmp.MoveNext
  823.                             Loop
  824.                             '更新结束
  825.                             rs_suppliercodet.MoveNext
  826.                             j = j + 1
  827.                         Loop
  828.                     End With
  829.                 End If
  830.                 rs_TempDis1.MoveNext
  831.             Loop
  832.             '有生产厂家的计划合并
  833.             str_SQLSelectT = "select distinct KjYear,Period,PurPlanDate,ExigenceFlag from Cg_V_PlanBill "
  834.             str_SQLTempDis2 = str_SQLSelectT & str_SQLWhere & " and ProcFactory<>'' "
  835.             Set rs_TempDis2 = Cw_DataEnvi.DataConnect.Execute(str_SQLTempDis2)
  836.             Do While Not rs_TempDis2.EOF()
  837.                 str_SQLWhereT = ""
  838.                 If str_SQLWhere <> "" Then
  839.                     If IsNull(rs_TempDis2.Fields("PurPlanDate")) Or Trim(rs_TempDis2.Fields("PurPlanDate") & "") = "" Then
  840.                         str_SQLWhereT = str_SQLWhere & " and (PurPlanDate is null  or PurPlanDate='') "
  841.                     Else
  842.                         str_SQLWhereT = str_SQLWhere & " and PurPlanDate = '" & Trim(rs_TempDis2.Fields("PurPlanDate") & "") & "'"
  843.                     End If
  844.                 Else
  845.                     If IsNull(rs_TempDis2.Fields("PurPlanDate")) Or Trim(rs_TempDis2.Fields("PurPlanDate") & "") = "" Then
  846.                         str_SQLWhereT = " where  (PurPlanDate is null  or PurPlanDate='') "
  847.                     Else
  848.                         str_SQLWhereT = " where PurPlanDate ='" & Trim(rs_TempDis2.Fields("PurPlanDate") & "") & "'"
  849.                     End If
  850.                 End If
  851.                 str_SQLWhereT = str_SQLWhereT & " and ProcFactory<>''"
  852.                 str_SQLSelectT = "select  ProcFactory,KjYear,Period,PurPlanDate,MNumber,sum(Quantity) as SumQuantity from Cg_V_PlanBill "
  853.                 str_SQLGroupT = " Group by ProcFactory,KjYear,Period ,PurPlanDate,MNumber "
  854.                 str_SQLSelectTmp = "select  PurPlanMainID,PurPlanSubID,KjYear,Period,PurPlanDate,MNumber,sum(Quantity),ProcFactory from Cg_V_PlanBill "
  855.                 str_SQLGroupTmp = " Group by KjYear,Period ,PurPlanMainID,PurPlanSubID,PurPlanDate,MNumber,ProcFactory "
  856.                 str_SQLSupplierCodeT = str_SQLSelectT & str_SQLWhereT & str_SQLGroupT
  857.                 Set rs_suppliercodet = Nothing
  858.                 Set rs_suppliercodet = Cw_DataEnvi.DataConnect.Execute(str_SQLSupplierCodeT)
  859.                 '写记录
  860.                 If Not rs_suppliercodet.EOF() Then
  861.                     With rs_CreatePurBillPri
  862.                         .AddNew
  863.                         .Fields("PurPlanMainID") = CreatBillID("1101")                  '单据ID
  864.                         .Fields("PurPlanNum") = CreatBillCode("1101", True)             '单据号
  865.                         .Fields("PurPlanDate") = rs_TempDis2.Fields("PurPlanDate")      '计划日期
  866.                         .Fields("KjYear") = Trim(rs_TempDis2.Fields("KjYear"))          '会计年
  867.                         .Fields("Period") = Trim(rs_TempDis2.Fields("Period"))          '会计期间
  868.                         .Fields("PurPlanType") = "合并生成"                             '计划类型
  869.                         .Fields("Maker") = Xtczy                                        '制单人
  870.                         .Fields("PurPlanStyle") = "2"                                   '不能被生产系统调用
  871.                         .Fields("SplitUniteNum") = Hbpc                                 '拆合过程号
  872.                         .Fields("SplitUniteFlag") = 0                                   '拆合标志
  873.                         .Fields("ExigenceFlag") = rs_TempDis2.Fields("ExigenceFlag")    '紧急标志
  874.                         .Fields("Checker") = Xtczy                                      '审核人
  875.                         .Fields("FinishFlag") = 0                                       '完成标志
  876.                         .Fields("Transmitter") = ""                                     '下达人置空
  877.                         .UpdateBatch
  878.                     End With
  879.                     With rs_CreatePurBillDet
  880.                         j = 1
  881.                         Do While Not rs_suppliercodet.EOF()
  882.                             .AddNew
  883.                             .Fields("PurPlanSubID") = j                                                 '子表ID
  884.                             .Fields("PurPlanMainID") = rs_CreatePurBillPri.Fields("PurPlanMainID") + 0  '单据ID
  885.                             .Fields("MNumber") = Trim(rs_suppliercodet.Fields("MNumber") & "")          '物料编码
  886.                             .Fields("Quantity") = Trim(rs_suppliercodet.Fields("SumQuantity") & "")     '数量
  887.                             .Fields("ProcFactory") = Trim(rs_suppliercodet.Fields("ProcFactory"))       '生产厂家
  888.                             .Fields("Remark") = ""                                                      '备注
  889.                             .UpdateBatch
  890.                             '更新计划拆合跟踪表
  891.                             str_SQLWhereTmp = str_SQLSelectTmp & str_SQLWhereT & str_SQLGroupTmp
  892.                             Set Rs_SQLWhereTmp = Nothing
  893.                             Set Rs_SQLWhereTmp = Cw_DataEnvi.DataConnect.Execute(str_SQLWhereTmp)
  894.                             Do While Not Rs_SQLWhereTmp.EOF()
  895.                                 str_Insert = "insert into Cg_SplitUnite(SplitUniteNum,NewPurPlanMainID,NewPurPlanSubID,PurPlanMainID,PurPlanSubID)" & "values( " & Hbpc & "," & rs_CreatePurBillPri.Fields("PurPlanMainID") & " ," & rs_CreatePurBillDet.Fields("PurPlanSubID") & "," & Rs_SQLWhereTmp.Fields("PurPlanMainID") & "," & Rs_SQLWhereTmp.Fields("PurPlanSubID") & ")"
  896.                                 Cw_DataEnvi.DataConnect.Execute (str_Insert)
  897.                                 Rs_SQLWhereTmp.MoveNext
  898.                             Loop
  899.                             '更新结束
  900.                             rs_suppliercodet.MoveNext
  901.                             j = j + 1
  902.                         Loop
  903.                     End With
  904.                 End If
  905.                 rs_TempDis2.MoveNext
  906.             Loop
  907.         Case 5  '供应商
  908.             str_SQLSelectT = "select distinct KjYear,Period,SupplierCode,ExigenceFlag from Cg_V_PlanBill "
  909.             str_SQLTempDis1 = str_SQLSelectT & str_SQLWhere & " and ProcFactory='' "
  910.             Set rs_TempDis1 = Cw_DataEnvi.DataConnect.Execute(str_SQLTempDis1)
  911.             Do While Not rs_TempDis1.EOF()
  912.                 str_SQLWhereT = ""
  913.                 If str_SQLWhere <> "" Then
  914.                     If IsNull(rs_TempDis1.Fields("SupplierCode")) Or Trim(rs_TempDis1.Fields("SupplierCode") & "") = "" Then
  915.                         str_SQLWhereT = str_SQLWhere & " and (SupplierCode is null  or SupplierCode='') "
  916.                     Else
  917.                         str_SQLWhereT = str_SQLWhere & " and SupplierCode = '" & Trim(rs_TempDis1.Fields("SupplierCode") & "") & "'"
  918.                     End If
  919.                 Else
  920.                     If IsNull(rs_TempDis1.Fields("SupplierCode")) Or Trim(rs_TempDis1.Fields("SupplierCode") & "") = "" Then
  921.                         str_SQLWhereT = " where  (SupplierCode is null  or SupplierCode='') "
  922.                     Else
  923.                         str_SQLWhereT = " where SupplierCode ='" & Trim(rs_TempDis1.Fields("SupplierCode") & "") & "'"
  924.                     End If
  925.                 End If
  926.                 str_SQLWhereT = str_SQLWhereT & " and ProcFactory=''"
  927.                 str_SQLSelectT = "select  KjYear,Period,SupplierCode,MNumber,sum(Quantity) as SumQuantity from Cg_V_PlanBill "
  928.                 str_SQLGroupT = " Group by KjYear,Period ,SupplierCode,MNumber "
  929.                 str_SQLSelectTmp = "select  PurPlanMainID,PurPlanSubID,KjYear,Period,SupplierCode,MNumber,sum(Quantity) from Cg_V_PlanBill "
  930.                 str_SQLGroupTmp = " Group by KjYear,Period ,PurPlanMainID,PurPlanSubID,SupplierCode,MNumber "
  931.                 str_SQLSupplierCodeT = str_SQLSelectT & str_SQLWhereT & str_SQLGroupT
  932.                 Set rs_suppliercodet = Nothing
  933.                 Set rs_suppliercodet = Cw_DataEnvi.DataConnect.Execute(str_SQLSupplierCodeT)
  934.                 '写记录
  935.                 If Not rs_suppliercodet.EOF() Then
  936.                     With rs_CreatePurBillPri
  937.                         .AddNew
  938.                         .Fields("PurPlanMainID") = CreatBillID("1101")                  '单据ID
  939.                         .Fields("PurPlanNum") = CreatBillCode("1101", True)             '单据号
  940.                         .Fields("PurPlanDate") = Format(Xtrq, "yyyy-mm-dd")             '计划日期
  941.                         .Fields("KjYear") = Trim(rs_TempDis1.Fields("KjYear"))          '会计年
  942.                         .Fields("Period") = Trim(rs_TempDis1.Fields("Period"))          '会计期间
  943.                         .Fields("SupplierCode") = rs_TempDis1.Fields("SupplierCode")    '供应商
  944.                         .Fields("PurPlanType") = "合并生成"                             '计划类型
  945.                         .Fields("Maker") = Xtczy                                        '制单人
  946.                         .Fields("PurPlanStyle") = "2"                                   '不能被生产系统调用
  947.                         .Fields("SplitUniteNum") = Hbpc                                 '拆合过程号
  948.                         .Fields("SplitUniteFlag") = 0                                   '拆合标志
  949.                         .Fields("ExigenceFlag") = rs_TempDis1.Fields("ExigenceFlag")    '紧急标志
  950.                         .Fields("Checker") = Xtczy                                      '审核人
  951.                         .Fields("FinishFlag") = 0                                       '完成标志
  952.                         .Fields("Transmitter") = ""                                     '下达人置空
  953.                         .UpdateBatch
  954.                     End With
  955.                     With rs_CreatePurBillDet
  956.                         j = 1
  957.                         Do While Not rs_suppliercodet.EOF()
  958.                             .AddNew
  959.                             .Fields("PurPlanSubID") = j                                                 '子表ID
  960.                             .Fields("PurPlanMainID") = rs_CreatePurBillPri.Fields("PurPlanMainID") + 0  '单据ID
  961.                             .Fields("MNumber") = Trim(rs_suppliercodet.Fields("MNumber") & "")          '物料编码
  962.                             .Fields("Quantity") = Trim(rs_suppliercodet.Fields("SumQuantity") & "")     '数量
  963.                             .Fields("ProcFactory") = ""                                                 '生产厂家
  964.                             .Fields("Remark") = ""                                                      '备注
  965.                             .UpdateBatch
  966.                             '更新计划拆合跟踪表
  967.                             str_SQLWhereTmp = str_SQLSelectTmp & str_SQLWhereT & str_SQLGroupTmp
  968.                             Set Rs_SQLWhereTmp = Nothing
  969.                             Set Rs_SQLWhereTmp = Cw_DataEnvi.DataConnect.Execute(str_SQLWhereTmp)
  970.                             Do While Not Rs_SQLWhereTmp.EOF()
  971.                                 str_Insert = "insert into Cg_SplitUnite(SplitUniteNum,NewPurPlanMainID,NewPurPlanSubID,PurPlanMainID,PurPlanSubID)" & "values( " & Hbpc & "," & rs_CreatePurBillPri.Fields("PurPlanMainID") & " ," & rs_CreatePurBillDet.Fields("PurPlanSubID") & "," & Rs_SQLWhereTmp.Fields("PurPlanMainID") & "," & Rs_SQLWhereTmp.Fields("PurPlanSubID") & ")"
  972.                                 Cw_DataEnvi.DataConnect.Execute (str_Insert)
  973.                                 Rs_SQLWhereTmp.MoveNext
  974.                             Loop
  975.                             '更新结束
  976.                             rs_suppliercodet.MoveNext
  977.                             j = j + 1
  978.                         Loop
  979.                     End With
  980.                 End If
  981.                 rs_TempDis1.MoveNext
  982.             Loop
  983.             '有生产厂家的计划合并
  984.             str_SQLSelectT = "select distinct KjYear,Period,SupplierCode,ExigenceFlag from Cg_V_PlanBill "
  985.             str_SQLTempDis2 = str_SQLSelectT & str_SQLWhere & " and ProcFactory<>'' "
  986.             Set rs_TempDis2 = Cw_DataEnvi.DataConnect.Execute(str_SQLTempDis2)
  987.             Do While Not rs_TempDis2.EOF()
  988.                 str_SQLWhereT = ""
  989.                 If str_SQLWhere <> "" Then
  990.                     If IsNull(rs_TempDis2.Fields("SupplierCode")) Or Trim(rs_TempDis2.Fields("SupplierCode") & "") = "" Then
  991.                         str_SQLWhereT = str_SQLWhere & " and (SupplierCode is null  or SupplierCode='') "
  992.                     Else
  993.                         str_SQLWhereT = str_SQLWhere & " and SupplierCode = '" & Trim(rs_TempDis2.Fields("SupplierCode") & "") & "'"
  994.                     End If
  995.                 Else
  996.                     If IsNull(rs_TempDis2.Fields("SupplierCode")) Or Trim(rs_TempDis2.Fields("SupplierCode") & "") = "" Then
  997.                         str_SQLWhereT = " where  (SupplierCode is null  or SupplierCode='') "
  998.                     Else
  999.                         str_SQLWhereT = " where SupplierCode ='" & Trim(rs_TempDis2.Fields("SupplierCode") & "") & "'"
  1000.                     End If
  1001.                 End If
  1002.                 str_SQLWhereT = str_SQLWhereT & " and ProcFactory<>''"
  1003.                 str_SQLSelectT = "select  ProcFactory,KjYear,Period,SupplierCode,MNumber,sum(Quantity) as SumQuantity from Cg_V_PlanBill "
  1004.                 str_SQLGroupT = " Group by ProcFactory,KjYear,Period ,SupplierCode,MNumber "
  1005.                 str_SQLSelectTmp = "select  PurPlanMainID,PurPlanSubID,KjYear,Period,SupplierCode,MNumber,sum(Quantity),ProcFactory from Cg_V_PlanBill "
  1006.                 str_SQLGroupTmp = " Group by KjYear,Period ,PurPlanMainID,PurPlanSubID,SupplierCode,MNumber,ProcFactory "
  1007.                 str_SQLSupplierCodeT = str_SQLSelectT & str_SQLWhereT & str_SQLGroupT
  1008.                 Set rs_suppliercodet = Nothing
  1009.                 Set rs_suppliercodet = Cw_DataEnvi.DataConnect.Execute(str_SQLSupplierCodeT)
  1010.                 '写记录
  1011.                 If Not rs_suppliercodet.EOF() Then
  1012.                     With rs_CreatePurBillPri
  1013.                         .AddNew
  1014.                         .Fields("PurPlanMainID") = CreatBillID("1101")                  '单据ID
  1015.                         .Fields("PurPlanNum") = CreatBillCode("1101", True)             '单据号
  1016.                         .Fields("PurPlanDate") = Format(Xtrq, "yyyy-mm-dd")             '计划日期
  1017.                         .Fields("KjYear") = Trim(rs_TempDis2.Fields("KjYear"))          '会计年
  1018.                         .Fields("Period") = Trim(rs_TempDis2.Fields("Period"))          '会计期间
  1019.                         .Fields("SupplierCode") = rs_TempDis2.Fields("SupplierCode")    '供应商
  1020.                         .Fields("PurPlanType") = "合并生成"                             '计划类型
  1021.                         .Fields("Maker") = Xtczy                                        '制单人
  1022.                         .Fields("PurPlanStyle") = "2"                                   '不能被生产系统调用
  1023.                         .Fields("SplitUniteNum") = Hbpc                                 '拆合过程号
  1024.                         .Fields("SplitUniteFlag") = 0                                   '拆合标志
  1025.                         .Fields("ExigenceFlag") = rs_TempDis2.Fields("ExigenceFlag")    '紧急标志
  1026.                         .Fields("Checker") = Xtczy                                      '审核人
  1027.                         .Fields("FinishFlag") = 0                                       '完成标志
  1028.                         .Fields("Transmitter") = ""                                     '下达人置空
  1029.                         .UpdateBatch
  1030.                     End With
  1031.                     With rs_CreatePurBillDet
  1032.                         j = 1
  1033.                         Do While Not rs_suppliercodet.EOF()
  1034.                             .AddNew
  1035.                             .Fields("PurPlanSubID") = j                                                 '子表ID
  1036.                             .Fields("PurPlanMainID") = rs_CreatePurBillPri.Fields("PurPlanMainID") + 0  '单据ID
  1037.                             .Fields("MNumber") = Trim(rs_suppliercodet.Fields("MNumber") & "")          '物料编码
  1038.                             .Fields("Quantity") = Trim(rs_suppliercodet.Fields("SumQuantity") & "")     '数量
  1039.                             .Fields("ProcFactory") = Trim(rs_suppliercodet.Fields("ProcFactory"))       '生产厂家
  1040.                             .Fields("Remark") = ""                                                      '备注
  1041.                             .UpdateBatch
  1042.                             '更新计划拆合跟踪表
  1043.                             str_SQLWhereTmp = str_SQLSelectTmp & str_SQLWhereT & str_SQLGroupTmp
  1044.                             Set Rs_SQLWhereTmp = Nothing
  1045.                             Set Rs_SQLWhereTmp = Cw_DataEnvi.DataConnect.Execute(str_SQLWhereTmp)
  1046.                             Do While Not Rs_SQLWhereTmp.EOF()
  1047.                                 str_Insert = "insert into Cg_SplitUnite(SplitUniteNum,NewPurPlanMainID,NewPurPlanSubID,PurPlanMainID,PurPlanSubID)" & "values( " & Hbpc & "," & rs_CreatePurBillPri.Fields("PurPlanMainID") & " ," & rs_CreatePurBillDet.Fields("PurPlanSubID") & "," & Rs_SQLWhereTmp.Fields("PurPlanMainID") & "," & Rs_SQLWhereTmp.Fields("PurPlanSubID") & ")"
  1048.                                 Cw_DataEnvi.DataConnect.Execute (str_Insert)
  1049.                                 Rs_SQLWhereTmp.MoveNext
  1050.                             Loop
  1051.                             '更新结束
  1052.                             rs_suppliercodet.MoveNext
  1053.                             j = j + 1
  1054.                         Loop
  1055.                     End With
  1056.                 End If
  1057.                 rs_TempDis2.MoveNext
  1058.             Loop
  1059.         Case 6   '物料编码
  1060.             str_SQLSelectT = "select distinct KjYear,Period,MNumber,ExigenceFlag from Cg_V_PlanBill "
  1061.             str_SQLTempDis1 = str_SQLSelectT & str_SQLWhere & " and ProcFactory='' "
  1062.             Set rs_TempDis1 = Cw_DataEnvi.DataConnect.Execute(str_SQLTempDis1)
  1063.             Do While Not rs_TempDis1.EOF()
  1064.                 str_SQLWhereT = ""
  1065.                 If str_SQLWhere <> "" Then
  1066.                     str_SQLWhereT = str_SQLWhere & " and MNumber = '" & Trim(rs_TempDis1.Fields("MNumber") & "") & "'"
  1067.                 Else
  1068.                     str_SQLWhereT = " where MNumber ='" & Trim(rs_TempDis1.Fields("MNumber") & "") & "'"
  1069.                 End If
  1070.                 str_SQLWhereT = str_SQLWhereT & " and ProcFactory=''"
  1071.                 str_SQLSelectT = "select  KjYear,Period,MNumber,sum(Quantity) as SumQuantity from Cg_V_PlanBill "
  1072.                 str_SQLGroupT = " Group by KjYear,Period ,MNumber "
  1073.                 str_SQLSelectTmp = "select  PurPlanMainID,PurPlanSubID,KjYear,Period,MNumber,sum(Quantity) from Cg_V_PlanBill "
  1074.                 str_SQLGroupTmp = " Group by KjYear,Period ,PurPlanMainID,PurPlanSubID,MNumber "
  1075.                 str_SQLSupplierCodeT = str_SQLSelectT & str_SQLWhereT & str_SQLGroupT
  1076.                 Set rs_suppliercodet = Nothing
  1077.                 Set rs_suppliercodet = Cw_DataEnvi.DataConnect.Execute(str_SQLSupplierCodeT)
  1078.                 '写记录
  1079.                 If Not rs_suppliercodet.EOF() Then
  1080.                     With rs_CreatePurBillPri
  1081.                         .AddNew
  1082.                         .Fields("PurPlanMainID") = CreatBillID("1101")                  '单据ID
  1083.                         .Fields("PurPlanNum") = CreatBillCode("1101", True)             '单据号
  1084.                         .Fields("PurPlanDate") = Format(Xtrq, "yyyy-mm-dd")             '计划日期
  1085.                         .Fields("KjYear") = Trim(rs_TempDis1.Fields("KjYear"))          '会计年
  1086.                         .Fields("Period") = Trim(rs_TempDis1.Fields("Period"))          '会计期间
  1087.                         .Fields("PurPlanType") = "合并生成"                             '计划类型
  1088.                         .Fields("Maker") = Xtczy                                        '制单人
  1089.                         .Fields("PurPlanStyle") = "2"                                   '不能被生产系统调用
  1090.                         .Fields("SplitUniteNum") = Hbpc                                 '拆合过程号
  1091.                         .Fields("SplitUniteFlag") = 0                                   '拆合标志
  1092.                         .Fields("ExigenceFlag") = rs_TempDis1.Fields("ExigenceFlag")    '紧急标志
  1093.                         .Fields("Checker") = Xtczy                                      '审核人
  1094.                         .Fields("FinishFlag") = 0                                       '完成标志
  1095.                         .Fields("Transmitter") = ""                                     '下达人置空
  1096.                         .UpdateBatch
  1097.                     End With
  1098.                     With rs_CreatePurBillDet
  1099.                         j = 1
  1100.                         Do While Not rs_suppliercodet.EOF()
  1101.                             .AddNew
  1102.                             .Fields("PurPlanSubID") = j                                                 '子表ID
  1103.                             .Fields("PurPlanMainID") = rs_CreatePurBillPri.Fields("PurPlanMainID") + 0  '单据ID
  1104.                             .Fields("MNumber") = Trim(rs_suppliercodet.Fields("MNumber") & "")          '物料编码
  1105.                             .Fields("Quantity") = Trim(rs_suppliercodet.Fields("SumQuantity") & "")     '数量
  1106.                             .Fields("ProcFactory") = ""                                                 '生产厂家
  1107.                             .Fields("Remark") = ""                                                      '备注
  1108.                             .UpdateBatch
  1109.                             '更新计划拆合跟踪表
  1110.                             str_SQLWhereTmp = str_SQLSelectTmp & str_SQLWhereT & str_SQLGroupTmp
  1111.                             Set Rs_SQLWhereTmp = Nothing
  1112.                             Set Rs_SQLWhereTmp = Cw_DataEnvi.DataConnect.Execute(str_SQLWhereTmp)
  1113.                             Do While Not Rs_SQLWhereTmp.EOF()
  1114.                                 str_Insert = "insert into Cg_SplitUnite(SplitUniteNum,NewPurPlanMainID,NewPurPlanSubID,PurPlanMainID,PurPlanSubID)" & "values( " & Hbpc & "," & rs_CreatePurBillPri.Fields("PurPlanMainID") & " ," & rs_CreatePurBillDet.Fields("PurPlanSubID") & "," & Rs_SQLWhereTmp.Fields("PurPlanMainID") & "," & Rs_SQLWhereTmp.Fields("PurPlanSubID") & ")"
  1115.                                 Cw_DataEnvi.DataConnect.Execute (str_Insert)
  1116.                                 Rs_SQLWhereTmp.MoveNext
  1117.                             Loop
  1118.                             '更新结束
  1119.                             rs_suppliercodet.MoveNext
  1120.                             j = j + 1
  1121.                         Loop
  1122.                     End With
  1123.                 End If
  1124.                 rs_TempDis1.MoveNext
  1125.             Loop
  1126.             '有生产厂家的计划合并
  1127.             str_SQLSelectT = "select distinct KjYear,Period,MNumber,ExigenceFlag from Cg_V_PlanBill "
  1128.             str_SQLTempDis2 = str_SQLSelectT & str_SQLWhere & " and ProcFactory<>'' "
  1129.             Set rs_TempDis2 = Cw_DataEnvi.DataConnect.Execute(str_SQLTempDis2)
  1130.             Do While Not rs_TempDis2.EOF()
  1131.                 str_SQLWhereT = ""
  1132.                 If str_SQLWhere <> "" Then
  1133.                     str_SQLWhereT = str_SQLWhere & " and MNumber = '" & Trim(rs_TempDis2.Fields("MNumber") & "") & "'"
  1134.                 Else
  1135.                     str_SQLWhereT = " where MNumber ='" & Trim(rs_TempDis2.Fields("MNumber") & "") & "'"
  1136.                 End If
  1137.                 str_SQLWhereT = str_SQLWhereT & " and ProcFactory<>''"
  1138.                 str_SQLSelectT = "select  ProcFactory,KjYear,Period,MNumber,sum(Quantity) as SumQuantity from Cg_V_PlanBill "
  1139.                 str_SQLGroupT = " Group by ProcFactory,KjYear,Period ,MNumber "
  1140.                 str_SQLSelectTmp = "select  PurPlanMainID,PurPlanSubID,KjYear,Period,MNumber,sum(Quantity),ProcFactory from Cg_V_PlanBill "
  1141.                 str_SQLGroupTmp = " Group by KjYear,Period ,PurPlanMainID,PurPlanSubID,MNumber,ProcFactory "
  1142.                 str_SQLSupplierCodeT = str_SQLSelectT & str_SQLWhereT & str_SQLGroupT
  1143.                 Set rs_suppliercodet = Nothing
  1144.                 Set rs_suppliercodet = Cw_DataEnvi.DataConnect.Execute(str_SQLSupplierCodeT)
  1145.                 '写记录
  1146.                 If Not rs_suppliercodet.EOF() Then
  1147.                     With rs_CreatePurBillPri
  1148.                         .AddNew
  1149.                         .Fields("PurPlanMainID") = CreatBillID("1101")                  '单据ID
  1150.                         .Fields("PurPlanNum") = CreatBillCode("1101", True)             '单据号
  1151.                         .Fields("PurPlanDate") = Format(Xtrq, "yyyy-mm-dd")             '计划日期
  1152.                         .Fields("KjYear") = Trim(rs_TempDis2.Fields("KjYear"))          '会计年
  1153.                         .Fields("Period") = Trim(rs_TempDis2.Fields("Period"))          '会计期间
  1154.                         .Fields("PurPlanType") = "合并生成"                             '计划类型
  1155.                         .Fields("Maker") = Xtczy                                        '制单人
  1156.                         .Fields("PurPlanStyle") = "2"                                   '不能被生产系统调用
  1157.                         .Fields("SplitUniteNum") = Hbpc                                 '拆合过程号
  1158.                         .Fields("SplitUniteFlag") = 0                                   '拆合标志
  1159.                         .Fields("ExigenceFlag") = rs_TempDis2.Fields("ExigenceFlag")    '紧急标志
  1160.                         .Fields("Checker") = Xtczy                                      '审核人
  1161.                         .Fields("FinishFlag") = 0                                       '完成标志
  1162.                         .Fields("Transmitter") = ""                                     '下达人置空
  1163.                         .UpdateBatch
  1164.                     End With
  1165.                     With rs_CreatePurBillDet
  1166.                         j = 1
  1167.                         Do While Not rs_suppliercodet.EOF()
  1168.                             .AddNew
  1169.                             .Fields("PurPlanSubID") = j                                                 '子表ID
  1170.                             .Fields("PurPlanMainID") = rs_CreatePurBillPri.Fields("PurPlanMainID") + 0  '单据ID
  1171.                             .Fields("MNumber") = Trim(rs_suppliercodet.Fields("MNumber") & "")          '物料编码
  1172.                             .Fields("Quantity") = Trim(rs_suppliercodet.Fields("SumQuantity") & "")     '数量
  1173.                             .Fields("ProcFactory") = Trim(rs_suppliercodet.Fields("ProcFactory"))       '生产厂家
  1174.                             .Fields("Remark") = ""                                                      '备注
  1175.                             .UpdateBatch
  1176.                             '更新计划拆合跟踪表
  1177.                             str_SQLWhereTmp = str_SQLSelectTmp & str_SQLWhereT & str_SQLGroupTmp
  1178.                             Set Rs_SQLWhereTmp = Nothing
  1179.                             Set Rs_SQLWhereTmp = Cw_DataEnvi.DataConnect.Execute(str_SQLWhereTmp)
  1180.                             Do While Not Rs_SQLWhereTmp.EOF()
  1181.                                 str_Insert = "insert into Cg_SplitUnite(SplitUniteNum,NewPurPlanMainID,NewPurPlanSubID,PurPlanMainID,PurPlanSubID)" & "values( " & Hbpc & "," & rs_CreatePurBillPri.Fields("PurPlanMainID") & " ," & rs_CreatePurBillDet.Fields("PurPlanSubID") & "," & Rs_SQLWhereTmp.Fields("PurPlanMainID") & "," & Rs_SQLWhereTmp.Fields("PurPlanSubID") & ")"
  1182.                                 Cw_DataEnvi.DataConnect.Execute (str_Insert)
  1183.                                 Rs_SQLWhereTmp.MoveNext
  1184.                             Loop
  1185.                             '更新结束
  1186.                             rs_suppliercodet.MoveNext
  1187.                             j = j + 1
  1188.                         Loop
  1189.                     End With
  1190.                 End If
  1191.                 rs_TempDis2.MoveNext
  1192.             Loop
  1193.     End Select
  1194.   
  1195.     '设置已经生成标志
  1196.     Set rs_CreatePurBillPri = Nothing
  1197.     Set rs_Temp = Nothing
  1198.     Set rs_Temp = Cw_DataEnvi.DataConnect.Execute("select distinct PurPlanMainID from Cg_V_PlanBill " & str_SQLWhere & " and Checker=''")
  1199.     If Not rs_Temp.EOF() Then
  1200.         Call Xtxxts("已经有选择的计划被其他人弃审,合并生成失败,返回为生成状态!", 0, 1)
  1201.         Cw_DataEnvi.DataConnect.RollbackTrans
  1202.         Xt_Wait.Hide
  1203.         Exit Sub
  1204.     End If
  1205.     Set rs_Temp = Nothing
  1206.     Set rs_Temp = Cw_DataEnvi.DataConnect.Execute("select distinct PurPlanMainID from Cg_V_PlanBill " & str_SQLWhere)
  1207.     Do While Not rs_Temp.EOF()
  1208.         Cw_DataEnvi.DataConnect.Execute ("update Cg_PurPlanMain set SplitUniteFlag= 1 where PurPlanMainID='" & rs_Temp.Fields("PurPlanMainID") & "'")
  1209.         rs_Temp.MoveNext
  1210.     Loop
  1211.     Cw_DataEnvi.DataConnect.CommitTrans
  1212.   
  1213.     Xt_Wait.Hide
  1214.     Call Xtxxts("合并生成完毕!", 0, 4)
  1215.     Unload Me
  1216.     Xtfhcs = "1"
  1217.     Exit Sub
  1218.     
  1219. Err_Ctrl:
  1220.   
  1221.     Cw_DataEnvi.DataConnect.RollbackTrans
  1222.     Xt_Wait.Hide
  1223.     Xtfhcs = "0"
  1224.     Call Xtxxts("合并生成失败,返回为生成状态!", 0, 4)
  1225. End Sub