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

企业管理

开发平台:

Visual Basic

  1. VERSION 5.00
  2. Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
  3. Begin VB.Form Balance_KF_Autobalance 
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "自动结算"
  6.    ClientHeight    =   2280
  7.    ClientLeft      =   45
  8.    ClientTop       =   330
  9.    ClientWidth     =   4560
  10.    HelpContextID   =   1215001
  11.    Icon            =   "结算_库房自动结算.frx":0000
  12.    KeyPreview      =   -1  'True
  13.    LinkTopic       =   "Form1"
  14.    MaxButton       =   0   'False
  15.    MinButton       =   0   'False
  16.    ScaleHeight     =   2280
  17.    ScaleWidth      =   4560
  18.    StartUpPosition =   2  '屏幕中心
  19.    Begin VB.Frame Frame2 
  20.       Height          =   1005
  21.       Left            =   60
  22.       TabIndex        =   19
  23.       Top             =   90
  24.       Visible         =   0   'False
  25.       Width           =   4425
  26.       Begin MSComctlLib.ProgressBar ProgressBar 
  27.          Height          =   285
  28.          Left            =   150
  29.          TabIndex        =   21
  30.          Top             =   570
  31.          Width           =   4035
  32.          _ExtentX        =   7117
  33.          _ExtentY        =   503
  34.          _Version        =   393216
  35.          BorderStyle     =   1
  36.          Appearance      =   0
  37.          Scrolling       =   1
  38.       End
  39.       Begin VB.Label Label2 
  40.          Caption         =   "正在进行数据处理..."
  41.          Height          =   255
  42.          Left            =   210
  43.          TabIndex        =   20
  44.          Top             =   240
  45.          Width           =   4005
  46.       End
  47.    End
  48.    Begin VB.CommandButton Cmd_Clear 
  49.       Caption         =   "全清"
  50.       Height          =   300
  51.       Left            =   60
  52.       TabIndex        =   18
  53.       Top             =   1920
  54.       Width           =   1120
  55.    End
  56.    Begin VB.Timer Timer1 
  57.       Enabled         =   0   'False
  58.       Interval        =   1
  59.       Left            =   150
  60.       Top             =   2910
  61.    End
  62.    Begin VB.CommandButton QxCommand 
  63.       Caption         =   "取消(&C)"
  64.       Height          =   300
  65.       Left            =   3360
  66.       TabIndex        =   5
  67.       Top             =   1920
  68.       Width           =   1120
  69.    End
  70.    Begin VB.CommandButton QdCommand 
  71.       Caption         =   "确定(&O)"
  72.       Height          =   300
  73.       Left            =   2160
  74.       TabIndex        =   6
  75.       Top             =   1920
  76.       Width           =   1120
  77.    End
  78.    Begin VB.Frame Frame1 
  79.       Height          =   1785
  80.       Left            =   60
  81.       TabIndex        =   8
  82.       Top             =   60
  83.       Width           =   4425
  84.       Begin VB.CommandButton Ydcommand1 
  85.          Height          =   300
  86.          Index           =   0
  87.          Left            =   2190
  88.          Picture         =   "结算_库房自动结算.frx":1042
  89.          Style           =   1  'Graphical
  90.          TabIndex        =   17
  91.          Top             =   210
  92.          Visible         =   0   'False
  93.          Width           =   300
  94.       End
  95.       Begin VB.TextBox LrText 
  96.          Height          =   300
  97.          Index           =   0
  98.          Left            =   1020
  99.          TabIndex        =   0
  100.          Text            =   "0"
  101.          Top             =   210
  102.          Width           =   1185
  103.       End
  104.       Begin VB.TextBox LrText 
  105.          Height          =   300
  106.          Index           =   1
  107.          Left            =   2850
  108.          TabIndex        =   1
  109.          Text            =   "1"
  110.          Top             =   210
  111.          Width           =   1185
  112.       End
  113.       Begin VB.TextBox LrText 
  114.          Height          =   300
  115.          Index           =   2
  116.          Left            =   1020
  117.          TabIndex        =   2
  118.          Text            =   "2"
  119.          Top             =   600
  120.          Width           =   3015
  121.       End
  122.       Begin VB.TextBox LrText 
  123.          Height          =   300
  124.          Index           =   3
  125.          Left            =   1020
  126.          TabIndex        =   3
  127.          Text            =   "3"
  128.          Top             =   990
  129.          Width           =   3015
  130.       End
  131.       Begin VB.TextBox LrText 
  132.          Height          =   300
  133.          Index           =   4
  134.          Left            =   1020
  135.          TabIndex        =   4
  136.          Text            =   "4"
  137.          Top             =   1380
  138.          Width           =   3015
  139.       End
  140.       Begin VB.CommandButton Ydcommand1 
  141.          Height          =   300
  142.          Index           =   4
  143.          Left            =   4020
  144.          Picture         =   "结算_库房自动结算.frx":13CC
  145.          Style           =   1  'Graphical
  146.          TabIndex        =   12
  147.          Top             =   1380
  148.          Visible         =   0   'False
  149.          Width           =   300
  150.       End
  151.       Begin VB.CommandButton Ydcommand1 
  152.          Height          =   300
  153.          Index           =   2
  154.          Left            =   4020
  155.          Picture         =   "结算_库房自动结算.frx":1756
  156.          Style           =   1  'Graphical
  157.          TabIndex        =   11
  158.          Top             =   600
  159.          Visible         =   0   'False
  160.          Width           =   300
  161.       End
  162.       Begin VB.CommandButton Ydcommand1 
  163.          Height          =   300
  164.          Index           =   1
  165.          Left            =   4020
  166.          Picture         =   "结算_库房自动结算.frx":1AE0
  167.          Style           =   1  'Graphical
  168.          TabIndex        =   10
  169.          Top             =   210
  170.          Visible         =   0   'False
  171.          Width           =   300
  172.       End
  173.       Begin VB.CommandButton Ydcommand1 
  174.          Height          =   300
  175.          Index           =   3
  176.          Left            =   4020
  177.          Picture         =   "结算_库房自动结算.frx":1E6A
  178.          Style           =   1  'Graphical
  179.          TabIndex        =   9
  180.          Top             =   990
  181.          Visible         =   0   'False
  182.          Width           =   300
  183.       End
  184.       Begin VB.Line Line2 
  185.          Index           =   1
  186.          X1              =   2580
  187.          X2              =   2760
  188.          Y1              =   360
  189.          Y2              =   360
  190.       End
  191.       Begin VB.Label Label1 
  192.          Caption         =   "日期:"
  193.          Height          =   255
  194.          Index           =   0
  195.          Left            =   150
  196.          TabIndex        =   16
  197.          Top             =   240
  198.          Width           =   465
  199.       End
  200.       Begin VB.Label Label1 
  201.          Caption         =   "物料编码:"
  202.          Height          =   255
  203.          Index           =   4
  204.          Left            =   120
  205.          TabIndex        =   15
  206.          Top             =   1410
  207.          Width           =   975
  208.       End
  209.       Begin VB.Label Label1 
  210.          Caption         =   "物料分类:"
  211.          Height          =   255
  212.          Index           =   3
  213.          Left            =   150
  214.          TabIndex        =   14
  215.          Top             =   1020
  216.          Width           =   975
  217.       End
  218.       Begin VB.Label Label1 
  219.          Caption         =   "供应商:"
  220.          Height          =   255
  221.          Index           =   2
  222.          Left            =   150
  223.          TabIndex        =   13
  224.          Top             =   660
  225.          Width           =   735
  226.       End
  227.    End
  228.    Begin VB.CheckBox UnloadCheck 
  229.       Caption         =   "卸载窗体"
  230.       Height          =   615
  231.       Left            =   4680
  232.       TabIndex        =   7
  233.       Top             =   1560
  234.       Width           =   825
  235.    End
  236. End
  237. Attribute VB_Name = "Balance_KF_Autobalance"
  238. Attribute VB_GlobalNameSpace = False
  239. Attribute VB_Creatable = False
  240. Attribute VB_PredeclaredId = True
  241. Attribute VB_Exposed = False
  242. '******************************************************************
  243. '*    模 块 名 称 :自动结算
  244. '*    功 能 描 述 :
  245. '*    程序员姓名  :周化江
  246. '*    最后修改人  :周化江
  247. '*    最后修改时间:2001/10/25
  248. '*    备        注:程序中所有依实际情况自定义部分均用[>>  <<]括起
  249. '******************************************************************
  250. Dim Tsxx As String                       '系统信息提示
  251. '以下为固定使用变量(文本框)
  252. Dim Textvar() As Variant                 '存储变体型文本框信息
  253. Dim Textboolean() As Boolean             '存储布尔型文本框信息
  254. Dim Textint() As Integer                 '存储整型文本框信息
  255. Dim Textstr() As String                  '存储字符型文本框信息
  256. Dim Max_Text_Index As Integer            '最大录入文本框索引值
  257. Dim TextGroupCode As String              '文本框录入分组编码
  258. Dim TextValiLock As Boolean              '文本框失去焦点是否进行有效性控制判断
  259. Dim TextValiJudgeLock() As Boolean       '文本框录入有效性判断控制锁
  260. Dim CurTextIndex As Integer              '当前文本框索引值
  261. Dim TextChangeLock As Boolean            '文本框内容变换控制锁
  262. Dim Bln_Cancel As Boolean                '取消按钮信息传递
  263. ' 以下为自定义
  264. Dim Bln_ClrkdKfsc As Boolean
  265. Dim FilterInvoice As String              '发票条件
  266. Dim FilterRKD As String                  'RKD条件
  267. Dim FilterInOut As String                '入库单中是否存在符合的记录
  268. Dim Collect_BalanceRelation() As New Collection
  269. Dim Bln_HaveErr As Boolean
  270. Private Sub Form_KeyPress(KeyAscii As Integer)   '控 制 焦 点 转 移(Fixed)
  271.     
  272.     Dim jdzygs As Integer                         '控件焦点转移个数
  273.     jdzygs = 8
  274.     Select Case KeyAscii
  275.     Case vbKeyReturn
  276.         If Kjjdzy(jdzygs) Then
  277.             KeyAscii = 0
  278.         End If
  279.     Case 39           '屏蔽"'"
  280.         KeyAscii = 0
  281.     End Select
  282.     
  283. End Sub
  284. Private Sub Form_Load()
  285.     
  286.     '以下为文本框处理程序(Fixed)
  287.     TextGroupCode = "Kf_Autobalance"
  288.     Call Drwbkxx(TextGroupCode, Textvar(), Textboolean(), Textint(), Textstr())  '读入文本框录入信息
  289.     Call Wbkcsh
  290.     
  291.     '[>>初始化查询条件默认值
  292.     LrText(0).Text = Format(CDate(Xtrq), "yyyy-mm-dd")
  293.     LrText(1).Text = Format(CDate(Xtrq), "yyyy-mm-dd")
  294.     '<<]
  295.     
  296. End Sub
  297. Private Sub QdCommand_Click()                                   '确 定
  298.     
  299.     '录入条件有效性判断(Fixed)
  300.     If Not Lrtjyxxpd Then
  301.         Exit Sub
  302.     End If
  303.     '<<]
  304.     Bln_ClrkdKfsc = Fun_ClrkdKfsc ''材料入库单是不是由库房生成
  305.     Call FilterCondition
  306.     If Check_InoutMain Then
  307.         Call Autobalance
  308.     End If
  309. End Sub
  310. Private Sub Autobalance()
  311.     Dim int_temp As Long
  312.     Dim rst_temp As New ADODB.Recordset
  313.     Dim str_sqlTemp As String
  314.     Dim str_SqlInOut As String
  315.     Dim Rst_Invoice As New ADODB.Recordset
  316.     Dim Rst_InOut As New ADODB.Recordset
  317.     Dim int_InvoiceMainID As Integer
  318.     Dim int_FrmHeight As Integer
  319. On Error GoTo Swcwcl
  320.     Cw_DataEnvi.DataConnect.BeginTrans
  321.     
  322.     Set Rst_Invoice = Cw_DataEnvi.DataConnect.Execute("select InvoiceMainID, CgBalanceCode, InvoiceDate, SupplierCode, MNumber, InvSortcode from kf_V_BalanceCG " & FilterInvoice)
  323.     If Rst_Invoice.RecordCount = 0 Then
  324.         Tsxx = "没有可以结算的发票数据!"
  325.         Call Xtxxts(Tsxx, 0, 4)
  326.         Rst_Invoice.Close
  327.         Set Rst_Invoice = Nothing
  328.         Cw_DataEnvi.DataConnect.RollbackTrans
  329.         Exit Sub
  330.     End If
  331.     int_FrmHeight = Me.Height
  332.     Me.Height = 1785
  333.     Me.Frame1.Visible = False
  334.     Me.Refresh
  335.     Me.ProgressBar.Max = Rst_Invoice.RecordCount + 1
  336.     Me.ProgressBar.Value = 0
  337.     Me.Frame2.Visible = True
  338.     Me.Refresh
  339.     
  340.     Rst_Invoice.MoveFirst
  341.     int_InvoiceMainID = Rst_Invoice.Fields("InvoiceMainID").Value
  342.     int_temp = 0
  343.     Int_InvoiceSubNumber = 0
  344.     ReDim Collect_BalanceRelation(0) As New Collection
  345.     With Rst_Invoice
  346.         Do While Not .EOF    '结算过程
  347.               Me.ProgressBar.Value = Me.ProgressBar.Value + 1
  348.               Me.Label2.Caption = Label2.Caption & ".."
  349.               str_SqlInOut = "SELECT Gy_InOutMain.InOutMainId,Gy_InOutSub.InOutSubId ,Gy_InOutMain.WhCode " & _
  350.                                 " FROM Gy_InOutMain INNER JOIN " & _
  351.                                       " Gy_InOutSub ON Gy_InOutMain.InOutMainId = Gy_InOutSub.InOutMainId INNER JOIN" & _
  352.                                       " Gy_Material ON Gy_InOutSub.MNumber = Gy_Material.MNumber" & _
  353.                                 " WHERE (Gy_InOutSub.BalanceDate IS NULL) AND (LTRIM(RTRIM(Gy_InOutMain.BillCode)) " & _
  354.                                       " = '1201' or LTRIM(RTRIM(Gy_InOutMain.BillCode))='1211' ) AND (LTRIM(RTRIM(ISNULL(Gy_InOutMain.SupplierCode, ''))) " & _
  355.                                       " + '#' + LTRIM(RTRIM(ISNULL(Gy_InOutSub.MNumber, ''))) " & _
  356.                                       " + '$' + LTRIM(RTRIM(CONVERT(char(40), CONVERT(decimal(18, 6), " & _
  357.                                       " Gy_InOutSub.FactReceiptQuan)))) = '" & Trim("" & Rst_Invoice.Fields("CgBalanceCode")) & "')  " & FilterRKD
  358.             Set Rst_InOut = Cw_DataEnvi.DataConnect.Execute(str_SqlInOut)
  359.                 If Rst_InOut.RecordCount <> 0 Then
  360.                      If int_InvoiceMainID <> Rst_Invoice.Fields("InvoiceMainID").Value Then
  361.                         Bln_HaveErr = False
  362.                         Call Creat_BalanceBill    ''生成结算单
  363.                         If Bln_HaveErr = True Then GoTo Errexec
  364.                         Me.Label2.Caption = "正在进行数据处理..."
  365.                         ReDim Collect_BalanceRelation(0) As New Collection
  366.                         int_InvoiceMainID = Rst_Invoice.Fields("InvoiceMainID").Value
  367.                         int_temp = 1
  368.                         ReDim Preserve Collect_BalanceRelation(int_temp) As New Collection
  369.                         Collect_BalanceRelation(int_temp).Add str(int_InvoiceMainID)
  370.                         Collect_BalanceRelation(int_temp).Add str(Rst_InOut.Fields("InOutMainId"))
  371.                         Collect_BalanceRelation(int_temp).Add str(Rst_InOut.Fields("InOutSubId"))
  372.                      Else
  373.                         int_temp = int_temp + 1
  374.                         ReDim Preserve Collect_BalanceRelation(int_temp) As New Collection
  375.                         Collect_BalanceRelation(int_temp).Add str(int_InvoiceMainID)
  376.                         Collect_BalanceRelation(int_temp).Add str(Rst_InOut.Fields("InOutMainId"))
  377.                         Collect_BalanceRelation(int_temp).Add str(Rst_InOut.Fields("InOutSubId"))
  378.                      End If
  379.                 End If
  380.             int_InvoiceMainID = Rst_Invoice.Fields("InvoiceMainID").Value
  381.             Rst_Invoice.MoveNext
  382.         Loop
  383.             Bln_HaveErr = False
  384.             Call Creat_BalanceBill    ''生成结算单
  385.             If Bln_HaveErr = True Then GoTo Errexec
  386.             ReDim Collect_BalanceRelation(0) As New Collection
  387.             int_temp = 1
  388.              Me.ProgressBar.Value = Me.ProgressBar.Value + 1
  389.     End With
  390.     Cw_DataEnvi.DataConnect.CommitTrans
  391.     Me.Label2.Caption = "数据处理完成!"
  392.     Tsxx = "自动结算完成!"
  393.     Call Xtxxts(Tsxx, 0, 4)
  394. Errexec:
  395.     Me.Frame2.Visible = False
  396.     Me.Height = int_FrmHeight
  397.     Me.Frame1.Visible = True
  398.     Me.Refresh
  399.     Exit Sub
  400. Swcwcl:
  401.     Cw_DataEnvi.DataConnect.RollbackTrans
  402. End Sub
  403. Private Sub Creat_BalanceBill()
  404.     Dim int_temp As Long
  405.     Dim str_sqlTemp As String
  406.     Dim rst_temp As New ADODB.Recordset
  407.     Dim Bln_BalanceOK As Boolean
  408.     Dim str_WhCode As String
  409.     Dim banl_MainRecordset As New ADODB.Recordset
  410.     Dim banl_SubRecordset As New ADODB.Recordset
  411.     Dim rst_BalanceRelation  As New ADODB.Recordset
  412.     Dim Rkd_MainRecordset As New ADODB.Recordset
  413.     Dim Rkd_subRecordset As New ADODB.Recordset
  414. On Error GoTo Swcwcl
  415.     Dim banl_Mainid As Integer
  416.     Dim RKd_MainId As Integer
  417.     Bln_BalanceOK = False
  418.     If UBound(Collect_BalanceRelation) <> 0 Then
  419.         str_sqlTemp = "SELECT B.InvoiceMainID, A.SupplierCode, B.MNumber,  " & _
  420.                               " B.Quantity * (C.PurInvCon1 / C.PurInvCon2) AS Quantity, A.DeptCode, A.PersonCode,  " & _
  421.                               " B.IsCharge, B.InvoiceSubID,  " & _
  422.                               " B.MoneyBb / (B.Quantity * (C.PurInvCon1 / C.PurInvCon2)) AS PriceBb ,B.TotalMoneyBb,B.TaxMoneyBb  " & _
  423.                         " FROM Cg_InvoiceMain A INNER JOIN  " & _
  424.                               " Cg_InvoiceSub B ON A.InvoiceMainID = B.InvoiceMainID INNER JOIN  " & _
  425.                               " Gy_Material C ON B.MNumber = C.MNumber" & _
  426.                               " WHERE (A.InvoiceMainID =" & Val(Collect_BalanceRelation(1).Item(1)) & ")"
  427.         Set rst_temp = Cw_DataEnvi.DataConnect.Execute(str_sqlTemp)
  428.         If rst_temp.RecordCount = UBound(Collect_BalanceRelation) Then
  429.              rst_temp.MoveFirst
  430.                  With banl_MainRecordset
  431.                      If .State = 1 Then .Close
  432.                      .Open "select * from Kf_BalanceMain where 2=1 ", Cw_DataEnvi.DataConnect, adOpenForwardOnly, adLockOptimistic
  433.                      .AddNew
  434.                      .Fields("BalanceMainId") = CreatBillID("1210")
  435.                      .Fields("BillNum") = CreatBillCode("1210", True)
  436.                      .Fields("BillCode") = "1210"
  437.                      If Trim("" & rst_temp.Fields("SupplierCode")) <> "" Then
  438.                      .Fields("SupplierCode") = Trim("" & rst_temp.Fields("SupplierCode"))
  439.                      End If
  440.                      .Fields("opertype") = "库房结算"
  441.                      If Trim("" & rst_temp.Fields("DeptCode")) <> "" Then
  442.                          .Fields("DeptCode") = Trim("" & rst_temp.Fields("DeptCode"))
  443.                      End If
  444.                      If Trim("" & rst_temp.Fields("PersonCode")) <> "" Then
  445.                         .Fields("PersonCode") = Trim("" & rst_temp.Fields("PersonCode"))
  446.                      End If
  447.                      .Fields("Maker") = Xtczy
  448.                      .Fields("BillDate") = CDate(Xtrq)
  449.                      .Fields("KjYear") = Xtyear
  450.                      .Fields("Period") = Xtmm
  451.                      .Fields("BanlType") = "1"
  452.                      .Update
  453.                      banl_Mainid = .Fields("BalanceMainId")
  454.                  End With
  455.             For int_temp = 1 To rst_temp.RecordCount
  456.                  With banl_SubRecordset
  457.                      If .State = 1 Then .Close
  458.                      .Open "select * from Kf_BalanceSub where 2=1 ", Cw_DataEnvi.DataConnect, adOpenForwardOnly, adLockOptimistic
  459.                      .AddNew
  460.                      .Fields("BalanceMainId") = banl_Mainid
  461.                      .Fields("BalanceSubId") = rst_temp.Fields("InvoiceSubID")
  462.                      .Fields("MNumber") = rst_temp.Fields("MNumber")
  463.                      .Fields("Quan") = rst_temp.Fields("Quantity")
  464.                      .Fields("Price") = rst_temp.Fields("PriceBb")
  465.                      .Fields("EMoney") = rst_temp.Fields("TotalMoneyBb")
  466.                      .Fields("TaxMoney") = rst_temp.Fields("TaxMoneyBb")
  467.                      .Fields("TotalMoney") = rst_temp.Fields("TaxMoneyBb") + rst_temp.Fields("TotalMoneyBb")
  468.                      .Update
  469.                  End With
  470.                  rst_temp.MoveNext
  471.             Next int_temp
  472.             For int_temp = 1 To UBound(Collect_BalanceRelation)
  473.                 With rst_BalanceRelation
  474.                     If .State = 1 Then .Close
  475.                     .Open "select * from Kf_BalanceRelation where 2=1 ", Cw_DataEnvi.DataConnect, adOpenForwardOnly, adLockOptimistic
  476.                     .AddNew
  477.                     .Fields("BalanceMainId") = banl_Mainid
  478.                     .Fields("InvoiceMainID") = Val(Collect_BalanceRelation(int_temp).Item(1))
  479.                     .Fields("InOutMainId") = Val(Collect_BalanceRelation(int_temp).Item(2))
  480.                     .Fields("InOutSubId") = Val(Collect_BalanceRelation(int_temp).Item(3))
  481.                     .Update
  482.                 End With
  483.             Next int_temp
  484.             Cw_DataEnvi.DataConnect.Execute (" Kf_Sp_BalanceRelation  " & banl_Mainid)
  485.             Bln_BalanceOK = True
  486.         End If
  487.     End If
  488.         If Bln_BalanceOK = False Then Exit Sub
  489.         
  490.         If Bln_ClrkdKfsc = True Then
  491.             Dim str_InsertSql As String
  492.                 Set rst_BalanceRelation = Cw_DataEnvi.DataConnect.Execute("SELECT InOutMainId From Kf_BalanceRelation Where (BalanceMainId = " & banl_Mainid & " ) GROUP BY InOutMainId")
  493.                 If rst_BalanceRelation.RecordCount <> 0 Then
  494.                     Do While Not rst_BalanceRelation.EOF
  495.                         Set rst_temp = Cw_DataEnvi.DataConnect.Execute("SELECT WhCode  FROM Gy_InOutMain where InOutMainId= " & rst_BalanceRelation.Fields("InOutMainId"))
  496.                         If rst_temp.RecordCount <> 0 Then
  497.                             rst_temp.MoveFirst
  498.                             str_WhCode = Trim("" & rst_temp.Fields(0))
  499.                         Else
  500.                             Tsxx = "结算过程中某单据发生变化,结算失败!"
  501.                             Call Xtxxts(Tsxx, 0, 1)
  502.                             GoTo Swcwcl
  503.                         End If
  504.                          RKd_MainId = CreatBillID("1212")
  505.                          str_InsertSql = " INSERT INTO Gy_InOutMain " & _
  506.                               " (InOutMainId, BillCode, BillNum, WhCode, InoutFlag, PurTypeCode, OperType,  " & _
  507.                               " OperbillNum, BillDate, InoutClassCode, TranCompanyCode, TransferWayCode, " & _
  508.                               " BusNum, DeptCode, PersonCode, CusCode, SupplierCode,   " & _
  509.                               " ConsignbillNum, Consignbillid, KfChecker , Maker, KjYear, Period,BanlanceId) " & _
  510.                         " SELECT " & RKd_MainId & " ,'1212', '" & CreatBillCode("1212", True, Xtyear, Xtmm, str_WhCode) & "', WhCode, InoutFlag, PurTypeCode, OperType, " & _
  511.                               " OperbillNum, convert(datetime,'" & Xtrq & "'), InoutClassCode, TranCompanyCode, TransferWayCode, " & _
  512.                               " BusNum, DeptCode, PersonCode, CusCode, SupplierCode,  " & _
  513.                               " ConsignbillNum , Consignbillid, '" & Xtczy & "','" & Xtczy & "', " & Xtyear & ", " & Xtmm & "," & banl_Mainid & _
  514.                         " From Gy_InOutMain " & _
  515.                         " Where (InOutMainId =" & rst_BalanceRelation.Fields("InOutMainId") & ")"
  516.                         Cw_DataEnvi.DataConnect.Execute (str_InsertSql)
  517.                         str_InsertSql = "INSERT INTO Gy_InOutSub " & _
  518.                                               " (InOutSubId, InOutMainId, MNumber, FactReceiptQuan, Price, EMoney, EvaluationMoney,  " & _
  519.                                               " PlanPrice, PlanMoney) " & _
  520.                                         " SELECT InOutSubId, " & RKd_MainId & ", MNumber, FactReceiptQuan, Price, EMoney, EvaluationMoney, " & _
  521.                                               " PlanPrice, PlanMoney" & _
  522.                                         " From Gy_InOutSub " & _
  523.                                         " WHERE (InOutMainId = " & rst_BalanceRelation.Fields("InOutMainId") & ") AND (InOutSubId IN " & _
  524.                                                   " (SELECT InOutSubId " & _
  525.                                                  " From Kf_BalanceRelation " & _
  526.                                                  " WHERE BalanceMainId = " & banl_Mainid & " AND InOutMainId = " & rst_BalanceRelation.Fields("InOutMainId") & "))"
  527.                        Cw_DataEnvi.DataConnect.Execute (str_InsertSql)
  528.                     rst_BalanceRelation.MoveNext
  529.                     Loop
  530.                 Else
  531.                     Tsxx = "结算过程中某单据发生变化,结算失败!"
  532.                     Call Xtxxts(Tsxx, 0, 1)
  533.                     GoTo Swcwcl
  534.                 End If
  535.         End If
  536. Exit Sub
  537. Swcwcl:
  538.     Cw_DataEnvi.DataConnect.RollbackTrans
  539.     Bln_HaveErr = True
  540. End Sub
  541. Private Function Check_InoutMain() As Boolean  '是否有可以结算的入库单
  542.     Dim int_temp As Long
  543.     Dim rst_temp As New ADODB.Recordset
  544.     Dim str_sqlTemp As String
  545.     str_sqlTemp = "SELECT Gy_InOutMain.InOutMainId " & _
  546.                     " FROM Gy_InOutMain INNER JOIN " & _
  547.                           " Gy_InOutSub ON Gy_InOutMain.InOutMainId = Gy_InOutSub.InOutMainId INNER JOIN" & _
  548.                             " Gy_Material ON Gy_InOutSub.MNumber = Gy_Material.MNumber" & _
  549.                     " WHERE (Gy_InOutSub.BalanceDate IS NULL and (ltrim(rtrim(isnull(Gy_InOutMain.kfChecker,''))) <>'')  AND (ltrim(rtrim(Gy_InOutMain.BillCode))='1211' or ltrim(rtrim(Gy_InOutMain.BillCode))='1201'))  " & FilterInOut
  550.     Set rst_temp = Cw_DataEnvi.DataConnect.Execute(str_sqlTemp)
  551.     If rst_temp.RecordCount <> 0 Then
  552.         Check_InoutMain = True
  553.     Else
  554.         Tsxx = "没有可以结算的入库单数据!"
  555.         Call Xtxxts(Tsxx, 0, 4)
  556.         Check_InoutMain = False
  557.     End If
  558.     rst_temp.Close
  559.     Set rst_temp = Nothing
  560. End Function
  561. Private Sub FilterCondition()
  562. Dim Jsqte As Integer
  563.     FilterInvoice = " where 1=1 "
  564.     FilterRKD = " "
  565.     FilterInOut = " "
  566.     For Jsqte = 1 To 5
  567.     Select Case Jsqte
  568.         Case 1  '查询日期范围(起始)
  569.             If Trim(LrText(0).Text) <> "" Then
  570.                 FilterInvoice = FilterInvoice & " And InvoiceDate>=convert(datetime,'" & Trim(LrText(0).Text) & "')"
  571.                 FilterRKD = FilterRKD & " And BillDate>=convert(datetime,'" & Trim(LrText(0).Text) & "')"
  572.                 FilterInOut = FilterInOut & " And BillDate>=convert(datetime,'" & Trim(LrText(0).Text) & "')"
  573.             End If
  574.         Case 2  '查询日期范围(终止)
  575.             If Trim(LrText(1).Text) <> "" Then
  576.                 FilterInvoice = FilterInvoice & " And InvoiceDate<= convert(datetime,'" & Trim(LrText(1).Text) & "')"
  577.                 FilterRKD = FilterRKD & " And BillDate<= convert(datetime,'" & Trim(LrText(1).Text) & "')"
  578.                 FilterInOut = FilterInOut & " And BillDate<= convert(datetime,'" & Trim(LrText(1).Text) & "')"
  579.             End If
  580.         Case 3  '供应商(Like)
  581.             If Trim(LrText(2).Text) <> "" Then
  582.                 FilterInvoice = FilterInvoice & " And SupplierCode ='" & Trim(LrText(2).Tag) & "'"
  583.                 FilterInOut = FilterInOut & " And SupplierCode ='" & Trim(LrText(2).Tag) & "'"
  584.             End If
  585.         Case 4  '物料分类
  586.             If Trim(LrText(3).Text) <> "" Then
  587.                 FilterInvoice = FilterInvoice & " and InvSortcode like '" & Trim(LrText(3).Tag) & "%'"
  588.                 FilterInOut = FilterInOut & " and InvSortcode like '" & Trim(LrText(3).Tag) & "%'"
  589.             End If
  590.         Case 5  '物料
  591.             If Trim(LrText(4).Text) <> "" Then
  592.                 FilterInvoice = FilterInvoice & " and Gy_InOutSub.MNumber= '" & Trim(LrText(4).Text) & "'"
  593.                 FilterInOut = FilterInOut & " and Gy_InOutSub.MNumber= '" & Trim(LrText(4).Text) & "'"
  594.             End If
  595.     End Select
  596.     Next
  597.     
  598.      FilterRKD = FilterRKD & " And Gy_InOutMain.WhCode in (select whcode from KF_V_WhLimit where ltrim(rtrim(Czybm))='" & Xtczybm & "')"
  599.      FilterInOut = FilterInOut & " And Gy_InOutMain.WhCode in (select whcode from KF_V_WhLimit where ltrim(rtrim(Czybm))='" & Xtczybm & "')"
  600.   
  601. End Sub
  602. Private Sub QxCommand_Click()                                    '取消(Fixed)
  603.    Unload Me
  604. End Sub
  605. Private Function Lrtjyxxpd() As Boolean                          '用户录入条件有效性判断
  606.     Dim Jsqte As Integer
  607.     Lrtjyxxpd = False
  608.  
  609.     '对需要进行事后判断的文本框录入内容进行有效性判断 (Fixed)
  610.     For Jsqte = 0 To Max_Text_Index
  611.         If Textint(Jsqte, 9) = 0 Or Textint(Jsqte, 9) = 2 Then
  612.             If Not TextYxxpd(Jsqte) Then
  613.                 Exit Function
  614.             End If
  615.         End If
  616.     Next Jsqte
  617.    
  618.     '[>>以下为依据实际情况自定义部分
  619.  
  620.     '查询日期范围应由小到大
  621.     If LrText(0).Text > LrText(1).Text And Trim(LrText(1).Text) <> "" Then
  622.         Tsxx = "查询日期范围应由小到大!"
  623.         Call Xtxxts(Tsxx, 0, 4)
  624.         LrText(0).SetFocus
  625.         Exit Function
  626.     End If
  627.     
  628.    
  629.     '<<]以上为依据实际情况自定义部分
  630.  
  631.     Lrtjyxxpd = True
  632. End Function
  633. Private Sub Cmd_Clear_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)    '将用户输入条件全部清除(可选)
  634.     '清除文本框(Fixed)
  635.     For Jsqte = 0 To Max_Text_Index
  636.         LrText(Jsqte).Tag = ""
  637.         LrText(Jsqte).Text = ""
  638.     Next Jsqte
  639.   
  640.     '[>>
  641.     '此处可以写入其他清除条件程序
  642.     '<<]
  643.   
  644. End Sub
  645. '*************以下为文本框录入处理程序(固定不变部分)*************'
  646. Private Sub Wbklrwbcl(Index As Integer)    '文本框录入事后处理程序
  647.   
  648.     '以下为依据实际情况自定义部分[
  649.     '在此填写文本框录入事后处理程序
  650.     ']以上为依据实际情况自定义部分
  651.   
  652. End Sub
  653. Private Sub LrText_Change(Index As Integer)
  654.    
  655.     '屏蔽程序改变控制
  656.     If TextChangeLock Then
  657.         Exit Sub
  658.     End If
  659.     
  660.     TextValiJudgeLock(Index) = False    '打开有效性判断锁
  661.     
  662.     '限制字段录入长度
  663.           
  664.     TextChangeLock = True  '加锁(防止执行Lrtext_Change)
  665.         
  666.     Select Case Textint(Index, 1)
  667.         Case 8, 11      '金额型
  668.             Call Sjgskz(LrText(Index), Xtjezws - Xtjexsws - 1, Xtjexsws)
  669.         Case 9, 12      '数量型
  670.             Call Sjgskz(LrText(Index), Xtslzws - Xtslxsws - 1, Xtslxsws)
  671.         Case 10          '单价型
  672.             Call Sjgskz(LrText(Index), Xtdjzws - Xtdjxsws - 1, Xtdjxsws)
  673.         Case Else        '其他小数类型控制
  674.             If Textint(Index, 6) <> 0 Or Textint(Index, 7) <> 0 Then
  675.                 Call Sjgskz(LrText(Index), Textint(Index, 6), Textint(Index, 7))
  676.             End If
  677.     End Select
  678.         
  679.     TextChangeLock = False '解锁
  680.     '如果仓库改变,清空对应的货区
  681. End Sub
  682. Private Sub LrText_GotFocus(Index As Integer)                                                 '文本框得到焦点,显示相应信息
  683.     Call TextShow(Index)
  684.     CurTextIndex = Index
  685.     LrText(Index).SelStart = Len(LrText(Index))
  686. End Sub
  687. Private Sub LrText_KeyDown(Index As Integer, KeyCode As Integer, Shift As Integer)            '字段按F2键提供帮助
  688.     
  689.     Select Case KeyCode
  690.         Case vbKeyF2
  691.             Call Text_Help(Index)
  692.     End Select
  693. End Sub
  694. Private Sub LrText_KeyPress(Index As Integer, KeyAscii As Integer)                            '文本框录入事中控制
  695.     Call InputFieldLimit(LrText(Index), Textint(Index, 1), KeyAscii)
  696. End Sub
  697. Private Sub LrText_LostFocus(Index As Integer)                                                '文本框失去焦点
  698.     '显示相应信息但不能进行有效性判断
  699.   
  700. End Sub
  701. Private Sub Ydcommand1_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)     '按钮提供帮助
  702.     Call Text_Help(Index)
  703. End Sub
  704. Private Sub Text_Help(Index As Integer)                                                       '录入字段帮助
  705.     If Not Textboolean(Index, 1) Then
  706.         Exit Sub
  707.     End If
  708.     If Textint(Index, 2) <> 1 Then
  709.         If Index = 0 Then
  710.             strHlpR = FunHlpR(Trim(Textstr(Index, 4)), "billcode", S1)
  711.         Else
  712.             strHlpR = FunHlpR(Trim(Textstr(Index, 4)), "czybm", Xtczybm)
  713.         End If
  714.     End If
  715.     Call Drbmhelp(Textint(Index, 2), Textstr(Index, 4), Trim(LrText(Index).Text))
  716.   
  717.     '根据设置选择显示编码和名称,并进行存储
  718.     If Len(Xtfhcs) <> 0 Then
  719.         If Textint(Index, 3) = 1 Then
  720.             LrText(Index).Text = Xtfhcsfz
  721.             LrText(Index).Tag = Xtfhcs
  722.         Else
  723.             LrText(Index).Text = Xtfhcs
  724.             LrText(Index).Tag = Xtfhcsfz
  725.         End If
  726.     End If
  727.    
  728.     LrText(Index).SetFocus
  729. End Sub
  730. Private Sub TextShow(Index As Integer)        '文本框得到焦点,显示相应信息
  731.     '填写文本框得到焦点,进行相应信息处理程序
  732.    
  733. End Sub
  734. Private Sub Wbkcsh()                          '录入文本框初始化
  735.     
  736.     Dim Jsqte As Integer
  737.   
  738.     '最大录入文本框索引值
  739.     Max_Text_Index = Textvar(1)
  740.   
  741.     ReDim TextValiJudgeLock(Max_Text_Index)
  742.     For Jsqte = 0 To Max_Text_Index
  743.         If Len(Trim(Textstr(Jsqte, 1))) <> 0 Then
  744.             If Textboolean(Jsqte, 1) Then
  745.                 If Jsqte <> 0 And Not Textboolean(Jsqte, 3) Then
  746.                     Load Ydcommand1(Jsqte)
  747.                 End If
  748.                 Ydcommand1(Jsqte).Visible = True
  749.                 Ydcommand1(Jsqte).Move LrText(Jsqte).Left + LrText(Jsqte).Width, LrText(Jsqte).Top
  750.             End If
  751.             TextChangeLock = True
  752.             LrText(Jsqte).Text = ""
  753.             LrText(Jsqte).Tag = ""
  754.             If Textint(Jsqte, 5) <> 0 Then
  755.                 LrText(Jsqte).MaxLength = Textint(Jsqte, 5)
  756.             End If
  757.             TextChangeLock = False
  758.         End If
  759.         TextValiJudgeLock(Jsqte) = True
  760.     Next Jsqte
  761. End Sub
  762. Private Function TextYxxpd(Index As Integer) As Boolean           '文本框有效性判断
  763.     
  764.     Dim Sqlstr As String
  765.     Dim Findrec As ADODB.Recordset
  766.   
  767.     '文本框内容未曾改变不进行有效性判断
  768.     If TextValiJudgeLock(Index) Then
  769.         TextYxxpd = True
  770.         Exit Function
  771.     End If
  772.   
  773.     '文本框内容为空认为有效,并清空其Tag值
  774.     If Trim(LrText(Index)) = "" Then
  775.         LrText(Index).Tag = ""
  776.         Call Wbklrwbcl(Index)
  777.         TextValiJudgeLock(Index) = True
  778.         TextYxxpd = True
  779.         Exit Function
  780.     End If
  781.   
  782.     '可在此加入不做有效性判断的理由
  783.   
  784.     Select Case Textint(Index, 4)
  785.         Case 1      '编码型
  786.             Sqlstr = Trim(Textstr(Index, 5))
  787.             Sqlstr = Replace(Sqlstr, "@", "'" + Trim(LrText(Index).Text) + "'")
  788.             Set Findrec = Cw_DataEnvi.DataConnect.Execute(Sqlstr)
  789.             If Findrec.EOF Then
  790.                 Call Xtxxts(Trim(Textstr(Index, 6)), 0, 1)
  791.                 LrText(Index).SetFocus
  792.                 Exit Function
  793.             Else
  794.                 Select Case Textint(Index, 3)
  795.                     Case 0
  796.                         If Len(Trim(Textstr(Index, 2))) <> 0 Then
  797.                             LrText(Index).Text = Trim(Findrec.Fields(Trim(Textstr(Index, 2))))
  798.                         End If
  799.                         If Len(Trim(Textstr(Index, 3) & "")) <> 0 Then
  800.                             LrText(Index).Tag = Trim(Findrec.Fields(Trim(Textstr(Index, 3))))
  801.                         End If
  802.                     Case 1
  803.                         If Len(Trim(Textstr(Index, 3) & "")) <> 0 Then
  804.                             LrText(Index).Text = Trim(Findrec.Fields(Trim(Textstr(Index, 3))))
  805.                         End If
  806.                         If Len(Trim(Textstr(Index, 2))) <> 0 Then
  807.                             LrText(Index).Tag = Trim(Findrec.Fields(Trim(Textstr(Index, 2))))
  808.                         End If
  809.                 End Select
  810.             End If
  811.         Case 2      '日期型
  812.             If IsDate(LrText(Index).Text) Then
  813.                 LrText(Index).Text = Format(LrText(Index).Text, "yyyy-mm-dd")
  814.                 If Val(Mid(LrText(Index), 1, 4)) < 1900 Then
  815.                     LrText(Index).Text = "1900" + Mid(LrText(Index), 5, 6)
  816.                 End If
  817.             Else
  818.                 Tsxx = "非法公历日期!(格式:" + Format(Date, "yyyy-mm-dd") + ")"
  819.                 Call Xtxxts(Tsxx, 0, 1)
  820.                 LrText(Index).SetFocus
  821.                 Exit Function
  822.             End If
  823.         Case 3      '其他类型
  824.     End Select
  825.     
  826.     '如果有效则加锁,用户不改变内容则不再进行有效性判断
  827.     TextValiJudgeLock(Index) = True
  828.     '调用文本框事后处理程序
  829.     Call Wbklrwbcl(Index)
  830.    
  831.     '有效性判断通过则返回True
  832.     TextYxxpd = True
  833.    
  834. End Function