用C#来写一个管理系统的登录界面
来源:互联网 发布:mac os 10.10 iso镜像 编辑:程序博客网 时间:2024/04/29 06:07
登录系统的代码:
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 登录系统与注册
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private SqlConnection conn;
private void RegisterButton_Click(object sender, EventArgs e)
{
if (NameText.Text == "" || passwordText.Text == "")
{
MessageBox.Show("用户名或密码不能为空!!!");
return;
}
try
{
SqlDataAdapter da = new SqlDataAdapter("select * from userTest", conn);
SqlCommandBuilder bc = new SqlCommandBuilder(da);
DataSet ds = new DataSet();
da.Fill(ds, "userTest");
DataTable dt = ds.Tables["userTest"];
Object[] arr = new Object[2];
foreach (DataRow row in dt.Rows)
{
arr = row.ItemArray;
if (NameText.Text.Equals(arr[0].ToString()))
{
if (passwordText.Text.Equals(arr[1].ToString()))
{
MessageBox.Show("登录成功!!!");
return;
}
else
{
MessageBox.Show("密码不正确,请查证!!!");
passwordText.Text = "";
return;
}
}
}
MessageBox.Show("用户名不存在,请先注册!!!");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
conn.Close();
}
}
private void Form1_Load(object sender, EventArgs e)
{
conn = new SqlConnection("Data Source=localhost;Initial Catalog=users;Integrated Security=True");
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
}
private void resetButton_Click(object sender, EventArgs e)
{
NameText.Text = "";
passwordText.Text ="";
}
private void zhuButton_Click(object sender, EventArgs e)
{
zhu z = new zhu();
this.Hide();
z.ShowDialog();
}
}
}
注册的代码:
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 登录系统与注册
{
public partial class zhu : Form
{
public zhu()
{
InitializeComponent();
}
private void zhuButton_Click(object sender, EventArgs e)
{
if (textPassword.Text == "" || textPassword2.Text == "" || textName.Text == "")
{
MessageBox.Show("注册信息不能为空!!!");
return;
}
if (!textPassword2.Text.Equals(textPassword.Text))
{
MessageBox.Show("两次输入的密码必须一致!!!");
textPassword.Text = "";
textPassword2.Text = "";
return;
}
//判断用户名是否已经被注册了
try
{
SqlDataAdapter da = new SqlDataAdapter("select * from userTest",conn);
SqlCommandBuilder bc = new SqlCommandBuilder(da);
DataSet ds = new DataSet();
da.Fill(ds, "userTest");
Object[] arr = new Object[2];
DataTable dt = ds.Tables["userTest"];
foreach (DataRow row in dt.Rows)
{
arr = row.ItemArray;
if (textName.Text.Equals(arr[0]))
{
MessageBox.Show("该用户已经被注册,请更换用户名!");
textName.Text = "";
textPassword.Text = "";
textPassword2.Text = "";
return;
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
conn.Close();
}
try
{
SqlCommand com = new SqlCommand("insert into userTest values('" + textName.Text + "','" + textPassword.Text + "')", conn);
conn.Open();
com.ExecuteNonQuery();
MessageBox.Show("恭喜!注册成功!!!");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
conn.Close();
}
}
private SqlConnection conn;
private void zhu_Load(object sender, EventArgs e)
{
conn = new SqlConnection("Data Source=localhost;Initial Catalog=users;Integrated Security=True");
}
private void resetButton_Click(object sender, EventArgs e)
{
textName.Text = "";
textPassword.Text = "";
textPassword2.Text = "";
}
private void backButton_Click(object sender, EventArgs e)
{
Form1 f = new Form1();
this.Hide();
f.ShowDialog();
}
}
}
- 用C#来写一个管理系统的登录界面
- 用C#写的一个 学生管理系统验证代码
- 用JSP写的一个用户登录界面
- html 写的一个登录界面
- 求java写的类似网吧的管理系统登录界面
- 用extjs写一个登录界面
- 用java的JFrame做一个登录系统的界面
- 《图书馆管理系统》登录界面
- C#写的简单的登录界面程序
- 如何写一个含验证码的登录界面
- jsp写一个简单的登录界面,有默认值
- 用 servlet 来创建一个用户登录界面
- 客运综合管理系统项目—登录界面的实现
- 用python写一个学生管理系统
- 用shell写一个作业管理系统
- 用标签写登录界面
- 用标签写登录界面
- 用C#做一个与SQL server数据库连接的登录界面
- PHP_语法基础
- powerdesigner 生成sql脚本
- JAVA连接各种数据库的JDBC驱动下载及连接字符串URL写法(原创加转帖)
- 启动2440的输出信息
- Idiot Programmer
- 用C#来写一个管理系统的登录界面
- Nebula3中的委托(Delegate)
- 工作笔记——Tslib的编译和触摸屏测试
- PHP_数组
- Spring Security-2.0入门教程(基础篇)转
- VC的Bug?
- pre tag
- Trap includes Interrupt and Exception
- Xpath in JavaScript (第二部分【命名空间】)