Visual Basic 2010 数据库开发之销售管理系统06客户信息设置

拖入“客户信息TableAdapter”,命名为CustomerTableAdapter

打开“数据集设计器”,在客户信息中添加查询

下一步至完成

同样加一个UpdateQuery

UPDATE  客户信息
SET         客户地址 = @客户地址, 邮编 = @邮编, 联系电话 = @联系电话, 职务 = @职务, 业务员 = @业务员, 开户行 = @开户行,  账号 = @账号, 备注 = @备注
WHERE   (客户姓名 = @客户姓名)

和一个Select查询,命名为FillByCondition

SELECT 客户姓名, 客户地址, 邮编, 联系电话, 职务, 业务员, 开户行, 账号, 备注 
FROM 客户信息
WHERE 客户姓名=@客户姓名
Imports System.Data.SqlClient
Imports 销售管理系统.xiaoshouxtDataSet
Imports 销售管理系统.xiaoshouxtDataSetTableAdapters
Public Class frmCustomer
    Private Sub SetControlDisable()
        GroupBox1.Enabled = False
    End Sub
    Private Sub SetControlEnable()
        GroupBox1.Enabled = True
    End Sub
    Private Sub SetControlEmpty()
        txtName.Text = ""
        txtAddress.Text = ""
        txtPostCode.Text = ""
        txtZhiWu.Text = ""
        txtPhone.Text = ""
        cmbYeWuYuan.Text = ""
        txtBank.Text = ""
        txtBankNum.Text = ""
        txtMemo.Text = ""
    End Sub
    Private Sub SetControlDebug()
        txtName.Text = ""
        txtAddress.Text = "北京"
        txtPostCode.Text = "000001"
        txtPhone.Text = "234923049"
        txtZhiWu.Text = "处长"
        cmbYeWuYuan.Text = "李雷"
        txtBank.Text = "很行银行"
        txtBankNum.Text = "982572340903"
        txtMemo.Text = "编的不太好"
    End Sub

    Dim dt As 客户信息DataTable
    Dim dv As DataView
    Dim bmdata As CurrencyManager
    Private Sub FillDataAndView()
        dt = New 客户信息DataTable
        CustomerTableAdapter1.Fill(dt)
        dv = New DataView(dt)
        bmdata = Me.BindingContext(dv)
    End Sub
    Private Sub bindFields()
        txtName.DataBindings.Clear()
        txtAddress.DataBindings.Clear()
        txtPostCode.DataBindings.Clear()
        txtPhone.DataBindings.Clear()
        txtZhiWu.DataBindings.Clear()
        cmbYeWuYuan.DataBindings.Clear()
        txtBank.DataBindings.Clear()
        txtBankNum.DataBindings.Clear()
        txtMemo.DataBindings.Clear()

        txtName.DataBindings.Add("text", dv, "客户姓名")
        txtAddress.DataBindings.Add("text", dv, "客户地址")
        txtPostCode.DataBindings.Add("text", dv, "邮编")
        txtPhone.DataBindings.Add("text", dv, "联系电话")
        txtZhiWu.DataBindings.Add("text", dv, "职务")
        cmbYeWuYuan.DataBindings.Add("text", dv, "业务员")
        txtBank.DataBindings.Add("text", dv, "开户行")
        txtBankNum.DataBindings.Add("text", dv, "账号")
        txtMemo.DataBindings.Add("text", dv, "备注")
    End Sub
    Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
        Dim intIndex As Integer = e.RowIndex
        txtName.Text = DataGridView1.Rows(intIndex).Cells(0).Value
        txtAddress.Text = DataGridView1.Rows(intIndex).Cells(1).Value
        txtPostCode.Text = DataGridView1.Rows(intIndex).Cells(2).Value
        txtPhone.Text = DataGridView1.Rows(intIndex).Cells(3).Value
        cmbYeWuYuan.Text = DataGridView1.Rows(intIndex).Cells(4).Value
        txtBank.Text = DataGridView1.Rows(intIndex).Cells(5).Value
        txtBankNum.Text = DataGridView1.Rows(intIndex).Cells(6).Value
        txtMemo.Text = DataGridView1.Rows(intIndex).Cells(7).Value
    End Sub

    Private Sub frmCustomer_Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Disposed
        Me.Close()
        frmMain.Show()
    End Sub


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

        FillDataAndView()
        bindFields()

        lblcounts.Text = dt.Rows.Count
        DataGridView1.DataSource = dt

        txtCondition.Text = "张曼玉"
    End Sub

    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        flag = "add"
        SetControlEnable()
        SetControlDebug()
    End Sub

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

    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        If flag = "add" Then
            CustomerTableAdapter1.Insert(txtName.Text, txtAddress.Text, txtPostCode.Text, txtZhiWu.Text, txtPhone.Text, cmbYeWuYuan.Text, txtBank.Text, txtBankNum.Text, txtMemo.Text)

        ElseIf flag = "modify" Then
            CustomerTableAdapter1.UpdateQuery(txtAddress.Text, txtPostCode.Text, txtZhiWu.Text, txtPhone.Text, cmbYeWuYuan.Text, txtBank.Text, txtBankNum.Text, txtMemo.Text, txtName.Text)
        Else
            Exit Sub
        End If
        SetControlDisable()

        FillDataAndView()
        bindFields()

        DataGridView1.DataSource = dt
    End Sub

    Private Sub btnDel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDel.Click
        Dim intposition As Integer = bmdata.Position
        If MessageBox.Show("确定删除吗?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Stop) = DialogResult.Yes Then
            CustomerTableAdapter1.DeleteQuery(txtName.Text)
        End If

        FillDataAndView()
        bindFields()

        DataGridView1.DataSource = dt
    End Sub

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

    Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
        frmCustomerReport.Show()
    End Sub

    Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
        Dim dtFind As New 客户信息DataTable
        CustomerTableAdapter1.FillByCondition(dtFind, txtCondition.Text)
        lblcounts.Text = dtFind.Rows.Count
        DataGridView1.DataSource = dtFind
    End Sub

    Private Sub btnRef_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRef.Click
        frmCustomer_Load(sender, e)
    End Sub
End Class

 

  • 0
    点赞
  • 0
    收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

ngbshzhn

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

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

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

打赏作者

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

抵扣说明:

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

余额充值