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

企业管理

开发平台:

Visual Basic

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