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

企业管理

开发平台:

Visual Basic

  1.                 If .Fields("EndDealFlagWh") Then
  2.                     Tsxx = "调入仓库在所选会计期间已经结帐,不能再填制单据!"
  3.                     Call Xtxxts(Tsxx, 0, 4)
  4.                     Exit Function
  5.                 End If
  6.             End If
  7.         End If
  8.     End With
  9.     adoRecTemp.Close
  10.     Set adoRecTemp = Nothing
  11.     '<<]
  12.   
  13.     '[>>下面将对所有有效数据行进行有效性判断
  14.   
  15.     Lng_RowCount = 0
  16.   
  17.     With WglrGrid
  18.         For Rowjsq = .FixedRows To .Rows - 1
  19.             '带*号者为有效数据行(Fixed)
  20.             If .TextMatrix(Rowjsq, 0) <> "*" Then
  21.                 Exit For
  22.             Else
  23.                 Lng_RowCount = Lng_RowCount + 1
  24.             End If
  25.             
  26.             '1.首先进行为空或为零判断(Fixed)
  27.             
  28.             For jsqte = Qslz To .Cols - 1
  29.             
  30.                 '字段不能为空
  31.                 If Not .ColHidden(Coljsq) Then
  32.                     If GridInt(jsqte, 5) = 1 Then
  33.                         If Len(Trim(.TextMatrix(Rowjsq, jsqte))) = 0 Then
  34.                             Tsxx = GridStr(jsqte, 2)
  35.                             Lrywlz = jsqte
  36.                             GoTo Lrcwcl
  37.                             Exit For
  38.                         End If
  39.                     End If
  40.                 End If
  41.                 '字段不能为零
  42.                 If GridInt(jsqte, 5) = 2 Then
  43.                     If Val(Trim(.TextMatrix(Rowjsq, jsqte))) = 0 Then
  44.                         Tsxx = GridStr(jsqte, 2)
  45.                         Lrywlz = jsqte
  46.                         GoTo Lrcwcl
  47.                         Exit For
  48.                     End If
  49.                 End If
  50.             Next jsqte
  51.                        
  52.             '2.判断物料编码是否存在(Define)
  53.            
  54.         Next Rowjsq
  55.      
  56.         '单据分录行数不能为零(Fixed)
  57.         If Lng_RowCount = 0 Then
  58.             Tsxx = "单据分录行数不能为零!"
  59.             Call Xtxxts(Tsxx, 0, 1)
  60.             Exit Function
  61.         End If
  62.         
  63.         '[>>
  64.         '此处可以定义整张单据不能通过有效性检查的理由
  65.         '<<]
  66.     End With  '网格
  67.    
  68.    
  69.     '二.=============如果以上有效性检查均顺利通过,则执行存盘动作============'
  70.    
  71.     '对存盘进行事务处理(Fixed)
  72.     On Error GoTo Swcwcl
  73.     Cw_DataEnvi.DataConnect.BeginTrans
  74.     
  75.     '判断单据状态以进行不同处理
  76.     
  77.     '1.先对单据主表进行处理
  78.     If Trim(Lab_OperStatus) = "2" Then
  79.     
  80.         '新增单据
  81.         
  82.         '1.对于某些单据号自动生成的单据则可在此处自动生成
  83.          LrText(0).Text = CreatBillCode(BillCode, True)
  84.     
  85.         '2.开始存盘
  86.          
  87.         '打开单据主表动态集
  88.         If Rec_InMain.State = 1 Then Rec_InMain.Close
  89.         Rec_InMain.Open "Select * From Gy_InOutMain Where 1=2", Cw_DataEnvi.DataConnect, adOpenDynamic, adLockOptimistic
  90.              
  91.         With Rec_InMain
  92.             .AddNew
  93.             .Fields("InOutMainId") = CreatBillID("1203")                                                            '单据ID
  94.             .Fields("BillCode") = "1203"
  95.             .Fields("BillNum") = CreatBillCode("1203", True, Xtyear, Xtmm, Trim(LrText(5).Tag))                     '生成入库单号                                        '单据号
  96.             .Fields("BillDate") = CDate(LrText(1).Text)
  97.             If Trim(LrText(3).Tag) <> "" Then
  98.                 .Fields("DeptCode") = Trim(LrText(3).Tag)                                                           '部门
  99.             Else
  100.                 .Fields("DeptCode") = Null
  101.             End If
  102.             .Fields("InoutFlag") = 1
  103.             If Trim(LrText(5).Tag) <> "" Then
  104.                 .Fields("WhCode") = Trim(LrText(5).Tag)                                                             '仓库
  105.             Else
  106.                 .Fields("WhCode") = Null
  107.             End If
  108.             If Trim(LrText(7).Tag) <> "" Then
  109.                 .Fields("InoutClassCode") = Trim(LrText(7).Tag)                                                     '收发类别
  110.             Else
  111.                 .Fields("InoutClassCode") = Null
  112.             End If
  113.             If Trim(LrText(8).Tag) <> "" Then
  114.                 .Fields("PersonCode") = Trim(LrText(8).Tag)                                                         '人员
  115.             Else
  116.                 .Fields("PersonCode") = Null
  117.             End If
  118.             .Fields("OperType") = Trim("调拨入库")                                                                  '业务类型
  119.             .Fields("OperbillNum") = Trim(LrText(0).Text)                                                           '业务单号
  120.             .Fields("RedBlueFlag") = "0"                                                                            '红字标志
  121.             .Fields("kjyear") = Int_Year                                                                            '会计年度
  122.             .Fields("period") = Int_Period                                                                          '会计期间
  123.             .Fields("Remark") = Trim(LrText(9).Text)                                                                '备注
  124.             .Fields("Maker") = Xtczy                                                                                '制单人
  125.             .Fields("KfChecker") = ""                                                                               '审核人
  126.             .Update
  127.             '系统读出单据ID写入InID
  128.             InID = .Fields("InOutMainId")
  129.         End With
  130.         
  131.         If Rec_OutMain.State = 1 Then Rec_OutMain.Close
  132.         Rec_OutMain.Open "Select * From Gy_InOutMain Where 1=2", Cw_DataEnvi.DataConnect, adOpenDynamic, adLockOptimistic
  133.              
  134.         With Rec_OutMain
  135.             .AddNew
  136.             .Fields("InOutMainId") = CreatBillID("1206")                                                            '出库单ID
  137.             .Fields("BillCode") = "1206"                                                                            '单据类型
  138.             .Fields("BillNum") = CreatBillCode("1206", True, Xtyear, Xtmm, Trim(LrText(4).Tag))                     '单据号
  139.             .Fields("BillDate") = CDate(LrText(1).Text)                                                             '日期
  140.             If Trim(LrText(2).Tag) <> "" Then
  141.                 .Fields("DeptCode") = Trim(LrText(2).Tag)                                                           '部门
  142.             Else
  143.                 .Fields("DeptCode") = Null
  144.             End If
  145.             .Fields("InoutFlag") = 0
  146.             If Trim(LrText(4).Tag) <> "" Then
  147.                 .Fields("WhCode") = Trim(LrText(4).Tag)                                                             '仓库
  148.             Else
  149.                 .Fields("WhCode") = Null
  150.             End If
  151.             If Trim(LrText(6).Tag) <> "" Then
  152.                 .Fields("InoutClassCode") = Trim(LrText(6).Tag)                                                     '收发类别
  153.             Else
  154.                 .Fields("InoutClassCode") = Null
  155.             End If
  156.             If Trim(LrText(8).Tag) <> "" Then
  157.                 .Fields("PersonCode") = Trim(LrText(8).Tag)                                                         '人员
  158.             Else
  159.                 .Fields("PersonCode") = Null
  160.             End If
  161.             .Fields("OperType") = Trim("调拨出库")                                                                  '业务类型
  162.             .Fields("OperbillNum") = Trim(LrText(0).Text)                                                           '业务单号
  163.             .Fields("RedBlueFlag") = "0"                                                                            '红字标志
  164.             .Fields("kjyear") = Int_Year                                                                            '会计年度
  165.             .Fields("period") = Int_Period                                                                          '会计期间
  166.             .Fields("Remark") = Trim(LrText(9).Text)                                                                '备注
  167.             .Fields("Maker") = Xtczy                                                                                '制单人
  168.             .Fields("KfChecker") = ""                                                                               '审核人
  169.             .Update
  170.             '系统读出单据ID写入OutID
  171.             OutID = .Fields("InOutMainId")
  172.         End With
  173.         
  174.         If Rec_VouchMain.State = 1 Then Rec_VouchMain.Close
  175.         Rec_VouchMain.Open "Select * From KF_MoveMain Where 1=2", Cw_DataEnvi.DataConnect, adOpenDynamic, adLockOptimistic
  176.              
  177.         With Rec_VouchMain
  178.             .AddNew
  179.             .Fields("MoveMainID") = CreatBillID(BillCode)                                                           '调拨单ID
  180.             .Fields("BillCode") = "1207"                                                                            '单据编号
  181.             .Fields("BillNum") = Trim(LrText(0).Text)                                                               '单据号
  182.             .Fields("BillDate") = CDate(LrText(1).Text)                                                             '单据日期
  183.             If Trim(LrText(2).Tag) <> "" Then
  184.                 .Fields("DeptCode1") = Trim(LrText(2).Tag)                                                          '转出部门
  185.             Else
  186.                 .Fields("DeptCode1") = Null
  187.             End If
  188.             If Trim(LrText(3).Tag) <> "" Then
  189.                 .Fields("DeptCode2") = Trim(LrText(3).Tag)                                                          '转入部门
  190.             Else
  191.                 .Fields("DeptCode2") = Null
  192.             End If
  193.             If Trim(LrText(4).Tag) <> "" Then
  194.                 .Fields("WhCode1") = Trim(LrText(4).Tag)                                                            '转出仓库
  195.             Else
  196.                 .Fields("WhCode1") = Null
  197.             End If
  198.             If Trim(LrText(5).Tag) <> "" Then
  199.                 .Fields("WhCode2") = Trim(LrText(5).Tag)                                                            '转入仓库
  200.             Else
  201.                 .Fields("WhCode2") = Null
  202.             End If
  203.             If Trim(LrText(6).Tag) <> "" Then
  204.                 .Fields("Outclass") = Trim(LrText(6).Tag)                                                           '收发类别
  205.             Else
  206.                 .Fields("Outclass") = Null
  207.             End If
  208.             If Trim(LrText(7).Tag) <> "" Then
  209.                 .Fields("Inclass") = Trim(LrText(7).Tag)                                                            '收发类别
  210.             Else
  211.                 .Fields("Inclass") = Null
  212.             End If
  213.             If Trim(LrText(8).Tag) <> "" Then
  214.                 .Fields("PersonCode") = Trim(LrText(8).Tag)                                                         '人员
  215.             Else
  216.                 .Fields("PersonCode") = Null
  217.             End If
  218.             .Fields("kjyear") = Int_Year                                                                            '会计年度
  219.             .Fields("period") = Int_Period                                                                          '会计期间
  220.             .Fields("Remark") = Trim(LrText(9).Text)                                                                '备注
  221.             .Fields("Maker") = Xtczy                                                                                '制单人
  222.             .Fields("Checker") = ""                                                                                 '审核人
  223.             .Fields("InMainId") = InID                                                                              '对应入库单ID
  224.             .Fields("OutMainId") = OutID                                                                            '对应出库单ID
  225.             .Update
  226.             '系统读出单据ID写入Lab_BillID
  227.             Lab_BillId.Caption = .Fields("MoveMainID")
  228.         End With
  229.     Else
  230.      
  231.          '修改单据
  232.         
  233.         If Rec_Sub.State = 1 Then Rec_Sub.Close
  234.         Set Rec_Sub = Cw_DataEnvi.DataConnect.Execute("select mnumber,marea,batchnum,factissuequan from Gy_inoutSub where InoutMainId=" & Val(OutID))
  235.         With Rec_Sub
  236.             If Not .EOF Then
  237.                 .MoveFirst
  238.                 For LsJs = 1 To .RecordCount
  239.                     If IsNull(.Fields("marea")) Then
  240.                         StrTemp1 = ""
  241.                     Else
  242.                         StrTemp1 = Trim(.Fields("marea"))
  243.                     End If
  244.                     '1修改现存量
  245.                     Cw_DataEnvi.DataConnect.Execute (" KF_SP_ChangeQuan  '" & Trim(LrText(4).Tag) & "','" & StrTemp1 & "','" & Trim(.Fields("mnumber")) & "','" & Trim(.Fields("batchnum")) & "'," & Val(.Fields("factissuequan")) & ",0")
  246.                 
  247.                     If Trim(.Fields("batchnum") & "") <> "" Then
  248.                         If BatchJudge(Trim(LrText(4).Tag), Trim(.Fields("mnumber")), Trim(.Fields("batchnum")), intCount, intFatherID(), intChildID(), IsQc(), True) = 0 Then
  249.                             Call RestoreQuan(intCount, intFatherID(), intChildID(), IsQc(), .Fields("factissuequan"), True)
  250.                         End If
  251.                     End If
  252.                     .MoveNext
  253.                 Next LsJs
  254.             End If
  255.         End With
  256.         
  257.         If Rec_Sub.State = 1 Then Rec_Sub.Close
  258.         Set Rec_Sub = Cw_DataEnvi.DataConnect.Execute("select mnumber,marea,batchnum,factreceiptquan from Gy_inoutSub where InoutMainId=" & Val(InID))
  259.         With Rec_Sub
  260.             If Not .EOF Then
  261.                  Cw_DataEnvi.DataConnect.Execute ("delete KF_Batch where fathertablenum='" & Val(InID) & "'")
  262.                 .MoveFirst
  263.                 For LsJs = 1 To .RecordCount
  264.                     If IsNull(.Fields("marea")) Then
  265.                         StrTemp1 = ""
  266.                     Else
  267.                         StrTemp1 = Trim(.Fields("marea"))
  268.                     End If
  269.                     '1修改现存量
  270.                     Cw_DataEnvi.DataConnect.Execute (" KF_SP_ChangeQuan '" & Trim(LrText(5).Tag) & "','" & StrTemp1 & "','" & Trim(.Fields("mnumber")) & "','" & Trim(.Fields("batchnum")) & "'," & Val(.Fields("factreceiptquan")) & ",1")
  271.                     .MoveNext
  272.                 Next LsJs
  273.             End If
  274.         End With
  275.            
  276.         '1.删除原单据子表中所有内容
  277.         
  278.         
  279.         Cw_DataEnvi.DataConnect.Execute ("Delete Gy_InOutSub Where InOutMainID=" & Val(InID))
  280.         Cw_DataEnvi.DataConnect.Execute ("Delete Gy_InOutSub Where InOutMainID=" & Val(OutID))
  281.         Cw_DataEnvi.DataConnect.Execute ("Delete KF_MoveSub Where MoveMainID=" & Val(Lab_BillId.Caption))
  282.         
  283.         If Rec_InMain.State = 1 Then Rec_InMain.Close
  284.         Rec_InMain.Open "Select * From Gy_InOutMain Where InOutMainID=" & Val(InID), Cw_DataEnvi.DataConnect, adOpenDynamic, adLockOptimistic
  285.              
  286.         With Rec_InMain
  287.             .Fields("BillNum") = CreatBillCode("1203", True, Xtyear, Xtmm, Trim(LrText(5).Tag))                                 '单据号
  288.             .Fields("BillDate") = CDate(LrText(1).Text)                                                                         '单据日期
  289.             If Trim(LrText(3).Tag) <> "" Then
  290.                 .Fields("DeptCode") = Trim(LrText(3).Tag)                                                                       '部门
  291.             Else
  292.                 .Fields("DeptCode") = Null
  293.             End If
  294.             .Fields("InoutFlag") = 1
  295.             If Trim(LrText(5).Tag) <> "" Then
  296.                 .Fields("WhCode") = Trim(LrText(5).Tag)                                                                         '仓库
  297.             Else
  298.                 .Fields("WhCode") = Null
  299.             End If
  300.             If Trim(LrText(7).Tag) <> "" Then
  301.                 .Fields("InoutClassCode") = Trim(LrText(7).Tag)                                                                 '收发类别
  302.             Else
  303.                 .Fields("InoutClassCode") = Null
  304.             End If
  305.             If Trim(LrText(8).Tag) <> "" Then
  306.                 .Fields("PersonCode") = Trim(LrText(8).Tag)                                                                     '业务员
  307.             Else
  308.                 .Fields("PersonCode") = Null
  309.             End If
  310.             .Fields("OperType") = Trim("调拨入库")                                                                              '业务类型
  311.             .Fields("OperbillNum") = Trim(LrText(0).Text)                                                                       '业务单号
  312.             .Fields("RedBlueFlag") = "0"
  313.             .Fields("kjyear") = Int_Year                                                                                        '会计年度
  314.             .Fields("period") = Int_Period                                                                                      '会计期间
  315.             .Fields("Remark") = Trim(LrText(9).Text)                                                                            '备注
  316.             .Fields("maker") = Xtczy
  317.             .Fields("kfChecker") = ""
  318.             .Update
  319.         End With
  320.         
  321.         If Rec_OutMain.State = 1 Then Rec_OutMain.Close
  322.         Rec_OutMain.Open "Select * From Gy_InOutMain Where InOutMainID=" & Val(OutID), Cw_DataEnvi.DataConnect, adOpenDynamic, adLockOptimistic
  323.              
  324.         With Rec_OutMain
  325.             .Fields("BillCode") = "1206"
  326.             .Fields("BillNum") = CreatBillCode("1206", True, Xtyear, Xtmm, Trim(LrText(4).Tag))                                 '单据号
  327.             .Fields("BillDate") = CDate(LrText(1).Text)                                                                         '单据日期
  328.             If Trim(LrText(2).Tag) <> "" Then
  329.                 .Fields("DeptCode") = Trim(LrText(2).Tag)                                                                       '部门
  330.             Else
  331.                 .Fields("DeptCode") = Null
  332.             End If
  333.             .Fields("InoutFlag") = 0
  334.             If Trim(LrText(4).Tag) <> "" Then
  335.                 .Fields("WhCode") = Trim(LrText(4).Tag)                                                                         '仓库
  336.             Else
  337.                 .Fields("WhCode") = Null
  338.             End If
  339.             If Trim(LrText(6).Tag) <> "" Then
  340.                 .Fields("InoutClassCode") = Trim(LrText(6).Tag)                                                                 '收发类别
  341.             Else
  342.                 .Fields("InoutClassCode") = Null
  343.             End If
  344.             If Trim(LrText(8).Tag) <> "" Then
  345.                 .Fields("PersonCode") = Trim(LrText(8).Tag)                                                                     '业务员
  346.             Else
  347.                 .Fields("PersonCode") = Null
  348.             End If
  349.             .Fields("OperType") = Trim("调拨出库")                                                                              '业务类型
  350.             .Fields("OperbillNum") = Trim(LrText(0).Text)                                                                       '业务单号
  351.             .Fields("RedBlueFlag") = "0"
  352.             .Fields("kjyear") = Int_Year                                                                                        '会计年度
  353.             .Fields("period") = Int_Period                                                                                      '会计期间
  354.             .Fields("Remark") = Trim(LrText(9).Text)                                                                            '备注
  355.             .Fields("maker") = Xtczy
  356.             .Fields("kfChecker") = ""
  357.             .Update
  358.             '系统读出单据ID写入Lab_BillID
  359.         End With
  360.         
  361.         '打开单据主表动态集
  362.         If Rec_VouchMain.State = 1 Then Rec_VouchMain.Close
  363.         Rec_VouchMain.Open "Select * From KF_MoveMain  Where MoveMainID=" & Val(Lab_BillId.Caption), Cw_DataEnvi.DataConnect, adOpenDynamic, adLockOptimistic
  364.         With Rec_VouchMain
  365.             .Fields("BillCode") = "1207"                                                                                        '单据类型
  366.             .Fields("BillNum") = Trim(LrText(0).Text)                                                                           '单据号
  367.             .Fields("BillDate") = CDate(LrText(1).Text)                                                                         '单据日期
  368.             If Trim(LrText(2).Tag) <> "" Then
  369.                 .Fields("DeptCode1") = Trim(LrText(2).Tag)                                                                      '转出部门
  370.             Else
  371.                 .Fields("DeptCode1") = Null
  372.             End If
  373.             If Trim(LrText(3).Tag) <> "" Then
  374.                 .Fields("DeptCode2") = Trim(LrText(3).Tag)                                                                      '转入部门
  375.             Else
  376.                 .Fields("DeptCode2") = Null
  377.             End If
  378.             If Trim(LrText(4).Tag) <> "" Then
  379.                 .Fields("WhCode1") = Trim(LrText(4).Tag)                                                                        '转出仓库
  380.             Else
  381.                 .Fields("WhCode1") = Null
  382.             End If
  383.             If Trim(LrText(5).Tag) <> "" Then
  384.                 .Fields("WhCode2") = Trim(LrText(5).Tag)                                                                        '转入仓库
  385.             Else
  386.                 .Fields("WhCode2") = Null
  387.             End If
  388.             If Trim(LrText(6).Tag) <> "" Then
  389.                 .Fields("Outclass") = Trim(LrText(6).Tag)                                                                       '出库类别
  390.             Else
  391.                 .Fields("Outclass") = Null
  392.             End If
  393.             If Trim(LrText(7).Tag) <> "" Then
  394.                 .Fields("Inclass") = Trim(LrText(7).Tag)                                                                        '入库类别
  395.             Else
  396.                 .Fields("Inclass") = Null
  397.             End If
  398.             If Trim(LrText(8).Tag) <> "" Then
  399.                 .Fields("PersonCode") = Trim(LrText(8).Tag)                                                                     '业务员
  400.             Else
  401.                 .Fields("PersonCode") = Null
  402.             End If
  403.             .Fields("kjyear") = Int_Year                                                                                        '会计年度
  404.             .Fields("period") = Int_Period                                                                                      '会计期间
  405.             .Fields("Remark") = Trim(LrText(9).Text)                                                                            '备注
  406.             .Fields("maker") = Xtczy                                                                                            '制单人
  407.             .Fields("Checker") = ""                                                                                             '审核人
  408.             .Fields("InMainId") = InID                                                                                          '入库ID
  409.             .Fields("OutMainId") = OutID                                                                                        '出库ID
  410.             .Update
  411.         End With
  412.     End If
  413.          
  414.     '2.对单据子表进行处理
  415.          
  416.     '打开单据子表动态集
  417.     
  418.     If Rec_InSub.State = 1 Then Rec_InSub.Close
  419.     Rec_InSub.Open "Select * From Gy_InOutSub Where 1=2", Cw_DataEnvi.DataConnect, adOpenDynamic, adLockOptimistic
  420.      
  421.     If Rec_OutSub.State = 1 Then Rec_OutSub.Close
  422.     Rec_OutSub.Open "Select * From Gy_InOutSub Where 1=2", Cw_DataEnvi.DataConnect, adOpenDynamic, adLockOptimistic
  423.     
  424.     If Rec_VouchSub.State = 1 Then Rec_VouchSub.Close
  425.     Rec_VouchSub.Open "Select * From KF_MoveSub Where 1=2", Cw_DataEnvi.DataConnect, adOpenDynamic, adLockOptimistic
  426.           
  427.     '将网格中有效数据行写入单据子表
  428.     For Rowjsq = WglrGrid.FixedRows To WglrGrid.Rows - 1
  429.         If WglrGrid.TextMatrix(Rowjsq, 0) <> "*" Then
  430.             Exit For
  431.         End If
  432.         
  433.         With Rec_InSub
  434.             .AddNew
  435.             .Fields("InOutSubID") = Rowjsq - WglrGrid.FixedRows + 1
  436.             .Fields("InOutMainID") = Val(InID)
  437.             .Fields("MNumber") = Trim(WglrGrid.TextMatrix(Rowjsq, Sydz("001", GridStr(), Szzls)))                                           '物料编码
  438.             
  439.             If Trim(WglrGrid.TextMatrix(Rowjsq, 4)) <> "" Then
  440.                 .Fields("MArea") = Trim(WglrGrid.TextMatrix(Rowjsq, 4))                                                                     '货区
  441.             Else
  442.                 .Fields("MArea") = Null
  443.             End If
  444.             .Fields("BatchNum") = Trim(WglrGrid.TextMatrix(Rowjsq, Sydz("007", GridStr(), Szzls)))                                          '批次
  445.             .Fields("FactReceiptQuan") = Val(WglrGrid.TextMatrix(Rowjsq, Sydz("008", GridStr(), Szzls)))                                    '入库数量
  446.             .Fields("PlanPrice") = Val(WglrGrid.TextMatrix(Rowjsq, Sydz("009", GridStr(), Szzls)))                                          '计划单价
  447.             .Fields("Price") = Val(WglrGrid.TextMatrix(Rowjsq, Sydz("010", GridStr(), Szzls)))                                              '单价
  448.             .Fields("PlanMoney") = Val(WglrGrid.TextMatrix(Rowjsq, Sydz("011", GridStr(), Szzls)))                                          '计划金额
  449.             .Fields("EMoney") = Val(WglrGrid.TextMatrix(Rowjsq, Sydz("012", GridStr(), Szzls)))                                             '实际金额
  450.             If Trim(WglrGrid.TextMatrix(Rowjsq, Sydz("013", GridStr(), Szzls))) <> "" Then
  451.                 .Fields("InvalidDate") = CDate(WglrGrid.TextMatrix(Rowjsq, Sydz("013", GridStr(), Szzls)))                                  '失效日期
  452.             Else
  453.                 .Fields("InvalidDate") = Null
  454.             End If
  455.             .Update
  456.         End With
  457.         
  458.         With Rec_OutSub
  459.             .AddNew
  460.             .Fields("InOutSubID") = Rowjsq - WglrGrid.FixedRows + 1
  461.             .Fields("InOutMainID") = Val(OutID)
  462.             .Fields("MNumber") = Trim(WglrGrid.TextMatrix(Rowjsq, Sydz("001", GridStr(), Szzls)))                                           '物料编码
  463.             If Trim(WglrGrid.TextMatrix(Rowjsq, 1)) <> "" Then
  464.                 .Fields("MArea") = Trim(WglrGrid.TextMatrix(Rowjsq, 1))                                                                     '货区
  465.             Else
  466.                 .Fields("MArea") = Null
  467.             End If
  468.             .Fields("BatchNum") = Trim(WglrGrid.TextMatrix(Rowjsq, Sydz("007", GridStr(), Szzls)))                                          '批号
  469.             .Fields("FactIssueQuan") = Val(WglrGrid.TextMatrix(Rowjsq, Sydz("008", GridStr(), Szzls)))                                      '调拨出库数量
  470.             .Fields("PlanPrice") = Val(WglrGrid.TextMatrix(Rowjsq, Sydz("009", GridStr(), Szzls)))                                          '计划单价
  471.             .Fields("Price") = Val(WglrGrid.TextMatrix(Rowjsq, Sydz("010", GridStr(), Szzls)))                                              '单价
  472.             .Fields("PlanMoney") = Val(WglrGrid.TextMatrix(Rowjsq, Sydz("011", GridStr(), Szzls)))                                          '计划金额
  473.             .Fields("issueMoney") = Val(WglrGrid.TextMatrix(Rowjsq, Sydz("012", GridStr(), Szzls)))                                         '金额
  474.             If Trim(WglrGrid.TextMatrix(Rowjsq, Sydz("013", GridStr(), Szzls))) <> "" Then
  475.                 .Fields("InvalidDate") = CDate(WglrGrid.TextMatrix(Rowjsq, Sydz("013", GridStr(), Szzls)))                                  '失效日期
  476.             Else
  477.                 .Fields("InvalidDate") = Null
  478.             End If
  479.             .Update
  480.         End With
  481.         
  482.         With Rec_VouchSub
  483.             .AddNew
  484.             .Fields("MoveSubID") = Rowjsq - WglrGrid.FixedRows + 1
  485.             .Fields("MoveMainID") = Val(Lab_BillId.Caption)
  486.             .Fields("MNumber") = Trim(WglrGrid.TextMatrix(Rowjsq, Sydz("001", GridStr(), Szzls)))                                           '物料编码
  487.             If Trim(WglrGrid.TextMatrix(Rowjsq, 1)) <> "" Then
  488.                 .Fields("MArea1") = Trim(WglrGrid.TextMatrix(Rowjsq, 1))                                                                    '转出货区
  489.             Else
  490.                 .Fields("MArea1") = Null
  491.             End If
  492.             If Trim(WglrGrid.TextMatrix(Rowjsq, 4)) <> "" Then
  493.                 .Fields("MArea2") = Trim(WglrGrid.TextMatrix(Rowjsq, 4))                                                                    '转入货区
  494.             Else
  495.                 .Fields("MArea2") = Null
  496.             End If
  497.             .Fields("BatchNum") = Trim(WglrGrid.TextMatrix(Rowjsq, Sydz("007", GridStr(), Szzls)))                                          '批号
  498.             .Fields("Quan") = Val(WglrGrid.TextMatrix(Rowjsq, Sydz("008", GridStr(), Szzls)))                                               '数量
  499.             .Fields("PlanPrice") = Val(WglrGrid.TextMatrix(Rowjsq, Sydz("009", GridStr(), Szzls)))                                          '计划单价
  500.             .Fields("Price") = Val(WglrGrid.TextMatrix(Rowjsq, Sydz("010", GridStr(), Szzls)))                                              '单价
  501.             .Fields("PlanMoney") = Val(WglrGrid.TextMatrix(Rowjsq, Sydz("011", GridStr(), Szzls)))                                          '计划金额
  502.             .Fields("EMoney") = Val(WglrGrid.TextMatrix(Rowjsq, Sydz("012", GridStr(), Szzls)))                                             '金额
  503.             If Trim(WglrGrid.TextMatrix(Rowjsq, Sydz("013", GridStr(), Szzls))) <> "" Then
  504.                 .Fields("InvalidDate") = CDate(WglrGrid.TextMatrix(Rowjsq, Sydz("013", GridStr(), Szzls)))                                  '失效日期
  505.             Else
  506.                 .Fields("InvalidDate") = Null
  507.             End If
  508.             .Fields("InOutSubId1") = Rec_InSub.Fields("InOutSubID")
  509.             .Fields("InOutSubId2") = Rec_OutSub.Fields("InOutSubID")
  510.             .Update
  511.         End With
  512.         
  513.         '修改现存量
  514.         strWhCode1 = Trim(LrText(4).Tag)
  515.         strWhCode2 = Trim(LrText(5).Tag)
  516.         strMArea1 = Trim(WglrGrid.TextMatrix(Rowjsq, 1) & "")
  517.         strMArea2 = Trim(WglrGrid.TextMatrix(Rowjsq, 4) & "")
  518.         strMNum = Trim(WglrGrid.TextMatrix(Rowjsq, Sydz("001", GridStr(), Szzls)))
  519.         strBatch = Trim(WglrGrid.TextMatrix(Rowjsq, Sydz("007", GridStr(), Szzls)) & "")
  520.         dblEndQuan = Val(WglrGrid.TextMatrix(Rowjsq, Sydz("008", GridStr(), Szzls)))
  521.         
  522.         Cw_DataEnvi.DataConnect.Execute (" KF_SP_ChangeQuan '" & strWhCode1 & "','" & strMArea1 & "','" & strMNum & "','" & strBatch & "'," & dblEndQuan & ",1")
  523.         Cw_DataEnvi.DataConnect.Execute (" KF_SP_ChangeQuan '" & strWhCode2 & "','" & strMArea2 & "','" & strMNum & "','" & strBatch & "'," & dblEndQuan & ",0")
  524.         '回填批次所对应的出库数量
  525.         If strBatch <> "" Then
  526.             If BatchJudge(Trim(LrText(4).Tag), strMNum, strBatch, intCount, intFatherID(), intChildID(), IsQc(), False) = 0 Then
  527.                 Call RestoreQuan(intCount, intFatherID(), intChildID(), IsQc(), dblEndQuan, False)
  528.             End If
  529.         End If
  530.         '添加批次
  531.         If strBatch <> "" Then
  532.             Cw_DataEnvi.DataConnect.Execute ("insert into KF_Batch(FatherTableNum,SubTableNum,WhCode,MNumber,BatchNum) values (" & Val(InID) & "," & Rec_InSub.Fields("InOutSubID") & ",'" & strWhCode2 & "','" & strMNum & "','" & strBatch & "')")
  533.         End If
  534.         
  535.         
  536.     Next Rowjsq
  537.     Cw_DataEnvi.DataConnect.CommitTrans
  538.     
  539.     Sub_SaveBill = True
  540.     Tsxx = "单据存盘完毕! 单据号:" & Trim(LrText(0).Text)
  541.     Call Xtxxts(Tsxx, 0, 4)
  542.     
  543.     '标识单据发生改动
  544.     Bln_BillChange = True
  545.     
  546.     '设置单据改变后的状态
  547.     Lab_OperStatus = "1"
  548.     Call Sub_OperStatus("10")
  549.     Rec_Query.Requery
  550.     Rec_Query.Find "MoveMainID=" & Val(Lab_BillId.Caption)
  551.     
  552.     Exit Function
  553. Swcwcl:       '数据存盘时出现错误
  554.     Cw_DataEnvi.DataConnect.RollbackTrans
  555.     With WglrGrid
  556.         If Err.Number = -2147217887 Then
  557.             Tsxx = "单据中第  " & Trim(str(Rowjsq - .FixedRows + 1)) & " 条分录录入数据超出允许范围!"
  558.             Call Xtxxts(Tsxx, 0, 1)
  559.             Changelock = True
  560.             .Select Rowjsq, Qslz
  561.             WglrGrid.SetFocus
  562.             Changelock = False
  563.             Exit Function
  564.         Else
  565.             Tsxx = "存盘过程中出现未知错误,程序自动恢复保存前状态!"
  566.             Call Xtxxts(Tsxx, 0, 1)
  567.             Exit Function
  568.         End If
  569.     End With
  570. Lrcwcl:        '录入错误处理(存盘前逐行有效性判断)
  571.     With WglrGrid
  572.         Call Xtxxts("(第 " & Trim(str(Rowjsq - .FixedRows + 1)) & " 条单据分录)-" & Tsxx, 0, 1)
  573.         Changelock = True
  574.         .Select Rowjsq, Lrywlz
  575.         WglrGrid.SetFocus
  576.         Changelock = False
  577.         Exit Function
  578.     End With
  579. End Function
  580. '选择首张,上张,下张,末张(此4个过程只需用您的单据ID字段名替换"MoveMainID"即可)
  581. Private Sub Sub_First()             '首 张
  582.     
  583.     With Rec_Query
  584.         If .RecordCount = 0 Then
  585.             Exit Sub
  586.         End If
  587.         .MoveFirst
  588.         Lab_BillId.Caption = .Fields("MoveMainID")
  589.         Call Sub_ShowBill
  590.     End With
  591. End Sub
  592. Private Sub Sub_Prev()             '上 张
  593.     
  594.     With Rec_Query
  595.         If .RecordCount = 0 Then
  596.             Exit Sub
  597.         End If
  598.         If Not .BOF Then
  599.             .MovePrevious
  600.         End If
  601.         If Not .BOF Then
  602.             Lab_BillId.Caption = .Fields("MoveMainID")
  603.         Else
  604.             .MoveNext
  605.         End If
  606.         Call Sub_ShowBill
  607.     End With
  608. End Sub
  609. Private Sub Sub_next()             '下 张
  610.     With Rec_Query
  611.         If .RecordCount = 0 Then
  612.             Exit Sub
  613.         End If
  614.         If Not .EOF Then
  615.             .MoveNext
  616.         End If
  617.         If Not .EOF Then
  618.             Lab_BillId.Caption = .Fields("MoveMainID")
  619.         Else
  620.             .MovePrevious
  621.         End If
  622.         Call Sub_ShowBill
  623.     End With
  624. End Sub
  625. Private Sub Sub_Last()              '末 张
  626.     
  627.     With Rec_Query
  628.         If .RecordCount = 0 Then
  629.             Exit Sub
  630.         End If
  631.         .MoveLast
  632.         Lab_BillId.Caption = .Fields("MoveMainID")
  633.         Call Sub_ShowBill
  634.     End With
  635. End Sub
  636.     
  637. '[>>===================以下为根据实际业务需要自定义过程区域=============================<<]
  638. '审核,弃审
  639. Private Sub Sub_CheckBill()             '审 核
  640.     
  641.     '[>>
  642.     '此处可以写入禁止单据审核的理由
  643.      '判断用户是否有此功能执行权限,如有则写上机日志(进入)
  644.      If Not Security_Log(Str_RightCheck, Xtczybm, 1, True) Then
  645.         Exit Sub
  646.      End If
  647.     '<<]
  648.     
  649.     '将单据写入审核标识
  650.     Cw_DataEnvi.DataConnect.Execute ("Update KF_MoveMain Set Checker='" & Xtczy & "' Where MoveMainID=" & Val(Lab_BillId.Caption))
  651.     
  652.     '写入系统操作员
  653.     LrText(11).Text = Xtczy
  654.     
  655.     '设置审核弃审按钮状态
  656.     Call Sub_CheckStatus
  657.     
  658.     '标识单据发生变化
  659.     Bln_BillChange = True
  660. End Sub
  661. Private Sub Sub_AbandonCheck()          '弃 审
  662.     
  663.     '[>>
  664.     '此处可以写入禁止单据弃审的理由
  665.      '判断用户是否有此功能执行权限,如有则写上机日志(进入)
  666.      If Not Security_Log(Str_RightCheck, Xtczybm, 1, True) Then
  667.         Exit Sub
  668.      End If
  669.     '<<]
  670.    
  671.     '将单据清除审核标识
  672.     Cw_DataEnvi.DataConnect.Execute ("Update KF_MoveMain Set Checker='' Where MoveMainID=" & Val(Lab_BillId.Caption))
  673.     
  674.     '清空单据审核人
  675.     LrText(11).Text = ""
  676.     
  677.     '设置审核弃审按钮状态
  678.     Call Sub_CheckStatus
  679.     
  680.     '标识单据发生变化
  681.     Bln_BillChange = True
  682.   
  683. End Sub
  684. Private Function Fun_AllowEdit() As Boolean                      '判断当前单据是否允许编辑或删除
  685.   
  686.     Dim RecTemp As New ADODB.Recordset     '临时使用动态集
  687.     Dim adoCheck As New ADODB.Recordset
  688.     
  689.     Fun_AllowEdit = False
  690.     Sqlstr = "Select Checker,ChalkitupMan From KF_MoveMain Where MoveMainID=" & Val(Lab_BillId.Caption)
  691.     Set RecTemp = Cw_DataEnvi.DataConnect.Execute(Sqlstr)
  692.     
  693.     Set adoCheck = Cw_DataEnvi.DataConnect.Execute("select KfChecker from gy_inoutmain where kfchecker<>'' and inoutmainid in(" & InID & "," & OutID & ")")
  694.     
  695.     With RecTemp
  696.         If Not .EOF Then
  697.             If Trim(.Fields("Checker") & "") <> "" Or Trim(.Fields("ChalkitupMan") & "") <> "" Then
  698.                 Tsxx = "该单据已审核或记帐,不能修改或删除!"
  699.                 Call Xtxxts(Tsxx, 0, 4)
  700.                 Exit Function
  701.             End If
  702.         End If
  703.     End With
  704.     
  705.     With adoCheck
  706.         If Not .EOF Then
  707.             Tsxx = "该单据的系统生成单据已审核或记帐,不能修改或删除!"
  708.             Call Xtxxts(Tsxx, 0, 4)
  709.             Exit Function
  710.         End If
  711.     End With
  712.     Fun_AllowEdit = True
  713. End Function
  714. '[>>===================以上为根据实际业务需要自定义过程区域=============================<<]
  715. '===================以 下 程 序 为 通 用 部 分 ,一 般 不 需 更 改(程序动作部分)======================='
  716. Private Sub Sub_AdjustGrid()
  717.   
  718.     '调 整 网 格
  719.     With WglrGrid
  720.         '加 1 保持一行录入行
  721.         If .Rows < Pmbcsjhs + .FixedRows + Fzxwghs + 1 Then
  722.             .Rows = Pmbcsjhs + .FixedRows + Fzxwghs + 1
  723.             For jsqte = .FixedRows To .Rows - 1
  724.                 .RowHeight(jsqte) = Sjhgd
  725.             Next jsqte
  726.         Else
  727.             '判断是否有辅助行和录入行,如没有则加行
  728.             Do While .TextMatrix(.Rows - 1 - Fzxwghs, 0) = "*"
  729.                 .AddItem ""
  730.                 .RowHeight(.Rows - 1) = Sjhgd
  731.             Loop
  732.         End If
  733.     End With
  734. End Sub
  735. Private Sub Lrzdbz()                                                      '录入字段帮助
  736.     
  737.     If Not Ydcommand.Visible Then
  738.         Exit Sub
  739.     End If
  740.    
  741.     With WglrGrid
  742.         Valilock = True
  743.     
  744.         '处理通用部分
  745.         Changelock = True        '调入另外窗体必须加锁
  746.         If GridInt(.Col, 6) <> 1 Then
  747.             If UCase(GridStr(.Col, 3)) = UCase("KF_BatchHelp") Then
  748.                 strHlpR = FunHlpR(Trim(GridStr(.Col, 3)), "whcode", Trim(LrText(4).Tag))
  749.                 Call Drbmhelp(GridInt(.Col, 6), GridStr(.Col, 3), Trim(.TextMatrix(.Row, Sydz("001", GridStr(), Szzls))))
  750.             Else
  751.                 If GridStr(.Col, 1) = "005" Then
  752.                     strHlpR = FunHlpR(Trim(GridStr(.Col, 3)), "whcode", Trim(LrText(4).Tag))
  753.                 ElseIf GridStr(.Col, 1) = "006" Then
  754.                     strHlpR = FunHlpR(Trim(GridStr(.Col, 3)), "whcode", Trim(LrText(5).Tag))
  755.                 Else
  756.                     strHlpR = FunHlpR(Trim(GridStr(.Col, 3)), "whcode", Trim(LrText(4).Tag))
  757.                 End If
  758.                 Call Drbmhelp(GridInt(.Col, 6), GridStr(.Col, 3), Trim(Ydtext.Text))
  759.             End If
  760.         Else
  761.             Call Drbmhelp(GridInt(.Col, 6), GridStr(.Col, 3), Trim(Ydtext.Text))
  762.         End If
  763.         
  764.         Changelock = False
  765.         
  766.         If Len(Xtfhcs) <> 0 Then
  767.             If GridInt(.Col, 7) = 0 Then
  768.                 Ydtext.Text = Xtfhcs
  769.             Else
  770.                 Ydtext.Text = Xtfhcsfz
  771.             End If
  772.         End If
  773.         
  774.         Valilock = False
  775.         If Ydtext.Visible Then
  776.             Ydtext.SetFocus
  777.         End If
  778.     End With
  779. End Sub
  780. Private Sub Cshhjwg()                                                     '初始化合计网格(*对合计网格来说,录入网格为容器)
  781.     
  782.     With HjGrid
  783.     
  784.        '是否显示合计网格
  785.        If Not Sfxshjwg Then
  786.            .Visible = False
  787.            Exit Sub
  788.        Else
  789.            .Visible = True
  790.        End If
  791.       
  792.        '设置网格相关属性
  793.        .Enabled = False
  794.        .Appearance = flexFlat
  795.        .BorderStyle = flexBorderNone
  796.        .ScrollBars = flexScrollBarNone
  797.        .Width = WglrGrid.Width
  798.        .FixedRows = 0
  799.        .Rows = 1
  800.        .Cols = WglrGrid.Cols
  801.        .LeftCol = WglrGrid.LeftCol
  802.        .TextMatrix(0, Qslz) = "合  计"
  803.        For jsqte = 0 To WglrGrid.Cols - 1
  804.            .ColHidden(jsqte) = WglrGrid.ColHidden(jsqte)
  805.            .ColWidth(jsqte) = WglrGrid.ColWidth(jsqte)
  806.            .ColAlignment(jsqte) = WglrGrid.ColAlignment(jsqte)
  807.            .ColFormat(jsqte) = WglrGrid.ColFormat(jsqte)
  808.        Next jsqte
  809.        .ColAlignment(Qslz) = flexAlignCenterTop
  810.        For jsqte = .FixedRows To .Rows - 1
  811.            .RowHeight(jsqte) = .Height / .Rows
  812.        Next jsqte
  813.        
  814.       '程序自动调整网格高度(自动设置为网格剩余高度+辅助项网格行数(默认为1)*数据行高度)、并设置其位置信息
  815.        .Height = Fzxwghs * Sjhgd + ((WglrGrid.Height - WglrGrid.FixedRows * WglrGrid.RowHeight(0)) Mod Sjhgd)
  816.        .RowHeight(0) = .Height
  817.        .Move 0, WglrGrid.Height - .Height, WglrGrid.Width, .Height
  818.     End With
  819. End Sub
  820. Private Sub Form_Resize()                                                '窗体大小发生变化时,重新显示文本框
  821.    Call Cxxswbk
  822. End Sub
  823. Private Function Fun_Drfrmyxxpd() As Boolean                             '调入其它窗体或功能产生的有效性判断(包括数据回写)
  824.     Fun_Drfrmyxxpd = True
  825.     With WglrGrid
  826.         
  827.         '如果当前网格处于编辑状态,则先进行数据回写再进行有效性判断
  828.         If Ydtext.Visible Or YdCombo.Visible Then
  829.             Call Lrsjhx
  830.             If Not sjzdyxxpd(Dqlrwgh, Dqlrwgl) Then
  831.                 Fun_Drfrmyxxpd = False
  832.                 Exit Function
  833.             End If
  834.         End If
  835.    
  836.         '进行行有效性判断
  837.         If Not Sjhzyxxpd(.Row) Then
  838.             Fun_Drfrmyxxpd = False
  839.             Exit Function
  840.         End If
  841.         
  842.     End With
  843. End Function
  844. Private Sub WglrGrid_AfterUserResize(ByVal Row As Long, ByVal Col As Long)       '调整列宽
  845.     
  846.     If HjGrid.Visible Then
  847.         With HjGrid
  848.             .ColWidth(Col) = WglrGrid.ColWidth(Col)
  849.         End With
  850.     End If
  851. End Sub
  852. Private Sub WglrGrid_EnterCell()                                                 '显示当前数据行相关信息
  853.     
  854.     With WglrGrid
  855.         If .Row >= .FixedRows Then
  856.             '[>>
  857.             '此处可以填写显示与此网格行相关信息
  858.             '<<]
  859.         End If
  860.     End With
  861. End Sub
  862. Private Sub WglrGrid_GotFocus()                                     '网格得到焦点
  863.     '网格得到焦点,如果当前选择行为非数据行
  864.     '则调整当前焦点至有效数据行
  865.     With WglrGrid
  866.         If .Row < .FixedRows And .Rows > .FixedRows Then
  867.             Changelock = True
  868.             .Select .FixedRows, .Col
  869.             Changelock = False
  870.         End If
  871.         If .Col < Qslz Then
  872.             Changelock = True
  873.             .Select .Row, Qslz
  874.             Changelock = False
  875.         End If
  876.     End With
  877. End Sub
  878. Private Sub WglrGrid_LostFocus()                                    '录入网格失去焦点
  879.     '用以屏蔽调用其它窗体时发生网格失去焦点事件
  880.     If Changelock Then
  881.         Exit Sub
  882.     End If
  883.     '引发网格RowcolChange事件
  884.     With WglrGrid
  885.         If Not (Ydtext.Visible Or YdCombo.Visible) Then
  886.             .Select 0, 0
  887.         End If
  888.     End With
  889. End Sub
  890. Private Sub WglrGrid_AfterScroll(ByVal OldTopRow As Long, ByVal OldLeftCol As Long, ByVal NewTopRow As Long, ByVal NewLeftCol As Long)                                       '限制用户在录入过程中滚动鼠标
  891.     If Gdtlock Then
  892.         Exit Sub
  893.     End If
  894.  
  895.     With WglrGrid
  896.         If Ydtext.Visible Or YdCombo.Visible Then
  897.             Gdtlock = True
  898.             .TopRow = Dqtoprow
  899.             .LeftCol = Dqleftcol
  900.             Gdtlock = False
  901.             Exit Sub
  902.         End If
  903.         HjGrid.LeftCol = .LeftCol
  904.     End With
  905. End Sub
  906. Private Sub WglrGrid_LeaveCell()                                    '离开单元格
  907.     
  908.     If Changelock Then
  909.         Exit Sub
  910.     End If
  911.     '记录刚刚离开网格单元的行列值
  912.     Dqlkwgh = WglrGrid.Row
  913.     Dqlkwgl = WglrGrid.Col
  914.     '判断是否需要录入数据回写
  915.     If Not (Ydtext.Visible Or YdCombo.Visible) Then
  916.         Exit Sub
  917.     End If
  918.     Call Lrsjhx
  919. End Sub
  920. Private Sub WglrGrid_RowColChange()                                '网格录入行列发生变化时,进行有效性判断
  921.     Valilock = True       '屏蔽文本框失去焦点进行有效性判断
  922.     With WglrGrid
  923.         If Changelock Then
  924.             Exit Sub
  925.         End If
  926.         If Not sjzdyxxpd(Dqlrwgh, Dqlrwgl) Then
  927.             Exit Sub
  928.         End If
  929.         If .Row <> Dqlkwgh Then
  930.             If Not Sjhzyxxpd(Dqlkwgh) Then
  931.                 Exit Sub
  932.             End If
  933.         End If
  934.     End With
  935.    
  936.     Call fhyxh
  937.     Call Xldql
  938.    
  939. End Sub
  940. Private Sub WglrGrid_DblClick()          '鼠标双击网格显示文本框
  941.       
  942.     If Lab_OperStatus = "2" Then
  943.         If Trim(LrText(4).Text) = "" Then
  944.             Tsxx = "请先输入仓库!"
  945.             Call Xtxxts(Tsxx, 0, 1)
  946.             LrText(4).SetFocus
  947.             Exit Sub
  948.         End If
  949.     End If
  950.     
  951.     With WglrGrid
  952.         Call xswbk
  953.     End With
  954. End Sub
  955. Private Sub Ycwbk()                      '隐藏文本框,帮助按钮,列表组合框
  956.     
  957.     Valilock = True
  958.     Ydtext.Visible = False
  959.     YdCombo.Visible = False
  960.     Ydcommand.Visible = False
  961. End Sub
  962. Private Sub YdCombo_KeyDown(KeyCode As Integer, Shift As Integer)        '列表框移动
  963.     With WglrGrid
  964.         Select Case KeyCode
  965.             Case vbKeyEscape                'ESC 键放弃录入
  966.                 Valilock = True
  967.                 .SetFocus
  968.                 Call Ycwbk
  969.                 Valilock = False
  970.             Case vbKeyReturn                '回 车 键 =13
  971.                 KeyCode = 0
  972.                 .SetFocus
  973.                 Call Lrsjhx
  974.                 Rowjsq = .Row
  975.                 Coljsq = .Col + 1
  976.                 If Coljsq > .Cols - 1 Then
  977.                     If Rowjsq < .Rows - 1 Then
  978.                         Rowjsq = Rowjsq + 1
  979.                     End If
  980.                     Coljsq = Qslz
  981.                 End If
  982.                 Do While Rowjsq <= .Rows - 1
  983.                     If .ColHidden(Coljsq) Or (Not GridBoolean(Coljsq, 1)) Then
  984.                         Coljsq = Coljsq + 1
  985.                         If Coljsq > .Cols - 1 Then
  986.                             Rowjsq = Rowjsq + 1
  987.                             Coljsq = Qslz
  988.                         End If
  989.                     Else
  990.                         Exit Do
  991.                     End If
  992.                 Loop
  993.                 .Select Rowjsq, Coljsq
  994.             Case vbKeyLeft                  '左 箭 头 =37
  995.                 If .Col - 1 = Qslz Then
  996.                     If .ColHidden(Qslz) Or (Not GridBoolean(Qslz, 1)) Then
  997.                         GoTo jzzx
  998.                     End If
  999.                 End If
  1000.                 If .Col > Qslz Then
  1001.                     KeyCode = 0
  1002.                     .SetFocus
  1003.                     Call Lrsjhx
  1004.                     Coljsq = .Col - 1
  1005.                     Do While Coljsq > Qslz
  1006.                         If Coljsq - 1 = Qslz Then
  1007.                             If .ColHidden(Qslz) Or (Not GridBoolean(Qslz, 1)) Then
  1008.                                 GoTo jzzx
  1009.                             End If
  1010.                         End If
  1011.                         If .ColHidden(Coljsq) Or (Not GridBoolean(Coljsq, 1)) Then
  1012.                             Coljsq = Coljsq - 1
  1013.                         Else
  1014.                             Exit Do
  1015.                         End If
  1016.                     Loop
  1017.                     .Select .Row, Coljsq
  1018.                 End If
  1019.             Case vbKeyRight                 '右 箭 头 =39
  1020.                 KeyCode = 0
  1021.                 .SetFocus
  1022.                 Call Lrsjhx
  1023.                 Rowjsq = .Row
  1024.                 Coljsq = .Col + 1
  1025.                 If Coljsq > .Cols - 1 Then
  1026.                     If Rowjsq < .Rows - 1 Then
  1027.                         Rowjsq = Rowjsq + 1
  1028.                     End If
  1029.                     Coljsq = Qslz
  1030.                 End If
  1031.                 Do While Rowjsq <= .Rows - 1
  1032.                     If .ColHidden(Coljsq) Or (Not GridBoolean(Coljsq, 1)) Then
  1033.                         Coljsq = Coljsq + 1
  1034.                         If Coljsq > .Cols - 1 Then
  1035.                             Rowjsq = Rowjsq + 1
  1036.                             Coljsq = Qslz
  1037.                         End If
  1038.                     Else
  1039.                         Exit Do
  1040.                     End If
  1041.                 Loop
  1042.                 .Select Rowjsq, Coljsq
  1043.         Case Else
  1044.    End Select
  1045.    
  1046. jzzx:
  1047.    
  1048.     End With
  1049. End Sub
  1050. Private Sub YdCombo_LostFocus()
  1051.   
  1052.     With WglrGrid                                    '因为选中网格会先发生Rowcolchange事件置Valiock
  1053.         If Not Valilock Then                           '为TRUE
  1054.             Call Lrsjhx
  1055.             If Not Sjhzyxxpd(Dqlrwgh) Then
  1056.                 Exit Sub
  1057.             End If
  1058.         End If
  1059.     End With
  1060. End Sub
  1061. Private Sub Ydcommand_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
  1062.     Call Lrzdbz
  1063. End Sub
  1064. Private Sub ydtext_KeyDown(KeyCode As Integer, Shift As Integer)
  1065.     Dim Rowjsq As Long, Coljsq As Long
  1066.     With WglrGrid
  1067.         Select Case KeyCode
  1068.             Case vbKeyF2
  1069.                 Call Lrzdbz
  1070.             Case vbKeyEscape                'ESC 键放弃录入
  1071.                 Valilock = True
  1072.                 Call Ycwbk
  1073.                 .SetFocus
  1074.             Case vbKeyReturn                '回 车 键 =13
  1075.                 KeyCode = 0
  1076.                 .SetFocus
  1077.                 Call Lrsjhx
  1078.                 Rowjsq = .Row
  1079.                 Coljsq = .Col + 1
  1080.                 If Coljsq > .Cols - 1 Then
  1081.                     If Rowjsq < .Rows - 1 Then
  1082.                         Rowjsq = Rowjsq + 1
  1083.                     End If
  1084.                     Coljsq = Qslz
  1085.                 End If
  1086.                 Do While Rowjsq <= .Rows - 1
  1087.                     If .ColHidden(Coljsq) Or (Not GridBoolean(Coljsq, 1)) Then
  1088.                         Coljsq = Coljsq + 1
  1089.                         If Coljsq > .Cols - 1 Then
  1090.                             Rowjsq = Rowjsq + 1
  1091.                             Coljsq = Qslz
  1092.                         End If
  1093.                     Else
  1094.                         Exit Do
  1095.                     End If
  1096.                 Loop
  1097.                 If Rowjsq <= .Rows - 1 Then
  1098.                     .Select Rowjsq, Coljsq
  1099.                 End If
  1100.             Case vbKeyUp                    '上 箭 头 =38
  1101.                 KeyCode = 0
  1102.                 .SetFocus
  1103.                 Call Lrsjhx
  1104.                 If .Row > .FixedRows Then
  1105.                     .Row = .Row - 1
  1106.                 End If
  1107.             Case vbKeyDown                  '下 箭 头 =40
  1108.                 KeyCode = 0
  1109.                 .SetFocus
  1110.                 Call Lrsjhx
  1111.                 If .Row < .Rows - 1 Then
  1112.                     .Row = .Row + 1
  1113.                 End If
  1114.             Case vbKeyLeft                  '左 箭 头 =37
  1115.                 If .Col - 1 = Qslz Then
  1116.                     If .ColHidden(Qslz) Or (Not GridBoolean(Qslz, 1)) Then
  1117.                         GoTo jzzx
  1118.                     End If
  1119.                 End If
  1120.                 If Ydtext.SelStart = 0 And .Col > Qslz Then
  1121.                     KeyCode = 0
  1122.                     .SetFocus
  1123.                     Call Lrsjhx
  1124.                     Coljsq = .Col - 1
  1125.                     Do While Coljsq > Qslz
  1126.                         If Coljsq - 1 = Qslz Then
  1127.                             If .ColHidden(Qslz) Or (Not GridBoolean(Qslz, 1)) Then
  1128.                                 GoTo jzzx
  1129.                             End If
  1130.                         End If
  1131.                         If .ColHidden(Coljsq) Or (Not GridBoolean(Coljsq, 1)) Then
  1132.                             Coljsq = Coljsq - 1
  1133.                         Else
  1134.                             Exit Do
  1135.                         End If
  1136.                     Loop
  1137.                     .Select .Row, Coljsq
  1138.                 End If
  1139. jzzx:
  1140.             Case vbKeyRight                 '右 箭 头 =39
  1141.                 wblong = Len(Ydtext.Text)
  1142.                 If (Ydtext.SelStart = wblong Or Ydtext.SelLength = wblong) Then
  1143.                     KeyCode = 0
  1144.                     .SetFocus
  1145.                     Call Lrsjhx
  1146.                     Rowjsq = .Row
  1147.                     Coljsq = .Col + 1
  1148.                     If Coljsq > .Cols - 1 Then
  1149.                         If Rowjsq < .Rows - 1 Then
  1150.                             Rowjsq = Rowjsq + 1
  1151.                         End If
  1152.                         Coljsq = Qslz
  1153.                     End If
  1154.                     Do While Rowjsq <= .Rows - 1
  1155.                         If .ColHidden(Coljsq) Or (Not GridBoolean(Coljsq, 1)) Then
  1156.                             Coljsq = Coljsq + 1
  1157.                             If Coljsq > .Cols - 1 Then
  1158.                                 Rowjsq = Rowjsq + 1
  1159.                                 Coljsq = Qslz
  1160.                             End If
  1161.                         Else
  1162.                             Exit Do
  1163.                         End If
  1164.                     Loop
  1165.                     .Select Rowjsq, Coljsq
  1166.                 End If
  1167.             Case Else
  1168.         End Select
  1169.     End With
  1170. End Sub
  1171. Private Sub ydtext_KeyPress(KeyAscii As Integer)         '录入字符事中控制
  1172.     
  1173.     Call InputFieldLimit(Ydtext, GridInt(WglrGrid.Col, 1), KeyAscii)
  1174.     If KeyAscii <> 0 Then
  1175.         Call Xyxhbz(Dqlrwgh)
  1176.     End If
  1177. End Sub
  1178. Private Sub ydtext_Change()                              '录入事中变化处理
  1179.     '防止程序改变但不进行处理
  1180.     If Wbkbhlock Then
  1181.         Exit Sub
  1182.     End If
  1183.     With WglrGrid
  1184.         '限制字段录入长度
  1185.         Wbkbhlock = True
  1186.         Call TextChangeLimit(Ydtext, GridInt(.Col, 1))  '去掉无效字符
  1187.         Select Case GridInt(.Col, 1)
  1188.             Case 8, 11   '金额型
  1189.                 Call Sjgskz(Ydtext, Xtjezws - Xtjexsws - 1, Xtjexsws)
  1190.             Case 9, 12   '数量型
  1191.                 Call Sjgskz(Ydtext, Xtslzws - Xtslxsws - 1, Xtslxsws)
  1192.             Case 10      '单价型
  1193.                 Call Sjgskz(Ydtext, Xtdjzws - Xtdjxsws - 1, Xtdjxsws)
  1194.             Case Else    '其他类型
  1195.                 If GridInt(.Col, 3) <> 0 Or GridInt(.Col, 4) <> 0 Then
  1196.                     Call Sjgskz(Ydtext, GridInt(.Col, 3), GridInt(.Col, 4))
  1197.                 End If
  1198.         End Select
  1199.         Wbkbhlock = False
  1200.     End With
  1201. End Sub
  1202. Private Sub ydtext_LostFocus()            '如果由于选中网格之外的控件而发生有效性判断(选中网格会先发生Rowcolchange事件置Valiock为TRUE)
  1203.   
  1204.     With WglrGrid
  1205.         If Not Valilock Then
  1206.             Call Lrsjhx
  1207.             If Not sjzdyxxpd(Dqlrwgh, Dqlrwgl) Then
  1208.                 Exit Sub
  1209.             End If
  1210.             If Not Sjhzyxxpd(Dqlrwgh) Then
  1211.                 Exit Sub
  1212.             End If
  1213.         End If
  1214.     End With
  1215. End Sub
  1216. Private Sub xswbk()                       '在当前选中单元显示文本框,列表框,帮助按钮(通用)
  1217.     
  1218.     Dim Wbkpy As Integer, Wbkpy1 As Integer '文本框偏移量
  1219.   
  1220.     '当某种条件成立时禁止文本框激活使单据处于录入状态
  1221.     If Not Fun_AllowInput Then
  1222.         Exit Sub
  1223.     End If
  1224.   
  1225.     '显示文本框前返回有效行列(解决滚动条问题)
  1226.     Call Xldqh
  1227.     Call Xldql
  1228.   
  1229.     '隐藏文本框,帮助按钮,列表组合框
  1230.     Call Ycwbk
  1231.   
  1232.     With WglrGrid
  1233.         Dqlrwgh = .Row
  1234.         Dqlrwgl = .Col
  1235.         If Not GridBoolean(.Col, 1) Or .Row < .FixedRows Then
  1236.             Exit Sub
  1237.         End If
  1238.      
  1239.         Wbkpy = 30
  1240.         Wbkpy1 = 15
  1241.     
  1242.         If GridBoolean(.Col, 3) Then
  1243.             YdCombo.Left = .CellLeft + .Left + Wbkpy
  1244.             YdCombo.Top = .CellTop + .Top + Wbkpy
  1245.             YdCombo.Width = .CellWidth - Wbkpy1
  1246.             Call Wbkcl
  1247.             YdCombo.Visible = True
  1248.             YdCombo.SetFocus
  1249.             Ydcommand.Visible = False
  1250.             Ydtext.Visible = False
  1251.         Else
  1252.             If GridBoolean(.Col, 2) Then
  1253.                 Ydcommand.Left = .Left + .CellLeft + .CellWidth - Ydcommand.Width + Wbkpy
  1254.                 Ydcommand.Top = .Top + .CellTop + .CellHeight - Ydcommand.Height + Wbkpy
  1255.                 Ydcommand.Visible = True
  1256.             Else
  1257.                 Ydcommand.Visible = False
  1258.             End If
  1259.              
  1260.             Ydtext.Left = .CellLeft + .Left + Wbkpy
  1261.             Ydtext.Top = .CellTop + .Top + Wbkpy
  1262.             If Ydcommand.Visible Then
  1263.                 If Sfblbzkd Then
  1264.                     Ydtext.Width = .CellWidth - Ydcommand.Width
  1265.                 Else
  1266.                     Ydtext.Width = .CellWidth - Wbkpy1
  1267.                 End If
  1268.             Else
  1269.                 Ydtext.Width = .CellWidth - Wbkpy1
  1270.             End If
  1271.             Ydtext.Height = .CellHeight - Wbkpy1
  1272.         
  1273.             If GridInt(.Col, 2) <> 0 Then
  1274.                 Ydtext.MaxLength = GridInt(.Col, 2)
  1275.             Else
  1276.                 Ydtext.MaxLength = 3000
  1277.             End If
  1278.       
  1279.             Call Wbkcl
  1280.       
  1281.             Ydtext.Visible = True
  1282.             Ydtext.SetFocus
  1283.         End If
  1284.         Dqtoprow = .TopRow
  1285.         Dqleftcol = .LeftCol
  1286.         
  1287.         '重置锁值
  1288.         Valilock = False
  1289.         Wbkbhlock = False
  1290.     End With
  1291. End Sub
  1292. Private Function Fun_AllowInput() As Boolean                           '当某种条件成立时禁止文本框激活使单据处于录入状态
  1293.    
  1294.     '如果单据操作状态为浏览状态则不能显示录入载体(通用)
  1295.     If Trim(Lab_OperStatus.Caption) = "1" Then
  1296.         Exit Function
  1297.     End If
  1298.    
  1299.     '[>>
  1300.     
  1301.     '此处可以填写禁止文本框激活使单据处于录入状态的理由
  1302.    
  1303.     '<<]
  1304.    
  1305.     Fun_AllowInput = True
  1306. End Function
  1307. Private Sub Cxxswbk()                                                  'Formresize中重新显示文本框,列表框,帮助按钮(通用)
  1308.                    
  1309.     Dim Wbkpy As Integer, Wbkpy1 As Integer
  1310.     Wbkpy = 30
  1311.     Wbkpy1 = 15
  1312.     With WglrGrid
  1313.         If YdCombo.Visible Then
  1314.             YdCombo.Left = .CellLeft + .Left + Wbkpy
  1315.             YdCombo.Top = .CellTop + .Top + Wbkpy
  1316.             YdCombo.Width = .CellWidth - Wbkpy1
  1317.         End If
  1318.         If Ydcommand.Visible Then
  1319.             Ydcommand.Left = .Left + .CellLeft + .CellWidth - Ydcommand.Width + Wbkpy
  1320.             Ydcommand.Top = .Top + .CellTop + .CellHeight - Ydcommand.Height + Wbkpy
  1321.         End If
  1322.         If Ydtext.Visible Then
  1323.             If Ydcommand.Visible Then
  1324.                 If Sfblbzkd Then
  1325.                     Ydtext.Width = .CellWidth - Ydcommand.Width
  1326.                 Else
  1327.                     Ydtext.Width = .CellWidth - Wbkpy1
  1328.                 End If
  1329.             Else
  1330.                 Ydtext.Width = .CellWidth - Wbkpy1
  1331.             End If
  1332.             Ydtext.Left = .CellLeft + .Left + Wbkpy
  1333.             Ydtext.Top = .CellTop + .Top + Wbkpy
  1334.             Ydtext.Height = .CellHeight - Wbkpy1
  1335.         End If
  1336.     End With
  1337. End Sub
  1338. Private Sub Lrsjhx()                                                   '文本框录入数据回写
  1339.     
  1340.     With WglrGrid
  1341.         If YdCombo.Visible Then
  1342.             .Text = Trim(YdCombo.Text)
  1343.         End If
  1344.         If Ydtext.Visible Then
  1345.             .Text = Trim(Ydtext.Text)
  1346.         End If
  1347.         
  1348.         '(如果字段录入内容发生变化,则打开有效性判断锁)
  1349.         If Zdlrqnr <> Trim(.Text) Then
  1350.             Yxxpdlock = False
  1351.             Hyxxpdlock = False
  1352.         End If
  1353.     
  1354.         '如果字段录入内容不为空则写数据行有效性标志
  1355.         If Len(Trim(.Text)) <> 0 Then
  1356.             Call Xyxhbz(.Row)
  1357.         End If
  1358.     
  1359.         '隐藏文本框,帮助按钮,列表组合框
  1360.         Call Ycwbk
  1361.     End With
  1362. End Sub
  1363. Private Sub WglrGrid_KeyDown(KeyCode As Integer, Shift As Integer)    '网格录入增行,删行快捷键
  1364.   
  1365.     '如果单据操作状态为浏览状态则不能显示录入载体
  1366.     If Trim(Lab_OperStatus.Caption) = "1" Then
  1367.         Exit Sub
  1368.     End If
  1369.     Select Case KeyCode
  1370.         Case vbKeyF2                   '按F2键参照
  1371.             Call xswbk
  1372.             Call Lrzdbz
  1373.         Case vbKeyDelete               '删行
  1374.             Call Scdqfl
  1375.         Case vbKeyInsert               '增行
  1376.             Call zjlrfl
  1377.     End Select
  1378. End Sub
  1379. Private Sub WglrGrid_KeyPress(KeyAscii As Integer)                             '网格接受键盘录入
  1380.     '当某种条件成立时禁止文本框激活使单据处于录入状态
  1381.     If Lab_OperStatus = "2" Then
  1382.         If Trim(LrText(4).Text) = "" Then
  1383.             Tsxx = "请先输入仓库!"
  1384.             Call Xtxxts(Tsxx, 0, 1)
  1385.             LrText(4).SetFocus
  1386.             Exit Sub
  1387.         End If
  1388.     End If
  1389.     
  1390.     If Not Fun_AllowInput Then
  1391.         Exit Sub
  1392.     End If
  1393.   
  1394.     With WglrGrid
  1395.         '屏 蔽 回 车 键
  1396.         If KeyAscii = vbKeyReturn Then
  1397.             KeyAscii = 0
  1398.             Rowjsq = .Row
  1399.             Coljsq = .Col + 1
  1400.             If Coljsq > .Cols - 1 Then
  1401.                 If Rowjsq < .Rows - 1 Then
  1402.                     Rowjsq = Rowjsq + 1
  1403.                 End If
  1404.                 Coljsq = Qslz
  1405.             End If
  1406.             Do While Rowjsq <= .Rows - 1
  1407.                 If .ColHidden(Coljsq) Or (Not GridBoolean(Coljsq, 1)) Then
  1408.                     Coljsq = Coljsq + 1
  1409.                     If Coljsq > .Cols - 1 Then
  1410.                         Rowjsq = Rowjsq + 1
  1411.                         Coljsq = Qslz
  1412.                     End If
  1413.                 Else
  1414.                     Exit Do
  1415.                 End If
  1416.             Loop
  1417.             If Rowjsq <= .Rows - 1 Then
  1418.                 .Select Rowjsq, Coljsq
  1419.             End If
  1420.             Exit Sub
  1421.         End If
  1422.      
  1423.         '接受用户录入
  1424.         Select Case KeyAscii
  1425.             Case 0 To 32             '用户输入KeyAscii为0-32的键 如空格
  1426.                 '显示录入载体
  1427.                 Call xswbk
  1428.             Case Else
  1429.                 '防止非编辑字段SendKeys()出现死循环
  1430.                 If Not GridBoolean(.Col, 1) Or .Row < .FixedRows Then
  1431.                     Exit Sub
  1432.                 End If
  1433.                 '如果此字段为列表框录入则调入相应列表框
  1434.                 If GridBoolean(.Col, 3) Then
  1435.                     '列表框录入
  1436.                     Call xswbk
  1437.                 Else
  1438.                     Ydtext.Text = ""
  1439.                     '录入限制
  1440.                     Call InputFieldLimit(Ydtext, GridInt(WglrGrid.Col, 1), KeyAscii)
  1441.                     If KeyAscii = 0 Then
  1442.                         Exit Sub
  1443.                     End If
  1444.                     '如果录入字符有效则写有效行数据标志
  1445.                     Call Xyxhbz(.Row)
  1446.                     Call xswbk
  1447.                     Ydtext.Text = ""
  1448.                     Valilock = True
  1449.                     SendKeys Chr(KeyAscii), True
  1450.                     DoEvents
  1451.                     Valilock = False
  1452.                 End If
  1453.         End Select
  1454.     End With
  1455. End Sub
  1456. Private Sub zjlrfl()                                                    '增加录入分录
  1457.     
  1458.     With WglrGrid
  1459.         If Not (Ydtext.Visible Or YdCombo.Visible) Then
  1460.             If Not Fun_Drfrmyxxpd Then
  1461.                 Exit Sub
  1462.             End If
  1463.         Else
  1464.             Exit Sub
  1465.         End If
  1466.         If .Row < .FixedRows Then
  1467.             Exit Sub
  1468.         End If
  1469.         .AddItem "", .Row
  1470.         .RowHeight(.Row) = Sjhgd
  1471.         If .Row <> .Rows - 1 Then
  1472.             If .TextMatrix(.Row + 1, 0) = "*" Then
  1473.                 .TextMatrix(.Row, 0) = "*"
  1474.             Else
  1475.                 .RemoveItem .Rows - 1
  1476.             End If
  1477.         End If
  1478.         Call Xldqh
  1479.         Call Xldql
  1480.         Hyxxpdlock = False
  1481.     End With
  1482. End Sub
  1483. Private Sub Scdqfl()                                                    '删除当前分录
  1484.     Dim Answer As Integer, Scqwghz As Long, Scqwglz As Long, Hjlzte As Long, Sflrzt As Boolean
  1485.     With WglrGrid
  1486.         Scqwghz = .Row
  1487.         Scqwglz = .Col
  1488.         If .TextMatrix(.Row, 0) = "*" Then
  1489.             '判断是否为录入状态
  1490.             If Ydtext.Visible Or YdCombo.Visible Then
  1491.                 Sflrzt = True
  1492.                 Validate = True
  1493.                 Call Lrsjhx
  1494.                 Validate = False
  1495.             End If
  1496.             Call Xldqh
  1497.             Changelock = True
  1498.             .Select .Row, 0
  1499.             Changelock = False
  1500.             If Shsfts Then
  1501.                 .Cell(flexcpBackColor, .Row, Qslz, .Row, .Cols - 1) = QBColor(12)
  1502.                 Tsxx = "请确认是否删除当前记录?"
  1503.                 Yhanswer = Xtxxts(Tsxx, 2, 2)
  1504.                 If Yhanswer = 2 Then
  1505.                     .Cell(flexcpBackColor, .Row, Qslz, .Row, .Cols - 1) = &H80000005
  1506.                     Changelock = True
  1507.                     .Select Scqwghz, Scqwglz
  1508.                     Changelock = False
  1509.                     
  1510.                     '如为录入状态,则恢复录入
  1511.                     If Sflrzt Then
  1512.                         Call xswbk
  1513.                     End If
  1514.                     Exit Sub
  1515.                 End If
  1516.             End If
  1517.             .RemoveItem .Row
  1518.             If .Rows < Pmbcsjhs + .FixedRows + Fzxwghs + 1 Then
  1519.                 .AddItem ""
  1520.                 .RowHeight(.Rows - 1) = Sjhgd
  1521.             End If
  1522.             Changelock = True
  1523.             .Select .Row, Scqwglz
  1524.             Changelock = False
  1525.    
  1526.             '重新计算合计数据
  1527.             For Hjlzte = Qslz To .Cols - 1
  1528.                 Call Sjhj(Hjlzte)
  1529.             Next Hjlzte
  1530.         End If
  1531.     End With
  1532. End Sub
  1533. Private Sub Sjhj(Hjwgl As Long)                                         '网格列数据合计
  1534.     
  1535.     Dim Hjjg As Double
  1536.     If Not GridBoolean(Hjwgl, 4) Then
  1537.         Exit Sub
  1538.     End If
  1539.     With WglrGrid
  1540.         Hjjg = 0
  1541.         For jsqte = .FixedRows To .Rows - 1
  1542.             If .TextMatrix(jsqte, 0) = "*" Then
  1543.                 Hjjg = Hjjg + Val(.TextMatrix(jsqte, Hjwgl))
  1544.             End If
  1545.         Next jsqte
  1546.         If GridBoolean(Hjwgl, 5) And Hjjg = 0 Then
  1547.             HjGrid.TextMatrix(0, Hjwgl) = ""
  1548.         Else
  1549.             HjGrid.TextMatrix(0, Hjwgl) = Hjjg
  1550.         End If
  1551.     End With
  1552. End Sub
  1553. Private Sub Qkwlzd(sjh As Long, Sjl As Long)                            '清空为零字段
  1554.     
  1555.     If Not GridBoolean(Sjl, 5) Then
  1556.         Exit Sub
  1557.     End If
  1558.     With WglrGrid
  1559.         If Val(Trim(.TextMatrix(sjh, Sjl))) = 0 Then
  1560.             .TextMatrix(sjh, Sjl) = ""
  1561.         End If
  1562.     End With
  1563. End Sub
  1564. Private Sub fhyxh()                                                     '返回录入数据有效行,同时让得到焦点网格可见
  1565.     
  1566.     With WglrGrid
  1567.         If .Row >= .FixedRows Then
  1568.             If .TextMatrix(.Row, 0) <> "*" Then
  1569.                 For Rowjsq = .FixedRows To .Rows - 1
  1570.                     If .TextMatrix(Rowjsq, 0) <> "*" Then
  1571.                         Exit For
  1572.                     End If
  1573.                 Next Rowjsq
  1574.                 If Rowjsq <= .Rows - 1 Then
  1575.                     Changelock = True
  1576.                     .Select Rowjsq, .Col
  1577.                     Changelock = False
  1578.                 Else
  1579.                     Changelock = True
  1580.                     .Select .Rows - 1, .Col
  1581.                     Changelock = False
  1582.                 End If
  1583.             End If
  1584.             Call Xldqh
  1585.         End If
  1586.   End With
  1587.   
  1588. End Sub
  1589. Private Sub Xldqh()                                                      '显露当前行
  1590.   
  1591.     Dim Toprowte As Long
  1592.     With WglrGrid
  1593.         Toprowte = 0
  1594.         Do While .CellTop + .RowHeight(.Row) + Fzxwghs * Sjhgd > .Height And .TopRow <> Toprowte
  1595.             Toprowte = .TopRow
  1596.             .TopRow = .TopRow + 1
  1597.         Loop
  1598.         Toprowte = 0
  1599.         Do While .CellTop < .FixedRows * .RowHeight(0) And .TopRow <> Toprowte
  1600.             Toprowte = .TopRow
  1601.             If .TopRow > 1 Then
  1602.                 .TopRow = .TopRow - 1
  1603.             End If
  1604.         Loop
  1605.     End With
  1606. End Sub
  1607. Private Sub Xldql()                                                     '显露当前列
  1608.     
  1609.     Dim Leftcolte As Long
  1610.     With WglrGrid
  1611.         If .Col >= Qslz And .Col >= .FixedCols Then
  1612.             If .LeftCol > .Col Then
  1613.                 .LeftCol = .Col
  1614.             End If
  1615.             Leftcolte = 0
  1616.             Do While .CellLeft + .CellWidth > .Width And .LeftCol <> Leftcolte
  1617.                 Leftcolte = .LeftCol
  1618.                 .LeftCol = .LeftCol + 1
  1619.             Loop
  1620.         End If
  1621.     End With
  1622. End Sub
  1623. Private Function pdhwk(sjh As Long)                                     '判断网格行是否为空行(所有录入字段均为空*非录入字段除外)
  1624.     
  1625.     With WglrGrid
  1626.         For Coljsq = Qslz To .Cols - 1
  1627.             If Len(Trim(.TextMatrix(sjh, Coljsq))) <> 0 And GridBoolean(Coljsq, 1) Then
  1628.                 pdhwk = False
  1629.                 Exit Function
  1630.             End If
  1631.         Next Coljsq
  1632.         pdhwk = True
  1633.     End With
  1634. End Function
  1635. Private Sub Xyxhbz(sjh As Long)                                         '写行有效性标志,并判断是否增行
  1636.     
  1637.     With WglrGrid
  1638.         If .TextMatrix(sjh, 0) = "*" Then
  1639.             Exit Sub
  1640.         End If
  1641.         .TextMatrix(sjh, 0) = "*"
  1642.         If sjh >= .Rows - Fzxwghs - 1 Then
  1643.             .AddItem ""
  1644.             .RowHeight(.Rows - 1) = Sjhgd
  1645.         End If
  1646.     End With
  1647. End Sub
  1648. '*****************************以下为文本框录入处理程序(固定不变部分)*******************************'
  1649. Private Sub Wbklrwbcl(Index As Integer)    '文本框录入事后处理程序
  1650.     '以下为依据实际情况自定义部分[
  1651.     Dim adoMode As New ADODB.Recordset
  1652.     '在此填写文本框录入事后处理程序
  1653.     Select Case Index
  1654.             
  1655.         Case 4
  1656.            Set adoMode = Cw_DataEnvi.DataConnect.Execute("select whname,pricemode,ishqgl from gy_warehouse where whcode='" & Trim(LrText(Index).Text) & "' or whname='" & Trim(LrText(Index).Text) & "'")
  1657.             If Not adoMode.EOF Then
  1658.                 If conArea = 1 Then
  1659.                     If CBool(adoMode.Fields("ishqgl")) Then
  1660.                         WglrGrid.ColHidden(Sydz("005", GridStr(), Szzls)) = False
  1661.                     Else
  1662.                         WglrGrid.ColHidden(Sydz("005", GridStr(), Szzls)) = True
  1663.                     End If
  1664.                 End If
  1665.                 If Trim(adoMode.Fields("PriceMode")) = "计划价法" Then
  1666.                     WglrGrid.ColHidden(Sydz("009", GridStr(), Szzls)) = False
  1667.                     WglrGrid.ColHidden(Sydz("011", GridStr(), Szzls)) = False
  1668.                 Else
  1669.                     WglrGrid.ColHidden(Sydz("009", GridStr(), Szzls)) = True
  1670.                     WglrGrid.ColHidden(Sydz("011", GridStr(), Szzls)) = True
  1671.                 End If
  1672.                 
  1673.             End If
  1674.             If (LrText(Index).Tag <> "" And LrText(Index).Tag = LrText(Index + 1).Tag) Then
  1675.                 Tsxx = "所选仓库与转入仓库相同!"
  1676.                 Call Xtxxts(Tsxx, 0, 1)
  1677.                 LrText(Index).Tag = "": LrText(Index).Text = ""
  1678.                 LrText(Index).SetFocus
  1679.             End If
  1680.             For rjsq = WglrGrid.FixedRows To WglrGrid.Rows - 1
  1681.                WglrGrid.TextMatrix(rjsq, Sydz("005", GridStr(), Szzls)) = ""
  1682.             Next rjsq
  1683.             Call Cshhjwg
  1684.             
  1685.         Case 5
  1686.            Set adoMode = Cw_DataEnvi.DataConnect.Execute("select whname,pricemode,ishqgl from gy_warehouse where whcode='" & Trim(LrText(Index).Text) & "' or whname='" & Trim(LrText(Index).Text) & "'")
  1687.             If Not adoMode.EOF Then
  1688.                 PriceMode = Trim(adoMode.Fields("PriceMode") & "")
  1689.                 If conArea = 1 Then
  1690.                     If CBool(adoMode.Fields("ishqgl")) Then
  1691.                         WglrGrid.ColHidden(Sydz("006", GridStr(), Szzls)) = False
  1692.                     Else
  1693.                         WglrGrid.ColHidden(Sydz("006", GridStr(), Szzls)) = True
  1694.                     End If
  1695.                 End If
  1696.                 If Trim(adoMode.Fields("PriceMode")) = "计划价法" Then
  1697.                     WglrGrid.ColHidden(Sydz("009", GridStr(), Szzls)) = False
  1698.                     WglrGrid.ColHidden(Sydz("011", GridStr(), Szzls)) = False
  1699.                 Else
  1700.                     WglrGrid.ColHidden(Sydz("009", GridStr(), Szzls)) = True
  1701.                     WglrGrid.ColHidden(Sydz("011", GridStr(), Szzls)) = True
  1702.                 End If
  1703.             End If
  1704.             If (LrText(Index).Tag <> "" And LrText(Index).Tag = LrText(Index - 1).Tag) Then
  1705.                 Tsxx = "所选仓库与转出仓库相同!"
  1706.                 Call Xtxxts(Tsxx, 0, 1)
  1707.                 LrText(Index).Tag = "": LrText(Index).Text = ""
  1708.                 LrText(Index).SetFocus
  1709.             End If
  1710.             For rjsq = WglrGrid.FixedRows To WglrGrid.Rows - 1
  1711.                WglrGrid.TextMatrix(rjsq, Sydz("006", GridStr(), Szzls)) = ""
  1712.             Next rjsq
  1713.             Call Cshhjwg
  1714.     End Select
  1715.      
  1716.     ']以上为依据实际情况自定义部分
  1717. End Sub
  1718. Private Sub LrText_Change(Index As Integer)
  1719.     '屏蔽程序改变控制
  1720.     If TextChangeLock Then
  1721.         Exit Sub
  1722.     End If
  1723.    
  1724.     TextValiJudgeLock(Index) = False    '打开有效性判断锁
  1725.         
  1726.     '限制字段录入长度
  1727.           
  1728.     TextChangeLock = True  '加锁(防止执行Lrtext_Change)
  1729.     Call TextChangeLimit(LrText(Index), Textint(Index, 1))  '去掉无效字符
  1730.         Select Case Textint(Index, 1)
  1731.             Case 8, 11       '金额型
  1732.                 Call Sjgskz(LrText(Index), Xtjezws - Xtjexsws - 1, Xtjexsws)
  1733.             Case 9, 12       '数量型
  1734.                 Call Sjgskz(LrText(Index), Xtslzws - Xtslxsws - 1, Xtslxsws)
  1735.             Case 10          '单价型
  1736.                 Call Sjgskz(LrText(Index), Xtdjzws - Xtdjxsws - 1, Xtdjxsws)
  1737.             Case Else        '其他小数类型控制
  1738.                 If Textint(Index, 6) <> 0 Or Textint(Index, 7) <> 0 Then
  1739.                     Call Sjgskz(LrText(Index), Textint(Index, 6), Textint(Index, 7))
  1740.                 End If
  1741.         End Select
  1742.         
  1743.         TextChangeLock = False '解锁
  1744.      
  1745. End Sub
  1746. Private Sub LrText_GotFocus(Index As Integer)                                                 '文本框得到焦点,显示相应信息
  1747.     Call TextShow(Index)
  1748. End Sub
  1749. Private Sub LrText_KeyDown(Index As Integer, KeyCode As Integer, Shift As Integer)            '字段按F2键提供帮助
  1750.     
  1751.     Select Case KeyCode
  1752.         Case vbKeyF2
  1753.             Call Text_Help(Index)
  1754.     End Select
  1755. End Sub
  1756. Private Sub LrText_KeyPress(Index As Integer, KeyAscii As Integer)                            '文本框录入事中控制
  1757.     Call InputFieldLimit(LrText(Index), Textint(Index, 1), KeyAscii)
  1758. End Sub
  1759. Private Sub LrText_LostFocus(Index As Integer)                                                '文本框失去焦点进行有效性判断及相应处理
  1760.     
  1761.     If Textint(Index, 9) = 0 Or Textint(Index, 9) = 1 Then '事中判断
  1762.         Call TextYxxpd(Index)
  1763.     End If
  1764. End Sub
  1765. Private Sub Ydcommand1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single) '点击按钮
  1766.     Call Text_Help(Ydcommand1.Tag)
  1767. End Sub
  1768. Private Sub Text_Help(Index As Integer)                                                       '录入字段帮助
  1769.     
  1770.     If Not Ydcommand1.Visible Then
  1771.         Exit Sub
  1772.     End If
  1773.     TextValiLock = True
  1774.      If Textint(Index, 2) <> 1 Then
  1775.         strHlpR = FunHlpR(Trim(Textstr(Index, 4)), "czybm", Xtczybm)
  1776.      End If
  1777.     Call Drbmhelp(Textint(Index, 2), Textstr(Index, 4), Trim(LrText(Index).Text))
  1778.     If Len(Xtfhcs) <> 0 Then
  1779.         If Textint(Index, 3) = 1 Then
  1780.             LrText(Index).Text = Xtfhcsfz
  1781.             LrText(Index).Tag = Xtfhcs
  1782.         Else
  1783.             LrText(Index).Text = Xtfhcs
  1784.             LrText(Index).Tag = Xtfhcsfz
  1785.         End If
  1786.     End If
  1787.     TextValiLock = False
  1788.     LrText(Index).SetFocus
  1789. End Sub
  1790. Private Sub TextShow(Index As Integer)        '文本框得到焦点,显示相应信息
  1791.     '如果文本框有帮助,则显示帮助按钮
  1792.     If Textboolean(Index, 1) Then
  1793.         Ydcommand1.Visible = True
  1794.         Ydcommand1.Move LrText(Index).Left + LrText(Index).Width, LrText(Index).Top
  1795.         Ydcommand1.Tag = Index
  1796.     Else
  1797.         Ydcommand1.Tag = ""
  1798.         Ydcommand1.Visible = False
  1799.     End If
  1800.     
  1801.     '[>>
  1802.     '可在此处定义其他处理动作
  1803.     '<<]
  1804. End Sub
  1805. Private Sub Wbkcsh()                          '录入文本框初始化
  1806.     Dim Int_TabIndex As Integer         'Tab焦点计数器
  1807.   
  1808.     '单据录入中文本框焦点由0开始
  1809.     LrText(0).TabIndex = 0
  1810.   
  1811.     '最大录入文本框索引值
  1812.     Max_Text_Index = Textvar(1)
  1813.   
  1814.     ReDim TextValiJudgeLock(Max_Text_Index)
  1815.     For jsqte = 0 To Max_Text_Index
  1816.         
  1817.         '判断此文本框录入索引号是否存在,如存在则对其进行初始化
  1818.         If Len(Trim(Textstr(jsqte, 1))) <> 0 Then
  1819.         
  1820.             '自动装入录入文本框和其解释标签
  1821.             If jsqte <> 0 Then
  1822.                 Load LrText(jsqte)
  1823.                 Load TsLabel(jsqte)
  1824.            
  1825.                 '判断录入文本框是否显示
  1826.                 If Textboolean(jsqte, 4) Then
  1827.                     LrText(jsqte).Visible = True
  1828.                     TsLabel(jsqte).Visible = True
  1829.                 End If
  1830.             
  1831.                 '判断文本框是否可编辑
  1832.                 If Textboolean(jsqte, 5) Then
  1833.                     LrText(jsqte).Enabled = True
  1834.                 Else
  1835.                     LrText(jsqte).Enabled = False
  1836.                 End If
  1837.             End If
  1838.            
  1839.            '初始化其内容
  1840.             TextChangeLock = True
  1841.             LrText(jsqte).Text = ""
  1842.             LrText(jsqte).Tag = ""
  1843.             If Textint(jsqte, 5) <> 0 Then
  1844.                 LrText(jsqte).MaxLength = Textint(jsqte, 5)
  1845.             End If
  1846.             TextChangeLock = False
  1847.         
  1848.             '设置文本框位置及大小,并设置相应标签内容及其位置
  1849.             LrText(jsqte).Move Textint(jsqte, 13), Textint(jsqte, 12), Textint(jsqte, 11), Textint(jsqte, 10)
  1850.             TsLabel(jsqte).Caption = Textstr(jsqte, 7) & ":"
  1851.             TsLabel(jsqte).Move Textint(jsqte, 13) - TsLabel(jsqte).Width - 20, Textint(jsqte, 12) + (Textint(jsqte, 10) - TsLabel(jsqte).Height) / 2 - 30
  1852.             
  1853.         End If
  1854.      
  1855.         '将文本框有效性判断进行加锁,在文本框内容发生变化时将锁打开
  1856.         TextValiJudgeLock(jsqte) = True
  1857.       
  1858.     Next jsqte
  1859.     
  1860.     '设置文本框焦点转移顺序(前提文本焦点从0至Max_Text_Index)
  1861.     For Int_TabIndex = 0 To Max_Text_Index
  1862.         For jsqte = 0 To Max_Text_Index
  1863.             If Textint(jsqte, 14) = Int_TabIndex Then
  1864.                LrText(jsqte).TabIndex = Int_TabIndex
  1865.             End If
  1866.         Next jsqte
  1867.     Next Int_TabIndex
  1868.   
  1869. End Sub
  1870. Private Function TextYxxpd(Index As Integer) As Boolean           '文本框有效性判断
  1871.   
  1872.     Dim Sqlstr As String
  1873.     Dim Findrec As New ADODB.Recordset
  1874.   
  1875.     '按帮助不进行有效性判断
  1876.   
  1877.     If TextValiLock Then
  1878.         TextValiLock = False
  1879.         TextYxxpd = True
  1880.         Exit Function
  1881.     End If
  1882.   
  1883.     '文本框内容未曾改变不进行有效性判断
  1884.   
  1885.     If TextValiJudgeLock(Index) Then
  1886.         Ydcommand1.Visible = False
  1887.         TextYxxpd = True
  1888.         Exit Function
  1889.     End If
  1890.   
  1891.     '文本框内容为空认为有效,并清空其Tag值
  1892.   
  1893.     If Trim(LrText(Index)) = "" Then
  1894.         LrText(Index).Tag = ""
  1895.         Call Wbklrwbcl(Index)
  1896.         Ydcommand1.Visible = False
  1897.         TextValiJudgeLock(Index) = True
  1898.         TextYxxpd = True
  1899.         Exit Function
  1900.     End If
  1901.    
  1902.     '[>>
  1903.       
  1904.     '可在此加入不做有效性判断的理由(参照上面程序)
  1905.       
  1906.     '<<]
  1907.   
  1908.     Select Case Textint(Index, 4)
  1909.         Case 1      '编码型
  1910.             Sqlstr = Trim(Textstr(Index, 5))
  1911.             Sqlstr = Replace(Sqlstr, "@", "'" + Trim(LrText(Index).Text) + "'")
  1912.             Set Findrec = Cw_DataEnvi.DataConnect.Execute(Sqlstr)
  1913.             If Findrec.EOF Then
  1914.                 Call Xtxxts(Trim(Textstr(Index, 6)), 0, 1)
  1915.                 LrText(Index).SetFocus
  1916.                 Exit Function
  1917.             Else
  1918.                 Select Case Textint(Index, 3)
  1919.                     Case 0
  1920.                         If Len(Trim(Textstr(Index, 2))) <> 0 Then
  1921.                             LrText(Index).Text = Trim(Findrec.Fields(Trim(Textstr(Index, 2))))
  1922.                         End If
  1923.                         If Len(Trim(Textstr(Index, 3) & "")) <> 0 Then
  1924.                             LrText(Index).Tag = Trim(Findrec.Fields(Trim(Textstr(Index, 3))))
  1925.                         End If
  1926.                     Case 1
  1927.                         If Len(Trim(Textstr(Index, 3) & "")) <> 0 Then
  1928.                             LrText(Index).Text = Trim(Findrec.Fields(Trim(Textstr(Index, 3))))
  1929.                         End If
  1930.                         If Len(Trim(Textstr(Index, 2))) <> 0 Then
  1931.                             LrText(Index).Tag = Trim(Findrec.Fields(Trim(Textstr(Index, 2))))
  1932.                         End If
  1933.                 End Select
  1934.             End If
  1935.         Case 2      '日期型
  1936.             If IsDate(LrText(Index).Text) Then
  1937.                 LrText(Index).Text = Format(LrText(Index).Text, "yyyy-mm-dd")
  1938.                 If Val(Mid(LrText(Index), 1, 4)) < 1900 Then
  1939.                     LrText(Index).Text = "1900" + Mid(LrText(Index), 5, 6)
  1940.                 End If
  1941.             Else
  1942.                 Tsxx = "非法公历日期!(格式:" + Format(Date, "yyyy-mm-dd") + ")"
  1943.                 Call Xtxxts(Tsxx, 0, 1)
  1944.                 LrText(Index).SetFocus
  1945.                 Exit Function
  1946.             End If
  1947.         Case 3      '其他类型
  1948.     End Select
  1949.     
  1950.     '隐藏帮助按钮
  1951.     Ydcommand1.Visible = False
  1952.    
  1953.     '如果有效则加锁,用户不改变内容则不再进行有效性判断
  1954.     TextValiJudgeLock(Index) = True
  1955.     '调用文本框事后处理程序
  1956.     Call Wbklrwbcl(Index)
  1957.    
  1958.     '有效性判断通过则返回True
  1959.     TextYxxpd = True
  1960.     
  1961. End Function
  1962. Public Sub VisulGrid()  '显示网格项目
  1963.  
  1964. With WglrGrid
  1965.     If Val(conArea) = 0 Then
  1966.         .ColHidden(Sydz("005", GridStr(), Szzls)) = True
  1967.         .ColHidden(Sydz("006", GridStr(), Szzls)) = True
  1968.     Else
  1969.         .ColHidden(Sydz("005", GridStr(), Szzls)) = False
  1970.         .ColHidden(Sydz("006", GridStr(), Szzls)) = False
  1971.     End If
  1972.     
  1973.     If Val(conBatch) = 1 Then
  1974.         .ColHidden(Sydz("007", GridStr(), Szzls)) = False
  1975.     Else
  1976.         .ColHidden(Sydz("007", GridStr(), Szzls)) = True
  1977.     End If
  1978. End With
  1979. Call Cshhjwg
  1980. End Sub