c#.net课程设计:ZCMU通讯录(待更新)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/yu121380/article/details/85137360

大部分参考:博客https://blog.csdn.net/qq_38899124/article/details/80813862

 

                                               .net课程设计

 

题目:ZCMU通讯录课程设计

 

学生姓名:yu121380      专业:计算机科学与技术

学院:....... 学号:......    

 

 

 

目录

一.引言

1.1 通讯录系统设计开发的目的和意义

1.2设计通讯录系统的任务及目标

1.3通讯录系统开发及运行的软硬件环境

二.通讯录系统的分析和设计

2.1 通讯录系统需求分析

2.1.1通讯录系统的目标任务

2.1.2 通讯录系统的数据流图

2.2 通讯录系统概念结构设计

2.3 通讯录系统逻辑结构设计

2.4 通讯录系统数据库创建

2.5 通讯录系统总体结构设计

三.通讯录系统的开发和实现

3.1 通讯录系统的登录模块

3.2 通讯录系统的主界面

3.2.1 管理员登录界面

3.2.2 普通用户登录界面

3.3通信录系统的插入界面

3.4 通讯录系统的修改界面

3.5 通讯录系统的分组管理

3.6 通讯录系统分组信息的插入和修改

四.总结

参考文献

附录一(各功能代码)

附录二 (背景图)

说明(问题解答等)

。。。。。。

。。。。。。(待更新)

。。。。。。

2.4 通讯录系统数据库创建

由系统E—R图转化而得到的关系模式如下:

(1)users(用户名,密码),其用户名为主键。

(2)联系人表(姓名,性别,出生日期,email,电话号码),其姓名为主键。

(3)分组信息(姓名,分组名称,工作地点),(姓名,分组名称)为主键。

建立数据库

数据库中用到的表:

user

分组信息

联系人表

软件:Microsoft visual studio 2010

各功能界面:

1.pubicclass类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Threading.Tasks;

