日期:2014-05-18  浏览次数:20945 次

C#.net 关于登陆的代码
textBox1  
textBox2
 
  表为login  
   
  表的字段: 用户名,密码 登入
SQL2005 VS2005  
  想要个登陆的代码 


------解决方案--------------------
using System;
using System.Data;
using System.IO;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Text;
using System.Windows.Forms;
using SystemFramework.DAL;
using DevExpress.XtraEditors;
using VSYT.RWGL.User;

namespace VSYT.RWGL.UI
{
public partial class XFrmLogin : XtraForm
{
[DllImport("user32.dll")]
public static extern bool ReleaseCapture();

[DllImport("user32.dll")]
public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);

public const int WM_SYSCOMMAND = 0x0112;
public const int SC_MOVE = 0xF010;
public const int HTCAPTION = 0x0002;
private string filename = string.Empty;
private DataBaseLayer DataLayer;

private string name;
public XFrmLogin(DataBaseLayer Session)
{
InitializeComponent();
DataLayer = Session;
tEdtPwd.Properties.PasswordChar = '*';
//username = TedtName.Text.ToString().Trim();
}


/// <summary>
/// 本地登录配置文件
/// </summary>
public string LocalFileName
{
get { return filename; }
set { filename = value; }
}

public DataBaseLayer DBSession
{
get { return DataLayer; }
set { DataLayer = value; }
}

//public string User_Real_Name()
//{
// return name;
//}
//窗体初始化




private void XFrmLogin_MouseDown(object sender, MouseEventArgs e)
{
ReleaseCapture();
SendMessage(Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
}


//确定登陆
private void sBtnOK_Click(object sender, EventArgs e)
{


//远程登陆
if (!DataLayer.CanConnectWeb())
{
XtraMessageBox.Show("无法链接服务器,请检查网络设备!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
name = TedtName.Text.Trim();
string pwd = tEdtPwd.Text.Trim();
if (name.Equals(""))
{
XtraMessageBox.Show("请输入登录名!", "提示信息",
MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
if (pwd.Equals(""))
{
XtraMessageBox.Show("请输入密码!", "提示信息",
MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}

string sql = "select * from u_user where user_name='" + name + "'";
DataTable DTSerInfo = DataLayer.ExecuteQuery(sql);
foreach (DataRow nrow in DTSerInfo.Rows)
{
Program.RealName = nrow["USER_REAL_NAME"].ToString();
// rwmain.User_Real_Name = RealName;
}


if (DTSerInfo.Rows.Count == 0)
{
XtraMessageBox.Show("用户\"" + name + "\"不存在,请输入正确的信息!");