www.pudn.com > SalesManager.rar > frmConSum.vb


Imports System.Data.OleDb 
Imports System.IO 
 
Public Class frmConSum 
    Inherits System.Windows.Forms.Form 
 
#Region " Windows 窗体设计器生成的代码 " 
 
    Public Sub New() 
        MyBase.New() 
 
        '该调用是 Windows 窗体设计器所必需的。 
        InitializeComponent() 
 
        '在 InitializeComponent() 调用之后添加任何初始化 
 
    End Sub 
 
    '窗体重写 dispose 以清理组件列表。 
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) 
        If disposing Then 
            If Not (components Is Nothing) Then 
                components.Dispose() 
            End If 
        End If 
        MyBase.Dispose(disposing) 
    End Sub 
 
    'Windows 窗体设计器所必需的 
    Private components As System.ComponentModel.IContainer 
 
    '注意: 以下过程是 Windows 窗体设计器所必需的 
    '可以使用 Windows 窗体设计器修改此过程。 
    '不要使用代码编辑器修改它。 
    Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox 
    Friend WithEvents Label4 As System.Windows.Forms.Label 
    Friend WithEvents Label5 As System.Windows.Forms.Label 
    Friend WithEvents Label66 As System.Windows.Forms.Label 
    Friend WithEvents btnConSumMonth As System.Windows.Forms.Button 
    Friend WithEvents btnConSumYear As System.Windows.Forms.Button 
    Friend WithEvents labConSum As System.Windows.Forms.Label 
    Friend WithEvents cbConSumMonth As System.Windows.Forms.ComboBox 
    Friend WithEvents cbConSumYear As System.Windows.Forms.ComboBox 
    Friend WithEvents Label64 As System.Windows.Forms.Label 
    Friend WithEvents Label1 As System.Windows.Forms.Label 
    Friend WithEvents Label2 As System.Windows.Forms.Label 
    Friend WithEvents Label3 As System.Windows.Forms.Label 
    Friend WithEvents btnCancel As System.Windows.Forms.Button 
    Friend WithEvents Label6 As System.Windows.Forms.Label 
    Friend WithEvents cbConFact As System.Windows.Forms.ComboBox 
    Friend WithEvents btnCon As System.Windows.Forms.Button 
     Private Sub InitializeComponent() 
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(frmConSum)) 
        Me.PictureBox1 = New System.Windows.Forms.PictureBox 
        Me.Label4 = New System.Windows.Forms.Label 
        Me.Label5 = New System.Windows.Forms.Label 
        Me.Label66 = New System.Windows.Forms.Label 
        Me.btnConSumMonth = New System.Windows.Forms.Button 
        Me.btnConSumYear = New System.Windows.Forms.Button 
        Me.labConSum = New System.Windows.Forms.Label 
        Me.cbConSumMonth = New System.Windows.Forms.ComboBox 
        Me.cbConSumYear = New System.Windows.Forms.ComboBox 
        Me.Label64 = New System.Windows.Forms.Label 
        Me.Label1 = New System.Windows.Forms.Label 
        Me.Label2 = New System.Windows.Forms.Label 
        Me.Label3 = New System.Windows.Forms.Label 
        Me.cbConFact = New System.Windows.Forms.ComboBox 
        Me.btnCon = New System.Windows.Forms.Button 
        Me.btnCancel = New System.Windows.Forms.Button 
        Me.Label6 = New System.Windows.Forms.Label 
        Me.SuspendLayout() 
        ' 
        'PictureBox1 
        ' 
        Me.PictureBox1.Image = CType(resources.GetObject("PictureBox1.Image"), System.Drawing.Image) 
        Me.PictureBox1.Location = New System.Drawing.Point(12, 8) 
        Me.PictureBox1.Name = "PictureBox1" 
        Me.PictureBox1.Size = New System.Drawing.Size(124, 256) 
        Me.PictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage 
        Me.PictureBox1.TabIndex = 0 
        Me.PictureBox1.TabStop = False 
        ' 
        'Label4 
        ' 
        Me.Label4.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D 
        Me.Label4.ForeColor = System.Drawing.SystemColors.ControlText 
        Me.Label4.Location = New System.Drawing.Point(204, 140) 
        Me.Label4.Name = "Label4" 
        Me.Label4.Size = New System.Drawing.Size(275, 2) 
        Me.Label4.TabIndex = 155 
        ' 
        'Label5 
        ' 
        Me.Label5.Location = New System.Drawing.Point(148, 136) 
        Me.Label5.Name = "Label5" 
        Me.Label5.Size = New System.Drawing.Size(60, 16) 
        Me.Label5.TabIndex = 154 
        Me.Label5.Text = "统计结果" 
        ' 
        'Label66 
        ' 
        Me.Label66.Font = New System.Drawing.Font("宋体", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte)) 
        Me.Label66.ForeColor = System.Drawing.SystemColors.ControlText 
        Me.Label66.Location = New System.Drawing.Point(168, 40) 
        Me.Label66.Name = "Label66" 
        Me.Label66.Size = New System.Drawing.Size(92, 16) 
        Me.Label66.TabIndex = 55 
        Me.Label66.Text = "年销售额查询:" 
        ' 
        'btnConSumMonth 
        ' 
        Me.btnConSumMonth.BackColor = System.Drawing.Color.FromArgb(CType(239, Byte), CType(243, Byte), CType(255, Byte)) 
        Me.btnConSumMonth.FlatStyle = System.Windows.Forms.FlatStyle.Popup 
        Me.btnConSumMonth.Location = New System.Drawing.Point(404, 68) 
        Me.btnConSumMonth.Name = "btnConSumMonth" 
        Me.btnConSumMonth.Size = New System.Drawing.Size(56, 24) 
        Me.btnConSumMonth.TabIndex = 54 
        Me.btnConSumMonth.Text = "查询" 
        ' 
        'btnConSumYear 
        ' 
        Me.btnConSumYear.BackColor = System.Drawing.Color.FromArgb(CType(239, Byte), CType(243, Byte), CType(255, Byte)) 
        Me.btnConSumYear.FlatStyle = System.Windows.Forms.FlatStyle.Popup 
        Me.btnConSumYear.Location = New System.Drawing.Point(404, 32) 
        Me.btnConSumYear.Name = "btnConSumYear" 
        Me.btnConSumYear.Size = New System.Drawing.Size(56, 24) 
        Me.btnConSumYear.TabIndex = 53 
        Me.btnConSumYear.Text = "查询" 
        ' 
        'labConSum 
        ' 
        Me.labConSum.Font = New System.Drawing.Font("宋体", 9.0!, CType((System.Drawing.FontStyle.Bold Or System.Drawing.FontStyle.Underline), System.Drawing.FontStyle), System.Drawing.GraphicsUnit.Point, CType(134, Byte)) 
        Me.labConSum.ForeColor = System.Drawing.SystemColors.ControlText 
        Me.labConSum.Location = New System.Drawing.Point(168, 160) 
        Me.labConSum.Name = "labConSum" 
        Me.labConSum.Size = New System.Drawing.Size(308, 52) 
        Me.labConSum.TabIndex = 52 
        Me.labConSum.Text = "2004年2月销售额为: 203094" 
        Me.labConSum.TextAlign = System.Drawing.ContentAlignment.MiddleCenter 
        ' 
        'cbConSumMonth 
        ' 
        Me.cbConSumMonth.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList 
        Me.cbConSumMonth.Items.AddRange(New Object() {"一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"}) 
        Me.cbConSumMonth.Location = New System.Drawing.Point(264, 68) 
        Me.cbConSumMonth.Name = "cbConSumMonth" 
        Me.cbConSumMonth.Size = New System.Drawing.Size(96, 20) 
        Me.cbConSumMonth.TabIndex = 51 
        ' 
        'cbConSumYear 
        ' 
        Me.cbConSumYear.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList 
        Me.cbConSumYear.Items.AddRange(New Object() {"2004", "2005", "2006"}) 
        Me.cbConSumYear.Location = New System.Drawing.Point(264, 36) 
        Me.cbConSumYear.Name = "cbConSumYear" 
        Me.cbConSumYear.Size = New System.Drawing.Size(96, 20) 
        Me.cbConSumYear.TabIndex = 50 
        ' 
        'Label64 
        ' 
        Me.Label64.Font = New System.Drawing.Font("宋体", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte)) 
        Me.Label64.ForeColor = System.Drawing.SystemColors.ControlText 
        Me.Label64.Location = New System.Drawing.Point(168, 72) 
        Me.Label64.Name = "Label64" 
        Me.Label64.Size = New System.Drawing.Size(92, 16) 
        Me.Label64.TabIndex = 49 
        Me.Label64.Text = "月销售额查询:" 
        ' 
        'Label1 
        ' 
        Me.Label1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D 
        Me.Label1.ForeColor = System.Drawing.SystemColors.ControlText 
        Me.Label1.Location = New System.Drawing.Point(204, 16) 
        Me.Label1.Name = "Label1" 
        Me.Label1.Size = New System.Drawing.Size(275, 2) 
        Me.Label1.TabIndex = 157 
        ' 
        'Label2 
        ' 
        Me.Label2.Location = New System.Drawing.Point(148, 12) 
        Me.Label2.Name = "Label2" 
        Me.Label2.Size = New System.Drawing.Size(60, 16) 
        Me.Label2.TabIndex = 156 
        Me.Label2.Text = "统计项目" 
        ' 
        'Label3 
        ' 
        Me.Label3.Font = New System.Drawing.Font("宋体", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte)) 
        Me.Label3.ForeColor = System.Drawing.SystemColors.ControlText 
        Me.Label3.Location = New System.Drawing.Point(168, 104) 
        Me.Label3.Name = "Label3" 
        Me.Label3.Size = New System.Drawing.Size(92, 16) 
        Me.Label3.TabIndex = 158 
        Me.Label3.Text = "合同统计:" 
        ' 
        'cbConFact 
        ' 
        Me.cbConFact.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList 
        Me.cbConFact.Items.AddRange(New Object() {"已执行", "未执行", "全部"}) 
        Me.cbConFact.Location = New System.Drawing.Point(264, 100) 
        Me.cbConFact.Name = "cbConFact" 
        Me.cbConFact.Size = New System.Drawing.Size(96, 20) 
        Me.cbConFact.TabIndex = 159 
        ' 
        'btnCon 
        ' 
        Me.btnCon.BackColor = System.Drawing.Color.FromArgb(CType(239, Byte), CType(243, Byte), CType(255, Byte)) 
        Me.btnCon.FlatStyle = System.Windows.Forms.FlatStyle.Popup 
        Me.btnCon.Location = New System.Drawing.Point(404, 104) 
        Me.btnCon.Name = "btnCon" 
        Me.btnCon.Size = New System.Drawing.Size(56, 24) 
        Me.btnCon.TabIndex = 160 
        Me.btnCon.Text = "查询" 
        ' 
        'btnCancel 
        ' 
        Me.btnCancel.Location = New System.Drawing.Point(408, 240) 
        Me.btnCancel.Name = "btnCancel" 
        Me.btnCancel.Size = New System.Drawing.Size(68, 24) 
        Me.btnCancel.TabIndex = 161 
        Me.btnCancel.Text = "关闭(&C)" 
        ' 
        'Label6 
        ' 
        Me.Label6.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D 
        Me.Label6.ForeColor = System.Drawing.SystemColors.ControlText 
        Me.Label6.Location = New System.Drawing.Point(148, 220) 
        Me.Label6.Name = "Label6" 
        Me.Label6.Size = New System.Drawing.Size(330, 2) 
        Me.Label6.TabIndex = 162 
        ' 
        'frmConSum 
        ' 
        Me.AcceptButton = Me.btnCancel 
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14) 
        Me.ClientSize = New System.Drawing.Size(494, 275) 
        Me.Controls.Add(Me.Label6) 
        Me.Controls.Add(Me.btnCancel) 
        Me.Controls.Add(Me.btnCon) 
        Me.Controls.Add(Me.Label3) 
        Me.Controls.Add(Me.cbConFact) 
        Me.Controls.Add(Me.Label1) 
        Me.Controls.Add(Me.Label2) 
        Me.Controls.Add(Me.Label4) 
        Me.Controls.Add(Me.Label5) 
        Me.Controls.Add(Me.PictureBox1) 
        Me.Controls.Add(Me.btnConSumMonth) 
        Me.Controls.Add(Me.Label66) 
        Me.Controls.Add(Me.Label64) 
        Me.Controls.Add(Me.cbConSumYear) 
        Me.Controls.Add(Me.cbConSumMonth) 
        Me.Controls.Add(Me.labConSum) 
        Me.Controls.Add(Me.btnConSumYear) 
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog 
        Me.MaximizeBox = False 
        Me.MinimizeBox = False 
        Me.Name = "frmConSum" 
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent 
        Me.Text = "合同统计" 
        Me.ResumeLayout(False) 
 
    End Sub 
 
#End Region 
 
 
    Private Sub btnCon_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCon.Click 
        If cbConFact.SelectedIndex = -1 Then 
            Exit Sub 
        End If 
        Dim factor As Boolean 
        Dim conNum As Long 
        Dim conSum As Double 
 
        If cbConFact.SelectedIndex = 0 Then 
            factor = True 
        ElseIf cbConFact.SelectedIndex = 1 Then 
            factor = False 
        ElseIf cbConFact.SelectedIndex = 2 Then 
            Dim myConn As New OleDbConnection(strConn) 
            Dim myComm As New OleDbCommand 
            myComm.Connection = myConn 
            myComm.CommandText = "select count(id),sum(csum) from contract" 
            Dim myReader As OleDbDataReader 
            myConn.Open() 
            myReader = myComm.ExecuteReader 
            While myReader.Read 
                conNum = myReader.GetInt32(0) 
                conSum = myReader.GetDouble(1) 
            End While 
            myConn.Close() 
            Me.labConSum.Text = "合同数目: " & conNum & "   交易金额: " & conSum 
            Exit Sub 
        End If 
        Dim Conn As New OleDbConnection(strConn) 
        Dim Comm As New OleDbCommand 
        Comm.Connection = Conn 
        Comm.CommandText = "select count(id),sum(csum) from contract where factor= @factor" 
        Comm.Parameters.Add("@factor", factor) 
        Dim Reader As OleDbDataReader 
        Conn.Open() 
        Reader = Comm.ExecuteReader 
        While Reader.Read 
 
            conNum = Reader.GetInt32(0) 
            If conNum = 0 Then 
                conSum = 0 
                Exit While 
            End If 
            conSum = Reader.GetDouble(1) 
        End While 
        Conn.Close() 
        Me.labConSum.Text = "合同数目: " & conNum & "   交易金额: " & conSum 
 
    End Sub 
 
    Private Sub frmConSum_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 
        Me.labConSum.Text = "统计结果" 
        Me.cbConSumYear.Items.Clear() 
        Dim beginYear As Integer 
        Dim endYear As Integer 
 
        Try 
            Dim strTemp() As String 
            Dim strFileSetting As String = "setting.ini" 
            Dim YearReader As StreamReader = New StreamReader(strFileSetting) 
            YearReader.ReadLine() 
            YearReader.ReadLine() 
            strTemp = YearReader.ReadLine().Split(" ") 
            beginYear = strTemp(1).Trim 
            strTemp = YearReader.ReadLine().Split(" ") 
            endYear = strTemp(1).Trim 
            YearReader.Close() 
            YearReader = Nothing 
        Catch ex As Exception 
            MsgBox(Err.Description) 
            MsgBox("读取起止统计年份失败!", MsgBoxStyle.Information, "提示信息") 
        End Try 
        Dim i As Integer 
        For i = 0 To endYear - beginYear 
            Me.cbConSumYear.Items.Add(beginYear + i) 
        Next 
 
    End Sub 
 
    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click 
        Me.Close() 
    End Sub 
 
    Private Sub btnConSumYear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConSumYear.Click 
        If Me.cbConSumYear.SelectedIndex = -1 Then 
            MsgBox("请选择年份!", MsgBoxStyle.Information, "提示信息") 
            Exit Sub 
        End If 
 
        Dim conNum As Long 
        Dim conSum As Double 
        Dim myConn As New OleDbConnection(strConn) 
        Dim myComm As New OleDbCommand 
        myComm.Connection = myConn 
        myComm.CommandText = "select count(id),sum(csum) from contract where factor = true and factdate>=#" & CDate(Me.cbConSumYear.SelectedItem & "-1-1") & "# and " & "factdate<=#" & CDate(Me.cbConSumYear.SelectedItem & "-12-31") & "#" 
        Dim myReader As OleDbDataReader 
        myConn.Open() 
        myReader = myComm.ExecuteReader 
        While myReader.Read 
            conNum = myReader.GetInt32(0) 
            If conNum = "0" Then 
                conSum = 0 
                Exit While 
            Else 
                conSum = myReader.GetDouble(1) 
            End If 
        End While 
        myConn.Close() 
        Me.labConSum.Text = "合同数目: " & conNum & "   交易金额: " & conSum 
 
    End Sub 
 
    Private Sub btnConSumMonth_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConSumMonth.Click 
        If Me.cbConSumYear.SelectedIndex = -1 Then 
            MsgBox("请选择年份!", MsgBoxStyle.Information, "提示信息") 
            Exit Sub 
        End If 
        If Me.cbConSumMonth.SelectedIndex = -1 Then 
            MsgBox("请选择月份!", MsgBoxStyle.Information, "提示信息") 
            Exit Sub 
        End If 
 
        Dim conNum As Long 
        Dim conSum As Double 
        Dim endDate As String 
        Dim MonthTemp As Integer 
        MonthTemp = Me.cbConSumMonth.SelectedIndex 
        '1,3,5,7,8,10,12-31 
        '0,2,4,6,7,9,11 
 
        '4,6,9,11-30 
        '3,5,8,10 
        If MonthTemp = 0 Or MonthTemp = 2 Or MonthTemp = 4 Or MonthTemp = 6 Or MonthTemp = 7 Or MonthTemp = 9 Or MonthTemp = 11 Then 
            endDate = "-31" 
        ElseIf MonthTemp = 1 Then 
            endDate = "-28" 
        ElseIf MonthTemp = 3 Or MonthTemp = 5 Or MonthTemp = 8 Or MonthTemp = 10 Then 
            endDate = "-30" 
        End If 
        Dim myConn As New OleDbConnection(strConn) 
        Dim myComm As New OleDbCommand 
        myComm.Connection = myConn 
        myComm.CommandText = "select count(id),sum(csum) from contract where factor = true and factdate>=#" & CDate(Me.cbConSumYear.SelectedItem & "-" & Me.cbConSumMonth.SelectedIndex + 1 & "-1") & "# and " & "factdate<=#" & CDate(Me.cbConSumYear.SelectedItem & "-" & Me.cbConSumMonth.SelectedIndex + 1 & endDate) & "#" 
        Dim myReader As OleDbDataReader 
        myConn.Open() 
        myReader = myComm.ExecuteReader 
        While myReader.Read 
            conNum = myReader.GetInt32(0) 
            If conNum = "0" Then 
                conSum = 0 
                Exit While 
            Else 
                conSum = myReader.GetDouble(1) 
            End If 
        End While 
        myConn.Close() 
        Me.labConSum.Text = "合同数目: " & conNum & "   交易金额: " & conSum 
    End Sub 
 
End Class