c#qq登录界面
登录界面
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; using System.Data.SqlClient;
namespace qq
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
zhuce zhu = new zhuce();
zhu.Show();
this.Visible = false;
}
private void button1_Click(object sender, EventArgs e)
{
string id = textBox1.Text;
SqlConnection con = new SqlConnection(@"Data Source=LENOVO-PC\SQLEXPRESS;Initial Catalog=qq;Integrated Security=True");
con.Open();
SqlCommand b = new SqlCommand("select * from qq where id="+id, con);
SqlDataReader c = b.ExecuteReader();
while (c.Read())
{
if (this.textBox1.Text.Equals(c["id"].ToString()))
{
if (this.textBox1.Text.Equals(c["id"].ToString()) && this.textBox2.Text.Equals(c["password"].ToString()))
{
MessageBox.Show("正确");
break;
}
//else
//{
// Response.Write("abc");
//}
if (this.textBox1.Text.Equals(c["id"].ToString())
&& !this.textBox2.Text.Equals(c["password"].ToString()))
{
MessageBox.Show("密码错误!");
break;
}
}
else
{ MessageBox.Show("用户不存在!请重新输入");
break;
}
}
}
}
}
注册界面
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; using System.Data.Sql;
using System.Data.SqlClient;
using System.Data.SqlTypes;
namespace qq
{
public partial class zhuce : Form
{
public zhuce()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string id = textBox1.Text;
string password = textBox2.Text;
if (textBox2.Text != textBox3.Text)
{ MessageBox.Show("密码不一致,请重新输入~"); }
SqlConnection con = new SqlConnection(@"Data Source=LENOVO-PC\SQLEXPRESS;Initial Catalog=qq;Integrated Security=True");
try
{
con.Open();
string strsql = "insert into qq values ('" + id +
"','" + password + "')";
SqlCommand cmd = new SqlCommand(strsql,
con);
cmd.ExecuteNonQuery();
label4.Text = "注册成功~";
}
catch
{
label5.Text = "注册失败!";
}
finally
{
con.Close();
}
}
private void label5_Click(object sender, EventArgs e)
{
Form1 cai = new Form1();
cai.Show();
this.Visible = false;
}
}
}