Imports System.Data.SqlClient
Public Class frmXiaoShou
Inherits System.Windows.Forms.Form
Dim ds As New DataSet
Dim sqlDa As New SqlDataAdapter
Dim sqlCmd As New SqlCommand
销售按钮:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Module1.sqlconn.Open()
Try
Dim str As String
sqlCmd.Connection = Module1.sqlconn
str = "insert into 销售表(名称,尺寸,颜色,金额,数量) values ('" & txtShoesID.Text & "','" & CombNoID.SelectedItem & "','" & combColorID.SelectedItem & "','" & txtTotalMoney.Text & "','" & NumericUpDown2.Text & "')"
sqlCmd.CommandType = CommandType.Text
sqlCmd.CommandText = str
sqlDa.InsertCommand = sqlCmd
sqlCmd.ExecuteNonQuery()
MessageBox.Show("销售成功!", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Information)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
' Dim row As DataRow
' row = Me.ds.Tables("销售表").NewRow
' ' row("名称") = Me.txtShoesID.Text
' row("尺寸") = Me.CombNoID.Text
' row("价格") = Me.txtUnitPrice.Text
' row("颜色") = Me.combColorID.Text
' row("折扣") = Me.NumericUpDown1.Text
' row("数量") = Me.NumericUpDown2.Text
' Me.ds.Tables("销售表").Rows.Add(row)
' If Me.ds.Tables("销售表").Rows.Count > 0 Then
' Me.txtTotalMoney.Text = Me.ds.Tables("销售表").Compute("sum(金额)", "")
' End If
' DataGrid1.DataSource = Me.ds.Tables("销售表")
'DataGrid1.DataBindings()
Module1.sqlconn.Close()
下面是更新库存表,这段代码还没有完成,这个步骤也要是把在datagrid中的数量通过点击销售来更新库存表
Module1.sqlconn.Open()
sqlCmd.CommandText = "update 库存表 set 数量 =数量-'" & NumericUpDown2.Text.Trim & "' where 名称='" & txtShoesID.Text & "' and 尺寸='" & CombNoID.SelectedItem & " and 颜色='" & combColorID.SelectedItem & "'"
sqlCmd.Connection = Module1.sqlconn
sqlCmd.CommandType = CommandType.Text
sqlDa.SelectCommand = sqlCmd
If sqlconn.State = ConnectionState.Open Then
Module1.sqlconn.Close()
End If
下面是把销售的情况打印出来
Dim printFrm As New Printfrmshoes
Dim printDoc As New CrystalReport2
printDoc.SetDataSource(ds.Tables("销售表"))
printFrm.CrystalReportViewershoes.ReportSource = printDoc
printFrm.Show()
End Sub
而下面这段代码是当我把鞋名和尺寸都输入后在输入颜色时会自动查询库存表里面的东西显示在
图片附件: 游客没有浏览图片的权限,请
登录 或
注册
图片5上面
Private Sub txtColorID_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles combColorID.SelectedIndexChanged
If Me.txtShoesID.Text.Trim.Length = 0 And Me.txtShoesID.Text.Trim.Length Then
MsgBox("请输入正确的数据!", MsgBoxStyle.Information, "提示")
Me.txtShoesID.Focus()
Me.CombNoID.Focus()
Exit Sub
End If
sqlCmd.CommandText = "select 名称 ,尺寸 ,颜色,价格,数量 from 库存表 where 名称='" & txtShoesID.Text & "' and 尺寸='" & CombNoID.SelectedItem & "' and 颜色='" & combColorID.SelectedItem & "'"
sqlCmd.Connection = Module1.sqlconn
sqlCmd.CommandType = CommandType.Text
sqlDa.SelectCommand = sqlCmd
Dim sqlDr As SqlDataReader
Try
If Module1.sqlconn.State <> ConnectionState.Open Then
Module1.sqlconn.Open()
End If
sqlDr = sqlCmd.ExecuteReader(CommandBehavior.CloseConnection)
If sqlDr.Read Then
Me.txtUnitPrice.Text = sqlDr("价格")
Me.txtStockQuantity.Text = sqlDr("数量")
End If
sqlDr.Close()
Module1.sqlconn.Close()
Catch ex As Exception
MsgBox("发生错误:" & ex.Message)
End Try
End Sub
下面的代码是确定按钮下的代码,通过点击可以把数据从在图片5上输入数据
点击确定显示在datagrid中的.
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
If Me.txtShoesID.Text.Trim.Length = 0 Then
MsgBox("请输入鞋名!", MsgBoxStyle.Information, "提示")
Me.txtShoesID.Focus()
Exit Sub
End If
If Me.CombNoID.Text.Trim.Length = 0 Then
MsgBox("请输入号码!", MsgBoxStyle.Information, "提示")
Me.CombNoID.Focus()
Exit Sub
End If
If Me.combColorID.Text.Trim.Length = 0 Then
MsgBox("请输入颜色!", MsgBoxStyle.Information, "提示")
Me.combColorID.Focus()
Exit Sub
End If
Dim row As DataRow
row = Me.ds.Tables("销售表").NewRow
row("名称") = Me.txtShoesID.Text
row("尺寸") = Me.CombNoID.Text
row("价格") = Me.txtUnitPrice.Text
row("颜色") = Me.combColorID.Text
row("折扣") = Me.NumericUpDown1.Text
row("数量") = Me.NumericUpDown2.Text
Me.ds.Tables("销售表").Rows.Add(row)
If Me.ds.Tables("销售表").Rows.Count > 0 Then
Me.txtTotalMoney.Text = Me.ds.Tables("销售表").Compute("sum(金额)", "")
End If
End Sub
这段代码是我要运行这个界面时会自动把下面的字段显示在datagrid中的
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim dt As New DataTable("销售表")
dt.Columns.Add("名称", System.Type.GetType("System.String"))
dt.Columns.Add("尺寸", System.Type.GetType("System.Int16"))
dt.Columns.Add("颜色", System.Type.GetType("System.String"))
dt.Columns.Add("价格", System.Type.GetType("System.Decimal"))
dt.Columns.Add("折扣", System.Type.GetType("System.Single"))
dt.Columns.Add("数量", System.Type.GetType("System.Int16"))
dt.Columns.Add("金额", System.Type.GetType("System.Decimal"), "价格*折扣*数量")
Me.ds.Tables.Add(dt)
Me.DataGrid1.DataSource = dt
End Sub