前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >VB.NET 日常开销记账本示例

VB.NET 日常开销记账本示例

作者头像
一线编程
发布2019-07-22 14:45:44
7810
发布2019-07-22 14:45:44
举报
文章被收录于专栏:办公魔盒办公魔盒办公魔盒

应某粉丝,要求弄得一个记账本示例程序

'-------------------------------------------------------------------------------

'主页源码'

Dim UI As New cls_UI

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

UI.ShowForm(浏览, Me)

End Sub

Private Sub Form1_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Closed

Login.Close()

浏览.Close()

添加.Close()

End Sub

Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click

UI.ShowForm(浏览, Me)

End Sub

Private Sub into_data_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles into_data.Click

UI.ShowForm(添加, Me)

End Sub

'----------------------------------------------------------------------

'登录页源码'

Dim CN As New cls_accdb

Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click

Dim dt, dt1 As DataTable

Dim TF, TF1 As Boolean

dt = CN.get_data("Select 用户名 From users Where 用户名='" & UsernameTextBox.Text & "'")

dt1 = CN.get_data("Select 密码 From users Where 用户名='" & UsernameTextBox.Text & "' AND 密码='" & PasswordTextBox.Text & "'")

If dt.Rows.Count > 0 Then TF = True

If dt1.Rows.Count > 0 Then TF1 = True

If UsernameTextBox.Text <> "" And PasswordTextBox.Text <> "" Then

If TF = True And TF1 = True Then

主页.Show()

Me.Visible = False

Else

UsernameTextBox.Text = ""

PasswordTextBox.Text = ""

MsgBox("密码错误!", MsgBoxStyle.Critical, "VB小源码")

End If

End If

End Sub

Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click

Me.Close()

End Sub

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

UsernameTextBox.Focus()

End Sub

Private Sub UsernameTextBox_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles UsernameTextBox.KeyUp

If e.KeyCode = Keys.Enter Then

PasswordTextBox.Focus()

End If

End Sub

End Class

'--------------------------------------------------------------------------------------------'

'access数据库操作源码类'

Imports System.Data

Imports System.IO

Imports System.Data.OleDb

Public Class cls_accdb

Public cn As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.StartupPath & "\mdb\DataSource.mdb") '定义连接---这里请更改为实际数据库路径及名称

Public DataBaseRST As Integer

Public Function DataModify(ByVal str As String) As Boolean

Dim cmdinsert As New OleDbCommand

Try

cmdinsert.CommandText = str

cmdinsert.Connection = cn

If cn.State = ConnectionState.Closed Then cn.Open()

DataBaseRST = cmdinsert.ExecuteNonQuery()

cn.Close()

Return True

Catch ex As Exception

MessageBox.Show(Err.Description, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)

Return False

End Try

End Function

Public Function get_data(ByVal str As String) As DataTable

Dim tb As New DataTable

Try

Dim ap As New OleDb.OleDbDataAdapter(str, cn)

ap.Fill(tb)

Return tb

Catch ex As Exception

MessageBox.Show(Err.Description, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)

Return tb

End Try

End Function

End Class

'--------------------------------------------------------------------------------------------------'

''查询也源码

Public Class 浏览

Dim cn As New cls_accdb

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

dgv.DataSource = cn.get_data("Select * From outdata")

End Sub

Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles out_menoy.Click

If OUT_TXT.Text = "" Or OUT_TXT.Text = "输入日期" Then

dgv.DataSource = cn.get_data("Select * From outdata")

Else

dgv.DataSource = cn.get_data("Select * From outdata where 日期 like '%" & OUT_TXT.Text & "%'")

End If

End Sub

Private Sub in_menoy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles in_menoy.Click

If OUT_TXT.Text = "" Or OUT_TXT.Text = "输入日期" Then

dgv.DataSource = cn.get_data("Select * From indata")

Else

dgv.DataSource = cn.get_data("Select * From indata where 日期 like '%" & OUT_TXT.Text & "%'")

End If

End Sub

Private Sub ToolStrip1_ItemClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolStripItemClickedEventArgs) Handles ToolStrip1.ItemClicked

End Sub

Private Sub DGv_CellFormatting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles dgv.CellFormatting

If dgv.Columns(e.ColumnIndex).Name = "是否超额" Then

If Not (e.Value Is Nothing) Then

If Not e.Value Is DBNull.Value Then

If e.Value = "是" Then

e.CellStyle.BackColor = Color.Red

End If

End If

End If

End If

End Sub

Private Sub ToolStripButton1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click

On Error Resume Next

Dim dt As DataTable

dt = cn.get_data("Select SUM(合计) From indata")

MsgBox("总收入 " & dt.Rows(0)(0) & " 大洋", MsgBoxStyle.Information, "VB小源码")

End Sub

Private Sub ToolStripButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton2.Click

On Error Resume Next

Dim dt As DataTable

dt = cn.get_data("Select SUM(合计) From outdata")

MsgBox("总支出 " & dt.Rows(0)(0) & " 大洋", MsgBoxStyle.Information, "VB小源码")

End Sub

End Class

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2018-12-07,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 办公魔盒 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档