Visual Basic 2010 数据库开发之超市管理系统06售货管理草稿

界面

后台

Imports System.Data.SqlClient
Namespace tableclass
    '用户表类
    Public Class user
        Private mName As String
        Private mPassword As String
        Public Property Name As String
            Get
                Return mName
            End Get
            Set(ByVal value As String)
                mName = value
            End Set
        End Property
        Public Property Password As String
            Get
                Return mPassword
            End Get
            Set(ByVal value As String)
                mPassword = value
            End Set
        End Property

        Public Function GetAllUser() As DataTable
            Dim conn As SqlConnection = GetConnection()
            conn.Open()
            Dim strSql As String = "Select * from usertable"
            Dim da As New SqlDataAdapter(strSql, conn)
            Dim dt As New DataTable
            da.Fill(dt)
            conn.Close()
            Return dt
        End Function

        Public Function GetByValue(ByVal strName As String, ByVal strpwd As String) As DataTable
            Dim conn As SqlConnection = GetConnection()
            conn.Open()
            Dim strSql As String = "Select * from usertable where name='{0}' and password='{1}'"
            strSql = String.Format(strSql, strName, strpwd)
            Dim da As New SqlDataAdapter(strSql, conn)
            Dim dt As New DataTable
            da.Fill(dt)
            conn.Close()
            Return dt
        End Function

        '添加
        Public Sub Add()
            Dim conn As SqlConnection = GetConnection()
            Try
                conn.Open()
                Dim sql As String = "INSERT INTO usertable (name,password) VALUES (@name,@password)"
                Dim comm As SqlCommand = New SqlCommand(sql, conn)
                Dim p1 As SqlParameter = New SqlParameter("@name", Name)
                Dim p2 As SqlParameter = New SqlParameter("@phone", Password)

                comm.Parameters.Add(p1)
                comm.Parameters.Add(p2)

                comm.ExecuteNonQuery()

            Finally
                conn.Close()
            End Try
        End Sub

        '更新
        Public Sub Update()
            Dim conn As SqlConnection = GetConnection()
            Try
                conn.Open()
                Dim sql As String = "UPDATE usertable SET password=@password WHERE username=" + Name
                Dim comm As SqlCommand = New SqlCommand(sql, conn)
                Dim p1 As SqlParameter = New SqlParameter("@name", Name)
                Dim p2 As SqlParameter = New SqlParameter("@phone", Password)
                comm.Parameters.Add(p1)
                comm.Parameters.Add(p2)
                comm.ExecuteNonQuery()
            Catch ex As Exception
            Finally
                conn.Close()
            End Try
        End Sub

        '删除
        Public Sub Delete(ByVal nm As String)
            Dim conn As SqlConnection = GetConnection()
            Try
                conn.Open()
                Dim sql As String = String.Format("DELETE FROM usertable WHERE name={0}", Name)
                Dim comm As SqlCommand = New SqlCommand(sql, conn)
                comm.ExecuteNonQuery()

            Catch ex As Exception
            Finally
                conn.Close()
            End Try
        End Sub
    End Class
    '进货表类
    Public Class JinHuo
        Private mjhID As String
        Private mjhDate As Date
        Private mjhZhongLei As String
        Private mjhHPID As String
        Private mjhMingCheng As String
        Private mjhDanWei As String
        Private mjhDanJia As Decimal
        Private mjhCount As Integer
        Private mjhJinE As Decimal
        Private mjhJinShouRen As String
        Private mjhGongYingShang As String

        Public Property jhID As String
            Get
                Return mjhID
            End Get
            Set(ByVal value As String)
                mjhID = value
            End Set
        End Property
        Public Property jhDate As Date
            Get
                Return mjhDate
            End Get
            Set(ByVal value As Date)
                mjhDate = value
            End Set
        End Property
        Public Property jhZhongLei As String
            Get
                Return mjhZhongLei
            End Get
            Set(ByVal value As String)
                mjhZhongLei = value
            End Set
        End Property
        Public Property jhHPID As String
            Get
                Return mjhHPID
            End Get
            Set(ByVal value As String)
                mjhHPID = value
            End Set
        End Property
        Public Property jhMingCheng As String
            Get
                Return mjhMingCheng
            End Get
            Set(ByVal value As String)
                mjhMingCheng = value
            End Set
        End Property
        Public Property jhDanWei As String
            Get
                Return mjhDanWei
            End Get
            Set(ByVal value As String)
                mjhDanWei = value
            End Set
        End Property
        Public Property jhDanJia As Decimal
            Get
                Return mjhDanJia
            End Get
            Set(ByVal value As Decimal)
                mjhDanJia = value
            End Set
        End Property
        Public Property jhCount As Integer
            Get
                Return mjhCount
            End Get
            Set(ByVal value As Integer)
                mjhCount = value
            End Set
        End Property
        Public Property jhJinE As Decimal
            Get
                Return mjhJinE
            End Get
            Set(ByVal value As Decimal)
                mjhJinE = value
            End Set
        End Property
        Public Property jhJingShouRen As String
            Get
                Return mjhJinShouRen
            End Get
            Set(ByVal value As String)
                mjhJinShouRen = value
            End Set
        End Property
        Public Property jhGongYingShang As String
            Get
                Return mjhGongYingShang
            End Get
            Set(ByVal value As String)
                mjhGongYingShang = value
            End Set
        End Property

        Public Function GetAllJinHouTable() As DataTable
            Dim conn As SqlConnection = GetConnection()
            conn.Open()

            Dim strSql As String = "Select * from jhTable"
            Dim jhda As New SqlDataAdapter(strSql, conn)
            Dim jhdt As New DataTable
            jhda.Fill(jhdt)

            conn.Close()
            Return jhdt
        End Function

        Public Sub Add()
            Dim conn As SqlConnection = GetConnection()
            Try
                conn.Open()
                Dim sql As String = _
                    "INSERT INTO jhTable" _
                  & "(票据号,进货日期,货品种类,货品编号,货品名称,单位,进货单价,进货数量,金额,经手人,供应商) " _
                  & "VALUES " _
                  & "(@票据号,@进货日期,@货品种类,@货品编号,@货品名称,@单位,@进货单价,@进货数量,@金额,@经手人,@供应商)"

                'MsgBox(sql)'检查语法用的

                Dim cmd As SqlCommand = New SqlCommand(sql, conn)

                Dim p1 As SqlParameter = New SqlParameter("@票据号", jhID)
                Dim p2 As SqlParameter = New SqlParameter("@进货日期", jhDate)
                Dim p3 As SqlParameter = New SqlParameter("@货品种类", jhZhongLei)
                Dim p4 As SqlParameter = New SqlParameter("@货品编号", jhHPID)
                Dim p5 As SqlParameter = New SqlParameter("@货品名称", jhMingCheng)
                Dim p6 As SqlParameter = New SqlParameter("@单位", jhDanWei)
                Dim p7 As SqlParameter = New SqlParameter("@进货单价", jhDanJia)
                Dim p8 As SqlParameter = New SqlParameter("@进货数量", jhCount)
                Dim p9 As SqlParameter = New SqlParameter("@金额", jhJinE)
                Dim p10 As SqlParameter = New SqlParameter("@经手人", jhJingShouRen)
                Dim p11 As SqlParameter = New SqlParameter("@供应商", jhGongYingShang)

                cmd.Parameters.Add(p1)
                cmd.Parameters.Add(p2)
                cmd.Parameters.Add(p3)
                cmd.Parameters.Add(p4)
                cmd.Parameters.Add(p5)
                cmd.Parameters.Add(p6)
                cmd.Parameters.Add(p7)
                cmd.Parameters.Add(p8)
                cmd.Parameters.Add(p9)
                cmd.Parameters.Add(p10)
                cmd.Parameters.Add(p11)

                cmd.ExecuteNonQuery()

            Finally
                conn.Close()
            End Try
        End Sub

        '更新
        Public Sub Update()
            Dim conn As SqlConnection = GetConnection()
            Try
                conn.Open()
                Dim strsql As String = _
                    "UPDATE jhTable " _
                  & "SET 票据号=@票据号,进货日期=@进货日期,货品种类=@货品种类," _
                  & "货品编号=@货品编号,货品名称=@货品名称,单位=@单位,进货单价=@进货单价," _
                  & "进货数量=@进货数量,金额=@金额,经手人=@经手人,供应商=@供应商 " _
                  & "WHERE 票据号='" + jhID + "'"

                MsgBox(strsql)

                Dim cmd As SqlCommand = New SqlCommand(strsql, conn)

                Dim p1 As SqlParameter = New SqlParameter("@票据号", jhID)
                Dim p2 As SqlParameter = New SqlParameter("@进货日期", jhDate)
                Dim p3 As SqlParameter = New SqlParameter("@货品种类", jhZhongLei)
                Dim p4 As SqlParameter = New SqlParameter("@货品编号", jhHPID)
                Dim p5 As SqlParameter = New SqlParameter("@货品名称", jhMingCheng)
                Dim p6 As SqlParameter = New SqlParameter("@单位", jhDanWei)
                Dim p7 As SqlParameter = New SqlParameter("@进货单价", jhDanJia)
                Dim p8 As SqlParameter = New SqlParameter("@进货数量", jhCount)
                Dim p9 As SqlParameter = New SqlParameter("@金额", jhJinE)
                Dim p10 As SqlParameter = New SqlParameter("@经手人", jhJingShouRen)
                Dim p11 As SqlParameter = New SqlParameter("@供应商", jhGongYingShang)

                cmd.Parameters.Add(p1)
                cmd.Parameters.Add(p2)
                cmd.Parameters.Add(p3)
                cmd.Parameters.Add(p4)
                cmd.Parameters.Add(p5)
                cmd.Parameters.Add(p6)
                cmd.Parameters.Add(p7)
                cmd.Parameters.Add(p8)
                cmd.Parameters.Add(p9)
                cmd.Parameters.Add(p10)
                cmd.Parameters.Add(p11)

                cmd.ExecuteNonQuery()
            Catch ex As Exception
            Finally
                conn.Close()
            End Try
        End Sub

        '删除
        Public Sub Delete(ByVal jhid As String)
            MsgBox(jhid)
            Dim conn As SqlConnection = GetConnection()
            Try
                conn.Open()

                Dim sql As String = String.Format("DELETE FROM jhTable WHERE 票据号='{0}'", jhid)
                Dim cmd As SqlCommand = New SqlCommand(sql, conn)
                cmd.ExecuteNonQuery()

            Catch ex As Exception
            Finally
                conn.Close()
            End Try
        End Sub

    End Class
    '价格类
    Public Class jiage
        Private mjgZhongLei As String
        Private mjgMingCheng As String
        Private mjgBianHao As String
        Private mjgJinJia As Decimal
        Private mjgShoujia As Decimal
        Public Property jgZhongLei As String
            Get
                Return mjgZhongLei
            End Get
            Set(ByVal value As String)
                mjgZhongLei = value
            End Set
        End Property
        Public Property jgMingCheng As String
            Get
                Return mjgMingCheng
            End Get
            Set(ByVal value As String)
                mjgMingCheng = value
            End Set
        End Property
        Public Property jgBianHao As String
            Get
                Return mjgBianHao
            End Get
            Set(ByVal value As String)
                mjgBianHao = value
            End Set
        End Property
        Public Property jgJinJia As Decimal
            Get
                Return mjgJinJia
            End Get
            Set(ByVal value As Decimal)
                mjgJinJia = value
            End Set
        End Property
        Public Property jgShoujia As Decimal
            Get
                Return mjgShoujia
            End Get
            Set(ByVal value As Decimal)
                mjgShoujia = value
            End Set
        End Property

        Public Function GetAllJiaGeTable() As DataTable
            Dim conn As SqlConnection = GetConnection()
            conn.Open()
            Dim strSql As String = "Select * from jgTable"
            Dim da As New SqlDataAdapter(strSql, conn)
            Dim dt As New DataTable
            da.Fill(dt)
            conn.Close()
            Return dt
        End Function
        Public Function GetZhongLei() As DataTable
            Dim conn As SqlConnection = GetConnection()
            conn.Open()

            Dim strSql As String = "Select 货品种类  from jhTable"
            Dim da As New SqlDataAdapter(strSql, conn)
            Dim dt As New DataTable
            da.Fill(dt)

            conn.Close()
            Return dt
        End Function
        Public Function GetByZhongLei(ByVal zhl As String) As DataTable
            Dim conn As SqlConnection = GetConnection()
            conn.Open()

            Dim strSql As String = "Select 货品名称,货品编号,进货单价 " _
                                 & "From jhTable " _
                                 & "Where 货品种类 like '%{0}%'"
            strSql = String.Format(strSql, zhl)
            Dim da As New SqlDataAdapter(strSql, conn)
            Dim dt As New DataTable
            da.Fill(dt)
            Return dt

            conn.Close()
        End Function

        Public Sub Add()
            Dim conn As SqlConnection = GetConnection()
            Try
                conn.Open()
                Dim sql As String = _
                    "INSERT INTO jgTable" _
                  & "(货品种类,货品名称,货品编号,进价,售价) " _
                  & "VALUES " _
                  & "(@货品种类,@货品名称,@货品编号,@进价,@售价)"

                'MsgBox(sql)'检查语法用的

                Dim cmd As SqlCommand = New SqlCommand(sql, conn)

                Dim p1 As SqlParameter = New SqlParameter("@货品种类", jgZhongLei)
                Dim p2 As SqlParameter = New SqlParameter("@货品名称", jgMingCheng)
                Dim p3 As SqlParameter = New SqlParameter("@货品编号", jgBianHao)
                Dim p4 As SqlParameter = New SqlParameter("@进价", jgJinJia)
                Dim p5 As SqlParameter = New SqlParameter("@售价", jgShoujia)

                cmd.Parameters.Add(p1)
                cmd.Parameters.Add(p2)
                cmd.Parameters.Add(p3)
                cmd.Parameters.Add(p4)
                cmd.Parameters.Add(p5)

                cmd.ExecuteNonQuery()

            Finally
                conn.Close()
            End Try
        End Sub

        '更新
        Public Sub Update()
            Dim conn As SqlConnection = GetConnection()
            Try
                conn.Open()
                Dim strsql As String = _
                    "UPDATE jgTable " _
                  & "SET 货品种类=@货品种类,货品编号=@货品编号,货品名称=@货品名称,进价=@进价,售价=@售价 " _
                  & "WHERE 货品编号='" + jgBianHao + "'"

                'MsgBox(strsql)

                Dim cmd As SqlCommand = New SqlCommand(strsql, conn)

                Dim p1 As SqlParameter = New SqlParameter("@货品种类", jgZhongLei)
                Dim p2 As SqlParameter = New SqlParameter("@货品编号", jgBianHao)
                Dim p3 As SqlParameter = New SqlParameter("@货品名称", jgMingCheng)
                Dim p4 As SqlParameter = New SqlParameter("@进价", jgJinJia)
                Dim p5 As SqlParameter = New SqlParameter("@售价", jgShoujia)

                cmd.Parameters.Add(p1)
                cmd.Parameters.Add(p2)
                cmd.Parameters.Add(p3)
                cmd.Parameters.Add(p4)
                cmd.Parameters.Add(p5)

                cmd.ExecuteNonQuery()
            Catch ex As Exception
            Finally
                conn.Close()
            End Try
        End Sub

        '删除
        Public Sub Delete(ByVal bianhao As String)
            Dim conn As SqlConnection = GetConnection()
            Try
                conn.Open()
                Dim sql As String = String.Format("DELETE FROM jgTable WHERE 货品编号='{0}'", bianhao)
                Dim cmd As SqlCommand = New SqlCommand(sql, conn)
                cmd.ExecuteNonQuery()

            Catch ex As Exception
            Finally
                conn.Close()
            End Try
        End Sub
    End Class
    '售货
    Public Class ShouHuo
        Private mshID As String
        Private mshDate As Date
        Private mshZhongLei As String
        Private mshBianHao As String
        Private mshMingCheng As String
        Private mshDanWei As String
        Private mshDanJia As Decimal
        Private mshCount As Integer
        Private mshJinE As Decimal
        Private mshJingShouRen As String
        Private mshBeiZhu As String

        Public Property shID As String
            Get
                Return mshID
            End Get
            Set(ByVal value As String)
                mshID = value
            End Set
        End Property
        Public Property shDate As Date
            Get
                Return mshDate
            End Get
            Set(ByVal value As Date)
                mshDate = value
            End Set
        End Property
        Public Property shZhongLei As String
            Get
                Return mshZhongLei
            End Get
            Set(ByVal value As String)
                mshZhongLei = value
            End Set
        End Property
        Public Property shBianHao As String
            Get
                Return mshBianHao
            End Get
            Set(ByVal value As String)
                mshBianHao = value
            End Set
        End Property
        Public Property shMingCheng As String
            Get
                Return mshMingCheng
            End Get
            Set(ByVal value As String)
                mshMingCheng = value
            End Set
        End Property
        Public Property shDanWei As Decimal
            Get
                Return mshDanWei
            End Get
            Set(ByVal value As Decimal)
                mshDanWei = value
            End Set
        End Property
        Public Property shDanJia As String
            Get
                Return mshDanJia
            End Get
            Set(ByVal value As String)
                mshDanJia = value
            End Set
        End Property
        Public Property shCount As Integer
            Get
                Return mshCount
            End Get
            Set(ByVal value As Integer)
                mshCount = value
            End Set
        End Property
        Public Property shJinE As Decimal
            Get
                Return mshJinE
            End Get
            Set(ByVal value As Decimal)
                mshJinE = value
            End Set
        End Property
        Public Property shJingShouRen As String
            Get
                Return mshJingShouRen
            End Get
            Set(ByVal value As String)
                mshJingShouRen = value
            End Set
        End Property
        Public Property shBeiZhu As String
            Get
                Return mshBeiZhu
            End Get
            Set(ByVal value As String)
                mshBeiZhu = value
            End Set
        End Property

        Public Function GetAllShouHuoTable() As DataTable
            Dim conn As SqlConnection = GetConnection()
            conn.Open()
            Dim strSql As String = "Select * from shTable"
            Dim da As New SqlDataAdapter(strSql, conn)
            Dim dt As New DataTable
            da.Fill(dt)
            conn.Close()
            Return dt
        End Function
        
        Public Sub Add()
            Dim conn As SqlConnection = GetConnection()
            Try
                conn.Open()
                Dim strsql As String = _
                   "INSERT INTO shTable " _
                 & "(售货日期,货品种类,货品编号,货品名称,单位,单价,数量,金额,经手人,备注) " _
                 & "VALUES " _
                 & "(@售货日期,@货品种类,@货品编号,@货品名称,@单位,@单价,@数量,@金额,@经手人,@备注)"

                MsgBox(strsql) '检查语法用的

                Dim comm As SqlCommand = New SqlCommand(strsql, conn)

                Dim p1 As SqlParameter = New SqlParameter("@售货日期", shDate)
                Dim p2 As SqlParameter = New SqlParameter("@货品种类", shZhongLei)
                Dim p3 As SqlParameter = New SqlParameter("@货品编号", shBianHao)
                Dim p4 As SqlParameter = New SqlParameter("@货品名称", shMingCheng)
                Dim p5 As SqlParameter = New SqlParameter("@单位", shDanWei)
                Dim p6 As SqlParameter = New SqlParameter("@单价", shDanJia)
                Dim p7 As SqlParameter = New SqlParameter("@数量", shCount)
                Dim p8 As SqlParameter = New SqlParameter("@金额", shJinE)
                Dim p9 As SqlParameter = New SqlParameter("@经手人", shJingShouRen)
                Dim p10 As SqlParameter = New SqlParameter("@备注", shBeiZhu)

                comm.Parameters.Add(p1)
                comm.Parameters.Add(p2)
                comm.Parameters.Add(p3)
                comm.Parameters.Add(p4)
                comm.Parameters.Add(p5)
                comm.Parameters.Add(p6)
                comm.Parameters.Add(p7)
                comm.Parameters.Add(p8)
                comm.Parameters.Add(p9)
                comm.Parameters.Add(p10)

                comm.ExecuteNonQuery()

            Finally
                conn.Close()
            End Try
        End Sub

        '更新
        Public Sub Update()
            Dim conn As SqlConnection = GetConnection()
            Try
                conn.Open()
                Dim strsql As String = _
                    "UPDATE shTable " _
                  & "SET 售货日期=@售货日期,货品种类=@货品种类,货品编号=@货品编号," _
                  & "货品名称=@货品名称,单位=@单位,单价=@单价,数量=@数量," _
                  & "金额=@金额,经手人=@经手人,备注=@备注 " _
                  & "WHERE 货品编号='" + shBianHao + "'"

                'MsgBox(strsql)

                Dim comm As SqlCommand = New SqlCommand(strsql, conn)

                Dim p1 As SqlParameter = New SqlParameter("@售货日期", shDate)
                Dim p2 As SqlParameter = New SqlParameter("@货品种类", shZhongLei)
                Dim p3 As SqlParameter = New SqlParameter("@货品编号", shBianHao)
                Dim p4 As SqlParameter = New SqlParameter("@货品名称", shMingCheng)
                Dim p5 As SqlParameter = New SqlParameter("@单位", shDanWei)
                Dim p6 As SqlParameter = New SqlParameter("@单价", shDanJia)
                Dim p7 As SqlParameter = New SqlParameter("@数量", shCount)
                Dim p8 As SqlParameter = New SqlParameter("@金额", shJinE)
                Dim p9 As SqlParameter = New SqlParameter("@经手人", shJingShouRen)
                Dim p10 As SqlParameter = New SqlParameter("@备注", shBeiZhu)

                comm.Parameters.Add(p1)
                comm.Parameters.Add(p2)
                comm.Parameters.Add(p3)
                comm.Parameters.Add(p4)
                comm.Parameters.Add(p5)
                comm.Parameters.Add(p6)
                comm.Parameters.Add(p7)
                comm.Parameters.Add(p8)
                comm.Parameters.Add(p9)
                comm.Parameters.Add(p10)

                comm.ExecuteNonQuery()
            Catch ex As Exception
            Finally
                conn.Close()
            End Try
        End Sub

        '删除
        Public Sub Delete(ByVal bianhao As String)
            Dim conn As SqlConnection = GetConnection()
            Try
                conn.Open()
                Dim sql As String = String.Format("DELETE FROM shTable WHERE 货品编号='{0}'", bianhao)
                Dim comm As SqlCommand = New SqlCommand(sql, conn)
                comm.ExecuteNonQuery()

            Catch ex As Exception
            Finally
                conn.Close()
            End Try
        End Sub
    End Class
