C#实现个人理财软件小项目

发布时间:2024-11-21 10:41

使用云财务软件如FreshBooks进行项目管理 #生活技巧# #财务管理技巧# #财务软件#

GitHub:https://github.com/Knock-man/PersonalFinanceSystem

个人理财小软件 一、数据库设计(MySQL)二、窗体设计(一)登录窗体(二)主界面窗体(三)收支管理窗体(四)统计查询窗体(五)添加收支项目窗体(六)用户管理窗体(七)关于窗体

一、数据库设计(MySQL)

数据库名称:BillManagement
关系模式设计:

收支表(收支编号,收支类型,日期,收支人,金额,说明,类别编号) incomeAndExpenses(InExId,InType,InDate,Person,Money,Explain,CateId) 收支类别(类别编号,收支类型,类别名称) Category(CateId,CaType,CaName) 收支项目(项目编号,类别编号,项目名称) Project(ProId,CateId,ProName) 用户表(用户编号,用户名,用户密码) UserBill(UserId,UserName,UserPassWord) 1234567891011

建表

#建库 CREATE DATABASE IF NOT EXISTS BillManagement; #建Category(CateId,CaType,CaName)表 CREATE TABLE IF NOT EXISTS Category(CateId INT NOT NULL AUTO_INCREMENT,CaType CHAR(10),CaName CHAR(10),PRIMARY KEY(CateId) ) #建incomeAndExpenses(InExId,InType,InDate,Person,Money,CateId)表 CREATE TABLE IF NOT EXISTS incomeAndExpenses(InExId INT NOT NULL AUTO_INCREMENT,InType CHAR(10),InDate DATE,Person CHAR(10),Money CHAR(10),InExplain CHAR(10),CateId INT,PRIMARY KEY (InExId),FOREIGN KEY(CateId) REFERENCES Category(CateId) ) #建Project(ProId,CateId,ProName)表 CREATE TABLE IF NOT EXISTS Project(ProId INT NOT NULL AUTO_INCREMENT,CateId INT,ProName CHAR(10),PRIMARY KEY(ProId),FOREIGN KEY (CateId) REFERENCES Category(CateId) ) #建UserBill(UserId,UserName,UserPassWord)表 CREATE TABLE IF NOT EXISTS UserBill(UserId INT NOT NULL AUTO_INCREMENT,UserName CHAR(10),UserPassWord CHAR(10),PRIMARY KEY(UserId) )

123456789101112131415161718192021222324252627282930313233343536

二、窗体设计

窗体控件字典:

用户名:userName 密码:passWord 验证码:verificationCode 收入类型-收入:shouRU 收入类型-支出:zhiCu 收入类别:shouRuLeiBie 备注:beiZhu 日期:rQ 说明:shuoMing 收支项目:shouZhiXiangMu 12345678910

(一)登录窗体

