我的思路是把数据保存到access数据文件里,因为时间原因,没有弄完,现把弄完的部分传上来。
部分代码:- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.IO;
- using System.Data;
- using System.Data.OleDb;
- using System.Drawing;
- using System.Windows.Forms;
- namespace 信息管理
- {
- public partial class Form1 : Form
- {
- boolean flag=false;
- //登录和删除信息数据的代码
- private void button1_Click(object sender, EventArgs e)
- {
- if (checkBox1.Checked == true)
- {
- String sqlPath = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Directory.GetCurrentDirectory() + "\\Info.mdb;Persist Security Info=True;Jet OLEDB:Database Password=198168888";
- OleDbConnection conn = new OleDbConnection(sqlPath);
- conn.Open();
- String sqlStr = "select * from log where user ='" + userText.Text + "' and pswd ='" + pswdText.Text + "'";
- OleDbCommand cmd = new OleDbCommand(sqlStr, conn);
- if (cmd.ExecuteReader().Read())
- {
- flagd = true;
- userID = userText.Text;
- label1.Visible = true;
- label1.Text = "登录成功!";
- label1.ForeColor = Color.Green;
- }
- else
- {
- label1.Visible = true;
- label1.Text = "用户名或密码错误!";
- label1.ForeColor = Color.Red;
- }
- conn.Close();
- }
- else
- {
- String sqlPath = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Directory.GetCurrentDirectory() + "\\Info.mdb;Persist Security Info=True;Jet OLEDB:Database Password=198168888";
- OleDbConnection conn = new OleDbConnection(sqlPath);
- conn.Open();
- String sqlStr = "delete log where user ='"+userText+"'";
- OleDbCommand cmd = new OleDbCommand(sqlStr, conn);
- cmd.ExecuteNonQuery();
- sqlStr = "delete UserInfo where user ='" + userText + "'";
- cmd = new OleDbCommand(sqlStr, conn);
- cmd.ExecuteNonQuery();
- conn.Close();
- }
-
- }
- //注册和更新数据
- private void button2_Click(object sender, EventArgs e)
- {
- String pswdzc = pswdzcText.Text;
- String rpswdzc = rpswdzcText.Text;
- String userIDzc = usertextBox.Text;
- String namezc=namezctext.Text;
- String agezc = agezctext.Text;
- String addrzc = addrzctext.Text;
- String telezc = telezctext.Text;
- if (pswdzc.Length < 8)
- {
- pswdzclabel.Text = "密码少于8个字符!";
- pswdzclabel.ForeColor = Color.Red;
- flag = false;
- }
- else
- {
- pswdzclabel.Text = "密码正确!";
- pswdzclabel.ForeColor = Color.Green;
- flag =true;
- if (pswdzc!=(rpswdzc))
- {
- rpswdzclabel.Text = "前后密码不一致";
- pswdzclabel.ForeColor = Color.Red;
- flag = false;
- rpswdzclabel.Visible = true;
- }
- else
- {
- rpswdzclabel.Text = "密码正确!";
- pswdzclabel.ForeColor = Color.Green;
- flag = true;
- rpswdzclabel.Visible = true;
- }
- }
- if (namezc == "") namezc = null;
- if (agezc == "") agezc = null;
- if (telezc == "") telezc =null;
- if (addrzc == "") addrzc = null;
- if (flag)
- {
- String sqlPath = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Directory.GetCurrentDirectory() + "\\Info.mdb;Persist Security Info=True;Jet OLEDB:Database Password=198168888";
- OleDbConnection conn = new OleDbConnection(sqlPath);
- conn.Open();
- String sqlStr = "insert into UserInfo (userName,age,tele,address,user) values('"+namezc+"','"+agezc+"','"+telezc+"','"+addrzc+"','"+userIDzc+"')";
- OleDbCommand cmd = new OleDbCommand(sqlStr, conn);
- cmd.ExecuteNonQuery();
- sqlStr="insert into log (user,pswd) values('"+userIDzc+"','"+pswdzc+"')";
- cmd = new OleDbCommand(sqlStr, conn);
- cmd.ExecuteNonQuery();
- conn.Close();
- }
- private void button4_Click(object sender, EventArgs e)
- {
- String userzc = usertextBox.Text;
- if(userzc.Length<5)
- {
- userlabel.Text = "用户名少于5个字符";
- userlabel.ForeColor = Color.Red;
- }
- else
- {
- String sqlPath = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Directory.GetCurrentDirectory() + "\\Info.mdb;Persist Security Info=True;Jet OLEDB:Database Password=198168888";
- OleDbConnection conn = new OleDbConnection(sqlPath);
- conn.Open();
- try
- {
- String sqlStr = "select * from log where user ='" + userzc + "'";
- OleDbCommand cmd = new OleDbCommand(sqlStr, conn);
- OleDbDataReader rd = cmd.ExecuteReader();
- if (rd.Read())
- {
- pswdzcText.Text = rd.GetString(2);
- rpswdzcText.Text = pswdzcText.Text;
- }
- }
- catch (System.Exception ex)
- {
-
- }
- try
- {
- String sqlStr = "select * from UserInfo where user ='" + userzc + "'";
- OleDbCommand cmd = new OleDbCommand(sqlStr, conn);
- OleDbDataReader rd = cmd.ExecuteReader();
- if (rd.Read())
- {
- namezctext.Text = rd.GetString(1);
- agezctext.Text = rd.GetString(4);
- telezctext.Text = rd.GetString(2);
- addrzctext.Text = rd.GetString(3);
- }
- }
- catch (System.Exception ex)
- {
- }
- conn.Close();
- }
- }
- }
复制代码 我是用C#写的。 |
|