End Namespace
 

客户端

Imports System.Data.SqlClient
Imports 超市管理系统.tableclass
Public Class FrmShouHuo
    Dim flag As String = ""
    Dim newShouHuo As New ShouHuo
    Dim shdt As DataTable
    '使用dataview定制从数据库返回的、存储在DataSet中的记录的视图
    Dim shDataView As DataView
    'CurrencyManager用于控制绑定数据
    Dim bmdata As CurrencyManager

    '数据填充并更新显示过程
    Private Sub FillDataSetAndView()
        shdt = New DataTable
        shdt = newShouHuo.GetAllShouHuoTable
        '将表填入dataview
        shDataView = New DataView(shdt)
        '将DataView变量绑定控件,能记录位置
        bmdata = Me.BindingContext(shDataView)
    End Sub

    '获得数据库最新数据,并填充DataView对象
    Private Sub BindFields()
        DateTimePicker1.DataBindings.Clear()
        cmbZhongLei.DataBindings.Clear()
        txtBianHao.DataBindings.Clear()
        txtMingCheng.DataBindings.Clear()
        txtDanWei.DataBindings.Clear()
        txtDanJia.DataBindings.Clear()
        txtCount.DataBindings.Clear()
        txtJinE.DataBindings.Clear()
        txtJingShouRen.DataBindings.Clear()
        txtMenu.DataBindings.Clear()


        'Add三个参数:控件属性,(DataSet,Datatable,DataView),数据字段
        DateTimePicker1.DataBindings.Add("value", shDataView, "售货日期")
        cmbZhongLei.DataBindings.Add("text", shDataView, "货品种类")
        txtBianHao.DataBindings.Add("text", shDataView, "货品编号")
        txtMingCheng.DataBindings.Add("text", shDataView, "货品名称")
        txtDanWei.DataBindings.Add("text", shDataView, "单位")
        txtDanJia.DataBindings.Add("text", shDataView, "单价")
        txtCount.DataBindings.Add("text", shDataView, "数量")
        txtJinE.DataBindings.Add("text", shDataView, "金额")
        txtJingShouRen.DataBindings.Add("text", shDataView, "经手人")
        txtMenu.DataBindings.Add("text", shDataView, "备注")

    End Sub

    '设置控件可用
    Private Sub SetControlEnable()
        DateTimePicker1.Enabled = True
        cmbZhongLei.Enabled = True
        txtBianHao.Enabled = True
        txtMingCheng.Enabled = True
        txtDanWei.Enabled = True
        txtDanJia.Enabled = True
        txtCount.Enabled = True
        txtJinE.Enabled = True
        txtJingShouRen.Enabled = True
        txtMenu.Enabled = True

    End Sub
    '设置控件不可用
    Private Sub SetControlDisable()
        DateTimePicker1.Enabled = False
        cmbZhongLei.Enabled = False
        txtBianHao.Enabled = False
        txtMingCheng.Enabled = False
        txtDanWei.Enabled = False
        txtDanJia.Enabled = False
        txtCount.Enabled = False
        txtJinE.Enabled = False
        txtJingShouRen.Enabled = False
        txtMenu.Enabled = False
    End Sub
    '测试数据
    Private Sub testDebug()
        DateTimePicker1.Value = Today
        cmbZhongLei.Text = "食品"
        txtBianHao.Text = "12354"
        txtMingCheng.Text = "糖圪塔"
        txtDanWei.Text = "块"
        txtDanJia.Text = 1
        txtCount.Text = 2
        txtJinE.Text = 2
        txtJingShouRen.Text = "李雷"
        txtMenu.Text = "韩梅梅每天都要吃两块"
    End Sub

    Private Sub FrmShouHuo_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


        SetControlDisable()

        FillDataSetAndView()
        BindFields()

        DataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill
        DataGridView1.DataSource = shdt
    End Sub

    Private Sub btnNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNew.Click
        flag = "add"
        testDebug()
        SetControlEnable()
        'bmdata.EndCurrentEdit()
        'bmdata.AddNew()
        DateTimePicker1.Text = Today
        txtJingShouRen.Text = username
    End Sub

    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        newShouHuo = New ShouHuo
        newShouHuo.shDate = DateTimePicker1.Value
        newShouHuo.shZhongLei = cmbZhongLei.Text
        newShouHuo.shBianHao = txtBianHao.Text
        newShouHuo.shMingCheng = txtMingCheng.Text
        newShouHuo.shDanWei = Val(txtDanWei.Text)
        newShouHuo.shDanJia = txtDanJia.Text
        newShouHuo.shCount = txtCount.Text
        newShouHuo.shJinE = txtJinE.Text
        newShouHuo.shJingShouRen = txtJingShouRen.Text
        newShouHuo.shBeiZhu = txtMenu.Text
        If flag = "add" Then
            newShouHuo.Add()
        ElseIf flag = "modify" Then
            newShouHuo.Update()
        Else
            Exit Sub
        End If

        flag = ""

        FillDataSetAndView()
        BindFields()

        DataGridView1.DataSource = shdt

        SetControlDisable()
    End Sub

    Private Sub btnModify_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnModify.Click
        flag = "modify"
        SetControlEnable()
        DateTimePicker1.Focus()
    End Sub

    Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
        If MessageBox.Show("确定删除吗?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Stop) = DialogResult.Yes Then
            If bmdata.Count > 0 Then
                newShouHuo.Delete(txtBianHao.Text)
                shdt.Rows(bmdata.Position).Delete()
            End If
        End If

        FillDataSetAndView()
        BindFields()

        DataGridView1.DataSource = shdt
    End Sub

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        Me.Close()
    End Sub

    Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
        SetControlDisable()

        Dim index As Integer = e.RowIndex
        bmdata.Position = index

        DateTimePicker1.Text = DataGridView1.Rows(index).Cells(1).Value
        cmbZhongLei.Text = DataGridView1.Rows(index).Cells(2).Value
        txtBianHao.Text = DataGridView1.Rows(index).Cells(3).Value
        txtMingCheng.Text = DataGridView1.Rows(index).Cells(4).Value
        txtDanWei.Text = DataGridView1.Rows(index).Cells(5).Value
        txtDanJia.Text = DataGridView1.Rows(index).Cells(6).Value
        txtCount.Text = DataGridView1.Rows(index).Cells(7).Value
        txtJinE.Text = DataGridView1.Rows(index).Cells(8).Value
        txtJingShouRen.Text = DataGridView1.Rows(index).Cells(9).Value
        txtMenu.Text = DataGridView1.Rows(index).Cells(10).Value
    End Sub

    '这段无效
    Private Sub txtBianHao_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtBianHao.Validated
        Dim conn1 As SqlConnection = GetConnection()
        conn1.Open()
        Dim strSql As String = "Select 货品名称,单位 from jhTable " _
                             & "Where 货品编号='" & txtBianHao.Text.Trim & "'"
        Dim comm As New SqlCommand(strSql, conn1)
        Dim dr As SqlDataReader
        dr = comm.ExecuteReader
        While dr.Read
            Try
                txtMingCheng.Text = dr.GetString(0)
                txtDanWei.Text = dr.GetString(1)
            Catch ex As Exception
                MsgBox(Err.Description)
            End Try
        End While

        conn1.Close()

        Dim conn2 As SqlConnection = GetConnection()
        conn2.Open()
        Dim strSql2 As String = "Select 售价 from jgTable " _
                             & "Where 货品编号='" & txtBianHao.Text.Trim & "'"
        Dim comm2 As New SqlCommand(strSql2, conn2)
        Dim dr2 As SqlDataReader
        dr2 = comm2.ExecuteReader
        While dr2.Read
            Try
                txtDanJia.Text = dr2.GetString(0)
            Catch ex As Exception
                MsgBox(Err.Description)
            End Try
        End While

        conn2.Close()
    End Sub

    Private Sub txtDanJia_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtDanJia.TextChanged
        txtJinE.Text = Val(txtDanJia.Text) * Val(txtCount.Text)
    End Sub

   
    Private Sub txtCount_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtCount.TextChanged
        txtJinE.Text = Val(txtDanJia.Text) * Val(txtCount.Text)
    End Sub
End Class

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ngbshzhn

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值