在这里插入图片描述
逻辑代码:

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using MySql.Data.MySqlClient; namespace PersonalFinanceSystem { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button2_Click(object sender, EventArgs e) { if (userName.Text != ""||passWord.Text!=""||verificationCode.Text!="") { userName.Text = ""; passWord.Text = ""; verificationCode.Text = ""; } } private void button3_Click(object sender, EventArgs e) { this.Close(); } private void userName_TextChanged(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { #region 连接数据库 //定义连接字符串 string connStr = "Database=BillManagement;Data Source=127.0.0.1;port=3306;User Id=root;"; MySqlConnection conn = new MySqlConnection(connStr);//创建Connection对象 conn.Open();//打开数据库 #endregion #region 查询 //验空 if (userName.Text == "") { MessageBox.Show("用户名不能为空", "用户登录", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } else if (passWord.Text == "") { MessageBox.Show("密码不能为空", "用户登录", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } else if (verificationCode.Text == "") { MessageBox.Show("验证不能为空", "用户登录", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } else if (verificationCode.Text != label5.Text) { MessageBox.Show("验证码错误,请重新输入", "用户登录", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); }else{ //创建命令 string username = userName.Text;//获取输入用户名 string password = passWord.Text;//获取输入密码 string sqlSel = "select count(*) from UserBill where UserName = '" + username + "' and UserPassWord = '" + password + "'";//查询语句 MySqlCommand com = new MySqlCommand(sqlSel, conn); //判断executeScalar方法返回的参数是否大于0,大于0表示查找有数据 if (Convert.ToInt32(com.ExecuteScalar()) > 0) { MessageBox.Show("欢迎加入个人理财系!", "登录成功", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); homepage home = new homepage(); this.Hide(); home.Show(); } else { MessageBox.Show("账户或者密码错误!请重新输入", "用户登录", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } #endregion } } private void Form1_Load(object sender, EventArgs e) { //this.IsMdiContainer = true; Random rd = new Random(); label5.Text =Convert.ToString(rd.Next(1000, 10000)); } private void label5_Click(object sender, EventArgs e) { } } }

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105

(二)主界面窗体

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述在这里插入图片描述

逻辑代码:

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace PersonalFinanceSystem { public partial class homepage : Form { public homepage() { InitializeComponent(); } private void homepage_Load(object sender, EventArgs e) { this.IsMdiContainer = true; } private void toolStripButton1_Click(object sender, EventArgs e) { incomeExpenditure stu = new incomeExpenditure(); stu.Show(); } private void 收支管理ToolStripMenuItem_Click(object sender, EventArgs e) { } private void 添加收支PCtrlPToolStripMenuItem_Click(object sender, EventArgs e) { incomeExpenditure stu = new incomeExpenditure(); stu.Show(); } private void 退出XCtrlXToolStripMenuItem_Click(object sender, EventArgs e) { this.Hide(); Form1 stu = new Form1(); stu.Show(); } private void 添加收支项目ICtrlIToolStripMenuItem_Click(object sender, EventArgs e) { InExaccount stu = new InExaccount(); stu.Show(); } private void 关于ACtrlAToolStripMenuItem_Click(object sender, EventArgs e) { aboutUs stu = new aboutUs(); stu.Show(); } private void 统计查询CCtrlCToolStripMenuItem_Click(object sender, EventArgs e) { statisticalQuery stu = new statisticalQuery(); stu.Show(); } private void toolStripButton2_Click(object sender, EventArgs e) { statisticalQuery stu = new statisticalQuery(); stu.Show(); } private void toolStripButton3_Click(object sender, EventArgs e) { InExaccount stu = new InExaccount(); stu.Show(); } private void 用户管理UCtrlUToolStripMenuItem_Click(object sender, EventArgs e) { userManagement stu = new userManagement(); stu.Show(); } private void toolStripButton4_Click(object sender, EventArgs e) { userManagement stu = new userManagement(); stu.Show(); } } }

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091

(三)收支管理窗体

在这里插入图片描述

逻辑代码:

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using MySql.Data.MySqlClient; namespace PersonalFinanceSystem { public partial class incomeExpenditure : Form { public incomeExpenditure() { InitializeComponent(); } private void checkBox4_CheckedChanged(object sender, EventArgs e) { chenge(); } private void button1_Click(object sender, EventArgs e) { #region 连接数据库 //定义连接字符串 string connStr = "Database=BillManagement;Data Source=127.0.0.1;port=3306;User Id=root;"; MySqlConnection conn = new MySqlConnection(connStr);//创建Connection对象 conn.Open();//打开数据库 #endregion //获取收入类型 string shouruleixing=""; if (shouRu.Checked) { shouruleixing = "0"; } else { shouruleixing = "1"; } //获取收入类别 string shouruleibie = ""; if (shouRuLeiBie.SelectedIndex != -1) { shouruleibie = shouRuLeiBie.SelectedItem.ToString(); } else { shouRuLeiBie.SelectedIndex = 0; } //获取类别编号 MySqlCommand cmd2 = new MySqlCommand("SELECT CateId FROM category WHERE CaName = @lb", conn); cmd2.Parameters.AddWithValue("lb", shouruleibie); MySqlDataReader reader2 = cmd2.ExecuteReader();//创建MySqlDataReader对象 int liebieid = 0; while (reader2.Read())//每次读一行显示在集合中 { liebieid = Convert.ToInt32(reader2[0]); } reader2.Close(); //获取日期 string date = ""; if (rQ.SelectedIndex != -1) { date = rQ.SelectedItem.ToString(); } else { rQ.SelectedIndex = 0; } //获取说明 string shuoming = ""; shuoming = shuoMing.Text; //获取收支人 string shouzhiren = ""; CheckBox[] person = new CheckBox[] { My, Family, Relative, Friend, Classmate, Other }; for (int i = 0; i < person.Length; i++) { if (person[i].Checked) { shouzhiren += person[i].Text + " "; } } //获取金额 string jiner = ""; jiner = jinEr.Text; //导入数据表 #region 插入 MySqlCommand cmdd = new MySqlCommand("insert into incomeAndExpenses set InType=@ty,InDate=@dat,Person=@per,Money=@mon,InExplain=@exp,CateId=@cate", conn); cmdd.Parameters.AddWithValue("ty", shouruleixing);//添加值 cmdd.Parameters.AddWithValue("dat", date); cmdd.Parameters.AddWithValue("per", shouzhiren); cmdd.Parameters.AddWithValue("mon", jiner); cmdd.Parameters.AddWithValue("exp", shuoming); cmdd.Parameters.AddWithValue("cate", liebieid); //执行语句 cmdd.ExecuteNonQuery(); this.Close(); #endregion } private void incomeExpenditure_Load(object sender, EventArgs e) { } //实时统计备注 private void chenge() { //获取收入类型 string shouruleixing; if (shouRu.Checked) { shouruleixing = "收入"; } else { shouruleixing = "支出"; } //获取收入类别 string shouruleibie=""; if (shouRuLeiBie.SelectedIndex != -1) { shouruleibie = shouRuLeiBie.SelectedItem.ToString(); } else { shouRuLeiBie.SelectedIndex = 0; } //获取日期 string date=""; if (rQ.SelectedIndex != -1) { date = rQ.SelectedItem.ToString(); } else { rQ.SelectedIndex = 0; } //获取说明 string shuoming = ""; shuoming = shuoMing.Text; //获取收支项目 string shouzhixiangmu = ""; if (shouZhiXiangMu.SelectedItems.Count == 0) { return; } else { shouzhixiangmu = shouZhiXiangMu.SelectedItem.ToString(); } //获取收支人 string shouzhiren = ""; CheckBox[] person = new CheckBox[] { My, Family, Relative, Friend, Classmate, Other }; for (int i = 0; i < person.Length; i++) { if (person[i].Checked) { shouzhiren += person[i].Text + " "; } } //获取金额 string jiner = ""; jiner = jinEr.Text; //合并备注 string remark = ""; remark += "要保存的信息为:\n"; remark += shouruleibie + "-" + shouzhixiangmu + "\n"; remark += "日 期:" + date + "\n"; remark += "说 明:" + shuoming + "\n"; remark += "收支人:" + shouzhiren + "\n"; remark += "金 额:" + jiner; beiZhu.Text = remark; } private void shouRu_CheckedChanged(object sender, EventArgs e) { #region 连接数据库 //定义连接字符串 string connStr = "Database=BillManagement;Data Source=127.0.0.1;port=3306;User Id=root;"; MySqlConnection conn = new MySqlConnection(connStr);//创建Connection对象 conn.Open();//打开数据库 #endregion shouRuLeiBie.Items.Clear(); //创建命令 string sql = "SELECT CaName FROM Category WHERE Catype='0'";//执行语句 MySqlCommand cmd = new MySqlCommand(sql, conn);//创建Command对象 //执行命令--读取数据 MySqlDataReader reader = cmd.ExecuteReader();//创建MySqlDataReader对象 shouRuLeiBie.Items.Clear(); while (reader.Read())//每次读一行显示在集合中 { shouRuLeiBie.Items.Add(reader[0]); } shouRuLeiBie.SelectedIndex = 0; reader.Close(); //获取选中类别名称 string shouruleibie = ""; if (shouRuLeiBie.SelectedIndex != -1) { shouruleibie = shouRuLeiBie.SelectedItem.ToString(); } else { shouRuLeiBie.SelectedIndex = 0; } shouZhiXiangMu.Items.Clear(); //获取类别编号 MySqlCommand cmd2 = new MySqlCommand("SELECT CateId FROM category WHERE CaName = @lb", conn); cmd2.Parameters.AddWithValue("lb", shouruleibie); MySqlDataReader reader2 = cmd2.ExecuteReader();//创建MySqlDataReader对象 int liebieid = 0; while (reader2.Read())//每次读一行显示在集合中 { liebieid = Convert.ToInt32(reader2[0]); } //shouZhiXiangMu.Items.Add(shouruleibie); // shouZhiXiangMu.Items.Add(liebieid); reader2.Close(); //导入项目 MySqlCommand cmd3 = new MySqlCommand("SELECT proName FROM project WHERE CateId = @idd", conn);//创建Command对象 cmd3.Parameters.AddWithValue("idd", liebieid);//添加值 MySqlDataReader reader3 = cmd3.ExecuteReader();//创建MySqlDataReader对象 //shouZhiXiangMu.Items.Clear(); while (reader3.Read()) { shouZhiXiangMu.Items.Add(reader3[0]); } reader3.Close(); chenge(); } private void zhiChu_CheckedChanged(object sender, EventArgs e) { #region 连接数据库 //定义连接字符串 string connStr = "Database=BillManagement;Data Source=127.0.0.1;port=3306;User Id=root;"; MySqlConnection conn = new MySqlConnection(connStr);//创建Connection对象 conn.Open();//打开数据库 #endregion shouRuLeiBie.Items.Clear(); //创建命令 string sql = "SELECT CaName FROM Category WHERE Catype='1'";//执行语句 MySqlCommand cmd = new MySqlCommand(sql, conn);//创建Command对象 //执行命令--读取数据 MySqlDataReader reader = cmd.ExecuteReader();//创建MySqlDataReader对象 shouRuLeiBie.Items.Clear(); while (reader.Read())//每次读一行显示在集合中 { shouRuLeiBie.Items.Add(reader[0]); } shouRuLeiBie.SelectedIndex = 0; reader.Close(); //获取选中类别名称 string shouruleibie = ""; if (shouRuLeiBie.SelectedIndex != -1) { shouruleibie = shouRuLeiBie.SelectedItem.ToString(); } else { shouRuLeiBie.SelectedIndex = 0; } shouZhiXiangMu.Items.Clear(); //获取类别编号 MySqlCommand cmd2 = new MySqlCommand("SELECT CateId FROM category WHERE CaName = @lb", conn); cmd2.Parameters.AddWithValue("lb", shouruleibie); MySqlDataReader reader2 = cmd2.ExecuteReader();//创建MySqlDataReader对象 int liebieid = 0; while (reader2.Read())//每次读一行显示在集合中 { liebieid = Convert.ToInt32(reader2[0]); } reader2.Close(); //导入项目 MySqlCommand cmd3 = new MySqlCommand("SELECT proName FROM project WHERE CateId = @idd", conn);//创建Command对象 cmd3.Parameters.AddWithValue("idd", liebieid);//添加值 MySqlDataReader reader3 = cmd3.ExecuteReader();//创建MySqlDataReader对象 //shouZhiXiangMu.Items.Clear(); while (reader3.Read()) { shouZhiXiangMu.Items.Add(reader3[0]); } reader3.Close(); chenge(); } private void textBox2_TextChanged(object sender, EventArgs e) { chenge(); } private void comboBox2_SelectedIndexChanged(object sender, EventArgs e) { chenge(); } private void shouZhiXiangMu_SelectedIndexChanged(object sender, EventArgs e) { chenge(); } private void shuoMing_TextChanged(object sender, EventArgs e) { chenge(); } private void My_CheckedChanged(object sender, EventArgs e) { chenge(); } private void Family_CheckedChanged(object sender, EventArgs e) { chenge(); } private void Relative_CheckedChanged(object sender, EventArgs e) { chenge(); } private void Classmate_CheckedChanged(object sender, EventArgs e) { chenge(); } private void Other_CheckedChanged(object sender, EventArgs e) { chenge(); } private void shouRuLeiBie_SelectedIndexChanged(object sender, EventArgs e) { chenge(); } private void button2_Click(object sender, EventArgs e) { this.Hide(); } } }

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356

(四)统计查询窗体

在这里插入图片描述
逻辑代码:

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using MySql.Data.MySqlClient; namespace PersonalFinanceSystem { public partial class statisticalQuery : Form { public statisticalQuery() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { string xiangmuName = textBox1.Text; #region 连接数据库 //定义连接字符串 string connStr = "Database=BillManagement;Data Source=127.0.0.1;port=3306;User Id=root;"; MySqlConnection conn = new MySqlConnection(connStr);//创建Connection对象 conn.Open();//打开数据库 #endregion listBox1.Items.Clear(); #region 查询 //创建命令 MySqlCommand cmd = new MySqlCommand("SELECT InDate,Person,Money,InExplain,caName FROM incomeAndExpenses,project,category WHERE incomeAndExpenses.CateId=project.CateId AND incomeAndExpenses.CateId=category.cateid AND project.ProName=@xmu;", conn);//创建Command对象 cmd.Parameters.AddWithValue("xmu", xiangmuName);//添加值 //执行命令--读取数据 MySqlDataReader reader = cmd.ExecuteReader();//创建MySqlDataReader对象 while (reader.Read())//每次读一行显示在集合中 { listBox1.Items.Add(string.Format(" 日期\t收支人\t金额\t说明 \t收支类型\n")); listBox1.Items.Add(string.Format("{0}\t{1}\t{2}\t{3}\t{4}", reader[0], reader[1], reader[2],reader[3],reader[4])); } reader.Close(); #endregion } private void statisticalQuery_Load(object sender, EventArgs e) { } } }

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354

(五)添加收支项目窗体

在这里插入图片描述
在这里插入图片描述逻辑代码:

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using MySql.Data.MySqlClient; namespace PersonalFinanceSystem { public partial class InExaccount : Form { public InExaccount() { InitializeComponent(); } private void tabPage2_Click(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { //获取项目名称 string projectName = textBox1.Text; string shouruleibie = ""; if (shouRuLeiBie.SelectedIndex != -1) { shouruleibie = shouRuLeiBie.SelectedItem.ToString(); } else { shouRuLeiBie.SelectedIndex = 0; } listBox1.Items.Clear(); listBox1.Items.Add("项目名称:" + projectName); listBox1.Items.Add("类别:" + shouruleibie); tabControl1.SelectedIndex = 1; } private void tabPage1_Click(object sender, EventArgs e) { this.tabControl1.SelectedTab = tabPage2; } private void button2_Click(object sender, EventArgs e) { #region 连接数据库 //定义连接字符串 string connStr = "Database=BillManagement;Data Source=127.0.0.1;port=3306;User Id=root;"; MySqlConnection conn = new MySqlConnection(connStr);//创建Connection对象 conn.Open();//打开数据库 #endregion //获取项目名称 string projectName = textBox1.Text; string shouruleibie = ""; //获取类别 if (shouRuLeiBie.SelectedIndex != -1) { shouruleibie = shouRuLeiBie.SelectedItem.ToString(); } else { shouRuLeiBie.SelectedIndex = 0; } //获取类别编号 MySqlCommand cmd = new MySqlCommand("SELECT CateId FROM category WHERE CaName=@leibie", conn); cmd.Parameters.AddWithValue("leibie", shouruleibie); MySqlDataReader reader = cmd.ExecuteReader();//创建MySqlDataReader对象 int liebieid=0; while (reader.Read())//每次读一行显示在集合中 { liebieid =Convert.ToInt32(reader[0]); } reader.Close(); //插入新项目数据 #region 插入 MySqlCommand cmdd = new MySqlCommand("insert into Project set CateId=@idd , ProName=@un", conn); cmdd.Parameters.AddWithValue("idd", liebieid);//添加值 cmdd.Parameters.AddWithValue("un", projectName); //执行语句 cmdd.ExecuteNonQuery(); #endregion this.Close(); } private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { } private void radioButton1_CheckedChanged(object sender, EventArgs e) { #region 连接数据库 //定义连接字符串 string connStr = "Database=BillManagement;Data Source=127.0.0.1;port=3306;User Id=root;"; MySqlConnection conn = new MySqlConnection(connStr);//创建Connection对象 conn.Open();//打开数据库 #endregion //判断是收入还是支出 if (radioButton1.Checked)//收入 { #region 查询 //创建命令 string sql = "SELECT caName FROM Category WHERE Catype='0'";//执行语句 MySqlCommand cmd = new MySqlCommand(sql, conn);//创建Command对象 //执行命令--读取数据 MySqlDataReader reader = cmd.ExecuteReader();//创建MySqlDataReader对象 shouRuLeiBie.Items.Clear(); while (reader.Read())//每次读一行显示在集合中 { shouRuLeiBie.Items.Add(reader[0]); } shouRuLeiBie.SelectedIndex = 0; #endregion } else//支出 { //创建命令 string sql = "SELECT caName FROM Category WHERE Catype='1'";//执行语句 MySqlCommand cmd = new MySqlCommand(sql, conn);//创建Command对象 //执行命令--读取数据 MySqlDataReader reader = cmd.ExecuteReader();//创建MySqlDataReader对象 shouRuLeiBie.Items.Clear(); while (reader.Read())//每次读一行显示在集合中 { shouRuLeiBie.Items.Add(reader[0]); } shouRuLeiBie.SelectedIndex = 0; } } private void groupBox1_Enter(object sender, EventArgs e) { } private void radioButton2_CheckedChanged(object sender, EventArgs e) { #region 连接数据库 //定义连接字符串 string connStr = "Database=BillManagement;Data Source=127.0.0.1;port=3306;User Id=root;"; MySqlConnection conn = new MySqlConnection(connStr);//创建Connection对象 conn.Open();//打开数据库 #endregion //判断是收入还是支出 if (radioButton1.Checked)//收入 { #region 查询 //创建命令 string sql = "SELECT caName FROM Category WHERE Catype='0'";//执行语句 MySqlCommand cmd = new MySqlCommand(sql, conn);//创建Command对象 //执行命令--读取数据 MySqlDataReader reader = cmd.ExecuteReader();//创建MySqlDataReader对象 shouRuLeiBie.Items.Clear(); while (reader.Read())//每次读一行显示在集合中 { shouRuLeiBie.Items.Add(reader[0]); } shouRuLeiBie.SelectedIndex = 0; #endregion } else//支出 { //创建命令 string sql = "SELECT caName FROM Category WHERE Catype='1'";//执行语句 MySqlCommand cmd = new MySqlCommand(sql, conn);//创建Command对象 //执行命令--读取数据 MySqlDataReader reader = cmd.ExecuteReader();//创建MySqlDataReader对象 shouRuLeiBie.Items.Clear(); while (reader.Read())//每次读一行显示在集合中 { shouRuLeiBie.Items.Add(reader[0]); } shouRuLeiBie.SelectedIndex = 0; } } private void InExaccount_Load(object sender, EventArgs e) { } } }

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196

(六)用户管理窗体

在这里插入图片描述逻辑代码:

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using MySql.Data.MySqlClient; namespace PersonalFinanceSystem { public partial class userManagement : Form { public userManagement() { InitializeComponent(); } private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { } private void userManagement_Load(object sender, EventArgs e) { #region 连接数据库 //定义连接字符串 string connStr = "Database=BillManagement;Data Source=127.0.0.1;port=3306;User Id=root;"; MySqlConnection conn = new MySqlConnection(connStr);//创建Connection对象 conn.Open();//打开数据库 #endregion #region 查询 //创建命令 string sql = "select * from UserBill";//执行语句 MySqlCommand cmd = new MySqlCommand(sql, conn);//创建Command对象 //执行命令--读取数据 MySqlDataReader reader = cmd.ExecuteReader();//创建MySqlDataReader对象 listBox1.Items.Add(string.Format("编号\t用户名\t密码")); while (reader.Read())//每次读一行显示在集合中 { listBox1.Items.Add(string.Format("{0}\t{1}\t{2}", reader[0], reader[1], reader[2])); } #endregion } private void button1_Click(object sender, EventArgs e) { #region 连接数据库 //定义连接字符串 string connStr = "Database=BillManagement;Data Source=127.0.0.1;port=3306;User Id=root;"; MySqlConnection conn = new MySqlConnection(connStr);//创建Connection对象 conn.Open();//打开数据库 #endregion #region 插入 string userName = textBox1.Text; string passWord = textBox2.Text; MySqlCommand cmd = new MySqlCommand("insert into UserBill set UserName=@un , UserPassWord=@pwd", conn); cmd.Parameters.AddWithValue("un", userName);//添加值 cmd.Parameters.AddWithValue("pwd", passWord); //执行语句 cmd.ExecuteNonQuery(); #endregion listBox1.Items.Clear(); #region 查询 //创建命令 string sql = "select * from UserBill";//执行语句 MySqlCommand cmdl = new MySqlCommand(sql, conn);//创建Command对象 //执行命令--读取数据 MySqlDataReader reader = cmdl.ExecuteReader();//创建MySqlDataReader对象 // listBox1.Items.Add(string.Format("编号\t用户名\t密码")); while (reader.Read())//每次读一行显示在集合中 { listBox1.Items.Add(string.Format("{0}\t{1}\t{2}", reader[0], reader[1], reader[2])); } #endregion } } }

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384

(七)关于窗体

在这里插入图片描述
逻辑代码:

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace PersonalFinanceSystem { public partial class aboutUs : Form { public aboutUs() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { this.Hide(); } private void aboutUs_Load(object sender, EventArgs e) { } } }

12345678910111213141516171819202122232425262728293031

网址:C#实现个人理财软件小项目 https://www.yuejiaxmz.com/news/view/173259

相关内容

项目分析:大学生个人财务管理系统的设计与实现
计算机实战项目之SSM家庭理财个人理财管理系统
C语言个人财务管理示例
小型家庭财务管理软件开题报告
记账理财软件哪些人气高 下载量高的记账理财软件推荐
设立个人财务目标并实现目标
项目经理常用的12大工具及5大最佳项目管理软件
快账财务软件试用版:实现企业财务数字化智能一键管理
Python项目设计:个人财务管理系统实现与功能详解
项目管理生活软件有哪些

随便看看