FrmSupplier厂商管理

Imports System.Data
Imports System.Data.SqlClient
Public Class FrmSupplier
    Private Sub FrmSupplier_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim conn As New SqlConnection
        conn.ConnectionString = "data source=127.0.0.1;initial catalog=Supermarket;user=text;password=text"
        Dim sql As String
        sql = "select supplierid as 厂商ID,companyname as 厂商名称,phone as 电话,address as 地址 " _
                & "from suppliers order by supplierid"
        Dim adp As New SqlDataAdapter(sql, conn)
        Dim ds As New DataSet
        adp.Fill(ds, "a")
        Me.DataGrid1.DataSource = ds.Tables("a").DefaultView
    End Sub

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

    '    Dim conn As New SqlConnection
    '    conn.ConnectionString = "data source=127.0.0.1;initial catalog=Supermarket;user=text;password=text"
    '    conn.Open()
    '    Dim sql As String
    '    sql = "select companyname from suppliers  "
    '    Dim cmd As New SqlCommand(sql, conn)
    '    Dim ds As New DataSet
    '    Dim dr As SqlDataReader
    '    dr = cmd.ExecuteReader
    '    Do While dr.Read
    '        ComboBox1.Items.Add(Trim(dr.Item("suppliername")))
    '    Loop
    '    frmload()
    'End Sub
    Private Sub ButAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButAdd.Click
        Try
            If Me.Txtsupp.Text = "" Or Me.TextBox2.Text = "" Then
                MsgBox("厂商名和ID不能为空!")
                Exit Sub
            Else
            End If
            Dim yn As Integer
            yn = MsgBox("是否保存新增加的记录?", MsgBoxStyle.YesNo, "增加记录")
            If yn = 6 Then
                Dim conn As New SqlConnection
                conn.ConnectionString = "data source=127.0.0.1;initial catalog=Supermarket;user=text;password=text"
                Dim ds As New DataSet
                Dim mytable As New DataTable
                Dim sql As String
                sql = "insert into suppliers(supplierid,companyname,phone,address)values("
                sql &= "'" & Me.Txtsupp.Text & "','" & Me.TextBox2.Text & "'," & Me.TextBox3.Text & ",'" & Me.TextBox4.Text & "')"
                MsgBox("增加成功")
                Dim adp As New SqlDataAdapter(sql, conn)
                adp.Fill(ds, "a")
                Me.DataGrid1.DataSource = ds.Tables("a")
                FrmSupplier_Load(sender, e)
            ElseIf yn = 7 Then
            End If
        Catch ex As Exception
            ' MsgBox(ex.ToString)
        End Try
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            Dim mytable As New DataTable
            Dim conn As New SqlConnection
            Dim sql As String
            conn.ConnectionString = "data source=127.0.0.1;initial catalog=Supermarket;user=text;password=text;"
            If Me.Txtsupp.Text = "" Then
                MsgBox("请输入条件")
            Else
                sql = "select supplierid as 厂商ID ,companyname as 厂商名称,address as 厂商地址,phone as  厂商电话 " _
                & "from suppliers  where  supplierid ='" & Me.Txtsupp.Text & "'"
                Dim adp As New SqlDataAdapter(sql, conn)
                Dim ds As New DataSet
                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 ButEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButEdit.Click
        Try
            Dim yn As Integer
            yn = MsgBox("是否修改记录?", MsgBoxStyle.YesNo, "修改记录")
            If yn = 6 Then
                Dim conn As New SqlConnection
                conn.ConnectionString = "data source=127.0.0.1;initial catalog=Supermarket;user=text;password=text"
                Dim myset As New DataSet
                Dim mytable As New DataTable
                Dim sql As String
                sql = "update suppliers set companyname='" & Me.TextBox2.Text & "',phone='" & Me.TextBox3.Text & "',address='" & Me.TextBox4.Text & "'where supplierid='" & Me.Txtsupp.Text & "'"
                Dim mydata As New SqlDataAdapter(sql, conn)
                MsgBox("修改成功 ")
                mydata.Fill(myset, "a")
                DataGrid1.DataSource = myset.Tables("a")
                FrmSupplier_Load(sender, e)
            Else
            End If
        Catch ex As Exception
            ' MsgBox(ex.ToString)
        End Try
    End Sub

    Private Sub ButDel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButDel.Click
        Try
            Dim yn As Integer
            yn = MsgBox("是否删除记录?", MsgBoxStyle.YesNo, "删除记录")
            If yn = 6 Then
                Dim conn As New SqlConnection
                conn.ConnectionString = "data source=127.0.0.1;initial catalog=Supermarket;user=text;password=text"

                Dim myset As New DataSet
                Dim mytable As New DataTable
                Dim sql As String
                sql = "delete from suppliers where supplierid='" & Me.Txtsupp.Text & "'"
                Me.Txtsupp.Text = ""
                Me.TextBox4.Text = ""
                Me.TextBox3.Text = ""
                Me.TextBox2.Text = ""
                MsgBox("记录删除成功")
                Dim mydata As New SqlDataAdapter(sql, conn)
                mydata.Fill(myset, "a")
                Me.DataGrid1.DataSource = myset.Tables("a")
                FrmSupplier_Load(sender, e)
            ElseIf yn = 7 Then
                FrmSupplier_Load(sender, e)
            End If
        Catch ex As Exception

        End Try
    End Sub
    Private Sub DataGrid1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.Click
        Try
            Me.Txtsupp.Text = DataGrid1.Item(DataGrid1.CurrentCell.RowNumber, 0)
            Me.TextBox2.Text = DataGrid1.Item(DataGrid1.CurrentCell.RowNumber, 1)
            Me.TextBox4.Text = DataGrid1.Item(DataGrid1.CurrentCell.RowNumber, 2)
            Me.TextBox3.Text = DataGrid1.Item(DataGrid1.CurrentCell.RowNumber, 3)

        Catch ex As Exception

        End Try

    End Sub
End Class 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值