www.pudn.com > Pepsi_five.rar > FrmRptMat.frm


VERSION 5.00 
Object = "{F0D2F211-CCB0-11D0-A316-00AA00688B10}#1.0#0"; "MSDATLST.OCX" 
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX" 
Begin VB.Form FrmRptMat  
   Caption         =   "仓库库存表设置" 
   ClientHeight    =   3300 
   ClientLeft      =   60 
   ClientTop       =   345 
   ClientWidth     =   5700 
   Icon            =   "FrmRptMat.frx":0000 
   LinkTopic       =   "Form1" 
   MDIChild        =   -1  'True 
   ScaleHeight     =   3300 
   ScaleWidth      =   5700 
   Begin MSComDlg.CommonDialog ComDlgRpt  
      Left            =   2640 
      Top             =   1440 
      _ExtentX        =   847 
      _ExtentY        =   847 
      _Version        =   393216 
   End 
   Begin VB.CommandButton CmdRpt  
      Caption         =   "退出(&X)" 
      Height          =   375 
      Index           =   3 
      Left            =   4320 
      TabIndex        =   16 
      Top             =   2520 
      Width           =   1155 
   End 
   Begin VB.CommandButton CmdRpt  
      Caption         =   "生成报表(&T)" 
      Enabled         =   0   'False 
      Height          =   375 
      Index           =   2 
      Left            =   2820 
      TabIndex        =   15 
      Top             =   2520 
      Width           =   1155 
   End 
   Begin VB.CommandButton CmdRpt  
      Caption         =   "导出报表(&E)" 
      Enabled         =   0   'False 
      Height          =   375 
      Index           =   1 
      Left            =   4320 
      TabIndex        =   14 
      Top             =   1920 
      Width           =   1155 
   End 
   Begin VB.CommandButton CmdRpt  
      Caption         =   "打印设置(&P)" 
      Height          =   375 
      Index           =   0 
      Left            =   2820 
      TabIndex        =   13 
      Top             =   1920 
      Width           =   1155 
   End 
   Begin VB.Frame Frame1  
      Caption         =   "报表日期" 
      Height          =   675 
      Index           =   2 
      Left            =   2520 
      TabIndex        =   6 
      Top             =   720 
      Width           =   3135 
      Begin VB.TextBox TxtDay  
         Height          =   300 
         Left            =   2040 
         MaxLength       =   2 
         TabIndex        =   12 
         Top             =   240 
         Width           =   315 
      End 
      Begin VB.TextBox TxtMonth  
         Height          =   300 
         Left            =   1380 
         MaxLength       =   2 
         TabIndex        =   11 
         Top             =   240 
         Width           =   315 
      End 
      Begin VB.TextBox TxtYear  
         Height          =   300 
         Left            =   540 
         MaxLength       =   4 
         TabIndex        =   10 
         Top             =   240 
         Width           =   495 
      End 
      Begin VB.Label Label1  
         Caption         =   "日" 
         Height          =   195 
         Index           =   2 
         Left            =   2400 
         TabIndex        =   9 
         Top             =   300 
         Width           =   195 
      End 
      Begin VB.Label Label1  
         Caption         =   "月" 
         Height          =   195 
         Index           =   1 
         Left            =   1800 
         TabIndex        =   8 
         Top             =   300 
         Width           =   195 
      End 
      Begin VB.Label Label1  
         Caption         =   "年" 
         Height          =   195 
         Index           =   0 
         Left            =   1140 
         TabIndex        =   7 
         Top             =   300 
         Width           =   195 
      End 
   End 
   Begin VB.Frame Frame1  
      Caption         =   "报表类别" 
      Height          =   675 
      Index           =   1 
      Left            =   2520 
      TabIndex        =   2 
      Top             =   0 
      Width           =   3135 
      Begin VB.OptionButton OptRptType  
         Caption         =   "年报" 
         Height          =   195 
         Index           =   2 
         Left            =   2220 
         TabIndex        =   5 
         Top             =   300 
         Width           =   855 
      End 
      Begin VB.OptionButton OptRptType  
         Caption         =   "月报" 
         Height          =   195 
         Index           =   1 
         Left            =   1260 
         TabIndex        =   4 
         Top             =   300 
         Width           =   855 
      End 
      Begin VB.OptionButton OptRptType  
         Caption         =   "日报" 
         Height          =   195 
         Index           =   0 
         Left            =   300 
         TabIndex        =   3 
         Top             =   300 
         Value           =   -1  'True 
         Width           =   855 
      End 
   End 
   Begin VB.Frame Frame1  
      Caption         =   "物品类别" 
      Height          =   3255 
      Index           =   0 
      Left            =   0 
      TabIndex        =   0 
      Top             =   0 
      Width           =   2475 
      Begin MSDataListLib.DataList DLtProType  
         Bindings        =   "FrmRptMat.frx":0442 
         Height          =   3000 
         Left            =   60 
         TabIndex        =   1 
         Top             =   180 
         Width           =   2355 
         _ExtentX        =   4154 
         _ExtentY        =   5292 
         _Version        =   393216 
         ListField       =   "type_name" 
         BoundColumn     =   "type_id" 
         Object.DataMember      =   "ComProType" 
      End 
   End 
End 
Attribute VB_Name = "FrmRptMat" 
Attribute VB_GlobalNameSpace = False 
Attribute VB_Creatable = False 
Attribute VB_PredeclaredId = True 
Attribute VB_Exposed = False 
Option Explicit 
Private cmRpt As ADODB.Command 
Private rsRpt As ADODB.Recordset 
Private rsExpMat As ADODB.Recordset 
Private rsPriMat As ADODB.Recordset 
Public strRptCap As String 
Public strRptDte As String 
Public strRptTyp As String 
 
Private Sub CmdRpt_Click(Index As Integer) 
    Dim strSQL As String 
    Select Case Index 
        Case 0 
            ComDlgRpt.ShowPrinter 
        Case 1 
            If TxtDay.Enabled = False Then TxtDay.Text = "" 
            If TxtMonth.Enabled = False Then TxtMonth.Text = "" 
            If DateIsTrue(TxtYear.Text, TxtMonth.Text, TxtDay.Text) Then 
                Call Mat_Rpt 
                If Dir(App.Path & "\xls\matrpt.xls") <> "" Then 
                    Kill App.Path & "\xls\matrpt.xls" 
                End If 
                strSQL = "select p_id as 物品编号,product_name as 物品名称," & _ 
                "product_model as 物品型号,unit as 单位,unit_price as 单价," & _ 
                "matbegqty as 期初数量,matbegprice as 期初金额,orderqty " & _ 
                "as 入库数量,orderprice as 入库金额,saleqty as 出库数量," & _ 
                "saleprice as 出库金额,matendqty as 期末数量,matendprice as " & _ 
                "期末金额 into [Excel 8.0;database=" & App.Path & _ 
                "\xls\matrpt.xls].mat from rpt_mat" 
                rsExpMat.Open strSQL, DEjxc.Conjxc, adOpenStatic, adLockOptimistic 
                'rsExpMat.Close 
                MsgBox "文件输出到" & App.Path & "\xls\matrpt.xls", vbInformation, "输出完毕" 
            Else 
                MsgBox "日期错误或大于系统启用日期!", vbCritical, "报表输出错误" 
            End If 
        Case 2 
            If TxtDay.Enabled = False Then TxtDay.Text = "" 
            If TxtMonth.Enabled = False Then TxtMonth.Text = "" 
            If DateIsTrue(TxtYear.Text, TxtMonth.Text, TxtDay.Text) Then 
                Call Mat_Rpt 
                rsPriMat.Close 
                RptJxc.Show 
            Else 
                MsgBox "日期错误或大于系统启用日期!", vbCritical, "报表生成错误" 
            End If 
        Case 3 
            Unload Me 
    End Select 
End Sub 
 
