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

企业管理

开发平台:

Visual Basic

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