当前位置:文档之家› 管理信息系统课程设计程序代码附录

管理信息系统课程设计程序代码附录

附录C Program程序代码using System;using System.Collections.Generic;using System.Windows.Forms;using xyq20091204;using System.Data.SqlClient;static class Program{///<summary>///应用程序的主入口点。

///</summary>[STAThread]static void Main(){Application.EnableVisualStyles();Application.SetCompatibleTextRenderingDefault(false);Application.Run(new用户登录());if (SQL_Class.LoginState == 1)data.data.ConnStr = "Data Source=CAE47;Initial Catalog=xyq20091204;IntegratedSecurity=True";Application.Run(new供应商管理信息系统());}}附录D Property_Class代码using System;using System.Collections.Generic;using System.Text;using ponentModel;namespace xyq20091204{class Property_Class{private string Id;private string Manager;private string Tel;private string Email;private string Addr;[CategoryAttribute("供应商基本信息"), DescriptionAttribute("显示供应商编号")] public string供应商编号{get { return Id; }set { Id = value; }}[CategoryAttribute("供应商基本信息"), DescriptionAttribute("显示负责人")] public string负责人{get { return Manager; }set { Manager = value; }}[CategoryAttribute("供应商基本信息"), DescriptionAttribute("显示联系电话")] public string联系电话{get { return Tel; }set { Tel = value; }}[CategoryAttribute("供应商基本信息"), DescriptionAttribute("显示电子邮箱")] public string电子邮箱{get { return Email; }set { Email = value; }}[CategoryAttribute("供应商基本信息"), DescriptionAttribute("显示通讯地址")] public string通讯地址{get { return Addr; }set { Addr = value; }}}}附录F SQL-Class代码using System;using System.Collections.Generic;using System.Text;using System.Data;using System.Data.SqlClient;namespace xyq20091204{public class SQL_Class{public static int LoginState = 0;public static SqlConnection xyq_con;public static string xyq_sqlcon = "Data Source=CAE47;Initial Catalog=xyq20091204;IntegratedSecurity=True";public static SqlConnection getcon(){xyq_con = new SqlConnection(xyq_sqlcon); //用SqlConnection对象与指定的数据库相连接xyq_con.Open(); //打开数据库连接return xyq_con; //返回SqlConnection对象的信息}public void con_close(){if (xyq_con.State == ConnectionState.Open) //判断是否打开与数据库的连接{xyq_con.Close(); //关闭数据库的连接xyq_con.Dispose(); //释放xyq_con变量的所用空间}}public SqlDataReader getcom(string SQLstr){getcon(); //打开与数据库的连接SqlCommand xyq_com = xyq_con.CreateCommand(); //创建一个SqlCommand对象xyq_mandText = SQLstr; //获取指定的SQL语句SqlDataReader xyq_read = xyq_com.ExecuteReader(); //执行SQL语句,生成一个SqlDataReader结果return xyq_read; //返回读取结果}public void getsqlcom(string SQLstr){getcon(); //打开与数据库的连接SqlCommand SQLcom = new SqlCommand(SQLstr, xyq_con);//创建一个SqlCommand对象SQLcom.ExecuteNonQuery(); //执行SQL语句SQLcom.Dispose(); //释放SQLcom变量的所有空间con_close(); //调用con_close()方法,关闭与数据库的连接}public DataSet getDataSet(string SQLstr, string tableName){getcon(); //打开与数据库的连接SqlDataAdapter SQLda = new SqlDataAdapter(SQLstr,xyq_con);//创建SqlDataAdapter对象DataSet xyq_DataSet = new DataSet(); //创建dataset对象SQLda.Fill(xyq_DataSet, tableName); //把读取的数据写入指定的数据表中return xyq_DataSet; //返回DataSet对象的信息}}}附录J 添加新产品设计代码using System;using System.Collections.Generic;using ponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Data.SqlClient;using System.Collections;namespace xyq20091204{public partial class添加产品信息 : Form{public ArrayList aryTem = new ArrayList();public添加产品信息(){InitializeComponent();}SQL_Class SQLClass = new SQL_Class();public string cmbString; //传递选中的供应商节点public string ID; //传递选中产品的编号public int OP_Type; //操作类型标识public int OP_OK; //操作完成标识private void添加产品信息_Load(object sender, EventArgs e){switch (OP_Type){case 0: //添加新产品信息SqlDataReader DR = SQLClass.getcom("select 供应商编号,供应商名称 from 供应商信息表 ");bool ifcom = DR.Read();if (!ifcom){MessageBox.Show("请先添加供应商!", "警告!", MessageBoxButtons.OK,rmation);OP_OK = 0; //没有执行相关操作this.Close();}else { 供应商编号cmb.Text = cmbString; } //复选框的Text为cmbString的值this.供应商编号cmb.Enabled = false;break;case 1: //修改产品信息LoadInfo(); //调用自定义方法LoadInfo(),对窗体中的控件进行赋值。

产品编号txt.ReadOnly = true;this.供应商编号cmb.Enabled = false;this.批次号txt.Enabled = false;this.数量txt.Enabled = false;this.单价txt.Enabled = false;this.联系人txt.Enabled = false;break;}}public void LoadInfo(){DataSet DSet = SQLClass.getDataSet("select * from 产品信息表 where 产品编号='" + ID +"'", "产品信息表");DataTable dt = DSet.Tables["产品信息表"];产品编号txt.Text = ID;产品名称txt.Text = dt.Rows[0]["产品名称"].ToString();所属系列cmb.Text = dt.Rows[0]["所属系列名称"].ToString();产品类型cmb.Text = dt.Rows[0]["产品类型"].ToString();质量等级txt.Text = dt.Rows[0]["质量等级"].ToString();规格txt.Text = dt.Rows[0]["规格"].ToString();保质期txt.Text = dt.Rows[0]["保质期"].ToString();净重txt.Text = dt.Rows[0]["净重"].ToString();产地txt.Text = dt.Rows[0]["产地"].ToString();产品编号txt.ReadOnly = true;产品名称txt.Enabled = true;供应商编号cmb.Enabled = true;所属系列cmb.Enabled = true;产品类型cmb.Enabled = true;质量等级txt.Enabled = true;规格txt.Enabled = true;保质期txt.Enabled = true;净重txt.Enabled = true;产地txt.Enabled = true;批次号txt.Enabled = true;数量txt.Enabled = true;单价txt.Enabled = true;联系人txt.Enabled = true;}private void确定_Click(object sender, EventArgs e){string[] strDept = 供应商编号cmb.Text.Split('(', ')'); //定义一个string数组strDeptswitch (OP_Type){case 0:if (产品编号txt.Text.Trim() == "" || 产品名称txt.Text.Trim() == "" || 产品类型cmb.Text.Trim() == "" || 所属系列cmb.Text.Trim() == "" || 供应商编号cmb.Text.Trim() == "" || 批次号txt.Text.Trim() == "" || 数量txt.Text.Trim() == "" || 单价txt.Text.Trim() == ""){MessageBox.Show("带*为必填选项,不可为空!", "警告!", MessageBoxButtons.OK,rmation);return;}if (数量txt.Text.Trim() == "0" || 单价txt.Text.Trim() == "0"){MessageBox.Show("数量及单价不可为零!", "警告!", MessageBoxButtons.OK,rmation);return;}string sq = "select * from 产品信息表 where 产品编号='" + 产品编号txt.Text.Trim() + "' ";SqlDataReader DR = SQLClass.getcom(sq);bool x = DR.Read();if (!x){string sql = "insert into 产品信息表 values ('" + 产品编号txt.Text.Trim() + "','"+ 产品名称txt.Text.Trim() + "','"+ 产品类型cmb.Text.Trim() + "','"+ 所属系列cmb.Text.Trim() + "','"+ 规格txt.Text.Trim() + "','"+ 净重txt.Text.Trim() + "','"+ 保质期txt.Text.Trim() + "','" + 产地txt.Text.Trim() + "','" + 质量等级txt.Text.Trim() + "')";SQLClass.getsqlcom(sql);}string sq1 = "select * from 供应商产品关联表 where 产品编号='" + 产品编号txt.Text.Trim() + "' and 供应商编号='" + strDept[0].ToString() + "'";SqlDataReader DR1 = SQLClass.getcom(sq1);bool y = DR1.Read();if (!y){aryTem.Add(产品编号txt.Text.Trim());aryTem.Add(产品名称txt.Text.Trim());aryTem.Add(产品类型cmb.Text.Trim());aryTem.Add(所属系列cmb.Text.Trim());aryTem.Add(规格txt.Text.Trim());aryTem.Add(净重txt.Text.Trim());aryTem.Add(保质期txt.Text.Trim());aryTem.Add(产地txt.Text.Trim());aryTem.Add(质量等级txt.Text.Trim());}sq1 = "select * from 供应商产品关联表 where 产品编号='" + 产品编号txt.Text.Trim() + "' and 供应商编号='" + strDept[0].ToString() + "' and 批次号='" + 批次号txt.Text.Trim() + "'";DR1 = SQLClass.getcom(sq1);y = DR1.Read();if (!y){string sql1 = "insert into 供应商产品关联表 values ('" + 产品编号txt.Text.Trim() + "','" + strDept[0].ToString() + "','" + 批次号txt.Text.Trim() + "','" + 数量txt.Text.Trim() + "','" + 单价txt.Text.Trim() + "','" + 联系人txt.Text.Trim() + "')";SQLClass.getsqlcom(sql1);}else{MessageBox.Show(this, "该批次已存在,请重新添加!", "提示",MessageBoxButtons.OK, rmation);return;}OP_OK = 1; //操作完成break;case 1:if (产品名称txt.Text.Trim() == "" || 产品类型cmb.Text.Trim() == "" || 所属系列cmb.Text.Trim() == "" ){MessageBox.Show("带*为必填选项,不可为空!", "警告!", MessageBoxButtons.OK,rmation);return;}string sql2 = "update 产品信息表 set 产品名称='"+ 产品名称txt.Text.Trim() + "',产品类型='" + 产品类型cmb.Text.Trim() + "',所属系列名称='" + 所属系列cmb.Text.Trim() + "',规格='" + 规格txt.Text.Trim() + "',净重='" + 净重txt.Text.Trim() + "',保质期='" + 保质期txt.Text.Trim() + "',产地='" + 产地txt.Text.Trim() + "',质量等级='" + 质量等级txt.Text.Trim() + "'where 产品编号='" + 产品编号txt.Text.Trim() + "'";SQLClass.getsqlcom(sql2);OP_OK = 1; //操作完成break;}SQLClass.con_close();this.Close();}private void取消_Click(object sender, EventArgs e){OP_OK = 0; SQLClass.con_close(); this.Close();}private void供应商编号cmb_SelectedIndexChanged(object sender, EventArgs e){this.供应商编号cmb.Items.Clear();DataSet DSet = SQLClass.getDataSet("select 供应商编号,供应商名称 from 供应商信息表", "供应商名称表");DataTable dt = DSet.Tables["供应商名称表"]; //创建一个DataTable对象for (int i = 0; i < dt.Rows.Count; i++){this.供应商编号cmb.Items.Add(dt.Rows[i]["供应商编号"].ToString() + "(" +dt.Rows[i]["供应商名称"].ToString() + ")");}}private void产品编号txt_TextChanged(object sender, EventArgs e){DataSet DSet = SQLClass.getDataSet("select * from 产品信息表 where 产品编号 = '"+ 产品编号txt .Text +"'", "产品信息表");DataTable dt = DSet.Tables["产品信息表"]; //创建一个DataTable对象if (dt.Rows.Count > 0){产品名称txt.Text = dt.Rows[0][1].ToString();产品类型cmb.Text = dt.Rows[0][2].ToString();所属系列cmb.Text = dt.Rows[0][3].ToString();规格txt.Text = dt.Rows[0][4].ToString();净重txt.Text = dt.Rows[0][5].ToString();保质期txt.Text = dt.Rows[0][6].ToString();产地txt.Text = dt.Rows[0][7].ToString();质量等级txt.Text = dt.Rows[0][8].ToString();产品名称txt.Enabled = false;产品类型cmb.Enabled = false;所属系列cmb.Enabled = false;规格txt.Enabled = false;净重txt.Enabled = false;保质期txt.Enabled = false;产地txt.Enabled = false;质量等级txt.Enabled = false;}else{产品名称txt.Text = "";产品类型cmb.Text = "";所属系列cmb.Text = "";规格txt.Text = "";净重txt.Text = "";保质期txt.Text = "";产地txt.Text = "";质量等级txt.Text = "";产品名称txt.Enabled = true;产品类型cmb.Enabled = true;所属系列cmb.Enabled = true;规格txt.Enabled = true;净重txt.Enabled = true;保质期txt.Enabled = true;产地txt.Enabled = true;质量等级txt.Enabled = true;}}private void产品类型cmb_TextChanged(object sender, EventArgs e){if (this.产品类型cmb.Text.Trim() == "日化类" || this.产品类型cmb.Text.Trim() == "洗化类"){this.所属系列cmb.Items.Clear();this.所属系列cmb.Items.Add("日用品");}else if (this.产品类型cmb.Text.Trim() == "干果类" || this.产品类型cmb.Text.Trim() == "膨化食品类" || this.产品类型cmb.Text.Trim() == "肉类"){this.所属系列cmb.Items.Clear();this.所属系列cmb.Items.Add("食品类");}else if (this.产品类型cmb.Text.Trim() == "礼服类" || this.产品类型cmb.Text.Trim() == "饰品类"){this.所属系列cmb.Items.Clear();this.所属系列cmb.Items.Add("服饰类");}else if (this.产品类型cmb.Text.Trim() == "小家电类"){this.所属系列cmb.Items.Clear();this.所属系列cmb.Items.Add("家电类");}}}}附录H 添加供应商类别设计代码using System;using System.Collections.Generic;using ponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Data.SqlClient;namespace xyq20091204{public partial class添加供应商类别 : Form{SQL_Class SQLClass = new SQL_Class();public string ID; //传递选中供应商类别的编号public int OP_Type; //操作类型标识,0表示添加供应商,1表示修改供应商信息public int OP_Ok; //操作完成标识public添加供应商类别(){InitializeComponent();}private void添加供应商类别_Load(object sender, EventArgs e){if (OP_Type == 1) //修改供应商类别信息{string sl = "select * from 供应商类别表 where 供应商类别编号='" + ID + "'";DataSet DSet = SQLClass.getDataSet(sl, "供应商类别表");DataTable dat = DSet.Tables["供应商类别表"];if (dat.Rows.Count > 0){供应商类别编号txt.Text = ID;供应商类别编号txt.ReadOnly = true; //设置只读属性供应商类别名称txt.Text = dat.Rows[0][1].ToString();}}}private void确定_Click(object sender, EventArgs e){switch (OP_Type){case 0: //添加供应商类别if (this.供应商类别编号txt.Text == "" || this.供应商类别名称txt.Text == "") {MessageBox.Show("请完善信息,带*为必填选项!", "警告!", MessageBoxButtons.OK, rmation);return;}string sql = "select * from 供应商类别表 where 供应商类别编号='" + 供应商类别编号txt.Text.ToString().Trim() + "' ";SqlDataReader DR = SQLClass.getcom(sql);bool ifcom = DR.Read();if (ifcom){MessageBox.Show("该供应商类别已存在,不能重复添加!", "警告!", MessageBoxButtons.OK, rmation);return;}string sql1 = "insert into 供应商类别表 values ('" + 供应商类别编号txt.Text.ToString().Trim() + "','" + 供应商类别名称txt.Text.ToString() + "')";SQLClass.getsqlcom(sql1);break;case 1: //修改供应商类别信息if (this.供应商类别编号txt.Text == "" || this.供应商类别名称txt.Text == "") {MessageBox.Show("请完善信息,带*为必填选项!", "警告!", MessageBoxButtons.OK, rmation);return;}string sql2 = "update 供应商类别表 set 供应商类别名称= '" + 供应商类别名称txt.Text.ToString() + "'where 供应商类别编号='" + ID + "'";SQLClass.getsqlcom(sql2);break;}OP_Ok = 1; //操作完成SQLClass.con_close();this.Close();}private void取消_Click(object sender, EventArgs e){OP_Ok = 0;SQLClass.con_close();this.Close();}}}附录I 添加供应商信息设计代码using System;using System.Collections.Generic;using ponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Data.SqlClient;namespace xyq20091204{public partial class添加供应商信息 : Form{SQL_Class SQLClass = new SQL_Class();public string ID;public int OP_Type;public int OP_Ok;public添加供应商信息(){InitializeComponent();}private void添加供应商信息_Load(object sender, EventArgs e){if (OP_Type == 1) //修改供应商信息{string sel = "select * from 供应商信息表 a,供应商类别表 b where 供应商编号='"+ ID + "'and a.供应商类别=b.供应商类别编号 ";DataSet DSet = SQLClass.getDataSet(sel, "供应商信息表");//创建一个DataSet对象,并把SQL的查询结果赋值给DSetDataTable dt = DSet.Tables["供应商信息表"];//创建一个DataTable对象供应商编号txt.Text = ID;供应商编号txt.ReadOnly = true;//把供应商名称txt赋值为SQL查询的结果表的第0行第1列的值供应商名称txt.Text = dt.Rows[0]["供应商名称"].ToString();供应商类别txt.Text = dt.Rows[0]["供应商类别名称"].ToString();负责人txt.Text = dt.Rows[0]["负责人"].ToString();联系电话txt.Text = dt.Rows[0]["联系电话"].ToString();电子邮箱txt.Text = dt.Rows[0]["电子邮箱"].ToString();通讯地址txt.Text = dt.Rows[0]["通讯地址"].ToString();简介rtxt.Text = dt.Rows[0]["简介"].ToString();}if (OP_Type == 0){供应商类别txt.ReadOnly = true;}}private void确定_Click(object sender, EventArgs e){switch (OP_Type){case 0: //添加供应商if (this.供应商编号txt.Text == "" || this.供应商名称txt.Text == ""){MessageBox.Show("请完善信息,带*为必填选项!", "警告!",MessageBoxButtons.OK, rmation);return;}string sql = "select * from 供应商信息表 where 供应商编号='" + 供应商编号txt.Text.ToString().Trim() + "' ";SqlDataReader DR = SQLClass.getcom(sql);bool ifcom = DR.Read();if (ifcom){MessageBox.Show("该供应商已存在,不能重复添加!", "警告!",MessageBoxButtons.OK, rmation);return;}string sql1 = "insert into 供应商信息表 values ('" + 供应商编号txt.Text.ToString().Trim() + "','" + 供应商名称txt.Text.ToString() + "','" + ID + "','" + 负责人txt.Text.ToString() + "','" + 联系电话txt.Text.ToString() + "','" + 电子邮箱txt.Text.ToString() + "','" + 通讯地址txt.Text.ToString() + "','" + 简介rtxt.Text.ToString() + "')";SQLClass.getsqlcom(sql1);break;case 1: //修改供应商信息if (this.供应商编号txt.Text == "" || this.供应商名称txt.Text == ""){MessageBox.Show("请完善信息,带*为必填选项!", "警告!", MessageBoxButtons.OK, rmation);return;}string sql2 ="update 供应商信息表 set 供应商名称= '" + 供应商名称txt.Text.ToString() + "',负责人= '" + 负责人txt.Text.ToString() + "',联系电话= '" + 联系电话txt.Text.ToString() + "',电子邮箱= '" + 电子邮箱txt.Text.ToString() + "',通讯地址= '" + 通讯地址txt.Text.ToString() + "',简介='"+ 简介rtxt.Text.ToString() +"'where 供应商编号='"+ID+"'";SQLClass.getsqlcom(sql2);break;}OP_Ok = 1; //操作完成SQLClass.con_close();this.Close();}private void取消_Click(object sender, EventArgs e){OP_Ok = 0;SQLClass.con_close();this.Close();}}}using System;using System.Collections.Generic;using ponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;namespace xyq20091204{public partial class新用户注册 : Form{ SQL_Class SQLClass = new SQL_Class();private void button1_Click(object sender, EventArgs e){if (txtName.Text == "" || txtPassword.Text == ""){ MessageBox.Show("用户名和密码不能为空!", "信息提示", MessageBoxButtons.OK, rmation);return;}System.Data.SqlClient.SqlDataReader dr = SQLClass.getcom("select * from 用户登录表where 用户名称='" + txtName.Text + "'");bool ifcom = dr.Read();if (ifcom){ MessageBox.Show("该用户名已经存在!", "信息提示", MessageBoxButtons.OK,rmation);return;}if (txtCheck.Text != txtPassword.Text){MessageBox.Show("两次输入的密码不一致,请重新输入!", "信息提示", MessageBoxButtons.OK,rmation);return;}SQLClass.getsqlcom("insert into 用户登录表(用户名称,用户密码) values ('" + txtName.Text + "','" + txtPassword.Text + "')");//调用SQL_Class类中的方法getsqlcom(),将新注册的信息写入用户登录表中SQLClass.con_close();this.Close();MessageBox.Show("注册成功,请使用新用户名登录!", "信息提示", MessageBoxButtons.OK,rmation);}private void button2_Click(object sender, EventArgs e){SQLClass.con_close();this.Close();}public新用户注册(){InitializeComponent();}using System;using System.Collections.Generic;using ponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Data.SqlClient;namespace xyq20091204{public partial class信息查询 : Form{public bool _radioButton1 = false;public bool _radioButton2 = false;//如果为false说明没有被选中public信息查询(){InitializeComponent();}SQL_Class SQLClass = new SQL_Class();public int OP_OK;public string sql; //传递SQL语句private void查询_Click(object sender, EventArgs e){if (this.radioButton1.Checked == false && this.radioButton2.Checked == false){MessageBox.Show("请选择要查询的项目!", "信息提示", MessageBoxButtons.OK, rmation);return;}else if (this.radioButton1.Checked == true){this._radioButton1 = true;this._radioButton2 = false;if (this.查询内容txt1.Text.ToString().Trim() == ""){MessageBox.Show("请输入查询内容!", "信息提示", MessageBoxButtons.OK, rmation);return;}SqlDataReader DR = SQLClass.getcom("select * from 产品信息表 where " + 查询类型cmb1.Text + "='" + 查询内容txt1.Text.ToString().Trim() + "'");bool ifcom = DR.Read();if (!ifcom){MessageBox.Show("没有找到该" + 查询类型cmb1.Text + "相关的产品信息!", "信息提示", MessageBoxButtons.OK, rmation);return;}else{sql = "select * from 产品信息表 where " + 查询类型cmb1.Text + "='" + 查询内容txt1.Text.ToString().Trim() + "'";}OP_OK = 1; SQLClass.con_close(); this.Close();}if (this.radioButton2.Checked == true){this._radioButton1 = false;this._radioButton2 = true;if (this.查询内容txt2.Text.ToString().Trim() == ""){MessageBox.Show("请输入查询内容!", "信息提示", MessageBoxButtons.OK, rmation);return;}SqlDataReader DR = SQLClass.getcom("select * from 供应商信息表 where " + 查询类型cmb2.Text + "='" + 查询内容txt2.Text.ToString().Trim() + "'");bool ifcom = DR.Read();if (!ifcom){MessageBox.Show("没有找到该" + 查询类型cmb2.Text + "相关的供应商信息!", "信息提示", MessageBoxButtons.OK, rmation);return;}else{sql = "select * from 供应商信息表 where " + 查询类型cmb2.Text + "='" + 查询内容txt2.Text.ToString().Trim() + "'";}OP_OK = 1; SQLClass.con_close(); this.Close();}}private void radioButton1_CheckedChanged(object sender, EventArgs e){if (this.radioButton1.Checked == true){this._radioButton1 = true;this._radioButton2 = false;this.groupBox1.Enabled = true;this.groupBox2.Enabled = false;}else{this._radioButton1 = false;this._radioButton2 = true;this.groupBox1.Enabled = false;this.groupBox2.Enabled = true;}}private void radioButton2_CheckedChanged(object sender, EventArgs e){if (this.radioButton1.Checked == true){this._radioButton1 = true;this._radioButton2 = false;this.groupBox1.Enabled = true;this.groupBox2.Enabled = false;}else{this._radioButton1 = false;this._radioButton2 = true;this.groupBox1.Enabled = false;this.groupBox2.Enabled = true;}}private void取消_Click(object sender, EventArgs e) {OP_OK = 0;this.Close();}}}附录A 用户登录设计代码using System;using System.Collections.Generic;using ponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;namespace xyq20091204{public partial class用户登录 : Form{public用户登录(){InitializeComponent();}private void用户登录_Load(object sender, EventArgs e){try{xyq20091204.SQL_Class.getcon(); //连接数据库txtName.Text = ""; //清空“用户名”文本框txtPassWord.Text = ""; //清空“密码”文本框}catch{MessageBox.Show("数据库连接失败!", "信息提示", MessageBoxButtons.OK, rmation);//当连接数据库失败时,显示错误信息Application.Exit(); //关闭整个工程}}private void btnRegister_Click(object sender, EventArgs e){新用户注册 dlg = new新用户注册();dlg.ShowDialog(); //显示新用户注册窗体}private void btnLogin_Click_1(object sender, EventArgs e){if (txtName.Text == ""){MessageBox.Show("用户名不能为空!", "信息提示", MessageBoxButtons.OK, rmation);return;}if (txtPassWord.Text == ""){MessageBox.Show("请输入密码!", "信息提示", MessageBoxButtons.OK, rmation);return;}SQL_Class SQLClass = new SQL_Class();string sql="select * from 用户登录表 where 用户名称='"+ txtName.Text.ToString().Trim() + "' and 用户密码='" + txtPassWord.Text.ToString().Trim()+"'";System.Data.SqlClient.SqlDataReader DR = SQLClass.getcom(sql);bool ifcom = DR.Read();if (ifcom) //当有记录时,用户名密码正确{SQL_Class.LoginState = 1; //标识登录成功SQLClass.con_close();this.Close();}else//数据库中没有记录,用户名密码不正确{MessageBox.Show("用户名或密码错误!", "信息提示", MessageBoxButtons.OK, rmation);txtName.Text = "";txtPassWord.Text = "";}SQLClass.con_close();}private void btnClose_Click(object sender, EventArgs e){Application.Exit();}}}。

相关主题