Imports System.Data
Imports System.Data.SqlClient
Public Class FrmSell
Dim str1 As String
Private Sub FrmSell_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim conn As New SqlConnection
Dim sql As String
Dim mytable As New DataTable
Dim ds As New DataSet
conn.ConnectionString = "data source=127.0.0.1;initial catalog=Supermarket;user=text;password=text"
Try
sql = "select sellid as 销售编号,barcode as 条形码 ,selldate as 销售日期,unitprice as 单价,quantity as 数量,unitprice*quantity as 总额,employeesid as 销售员工编号" _
& " from sells "
Dim adp As New SqlDataAdapter(sql, conn)
adp.Fill(ds, "a")
Me.DataGrid1.DataSource = ds.Tables("a")
Catch ex As Exception
' MsgBox(ex.ToString)
Finally
End Try
End Sub
Private Sub ButQuery_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButQuery.Click
Select Case Me.ComboBox1.Text
Case "员工ID"
str1 = "employeesid"
chaxun()
Case "条形码"
str1 = "barcode"
chaxun()
End Select
End Sub
Private Sub ButCollect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButCollect.Click
Select Case Me.ComboBox1.Text
Case "员工ID"
str1 = "employeesid"
huizhong()
Case "条形码"
str1 = "barcode"
huizhong()
End Select
End Sub
Private Sub huizhong()
Try
If Me.ComboBox1.Text = "" Or Me.TxtCondition.Text = "" Then
MsgBox("方法,条件不能为空!")
Else
Dim conn As New SqlConnection
Dim sql As String
Dim ds As New DataSet
conn.ConnectionString = "data source=127.0.0.1;initial catalog=Supermarket;user=text;password=text"
sql = " select sum(unitprice * quantity) as 总额 from sells where " & str1 & "='" & Me.TxtCondition.Text & "' and selldate between '" & Me.DTime1.Text & "' and '" & Me.DTime2.Text & "'"
Dim adp As New SqlDataAdapter(sql, conn)
adp.Fill(ds, "a")
Me.DataGrid1.DataSource = ds.Tables("a")
End If
Catch ex As Exception
' MsgBox(ex.ToString)
End Try
End Sub
Private Sub chaxun()
Try
Dim conn As New SqlConnection
Dim sql As String
Dim ds As New DataSet
conn.ConnectionString = "data source=127.0.0.1;initial catalog=Supermarket;user=text;password=text"
If Me.ComboBox1.Text = "" Or Me.TxtCondition.Text = "" Then
MsgBox("方法,条件不能为空!")
Else
sql = "select sellid as 销售编号,barcode as 条形码 ,selldate as 销售日期,unitprice as 单价,quantity as 数量,unitprice*quantity as 总额,employeesid as 销售员工编号" _
& " from sells where " & str1 & "='" & Me.TxtCondition.Text & "' and selldate between '" & Me.DTime1.Text & "' and '" & Me.DTime2.Text & "'"
Dim adp As New SqlDataAdapter(sql, conn)
adp.Fill(ds, "a")
Me.DataGrid1.DataSource = ds.Tables("a").DefaultView
End If
Catch ex As Exception
' MsgBox(ex.ToString)
End Try
End Sub
End Class