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

企业管理

开发平台:

Visual Basic

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