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

企业管理

开发平台:

Visual Basic

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