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

企业管理

开发平台:

Visual Basic

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