温馨提示:代码在线浏览功能只能做为源码浏览参考,不能展示项目的全部,如果想更进一步了解该代码请下载:NChat简易聊天室源码(.Net 3.5,LINQ,AJAX)
当前文件路径:NChat/NChart.DBHelper/UserHelper.cs

1using System; 2
using System.Collections.Generic; 3
using System.Linq; 4
using System.Text; 5
using System.Data.Linq; 6
using System.Web; 7
using NChat.Common; 8
//该源码下载自www.51aspx.com(51aspx.com) 9
namespace NChart.DBHelper 10
{ 11
public abstract class UserHelper 12
{ 13
public static User Login(User user) 14
{ 15
NChatDataContext context = NChatData.Instance; 16
var users = from u in context.Users 17
where u.Name == user.Name && u.Password == user.Password 18
select u; 19
if (users.Count() > 0) 20
return users.Single(); 21
else 22
{ 23
if (!IsExits(user)) 24
{ 25
Register(user); 26
return Login(user); 27
} 28
else 29
{ 30
user.ID = -1; 31
return user; 32
} 33
} 34
} 35
//5_1_a_s_p_x.c_o_m 36
37
public static bool IsExits(User user) 38
{ 39
NChatDataContext context = NChatData.Instance; 40
var users = from u in context.Users 41
where u.Name == user.Name 42
select u; 43
if (users.Count() > 0) 44
return true; 45
else 46
return false; 47
} 48
49
public static void Register(User user) 50
{ 51
NChatDataContext context = NChatData.Instance; 52
context.Users.InsertOnSubmit(user); 53
context.SubmitChanges(); 54
} 55
56
public static IQueryable<User> Users() 57
{ 58
NChatDataContext context = NChatData.Instance; 59
var users = from user in context.Users 60
select user; 61
return users; 62
} 63
} 64
} 65





}
}