Private Sub DLtProType_Click() 
    If Me.DLtProType.BoundText <> "" Then 
        CmdRpt(1).Enabled = True 
        CmdRpt(2).Enabled = True 
        strRptTyp = Me.DLtProType.Text 
    End If 
End Sub 
 
Private Sub Form_Load() 
    intNumWindows = OpenWindow(intNumWindows) 
    Me.Height = 3705 
    Me.Width = 5820 
    Call SetFormStu(Me, frmMain) 
    Set cmRpt = New ADODB.Command 
    cmRpt.ActiveConnection = DEjxc.Conjxc 
    cmRpt.CommandType = adCmdText 
    Set rsRpt = New ADODB.Recordset 
    Set rsExpMat = New ADODB.Recordset 
    Set rsPriMat = DEjxc.rsComRptMat 
    rsPriMat.Open 
    TxtYear.Text = Year(dteSysDate) 
    TxtMonth.Text = Month(dteSysDate) 
    TxtDay.Text = Day(dteSysDate) 
End Sub 
 
Private Sub Form_Unload(Cancel As Integer) 
    intNumWindows = Closewindow(intNumWindows) 
    rsPriMat.Close 
    Set cmRpt = Nothing 
    Set rsRpt = Nothing 
    Set rsExpMat = Nothing 
    Set rsPriMat = Nothing 
End Sub 
 
Private Sub OptRptType_Click(Index As Integer) 
    Select Case Index 
        Case 0 
            Me.TxtDay.Enabled = True 
            Me.TxtMonth.Enabled = True 
        Case 1 
            Me.TxtDay.Enabled = False 
            Me.TxtMonth.Enabled = True 
        Case 2 
            Me.TxtDay.Enabled = False 
            Me.TxtMonth.Enabled = False 
    End Select 
End Sub 
 
Private Sub OptRptType_KeyPress(Index As Integer, KeyAscii As Integer) 
    If KeyAscii = 13 Then 
        TxtYear.SelStart = 0 
        TxtYear.SelLength = Len(TxtYear.Text) 
        TxtYear.SetFocus 
    End If 
End Sub 
 
Private Sub TxtDay_KeyPress(KeyAscii As Integer) 
    Dim strValid As String 
    strValid = "0123456789" 
    If KeyAscii > 26 Then 
        If InStr(strValid, Chr(KeyAscii)) = 0 Then 
            KeyAscii = 0 
        End If 
    ElseIf KeyAscii = 13 Then 
            CmdRpt(0).SetFocus 
    End If 
End Sub 
 
Private Sub TxtMonth_KeyPress(KeyAscii As Integer) 
    Dim strValid As String 
    strValid = "0123456789" 
    If KeyAscii > 26 Then 
        If InStr(strValid, Chr(KeyAscii)) = 0 Then 
            KeyAscii = 0 
        End If 
    ElseIf KeyAscii = 13 Then 
        If TxtDay.Enabled = True Then 
            TxtDay.SelStart = 0 
            TxtDay.SelLength = Len(TxtYear.Text) 
            TxtDay.SetFocus 
        Else 
            CmdRpt(0).SetFocus 
        End If 
    End If 
End Sub 
 
Private Sub TxtYear_KeyPress(KeyAscii As Integer) 
    Dim strValid As String 
    strValid = "0123456789" 
    If KeyAscii > 26 Then 
        If InStr(strValid, Chr(KeyAscii)) = 0 Then 
            KeyAscii = 0 
        End If 
    ElseIf KeyAscii = 13 Then 
        If TxtMonth.Enabled = True Then 
            TxtMonth.SelStart = 0 
            TxtMonth.SelLength = Len(TxtYear.Text) 
            TxtMonth.SetFocus 
        Else 
            CmdRpt(0).SetFocus 
        End If 
    End If 
End Sub 
 
Private Function DateIsTrue(strYear As String, strMonth As String, strDay As String) As Boolean 
    Dim strdate As String 
    Dim strSQL As String 
    If OptRptType(0).Value = True Then 
        strdate = strYear & "-" & strMonth & "-" & strDay 
    ElseIf OptRptType(1).Value = True Then 
        strdate = strYear & "-" & strMonth 
    Else 
        strdate = strYear & "-12" 
    End If 
    If IsDate(strdate) Then 
        rsRpt.Open "select * from r_parameter", DEjxc.Conjxc, adOpenStatic, adLockReadOnly 
        With rsRpt 
            .MoveFirst 
            If strDay <> "" Then 
                If CDate(strdate) >= !pass_date Then 
                    DateIsTrue = True 
                Else 
                    DateIsTrue = False 
                End If 
            Else 
                If CDate(Format(strdate, "yyyy-mm")) >= Format(!pass_date, "yyyy-mm") Then 
                    DateIsTrue = True 
                Else 
                    DateIsTrue = False 
                End If 
            End If 
        End With 
        rsRpt.Close 
    Else 
        DateIsTrue = False 
    End If 
End Function 
 
Private Sub Mat_Rpt() 
    Dim strSQL As String 
    Dim dteDate As Date 
    Dim strY, strM, strD As String 
    strSQL = "delete from rpt_mat" 
    cmRpt.CommandText = strSQL 
    cmRpt.Execute 
    strSQL = "select p_id,product_name,product_model,unit," & _ 
    "unit_price,matbegqty as begqty,matbegprice " & _ 
    "as begprice,orderqty as oqty,orderprice as oprice,saleqty as sqty," & _ 
    "saleprice as sprice,matendqty,matendprice into temp_mat from rpt_mat" 
    cmRpt.CommandText = strSQL 
    cmRpt.Execute 
    If OptRptType(0).Value = True Then 
        dteDate = CDate(TxtYear.Text & "-" & TxtMonth.Text & "-" & TxtDay.Text) 
    ElseIf OptRptType(1).Value = True Then 
        dteDate = CDate(TxtYear.Text & "-" & TxtMonth.Text) 
    ElseIf OptRptType(2).Value = True Then 
        dteDate = CDate(TxtYear.Text & "-09") 
    End If 
    strY = CStr(Year(dteDate)) 
    strM = Format(CStr(Month(dteDate)), "0#") 
    If OptRptType(0).Value = True Then 
        strSQL = "insert into temp_mat select p_id,qty" & Right(strY, 2) & strM & _ 
        " as begqty,price" & Right(strY, 2) & strM & " as begprice from mat_head" _ 
        & " where p_id in (select p_id from product where type_id ='" & _ 
        Me.DLtProType.BoundText & "')" 
        cmRpt.CommandText = strSQL 
        cmRpt.Execute 
        strSQL = "insert into temp_mat select p_id,sum(qty) as oqty" & _ 
        ",sum(price) as oprice from order_detail_b where p_id in " & _ 
        "(select p_id from product where type_id ='" & _ 
        Me.DLtProType.BoundText & "') and (order_id in (select ps_id from " & _ 
        "ps_head_b where ps_date>=cdate('" & Left(CStr(dteDate), Len(CStr(dteDate)) - 2) & _ 
        "01" & "') and ps_date=cdate('" & _ 
        Left(CStr(dteDate), Len(CStr(dteDate)) - 2) & "01" & "') and " & _ 
        "other_date=cdate('" & Left(CStr(dteDate), Len(CStr(dteDate)) - 2) & _ 
        "01" & "') and sale_date0" 
    cmRpt.CommandText = strSQL 
    cmRpt.Execute 
    strSQL = "update rpt_mat set saleprice=unit_price*saleqty" 
    cmRpt.CommandText = strSQL 
    cmRpt.Execute 
    strSQL = "update rpt_mat set matendqty=matbegqty+orderqty-saleqty," & _ 
    "matendprice=matbegprice+orderprice-saleprice" 
    cmRpt.CommandText = strSQL 
    cmRpt.Execute 
    strSQL = "drop table temp_mat" 
    cmRpt.CommandText = strSQL 
    cmRpt.Execute 
End Sub