namespace Tonxunlu
{
    public class publicclass
    {
        public static SqlConnection createconn()
        {
            //@"Data source=PC-20140124HPZO\SQLEXPRESS;User ID=sa;pwd=123456;Initial Catalog=DatabaseTonxunlu";
            //注意:Data source---指定sql sever数据库(我用的是sql)所在计算机名称或IP;(PC-20140124HPZO本计算机名+/SQLEXPRESS)
            //      User ID,pwd---指定用户名和数据库的账户和密码
            //      Initial Catalog---指定连接的数据库名称(DatabaseTonxunlu)
            string connStr = @"Data source=PC-20140124HPZO\SQLEXPRESS;User ID=sa;pwd=123456;Initial Catalog=DatabaseTonxunlu";
            SqlConnection conn = new SqlConnection(connStr);
            return conn;
        }
        public static DataTable gettable(string sql)
        {
            SqlConnection conn = createconn();
            SqlDataAdapter da = new SqlDataAdapter(sql, conn);
            DataTable dt = new DataTable();
            da.Fill(dt);
            return dt;
        }
        public static bool zhixingSQl(string sql)
        {
            SqlConnection conn1 = createconn();
            SqlCommand cmd = new SqlCommand(sql, conn1);
            if (conn1.State != ConnectionState.Open)
            {
                conn1.Open();
            }
            if (cmd.ExecuteNonQuery() > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
            conn1.Close();
        }
        public static bool checkUser(string userName, string passWord)
        {
            string sql = "select 密码 from users where 用户名= '" + userName + "'";
            DataTable dt = gettable(sql);
            if (passWord == dt.Rows[0]["密码"].ToString().Trim())
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }
}

2.welcome界面源代码

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 Tonxunlu
{
    public partial class welcome : Form
    {
        public welcome()
        {
            InitializeComponent();
        }
        private void Welcome_Load(object sender, EventArgs e)
        {

        }
        private void button1_Click(object sender, EventArgs e)
        {
            login lo = new login();
            lo.Show();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            login1 lo1 = new login1();
            lo1.Show();
        }

        private void closenow_Click(object sender, EventArgs e)
        {
            this.Close();
        }

    }
}


3.login界面源代码

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 Tonxunlu
{
    public partial class login : Form
    {
        public login()
        {
            InitializeComponent();
        }

        private void login_Load(object sender, EventArgs e)
        {

        }

        private void buttonok_Click(object sender, EventArgs e)
        {
            if(textBoxname.Text.Length != 0 && textBoxpwd.Text.Length != 0)
            {
                if(publicclass.checkUser(textBoxname.Text.Trim(), textBoxpwd.Text.Trim()))
                {
                    main formMain = new main();
                    formMain.Show();
                }
                else
                {
                    MessageBox.Show("用户名或密码不正确", "提示");
                }
            }
            else
            {
                MessageBox.Show("用户名或密码不能为空", "提示");
            }
        }

        private void buttoncancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}


4.login1界面源代码

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 Tonxunlu;

namespace Tonxunlu
{
    public partial class login1 : Form
    {
        public login1()
        {
            InitializeComponent();

        }
        private void button1_Click(object sender, EventArgs e)
        {
            if (textBoxname.Text.Length != 0 && textBoxpwd.Text.Length != 0)
            {
                if(publicclass.checkUser(textBoxname.Text.Trim(), textBoxpwd.Text.Trim()))
                {
                    main1 formMain = new main1();
                    formMain.Show();
                }
                else
                {
                    MessageBox.Show("用户名或密码不正确", "提示");
                }
            }
            else
            {
                MessageBox.Show("用户名或密码不能为空", "提示");
            }
        }
        private void button2_Click(object sender, EventArgs e)
        {
            //Application.Exit();
            this.Close();
        }

        private void login1_Load(object sender, EventArgs e)
        {

        }
    }
}


5.main界面源代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Tonxunlu
{
    public partial class main : Form
    {
        public main()
        {
            InitializeComponent();
        }

        private void main_Load(object sender, EventArgs e)
        {
            DataTable dt = publicclass.gettable("select * from 联系人表");
            dataGridView1.DataSource = dt;
        }

        private void buttoninsert_Click(object sender, EventArgs e)
        {
            insert forminsert = new insert();
            forminsert.Show();
        }

        private void buttondelete_Click(object sender, EventArgs e)
        {
            string name;
            int index = dataGridView1.CurrentRow.Index;
            name = dataGridView1["姓名", index].Value.ToString().Trim();
            string sql = "delete 联系人表 where 姓名='" + name + "'";
            if (MessageBox.Show("是否要删除", "提示", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
            {
                if (publicclass.zhixingSQl(sql))
                {
                    MessageBox.Show("删除成功|");
                    group formgroup1 = new group();
                    formgroup1.Show();
                }
                else
                {
                    MessageBox.Show("删除失败");
                }
            }
        }

        private void buttonchange_Click(object sender, EventArgs e)
        {
            string name;
            int index = dataGridView1.CurrentRow.Index;
            name = dataGridView1["姓名", index].Value.ToString().Trim();
            modify formmodify = new modify(name);
            formmodify.Show();
        }

        private void buttonaddgroup_Click(object sender, EventArgs e)
        {
            group formgroup = new group();
            formgroup.Show();
        }

        private void buttoninquiry_Click(object sender, EventArgs e)
        {
            string sql;
            if (textBoxname.Text.Length != 0)
            {
                sql = "select * from 联系人表 where 姓名= '" + textBoxname.Text.Trim() + "'";
            }
            else
            {
                sql = "select * from 联系人表";
                MessageBox.Show("请输入姓名!", "提示");
            }
            DataTable dt = publicclass.gettable(sql);
            dataGridView1.DataSource = dt;
        }

        private void buttonrefresh_Click(object sender, EventArgs e)
        {
            main_Load(null, null);
        }
    }
}


6.main1界面源代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Tonxunlu
{
    public partial class main1 : Form
    {
        public main1()
        {
            InitializeComponent();
        }

        private void main1_Load(object sender, EventArgs e)
        {
            DataTable dt = publicclass.gettable("select * from 分组信息");
            dataGridView1.DataSource = dt;
        }

        private void buttoninquiry_Click(object sender, EventArgs e)
        {
            string sql;
            if (textBox1.Text.Length != 0)
            {
                sql = "select 联系人表.*,分组信息.分组名称,分组信息.工作地点 from 联系人表,分组信息 where 分组信息.分组名称='" + textBox1.Text.Trim() + "' and 联系人表.姓名=分组信息.姓名";
            }
            else
            {
                sql = "select * from 分组信息";
                MessageBox.Show("请输入分组名称!", "提示");
            }
            DataTable dt = publicclass.gettable(sql);
            dataGridView1.DataSource = dt;
        }
    }
}


7.insert界面源代码

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 Tonxunlu;


namespace Tonxunlu
{
    public partial class insert : Form
    {
        public insert()
        {
            InitializeComponent();
        }
        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        private void insert_Load(object sender, EventArgs e)
        {
            try
            {
                comboBox1.Items.Add("man");
                comboBox1.Items.Add("woman");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void in_insert_Click_1(object sender, EventArgs e)
        {
            if (in_name.Text.Length != 0 && in_phone.Text.Length != 0 &&
                 in_email.Text.Length != 0 && in_datatime.Text.Length != 0 &&
                comboBox1.SelectedItem != null)
            {
                string sql = "insert into 联系人表 (姓名,性别,出生日期,email,电话号码)values('" +
                   in_name.Text.Trim() + "','" + comboBox1.SelectedItem.ToString() + "','" + in_datatime.Text.Trim() + "','" + in_email.Text.Trim() + "','" + in_phone.Text.Trim() + "')";
                if (publicclass.zhixingSQl(sql))
                {
                    MessageBox.Show("插入成功");
                    this.Close();
                }
                else
                {
                    MessageBox.Show("插入失败");
                }
            }
            else
            {
                MessageBox.Show("请完整填写信息");
            }
        }

        private void button2_Click_1(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}


8.modify界面源代码

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 Tonxunlu;

namespace Tonxunlu
{
    public partial class modify : Form
    {
        string _name;
        public modify(string name)
        {
            InitializeComponent();
            _name = name;
        }
        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        private void modify_Load(object sender, EventArgs e)
        {
            DataTable dt = publicclass.gettable("select * from 联系人表 where 姓名 = '" + _name + "'");
            mo_name.Text = _name;
            mo_sex.Text = dt.Rows[0][1].ToString().Trim();
            mo_datetime.Text = dt.Rows[0][2].ToString().Trim();
            mo_email.Text = dt.Rows[0][3].ToString().Trim();
            mo_phone.Text = dt.Rows[0][4].ToString().Trim();

        }

        private void mo_modify_Click_1(object sender, EventArgs e)
        {
            if (mo_name.Text.Length != 0 && mo_phone.Text.Length != 0 &&
                 mo_email.Text.Length != 0 && mo_datetime.Text.Length != 0 &&
                mo_sex.Text.Length != 0)
            {
                string sql = "update 联系人表 set 性别= '" + mo_sex.Text.Trim() + "',出生日期 = '" +
                   mo_datetime.Text.Trim() + "',email='" + mo_email.Text.Trim() + "' ,电话号码='" + mo_phone.Text.Trim() + "' where 姓名= '" + _name + "'";
                if (publicclass.zhixingSQl(sql))
                {
                    MessageBox.Show("修改成功");
                    this.Close();
                }
                else
                {
                    MessageBox.Show("修改失败");
                }

            }
            else
            {
                MessageBox.Show("请完整填写信息");
            }
        }
    }

}


9.group界面源代码

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 Tonxunlu;

namespace Tonxunlu
{
    public partial class group : Form
    {
        public group()
        {
            InitializeComponent();
        }
        private void group_Load(object sender, EventArgs e)
        {
            DataTable dt = publicclass.gettable("select * from 分组信息");
            dataGridView1.DataSource = dt;

        }
        

        private void buttonadd_Click(object sender, EventArgs e)
        {
            group1 formgroup1 = new group1();
            formgroup1.Show();
        }

        private void buttonchange_Click(object sender, EventArgs e)
        {
            string gr_name;
            int index = dataGridView1.CurrentRow.Index;
            gr_name = dataGridView1["姓名", index].Value.ToString().Trim();
            group1 modgr = new group1(gr_name);
            modgr.Show();
        }

        private void buttondelect_Click(object sender, EventArgs e)
        {
            string name;
            int index = dataGridView1.CurrentRow.Index;
            name = dataGridView1["姓名", index].Value.ToString().Trim();
            string sql = "delete 分组信息 where 姓名='" + name + "'";
            if (MessageBox.Show("是否要删除", "提示", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
            {
                if (publicclass.zhixingSQl(sql))
                {

                   MessageBox.Show("删除成功");
                }
                else
                {
                   MessageBox.Show("删除失败");
                }
            }
        }
        private void buttonrefresh_Click(object sender, EventArgs e)
        {
            group_Load(null, null);
        }
    }
}


10.group1界面源代码

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 Tonxunlu
{
    public partial class group1 : Form
    {
        public group1()
        {
            InitializeComponent();
        }
        public group1(string gr_num)
        {
            InitializeComponent();
            this.Text = "修改";
            this.gr_name1.Text = gr_num;
            this.gr_name1.Enabled = false;
            this.button1.Text = "修改";
        }
        private void button1_Click_1(object sender, EventArgs e)
        {
            if (this.Text != "修改")
            {
                if (gr_name1.Text.Length != 0 && gr_name.Text.Length != 0 && gr_add.Text.Length != 0)
                {
                    string sql = "insert into 分组信息(姓名,分组名称,工作地点) values('" +
                         gr_name1.Text.Trim() + "','" + gr_name.Text.Trim() + "','" + gr_add.Text.Trim() + "')";
                    if (publicclass.zhixingSQl(sql))
                    {
                        MessageBox.Show("插入成功");
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("插入失败");
                    }
                }
                else
                {
                    MessageBox.Show("请完整填写信息");

                }
            }

            else
            {
                if (gr_name1.Text.Length != 0 && gr_name.Text.Length != 0 && gr_add.Text.Length != 0)
                {
                    string sql = "update 分组信息 set 工作地点='" + gr_add.Text.Trim() + "',分组名称 = '" +
                            gr_name.Text.Trim() + "' where 姓名= '" + gr_name1.Text.Trim() + "'";
                    if (publicclass.zhixingSQl(sql))
                    {
                        MessageBox.Show("修改成功");

                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("修改失败");

                    }
                }
                else
                {

                    MessageBox.Show("请完整填写信息");

                }
            }
        }
        private void button2_Click_1(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}

背景图:

想要项目可私聊!

 

 

 

猜你喜欢

转载自blog.csdn.net/yu121380/article/details/85137360