📄 frmcustomer.vb
字号:
txtPhone.Text = ""
txtFax.Text = ""
txtDescr.Text = ""
btnUpdate.Enabled = False
btnDel.Enabled = False
strCommand = "add"
End Sub
Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
If strCommand = "add" Then
If cboCustomerType.Text = "" Or txtCustomerName.Text.Trim = "" Or txtBankName.Text.Trim = "" Or txtBankAccount.Text.Trim = "" Or txtZipCode.Text = "" Or txtAddress.Text = "" Or txtPhone.Text = "" Or txtContactName.Text = "" Then
MsgBox("请填写完整的信息", MsgBoxStyle.Exclamation)
Exit Sub
End If
Dim STRSQL = "SELECT * FROM CUSTOMER WHERE CustomerName='" & txtCustomerName.Text.Trim() & "'"
myDataObj.ExecuteSQL(STRSQL, drSqlServer)
If drSqlServer.Read() Then
MsgBox("此仓库已存在", MsgBoxStyle.Exclamation)
GroupBox2.Enabled = True
txtCustomerID.Text = ""
txtCustomerName.Text = ""
cboCustomerType.SelectedIndex = 0
txtBankName.Text = ""
txtBankAccount.Text = ""
txtContactName.Text = ""
txtZipCode.Text = ""
txtAddress.Text = ""
txtPhone.Text = ""
txtFax.Text = ""
txtDescr.Text = ""
drSqlServer.Close()
Else
drSqlServer.Close()
Dim Params() As SqlParameter = _
{New SqlParameter("@CustomerName", SqlDbType.VarChar), _
New SqlParameter("@CustomerType", SqlDbType.NChar), _
New SqlParameter("@BankName", SqlDbType.VarChar), _
New SqlParameter("@BankAccount", SqlDbType.VarChar), _
New SqlParameter("@ContactName", SqlDbType.VarChar), _
New SqlParameter("@Address", SqlDbType.VarChar), _
New SqlParameter("@ZipCode", SqlDbType.NChar), _
New SqlParameter("@Phone", SqlDbType.VarChar), _
New SqlParameter("@Fax", SqlDbType.VarChar), _
New SqlParameter("@Descr", SqlDbType.VarChar)}
Params(0).Value = txtCustomerName.Text.Trim()
Params(1).Value = cboCustomerType.Text.Trim()
Params(2).Value = txtBankName.Text.Trim()
Params(3).Value = txtBankAccount.Text.Trim()
Params(4).Value = txtContactName.Text.Trim()
Params(5).Value = txtAddress.Text.Trim()
Params(6).Value = txtZipCode.Text.Trim()
Params(7).Value = txtPhone.Text.Trim()
Params(8).Value = txtFax.Text.Trim()
Params(9).Value = txtDescr.Text.Trim()
myDataObj.ExecuteSP("sp_InsertCustomer", Params)
MsgBox("添加完毕", MsgBoxStyle.Information)
End If
ElseIf strCommand = "update" Then
Dim Params() As SqlParameter = _
{New SqlParameter("@CustomerID", SqlDbType.Int), _
New SqlParameter("@CustomerName", SqlDbType.VarChar), _
New SqlParameter("@CustomerType", SqlDbType.NChar), _
New SqlParameter("@BankName", SqlDbType.VarChar), _
New SqlParameter("@BankAccount", SqlDbType.VarChar), _
New SqlParameter("@ContactName", SqlDbType.VarChar), _
New SqlParameter("@Address", SqlDbType.VarChar), _
New SqlParameter("@ZipCode", SqlDbType.NChar), _
New SqlParameter("@Phone", SqlDbType.VarChar), _
New SqlParameter("@Fax", SqlDbType.VarChar), _
New SqlParameter("@Descr", SqlDbType.VarChar)}
params(0).Value = txtCustomerID.Text.Trim()
Params(1).Value = txtCustomerName.Text.Trim()
Params(2).Value = cboCustomerType.Text.Trim()
Params(3).Value = txtBankName.Text.Trim()
Params(4).Value = txtBankAccount.Text.Trim()
Params(5).Value = txtContactName.Text.Trim()
Params(6).Value = txtAddress.Text.Trim()
Params(7).Value = txtZipCode.Text.Trim()
Params(8).Value = txtPhone.Text.Trim()
Params(9).Value = txtFax.Text.Trim()
Params(10).Value = txtDescr.Text.Trim()
myDataObj.ExecuteSP("sp_UpdateCustomer", Params)
MsgBox("更新完毕", MsgBoxStyle.Information)
Else
Me.Close()
End If
GroupBox2.Enabled = False
btnAdd.Enabled = True
btnUpdate.Enabled = True
btnDel.Enabled = True
strCommand = ""
freshData()
End Sub
Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
GroupBox2.Enabled = True
btnAdd.Enabled = False
btnDel.Enabled = False
strCommand = "update"
End Sub
Private Sub dgCustomer_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles dgCustomer.Click
showData()
End Sub
Private Sub btnDel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDel.Click
If MsgBox("确定要删除记录:" & txtCustomerID.Text & "?", MsgBoxStyle.OKCancel) = MsgBoxResult.OK Then
Dim Params() As SqlParameter = {New SqlParameter("@CustomerID", SqlDbType.Int)}
Params(0).Value = txtCustomerID.Text.Trim()
myDataObj.ExecuteSP("sp_DelCustomer", Params)
Dim strSQL = "SELECT * FROM CUSTOMER WHERE CUSTOMERID='" & Params(0).Value & "'"
myDataObj.ExecuteSQL(strSQL, drSqlServer)
If drSqlServer.Read() Then
MsgBox("此客户已在其它地方存在记录,不可删除!", MsgBoxStyle.Information)
Else
MsgBox("删除完毕", MsgBoxStyle.Information)
End If
drSqlServer.Close()
freshData()
End If
End Sub
Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
If strCommand = "add" Then
txtCustomerID.Text = ""
txtCustomerName.Text = ""
cboCustomerType.SelectedIndex = 0
txtBankName.Text = ""
txtBankAccount.Text = ""
txtContactName.Text = ""
txtZipCode.Text = ""
txtAddress.Text = ""
txtPhone.Text = ""
txtFax.Text = ""
txtDescr.Text = ""
btnAdd.Enabled = True
btnUpdate.Enabled = True
btnDel.Enabled = True
GroupBox2.Enabled = False
strCommand = ""
ElseIf strCommand = "update" Then
btnAdd.Enabled = True
btnUpdate.Enabled = True
btnDel.Enabled = True
GroupBox2.Enabled = False
strCommand = ""
Else
Me.Close()
End If
End Sub
Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
strSQL = "SELECT * FROM Customer WHERE CustomerName like '%" & txtOrderbyName.Text.Trim & "%'"
freshData()
End Sub
Private Sub cboOrderbyType_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboOrderbyType.SelectedIndexChanged
If cboOrderbyType.SelectedIndex = 0 Then
strSQL = "SELECT * FROM Customer"
Else
strSQL = "SELECT * FROM Customer WHERE CustomerType='" & cboOrderbyType.Text & "'"
End If
freshData()
End Sub
Private Sub dgCustomer_Navigate(ByVal sender As System.Object, ByVal ne As System.Windows.Forms.NavigateEventArgs) Handles dgCustomer.Navigate
End Sub
Private Sub txtBankAccount_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtBankAccount.TextChanged
End Sub
Private Sub txtBankAccount_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtBankAccount.LostFocus
Dim i As Integer
txtBankAccount.Text = Trim(txtBankAccount.Text)
If txtBankAccount.Text = "" Then
Exit Sub
End If
Try
i = CDbl(txtBankAccount.Text)
Catch
MsgBox("只能是0-9之间的数字组成", MsgBoxStyle.Information)
txtBankAccount.Text = ""
txtBankAccount.Focus()
Exit Sub
End Try
End Sub
Private Sub txtZipCode_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtZipCode.TextChanged
End Sub
Private Sub txtZipCode_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtZipCode.LostFocus
Dim i As Integer
txtZipCode.Text = Trim(txtZipCode.Text)
If txtZipCode.Text = "" Then
Exit Sub
End If
Try
i = CDbl(txtZipCode.Text)
Catch
MsgBox("只能是0-9之间的数字组成", MsgBoxStyle.Information)
txtZipCode.Text = ""
txtZipCode.Focus()
Exit Sub
End Try
End Sub
Private Sub txtPhone_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtPhone.TextChanged
End Sub
Private Sub txtPhone_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtPhone.LostFocus
Dim i As Integer
txtPhone.Text = Trim(txtPhone.Text)
If txtPhone.Text = "" Then
Exit Sub
End If
Try
i = CDbl(txtPhone.Text)
Catch
MsgBox("只能是0-9之间的数字组成", MsgBoxStyle.Information)
txtPhone.Text = ""
txtPhone.Focus()
Exit Sub
End Try
End Sub
Private Sub txtFax_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtFax.TextChanged
End Sub
Private Sub txtFax_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtFax.LostFocus
Dim i As Integer
txtFax.Text = Trim(txtFax.Text)
If txtFax.Text = "" Then
Exit Sub
End If
Try
i = CDbl(txtFax.Text)
Catch
MsgBox("只能是0-9之间的数字组成", MsgBoxStyle.Information)
txtFax.Text = ""
txtFax.Focus()
Exit Sub
End Try
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -