视频1 视频21 视频41 视频61 视频文章1 视频文章21 视频文章41 视频文章61 推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37 推荐39 推荐41 推荐43 推荐45 推荐47 推荐49 关键词1 关键词101 关键词201 关键词301 关键词401 关键词501 关键词601 关键词701 关键词801 关键词901 关键词1001 关键词1101 关键词1201 关键词1301 关键词1401 关键词1501 关键词1601 关键词1701 关键词1801 关键词1901 视频扩展1 视频扩展6 视频扩展11 视频扩展16 文章1 文章201 文章401 文章601 文章801 文章1001 资讯1 资讯501 资讯1001 资讯1501 标签1 标签501 标签1001 关键词1 关键词501 关键词1001 关键词1501 专题2001
通讯录管理系统论文
2025-10-02 12:24:35 责编:小OO
文档
            

学生毕业设计(论文)

课题:通讯录管理系统

姓名:               

学号:              

班级:              

导师:              

项目开发日期:2008年11月

开发目的:毕业设计

目录

摘要    2

第一部分    3

1.1设计构思    3

1.2系统数据流图:    4

1.3系统数据流程图:    5

1.4系统功能结构图:    6

1.5管理员用户部分功能图:    6

1.6普通用户部分功能图:    6

1.7开发及运行环境:    7

第二部分 数据库设计:    7

2.1用户信息表(tb_User):    7

2.2资料信息表(tb_info)    8

第三部分  通讯录管理系统的实现    9

3.1 公共类的编写    9

3.1.1  OperateAndValidate.cs类    10

3.1.2 OperateAndValidate.cs类    12

3.2  系统登录模块设计:    13

3.3  系统主窗体块模块设计:    15

3.4    添加用户窗体块模块设计:    25

3.5    添加窗体块模块设计:    26

3.6    修改密码窗体块模块设计:    28

第四部分  总结    30

摘要

日益繁多的人际交往使得我们很难搞清楚与每个人之间的联系方式,特别是对于做经常出差的人来说更是难,所以通讯录能够便捷的给我们带来所需要的相关信息。而随着计算机的普及,人们的生活摆脱了传统式的记事本、电话簿,越来越多的靠计算机来帮助人们记住这些事情,极其简便。这就需要有一个使用的通讯录管理系统,用户可以方便的通过自己电脑的通讯录管理系统,来随时查阅自己所需要的信息,而不必再大费周折去翻开那繁琐的记事本。

通讯录管理系统是一个专门针对储存用户联系方式以及一些简单个人信息的实用管理系统,它方便了用户对众多客户、朋友、同事等个人信息的储存和快速查阅的功能,大大减少了查找过程的时间。

第一部分

1.1设计构思

通讯录管理系统功能需求分析:

通讯录管理系统主要功能分为三个模块:用户登录、系统维护以及数据的输出。

用户登录:实现管理员用户与游客用户的不同权限,对系统的实用权的区别

系统维护:包括对用户的添加,信息添加、删除、、查找、排序、修改,修改密码,注销等操作

数据的输出:主要是对相关信息的打印输出功能以及导入Excel功能,能够方便的使用户打印

1.2系统数据流图:

1.3系统数据流程图:

1.4系统功能结构图:

1.5管理员用户部分功能图:

1.6普通用户部分功能图:

1.7开发及运行环境:

本系统开发平台及运行环境如下:

系统开发平台:Microsoft Visual Studio 2005

系统开发语言:C#

数据库管理软件:SQL Server 2000

运行平台:Windows XP (SP2) / Windows2000 (SP4) / Windows Server 2003 (SP1)

运行环境:Microsoft.NET Framework SDK v2.0

分辨率: 最佳效果 1024×768 像素

说明:SP(Service Pack)为Windows操作系统补丁。

第二部分 数据库设计:

数据库名称:db_User,共有2个表:1、用户信息表(tb_User) 2、资料信息表(tb_info)

2.1用户信息表(tb_User):

字段名数据类型长度主键否描述
UserNamevarchar20用户名称
 UserPwdvarchar20用户密码
UseRightvarchar20用户权限

2.2资料信息表(tb_info)

字段名数据类型长度主键否描述
类别varchar50记录用户的类别
姓名varchar50记录用户名称
性别varchar50记录用户性别
年龄intr4记录用户年龄
生日varchar30记录用户生日
手机varchar30记录用户手机号
宅电varchar30记录用户宅电
传真varchar30记录用户传真
QQvarchar20记录用户QQ号

邮编bigint8记录用户邮编
电子邮箱varchar50记录用户Email

家庭住址varchar500记录家庭住址
个人爱好varchar500记录用户爱好
个人主页varchar250记录用户主页
备注varchar1000记录其他信息

第三部分  通讯录管理系统的实现

3.1 公共类的编写

开发项目时,以类的形式来组织、封装一些常用的方法和事件,以便提高代码的重用率,大大方便了代码的管理。本系统中创建了两个公共类:BaseOperate.cs 和OperateAndValidate.cs,其中BaseOperate.cs主要用来访问SQL Server数据库和返回基本的ADO.NET对象,OperateAndValidate.cs类主要用来执行控件绑定和数据验证等功能。程序开发时只需要调用相应方法即可。

3.1.1  OperateAndValidate.cs类

OperateAndValidate.cs类文件中,在命名空间区域引用using System..Data.SqlClient命名空间,用来连接数据库和进行有关数据库操作。主要代码如下:

using System;

using System.Collections.Generic;

using System.Text;

using System.Data;

using System.Data.SqlClient;

namespace BS

{

class BaseOperate

{

#region  建立数据库连接

///

/// 建立数据库连接

///

/// 返回SqlConnection对象

public SqlConnection getcon()

{

//定义SQL Server 连接字符串

string str_sqlcon =@"server =.;database =db_User;uid =sa; pwd =";

//SqlConnection类用来连接数据库

SqlConnection myCon = new SqlConnection(str_sqlcon);

return myCon;

}

#endregion

#region 执行SqlCommand命令

///

/// 执行SqlCommand命令

///

/// SQL语句

public void getcom(string str_sqlcon)

{

SqlConnection sqlcon = this.getcon();

//SqlConnection类的Open()方法用来打开数据库连接。

sqlcon.Open();

//SqlCommand类表示要对SQL Server数据库执行一个SQL语句或存储过程

SqlCommand sqlcom = new SqlCommand(str_sqlcon, sqlcon);

//SqlCommand类的ExecuteNonQuery()方法用来执行SqlCommand命令

sqlcom.ExecuteNonQuery();

//SqlCommand类的Dispose()方法用来释放SqlCommand对象占用的资源

sqlcom.Dispose();

//SqlConnection类的Close()方法用来关闭数据库连接。

sqlcon.Close();

sqlcon.Dispose();

}

#endregion

#region 创建DataSet对象

///

/// 创建一个DataSet对象

///

/// SQL语句

/// SQL语句表名

public DataSet getds(string str_sqlcon, string str_tb_Table)

{

SqlConnection sqlcon = this.getcon();

//SqlDataAdapter类表示用于填充DataSet和更新SQL Server数据库的一组数据命令和一个数据库连接

SqlDataAdapter sqlda = new SqlDataAdapter(str_sqlcon, sqlcon);

//DataSet是数据的内存驻留流表示形式,它表示一个数据集。

DataSet myds = new DataSet();

//SqlDataAdapter类的Fill()方法用来填充DataSet和DataSetr数据集

sqlda.Fill(myds, str_tb_Table);

return myds;

}

#endregion

#region 创建SqlDataReader对象

///

/// 创建一个SqlDataReader对象

///

/// SQL语句

/// 返回SqlDataRead对象

public SqlDataReader getread(string str_sqlstr)

{

SqlConnection sqlcon = this.getcon();

SqlCommand sqlcom = new SqlCommand(str_sqlstr, sqlcon);

sqlcon.Open();

SqlDataReader sqlread = sqlcom.ExecuteReader(CommandBehavior.CloseConnection);

return sqlread;

}

#endregion

}}

3.1.2 OperateAndValidate.cs类

OperateAndValidate.cs类文件中,首先在命名空间区域添加如下命名空间:

Using.System.Data.SqlClentSystem.Text.RegularExpressions用来进行数据库操作,生成BaseOperate类的一个对象,通过类对象调用类中的方法功能,是现在代码如下:

using System;

using System.Collections.Generic;

using System.Text;

using System.Windows.Forms;

using System.Data;

using System.Data.SqlClient;

using System.Text.RegularExpressions;

using CrystalDecisions.CrystalReports.Engine;

namespace BS

{    class OperateAndValidate

    {

        BaseOperate boperate = new BaseOperate();//声明 BaseOperate 类的一个对象,以调用其方法 

        #region 绑定ComboBox控件

///

        /// 对ComboBox控件进行数据绑定

///

        /// SQL语句

        /// 表名

        /// 数据表中字段名

        /// ComboBox控件ID

        public void cboxBind(string P_str_sqlstr, string P_str_tb_Table, string P_str_tbMember, ComboBox cbox)

        {

            //调用BaseOperate类中的geds方法生成一个DataSet数据集对象

            DataSet myds=boperate.getds(P_str_sqlstr,P_str_tb_Table);

            //DataSource 属性用来获取或设置ComboBox控件的数据源

            cbox.DataSource = myds.Tables[P_str_tb_Table];

            //DisplayMember 属性用来获取或设置要为ComboBox控件显示的属性

            cbox.DisplayMember = P_str_tbMember;

        }

        #endregion

    }}

3.2  系统登录模块设计:

系统登录模块运行结果如图所示:

主要代码实现如下:

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using System.Data.SqlClient;

namespace BS

{

    public partial class frmLogin : Form

    {

        public static string str_name;//记录登录用户名字

        public static string str_pwd;//记录登录用户密码

        public static string str_right;//记录登录用户权限

        BS.BaseOperate boperate = new BS.BaseOperate();

        BS.OperateAndValidate opAndvalidate = new BS.OperateAndValidate();

        public frmLogin()

        {

            InitializeComponent();

        }

        private void timer1_Tick(object sender, EventArgs e)

        {

            DateTime dt = DateTime.Now;  //在登录页面显示获取的系统当前时间          

            label5.Text = "当前时间:"+dt.Year + "年" + dt.Month + "月" + dt.Day + "日" + dt.Hour + "时" + dt.Minute + "分" + dt.Second + "秒";

        }

        private void button2_Click(object sender, EventArgs e)

        {

            Application.Exit();

        }

        private void button1_Click(object sender, EventArgs e)

        {

         SqlDataReader sqlread = boperate.getread("select UserName,UserPwd from tb_User where UserName='" + cbox.Text.Trim() + "' and UserPwd='" + txtPwd.Text.Trim() + "'");

        sqlread.Read();//HasRows属性用来获取一个值,指示SqlDataReader是否包含一行或多行

            if (sqlread.HasRows)

            {

                str_name = cbox.Text;

                str_pwd = txtPwd.Text.Trim();

                frmMain fmain = new frmMain();

                this.Hide();//Hide()方法用来隐藏窗体

                fmain.Show();//Show()方法用来显示执行窗体

            }

            else

            {

                MessageBox.Show("用户名或密码错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

                txtPwd.Text = "";

                cbox.Focus();//Focus()方法用来为控件获取焦点

            }

            sqlread.Close();

        }

        private void frmLogin_Load(object sender, EventArgs e)

        {

            //通过调用公共类OpenAndValidate中的cboxBind方法对显示用户登录名的ComboBox控件进行数据绑定

            opAndvalidate.cboxBind("select UserName from tb_User

        }

        private void cbox_SelectedIndexChanged(object sender, EventArgs e)

        {

            //通过调用公共类BaseOperate类中的getread方法成一个SqlDataReader对象

            SqlDataReader sqlread=boperate.getread("select UserName,UserRight from tb_User where UserName='"+cbox.Text+"'");

            //Read()方法用来使 SqlDataReader对象前进到下一条记录

            if(sqlread.Read())

            {

                label4.Text=sqlread["UserRight"].ToString();

                str_right=label4.Text;

            }

            sqlread.Close();//Close方法用来关闭SqlDataReader对象}     }

}

3.3  系统主窗体块模块设计:

系统主窗体运行程序如图所示:

其主要代码实现如下:

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using System.Data.SqlClient;

using System.IO;

 namespace BS

{

    public partial class frmMain : Form

    {

        BS.BaseOperate boperate = new BS.BaseOperate();//调用公共类,以便使用其中的方法

        BS.OperateAndValidate opAndvalidate = new OperateAndValidate();

        protected string str_sql = "select * from tb_info";//获取用户信息,在dataGridView显示数据

        protected string str_table = "tb_info";

        private DataSet myds = new DataSet(); //建立数据集  

        public frmMain()

        {

            InitializeComponent();

        }       

        private void timer1_Tick(object sender, EventArgs e)

        {

            DateTime dt = DateTime.Now;

            tss1STime.Text = "|系统时间:" + dt.Year + "年" + dt.Month + "月" + dt.Day + "日" + dt.Hour + "时" + dt.Minute + "分" + dt.Second + "秒";

        }

        private void frmMain_Load(object sender, EventArgs e)

        {

            timer1.Start();//计时器启动,用来获取系统当前时间

            tss1User.Text= "|操作用户:" + frmLogin.str_name;

            tss1Time.Text = "|登录时间:" + DateTime.Now.ToShortTimeString();

             DateTime dt = DateTime.Now;

            tss1STime.Text = "|当前时间:" + dt.Year + "年" + dt.Month + "月" + dt.Day + "日" + dt.Hour + "时" + dt.Minute + "分" + dt.Second + "秒";

            if (frmLogin.str_right.ToString().Trim() == "普通用户")//判断用户权限,Trim()方法用来删除字符串最后的空白字符

            {

                //Enabled属性用来设置控件是否可用

                添加ToolStripMenuItem.Enabled = false;

                删除ToolStripMenuItem.Enabled = false;

                修改ToolStripMenuItem.Enabled = false;

                打印ToolStripMenuItem.Enabled = false;

                打印toolStripButton.Enabled = false;

                添加toolStripButton.Enabled = false;

                删除toolStripButton.Enabled = false;

                修改toolStripButton.Enabled = false;

                添加用户AToolStripMenuItem.Enabled = false;      

            }

            DataSet myds = boperate.getds(str_sql, str_table);//在dataGridView显示数据

            dataGridView1.DataSource=myds.Tables["tb_info"];

        }

        private void toolStripComboBox1_SelectedIndexChanged(object sender, EventArgs e)

        {

              string str_sql = "select * from tb_info where 类别='"+toolStripComboBox1.Text.Trim() + "'";//获取用户类别信息

              string str_table = "tb_info";

              DataSet myds = boperate.getds(str_sql, str_table);

              dataGridView1.DataSource=myds.Tables["tb_info"];        }

        private void 添加toolStripButton_Click(object sender, EventArgs e)

        {

            frmAdd frmAdd1 = new frmAdd();//新建添加窗体

            frmAdd1.ShowDialog();

           

        }

        private void 修改toolStripButton_Click(object sender, EventArgs e)

        {

            if (textBox1.Text == "")//判断用户类别是否为空

            {

                MessageBox.Show("类别不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }

            else if (textBox2.Text == "")//判断用户姓名是否为空

            {

                MessageBox.Show("姓名不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }

            else if (textBox3.Text == "")//判断用户性别是否为空

            {

                MessageBox.Show("性别不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }

            else if (textBox4.Text == "")//判断用户年龄是否为空

            {

                MessageBox.Show("年龄不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }

            else

            {

                //调用公共类方法修改数据库

                boperate.getcom("update tb_info set 类别='" + textBox1.Text.Trim() + "',姓名='" + textBox2.Text.Trim() + "',性别='" + textBox3.Text.Trim() + "',年龄='" + textBox4.Text.Trim() + "',生日='" + textBox5.Text.Trim() + "',手机='" + textBox6.Text.Trim() + "',宅电='" +

                    textBox7.Text.Trim() + "',传真='" + textBox8.Text.Trim() + "',QQ='" + textBox9.Text.Trim() + "',邮编='" + textBox10.Text.Trim() + "',电子邮箱='" + textBox11.Text.Trim() + "',家庭住址='" + textBox12.Text.Trim() + "',个人爱好='" +

                    textBox13.Text.Trim() + "',个人主页='" + textBox14.Text.Trim() + "',备注='" + richTextBox1.Text.Trim() + "'where 姓名='" + textBox2.Text.Trim() + "'");           

                MessageBox.Show("个人信息修改成功!请点击刷新后再打印!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

                textBox1.Text = "";

                textBox2.Text = "";

                textBox3.Text = "";

                textBox4.Text = "";

                textBox5.Text = "";

                textBox6.Text = "";

                textBox7.Text = "";

                textBox8.Text = "";

                textBox9.Text = "";

                textBox10.Text = "";

                textBox11.Text = "";

                textBox12.Text = "";

                textBox13.Text = "";

                textBox14.Text = "";

                richTextBox1.Text = "";

            }

          

        }

        private void 删除toolStripButton_Click(object sender, EventArgs e)

        {

            try

            {

                if (MessageBox.Show("确实要删除这条信息吗?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)

                {

                    //调用公共类方法从数据库中删除相关信息

                    boperate.getcom("delete from tb_info where 类别='" + Convert.ToString(dataGridView1[0, dataGridView1.CurrentCell.RowIndex].Value).Trim() + "'");

                    MessageBox.Show("删除信息成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

                }

            }

            catch (Exception ex)

            {

                MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);

            }

        }     

        private void toolStripButton1_Click(object sender, EventArgs e)

        {

            //刷新用户信息

            DataSet myds = boperate.getds(str_sql, str_table);

            dataGridView1.DataSource = myds.Tables["tb_info"];

            textBox1.Text = "";

            textBox2.Text = "";

            textBox3.Text = "";

            textBox4.Text = "";

            textBox5.Text = "";

            textBox6.Text = "";

            textBox7.Text = "";

            textBox8.Text = "";

            textBox9.Text = "";

            textBox10.Text = "";

            textBox11.Text = "";

            textBox12.Text = "";

            textBox13.Text = "";

            textBox14.Text = "";

            richTextBox1.Text ="";

            toolStripTextBox1.Text = "";

            toolStripComboBox1.Text = "";         

        }

        private void 退出XToolStripMenuItem_Click(object sender, EventArgs e)

        {

            Application.Exit();

        }

        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)

        {

            //单击dataGridView中任意单元格,其该用户相关信息出现在对应textBox中

            textBox1.Text = Convert.ToString(dataGridView1[0, dataGridView1.CurrentCell.RowIndex].Value).Trim();

            textBox2.Text = Convert.ToString(dataGridView1[1, dataGridView1.CurrentCell.RowIndex].Value).Trim();

            textBox3.Text = Convert.ToString(dataGridView1[2, dataGridView1.CurrentCell.RowIndex].Value).Trim();

            textBox4.Text = Convert.ToString(dataGridView1[3, dataGridView1.CurrentCell.RowIndex].Value).Trim();

            textBox5.Text = Convert.ToString(dataGridView1[4, dataGridView1.CurrentCell.RowIndex].Value).Trim();

            textBox6.Text = Convert.ToString(dataGridView1[5, dataGridView1.CurrentCell.RowIndex].Value).Trim();

            textBox7.Text = Convert.ToString(dataGridView1[6, dataGridView1.CurrentCell.RowIndex].Value).Trim();

            textBox8.Text = Convert.ToString(dataGridView1[7, dataGridView1.CurrentCell.RowIndex].Value).Trim();

            textBox9.Text = Convert.ToString(dataGridView1[8, dataGridView1.CurrentCell.RowIndex].Value).Trim();

            textBox10.Text = Convert.ToString(dataGridView1[9, dataGridView1.CurrentCell.RowIndex].Value).Trim();

            textBox11.Text = Convert.ToString(dataGridView1[10, dataGridView1.CurrentCell.RowIndex].Value).Trim();

            textBox12.Text = Convert.ToString(dataGridView1[11, dataGridView1.CurrentCell.RowIndex].Value).Trim();

            textBox13.Text = Convert.ToString(dataGridView1[12, dataGridView1.CurrentCell.RowIndex].Value).Trim();

            textBox14.Text = Convert.ToString(dataGridView1[13, dataGridView1.CurrentCell.RowIndex].Value).Trim();

            richTextBox1.Text = Convert.ToString(dataGridView1[14, dataGridView1.CurrentCell.RowIndex].Value).Trim();

        }

        private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)

        {

            //定义打印用户信息的页面设置

            e.Graphics.DrawString(textBox2.Text, new Font("黑体", 20), Brushes.Black, 300, 50);

            e.Graphics.DrawString("的个人信息", new Font("宋体", 20), Brushes.Black, 390, 50);

            e.Graphics.DrawLine(new Pen(Color.Black, (float)5.00),0, 85, 950, 85);

            e.Graphics.DrawString(label1.Text , new Font("黑体", 20), Brushes.Black, 100,150);//类别

            e.Graphics.DrawString(textBox1.Text, new Font("宋体", 20), Brushes.Black, 200, 150);

            e.Graphics.DrawString(label2.Text, new Font("黑体", 20), Brushes.Black, 350, 150);//姓名

            e.Graphics.DrawString(textBox2.Text, new Font("宋体", 20), Brushes.Black, 450, 150);

            e.Graphics.DrawString(label3.Text, new Font("黑体", 20), Brushes.Black,550, 150);//性别

            e.Graphics.DrawString(textBox3.Text, new Font("宋体", 20), Brushes.Black, 630, 150);

            e.Graphics.DrawString(label4.Text, new Font("黑体", 20), Brushes.Black, 100, 250);//年龄

            e.Graphics.DrawString(textBox4.Text, new Font("宋体", 20), Brushes.Black, 180, 250);

            e.Graphics.DrawString(label5.Text, new Font("黑体", 20), Brushes.Black, 250, 250);//生日

            e.Graphics.DrawString(textBox5.Text, new Font("宋体", 20), Brushes.Black, 350, 250);

            e.Graphics.DrawString(label6.Text, new Font("黑体", 20), Brushes.Black, 550, 250);//手机

            e.Graphics.DrawString(textBox6.Text, new Font("宋体", 20), Brushes.Black, 630, 250);

            e.Graphics.DrawString(label7.Text, new Font("黑体", 20), Brushes.Black, 100, 350);//宅电

            e.Graphics.DrawString(textBox7.Text, new Font("宋体", 20), Brushes.Black, 180, 350);

            e.Graphics.DrawString(label8.Text, new Font("黑体", 20), Brushes.Black, 450, 350);//传真

            e.Graphics.DrawString(textBox8.Text, new Font("宋体", 20), Brushes.Black, 550, 350);

            e.Graphics.DrawString(label9.Text, new Font("黑体", 20), Brushes.Black, 100, 450);//QQ

            e.Graphics.DrawString(textBox9.Text, new Font("宋体", 20), Brushes.Black, 180, 450);

            e.Graphics.DrawString(label10.Text, new Font("黑体", 20), Brushes.Black, 450, 450);//邮编

            e.Graphics.DrawString(textBox10.Text, new Font("宋体", 20), Brushes.Black, 550, 450);

            e.Graphics.DrawString(label11.Text, new Font("黑体", 20), Brushes.Black, 100, 550);//电子邮箱

            e.Graphics.DrawString(textBox11.Text, new Font("宋体", 20), Brushes.Black, 250, 550);

            e.Graphics.DrawString(label12.Text, new Font("黑体", 20), Brushes.Black, 100, 650);//家庭住址

            e.Graphics.DrawString(textBox12.Text, new Font("宋体", 20), Brushes.Black, 250, 650);

            e.Graphics.DrawString(label13.Text, new Font("黑体", 20), Brushes.Black, 100, 750);//个人爱好

            e.Graphics.DrawString(textBox13.Text, new Font("宋体", 20), Brushes.Black, 250, 750);

            e.Graphics.DrawString(label14.Text, new Font("黑体", 20), Brushes.Black, 100, 850);//个人主页

            e.Graphics.DrawString(textBox14.Text, new Font("宋体", 20), Brushes.Black, 250, 850);

            e.Graphics.DrawString(label15.Text, new Font("黑体", 20), Brushes.Black, 100, 950);//备注

            e.Graphics.DrawString(richTextBox1.Text, new Font("宋体", 20), Brushes.Black, 250, 950);

            

        }

        private void 打印toolStripButton_Click(object sender, EventArgs e)

        {

            //调用Print()方法打印用户信息

            printDocument1.Print();

        }

        private void toolStripButton2_Click(object sender, EventArgs e)

        {

            //预览需要打印的用户信息

            this.printPreviewDialog1.Document = this.printDocument1;

            printPreviewDialog1.ShowDialog();

        }

        private void 关于ToolStripMenuItem_Click(object sender, EventArgs e)

        {

             

            frmAbout frmAbout1 = new frmAbout();

            frmAbout1.ShowDialog();

        }

        private void 修改密码ToolStripMenuItem_Click(object sender, EventArgs e)

        {

            frmMima frmMima1 = new frmMima();

            frmMima1.ShowDialog();

        }

        private void 添加用户AToolStripMenuItem_Click(object sender, EventArgs e)

        {

            frmAddUser frmAddUser1 = new frmAddUser();

            frmAddUser1.ShowDialog();

        }

        private void 导入ExcelIToolStripMenuItem_Click(object sender, EventArgs e)//另存新档按钮   导出成Excel

        { 

            SaveFileDialog saveFileDialog = new SaveFileDialog();

            saveFileDialog.Filter = "Execl files (*.xls)|*.xls";

            saveFileDialog.FilterIndex = 0;

            saveFileDialog.RestoreDirectory = true;

            saveFileDialog.CreatePrompt = true;

            saveFileDialog.Title = "Export Excel File To"; 

            saveFileDialog.ShowDialog();

            Stream myStream;

            myStream = saveFileDialog.OpenFile();

            //StreamWriter sw = new StreamWriter(myStream, System.Text.Encoding.GetEncoding("gb2312"));

            StreamWriter sw = new StreamWriter(myStream, System.Text.Encoding.GetEncoding(-0));

            string str = "";

            try

            {

                //写标题

                for (int i = 0; i < dataGridView1.ColumnCount; i++)

                {

                    if (i > 0)

                    {

                        str += "\";

                    }

                    str += dataGridView1.Columns[i].HeaderText;

                }

                sw.WriteLine(str);

                //写内容

                for (int j = 0; j < dataGridView1.Rows.Count; j++)

                {

                    string tempStr = "";

                    for (int k = 0; k < dataGridView1.Columns.Count; k++)

                    {

                        if (k > 0)

                        {

                            tempStr += "\";

                        }

                        tempStr += dataGridView1.Rows[j].Cells[k].Value.ToString();

                    }                    

                    sw.WriteLine(tempStr);                    

                }

                sw.Close();

                myStream.Close();

            }

            catch (Exception x)

            {

                MessageBox.Show(x.ToString());

            }

            finally

            {

                sw.Close();

                myStream.Close();

            }             

        }

        private void 注销RToolStripMenuItem_Click(object sender, EventArgs e)

        {

            frmLogin flodin = new frmLogin();

            flodin.Show();

            //Form.Dispose()方法用来释放当前窗体正在使用的资源

            this.Dispose();

        }

        private void toolStripButton3_Click(object sender, EventArgs e)

        {

            if (toolStripTextBox1.Text == "")//判断用户输入关键字是否为空

            {

                MessageBox.Show("关键字不能为空!请重新输入!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

                toolStripTextBox1.Focus();

            }

            else if (toolStripTextBox1.Text != "select * from tb_info where 姓名='" + toolStripTextBox1.Text.Trim() + "'")//判断用户所查找的信息是否存在

            {

                MessageBox.Show("对不起!没有找到你所需要的信息!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

                toolStripTextBox1.Text = "";

                toolStripTextBox1.Focus();

            }

            else

            {

                string str_sql = "select * from tb_info where 姓名='" + toolStripTextBox1.Text.Trim() + "'";//获取用户类别信息

                string str_table = "tb_info";

                DataSet myds = boperate.getds(str_sql, str_table);

                dataGridView1.DataSource = myds.Tables["tb_info"];

            }        }

        private void toolStripButton4_Click(object sender, EventArgs e)

        {

            string str_sql = "select * from tb_info  order by 姓名 asc, 年龄 desc";//按姓名升序、年龄降序排序

            string str_table = "tb_info";

            DataSet myds = boperate.getds(str_sql, str_table);

            dataGridView1.DataSource = myds.Tables["tb_info"]; }  

3.4添加用户窗体块模块设计:

添加用户窗体运行程序结果如图所示:

其主要代码如下:

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using System.Data.SqlClient;

namespace BS

{

    public partial class frmAddUser : Form

    {

        BS.BaseOperate boperate = new BS.BaseOperate();//调用公共类方法,定义一个对象

        BS.OperateAndValidate opAndvalidate = new BS.OperateAndValidate();

        public frmAddUser()

        {

            InitializeComponent();

        }

        private void button1_Click(object sender, EventArgs e)

        {

            if (textBox1.Text == "")

            {

                MessageBox.Show("用户名不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }

            else if (textBox3.Text == "")

            {

                MessageBox.Show("用户权限不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }

            else

            {

                boperate.getcom("insert into tb_User(UserName,UserPwd,UserRight)" + "values('" + textBox1.Text.Trim() + "','" + textBox2.Text.Trim() + "','" + textBox3.Text.Trim() + "')");

                this.Close();

                MessageBox.Show("个人信息添加成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }

        }

        private void button2_Click(object sender, EventArgs e)

        {

            this.Close();

        }

3.5添加窗体块模块设计:

添加窗体运行结果如图所示:

其主要代码实现如下:

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using System.Data.SqlClient;

namespace BS

{

    public partial class frmAdd : Form

    {

        BS.BaseOperate boperate = new BS.BaseOperate();//调用公共类中的方法,定义一个对象

        BS.OperateAndValidate opAndvalidate = new OperateAndValidate();        

        public frmAdd()

        {

            InitializeComponent();

        }

        private void button2_Click(object sender, EventArgs e)

        {

            this.Close();

        }

        private void button1_Click(object sender, EventArgs e)

        {

            if (txtLB.Text == "")

            {

                MessageBox.Show("类别不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }

            else if (txtName.Text == "")

            {

                MessageBox.Show("姓名不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }

            else if (txtSex.Text == "")

            {

                MessageBox.Show("性别不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }

            else if (txtYear.Text == "")

            {

                MessageBox.Show("年龄不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information) ;

            }

            else

            {

                boperate.getcom("insert into tb_info(类别,姓名,性别,年龄,生日,手机,宅电,传真,QQ,邮编,电子邮箱,家庭住址,个人爱好,个人主页,备注)" + "values('" + txtLB.Text.Trim() + "','" + txtName.Text.Trim() + "','" + txtSex.Text.Trim() + "','" + txtYear.Text.Trim() + "','" +

                    txtBirth.Text.Trim() + "','" + txtPhone.Text.Trim() + "','" + txtHomephone.Text.Trim() + "','" + txtCZ.Text.Trim() + "','" + txtQQ.Text.Trim() + "','" + txtYB.Text.Trim() + "','" + txtEmail.Text.Trim() + "','" + txtAddress.Text.Trim() + "','" +

                   txtSl.Text.Trim() + "','" + txtSW.Text.Trim() + "','" + richTextBox1.Text.Trim() + "')");              

                this.Close();              

                MessageBox.Show("个人信息添加成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);                

            } 

3.6修改密码窗体块模块设计:

 修改密码窗体运行结果:

其代码实现如下:

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using System.Data.SqlClient; 

namespace BS

{

    public partial class frmMima : Form

    {

        public static string str_name;//记录用户名

        public static string str_pwd;//记录用户密码

        public static string str_right;//记录用权限

        BS.BaseOperate boperate = new BS.BaseOperate();//调用公共类方法,定义一个对象

        BS.OperateAndValidate opAndvalidate = new BS.OperateAndValidate();

        public frmMima()

        {

            InitializeComponent();

        }

        private void button1_Click(object sender, EventArgs e)

        {

            SqlDataReader sqlread = boperate.getread("select UserName,UserPwd from tb_User where UserName='" + textBox1.Text.Trim() + "' and UserPwd='" + textBox2.Text.Trim() + "'");

            sqlread.Read();

            if (!sqlread.HasRows)

            {

                MessageBox.Show("用户名密码错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

                textBox2.Text = "";

                textBox3.Text="";

                textBox4.Text="";

            }

            else if (textBox3.Text.Trim() != textBox4.Text.Trim())

            {

                MessageBox.Show("密码确认错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

                textBox2.Text = "";

                textBox3.Text="";

                textBox4.Text="";

            }

            else

            {

                boperate.getcom("update tb_User set UserName='" + textBox1.Text.Trim() + "',UserPwd='" + textBox3.Text.Trim() + "'where UserName='" + textBox1.Text.Trim() + "'");

                MessageBox.Show("密码修改成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

                this.Close();

            }           

              sqlread.Close();

        }

        private void button2_ Click(object sender, EventArgs e)

        {

            this.Close();

        }

第四部分  总结

通过毕业设计,使我们学到了以前没有学过的很多知识,使我们对.NET程序设计有了更深层次的认识和理解,懂得了灵活运用.NET和SQL Server 2000等工具。在计算机飞速发展的今天,懂得一门计算机语言技术是非常必要的。同时,我们也清醒的认识到,只有自己肯努力,愿意去付出劳动,就能够得到属于我们自己所期望的东西。

    最后,在此由衷的向我的指导老师黄玲老师表示衷心的感谢,是她的悉心指导和严格要求,才使我的毕业设计有了较为完善的一面,才有了我能力的提高,得到了充分的锻炼。下载本文

显示全文
专题