📄 form1.vb
字号:
Me.Controls.Add(Me.Button4)
Me.Controls.Add(Me.Button3)
Me.Controls.Add(Me.Button2)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.ComboBox2)
Me.Controls.Add(Me.ComboBox1)
Me.Controls.Add(Me.TextBox4)
Me.Controls.Add(Me.TextBox3)
Me.Controls.Add(Me.TextBox2)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.Label6)
Me.Controls.Add(Me.Label5)
Me.Controls.Add(Me.Label4)
Me.Controls.Add(Me.Label3)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.DataGrid1)
Me.Font = New System.Drawing.Font("宋体", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.MaximizeBox = False
Me.Name = "Form1"
Me.StartPosition = System.Windows.Forms.FormStartPosition.Manual
Me.Text = "房源信息"
Me.TopMost = True
CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).EndInit()
CType(Me.Ds1, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Try
If Button5.Text = "添加" Then
Me.BindingContext(Ds1, "房源库").AddNew()
Button5.Text = "确定"
Button6.Enabled = False
Button7.Enabled = False
Button8.Enabled = False
Button10.Enabled = False
Else
If Button5.Text <> "确定" Then
Exit Sub
End If
Me.BindingContext(Ds1, "房源库").EndCurrentEdit()
OleDbDataAdapter1.Update(Ds1.房源库)
MsgBox("添加成功!")
Button5.Text = "添加"
Button6.Enabled = True
Button7.Enabled = True
Button8.Enabled = True
Button10.Enabled = True
Me.TxtLocation.Text = (((Me.BindingContext(Ds1, "房源库").Position + 1).ToString + _
"/") + Me.BindingContext(Ds1, "房源库").Count.ToString)
Me.DataGrid1.Select(DataGrid1.CurrentRowIndex)
End If
Catch ex As Exception
If Err.Number = 5 Then
MsgBox("已有相同的记录存在!")
Else
MsgBox(ex.Message)
End If
End Try
End Sub
Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
Try
OleDbDataAdapter1.SelectCommand.CommandText = "Select * from 房源库"
Ds1.Clear()
OleDbDataAdapter1.Fill(Ds1)
Me.DataGrid1.Select(DataGrid1.CurrentRowIndex)
Me.TxtLocation.Text = (((Me.BindingContext(Ds1, "房源库").Position + 1).ToString + _
"/") + Me.BindingContext(Ds1, "房源库").Count.ToString)
Catch ex As Exception
MsgBox("数据库中无您所需数据!")
End Try
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
OleDbDataAdapter1.SelectCommand.CommandText = "Select * from 房源库"
Ds1.Clear()
OleDbDataAdapter1.Fill(Ds1)
Me.DataGrid1.Select(DataGrid1.CurrentRowIndex)
Me.TxtLocation.Text = (((Me.BindingContext(Ds1, "房源库").Position + 1).ToString + _
"/") + Me.BindingContext(Ds1, "房源库").Count.ToString)
Catch ex As Exception
MsgBox("数据库中无数据!")
End Try
' Dim F As New 提示二
' F.Hide()
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
Try
If MsgBox("真的要删除此记录?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
Ds1.房源库.Rows(Me.BindingContext(Ds1, "房源库").Position).Delete()
OleDbDataAdapter1.Update(Ds1)
Me.TxtLocation.Text = (((Me.BindingContext(Ds1, "房源库").Position + 1).ToString + _
"/") + Me.BindingContext(Ds1, "房源库").Count.ToString)
Me.DataGrid1.Select(DataGrid1.CurrentRowIndex)
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
Try
Me.BindingContext(Ds1, "房源库").EndCurrentEdit()
If Ds1.HasChanges(DataRowState.Modified) Then
OleDbDataAdapter1.Update(Ds1)
MsgBox("更新成功!")
End If
Catch
End Try
End Sub
Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
Me.BindingContext(Ds1, "房源库").CancelCurrentEdit()
Button5.Text = "添加"
Button6.Enabled = True
Button7.Enabled = True
Button8.Enabled = True
Button10.Enabled = True
End Sub
Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
Me.Close()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Me.BindingContext(Ds1, "房源库").Count = 0 Then
Exit Sub
End If
Me.DataGrid1.UnSelect(DataGrid1.CurrentRowIndex)
Me.BindingContext(Ds1, "房源库").Position = 0
Me.TxtLocation.Text = (((Me.BindingContext(Ds1, "房源库").Position + 1).ToString + _
"/") + Me.BindingContext(Ds1, "房源库").Count.ToString)
Me.DataGrid1.Select(DataGrid1.CurrentRowIndex)
Me.DataGrid1.Select(DataGrid1.CurrentRowIndex)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If Me.BindingContext(Ds1, "房源库").Count = 0 Then
Exit Sub
End If
If Me.BindingContext(Ds1, "房源库").Position > 0 Then
Me.BindingContext(Ds1, "房源库").Position = (Me.BindingContext(Ds1, "房源库").Position - 1)
Me.TxtLocation.Text = (((Me.BindingContext(Ds1, "房源库").Position + 1).ToString + _
"/") + Me.BindingContext(Ds1, "房源库").Count.ToString)
Me.DataGrid1.Select(DataGrid1.CurrentRowIndex)
End If
DataGrid1.UnSelect(DataGrid1.CurrentRowIndex + 1)
Me.DataGrid1.Select(DataGrid1.CurrentRowIndex)
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
If Me.BindingContext(Ds1, "房源库").Count = 0 Then
Exit Sub
End If
Dim i As Integer
i = Me.BindingContext(Ds1, "房源库").Count - 1
If Me.BindingContext(Ds1, "房源库").Position < i Then
Me.BindingContext(Ds1, "房源库").Position += 1
Me.TxtLocation.Text = (((Me.BindingContext(Ds1, "房源库").Position + 1).ToString + _
"/") + Me.BindingContext(Ds1, "房源库").Count.ToString)
Me.DataGrid1.Select(DataGrid1.CurrentRowIndex)
End If
DataGrid1.UnSelect(DataGrid1.CurrentRowIndex - 1)
Me.DataGrid1.Select(DataGrid1.CurrentRowIndex)
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
If Me.BindingContext(Ds1, "房源库").Count = 0 Then
Exit Sub
End If
Me.DataGrid1.UnSelect(DataGrid1.CurrentRowIndex)
Me.BindingContext(Ds1, "房源库").Position = Me.BindingContext(Ds1, "房源库").Count - 1
Me.TxtLocation.Text = (((Me.BindingContext(Ds1, "房源库").Position + 1).ToString + _
"/") + Me.BindingContext(Ds1, "房源库").Count.ToString)
Me.DataGrid1.Select(DataGrid1.CurrentRowIndex)
Me.DataGrid1.Select(DataGrid1.CurrentRowIndex)
End Sub
Private Sub DataGrid1_Navigate(ByVal sender As System.Object, ByVal ne As System.Windows.Forms.NavigateEventArgs) Handles DataGrid1.Navigate
End Sub
Private Sub Form1_VisibleChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.VisibleChanged
Dim FK As New 提示
FK.Close()
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -