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

企业管理

开发平台:

Visual Basic

  1. VERSION 5.00
  2. Object = "{BEEECC20-4D5F-4F8B-BFDC-5D9B6FBDE09D}#1.0#0"; "vsflex8.ocx"
  3. Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "mscomctl.ocx"
  4. Begin VB.Form Balance_KF_HandBalance 
  5.    Caption         =   "手工结算"
  6.    ClientHeight    =   6315
  7.    ClientLeft      =   60
  8.    ClientTop       =   345
  9.    ClientWidth     =   10080
  10.    HelpContextID   =   1215002
  11.    Icon            =   "结算_手工结算.frx":0000
  12.    LinkTopic       =   "Form3"
  13.    ScaleHeight     =   6315
  14.    ScaleWidth      =   10080
  15.    StartUpPosition =   2  '屏幕中心
  16.    Begin VB.Timer Timer2 
  17.       Enabled         =   0   'False
  18.       Interval        =   1
  19.       Left            =   4500
  20.       Top             =   570
  21.    End
  22.    Begin VB.Timer Timer1 
  23.       Enabled         =   0   'False
  24.       Interval        =   1
  25.       Left            =   3510
  26.       Top             =   540
  27.    End
  28.    Begin VB.ComboBox Combo1 
  29.       Height          =   300
  30.       ItemData        =   "结算_手工结算.frx":1042
  31.       Left            =   7785
  32.       List            =   "结算_手工结算.frx":1044
  33.       Style           =   2  'Dropdown List
  34.       TabIndex        =   5
  35.       Top             =   585
  36.       Width           =   2235
  37.    End
  38.    Begin VB.CommandButton ydcommand 
  39.       Height          =   300
  40.       Left            =   1287
  41.       Picture         =   "结算_手工结算.frx":1046
  42.       Style           =   1  'Graphical
  43.       TabIndex        =   4
  44.       Top             =   4379
  45.       Visible         =   0   'False
  46.       Width           =   300
  47.    End
  48.    Begin VB.TextBox Ydtext 
  49.       BackColor       =   &H80000018&
  50.       BorderStyle     =   0  'None
  51.       Height          =   309
  52.       Left            =   1671
  53.       MultiLine       =   -1  'True
  54.       TabIndex        =   3
  55.       Top             =   3795
  56.       Visible         =   0   'False
  57.       Width           =   1200
  58.    End
  59.    Begin VB.ComboBox YdCombo 
  60.       Height          =   300
  61.       Left            =   2904
  62.       Style           =   2  'Dropdown List
  63.       TabIndex        =   2
  64.       Top             =   3795
  65.       Visible         =   0   'False
  66.       Width           =   1170
  67.    End
  68.    Begin VB.OptionButton Option1 
  69.       Caption         =   "按数量分摊"
  70.       Height          =   239
  71.       Left            =   7320
  72.       TabIndex        =   1
  73.       Top             =   3915
  74.       Width           =   1229
  75.    End
  76.    Begin VB.OptionButton Option2 
  77.       Caption         =   "按金额分摊"
  78.       Height          =   240
  79.       Left            =   8760
  80.       TabIndex        =   0
  81.       Top             =   3915
  82.       Width           =   1229
  83.    End
  84.    Begin MSComctlLib.ImageList ImageList1 
  85.       Left            =   2400
  86.       Top             =   390
  87.       _ExtentX        =   1005
  88.       _ExtentY        =   1005
  89.       BackColor       =   -2147483643
  90.       ImageWidth      =   16
  91.       ImageHeight     =   16
  92.       MaskColor       =   12632256
  93.       _Version        =   393216
  94.       BeginProperty Images {2C247F25-8591-11D1-B16A-00C0F0283628} 
  95.          NumListImages   =   11
  96.          BeginProperty ListImage1 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  97.             Picture         =   "结算_手工结算.frx":13D0
  98.             Key             =   "sz"
  99.          EndProperty
  100.          BeginProperty ListImage2 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  101.             Picture         =   "结算_手工结算.frx":176A
  102.             Key             =   "dy"
  103.          EndProperty
  104.          BeginProperty ListImage3 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  105.             Picture         =   "结算_手工结算.frx":1B04
  106.             Key             =   "yl"
  107.          EndProperty
  108.          BeginProperty ListImage4 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  109.             Picture         =   "结算_手工结算.frx":1E9E
  110.             Key             =   "gl"
  111.          EndProperty
  112.          BeginProperty ListImage5 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  113.             Picture         =   "结算_手工结算.frx":2238
  114.             Key             =   "rkd"
  115.          EndProperty
  116.          BeginProperty ListImage6 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  117.             Picture         =   "结算_手工结算.frx":25D2
  118.             Key             =   "fp"
  119.          EndProperty
  120.          BeginProperty ListImage7 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  121.             Picture         =   "结算_手工结算.frx":296C
  122.             Key             =   "fyd"
  123.          EndProperty
  124.          BeginProperty ListImage8 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  125.             Picture         =   "结算_手工结算.frx":2D06
  126.             Key             =   "fyp"
  127.          EndProperty
  128.          BeginProperty ListImage9 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  129.             Picture         =   "结算_手工结算.frx":30A0
  130.             Key             =   "js"
  131.          EndProperty
  132.          BeginProperty ListImage10 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  133.             Picture         =   "结算_手工结算.frx":343A
  134.             Key             =   "bz"
  135.          EndProperty
  136.          BeginProperty ListImage11 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  137.             Picture         =   "结算_手工结算.frx":37D4
  138.             Key             =   "tc"
  139.          EndProperty
  140.       EndProperty
  141.    End
  142.    Begin VSFlex8Ctl.VSFlexGrid BanlGrid1 
  143.       Height          =   2865
  144.       Left            =   75
  145.       TabIndex        =   6
  146.       Top             =   915
  147.       Width           =   9945
  148.       _cx             =   5080
  149.       _cy             =   5080
  150.       Appearance      =   1
  151.       BorderStyle     =   1
  152.       Enabled         =   -1  'True
  153.       BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
  154.          Name            =   "宋体"
  155.          Size            =   9
  156.          Charset         =   134
  157.          Weight          =   400
  158.          Underline       =   0   'False
  159.          Italic          =   0   'False
  160.          Strikethrough   =   0   'False
  161.       EndProperty
  162.       MousePointer    =   0
  163.       BackColor       =   -2147483643
  164.       ForeColor       =   -2147483640
  165.       BackColorFixed  =   -2147483633
  166.       ForeColorFixed  =   -2147483630
  167.       BackColorSel    =   -2147483643
  168.       ForeColorSel    =   -2147483641
  169.       BackColorBkg    =   8421504
  170.       BackColorAlternate=   -2147483643
  171.       GridColor       =   -2147483633
  172.       GridColorFixed  =   -2147483632
  173.       TreeColor       =   -2147483632
  174.       FloodColor      =   192
  175.       SheetBorder     =   -2147483642
  176.       FocusRect       =   1
  177.       HighLight       =   1
  178.       AllowSelection  =   -1  'True
  179.       AllowBigSelection=   -1  'True
  180.       AllowUserResizing=   0
  181.       SelectionMode   =   0
  182.       GridLines       =   1
  183.       GridLinesFixed  =   2
  184.       GridLineWidth   =   1
  185.       Rows            =   5000
  186.       Cols            =   10
  187.       FixedRows       =   1
  188.       FixedCols       =   0
  189.       RowHeightMin    =   0
  190.       RowHeightMax    =   0
  191.       ColWidthMin     =   0
  192.       ColWidthMax     =   0
  193.       ExtendLastCol   =   0   'False
  194.       FormatString    =   ""
  195.       ScrollTrack     =   0   'False
  196.       ScrollBars      =   3
  197.       ScrollTips      =   0   'False
  198.       MergeCells      =   0
  199.       MergeCompare    =   0
  200.       AutoResize      =   -1  'True
  201.       AutoSizeMode    =   0
  202.       AutoSearch      =   0
  203.       AutoSearchDelay =   2
  204.       MultiTotals     =   -1  'True
  205.       SubtotalPosition=   0
  206.       OutlineBar      =   0
  207.       OutlineCol      =   0
  208.       Ellipsis        =   0
  209.       ExplorerBar     =   0
  210.       PicturesOver    =   0   'False
  211.       FillStyle       =   0
  212.       RightToLeft     =   0   'False
  213.       PictureType     =   0
  214.       TabBehavior     =   0
  215.       OwnerDraw       =   0
  216.       Editable        =   0
  217.       ShowComboButton =   1
  218.       WordWrap        =   0   'False
  219.       TextStyle       =   0
  220.       TextStyleFixed  =   0
  221.       OleDragMode     =   0
  222.       OleDropMode     =   0
  223.       DataMode        =   0
  224.       VirtualData     =   -1  'True
  225.       DataMember      =   ""
  226.       ComboSearch     =   3
  227.       AutoSizeMouse   =   -1  'True
  228.       FrozenRows      =   0
  229.       FrozenCols      =   0
  230.       AllowUserFreezing=   0
  231.       BackColorFrozen =   0
  232.       ForeColorFrozen =   0
  233.       WallPaperAlignment=   9
  234.       AccessibleName  =   ""
  235.       AccessibleDescription=   ""
  236.       AccessibleValue =   ""
  237.       AccessibleRole  =   24
  238.    End
  239.    Begin VSFlex8Ctl.VSFlexGrid BanlGrid2 
  240.       Height          =   2010
  241.       Left            =   75
  242.       TabIndex        =   7
  243.       Top             =   4200
  244.       Width           =   9945
  245.       _cx             =   5080
  246.       _cy             =   5080
  247.       Appearance      =   1
  248.       BorderStyle     =   1
  249.       Enabled         =   -1  'True
  250.       BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
  251.          Name            =   "宋体"
  252.          Size            =   9
  253.          Charset         =   134
  254.          Weight          =   400
  255.          Underline       =   0   'False
  256.          Italic          =   0   'False
  257.          Strikethrough   =   0   'False
  258.       EndProperty
  259.       MousePointer    =   0
  260.       BackColor       =   -2147483643
  261.       ForeColor       =   -2147483640
  262.       BackColorFixed  =   -2147483633
  263.       ForeColorFixed  =   -2147483630
  264.       BackColorSel    =   -2147483643
  265.       ForeColorSel    =   -2147483640
  266.       BackColorBkg    =   8421504
  267.       BackColorAlternate=   -2147483643
  268.       GridColor       =   -2147483633
  269.       GridColorFixed  =   -2147483632
  270.       TreeColor       =   -2147483632
  271.       FloodColor      =   192
  272.       SheetBorder     =   -2147483642
  273.       FocusRect       =   1
  274.       HighLight       =   1
  275.       AllowSelection  =   -1  'True
  276.       AllowBigSelection=   -1  'True
  277.       AllowUserResizing=   0
  278.       SelectionMode   =   0
  279.       GridLines       =   1
  280.       GridLinesFixed  =   2
  281.       GridLineWidth   =   1
  282.       Rows            =   5000
  283.       Cols            =   10
  284.       FixedRows       =   1
  285.       FixedCols       =   0
  286.       RowHeightMin    =   0
  287.       RowHeightMax    =   0
  288.       ColWidthMin     =   0
  289.       ColWidthMax     =   0
  290.       ExtendLastCol   =   0   'False
  291.       FormatString    =   ""
  292.       ScrollTrack     =   0   'False
  293.       ScrollBars      =   3
  294.       ScrollTips      =   0   'False
  295.       MergeCells      =   0
  296.       MergeCompare    =   0
  297.       AutoResize      =   -1  'True
  298.       AutoSizeMode    =   0
  299.       AutoSearch      =   0
  300.       AutoSearchDelay =   2
  301.       MultiTotals     =   -1  'True
  302.       SubtotalPosition=   1
  303.       OutlineBar      =   0
  304.       OutlineCol      =   0
  305.       Ellipsis        =   0
  306.       ExplorerBar     =   0
  307.       PicturesOver    =   0   'False
  308.       FillStyle       =   0
  309.       RightToLeft     =   0   'False
  310.       PictureType     =   0
  311.       TabBehavior     =   0
  312.       OwnerDraw       =   0
  313.       Editable        =   0
  314.       ShowComboButton =   1
  315.       WordWrap        =   0   'False
  316.       TextStyle       =   0
  317.       TextStyleFixed  =   0
  318.       OleDragMode     =   0
  319.       OleDropMode     =   0
  320.       DataMode        =   0
  321.       VirtualData     =   -1  'True
  322.       DataMember      =   ""
  323.       ComboSearch     =   3
  324.       AutoSizeMouse   =   -1  'True
  325.       FrozenRows      =   0
  326.       FrozenCols      =   0
  327.       AllowUserFreezing=   0
  328.       BackColorFrozen =   0
  329.       ForeColorFrozen =   0
  330.       WallPaperAlignment=   9
  331.       AccessibleName  =   ""
  332.       AccessibleDescription=   ""
  333.       AccessibleValue =   ""
  334.       AccessibleRole  =   24
  335.    End
  336.    Begin MSComctlLib.Toolbar SzToolbar1 
  337.       Align           =   1  'Align Top
  338.       Height          =   555
  339.       Left            =   0
  340.       TabIndex        =   8
  341.       Top             =   0
  342.       Width           =   10080
  343.       _ExtentX        =   17780
  344.       _ExtentY        =   979
  345.       ButtonWidth     =   1138
  346.       ButtonHeight    =   926
  347.       Appearance      =   1
  348.       Style           =   1
  349.       ImageList       =   "ImageList1"
  350.       _Version        =   393216
  351.       BeginProperty Buttons {66833FE8-8583-11D1-B16A-00C0F0283628} 
  352.          NumButtons      =   11
  353.          BeginProperty Button1 {66833FEA-8583-11D1-B16A-00C0F0283628} 
  354.             Caption         =   "设置"
  355.             Key             =   "ymsz"
  356.             Object.ToolTipText     =   "打印页面设置"
  357.             ImageKey        =   "sz"
  358.          EndProperty
  359.          BeginProperty Button2 {66833FEA-8583-11D1-B16A-00C0F0283628} 
  360.             Caption         =   "打印"
  361.             Key             =   "dy"
  362.             ImageKey        =   "dy"
  363.          EndProperty
  364.          BeginProperty Button3 {66833FEA-8583-11D1-B16A-00C0F0283628} 
  365.             Caption         =   "预览"
  366.             Key             =   "yl"
  367.             ImageKey        =   "yl"
  368.          EndProperty
  369.          BeginProperty Button4 {66833FEA-8583-11D1-B16A-00C0F0283628} 
  370.             Caption         =   "过滤"
  371.             Key             =   "gl"
  372.             ImageKey        =   "gl"
  373.          EndProperty
  374.          BeginProperty Button5 {66833FEA-8583-11D1-B16A-00C0F0283628} 
  375.             Style           =   3
  376.          EndProperty
  377.          BeginProperty Button6 {66833FEA-8583-11D1-B16A-00C0F0283628} 
  378.             Caption         =   "入库单"
  379.             Key             =   "rkd"
  380.             Object.ToolTipText     =   "选择入库单"
  381.             ImageKey        =   "rkd"
  382.          EndProperty
  383.          BeginProperty Button7 {66833FEA-8583-11D1-B16A-00C0F0283628} 
  384.             Caption         =   "发票"
  385.             Key             =   "fp"
  386.             Object.ToolTipText     =   "选择发票"
  387.             ImageKey        =   "fp"
  388.          EndProperty
  389.          BeginProperty Button8 {66833FEA-8583-11D1-B16A-00C0F0283628} 
  390.             Caption         =   "结算"
  391.             Key             =   "js"
  392.             Object.ToolTipText     =   "结算"
  393.             ImageKey        =   "js"
  394.          EndProperty
  395.          BeginProperty Button9 {66833FEA-8583-11D1-B16A-00C0F0283628} 
  396.             Style           =   3
  397.          EndProperty
  398.          BeginProperty Button10 {66833FEA-8583-11D1-B16A-00C0F0283628} 
  399.             Caption         =   "帮助"
  400.             Key             =   "bz"
  401.             ImageKey        =   "bz"
  402.          EndProperty
  403.          BeginProperty Button11 {66833FEA-8583-11D1-B16A-00C0F0283628} 
  404.             Caption         =   "退出"
  405.             Key             =   "fh"
  406.             ImageKey        =   "tc"
  407.          EndProperty
  408.       EndProperty
  409.       BorderStyle     =   1
  410.       Begin MSComctlLib.ProgressBar ProgressBar1 
  411.          Height          =   105
  412.          Left            =   6390
  413.          TabIndex        =   14
  414.          Top             =   270
  415.          Visible         =   0   'False
  416.          Width           =   3435
  417.          _ExtentX        =   6059
  418.          _ExtentY        =   185
  419.          _Version        =   393216
  420.          Appearance      =   0
  421.          Max             =   2000
  422.       End
  423.    End
  424.    Begin VB.Label Label2 
  425.       AutoSize        =   -1  'True
  426.       Caption         =   "结算类型:"
  427.       Height          =   180
  428.       Left            =   6960
  429.       TabIndex        =   13
  430.       Top             =   645
  431.       Width           =   810
  432.    End
  433.    Begin VB.Label Lab_Row 
  434.       Alignment       =   2  'Center
  435.       Appearance      =   0  'Flat
  436.       BackColor       =   &H80000005&
  437.       BackStyle       =   0  'Transparent
  438.       ForeColor       =   &H00FF0000&
  439.       Height          =   211
  440.       Left            =   72
  441.       TabIndex        =   12
  442.       Top             =   0
  443.       Width           =   319
  444.    End
  445.    Begin VB.Label Label1 
  446.       AutoSize        =   -1  'True
  447.       Caption         =   "结算汇总:"
  448.       Height          =   180
  449.       Left            =   135
  450.       TabIndex        =   11
  451.       Top             =   645
  452.       Width           =   810
  453.    End
  454.    Begin VB.Label Label3 
  455.       AutoSize        =   -1  'True
  456.       Caption         =   "结算费用汇总:"
  457.       Height          =   180
  458.       Left            =   105
  459.       TabIndex        =   10
  460.       Top             =   3945
  461.       Width           =   1170
  462.    End
  463.    Begin VB.Label Label4 
  464.       AutoSize        =   -1  'True
  465.       Caption         =   "费用分摊方式:"
  466.       Height          =   180
  467.       Left            =   6000
  468.       TabIndex        =   9
  469.       Top             =   3945
  470.       Width           =   1170
  471.    End
  472. End
  473. Attribute VB_Name = "Balance_KF_HandBalance"
  474. Attribute VB_GlobalNameSpace = False
  475. Attribute VB_Creatable = False
  476. Attribute VB_PredeclaredId = True
  477. Attribute VB_Exposed = False
  478. '**************************************************************************************
  479. '*    模 块 名 称 :手工结算
  480. '*    功 能 描 述 :
  481. '*    程序员姓名  :周化江
  482. '*    最后修改人  :周化江
  483. '*    最后修改时间:2001/10/16
  484. '*    备        注:程序中所有依实际情况自定义部分均用[>> <<]括起
  485. '*
  486. '*    1.每次调入外部功能窗体,均要加锁ChangeLock=True,窗体关闭后解锁ChangeLock=false
  487. '*
  488. '*    3.Lab_OperStatus 用此标签来标识单据录入状态(默认值为1) 1-浏览 2-修改
  489. '*
  490. '***************************************************************************************
  491.  
  492. '以下为自定义变量
  493.  
  494. '其它固定使用变量
  495. Dim Tsxx As String                              '系统信息提示(Fixed)
  496. Dim ReportTitle As String                       '报表主标题(Fixed)
  497.    
  498. '以下为固定使用变量(网格)
  499. Dim Cxnrrec As New ADODB.Recordset              '显示查询内容动态集
  500. Dim Dyymctbl As New DY_Dyymsz                   '打印页面窗体变量
  501. Dim GridCode As String                          '显示网格网格代码
  502. Dim GridInf() As Variant                        '整个网格设置信息
  503. Dim Pmbcsjhs As Long                            '屏幕网格保持数据行数(大于等于1)
  504. Dim Fzxwghs As Integer                          '辅助项网格行数(包括合计行)
  505. Dim Sfxshjwg As Boolean                         '是否显示合计网格
  506. Dim Qslz As Long                                '网格隐藏(非操作显示)列数
  507. Dim Sjhgd As Double                             '网格数据行高度
  508. Dim GridBoolean() As Boolean                    '网格列信息(布尔型)
  509. Dim GridStr()  As String                        '网格列信息(字符型)
  510. Dim GridInt() As Integer                        '网格列信息(整型)
  511. Dim Sfblbzkd As Boolean                         '是否保留帮助宽度(字段提供帮助时,是否为按钮保留空间)
  512. Dim Dqlrwgh As Long                             '当前录入数据网格行
  513. Dim Dqlrwgl As Long                             '当前录入数据网格列
  514. Dim Dqlkwgh As Long                             '刚刚离开网格行(不一定为录入行)
  515. Dim Dqlkwgl As Long                             '刚刚离开网格列
  516. Dim Dqtoprow As Long                            '当前录入状态时最上端可视行
  517. Dim Dqleftcol As Long                           '当前录入状态时最左端可视列
  518. Dim Zdlrqnr As String                           '字段录入修改前内容(用来判断内容是否修改)
  519. Dim Wbkbhlock As Boolean                        '文本框改变值锁
  520. Dim Changelock As Boolean                       '网格行列改变控制锁(用来区别用户改变.程序改变)
  521. Dim Gdtlock As Boolean                          '滚动条滚动控制(用来区别用户改变.程序改变)
  522. Dim Yxxpdlock As Boolean                        '字段有效性判断锁(内容不修改不需进行字段有效性判断)
  523. Dim Hyxxpdlock As Boolean                       '行有效性判断锁(字段内容不修改不需进行行有效性判断)
  524. Dim Valilock As Boolean                         '文本框失去焦点是否进行有效性控制(TRUE 为锁定*限用网格录入)
  525. Dim Shsfts As Boolean                           '删除记录行是否提示
  526. Dim Szzls As Integer                            '网格信息数组最大下标值(网格列数-1)
  527. '''''''''''''''''''''''
  528. '以下为固定使用变量
  529. Dim GridCode1 As String                   '显示网格网格代码
  530. Dim GridInf1() As Variant                 '整个网格设置信息
  531. Dim Qslz1 As Long                         '网格隐藏(非操作显示)列数
  532. Dim Sjhgd1 As Double                      '网格数据行高度
  533. Dim Sfxshjwg1 As Boolean                  '是否显示合计网格
  534. Dim GridBoolean1() As Boolean             '网格列信息(布尔型)
  535. Dim GridStr1()  As String                 '网格列信息(字符型)
  536. Dim GridInt1() As Integer                 '网格列信息(整型)
  537. Dim Szzls1 As Integer                     '数组总列数(网格列数-1)
  538. ''''''''''''''自定义
  539. Dim gridlock As Boolean
  540. Dim Bln_ClrkdKfsc As Boolean
  541. Dim FilterInvoice As String              '发票条件
  542. Dim FilterInOut As String                '入库单中是否存在符合的记录
  543. Dim Collect_BalanceRelation() As New Collection
  544. Dim str_InvoiceFilterCondition As String
  545. Dim str_InOutFilterCondition As String
  546. Dim str_InOutFilterConditionOther As String
  547. Private Sub BanlGrid1_AfterEdit(ByVal Row As Long, ByVal Col As Long)
  548.     With BanlGrid1
  549.         If .ValueMatrix(.Row, 1) = 0 Or .IsSubtotal(.Row) Then
  550.             Exit Sub
  551.         End If
  552.         Select Case .Col
  553.             Case Sydz("013", GridStr1(), Szzls1)
  554.                 If .ValueMatrix(.Row, .Col) = 0 Then
  555.                     .TextMatrix(.Row, .Col) = ""
  556.                 End If
  557.                 Call SubTotal
  558.             Case Sydz("014", GridStr1(), Szzls1)
  559.                 If .ValueMatrix(.Row, .Col) = 0 Then
  560.                     .TextMatrix(.Row, .Col) = ""
  561.                 End If
  562.                 Call SubTotal
  563.             Case Sydz("015", GridStr1(), Szzls1)
  564.                 If .ValueMatrix(.Row, .Col) = 0 Then
  565.                     .TextMatrix(.Row, .Col) = ""
  566.                 End If
  567.                 Call SubTotal
  568.         End Select
  569.     End With
  570. End Sub
  571. Private Sub BanlGrid1_EnterCell()
  572.     With BanlGrid1
  573.         Select Case .Col
  574.             Case Sydz("013", GridStr1(), Szzls1), Sydz("014", GridStr1(), Szzls1), Sydz("015", GridStr1(), Szzls1)     '当发票为负发票时,不允许输入损耗
  575.                 If .IsSubtotal(.Row) = False And .ValueMatrix(.Row, 1) = 1 Then
  576.                         gridlock = False
  577.                         BanlGrid1.Editable = True
  578.                 Else
  579.                     BanlGrid1.Editable = False
  580.                 End If
  581.              Case Else
  582.                 gridlock = True
  583.                 BanlGrid1.Editable = False
  584.         End Select
  585.     End With
  586. End Sub
  587. Private Sub BanlGrid1_KeyPressEdit(ByVal Row As Long, ByVal Col As Long, KeyAscii As Integer)
  588.     Select Case Col
  589.         Case Sydz("013", GridStr1(), Szzls1), Sydz("015", GridStr1(), Szzls1) '控制合理损耗为有效的数值
  590.             Call check_num_for_grid(BanlGrid1, KeyAscii)
  591.         Case Sydz("014", GridStr1(), Szzls1)      '控制非合理损耗只能为正
  592.             Call check_num_for_grid1(BanlGrid1, KeyAscii)
  593.     End Select
  594. End Sub
  595. Private Sub BanlGrid1_LeaveCell()
  596.     With BanlGrid1
  597.         If .Rows <= 1 Then Exit Sub
  598.         If .ValueMatrix(.Row, 1) = 0 Or .IsSubtotal(.Row) Then
  599.             Exit Sub
  600.         End If
  601.         Select Case .Col
  602.             Case Sydz("013", GridStr1(), Szzls1)
  603.                 If .ValueMatrix(.Row, .Col) = 0 Then
  604.                     .TextMatrix(.Row, .Col) = ""
  605.                 End If
  606.                 Call SubTotal
  607.             Case Sydz("014", GridStr1(), Szzls1)
  608.                 If .ValueMatrix(.Row, .Col) = 0 Then
  609.                     .TextMatrix(.Row, .Col) = ""
  610.                 End If
  611.                 Call SubTotal
  612.             Case Sydz("015", GridStr1(), Szzls1)
  613.                 If .ValueMatrix(.Row, .Col) = 0 Then
  614.                     .TextMatrix(.Row, .Col) = ""
  615.                 End If
  616.                 Call SubTotal
  617.         End Select
  618.     End With
  619.     
  620. End Sub
  621. Private Sub BanlGrid1_LostFocus()
  622.      Call SubTotal
  623. End Sub
  624. Private Sub Form_KeyPress(KeyAscii As Integer)      '限制录入字符"'"
  625.     Select Case KeyAscii
  626.         Case 39           '屏蔽字符"'"
  627.             KeyAscii = 0
  628.     End Select
  629.     
  630. End Sub
  631. Private Sub Form_Load()                              '窗 体 装 入
  632.   
  633.     '初始化各种锁值(Fixed)
  634.     Changelock = False             '网格行列改变控制锁
  635.     Gdtlock = False                '滚动条滚动控制
  636.     Yxxpdlock = True               '字段有效性判断锁
  637.     Hyxxpdlock = True              '行有效性判断锁
  638.     Wbkbhlock = False              '文本框内容改变锁
  639.      
  640.     '报表主标题及报表编码(Fixed)
  641.     ReportTitle = "手工结算列表"
  642.     XtReportCode = "KF_HandBalance"
  643.     Load Dyymctbl
  644.     
  645.     GridCode1 = "KF_HandBalanceTop"      '网格属性编码
  646.     Call BzWgcsh(BanlGrid1, GridCode1, GridInf1(), GridBoolean1(), GridInt1(), GridStr1())
  647.     Qslz1 = GridInf1(1)
  648.     Sjhgd1 = GridInf1(2)
  649.     Sfxshjwg1 = GridInf1(7)
  650.     Szzls1 = BanlGrid1.Cols - 1
  651.     '调 入 网 格(Fixed)
  652.     GridCode = "KF_HandBalanceBottom"      '网格属性编码
  653.     Call BzWgcsh(BanlGrid2, GridCode, GridInf(), GridBoolean(), GridInt(), GridStr())
  654.     
  655.     Qslz = GridInf(1)
  656.     Sjhgd = GridInf(2)
  657.     Pmbcsjhs = GridInf(3)
  658.     Fzxwghs = GridInf(4)
  659.     Sfblbzkd = GridInf(5)
  660.     Shsfts = GridInf(6)
  661.     Sfxshjwg = GridInf(7)
  662.     Szzls = BanlGrid2.Cols - 1
  663.     
  664.     '设置状态为修改状态
  665.     Lab_OperStatus = "2"
  666.     Call FillCombo1(Combo1, "KF_BalanceType", "", 0)
  667.     FilterInvoice = " where 1=1 "
  668.     FilterInOut = " where 1=1 "
  669.     FilterInOut = FilterInOut & " And WhCode in (select whcode from KF_V_WhLimit where ltrim(rtrim(Czybm))='" & Xtczybm & "')"
  670.     Me.InOut_FilterCondition = "  1=2 "
  671.     Me.Invoice_FilterCondition = "  1=2 "
  672.     Bln_ClrkdKfsc = Fun_ClrkdKfsc ''材料入库单是不是由库房生成
  673. End Sub
  674. Private Sub Form_Unload(Cancel As Integer)           '窗体卸载
  675.     '卸载打印页面窗体
  676.     Unload Dyymctbl
  677.     Dim frm_temp As Form
  678.     For Each frm_temp In Forms
  679.        If frm_temp.Name = "Balance_KF_InOut" Then
  680.            Balance_KF_InOut.UnloadCheck = 1
  681.            Unload Balance_KF_InOut
  682.        ElseIf frm_temp.Name = "Balance_KF_Invoice" Then
  683.            Balance_KF_Invoice.UnloadCheck = 1
  684.            Unload Balance_KF_Invoice
  685.        ElseIf frm_temp.Name = "Balance_KF_Query" Then
  686.            Balance_KF_Query.UnloadCheck = 1
  687.            Unload Balance_KF_Query
  688.        End If
  689.     Next frm_temp
  690. End Sub
  691. Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)        '支持热键操作
  692.   
  693.     If Shift = 2 Then
  694.         Select Case UCase(Chr(KeyCode))
  695.             Case "P"                   'Ctrl+P 打印
  696.                 If Tlb_Action.Buttons("dy").Enabled Then
  697.                     Call bbyl(False)
  698.                 End If
  699.         End Select
  700.     End If
  701.     
  702. End Sub
  703. Private Sub Wbkcl()                                                 '文本框录入之前处理(根据实际情况)
  704.  
  705.     Dim xswbrr As String
  706.  
  707.     With BanlGrid2
  708.         Zdlrqnr = Trim(.Text)
  709.         xswbrr = Trim(.Text)
  710.     
  711.         If GridBoolean(.Col, 3) Then   '列表框录入
  712.     
  713.             '填充列表框程序
  714.             Call FillCombo(YdCombo, GridStr(.Col, 5), xswbrr, 0)
  715.         Else
  716.             Wbkbhlock = True
  717.        
  718.             '====以下为用户自定义
  719.             Ydtext.Text = xswbrr
  720.             '====以上为用户自定义
  721.          
  722.             Wbkbhlock = False
  723.             Ydtext.SelStart = Len(Ydtext.Text)
  724.         End If
  725.     End With
  726.     
  727. End Sub
  728. Private Function sjzdyxxpd(Dqpdwgh As Long, Dqpdwgl As Long)        '录入数据字段有效性判断,同时进行字段录入事后处理
  729.     
  730.     Dim Str_JudgeText As String            '临时有效性判断字段内容
  731.     Dim Coljsq As Long                     '临时列计数器
  732.     Dim RecTemp As New ADODB.Recordset     '临时使用动态集
  733.     Dim Dbl_Qcye As Double                 '临时期初余额
  734.  
  735.     With BanlGrid2
  736.     
  737.         '非录入状态有效性为合法
  738.         If Yxxpdlock Or .Row < .FixedRows Then
  739.            sjzdyxxpd = True
  740.            Exit Function
  741.         End If
  742.  
  743.         Str_JudgeText = Trim(.TextMatrix(Dqpdwgh, Dqpdwgl))
  744.         Select Case GridStr(Dqpdwgl, 1)
  745.          
  746.             '以下为自定义部分[
  747.             Case "009"
  748.                 If Trim(Str_JudgeText) <> "" Then
  749.                     Sqlstr = "SELECT WhName, WhCode FROM KF_V_WhLimit  WHERE ( WhCode='" & Trim(Str_JudgeText) & "' or WhName='" & Trim(Str_JudgeText) & "') AND (Czybm = '" & Xtczybm & "')"
  750.                     Set RecTemp = Cw_DataEnvi.DataConnect.Execute(Sqlstr)
  751.                     If RecTemp.EOF Then
  752.                         Tsxx = "此仓库不存在或权限不够!"
  753.                         GoTo Lrcwcl
  754.                     Else
  755.                         .TextMatrix(Dqpdwgh, 4) = Trim("" & RecTemp.Fields("WhCode"))
  756.                         .TextMatrix(Dqpdwgh, Sydz("009", GridStr(), Szzls)) = Trim("" & RecTemp.Fields("WhName"))
  757.                     End If
  758.                 Else
  759.                     .TextMatrix(Dqpdwgh, 4) = ""
  760.                     .TextMatrix(Dqpdwgh, Sydz("009", GridStr(), Szzls)) = ""
  761.                 End If
  762.             Case "010"
  763.                 If Trim(Str_JudgeText) <> "" Then
  764.                     Sqlstr = "SELECT MNumber, MName FROM Gy_Material WHERE (IsCharge = 0) AND (MNumber ='" & Trim(Str_JudgeText) & "' or MName='" & Trim(Str_JudgeText) & "')"
  765.                     Set RecTemp = Cw_DataEnvi.DataConnect.Execute(Sqlstr)
  766.                     If RecTemp.EOF Then
  767.                         Tsxx = "此物料(实物)不存在!"
  768.                         GoTo Lrcwcl
  769.                     Else
  770.                         .TextMatrix(Dqpdwgh, 5) = Trim("" & RecTemp.Fields("MNumber"))
  771.                         .TextMatrix(Dqpdwgh, Sydz("010", GridStr(), Szzls)) = Trim("" & RecTemp.Fields("MName"))
  772.                     End If
  773.                 Else
  774.                     .TextMatrix(Dqpdwgh, 5) = ""
  775.                     .TextMatrix(Dqpdwgh, Sydz("010", GridStr(), Szzls)) = ""
  776.                 End If
  777.             '以上为自定义部分]
  778.         End Select
  779.      
  780.         '字段录入正确后为零字段清空
  781.         Call Qkwlzd(Dqpdwgh, Dqpdwgl)
  782.     
  783.         sjzdyxxpd = True
  784.         Yxxpdlock = True
  785.         Exit Function
  786.     
  787.     End With
  788.   
  789. Lrcwcl:    '录入错误处理
  790.     With BanlGrid2
  791.         Call Xtxxts(Tsxx, 0, 1)
  792.         Changelock = True
  793.         .Select Dqpdwgh, Dqpdwgl
  794.         Changelock = False
  795.         Call xswbk
  796.         sjzdyxxpd = False
  797.         Exit Function
  798.     End With
  799.     
  800. End Function
  801. Private Function Sjhzyxxpd(ByVal Yxxpdh As Long) As Boolean                  '录入数据行有效性判断,同时进行行处理
  802.  
  803.     Dim Lrywlz As Long                     '录入错误列值(Fixed)
  804.     Dim RecTemp As New ADODB.Recordset     '临时使用动态集
  805.     Dim Sqlstr As String                   '临时查询字符串
  806.     Dim Str_Ccode As String                '临时索引编码
  807.     With BanlGrid2
  808.         If Yxxpdh > (.Rows - 1) Then Exit Function
  809.         '行没有发生变化则不进行有效性判断
  810.         If Hyxxpdlock Then
  811.             Sjhzyxxpd = True
  812.             Exit Function
  813.         End If
  814.     
  815.         '以下为自定义部分[
  816.     
  817.         '1.1首先进行单个不能为空或不能为零判断(Fixed)
  818.         For jsqte = Qslz To .Cols - 1
  819.             '字段不能为空
  820.             If GridInt(jsqte, 5) = 1 Then
  821.                 If Len(Trim(.TextMatrix(Yxxpdh, jsqte))) = 0 Then
  822.                     Tsxx = GridStr(jsqte, 2)
  823.                     Lrywlz = jsqte
  824.                     GoTo Lrcwcl
  825.                     Exit For
  826.                 End If
  827.             End If
  828.             
  829.             '字段不能为零
  830.             If GridInt(jsqte, 5) = 2 Then
  831.                 If Val(Trim(.TextMatrix(Yxxpdh, jsqte))) = 0 Then
  832.                     Tsxx = GridStr(jsqte, 2)
  833.                     Lrywlz = jsqte
  834.                     GoTo Lrcwcl
  835.                     Exit For
  836.                 End If
  837.             End If
  838.         Next jsqte
  839.     
  840.     
  841.         '1.2进行其他有效性判断,编写格式同1.1
  842.                 
  843.         '2.放置行处理程序(当数据行通过有效性判断)
  844.            
  845.         Str_Ccode = Trim(.TextMatrix(Yxxpdh, Sydz("001", GridStr(), Szzls)))
  846.            
  847.          
  848.     End With
  849.     '以上为自定义部分]
  850.     Sjhzyxxpd = True
  851.     Hyxxpdlock = True
  852.     Exit Function
  853. Swcwcl:
  854.     Cw_DataEnvi.DataConnect.RollbackTrans
  855.     Tsxx = "存盘过程中出现未知错误,程序自动恢复保存前状态!"
  856.     Call Xtxxts(Tsxx, 0, 1)
  857.     Exit Function
  858. Lrcwcl:      '录入错误处理
  859.     With BanlGrid2
  860.         Call Xtxxts(Tsxx, 0, 1)
  861.         Changelock = True
  862.         .Select Yxxpdh, Lrywlz
  863.         Changelock = False
  864.         Call xswbk
  865.         Sjhzyxxpd = False
  866.         Exit Function
  867.     End With
  868.     
  869. End Function
  870. '===================以 下 程 序 为 通 用 部 分 ,一 般 不 需 更 改(程序动作部分)======================='
  871. Private Sub Lrzdbz()                                                      '录入字段帮助
  872.   
  873.     If Not Ydcommand.Visible Then
  874.         Exit Sub
  875.     End If
  876.    
  877.     With BanlGrid2
  878.      
  879.         Valilock = True
  880.     
  881.         '处理通用部分
  882.         Changelock = True        '调入另外窗体必须加锁
  883.         If GridInt(.Col, 6) <> 1 Then
  884.             strHlpR = FunHlpR(Trim(GridStr(.Col, 3)), "czybm", Xtczybm)
  885.         End If
  886.         Call Drbmhelp(GridInt(.Col, 6), GridStr(.Col, 3), Trim(Ydtext.Text))
  887.         strHlpR = ""
  888.         Changelock = False
  889.         
  890.         If Len(Xtfhcs) <> 0 Then
  891.             If GridInt(.Col, 7) = 0 Then
  892.                 Ydtext.Text = Xtfhcs
  893.             Else
  894.                 Ydtext.Text = Xtfhcsfz
  895.             End If
  896.         End If
  897.         
  898.         Valilock = False
  899.   
  900.         If Ydtext.Visible Then
  901.             Ydtext.SetFocus
  902.         End If
  903.     End With
  904.     
  905. End Sub
  906. Private Sub Form_Resize()                                                '窗体大小发生变化时,重新显示文本框
  907.    
  908.     Call Cxxswbk
  909. End Sub
  910. Private Function Fun_Drfrmyxxpd() As Boolean                             '调入其它窗体或功能产生的有效性判断(包括数据回写)
  911.   
  912.     Fun_Drfrmyxxpd = True
  913.     
  914.     With BanlGrid2
  915.    
  916.         '如果当前网格处于编辑状态,则先进行数据回写再进行有效性判断
  917.   
  918.         If Ydtext.Visible Or YdCombo.Visible Then
  919.             Call Lrsjhx
  920.             If Not sjzdyxxpd(Dqlrwgh, Dqlrwgl) Then
  921.                 Fun_Drfrmyxxpd = False
  922.                 Exit Function
  923.             End If
  924.         End If
  925.    
  926.         '进行行有效性判断
  927.         If Not Sjhzyxxpd(.Row) Then
  928.             Fun_Drfrmyxxpd = False
  929.             Exit Function
  930.         End If
  931.     End With
  932.   
  933. End Function
  934. Private Sub BanlGrid2_EnterCell()                                          '显示当前数据行相关信息
  935.     With BanlGrid2
  936.         If .Row >= .FixedRows Then
  937.             '[>>
  938.                 '此处可以填写显示与此网格行相关信息
  939.             '<<]
  940.         End If
  941.     End With
  942.    
  943. End Sub
  944. Private Sub BanlGrid2_GotFocus()                                           '网格得到焦点
  945.     '网格得到焦点,如果当前选择行为非数据行
  946.     '则调整当前焦点至有效数据行
  947.     With BanlGrid2
  948.         If .Row < .FixedRows And .Rows > .FixedRows Then
  949.             Changelock = True
  950.             .Select .FixedRows, .Col
  951.             Changelock = False
  952.         End If
  953.         If .Col < Qslz Then
  954.             Changelock = True
  955.             .Select .Row, Qslz
  956.             Changelock = False
  957.         End If
  958.     End With
  959. End Sub
  960. Private Sub BanlGrid2_LostFocus()                                          '录入网格失去焦点
  961.     '用以屏蔽调用其它窗体时发生网格失去焦点事件
  962.     If Changelock Then
  963.         Exit Sub
  964.     End If
  965.     '引发网格RowcolChange事件
  966.     With BanlGrid2
  967.         If Not (Ydtext.Visible Or YdCombo.Visible) Then
  968.             .Select 0, 0
  969.         End If
  970.     End With
  971. End Sub
  972. Private Sub BanlGrid2_AfterScroll(ByVal OldTopRow As Long, ByVal OldLeftCol As Long, ByVal NewTopRow As Long, ByVal NewLeftCol As Long)                                             '限制用户在录入过程中滚动鼠标
  973.     If Gdtlock Then
  974.         Exit Sub
  975.     End If
  976.  
  977.     With BanlGrid2
  978.         If Ydtext.Visible Or YdCombo.Visible Then
  979.             Gdtlock = True
  980.             .TopRow = Dqtoprow
  981.             .LeftCol = Dqleftcol
  982.             Gdtlock = False
  983.             Exit Sub
  984.         End If
  985.     End With
  986.     
  987. End Sub
  988. Private Sub BanlGrid2_LeaveCell()                                    '离开单元格
  989.     If Changelock Then
  990.         Exit Sub
  991.     End If
  992.     '记录刚刚离开网格单元的行列值
  993.     Dqlkwgh = BanlGrid2.Row
  994.     Dqlkwgl = BanlGrid2.Col
  995.     '判断是否需要录入数据回写
  996.     If Not (Ydtext.Visible Or YdCombo.Visible) Then
  997.         Exit Sub
  998.     End If
  999.     
  1000.     Call Lrsjhx
  1001.     
  1002. End Sub
  1003. Private Sub BanlGrid2_RowColChange()                                '网格录入行列发生变化时,进行有效性判断
  1004.    
  1005.     Valilock = True       '屏蔽文本框失去焦点进行有效性判断
  1006.     
  1007.     With BanlGrid2
  1008.         If Changelock Then
  1009.             Exit Sub
  1010.         End If
  1011.         If Not sjzdyxxpd(Dqlrwgh, Dqlrwgl) Then
  1012.             Exit Sub
  1013.         End If
  1014.         If .Row <> Dqlkwgh Then
  1015.             If Not Sjhzyxxpd(Dqlkwgh) Then
  1016.                 Exit Sub
  1017.             End If
  1018.         End If
  1019.    End With
  1020.    
  1021.    Call fhyxh
  1022.    Call Xldql
  1023.    
  1024. End Sub
  1025. Private Sub BanlGrid2_DblClick()                                    '鼠标双击网格显示文本框
  1026.   
  1027.     With BanlGrid2
  1028.         Call xswbk
  1029.     End With
  1030.     
  1031. End Sub
  1032. Private Sub Ycwbk()                                                '隐藏文本框,帮助按钮,列表组合框
  1033.     
  1034.     Valilock = True
  1035.     Ydtext.Visible = False
  1036.     YdCombo.Visible = False
  1037.     Ydcommand.Visible = False
  1038.     
  1039. End Sub
  1040. Private Sub SzToolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)
  1041.     If Trim(Ydtext) = "" Then
  1042.         Call Ycwbk
  1043.     End If
  1044.         Select Case Button.Key
  1045.             Case "ymsz"                                          '页面设置
  1046.                Dyymctbl.Show 1
  1047.             Case "yl"                                            '预 览
  1048.                Call bbyl(True)
  1049.             Case "dy"                                            '打 印
  1050.                Call bbyl(False)
  1051.             Case "gl"
  1052.                Balance_KF_Query.Show 1
  1053.             Case "fp"
  1054.                Balance_KF_Invoice.Now_FilterCondition = FilterInvoice
  1055.                Balance_KF_Invoice.Show 1
  1056.             Case "rkd"
  1057.                Balance_KF_InOut.Now_FilterCondition = FilterInOut
  1058.                Balance_KF_InOut.Show 1
  1059.             Case "js"
  1060.                If Fun_Drfrmyxxpd Then Call Sub_HandBalance
  1061.                
  1062.             Case "bz"                                            '帮 助
  1063.                Call F1bz
  1064.             Case "fh"                                            '退 出
  1065.             Unload Me
  1066.        End Select
  1067. End Sub
  1068. Private Sub Timer1_Timer()
  1069. Timer1.Enabled = False
  1070. Dim jsqte As Integer
  1071.     FilterInvoice = " where 1=1 "
  1072.     FilterInOut = " where 1=1 "
  1073.  With Balance_KF_Query
  1074.     For jsqte = 1 To 5
  1075.     Select Case jsqte
  1076.         Case 1  '查询日期范围(起始)
  1077.             If Trim(.LrText(0).Text) <> "" Then
  1078.                 FilterInvoice = FilterInvoice & " And InvoiceDate>=convert(datetime,'" & Trim(.LrText(0).Text) & "')"
  1079.                 FilterInOut = FilterInOut & " And BillDate>=convert(datetime,'" & Trim(.LrText(0).Text) & "')"
  1080.             End If
  1081.         Case 2  '查询日期范围(终止)
  1082.             If Trim(.LrText(1).Text) <> "" Then
  1083.                 FilterInvoice = FilterInvoice & " And InvoiceDate<= convert(datetime,'" & Trim(.LrText(1).Text) & "')"
  1084.                 FilterInOut = FilterInOut & " And BillDate<= convert(datetime,'" & Trim(.LrText(1).Text) & "')"
  1085.             End If
  1086.         Case 3  '供应商(Like)
  1087.             If Trim(.LrText(2).Text) <> "" Then
  1088.                 FilterInvoice = FilterInvoice & " And ( SupplierCode like '%" & Trim(.LrText(2).Text) & "%' or SupplierName like '%" & Trim(.LrText(2).Text) & "%')"
  1089.                 FilterInOut = FilterInOut & " And ( SupplierCode like '%" & Trim(.LrText(2).Text) & "%' or SupplierName like '%" & Trim(.LrText(2).Text) & "%')"
  1090.             End If
  1091.         Case 4  '物料分类
  1092.             If Trim(.LrText(3).Text) <> "" Then
  1093.                 FilterInvoice = FilterInvoice & " and InvSortcode like '" & Trim(.LrText(3).Tag) & "%'"
  1094.                 FilterInOut = FilterInOut & " and InvSortcode like '" & Trim(.LrText(3).Tag) & "%'"
  1095.             End If
  1096.         Case 5  '物料
  1097.             If Trim(.LrText(4).Text) <> "" Then
  1098.                 FilterInvoice = FilterInvoice & " and MNumber like  '%" & Trim(.LrText(4).Text) & "%'"
  1099.                 FilterInOut = FilterInOut & " and MNumber like  '%" & Trim(.LrText(4).Text) & "%'"
  1100.             End If
  1101.     End Select
  1102.     Next
  1103.   End With
  1104.      FilterInOut = FilterInOut & " And WhCode in (select whcode from KF_V_WhLimit where ltrim(rtrim(Czybm))='" & Xtczybm & "')"
  1105. End Sub
  1106. Private Sub Timer2_Timer()
  1107. Timer2.Enabled = False
  1108.     Dim int_temp As Integer
  1109.     Dim rst_temp As New ADODB.Recordset
  1110.     Dim str_sqlTemp As String
  1111.     Dim Jsqte1 As Integer
  1112.     Dim Jsqte2 As Integer
  1113.     
  1114.     BanlGrid1.Rows = BanlGrid1.FixedRows
  1115.     BanlGrid2.Rows = BanlGrid2.FixedRows
  1116.     str_sqlTemp = "SELECT 0 as IsInvoice, InOutMainId as Mainid, InOutSubId as SubId, MNumber, MName, Model, PrimaryUnitName, BillNum, " & _
  1117.                           " '' AS InvoiceNum, FactReceiptQuan, 0 AS InvoiceQuan, Price, 0 AS InvoicePriceBb, " & _
  1118.                           " EMoney, 0 AS InvoiceTotalMoneyBb, 0 AS Ischarge ,'' as SupplierCode,'' as SupplierName " & _
  1119.                     " From KF_V_BalanceInOut " & "Where " & Me.InOut_FilterCondition & _
  1120.                     " Union " & _
  1121.                     " SELECT 1 as IsInvoice,InvoiceMainID as Mainid, InvoiceSubID as Subid , MNumber, MName, Model, PrimaryUnitName, " & _
  1122.                           " '' AS InoutNum, InvoiceNum, 0 AS InOutQuan, Quantity, 0 AS InoutPrice, PriceBb, " & _
  1123.                           " 0 AS InOutMoney, TotalMoneyBb, IsCharge ,SupplierCode, SupplierName" & _
  1124.                     " From KF_V_BalanceInvoice  where " & Me.Invoice_FilterCondition & _
  1125.                     " ORDER BY MNumber, IsInvoice "
  1126.     Set rst_temp = Cw_DataEnvi.DataConnect.Execute(str_sqlTemp)
  1127.     Jsqte1 = BanlGrid1.FixedRows
  1128.     Jsqte2 = BanlGrid2.FixedRows
  1129.     If rst_temp.RecordCount <> 0 Then
  1130.         rst_temp.MoveFirst
  1131.         For int_temp = 1 To rst_temp.RecordCount
  1132.             If rst_temp.Fields("IsCharge") = False Then   '是否费用
  1133.                 With BanlGrid1
  1134.                     If Jsqte1 >= .Rows Then
  1135.                        .AddItem ""
  1136.                     End If
  1137.                     .TextMatrix(Jsqte1, 0) = Trim("" & rst_temp.Fields("MNumber"))
  1138.                     .TextMatrix(Jsqte1, 1) = rst_temp.Fields("IsInvoice")
  1139.                     .TextMatrix(Jsqte1, 2) = rst_temp.Fields("Mainid")                        '主表ID
  1140.                     .TextMatrix(Jsqte1, 3) = rst_temp.Fields("SubId")                        '子表ID
  1141.                     .TextMatrix(Jsqte1, Sydz("001", GridStr1(), Szzls1)) = Trim("" & rst_temp.Fields("MNumber"))
  1142.                     .TextMatrix(Jsqte1, Sydz("002", GridStr1(), Szzls1)) = Trim("" & rst_temp.Fields("MName"))
  1143.                     .TextMatrix(Jsqte1, Sydz("003", GridStr1(), Szzls1)) = Trim(rst_temp.Fields("Model") & "")
  1144.                     .TextMatrix(Jsqte1, Sydz("004", GridStr1(), Szzls1)) = Trim(rst_temp.Fields("PrimaryUnitName") & "")
  1145.                     .TextMatrix(Jsqte1, Sydz("005", GridStr1(), Szzls1)) = Trim(rst_temp.Fields("BillNum") & "")
  1146.                     .TextMatrix(Jsqte1, Sydz("006", GridStr1(), Szzls1)) = Trim("" & rst_temp.Fields("InvoiceNum"))
  1147.                     .TextMatrix(Jsqte1, Sydz("007", GridStr1(), Szzls1)) = IIf(IsNull(rst_temp.Fields("FactReceiptQuan")) Or rst_temp.Fields("FactReceiptQuan") = 0, "", rst_temp.Fields("FactReceiptQuan"))
  1148.                     .TextMatrix(Jsqte1, Sydz("008", GridStr1(), Szzls1)) = IIf(IsNull(rst_temp.Fields("InvoiceQuan")) Or rst_temp.Fields("InvoiceQuan") = 0, "", rst_temp.Fields("InvoiceQuan"))
  1149.                     .TextMatrix(Jsqte1, Sydz("009", GridStr1(), Szzls1)) = IIf(IsNull(rst_temp.Fields("Price")) Or rst_temp.Fields("Price") = 0, "", rst_temp.Fields("Price"))
  1150.                     .TextMatrix(Jsqte1, Sydz("010", GridStr1(), Szzls1)) = IIf(IsNull(rst_temp.Fields("InvoicePriceBb")) Or rst_temp.Fields("InvoicePriceBb") = 0, "", rst_temp.Fields("InvoicePriceBb"))
  1151.                     .TextMatrix(Jsqte1, Sydz("011", GridStr1(), Szzls1)) = IIf(IsNull(rst_temp.Fields("EMoney")) Or rst_temp.Fields("EMoney") = 0, "", rst_temp.Fields("EMoney"))
  1152.                     .TextMatrix(Jsqte1, Sydz("012", GridStr1(), Szzls1)) = IIf(IsNull(rst_temp.Fields("InvoiceTotalMoneyBb")) Or rst_temp.Fields("InvoiceTotalMoneyBb") = 0, "", rst_temp.Fields("InvoiceTotalMoneyBb"))
  1153.                     .RowHeight(Jsqte1) = Sjhgd1
  1154.                     Jsqte1 = Jsqte1 + 1
  1155.                 End With
  1156.             ElseIf rst_temp.Fields("IsCharge") = 1 And rst_temp.Fields("IsInvoice") = 1 Then
  1157.                 With BanlGrid2
  1158.                     If Jsqte2 >= .Rows Then
  1159.                        .AddItem ""
  1160.                     End If
  1161.                     .TextMatrix(Jsqte2, 1) = rst_temp.Fields("IsInvoice")
  1162.                     .TextMatrix(Jsqte2, 2) = rst_temp.Fields("Mainid")                        '主表ID
  1163.                     .TextMatrix(Jsqte2, 3) = rst_temp.Fields("SubId")                        '子表ID
  1164.                     .TextMatrix(Jsqte2, Sydz("001", GridStr(), Szzls)) = Trim("" & rst_temp.Fields("MNumber"))                  '
  1165.                     .TextMatrix(Jsqte2, Sydz("002", GridStr(), Szzls)) = Trim("" & rst_temp.Fields("MName"))
  1166.                     .TextMatrix(Jsqte2, Sydz("003", GridStr(), Szzls)) = Trim(rst_temp.Fields("Model") & "")
  1167.                     .TextMatrix(Jsqte2, Sydz("004", GridStr(), Szzls)) = Trim(rst_temp.Fields("PrimaryUnitName") & "")
  1168.                     .TextMatrix(Jsqte2, Sydz("005", GridStr(), Szzls)) = Trim(rst_temp.Fields("InvoiceNum") & "")
  1169.                     .TextMatrix(Jsqte2, Sydz("006", GridStr(), Szzls)) = IIf(IsNull(rst_temp.Fields("InvoiceQuan")) Or rst_temp.Fields("InvoiceQuan") = 0, "", rst_temp.Fields("InvoiceQuan"))
  1170.                     .TextMatrix(Jsqte2, Sydz("007", GridStr(), Szzls)) = IIf(IsNull(rst_temp.Fields("InvoiceTotalMoneyBb")) Or rst_temp.Fields("InvoiceTotalMoneyBb") = 0, "", rst_temp.Fields("InvoiceTotalMoneyBb"))
  1171.                     .TextMatrix(Jsqte2, Sydz("008", GridStr(), Szzls)) = Trim("" & rst_temp.Fields("SupplierName"))
  1172.                     .RowHeight(Jsqte2) = Sjhgd
  1173.                     Jsqte2 = Jsqte2 + 1
  1174.                 End With
  1175.             End If
  1176.             rst_temp.MoveNext
  1177.         Next int_temp
  1178.     End If
  1179.     rst_temp.Close
  1180.     Set rst_temp = Nothing
  1181.     Call SubTotal '加入小合计
  1182.         
  1183. '''''''''''''''
  1184.         For int_temp = BanlGrid1.FixedRows To BanlGrid1.Rows - 1
  1185.             If BanlGrid1.IsSubtotal(int_temp) = True Then
  1186.                  BanlGrid1.TextMatrix(int_temp, Sydz("001", GridStr1(), Szzls1)) = "合 计"
  1187.             End If
  1188.         Next int_temp
  1189. ''''''''''''''''
  1190. End Sub
  1191. Private Sub SubTotal()
  1192. Dim int_temp As Integer
  1193.     If BanlGrid1.Rows <> BanlGrid1.FixedRows Then
  1194.        BanlGrid1.BackColorAlternate = &H80000005
  1195.        BanlGrid1.SubTotal flexSTSum, 0, Sydz("007", GridStr1(), Szzls1), , &HF7F3EC, , , "合计"
  1196.        BanlGrid1.SubTotal flexSTSum, 0, Sydz("008", GridStr1(), Szzls1), , &HF7F3EC, , , "合计"
  1197.        BanlGrid1.SubTotal flexSTSum, 0, Sydz("011", GridStr1(), Szzls1), , &HF7F3EC, , , "合计"
  1198.        BanlGrid1.SubTotal flexSTSum, 0, Sydz("012", GridStr1(), Szzls1), , &HF7F3EC, , , "合计"
  1199.        BanlGrid1.SubTotal flexSTSum, 0, Sydz("013", GridStr1(), Szzls1), , &HF7F3EC, , , "合计"
  1200.        BanlGrid1.SubTotal flexSTSum, 0, Sydz("014", GridStr1(), Szzls1), , &HF7F3EC, , , "合计"
  1201.        BanlGrid1.SubTotal flexSTSum, 0, Sydz("015", GridStr1(), Szzls1), , &HF7F3EC, , , "合计"
  1202.         For int_temp = BanlGrid1.FixedRows To BanlGrid1.Rows - 1
  1203.             If BanlGrid1.IsSubtotal(int_temp) = True Then
  1204.                  If BanlGrid1.ValueMatrix(int_temp, Sydz("007", GridStr1(), Szzls1)) = 0 Then
  1205.                     BanlGrid1.TextMatrix(int_temp, Sydz("007", GridStr1(), Szzls1)) = ""
  1206.                  End If
  1207.                  If BanlGrid1.ValueMatrix(int_temp, Sydz("008", GridStr1(), Szzls1)) = 0 Then
  1208.                     BanlGrid1.TextMatrix(int_temp, Sydz("008", GridStr1(), Szzls1)) = ""
  1209.                  End If
  1210.                  If BanlGrid1.ValueMatrix(int_temp, Sydz("011", GridStr1(), Szzls1)) = 0 Then
  1211.                     BanlGrid1.TextMatrix(int_temp, Sydz("011", GridStr1(), Szzls1)) = ""
  1212.                  End If
  1213.                  If BanlGrid1.ValueMatrix(int_temp, Sydz("012", GridStr1(), Szzls1)) = 0 Then
  1214.                     BanlGrid1.TextMatrix(int_temp, Sydz("012", GridStr1(), Szzls1)) = ""
  1215.                  End If
  1216.                  If BanlGrid1.ValueMatrix(int_temp, Sydz("013", GridStr1(), Szzls1)) = 0 Then
  1217.                     BanlGrid1.TextMatrix(int_temp, Sydz("013", GridStr1(), Szzls1)) = ""
  1218.                  End If
  1219.                  If BanlGrid1.ValueMatrix(int_temp, Sydz("014", GridStr1(), Szzls1)) = 0 Then
  1220.                     BanlGrid1.TextMatrix(int_temp, Sydz("014", GridStr1(), Szzls1)) = ""
  1221.                  End If
  1222.                  If BanlGrid1.ValueMatrix(int_temp, Sydz("015", GridStr1(), Szzls1)) = 0 Then
  1223.                     BanlGrid1.TextMatrix(int_temp, Sydz("015", GridStr1(), Szzls1)) = ""
  1224.                  End If
  1225.             End If
  1226.         Next int_temp
  1227.     End If
  1228. End Sub
  1229. Private Sub YdCombo_KeyDown(KeyCode As Integer, Shift As Integer)        '列表框移动
  1230.     
  1231.     With BanlGrid2
  1232.         Select Case KeyCode
  1233.             Case vbKeyEscape                'ESC 键放弃录入
  1234.                 Valilock = True
  1235.                 .SetFocus
  1236.                 Call Ycwbk
  1237.                 Valilock = False
  1238.                 
  1239.             Case vbKeyReturn                '回 车 键 =13
  1240.                 KeyCode = 0
  1241.                 .SetFocus
  1242.                 Call Lrsjhx
  1243.                 Rowjsq = .Row
  1244.                 Coljsq = .Col + 1
  1245.                 If Coljsq > .Cols - 1 Then
  1246.                     If Rowjsq < .Rows - 1 Then
  1247.                         Rowjsq = Rowjsq + 1
  1248.                     End If
  1249.                     Coljsq = Qslz
  1250.                 End If
  1251.                 Do While Rowjsq <= .Rows - 1
  1252.                     If .ColHidden(Coljsq) Or (Not GridBoolean(Coljsq, 1)) Then
  1253.                         Coljsq = Coljsq + 1
  1254.                         If Coljsq > .Cols - 1 Then
  1255.                             Rowjsq = Rowjsq + 1
  1256.                             Coljsq = Qslz
  1257.                         End If
  1258.                     Else
  1259.                         Exit Do
  1260.                     End If
  1261.                 Loop
  1262.                 .Select Rowjsq, Coljsq
  1263.                 
  1264.             Case vbKeyLeft                  '左 箭 头 =37
  1265.                 If .Col - 1 = Qslz Then
  1266.                     If .ColHidden(Qslz) Or (Not GridBoolean(Qslz, 1)) Then
  1267.                         GoTo jzzx
  1268.                     End If
  1269.                 End If
  1270.                 If .Col > Qslz Then
  1271.                     KeyCode = 0
  1272.                     .SetFocus
  1273.                     Call Lrsjhx
  1274.                     Coljsq = .Col - 1
  1275.                     Do While Coljsq > Qslz
  1276.                         If Coljsq - 1 = Qslz Then
  1277.                             If .ColHidden(Qslz) Or (Not GridBoolean(Qslz, 1)) Then
  1278.                                 GoTo jzzx
  1279.                             End If
  1280.                         End If
  1281.                         If .ColHidden(Coljsq) Or (Not GridBoolean(Coljsq, 1)) Then
  1282.                             Coljsq = Coljsq - 1
  1283.                         Else
  1284.                             Exit Do
  1285.                         End If
  1286.                     Loop
  1287.                     .Select .Row, Coljsq
  1288.                 End If
  1289.             Case vbKeyRight                 '右 箭 头 =39
  1290.                 KeyCode = 0
  1291.                 .SetFocus
  1292.                 Call Lrsjhx
  1293.                 Rowjsq = .Row
  1294.                 Coljsq = .Col + 1
  1295.                 If Coljsq > .Cols - 1 Then
  1296.                     If Rowjsq < .Rows - 1 Then
  1297.                         Rowjsq = Rowjsq + 1
  1298.                     End If
  1299.                     Coljsq = Qslz
  1300.                 End If
  1301.                 Do While Rowjsq <= .Rows - 1
  1302.                     If .ColHidden(Coljsq) Or (Not GridBoolean(Coljsq, 1)) Then
  1303.                         Coljsq = Coljsq + 1
  1304.                         If Coljsq > .Cols - 1 Then
  1305.                             Rowjsq = Rowjsq + 1
  1306.                             Coljsq = Qslz
  1307.                         End If
  1308.                     Else
  1309.                         Exit Do
  1310.                     End If
  1311.                 Loop
  1312.                 .Select Rowjsq, Coljsq
  1313.         Case Else
  1314.     End Select
  1315.    
  1316. jzzx:
  1317.    
  1318.     End With
  1319.     
  1320. End Sub
  1321. Private Sub YdCombo_LostFocus()                    '列表框失去焦点
  1322.     
  1323.     With BanlGrid2                                    '因为选中网格会先发生Rowcolchange事件置Valiock
  1324.         If Not Valilock Then                           '为TRUE
  1325.             Call Lrsjhx
  1326.             If Not Sjhzyxxpd(Dqlrwgh) Then
  1327.                 Exit Sub
  1328.             End If
  1329.         End If
  1330.     End With
  1331.     
  1332. End Sub
  1333. Private Sub Ydcommand_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
  1334.     
  1335.     Call Lrzdbz
  1336.     
  1337. End Sub
  1338. Private Sub ydtext_KeyDown(KeyCode As Integer, Shift As Integer)
  1339.    
  1340.     Dim Rowjsq As Long, Coljsq As Long
  1341.    
  1342.     With BanlGrid2
  1343.         Select Case KeyCode
  1344.             Case vbKeyF2
  1345.                 Call Lrzdbz
  1346.             Case vbKeyEscape                'ESC 键放弃录入
  1347.                 Valilock = True
  1348.                 Call Ycwbk
  1349.                 .SetFocus
  1350.             Case vbKeyReturn                '回 车 键 =13
  1351.                 KeyCode = 0
  1352.                 .SetFocus
  1353.                 Call Lrsjhx
  1354.                 Rowjsq = .Row
  1355.                 Coljsq = .Col + 1
  1356.                 If Coljsq > .Cols - 1 Then
  1357.                     If Rowjsq < .Rows - 1 Then
  1358.                         Rowjsq = Rowjsq + 1
  1359.                     End If
  1360.                     Coljsq = Qslz
  1361.                 End If
  1362.                 Do While Rowjsq <= .Rows - 1
  1363.                     If .ColHidden(Coljsq) Or (Not GridBoolean(Coljsq, 1)) Then
  1364.                         Coljsq = Coljsq + 1
  1365.                         If Coljsq > .Cols - 1 Then
  1366.                             Rowjsq = Rowjsq + 1
  1367.                             Coljsq = Qslz
  1368.                         End If
  1369.                     Else
  1370.                         Exit Do
  1371.                     End If
  1372.                 Loop
  1373.                 If Rowjsq <= .Rows - 1 Then
  1374.                     .Select Rowjsq, Coljsq
  1375.                 End If
  1376.                 
  1377.             Case vbKeyUp                    '上 箭 头 =38
  1378.                 KeyCode = 0
  1379.                 .SetFocus
  1380.                 Call Lrsjhx
  1381.                 If .Row > .FixedRows Then
  1382.                     .Row = .Row - 1
  1383.                 End If
  1384.                 
  1385.             Case vbKeyDown                  '下 箭 头 =40
  1386.                 KeyCode = 0
  1387.                 .SetFocus
  1388.                 Call Lrsjhx
  1389.                 If .Row < .Rows - 1 Then
  1390.                     .Row = .Row + 1
  1391.                 End If
  1392.             Case vbKeyLeft                  '左 箭 头 =37
  1393.                 If .Col - 1 = Qslz Then
  1394.                     If .ColHidden(Qslz) Or (Not GridBoolean(Qslz, 1)) Then
  1395.                         GoTo jzzx
  1396.                     End If
  1397.                 End If
  1398.                 If Ydtext.SelStart = 0 And .Col > Qslz Then
  1399.                     KeyCode = 0
  1400.                     .SetFocus
  1401.                     Call Lrsjhx
  1402.                     Coljsq = .Col - 1
  1403.                     Do While Coljsq > Qslz
  1404.                         If Coljsq - 1 = Qslz Then
  1405.                             If .ColHidden(Qslz) Or (Not GridBoolean(Qslz, 1)) Then
  1406.                                 GoTo jzzx
  1407.                             End If
  1408.                         End If
  1409.                         If .ColHidden(Coljsq) Or (Not GridBoolean(Coljsq, 1)) Then
  1410.                             Coljsq = Coljsq - 1
  1411.                         Else
  1412.                             Exit Do
  1413.                         End If
  1414.                     Loop
  1415.                     .Select .Row, Coljsq
  1416.                 End If
  1417. jzzx:
  1418.            
  1419.            
  1420.             Case vbKeyRight                 '右 箭 头 =39
  1421.                 wblong = Len(Ydtext.Text)
  1422.                 If (Ydtext.SelStart = wblong Or Ydtext.SelLength = wblong) Then
  1423.                     KeyCode = 0
  1424.                     .SetFocus
  1425.                     Call Lrsjhx
  1426.                     Rowjsq = .Row
  1427.                     Coljsq = .Col + 1
  1428.                     If Coljsq > .Cols - 1 Then
  1429.                         If Rowjsq < .Rows - 1 Then
  1430.                             Rowjsq = Rowjsq + 1
  1431.                         End If
  1432.                         Coljsq = Qslz
  1433.                     End If
  1434.                     Do While Rowjsq <= .Rows - 1
  1435.                         If .ColHidden(Coljsq) Or (Not GridBoolean(Coljsq, 1)) Then
  1436.                             Coljsq = Coljsq + 1
  1437.                             If Coljsq > .Cols - 1 Then
  1438.                                 Rowjsq = Rowjsq + 1
  1439.                                 Coljsq = Qslz
  1440.                             End If
  1441.                         Else
  1442.                             Exit Do
  1443.                         End If
  1444.                     Loop
  1445.                     .Select Rowjsq, Coljsq
  1446.                 End If
  1447.             Case Else
  1448.         End Select
  1449.     End With
  1450.     
  1451. End Sub
  1452. Private Sub ydtext_KeyPress(KeyAscii As Integer)         '录入字符事中控制
  1453.   
  1454.     Call InputFieldLimit(Ydtext, GridInt(BanlGrid2.Col, 1), KeyAscii)
  1455. End Sub
  1456. Private Sub ydtext_Change()                              '录入事中变化处理
  1457.     '防止程序改变但不进行处理
  1458.     If Wbkbhlock Then
  1459.          Exit Sub
  1460.     End If
  1461.     With BanlGrid2
  1462.         '限制字段录入长度
  1463.         Wbkbhlock = True
  1464.         
  1465.         Select Case GridInt(.Col, 1)
  1466.             Case 8, 11   '金额型
  1467.                 Call Sjgskz(Ydtext, Xtjezws - Xtjexsws - 1, Xtjexsws)
  1468.             Case 9, 12   '数量型
  1469.                 Call Sjgskz(Ydtext, Xtslzws - Xtslxsws - 1, Xtslxsws)
  1470.             Case 10      '单价型
  1471.                 Call Sjgskz(Ydtext, Xtdjzws - Xtdjxsws - 1, Xtdjxsws)
  1472.             Case Else    '其他类型
  1473.                 If GridInt(.Col, 3) <> 0 Or GridInt(.Col, 4) <> 0 Then
  1474.                     Call Sjgskz(Ydtext, GridInt(.Col, 3), GridInt(.Col, 4))
  1475.                 End If
  1476.         End Select
  1477.         
  1478.         Wbkbhlock = False
  1479.     End With
  1480.     
  1481. End Sub
  1482. Private Sub ydtext_LostFocus()            '如果由于选中网格之外的控件而发生有效性判断(选中网格会先发生Rowcolchange事件置Valiock为TRUE)
  1483.   
  1484.     With BanlGrid2
  1485.         If Not Valilock Then
  1486.             Call Lrsjhx
  1487.             If Not sjzdyxxpd(Dqlrwgh, Dqlrwgl) Then
  1488.                 Exit Sub
  1489.             End If
  1490.             If Not Sjhzyxxpd(Dqlrwgh) Then
  1491.                 Exit Sub
  1492.             End If
  1493.         End If
  1494.     End With
  1495.   
  1496. End Sub
  1497. Private Sub xswbk()                       '在当前选中单元显示文本框,列表框,帮助按钮(通用)
  1498.   
  1499.     Dim Wbkpy As Integer, Wbkpy1 As Integer '文本框偏移量
  1500.   
  1501.     '当某种条件成立时禁止文本框激活使单据处于录入状态
  1502.     If Not Fun_AllowInput Then
  1503.         Exit Sub
  1504.     End If
  1505.   
  1506.     '显示文本框前返回有效行列(解决滚动条问题)
  1507.     Call Xldqh
  1508.     Call Xldql
  1509.   
  1510.     '隐藏文本框,帮助按钮,列表组合框
  1511.     Call Ycwbk
  1512.   
  1513.     With BanlGrid2
  1514.         Dqlrwgh = .Row
  1515.         Dqlrwgl = .Col
  1516.         If Not GridBoolean(.Col, 1) Or .Row < .FixedRows Then
  1517.             Exit Sub
  1518.         End If
  1519.      
  1520.         Wbkpy = 30
  1521.         Wbkpy1 = 15
  1522.     
  1523.         On Error Resume Next
  1524.         
  1525.         If GridBoolean(.Col, 3) Then
  1526.             YdCombo.Left = .CellLeft + .Left + Wbkpy
  1527.             YdCombo.Top = .CellTop + .Top + Wbkpy
  1528.             YdCombo.Width = .CellWidth - Wbkpy1
  1529.             Call Wbkcl
  1530.             YdCombo.Visible = True
  1531.             YdCombo.SetFocus
  1532.             Ydcommand.Visible = False
  1533.             Ydtext.Visible = False
  1534.         Else
  1535.             If GridBoolean(.Col, 2) Then
  1536.                 Ydcommand.Height = .RowHeight(.Row)  'remonstrate
  1537.                 Ydcommand.Width = Ydcommand.Height
  1538.                 Ydcommand.Left = .Left + .CellLeft + .CellWidth - Ydcommand.Width + Wbkpy
  1539.                 Ydcommand.Top = .Top + .CellTop + .CellHeight - Ydcommand.Height + Wbkpy
  1540.                 Ydcommand.Visible = True
  1541.             Else
  1542.                 Ydcommand.Visible = False
  1543.             End If
  1544.      
  1545.             Ydtext.Left = .CellLeft + .Left + Wbkpy
  1546.             Ydtext.Top = .CellTop + .Top + Wbkpy
  1547.             
  1548.             If Ydcommand.Visible Then
  1549.                 If Sfblbzkd Then
  1550.                     Ydtext.Width = .CellWidth - Ydcommand.Width
  1551.                 Else
  1552.                     Ydtext.Width = .CellWidth - Wbkpy1
  1553.                 End If
  1554.             Else
  1555.                 Ydtext.Width = .CellWidth - Wbkpy1
  1556.             End If
  1557.             
  1558.             Ydtext.Height = .CellHeight - Wbkpy1
  1559.       
  1560.             If GridInt(.Col, 2) <> 0 Then
  1561.                 Ydtext.MaxLength = GridInt(.Col, 2)
  1562.             Else
  1563.                 Ydtext.MaxLength = 3000
  1564.             End If
  1565.       
  1566.             Call Wbkcl
  1567.       
  1568.             Ydtext.Visible = True
  1569.             Ydtext.SetFocus
  1570.         End If
  1571.     
  1572.         Dqtoprow = .TopRow
  1573.         Dqleftcol = .LeftCol
  1574.     
  1575.         '重置锁值
  1576.         Valilock = False
  1577.         Wbkbhlock = False
  1578.     End With
  1579.  
  1580. End Sub
  1581. Private Function Fun_AllowInput() As Boolean                           '当某种条件成立时禁止文本框激活使单据处于录入状态
  1582.    
  1583.     '如果单据操作状态为浏览状态则不能显示录入载体(通用)
  1584. '    If Trim(Lab_OperStatus.Caption) = "1" Then
  1585. '        Exit Function
  1586. '    End If
  1587.    
  1588.     '[>>
  1589.     
  1590.         '此处可以填写禁止文本框激活使单据处于录入状态的理由
  1591.    
  1592.     '<<]
  1593.    
  1594.     Fun_AllowInput = True
  1595.     
  1596. End Function
  1597. Private Sub Cxxswbk()                                                  'Formresize中重新显示文本框,列表框,帮助按钮(通用)
  1598.                    
  1599.     Dim Wbkpy As Integer, Wbkpy1 As Integer
  1600.     
  1601.     Wbkpy = 30
  1602.     Wbkpy1 = 15
  1603.     
  1604.     With BanlGrid2
  1605.         If YdCombo.Visible Then
  1606.             YdCombo.Left = .CellLeft + .Left + Wbkpy
  1607.             YdCombo.Top = .CellTop + .Top + Wbkpy
  1608.             YdCombo.Width = .CellWidth - Wbkpy1
  1609.         End If
  1610.         If Ydcommand.Visible Then
  1611.             Ydcommand.Height = .RowHeight(.Row) 'remonstrate
  1612.             Ydcommand.Width = Ydcommand.Height
  1613.             Ydcommand.Left = .Left + .CellLeft + .CellWidth - Ydcommand.Width + Wbkpy
  1614.             Ydcommand.Top = .Top + .CellTop + .CellHeight - Ydcommand.Height + Wbkpy
  1615.         End If
  1616.         If Ydtext.Visible Then
  1617.             If Ydcommand.Visible Then
  1618.                 If Sfblbzkd Then
  1619.                     Ydtext.Width = .CellWidth - Ydcommand.Width
  1620.                 Else
  1621.                     Ydtext.Width = .CellWidth - Wbkpy1
  1622.                 End If
  1623.             Else
  1624.                 Ydtext.Width = .CellWidth - Wbkpy1
  1625.             End If
  1626.       
  1627.             Ydtext.Left = .CellLeft + .Left + Wbkpy
  1628.             Ydtext.Top = .CellTop + .Top + Wbkpy
  1629.             Ydtext.Height = .CellHeight - Wbkpy1
  1630.         End If
  1631.     End With
  1632.    Call Xldql
  1633. End Sub
  1634. Private Sub Lrsjhx()                                                             '文本框录入数据回写
  1635.   
  1636.     With BanlGrid2
  1637.         If YdCombo.Visible Then
  1638.             .Text = Trim(YdCombo.Text)
  1639.         End If
  1640.         If Ydtext.Visible Then
  1641.             .Text = Trim(Ydtext.Text)
  1642.         End If
  1643.    
  1644.         '(如果字段录入内容发生变化,则打开有效性判断锁)
  1645.         If Zdlrqnr <> Trim(.Text) Then
  1646.             Yxxpdlock = False
  1647.             Hyxxpdlock = False
  1648.         End If
  1649.    
  1650.         '隐藏文本框,帮助按钮,列表组合框
  1651.         Call Ycwbk
  1652.    
  1653.     End With
  1654.     
  1655. End Sub
  1656. Private Sub BanlGrid2_KeyDown(KeyCode As Integer, Shift As Integer)              '网格快捷键
  1657.   
  1658.     '如果单据操作状态为浏览状态则不能显示录入载体
  1659. '    If Trim(Lab_OperStatus.Caption) = "1" Then
  1660. '        Exit Sub
  1661. '    End If
  1662.     Select Case KeyCode
  1663.         Case vbKeyF2                   '按F2键参照
  1664.             Call xswbk
  1665.             Call Lrzdbz
  1666.     End Select
  1667. End Sub
  1668. Private Sub BanlGrid2_KeyPress(KeyAscii As Integer)                              '网格接受键盘录入
  1669.     '当某种条件成立时禁止文本框激活使单据处于录入状态
  1670.     If Not Fun_AllowInput Then
  1671.         Exit Sub
  1672.     End If
  1673.   
  1674.     With BanlGrid2
  1675.   
  1676.         '屏 蔽 回 车 键
  1677.         If KeyAscii = vbKeyReturn Then
  1678.             KeyAscii = 0
  1679.             Rowjsq = .Row
  1680.             Coljsq = .Col + 1
  1681.             If Coljsq > .Cols - 1 Then
  1682.                 If Rowjsq < .Rows - 1 Then
  1683.                     Rowjsq = Rowjsq + 1
  1684.                 End If
  1685.                 Coljsq = Qslz
  1686.             End If
  1687.             Do While Rowjsq <= .Rows - 1
  1688.                 If .ColHidden(Coljsq) Or (Not GridBoolean(Coljsq, 1)) Then
  1689.                     Coljsq = Coljsq + 1
  1690.                     If Coljsq > .Cols - 1 Then
  1691.                         Rowjsq = Rowjsq + 1
  1692.                         Coljsq = Qslz
  1693.                     End If
  1694.                 Else
  1695.                     Exit Do
  1696.                 End If
  1697.             Loop
  1698.           
  1699.             If Rowjsq <= .Rows - 1 Then
  1700.                 .Select Rowjsq, Coljsq
  1701.             End If
  1702.        
  1703.             Exit Sub
  1704.        
  1705.         End If
  1706.      
  1707.         '接受用户录入
  1708.         Select Case KeyAscii
  1709.             Case 0 To 32             '用户输入KeyAscii为0-32的键 如空格
  1710.                 '显示录入载体
  1711.                 Call xswbk
  1712.             Case Else
  1713.                 
  1714.                 '防止非编辑字段SendKeys()出现死循环
  1715.                 If Not GridBoolean(.Col, 1) Or .Row < .FixedRows Then
  1716.                     Exit Sub
  1717.                 End If
  1718.                 
  1719.                 '如果此字段为列表框录入则调入相应列表框
  1720.                 If GridBoolean(.Col, 3) Then
  1721.                    '列表框录入
  1722.                     Call xswbk
  1723.                 Else
  1724.                     Ydtext.Text = ""
  1725.             
  1726.                     '录入限制
  1727.                     Call InputFieldLimit(Ydtext, GridInt(BanlGrid2.Col, 1), KeyAscii)
  1728.                     If KeyAscii = 0 Then
  1729.                         Exit Sub
  1730.                     End If
  1731.                     Call xswbk
  1732.                     Ydtext.Text = ""
  1733.                     Valilock = True
  1734.                     SendKeys Chr(KeyAscii), True
  1735.                     DoEvents
  1736.                     Valilock = False
  1737.                 End If
  1738.         End Select
  1739.     End With
  1740. End Sub
  1741. Private Sub Qkwlzd(sjh As Long, Sjl As Long)                            '清空为零字段
  1742.     
  1743.     If Not GridBoolean(Sjl, 5) Then
  1744.         Exit Sub
  1745.     End If
  1746.     
  1747.     With BanlGrid2
  1748.         If Val(Trim(.TextMatrix(sjh, Sjl))) = 0 Then
  1749.             .TextMatrix(sjh, Sjl) = ""
  1750.         End If
  1751.     End With
  1752. End Sub
  1753. Private Sub fhyxh()                                                     '返回录入数据有效行,同时让得到焦点网格可见
  1754.     
  1755.     With BanlGrid2
  1756.         If .Row >= .FixedRows Then
  1757.             Call Xldqh
  1758.         End If
  1759.     End With
  1760. End Sub
  1761. Private Sub Xldqh()                                                      '显露当前行
  1762.     
  1763.     Dim Toprowte As Long
  1764.     With BanlGrid2
  1765.         Toprowte = 0
  1766.         Do While .CellTop + .RowHeight(.Row) + Fzxwghs * Sjhgd > .Height And .TopRow <> Toprowte
  1767.             Toprowte = .TopRow
  1768.             .TopRow = .TopRow + 1
  1769.         Loop
  1770.         Toprowte = 0
  1771.         Do While .CellTop < .FixedRows * .RowHeight(0) And .TopRow <> Toprowte
  1772.             Toprowte = .TopRow
  1773.             If .TopRow > 1 Then
  1774.                 .TopRow = .TopRow - 1
  1775.             End If
  1776.         Loop
  1777.     End With
  1778. End Sub
  1779. Private Sub Xldql()                                                                  '显露当前列
  1780.     
  1781.     Dim Leftcolte As Long
  1782.     With BanlGrid2
  1783.         If .Col >= Qslz And .Col >= .FixedCols Then
  1784.             If .LeftCol > .Col Then
  1785.                 .LeftCol = .Col
  1786.             End If
  1787.             Leftcolte = 0
  1788.             Do While .CellLeft + .CellWidth > .Width And .LeftCol <> Leftcolte
  1789.                 Leftcolte = .LeftCol
  1790.                 .LeftCol = .LeftCol + 1
  1791.             Loop
  1792.         End If
  1793.     End With
  1794. End Sub
  1795. Private Sub BanlGrid2_BeforeMoveColumn(ByVal Col As Long, Position As Long)           '网格列发生移动时自动交换网格索引信息
  1796.     Call FnBln_RefreshArray(Col, Position, GridStr(), GridInf())
  1797. End Sub
  1798. Private Sub bbyl(bbylte As Boolean)                    '报表打印预览
  1799.     
  1800.     Dim Bbzbt$, Bbxbt() As String, bbxbtzzxs() As Integer, Bbxbtgs As Integer
  1801.     Dim Bbbwh() As String, Bbbwhzzxs() As Integer, Bbbwhgs As Integer
  1802.     Bbxbtgs = 1                                          '报 表 小 标 题 行 数
  1803.     Bbbwhgs = 0                                          '报 表 表 尾 行 数
  1804.     ReDim Bbxbt(1 To Bbxbtgs)
  1805.     ReDim bbxbtzzxs(1 To Bbxbtgs)
  1806.     If Bbbwhgs <> 0 Then
  1807.         ReDim Bbbwh(1 To Bbbwhgs)
  1808.         ReDim Bbbwhzzxs(1 To Bbbwhgs)
  1809.     End If
  1810.     Bbzbt = ReportTitle
  1811.     Call Scyxsjb(BanlGrid1)                               '生成报表数据
  1812.     Call Scdybb(Dyymctbl, Bbzbt, Bbxbt(), bbxbtzzxs(), Bbxbtgs, Bbbwh(), Bbbwhzzxs(), Bbbwhgs, bbylte)
  1813.     If Not bbylte Then
  1814.         Unload DY_Tybbyldy
  1815.     End If
  1816. End Sub
  1817. Private Sub Sub_HandBalance()
  1818.         Dim int_temp As Integer
  1819.         Select Case Left(Trim(Combo1.Text), 1)
  1820.             Case "1" '入库单、发票、费用发票结算
  1821.                 If BanlGrid1.FixedRows = BanlGrid1.Rows Then
  1822.                     Tsxx = "必须同时选择发票和入库单且发票数量(实物)等于入库单数量!"
  1823.                     Call Xtxxts(Tsxx, 0, 1)
  1824.                     Exit Sub
  1825.                 End If
  1826.                 With BanlGrid1
  1827.                     For int_temp = .FixedRows To .Rows - 1  '判断处有一点问题,不能解决入库单合正好为零的情况
  1828.                         If .IsSubtotal(int_temp) = True Then
  1829.                             If Abs(.ValueMatrix(int_temp, Sydz("007", GridStr1(), Szzls1)) - (.ValueMatrix(int_temp, Sydz("008", GridStr1(), Szzls1)) - .ValueMatrix(int_temp, Sydz("013", GridStr1(), Szzls1)) - .ValueMatrix(int_temp, Sydz("014", GridStr1(), Szzls1)))) > 0.0000001 Then
  1830.                                 Tsxx = "必须同时选择发票和入库单且发票数量(实物)等于入库单数量!"
  1831.                                 Call Xtxxts(Tsxx, 0, 1)
  1832.                                 Exit Sub
  1833.                             End If
  1834.                             If (.ValueMatrix(int_temp, Sydz("008", GridStr1(), Szzls1)) - .ValueMatrix(int_temp, Sydz("013", GridStr1(), Szzls1)) - .ValueMatrix(int_temp, Sydz("014", GridStr1(), Szzls1))) = 0 Then
  1835.                                 Tsxx = "必须同时选择发票和入库单且发票数量(实物)等于入库单数量!"
  1836.                                 Call Xtxxts(Tsxx, 0, 1)
  1837.                                 Exit Sub
  1838.                             End If
  1839.                         End If
  1840.                     Next int_temp
  1841.                 End With
  1842.             Case "2" '入库单、发票结算
  1843.                 If BanlGrid1.FixedRows = BanlGrid1.Rows Then
  1844.                     Tsxx = "必须同时选择发票和入库单且发票数量(实物)等于入库单数量!"
  1845.                     Call Xtxxts(Tsxx, 0, 1)
  1846.                     Exit Sub
  1847.                 End If
  1848.                 If BanlGrid2.FixedRows <> BanlGrid2.Rows Then
  1849.                     Tsxx = "所选发票中有费用存在!"
  1850.                     Call Xtxxts(Tsxx, 0, 1)
  1851.                     Exit Sub
  1852.                 End If
  1853.                 With BanlGrid1
  1854.                    For int_temp = .FixedRows To .Rows - 1
  1855.                         If .IsSubtotal(int_temp) = True Then
  1856.                             If Abs(.ValueMatrix(int_temp, Sydz("007", GridStr1(), Szzls1)) - (.ValueMatrix(int_temp, Sydz("008", GridStr1(), Szzls1)) - .ValueMatrix(int_temp, Sydz("013", GridStr1(), Szzls1)) - .ValueMatrix(int_temp, Sydz("014", GridStr1(), Szzls1)))) > 0.0000001 Then
  1857.                                 Tsxx = "必须同时选择发票和入库单且发票数量(实物)等于入库单数量!"
  1858.                                 Call Xtxxts(Tsxx, 0, 1)
  1859.                                 Exit Sub
  1860.                             End If
  1861.                             If (.ValueMatrix(int_temp, Sydz("008", GridStr1(), Szzls1)) - .ValueMatrix(int_temp, Sydz("013", GridStr1(), Szzls1)) - .ValueMatrix(int_temp, Sydz("014", GridStr1(), Szzls1))) = 0 Then
  1862.                                 Tsxx = "必须同时选择发票和入库单且发票数量(实物)等于入库单数量!"
  1863.                                 Call Xtxxts(Tsxx, 0, 1)
  1864.                                 Exit Sub
  1865.                             End If
  1866.                         End If
  1867.                    Next int_temp
  1868.                 End With
  1869.             Case "3" '费用发票单独结算
  1870.                 If BanlGrid1.FixedRows <> BanlGrid1.Rows Then
  1871.                     Tsxx = "只能选择全是费用的发票!"
  1872.                     Call Xtxxts(Tsxx, 0, 1)
  1873.                     Exit Sub
  1874.                 End If
  1875.                 If BanlGrid2.FixedRows = BanlGrid2.Rows Then
  1876.                     Tsxx = "未选择费用发票!"
  1877.                     Call Xtxxts(Tsxx, 0, 1)
  1878.                     Exit Sub
  1879.                 End If
  1880.                 With BanlGrid2
  1881.                     For int_temp = .FixedRows To .Rows - 1
  1882.                         If Trim(.TextMatrix(int_temp, Sydz("009", GridStr(), Szzls))) = "" Or Trim(.TextMatrix(int_temp, Sydz("010", GridStr(), Szzls))) = "" Then
  1883.                             banl_flag = False
  1884.                             Tsxx = "费用发票单独结算时必须输入对应仓库和对应物料!"
  1885.                             Call Xtxxts(Tsxx, 0, 1)
  1886.                             Exit Sub
  1887.                         End If
  1888.                     Next
  1889.                 End With
  1890.             Case "4" '正负发票结算
  1891.                 Exit Sub
  1892.             Case "5" '正负入库单结算
  1893.                 Exit Sub
  1894.             Case Else
  1895.                 Tsxx = "未选择结算方式!"
  1896.                 Call Xtxxts(Tsxx, 0, 1)
  1897.                 Exit Sub
  1898.         End Select
  1899.             Cw_DataEnvi.DataConnect.BeginTrans
  1900.             If Fun_HandBalanceExecute(Left(Trim(Combo1.Text), 1)) = True Then
  1901.                 Cw_DataEnvi.DataConnect.CommitTrans
  1902.                 Tsxx = "结算完成!"
  1903.                 Call Xtxxts(Tsxx, 0, 4)
  1904.                 BanlGrid1.Rows = BanlGrid1.FixedRows
  1905.                 BanlGrid2.Rows = BanlGrid2.FixedRows
  1906.             Else
  1907.                 Cw_DataEnvi.DataConnect.RollbackTrans
  1908.             End If
  1909.             ProgressBar1.Visible = False
  1910. End Sub
  1911. Private Function Fun_HandBalanceExecute(BalanceType As String) As Boolean
  1912.     Dim int_temp As Integer
  1913.     Dim str_sqlTemp As String
  1914.     Dim str_temp As String
  1915.     Dim rst_temp As New ADODB.Recordset
  1916.     Dim str_UpdateSql As String
  1917.     Dim str_InsertSql As String
  1918.     Dim Lng_TotalMoney As Double                     '发票总金额(包括非合理损耗)
  1919.     Dim lng_TotalQuantity As Double                      '发票总数量
  1920.     Dim lng_WasteMoneyPercentage As Double               '按金额比率
  1921.     Dim lng_WasteQuantityPercentage As Double            '按数量比率
  1922.     Dim lng_NotinreasonWasteMoney As Double              '非合理损耗金额总额
  1923.     Dim Lng_TotalMoneyInvoice As Double                  '发票总金额除非合理损耗
  1924.     Dim Lng_WasteMoney As Double                         '分摊费用总额
  1925.     Dim Lng_TotalquanInOut As Double                     '入库单的实物数量
  1926.     
  1927.     Dim int_MainId As Integer                         '结算单主Id
  1928.     Dim str_BillCode As String
  1929.     Dim str_WhCode As String
  1930.     Dim str_MNumber As String
  1931.     Dim RKd_MainCode As String
  1932.     Dim RKd_MainId As Integer
  1933.     Dim str_SupplierCode As String
  1934. On Error GoTo errExecute
  1935.     Select Case BalanceType
  1936.         Case "1", "2"
  1937.             ProgressBar1.Max = (BanlGrid2.Rows - 1) * 15 + (BanlGrid1.Rows - 1) * 10 + 60
  1938.             Call ProgressBar_move
  1939.             Lng_WasteMoney = 0
  1940.             If BanlGrid2.FixedRows <> BanlGrid2.Rows Then
  1941.                 For int_temp = BanlGrid2.FixedRows To BanlGrid2.Rows - 1
  1942.                     If Trim(BanlGrid2.TextMatrix(int_temp, Sydz("009", GridStr(), Szzls))) = "" Or Trim(BanlGrid2.TextMatrix(int_temp, Sydz("010", GridStr(), Szzls))) = "" Then
  1943.                         Lng_WasteMoney = Lng_WasteMoney + BanlGrid2.ValueMatrix(int_temp, Sydz("007", GridStr(), Szzls))
  1944.                     End If
  1945.                 Next int_temp
  1946.             End If
  1947.             lng_NotinreasonWasteMoney = 0
  1948.             Call ProgressBar_move
  1949.             With BanlGrid1
  1950.                 For int_temp = .FixedRows To .Rows - 1
  1951.                 Call ProgressBar_move
  1952.                     If .IsSubtotal(int_temp) = False And .ValueMatrix(int_temp, 1) = 1 Then    '回写发票
  1953.                         str_UpdateSql = "UPDATE Cg_InvoiceSub " & _
  1954.                                         " SET InreasonWasteQuan =" & .ValueMatrix(int_temp, Sydz("013", GridStr1(), Szzls1)) & "/ (isnull((SELECT TOP 1 (A.PurInvCon1 / A.PurInvCon2) FROM Gy_Material A WHERE Mnumber = Cg_InvoiceSub.Mnumber), 1)) " & _
  1955.                                         " , NotinreasonWasteQuan =" & .ValueMatrix(int_temp, Sydz("014", GridStr1(), Szzls1)) & "/ (isnull((SELECT TOP 1 (A.PurInvCon1 / A.PurInvCon2) FROM Gy_Material A WHERE Mnumber = Cg_InvoiceSub.Mnumber), 1)) " & _
  1956.                                         ", NotinreasonWasteMoney = " & .ValueMatrix(int_temp, Sydz("015", GridStr1(), Szzls1)) & _
  1957.                                         " WHERE (InvoiceMainID = " & .ValueMatrix(int_temp, 2) & ") AND (InvoiceSubID = " & .ValueMatrix(int_temp, 3) & ")"
  1958.                         Cw_DataEnvi.DataConnect.Execute (str_UpdateSql)
  1959.                         lng_NotinreasonWasteMoney = lng_NotinreasonWasteMoney + .ValueMatrix(int_temp, Sydz("015", GridStr1(), Szzls1)) '非合理损耗金额总额
  1960.                     End If
  1961.                 Next int_temp
  1962.                 
  1963.                 str_sqlTemp = "SELECT SUM(FactReceiptQuan) AS FactReceiptQuanTotal FROM Gy_InOutSub  where " & Me.InOut_FilterCondition
  1964.                 Set rst_temp = Cw_DataEnvi.DataConnect.Execute(str_sqlTemp)
  1965.                 Lng_TotalquanInOut = 0
  1966.                 If rst_temp.RecordCount <> 0 Then
  1967.                     Lng_TotalquanInOut = rst_temp.Fields(0)
  1968.                 End If
  1969.                 rst_temp.Close
  1970.                 Set rst_temp = Nothing
  1971.                 Call ProgressBar_move
  1972.                 str_sqlTemp = "SELECT ISNULL(SUM(A.TotalMoneyBb - ISNULL(A.NotinreasonWasteMoney, 0)), 0)  " & _
  1973.                                       " AS TotalMoneyBb, ISNULL(SUM(A.Quantity * (B.PurInvCon1 / B.PurInvCon2)) " & _
  1974.                                       " - SUM(ISNULL(A.NotinreasonWasteQuan, 0) * (B.PurInvCon1 / B.PurInvCon2)) " & _
  1975.                                       " - SUM(ISNULL(A.InreasonWasteQuan, 0) * (B.PurInvCon1 / B.PurInvCon2)), 0) " & _
  1976.                                       " AS quantity " & _
  1977.                                " FROM Cg_InvoiceSub A INNER JOIN " & _
  1978.                                       " Gy_Material B ON A.MNumber = B.MNumber " & _
  1979.                                " WHERE (A.IsCharge = 0) and " & Me.Invoice_FilterCondition
  1980.                Set rst_temp = Cw_DataEnvi.DataConnect.Execute(str_sqlTemp)
  1981.                Lng_TotalMoney = 0
  1982.                lng_TotalQuantity = 0
  1983.                If rst_temp.RecordCount <> 0 Then
  1984.                     rst_temp.MoveFirst
  1985.                     Lng_TotalMoney = rst_temp.Fields(0).Value
  1986.                     lng_TotalQuantity = rst_temp.Fields(1).Value
  1987.                End If
  1988.                rst_temp.Close
  1989.                Set rst_temp = Nothing
  1990.                 Call ProgressBar_move
  1991.                If Lng_TotalquanInOut <> lng_TotalQuantity Then                '结算前的判断
  1992.                     Tsxx = "发票或入库单有变化,结算失败!"
  1993.                     Call Xtxxts(Tsxx, 0, 1)
  1994.                     Fun_HandBalanceExecute = False
  1995.                     Exit Function
  1996.                End If
  1997.                
  1998.                lng_WasteMoneyPercentage = 0
  1999.                lng_WasteQuantityPercentage = 0
  2000.                If Lng_TotalMoney <> 0 Then '求得分摊比率
  2001.                     lng_WasteMoneyPercentage = Lng_WasteMoney / Lng_TotalMoney
  2002.                End If
  2003.                If lng_TotalQuantity <> 0 Then
  2004.                     lng_WasteQuantityPercentage = Lng_WasteMoney / lng_TotalQuantity
  2005.                End If
  2006.                If Me.Option1.Value = True Then '数量分摊
  2007.                     For int_temp = .FixedRows To .Rows - 1
  2008.                         Call ProgressBar_move
  2009.                         If .IsSubtotal(int_temp) = False And .ValueMatrix(int_temp, 1) = 1 Then
  2010.                             str_UpdateSql = "UPDATE Cg_InvoiceSub " & _
  2011.                                             " Set DistributeCharge = Quantity * (isnull((SELECT TOP 1 (A.PurInvCon1 / A.PurInvCon2) FROM Gy_Material A WHERE Mnumber = Cg_InvoiceSub.Mnumber), 1) * " & lng_WasteQuantityPercentage & ")" & _
  2012.                                             " WHERE (InvoiceMainID = " & .ValueMatrix(int_temp, 2) & ") AND (InvoiceSubID = " & .ValueMatrix(int_temp, 3) & ")"
  2013.                             Cw_DataEnvi.DataConnect.Execute (str_UpdateSql)
  2014.                         End If
  2015.                     Next int_temp
  2016.                ElseIf Me.Option1.Value = False Then '金额分摊
  2017.                     For int_temp = .FixedRows To .Rows - 1
  2018.                         Call ProgressBar_move
  2019.                         If .IsSubtotal(int_temp) = False And .ValueMatrix(int_temp, 1) = 1 Then
  2020.                             str_UpdateSql = "UPDATE Cg_InvoiceSub " & _
  2021.                                             " Set DistributeCharge = ((TotalMoneyBb - IsNull(NotinreasonWasteMoney, 0)) * " & lng_WasteMoneyPercentage & ")" & _
  2022.                                             " WHERE (InvoiceMainID = " & .ValueMatrix(int_temp, 2) & ") AND (InvoiceSubID = " & .ValueMatrix(int_temp, 3) & ")"
  2023.                             Cw_DataEnvi.DataConnect.Execute (str_UpdateSql)
  2024.                         End If
  2025.                     Next int_temp
  2026.                Else
  2027.                     Tsxx = "未选择费用的分摊方式!"
  2028.                     Call Xtxxts(Tsxx, 0, 1)
  2029.                     Fun_HandBalanceExecute = False
  2030.                     Exit Function
  2031.                End If
  2032.                 For int_temp = .FixedRows To .Rows - 1   '处理发票差额
  2033.                     If .IsSubtotal(int_temp) = False And .ValueMatrix(int_temp, 1) = 1 Then
  2034.                     Call ProgressBar_move
  2035.                         
  2036.                         str_UpdateSql = "UPDATE Cg_InvoiceSub " & _
  2037.                                         " Set DistributeCharge = DistributeCharge+ (SELECT " & Lng_WasteMoney & "- ISNULL(SUM(DistributeCharge), 0) AS TatolDistributeCharge " & _
  2038.                                                                                    " From Cg_InvoiceSub " & _
  2039.                                                                                    " WHERE (IsCharge = 0) " & "and " & Me.Invoice_FilterCondition & ")" & _
  2040.                                         " WHERE (InvoiceMainID = " & .ValueMatrix(int_temp, 2) & ") AND (InvoiceSubID = " & .ValueMatrix(int_temp, 3) & ")"
  2041.                         Cw_DataEnvi.DataConnect.Execute (str_UpdateSql)
  2042.                         Exit For
  2043.                     End If
  2044.                 Next int_temp
  2045.            End With
  2046.             
  2047.               int_MainId = CreatBillID("1210")
  2048.               str_BillCode = CreatBillCode("1210", True)
  2049.               str_InsertSql = "INSERT INTO Kf_BalanceMain " & _
  2050.                             "(BalanceMainId, BillNum, BillCode, SupplierCode, OperType, DeptCode, PersonCode, " & _
  2051.                             " Maker, BillDate, KjYear, Period, BanlType) " & _
  2052.                             " SELECT TOP 1 " & int_MainId & ",'" & str_BillCode & "', '1210', SupplierCode, '库房结算', ltrim(rtrim(DeptCode)), ltrim(rtrim(PersonCode)),'" & Xtczy & "',convert(datetime,'" & Xtrq & "')," & Xtyear & "," & Xtmm & ",1" & _
  2053.                             " FROM Cg_InvoiceMain " & _
  2054.                             " where InvoiceMainID in (SELECT A.InvoiceMainID " & _
  2055.                                                         " FROM Cg_InvoiceMain A INNER JOIN  Cg_InvoiceSub B ON A.InvoiceMainID = B.InvoiceMainID" & _
  2056.                                                         " Where (b.IsCharge = 0) and Cg_InvoiceMain." & Trim(Me.Invoice_FilterCondition) & ")"
  2057.               
  2058.               Cw_DataEnvi.DataConnect.Execute (str_InsertSql) '生成结算单主表
  2059.                Call ProgressBar_move
  2060.                str_InsertSql = "SELECT " & int_MainId & " AS MainId, IDENTITY (int, 1, 1) AS SubId, MNumber, isnull" & _
  2061.                                           " ((SELECT SUM(isnull(FactReceiptQuan, 0))" & _
  2062.                                           " From Gy_InOutSub" & _
  2063.                                           " WHERE mnumber = Cg_InvoiceSub.mnumber and  " & Me.InOut_FilterConditionO & "), 0) AS Quantity," & _
  2064.                                       " SUM(TotalMoneyBb + ISNULL(DistributeCharge, 0)" & _
  2065.                                       " - ISNULL(NotinreasonWasteMoney, 0)) AS EMoney," & _
  2066.                                       " SUM(TotalMoneyBb + ISNULL(DistributeCharge, 0)" & _
  2067.                                       " - ISNULL(NotinreasonWasteMoney, 0)) / isnull" & _
  2068.                                           " ((SELECT SUM(isnull(FactReceiptQuan, 0))" & _
  2069.                                           " From Gy_InOutSub" & _
  2070.                                           " WHERE mnumber = Cg_InvoiceSub.mnumber and  " & Me.InOut_FilterConditionO & "), 1) AS price," & _
  2071.                                      "SUM(isnull(TaxMoneyBb,0)) as TaxMoneyBb, " & _
  2072.                                       " SUM(TotalMoneyBb + ISNULL(DistributeCharge, 0)" & _
  2073.                                       " - ISNULL(NotinreasonWasteMoney, 0))+SUM(isnull(TaxMoneyBb,0)) as TotalMoney " & _
  2074.                                 " INTO #remonstrate" & _
  2075.                                 " From Cg_InvoiceSub" & _
  2076.                                 " Where (IsCharge = 0) And " & Me.Invoice_FilterCondition & _
  2077.                                 " GROUP BY MNumber"
  2078.                Cw_DataEnvi.DataConnect.Execute ("Kf_Sp_BalanceCreateSub '" & str_InsertSql & "' , 0 ") '生成结算单子表
  2079.                Call ProgressBar_move
  2080.                str_InsertSql = " INSERT INTO Kf_BalanceRelation " & _
  2081.                        " (BalanceMainId, InvoiceMainID, InOutMainId, InOutSubId) " & _
  2082.                        " SELECT distinct " & int_MainId & ", InvoiceMainID ,0,0  FROM Cg_InvoiceMain where InvoiceMainID in (SELECT A.InvoiceMainID " & _
  2083.                                                         " FROM Cg_InvoiceMain A INNER JOIN  Cg_InvoiceSub B ON A.InvoiceMainID = B.InvoiceMainID" & _
  2084.                                                         " Where (b.IsCharge = 0) and A." & Trim(Me.Invoice_FilterCondition) & ")"
  2085.                Cw_DataEnvi.DataConnect.Execute (str_InsertSql) '生成发票结算关系
  2086.                
  2087.                 If BanlGrid2.FixedRows <> BanlGrid2.Rows Then
  2088.                     For int_temp = BanlGrid2.FixedRows To BanlGrid2.Rows - 1
  2089.                         If Trim(BanlGrid2.TextMatrix(int_temp, Sydz("009", GridStr(), Szzls))) = "" Or Trim(BanlGrid2.TextMatrix(int_temp, Sydz("010", GridStr(), Szzls))) = "" Then
  2090.                             str_sqlTemp = " SELECT * " & _
  2091.                                          " From Kf_BalanceRelation  " & _
  2092.                                          " Where (BalanceMainId = " & int_MainId & ") And (InvoiceMainID = " & BanlGrid2.ValueMatrix(int_temp, 2) & ") "
  2093.                             Set rst_temp = Cw_DataEnvi.DataConnect.Execute(str_sqlTemp)
  2094.                             If rst_temp.RecordCount = 0 Then
  2095.                                 str_InsertSql = "INSERT INTO Kf_BalanceRelation" & _
  2096.                                           " (BalanceMainId, InvoiceMainID, InOutMainId, InOutSubId) " & _
  2097.                                     " VALUES (" & int_MainId & "," & BanlGrid2.ValueMatrix(int_temp, 2) & ",0,0)"
  2098.                                 Cw_DataEnvi.DataConnect.Execute (str_InsertSql) '生成费用发票结算关系
  2099.                             End If
  2100.                             rst_temp.Close
  2101.                             Set rst_temp = Nothing
  2102.                         End If
  2103.                     Next int_temp
  2104.                 End If
  2105.                               
  2106.                Call ProgressBar_move
  2107.                str_InsertSql = " INSERT INTO Kf_BalanceRelation " & _
  2108.                        " (BalanceMainId, InvoiceMainID, InOutMainId, InOutSubId) " & _
  2109.                "SELECT distinct " & int_MainId & ",0,InOutMainId, InOutSubId FROM Gy_InOutSub where " & Me.InOut_FilterCondition
  2110.                Cw_DataEnvi.DataConnect.Execute (str_InsertSql) '生成入库单结算关系
  2111.                Call ProgressBar_move
  2112.                Cw_DataEnvi.DataConnect.Execute ("Kf_Sp_BalanceRelation  " & int_MainId)  '回写入库单及发票
  2113.                 Call ProgressBar_move
  2114.                 Lng_TotalMoneyInvoice = 0 '发票总金额除非合理损耗
  2115.                 str_sqlTemp = "SELECT ISNULL(SUM(TotalMoneyBb),0) " & _
  2116.                                    " FROM Cg_InvoiceSub  " & _
  2117.                                    " WHERE (IsCharge = 0) and " & Me.Invoice_FilterCondition
  2118.                  Set rst_temp = Cw_DataEnvi.DataConnect.Execute(str_sqlTemp)
  2119.                  If rst_temp.RecordCount <> 0 Then
  2120.                     Lng_TotalMoneyInvoice = rst_temp.Fields(0).Value
  2121.                  Else
  2122.                     Tsxx = "进行结算的发票有变化,结算失败!"
  2123.                     Call Xtxxts(Tsxx, 0, 1)
  2124.                     Fun_HandBalanceExecute = False
  2125.                     Exit Function
  2126.                  End If
  2127.                  rst_temp.Close
  2128.                  Set rst_temp = Nothing
  2129.                  Call ProgressBar_move
  2130.                 With BanlGrid1
  2131.                     For int_temp = .FixedRows To .Rows - 1   '处理入库单差额
  2132.                         Call ProgressBar_move
  2133.                         If .IsSubtotal(int_temp) = False And .ValueMatrix(int_temp, 1) = 0 Then
  2134.                             str_UpdateSql = " Update Gy_InOutSub " & _
  2135.                                                 " SET EMoney =EMoney+(SELECT " & Lng_TotalMoneyInvoice - lng_NotinreasonWasteMoney - Lng_WasteMoney & " -SUM(ISNULL(EMoney, 0)) " & _
  2136.                                                             " From Gy_InOutSub " & _
  2137.                                                             " Where " & Me.InOut_FilterCondition & ") " & _
  2138.                                                 " Where(InOutSubId = " & .ValueMatrix(int_temp, 2) & ") And (InOutMainId = " & .ValueMatrix(int_temp, 3) & ")"
  2139.                             Cw_DataEnvi.DataConnect.Execute (str_UpdateSql)
  2140.                             Exit For
  2141.                         End If
  2142.                     Next int_temp
  2143.                 End With
  2144.         
  2145.                 If Bln_ClrkdKfsc = True Then    '是否生成材料入库单
  2146.                     Call ProgressBar_move
  2147.                     str_sqlTemp = "SELECT DISTINCT B.WhCode, C.SupplierCode " & _
  2148.                                 " FROM Kf_BalanceRelation A INNER JOIN " & _
  2149.                                       " Gy_InOutMain B ON A.InOutMainId = B.InOutMainId INNER JOIN Kf_BalanceMain C ON A.BalanceMainId = C.BalanceMainId " & _
  2150.                                 " WHERE (A.BalanceMainId = " & int_MainId & ")"
  2151.                     Set rst_temp = Cw_DataEnvi.DataConnect.Execute(str_sqlTemp)
  2152.                        Call ProgressBar_move
  2153.                        If rst_temp.RecordCount <> 0 Then
  2154.                             rst_temp.MoveFirst
  2155.                             For int_temp = 1 To rst_temp.RecordCount
  2156.                                  Call ProgressBar_move
  2157.                                  str_WhCode = Trim("" & rst_temp.Fields("WhCode"))
  2158.                                  If Trim(str_WhCode) = "" Then
  2159.                                     Tsxx = "入库单中仓库不空,结算失败!"
  2160.                                     Call Xtxxts(Tsxx, 0, 1)
  2161.                                     Fun_HandBalanceExecute = False
  2162.                                     Exit Function
  2163.                                  End If
  2164.                                  str_SupplierCode = Trim("" & rst_temp.Fields("SupplierCode"))
  2165.                                  RKd_MainId = CreatBillID("1212")
  2166.                                  
  2167.                                  str_InsertSql = " INSERT INTO Gy_InOutMain " & _
  2168.                                       " (InOutMainId, BillCode, BillNum, WhCode, InoutFlag, PurTypeCode, OperType,  " & _
  2169.                                       " OperbillNum, BillDate, InoutClassCode, TranCompanyCode, TransferWayCode, " & _
  2170.                                       " BusNum, DeptCode, PersonCode, CusCode, SupplierCode,   " & _
  2171.                                       " ConsignbillNum, Consignbillid,KfChecker , Maker, KjYear, Period,BanlanceId) " & _
  2172.                                 " SELECT top 1 " & RKd_MainId & " ,'1212', '" & CreatBillCode("1212", True, Xtyear, Xtmm, str_WhCode) & "', WhCode, InoutFlag, PurTypeCode, OperType, " & _
  2173.                                       " OperbillNum, convert(datetime,'" & Xtrq & "'), InoutClassCode, TranCompanyCode, TransferWayCode, " & _
  2174.                                       " BusNum, DeptCode, PersonCode, CusCode, '" & str_SupplierCode & "', " & _
  2175.                                       " ConsignbillNum , Consignbillid, '" & Xtczy & "', '" & Xtczy & "', " & Xtyear & ", " & Xtmm & "," & int_MainId & _
  2176.                                 " From Gy_InOutMain " & _
  2177.                                 " Where ltrim(rtrim(WhCode))='" & Trim(str_WhCode) & "' and  InOutMainId  in (SELECT InOutMainId From Kf_BalanceRelation Where (BalanceMainId = " & int_MainId & "))"
  2178.                                 Cw_DataEnvi.DataConnect.Execute (str_InsertSql) '生成材料入库单主表
  2179.                                 
  2180.                                 str_InsertSql = "SELECT IDENTITY (int, 1, 1) AS SubId, " & RKd_MainId & " AS MainId, Gy_InOutSub.MNumber,  " & _
  2181.                                                       " sum(Gy_InOutSub.FactReceiptQuan) as FactReceiptQuan, avg(Gy_InOutSub.Price) as Price , sum(Gy_InOutSub.EMoney) as EMoney, " & _
  2182.                                                       " sum(Gy_InOutSub.EvaluationMoney) as EvaluationMoney, avg(Gy_InOutSub.PlanPrice) as PlanPrice, sum(Gy_InOutSub.PlanMoney) as PlanMoney " & _
  2183.                                                 " into #remonstrate " & _
  2184.                                                 " FROM Gy_InOutSub INNER JOIN " & _
  2185.                                                       " Gy_InOutMain ON Gy_InOutSub.InOutMainId = Gy_InOutMain.InOutMainId " & _
  2186.                                                 " WHERE ( ltrim(rtrim(Gy_InOutMain.WhCode))=''" & Trim(str_WhCode) & "'') AND ((LTRIM(RTRIM(CONVERT(char(20), " & _
  2187.                                                       " Gy_InOutSub.InOutMainId))) + ''#'' + LTRIM(RTRIM(CONVERT(char(10), " & _
  2188.                                                       " Gy_InOutSub.InOutSubId)))) IN " & _
  2189.                                                           " (SELECT ltrim(rtrim(CONVERT(char(20), InoutMainID))) " & _
  2190.                                                                " + ''#'' + ltrim(rtrim(CONVERT(char(10), InoutSubId))) " & _
  2191.                                                          " From Kf_BalanceRelation " & _
  2192.                                                          " WHERE BalanceMainId = " & int_MainId & ")) " & _
  2193.                                                 " Group by  Gy_InOutSub.MNumber"
  2194.                                 Cw_DataEnvi.DataConnect.Execute ("Kf_Sp_BalanceCreateSub '" & str_InsertSql & "' ,1 ")  '生成材料入库单子表
  2195.                                 Call ProgressBar_move
  2196.                                 rst_temp.MoveNext
  2197.                             Next int_temp
  2198.                        Else
  2199.                             Tsxx = "入库单有变化,结算失败!"
  2200.                             Call Xtxxts(Tsxx, 0, 1)
  2201.                             Fun_HandBalanceExecute = False
  2202.                             Exit Function
  2203.                        End If
  2204.                     End If
  2205.                     
  2206.                     '费用发票单独结算
  2207.                 If BanlGrid2.FixedRows <> BanlGrid2.Rows Then
  2208.                     For int_temp = BanlGrid2.FixedRows To BanlGrid2.Rows - 1
  2209.                         If Trim(BanlGrid2.TextMatrix(int_temp, Sydz("009", GridStr(), Szzls))) <> "" And Trim(BanlGrid2.TextMatrix(int_temp, Sydz("010", GridStr(), Szzls))) <> "" Then
  2210.                             '结算前的判断
  2211.                             str_sqlTemp = "SELECT * " & _
  2212.                                           " From Cg_InvoiceSub " & _
  2213.                                           " Where (IsCharge = 1) And (InvoiceMainID = " & BanlGrid2.ValueMatrix(int_temp, 2) & ") And (InvoiceSubID = " & BanlGrid2.ValueMatrix(int_temp, 3) & ") " & _
  2214.                                           " And " & Me.Invoice_FilterCondition
  2215.                             Set rst_temp = Cw_DataEnvi.DataConnect.Execute(str_sqlTemp)
  2216.                             Call ProgressBar_move
  2217.                             If rst_temp.RecordCount = 0 Then
  2218.                                 Tsxx = "发票有变化,结算失败!"
  2219.                                 Call Xtxxts(Tsxx, 0, 1)
  2220.                                 Fun_HandBalanceExecute = False
  2221.                                 Exit Function
  2222.                             End If
  2223.                              rst_temp.Close
  2224.                              Set rst_temp = Nothing
  2225.     
  2226.                             str_WhCode = Trim(BanlGrid2.TextMatrix(int_temp, 4))
  2227.                             str_MNumber = Trim(BanlGrid2.TextMatrix(int_temp, 5))
  2228.                             
  2229.                             int_MainId = CreatBillID("1210")
  2230.                             str_BillCode = CreatBillCode("1210", True)
  2231.                             
  2232.                             str_InsertSql = "INSERT INTO Kf_BalanceRelation" & _
  2233.                                       " (BalanceMainId, InvoiceMainID, InOutMainId, InOutSubId) " & _
  2234.                                 " VALUES (" & int_MainId & "," & BanlGrid2.ValueMatrix(int_temp, 2) & ",0,0)"
  2235.                             Cw_DataEnvi.DataConnect.Execute (str_InsertSql) '生成结算发票关系
  2236.                             
  2237.                             str_InsertSql = "INSERT INTO Kf_BalanceMain " & _
  2238.                                           "(BalanceMainId, BillNum, BillCode, SupplierCode, OperType, DeptCode, PersonCode, " & _
  2239.                                           " Maker, BillDate, KjYear, Period, BanlType) " & _
  2240.                                           " (SELECT TOP 1 " & int_MainId & ",'" & str_BillCode & "', '1210', SupplierCode, '库房结算', ltrim(rtrim(DeptCode)), ltrim(rtrim(PersonCode)),'" & Xtczy & "',convert(datetime,'" & Xtrq & "')," & Xtyear & "," & Xtmm & ",1" & _
  2241.                                           " FROM Cg_InvoiceMain  where InvoiceMainID =" & BanlGrid2.ValueMatrix(int_temp, 2) & ")"
  2242.                             Cw_DataEnvi.DataConnect.Execute (str_InsertSql) '生成结算单主表
  2243.                             Call ProgressBar_move
  2244.                             Cw_DataEnvi.DataConnect.Execute ("Kf_Sp_WasteBalanceRelation  " & int_MainId & ",'" & str_WhCode & "','" & str_MNumber & "'," & BanlGrid2.ValueMatrix(int_temp, 3)) '生成结算单子表
  2245.                             Call ProgressBar_move
  2246.                             If Bln_ClrkdKfsc = True Then    '是否生成费用材料入库单
  2247.                                      str_WhCode = Trim(BanlGrid2.TextMatrix(int_temp, 4))
  2248.                                      If Trim(str_WhCode) = "" Then
  2249.                                         Tsxx = "单独结算的费用发票仓库不能为空!"
  2250.                                         Call Xtxxts(Tsxx, 0, 1)
  2251.                                         Fun_HandBalanceExecute = False
  2252.                                         Exit Function
  2253.                                      End If
  2254.                                      RKd_MainId = CreatBillID("1212")
  2255.                                      RKd_MainCode = CreatBillCode("1212", True, Xtyear, Xtmm, str_WhCode)
  2256.                                      Cw_DataEnvi.DataConnect.Execute ("Kf_Sp_WasteRkd " & int_MainId & "," & RKd_MainId & ",'" & str_WhCode & "','" & RKd_MainCode & "'")
  2257.                             End If
  2258.                         End If
  2259.                     Call ProgressBar_move
  2260.                     Next int_temp
  2261.                End If
  2262.         Case "3"
  2263.              ProgressBar1.Max = (BanlGrid1.Rows - 1) * 10 + 10
  2264.             If BanlGrid2.FixedRows <> BanlGrid2.Rows Then
  2265.                 For int_temp = BanlGrid2.FixedRows To BanlGrid2.Rows - 1
  2266.                     If Trim(BanlGrid2.TextMatrix(int_temp, Sydz("009", GridStr(), Szzls))) <> "" And Trim(BanlGrid2.TextMatrix(int_temp, Sydz("010", GridStr(), Szzls))) <> "" Then
  2267.                         Call ProgressBar_move
  2268.                         '结算前的判断
  2269.                         str_sqlTemp = "SELECT * " & _
  2270.                                       " From Cg_InvoiceSub " & _
  2271.                                       " Where (IsCharge = 1) And (InvoiceMainID = " & BanlGrid2.ValueMatrix(int_temp, 2) & ") And (InvoiceSubID = " & BanlGrid2.ValueMatrix(int_temp, 3) & ") " & _
  2272.                                       " And " & Me.Invoice_FilterCondition
  2273.                         Set rst_temp = Cw_DataEnvi.DataConnect.Execute(str_sqlTemp)
  2274.                         If rst_temp.RecordCount = 0 Then
  2275.                             Tsxx = "发票有变化,结算失败!"
  2276.                             Call Xtxxts(Tsxx, 0, 1)
  2277.                             Fun_HandBalanceExecute = False
  2278.                             Exit Function
  2279.                         End If
  2280.                          rst_temp.Close
  2281.                          Set rst_temp = Nothing
  2282.                         str_WhCode = Trim(BanlGrid2.TextMatrix(int_temp, 4))
  2283.                         str_MNumber = Trim(BanlGrid2.TextMatrix(int_temp, 5))
  2284.                         
  2285.                         int_MainId = CreatBillID("1210")
  2286.                         str_BillCode = CreatBillCode("1210", True)
  2287.                         
  2288.                         str_InsertSql = "INSERT INTO Kf_BalanceRelation" & _
  2289.                                   " (BalanceMainId, InvoiceMainID, InOutMainId, InOutSubId) " & _
  2290.                             " VALUES (" & int_MainId & "," & BanlGrid2.ValueMatrix(int_temp, 2) & ",0,0)"
  2291.                         Cw_DataEnvi.DataConnect.Execute (str_InsertSql) '生成结算发票关系
  2292.                         
  2293.                         str_InsertSql = "INSERT INTO Kf_BalanceMain " & _
  2294.                                       "(BalanceMainId, BillNum, BillCode, SupplierCode, OperType, DeptCode, PersonCode, " & _
  2295.                                       " Maker, BillDate, KjYear, Period, BanlType) " & _
  2296.                                       " (SELECT TOP 1 " & int_MainId & ",'" & str_BillCode & "', '1210', SupplierCode, '库房结算', ltrim(rtrim(DeptCode)), ltrim(rtrim(PersonCode)),'" & Xtczy & "',convert(datetime,'" & Xtrq & "')," & Xtyear & "," & Xtmm & ",1" & _
  2297.                                       " FROM Cg_InvoiceMain  where InvoiceMainID =" & BanlGrid2.ValueMatrix(int_temp, 2) & ")"
  2298.                         Cw_DataEnvi.DataConnect.Execute (str_InsertSql) '生成结算单主表
  2299.                         Call ProgressBar_move
  2300.                         Cw_DataEnvi.DataConnect.Execute ("Kf_Sp_WasteBalanceRelation  " & int_MainId & ",'" & str_WhCode & "','" & str_MNumber & "'," & BanlGrid2.ValueMatrix(int_temp, 3)) '生成结算单子表
  2301.                         Call ProgressBar_move
  2302.                         If Bln_ClrkdKfsc = True Then    '是否生成费用材料入库单
  2303.                                  str_WhCode = Trim(BanlGrid2.TextMatrix(int_temp, 4))
  2304.                                  If Trim(str_WhCode) = "" Then
  2305.                                     Tsxx = "单独结算的费用发票仓库不能为空!"
  2306.                                     Call Xtxxts(Tsxx, 0, 1)
  2307.                                     Fun_HandBalanceExecute = False
  2308.                                     Exit Function
  2309.                                  End If
  2310.                                  RKd_MainId = CreatBillID("1212")
  2311.                                  RKd_MainCode = CreatBillCode("1212", True, Xtyear, Xtmm, str_WhCode)
  2312.                                  Cw_DataEnvi.DataConnect.Execute ("Kf_Sp_WasteRkd " & int_MainId & "," & RKd_MainId & ",'" & str_WhCode & "','" & RKd_MainCode & "'")
  2313.                         End If
  2314.                     End If
  2315.                 Call ProgressBar_move
  2316.                 Next int_temp
  2317.             End If
  2318.     End Select
  2319.     Fun_HandBalanceExecute = True
  2320.     Exit Function
  2321. errExecute:
  2322.     Fun_HandBalanceExecute = False
  2323. End Function
  2324. Private Sub ProgressBar_move()
  2325.     If ProgressBar1.Value = 0 Then
  2326.         ProgressBar1.Visible = True
  2327.         ProgressBar1.Value = ProgressBar1.Value + 5
  2328.     ElseIf ProgressBar1.Value < ProgressBar1.Max - 5 Then
  2329.         ProgressBar1.Value = ProgressBar1.Value + 5
  2330.     Else
  2331.       ProgressBar1.Value = ProgressBar1.Max
  2332.       ProgressBar1.Visible = False
  2333.     End If
  2334. End Sub
  2335. Public Property Get Invoice_FilterCondition() As String
  2336.   Invoice_FilterCondition = str_InvoiceFilterCondition
  2337. End Property
  2338. Public Property Let Invoice_FilterCondition(ByVal vNewValue As String)
  2339.   str_InvoiceFilterCondition = vNewValue
  2340. End Property
  2341. Public Property Get InOut_FilterCondition() As String
  2342.   InOut_FilterCondition = str_InOutFilterCondition
  2343. End Property
  2344. Public Property Let InOut_FilterCondition(ByVal vNewValue As String)
  2345.   str_InOutFilterCondition = vNewValue
  2346. End Property
  2347. Public Property Get InOut_FilterConditionO() As String
  2348.   InOut_FilterConditionO = str_InOutFilterConditionOther
  2349. End Property
  2350. Public Property Let InOut_FilterConditionO(ByVal vNewValue As String)
  2351.   str_InOutFilterConditionOther = vNewValue
  2352. End Property
  2353. Private Sub check_num_for_grid1(mgrid As VSFlexGrid, mkeyascii As Integer)      '文本框录入整数值(负)限制
  2354.   If Not ((mkeyascii >= Asc("0") And Chr(mkeyascii) <= "9") Or (Chr(mkeyascii) = "." And InStr(1, mgrid.EditText, ".") = 0) Or Chr(mkeyascii) = vbKeyBack) Then
  2355.      mkeyascii = 0
  2356.   End If
  2357. End Sub
  2358. Private Sub check_num_for_grid(mgrid As VSFlexGrid, mkeyascii As Integer)      '文本框录入整数值(负)限制
  2359.   If Not ((mkeyascii >= Asc("0") And mkeyascii <= Asc("9")) Or (Chr(mkeyascii) = "." And InStr(1, mgrid.EditText, ".") = 0) Or mkeyascii = vbKeyBack Or (Chr(mkeyascii) = "-" And mgrid.EditSelStart = 0)) Then
  2360.      mkeyascii = 0
  2361.   End If
  2362. End Sub
  2363. Private Function FillCombo1(Combote As ComboBox, Lbkbmte As String, Dwnr As String, AddType As Integer) As String    '填充列表框并定位
  2364.     '函数参数:列表框,列表框分组编码,定位内容,填充类型(0-无空记录  1-有空记录(1个空格) )
  2365.     Dim Lbknrrec As ADODB.Recordset
  2366.   
  2367.     '填充列表框内容
  2368.     Set Lbknrrec = Cw_DataEnvi.DataConnect.Execute("select * from xt_combolist where combo_code='" + Trim(Lbkbmte) + "' order by item_index")
  2369.     Combote.Clear
  2370.     If AddType = 1 Then
  2371.         Combote.AddItem " "
  2372.     End If
  2373.     With Lbknrrec
  2374.         Do While Not .EOF
  2375.             Combote.AddItem Trim(.Fields("item_index")) & "-" & Trim(.Fields("item_content"))
  2376.             .MoveNext
  2377.         Loop
  2378.     End With
  2379.     
  2380.     '定位列表框内容
  2381.     With Combote
  2382.         For jsqte = .ListCount - 1 To 0 Step -1
  2383.             If Dwnr = Trim(.List(jsqte)) Then
  2384.                 Exit For
  2385.             End If
  2386.         Next jsqte
  2387.         If jsqte <> -1 Then
  2388.             Combote.Text = .List(jsqte)
  2389.         Else
  2390.             If .ListCount <> 0 Then
  2391.                 .Text = .List(0)
  2392.             End If
  2393.         End If
  2394.     End With
  2395. End Function