Public class类源程序
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
计算机与通信工程学院
Public class类源程序
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace通讯录
{
{
class publicclass
{
public static SqlConnection createconn()
{
string connStr = "Data Source=ABLE-ABLE;Initial Catalog=tongxunlu;Integrated Security=True";
SqlConnection conn = new SqlConnection(connStr);
return conn;
}
public static DataTable gettable(string sql)
{
SqlConnection conn = createconn();
SqlDataAdapter da=new SqlDataAdapter (sql,conn);
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}
public static bool zhixingSQl(string sql)
{
SqlConnection conn = createconn();
SqlCommand cmd = new SqlCommand(sql, conn);
if (conn.State != ConnectionState.Open)
{
conn.Open();
}
if (cmd.ExecuteNonQuery() > 0)
{
return true;
}
else
{
return false;
conn.Close();
}
public static bool checkUser(string userName, string passWord)
{
string sql = "select 密码 from users where 用户名= '" + userName + "'";
DataTable dt = gettable(sql);
if (passWord == dt.Rows[0]["密¹码"].ToString().Trim())
{
return true;
}
else
{
return false;
}
}
}
}
附录二
welcome界面源程序
using System;
using System.Collections.Generic;
using ponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace通讯录
{
public partial class welcome : Form
{
public welcome()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
login lo = new login();
lo.Show();
}
private void button2_Click(object sender, EventArgs e)
{
login1 lo1 = new login1();
lo1.Show();
}
}
}
Login 界面源程序
using System;
using System.Collections.Generic;
using ponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace通讯录
{
public partial class login : Form
{
public login()
{
InitializeComponent();
}
private void buttonok_Click(object sender, EventArgs e)
{
if (textBoxname.Text.Length != 0 && textBoxpwd.Text.Length != 0)
{
if (publicclass.checkUser(textBoxname.Text.Trim(), textBoxpwd.Text.Trim())) {
main formMain = new main();
formMain.Show();
}
else
{
MessageBox.Show("用户名或密码不正确", "提示");
}
}
else
{
MessageBox.Show("用户名或¨密码不能¨为空", "提示");
}
}
private void buttoncancel_Click(object sender, EventArgs e)
{
Application.Exit();