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

企业管理

开发平台:

Visual Basic

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