序:今天开始写一个算是我第一个系列的文章——高校手机签到系统。本系统结合我们学校自身的一些特点编写。这是我的毕业设计项目,写在这里算是给最后论文的时候一些点滴的记录。另外也想通过这个系列的文章找到一份工作,我知道许多大神都在博客园。我的邮箱:dugukuangshao@Gmail.com,在这个系列文章快完成的时候,我会将该项目开源并附上简历。

基本思路:根据每堂课唯一的guid标识加上当前时间,生成每5秒刷新一次的图片,再用手机客户端连接到校园网wifi再去扫描这张图片来签到。手机客户端还能从校园网上获得课程表。最后通过签到的数据还能分析课程的到课率、班级出勤率等。

由于教务处网站没有开放的接口,所以我自己实现了一个选课的系统,根据这个系统来查询课程表。选课网站构成了服务器端,采用.net平台,毕业设计自然要有些难度和挑战,所以手机客户端采用了android平台,也就是java。服务器端使用mvc4模式开发,mybatis.net作为orm的框架。

  第一部分是Authority权限系统。涉及到domain层的Membership和Organization。如图所示:Membership下存在四个类:User用户、Profile详细资料、Role角色、UsersInRoles。Organization下存在三个类:Class班级、Institution机构、UsersInInstitutions。各类之间的关系如图:

代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; namespace signin.domain.Membership
{
public partial class User
{
public Guid UserId { get; set; } //创建时插入
public String UserName { get; set; } //创建时插入
public DateTime LastActivityDate { get; set; } //关闭窗口时插入 public String Password { get; set; } //创建时插入
public String PasswordSalt { get; set; } //创建时插入
public String Email { get; set; } //创建时插入
public String PasswordQuestion { get; set; } //创建时插入
public String PasswordAnswer { get; set; } //创建时插入
public bool IsApproved { get; set; }
public bool IsIsLockedOut { get; set; } //密码错误次数超过限度时锁定
public DateTime CreateDate { get; set; }
public DateTime LastLoginDate { get; set; } //关闭窗口时插入
public DateTime LastPasswordChangedDate { get; set; } //修改密码时更新
public DateTime LastLockoutDate { get; set; } //密码错误次数超过限度时锁定
public int FailedPasswordAttemptCount { get; set; }
public DateTime FailedPasswordAttemptWindowStart { get; set; }
public int FailedPasswordAnswerAttemptCount { get; set; }
public DateTime FailedPasswordAnswerAttemptWindowStart { get; set; }
public String Comment { get; set; }
public bool IsOnline { get; set; }
} public partial class User
{
public string ConfirmPassword { get; set; }
}
}

User.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using signin.domain.Common; namespace signin.domain.Membership
{
public class Profile : User,IPager
{
public string No { get; set; } // 创建时插入
public string Nickname { get; set; } // 创建时插入
public bool Gender { get; set; } // 创建时插入
public int Age { get; set; } // 非数据库字段
public DateTime Birthday { get; set; } //生日 创建时插入
public bool Calendar { get; set; } //历法 创建时插入
public string Nation { get; set; } //民族 创建时插入
public string Address { get; set; }
public string PoliticalStatus { get; set; } //政治面貌 创建时插入
public string CellPhoneNumber { get; set; } //手机号码 创建时插入
public string IMSI { get; set; } //国际移动用户识别码
public string ImgLink { get; set; }
public bool IsBound { get; set; }
public bool IsUpdated { get; set; } #region Pager
private int pageSize = ;
private int pageCount; public int CurrentPage { get; set; }
public int PageSize
{
get { return pageSize; }
set { pageSize = value; }
}
public int RecordCount { get; set; }
public int PageCount
{
get
{
if (pageSize == )
{
return ;
}
pageCount = RecordCount / pageSize;
return (RecordCount % pageSize == ) ? pageCount : ++pageCount;
}
}
public int PageIndex { get; set; }
#endregion
}
}

Profile.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; namespace signin.domain.Membership
{
public class Role
{
public Guid RoleId { get; set; }
public string RoleName { get; set; }
public string Description { get; set; }
}
}

Role.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; namespace signin.domain.Membership
{
public class UsersInRoles
{
public Guid UserId { get; set; }
public Guid RoleId { get; set; }
}
}

UsersInRoles.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; namespace signin.domain.Organization
{
public class Institution
{
public Guid Id { get; set; }
public string Name { get; set; }
public string Type { get; set; }
public Guid SuperiorId { get; set; } //上级机构Id
public bool IsUpdated { get; set; }
}
}

Institution.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; namespace signin.domain.Organization
{
public class Class:Institution
{
public string ClassCode { get; set; }
public string Grade { get; set; } //年级
public int ClassNo { get; set; } //班号
public DateTime StartDate { get; set; }
public DateTime GraduationDate { get; set; }
public string Semesters { get; set; }
public IList<Semester> Sems { get; set; } public int getSemesterNo(DateTime date)
{
foreach (Semester semester in Sems)
{
if (DateTime.Compare(date, semester.StartDate) > && DateTime.Compare(date,semester.EndDate)<)
return semester.No;
}
return -;
}
} public class Semester
{
public int No { get; set; }
public DateTime StartDate { get; set; } //开学时间
public DateTime EndDate { get; set; }
}
}

Class.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; namespace signin.domain.Organization
{
public class UsersInInstitutions
{
public Guid UserId { get; set; }
public Guid InstitutionId { get; set; }
}
}

UsersInInstitutions.cs

Profile里的IMSI字段是手机的唯一标识,用来绑定学生的客户端,也就是一部手机只能为一个人签到。Profile继承自User,为什么是继承?Profile和User难道不是Has-A的关系,怎么是IS-A?从User的属性看,User只是一个Account,用户在这个网站上的账户。而,Profile具有完整的一个Person的属性,所以谁属于谁还不好说。这里采用继承,是因为我在查询User的sql语句中采用了联合查询,User和Profile一起返回,在Dao层的方法里使用了泛型,sqlMapper即可根据需要返回我要的User或者Profile。这样做在性能上有多大的影响我也不是太清楚,只是图省事儿,学校的学生老师也不是太多。下面是Mapper的代码:

<?xml version="1.0" encoding="utf-8" ?>
<sqlMap namespace="signin.domain" xmlns="http://ibatis.apache.org/mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<alias>
<typeAlias alias="User" type="signin.domain.Membership.User,signin.domain"/>
</alias>
<statements>
<insert id="InsertUser" parameterClass="User">
INSERT INTO [signin].[dbo].[User] ([User].[UserId],[UserName],[LastActivityDate],[Password],[PasswordSalt],[Email],[PasswordQuestion],[PasswordAnswer],[IsApproved],[IsLockedOut],[CreateDate],[LastLoginDate],[LastPasswordChangedDate],[LastLockoutDate],[FailedPasswordAttemptCount],[FailedPasswordAttemptWindowStart],[FailedPasswordAnswerAttemptCount],[FailedPasswordAnswerAttemptWindowStart],[Comment]) VALUES (#UserId#,#UserName#,getdate(),#Password#,#PasswordSalt#,#Email#,#PasswordQuestion#,#PasswordAnswer#,1,0,getdate(),getdate(),getdate(),CONVERT( datetime, '17540101', 112 ),0,CONVERT( datetime, '17540101', 112 ),0,CONVERT( datetime, '17540101', 112 ),#Comment#)
</insert>
<delete id="DeleteUser" parameterClass="User" resultClass="Int">
DELETE FROM [signin].[dbo].[User] WHERE [UserId] LIKE '%$UserId$%'
<isNotEmpty prepend="OR" property="UserName">[UserName] = #UserName#</isNotEmpty>
</delete>
<select id="SelectUserById" patameterClass="String" resultClass="signin.domain.Membership.Profile">
SELECT [User].[UserId],[UserName],[LastActivityDate],[Password],[PasswordSalt],[Email],[PasswordQuestion],[PasswordAnswer],[IsApproved],[IsLockedOut],[CreateDate],[LastLoginDate],[LastPasswordChangedDate],[LastLockoutDate],[FailedPasswordAttemptCount],[FailedPasswordAttemptWindowStart],[FailedPasswordAnswerAttemptCount],[FailedPasswordAnswerAttemptWindowStart],[Comment],[IsOnline],[No],[Nickname],[Gender],[Birthday],[Calendar],[Nation],[Address],[PoliticalStatus],[CellPhoneNumber],[IMSI],[ImgLink],[IsBound] FROM [signin].[dbo].[User] LEFT JOIN [signin].[dbo].[Profile] ON [Profile].[UserId] = [User].[UserId] WHERE [User].[UserId] LIKE '%$UserId$%'
</select>
<select id="SelectUserByNo" patameterClass="String" resultClass="signin.domain.Membership.Profile">
SELECT [User].[UserId],[UserName],[LastActivityDate],[Password],[PasswordSalt],[Email],[PasswordQuestion],[PasswordAnswer],[IsApproved],[IsLockedOut],[CreateDate],[LastLoginDate],[LastPasswordChangedDate],[LastLockoutDate],[FailedPasswordAttemptCount],[FailedPasswordAttemptWindowStart],[FailedPasswordAnswerAttemptCount],[FailedPasswordAnswerAttemptWindowStart],[Comment],[IsOnline],[No],[Nickname],[Gender],[Birthday],[Calendar],[Nation],[Address],[PoliticalStatus],[CellPhoneNumber],[IMSI],[ImgLink],[IsBound] FROM [signin].[dbo].[User] LEFT JOIN [signin].[dbo].[Profile] ON [Profile].[UserId] = [User].[UserId] WHERE [User].[No] = #No#
</select>
<select id="SelectUserByUserName" patameterClass="String" resultClass="signin.domain.Membership.Profile">
SELECT [User].[UserId],[UserName],[LastActivityDate],[Password],[PasswordSalt],[Email],[PasswordQuestion],[PasswordAnswer],[IsApproved],[IsLockedOut],[CreateDate],[LastLoginDate],[LastPasswordChangedDate],[LastLockoutDate],[FailedPasswordAttemptCount],[FailedPasswordAttemptWindowStart],[FailedPasswordAnswerAttemptCount],[FailedPasswordAnswerAttemptWindowStart],[Comment],[IsOnline],[No],[Nickname],[Gender],[Birthday],[Calendar],[Nation],[Address],[PoliticalStatus],[CellPhoneNumber],[IMSI],[ImgLink],[IsBound] FROM [signin].[dbo].[User] LEFT JOIN [signin].[dbo].[Profile] ON [Profile].[UserId] = [User].[UserId] WHERE [User].[UserName] LIKE '%'+#UserName#+'%'
</select>
<select id="SelectUserByNickname" patameterClass="String" resultClass="signin.domain.Membership.Profile">
SELECT [User].[UserId],[UserName],[LastActivityDate],[Password],[PasswordSalt],[Email],[PasswordQuestion],[PasswordAnswer],[IsApproved],[IsLockedOut],[CreateDate],[LastLoginDate],[LastPasswordChangedDate],[LastLockoutDate],[FailedPasswordAttemptCount],[FailedPasswordAttemptWindowStart],[FailedPasswordAnswerAttemptCount],[FailedPasswordAnswerAttemptWindowStart],[Comment],[IsOnline],[No],[Nickname],[Gender],[Birthday],[Calendar],[Nation],[Address],[PoliticalStatus],[CellPhoneNumber],[IMSI],[ImgLink],[IsBound] FROM [signin].[dbo].[User] LEFT JOIN [signin].[dbo].[Profile] ON [Profile].[UserId] = [User].[UserId] WHERE [Profile].[Nickname] LIKE '%'+#Nickname#+'%'
</select>
<select id="SelectAllUsers" patameterClass="String" resultClass="signin.domain.Membership.Profile">
SELECT [User].[UserId],[UserName],[LastActivityDate],[Password],[PasswordSalt],[Email],[PasswordQuestion],[PasswordAnswer],[IsApproved],[IsLockedOut],[CreateDate],[LastLoginDate],[LastPasswordChangedDate],[LastLockoutDate],[FailedPasswordAttemptCount],[FailedPasswordAttemptWindowStart],[FailedPasswordAnswerAttemptCount],[FailedPasswordAnswerAttemptWindowStart],[Comment],[IsOnline],[No],[Nickname],[Gender],[Birthday],[Calendar],[Nation],[Address],[PoliticalStatus],[CellPhoneNumber],[IMSI],[ImgLink],[IsBound] FROM [signin].[dbo].[User] LEFT JOIN [signin].[dbo].[Profile] ON [Profile].[UserId] = [User].[UserId]
</select>
<select id="SelectAllStuffs" patameterClass="String" resultClass="signin.domain.Membership.Profile">
SELECT [User].[UserId],[UserName],[LastActivityDate],[Password],[PasswordSalt],[Email],[PasswordQuestion],[PasswordAnswer],[IsApproved],[IsLockedOut],[CreateDate],[LastLoginDate],[LastPasswordChangedDate],[LastLockoutDate],[FailedPasswordAttemptCount],[FailedPasswordAttemptWindowStart],[FailedPasswordAnswerAttemptCount],[FailedPasswordAnswerAttemptWindowStart],[Comment],[IsOnline],[No],[Nickname],[Gender],[Birthday],[Calendar],[Nation],[Address],[PoliticalStatus],[CellPhoneNumber],[IMSI],[ImgLink],[IsBound] FROM [signin].[dbo].[User] LEFT JOIN [signin].[dbo].[Profile] ON [Profile].[UserId] = [User].[UserId] WHERE [User].[UserId] IN (SELECT [UserId] FROM [signin].[dbo].[UsersInRoles] JOIN [signin].[dbo].[Role] ON [UsersInRoles].[RoleId]=[Role].[RoleId] WHERE [Role].[RoleName]='教职工')
</select>
<select id="SelectStuffsByPage" parameterClass="Profile" resultClass="signin.domain.Membership.Profile">
WITH LIST AS (SELECT [User].[UserId],[UserName],[LastActivityDate],[Password],[PasswordSalt],[Email],[PasswordQuestion],[PasswordAnswer],[IsApproved],[IsLockedOut],[CreateDate],[LastLoginDate],[LastPasswordChangedDate],[LastLockoutDate],[FailedPasswordAttemptCount],[FailedPasswordAttemptWindowStart],[FailedPasswordAnswerAttemptCount],[FailedPasswordAnswerAttemptWindowStart],[Comment],[IsOnline],[No],[Nickname],[Gender],[Birthday],[Calendar],[Nation],[Address],[PoliticalStatus],[CellPhoneNumber],[IMSI],[ImgLink],[IsBound],ROW_NUMBER() OVER(ORDER BY [No] asc) AS PageIndex,RecordCount = count(1) over() FROM [signin].[dbo].[User] LEFT JOIN [signin].[dbo].[Profile] ON [Profile].[UserId] = [User].[UserId] WHERE [User].[UserId] IN (SELECT [UserId] FROM [signin].[dbo].[UsersInRoles] JOIN [signin].[dbo].[Role] ON [UsersInRoles].[RoleId]=[Role].[RoleId] WHERE [Role].[RoleName]='教职工'))
SELECT [UserId],[UserName],[LastActivityDate],[Password],[PasswordSalt],[Email],[PasswordQuestion],[PasswordAnswer],[IsApproved],[IsLockedOut],[CreateDate],[LastLoginDate],[LastPasswordChangedDate],[LastLockoutDate],[FailedPasswordAttemptCount],[FailedPasswordAttemptWindowStart],[FailedPasswordAnswerAttemptCount],[FailedPasswordAnswerAttemptWindowStart],[Comment],[IsOnline],[No],[Nickname],[Gender],[Birthday],[Calendar],[Nation],[Address],[PoliticalStatus],[CellPhoneNumber],[IMSI],[ImgLink],[IsBound],[PageIndex],[RecordCount] FROM LIST WHERE PageIndex BETWEEN (#CurrentPage#-1)*#PageSize#+1 AND #CurrentPage#*#PageSize#
</select>
<select id="SelectAllStudents" patameterClass="String" resultClass="signin.domain.Membership.Profile">
SELECT [User].[UserId],[UserName],[LastActivityDate],[Password],[PasswordSalt],[Email],[PasswordQuestion],[PasswordAnswer],[IsApproved],[IsLockedOut],[CreateDate],[LastLoginDate],[LastPasswordChangedDate],[LastLockoutDate],[FailedPasswordAttemptCount],[FailedPasswordAttemptWindowStart],[FailedPasswordAnswerAttemptCount],[FailedPasswordAnswerAttemptWindowStart],[Comment],[IsOnline],[No],[Nickname],[Gender],[Birthday],[Calendar],[Nation],[Address],[PoliticalStatus],[CellPhoneNumber],[IMSI],[ImgLink],[IsBound] FROM [signin].[dbo].[User] LEFT JOIN [signin].[dbo].[Profile] ON [Profile].[UserId] = [User].[UserId] WHERE [User].[UserId] IN (SELECT [UserId] FROM [signin].[dbo].[UsersInRoles] JOIN [signin].[dbo].[Role] ON [UsersInRoles].[RoleId]=[Role].[RoleId] WHERE [Role].[RoleName]='学生')
</select>
<select id="SelectStudentsByPage" parameterClass="Profile" resultClass="signin.domain.Membership.Profile">
WITH LIST AS (SELECT [User].[UserId],[UserName],[LastActivityDate],[Password],[PasswordSalt],[Email],[PasswordQuestion],[PasswordAnswer],[IsApproved],[IsLockedOut],[CreateDate],[LastLoginDate],[LastPasswordChangedDate],[LastLockoutDate],[FailedPasswordAttemptCount],[FailedPasswordAttemptWindowStart],[FailedPasswordAnswerAttemptCount],[FailedPasswordAnswerAttemptWindowStart],[Comment],[IsOnline],[No],[Nickname],[Gender],[Birthday],[Calendar],[Nation],[Address],[PoliticalStatus],[CellPhoneNumber],[IMSI],[ImgLink],[IsBound],ROW_NUMBER() OVER(ORDER BY [No] asc) AS PageIndex,RecordCount = count(1) over() FROM [signin].[dbo].[User] LEFT JOIN [signin].[dbo].[Profile] ON [Profile].[UserId] = [User].[UserId] WHERE [User].[UserId] IN (SELECT [UserId] FROM [signin].[dbo].[UsersInRoles] JOIN [signin].[dbo].[Role] ON [UsersInRoles].[RoleId]=[Role].[RoleId] WHERE [Role].[RoleName]='学生'))
SELECT [UserId],[UserName],[LastActivityDate],[Password],[PasswordSalt],[Email],[PasswordQuestion],[PasswordAnswer],[IsApproved],[IsLockedOut],[CreateDate],[LastLoginDate],[LastPasswordChangedDate],[LastLockoutDate],[FailedPasswordAttemptCount],[FailedPasswordAttemptWindowStart],[FailedPasswordAnswerAttemptCount],[FailedPasswordAnswerAttemptWindowStart],[Comment],[IsOnline],[No],[Nickname],[Gender],[Birthday],[Calendar],[Nation],[Address],[PoliticalStatus],[CellPhoneNumber],[IMSI],[ImgLink],[IsBound],[PageIndex],[RecordCount] FROM LIST WHERE PageIndex BETWEEN (#CurrentPage#-1)*#PageSize#+1 AND #CurrentPage#*#PageSize#
</select>
<update id="ChangePassword" parameterClass="User" resultClass="Int">
UPDATE [signin].[dbo].[User] SET [Password] = #Password#,[PasswordSalt] = #PasswordSalt#,[LastPasswordChangedDate] = getdate() WHERE [UserId] LIKE '%$UserId$%'
<isNotEmpty prepend="OR" property="UserName">[UserName] = #UserName#</isNotEmpty>
</update>
<update id="UpdateLoginRecord" parameterClass="User" resultClass="Int">
UPDATE [signin].[dbo].[User] SET [LastActivityDate] = getdate(),[LastLoginDate] = getdate() WHERE [UserId] LIKE '%$UserId$%'
<isNotEmpty prepend="OR" property="UserName">[UserName] = #UserName#</isNotEmpty>
</update>
<update id="UpdateFailedPasswordRecord" parameterClass="User" resultClass="Int">
UPDATE [signin].[dbo].[User] SET [FailedPasswordAttemptCount] = [FailedPasswordAttemptCount]+1,[FailedPasswordAttemptWindowStart] = getdate() WHERE [UserId] LIKE '%$UserId$%'
<isNotEmpty prepend="OR" property="UserName">[UserName] = #UserName#</isNotEmpty>
</update>
<update id="UpdateFailedPasswordAnswerRecord" parameterClass="User" resultClass="Int">
UPDATE [signin].[dbo].[User] SET [FailedPasswordAnswerAttemptCount] = [FailedPasswordAnswerAttemptCount]+1,[FailedPasswordAnswerAttemptWindowStart] = getdate() WHERE [UserId] LIKE '%$UserId$%'
<isNotEmpty prepend="OR" property="UserName">[UserName] = #UserName#</isNotEmpty>
</update>
<select id="IsUserNameExists" patameterClass="String" resultClass="Int">
SELECT COUNT([UserName]) FROM [signin].[dbo].[User] WHERE [UserName] = #UserName#
</select>
<select id="IsEmailExists" patameterClass="String" resultClass="Int">
SELECT COUNT([Email]) FROM [signin].[dbo].[User] WHERE [Email] LIKE '%'+#Email#+'%'
</select>
<select id="GetInstitutionsForUser" parameterClass="String" resultClass="signin.domain.Organization.Institution">
SELECT Institution.* FROM [Signin].[dbo].[Institution] JOIN [Signin].[dbo].[PeopleInInstitutions] ON [PeopleInInstitutions].InstitutionId = [Institution].Id JOIN [Signin].[dbo].[User] ON [User].UserId = [PeopleInInstitutions].UserId WHERE [User].UserName = #UserName#
</select>
<select id="GetClassesForUser" parameterClass="String" resultClass="signin.domain.Organization.Institution">
SELECT [Institution].[Id],[ClassCode],[Nickname],[SuperiorId],[Grade],[ClassNo],[StartDate],[GraduationDate],[Semesters] FROM [signin].[dbo].[Class] JOIN [signin].[dbo].[Institution] ON [Institution].Id = [Class].Id JOIN [Signin].[dbo].[PeopleInInstitutions] ON [PeopleInInstitutions].InstitutionId = [Institution].Id JOIN [Signin].[dbo].[User] ON [User].UserId = [PeopleInInstitutions].UserId WHERE [User].UserName = #UserName#
</select>
</statements>
</sqlMap>

User.Xml

<?xml version="1.0" encoding="utf-8" ?>
<sqlMap namespace="signin.domain" xmlns="http://ibatis.apache.org/mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<alias>
<typeAlias alias="Profile" type="signin.domain.Membership.Profile,signin.domain"/>
</alias>
<statements>
<insert id="AddProfileToUser" parameterClass="Profile">
INSERT IntO [signin].[dbo].[Profile] ([UserId],[No],[Nickname],[Gender],[Birthday],[Calendar],[Nation],[Address],[PoliticalStatus],[CellPhoneNumber],[IMSI],[ImgLink],[IsBound]) VALUES (#UserId#,#No#,#Nickname#,#Gender#,#Birthday#,#Calendar#,#Nation#,#Address#,#PoliticalStatus#,#CellPhoneNumber#,#IMSI#,#ImgLink#,0)
</insert>
<delete id="RemoveProfileForUser" parameterClass="Profile" resultClass="Int">
DELETE FROM [signin].[dbo].[Profile] WHERE [UserId] LIKE '%$UserId$%'
<isNotEmpty prepend="OR" property="No">[No] = #No#</isNotEmpty>
</delete>
<update id="UpdateProfileForUser" parameterClass="Profile" resultClass="Int">
UPDATE [signin].[dbo].[Profile]
SET [IsUpdated] = 1
<isNotEmpty prepend="," property="No">[No] = #No# </isNotEmpty>
<isNotEmpty prepend="," property="Nickname">[Nickname] = #Nickname# </isNotEmpty>
<isEqual prepend="," property="Gender" compareValue="true">[Gender] = #Gender#</isEqual>
<isEqual prepend="," property="Gender" compareValue="false">[Gender] = #Gender#</isEqual>
<isNotNull prepend="," property="Birthday">[Birthday] = #Birthday#</isNotNull>
<isEqual prepend="," property="Calendar" compareValue="true">[Calendar] = #Calendar#</isEqual>
<isEqual prepend="," property="Calendar" compareValue="false">[Calendar] = #Calendar#</isEqual>
<isNotEmpty prepend="," property="Nation">[Nation] = #Nation#</isNotEmpty>
<isNotEmpty prepend="," property="Address">[Address] = #Address#</isNotEmpty>
<isNotEmpty prepend="," property="PoliticalStatus">[PoliticalStatus] = #PoliticalStatus#</isNotEmpty>
<isNotEmpty prepend="," property="CellPhoneNumber">[CellPhoneNumber] = #CellPhoneNumber#</isNotEmpty>
<isNotEmpty prepend="," property="IMSI">[IMSI] = #IMSI#</isNotEmpty>
<isNotEmpty prepend="," property="ImgLink">[ImgLink] = #ImgLink#</isNotEmpty>
<isEqual prepend="," property="IsBound" compareValue="true">[IsBound] = #IsBound#</isEqual>
<isEqual prepend="," property="IsBound" compareValue="false">[IsBound] = #IsBound#</isEqual> WHERE [UserId] LIKE '%$UserId$%'
</update>
<select id="IsProfileNoExists" patameterClass="String" resultClass="Boolean">
SELECT COUNT([No]) FROM [signin].[dbo].[Profile] WHERE [No] = #No#
</select>
<select id="IsProfileIMSIExists" patameterClass="String" resultClass="Boolean">
SELECT COUNT([IMSI]) FROM [signin].[dbo].[Profile] WHERE [IMSI] LIKE = #IMSI#
</select>
</statements>
</sqlMap>

Profile.xml

<?xml version="1.0" encoding="utf-8" ?>
<sqlMap namespace="signin.domain" xmlns="http://ibatis.apache.org/mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<alias>
<typeAlias alias="Role" type="signin.domain.Membership.Role,signin.domain"/>
</alias>
<statements>
<insert id="CreateRole" parameterClass="Role">
INSERT IntO [signin].[dbo].[Role] ([RoleId],[RoleName],[Description]) VALUES (#RoleId#,#RoleName#,#Description#)
</insert>
<delete id="DeleteRole" parameterClass="Role" resultClass="Int">
DELETE FROM [signin].[dbo].[Role] WHERE [RoleId] LIKE '%$RoleId$%'
<isNotEmpty prepend="OR" property="RoleName">[RoleName] = #RoleName#</isNotEmpty>
</delete>
<insert id="AddUserToRole" parameterClass="System.Collections.IDictionary">
INSERT IntO [signin].[dbo].[UsersInRoles] ([UserId],[RoleId]) SELECT [UserId],[RoleId] FROM [signin].[dbo].[User],[signin].[dbo].[Role] WHERE [UserName] = #UserName# AND [RoleName] = #RoleName#
</insert>
<select id="GetUsersInRole" parameterClass="String" resultClass="signin.domain.Membership.User">
SELECT [signin].[dbo].[User].* FROM [signin].[dbo].[Role] JOIN [signin].[dbo].[UsersInRoles] ON [Role].RoleId = [UsersInRoles].RoleId JOIN [signin].[dbo].[User] ON [UsersInRoles].UserId = [User].UserId WHERE [Role].RoleName = #RoleName#
</select>
<select id="GetRolesForUser" parameterClass="String" resultClass="Role">
SELECT [signin].[dbo].[Role].* FROM [signin].[dbo].[Role] JOIN [signin].[dbo].[UsersInRoles] ON [Role].RoleId = [UsersInRoles].RoleId JOIN [signin].[dbo].[User] ON [UsersInRoles].UserId = [User].UserId WHERE [User].UserName = #UserName#
</select>
<select id="IsUserInRole" parameterClass="System.Collections.IDictionary" resultClass="Boolean">
SELECT COUNT([UserName]) FROM [signin].[dbo].[Role] JOIN [signin].[dbo].[UsersInRoles] ON [Role].RoleId = [UsersInRoles].RoleId JOIN [signin].[dbo].[User] ON [UsersInRoles].UserId = [User].UserId WHERE [Role].RoleName = #RoleName# AND [User].[UserName] = #UserName#
</select>
<delete id="RemoveUserFromRole" parameterClass="System.Collections.IDictionary" resultClass="Int">
DELETE FROM [signin].[dbo].[UsersInRoles] FROM [signin].[dbo].[Role] JOIN [signin].[dbo].[UsersInRoles] ON [Role].RoleId = [UsersInRoles].RoleId JOIN [signin].[dbo].[User] ON [UsersInRoles].UserId = [User].UserId WHERE [Role].RoleName = #RoleName# AND [User].[UserName] = #UserName#
</delete>
<select id="RoleExists" parameterClass="String" resultClass="Int">
SELECT COUNT([RoleName]) FROM [signin].[dbo].[Role] WHERE [RoleName] = #RoleName#
</select>
<select id="GetAllRoles" resultClass="Role">
SELECT * FROM [signin].[dbo].[Role]
</select>
</statements>
</sqlMap>

Role.xml

<?xml version="1.0" encoding="utf-8" ?>
<sqlMap namespace="signin.domain" xmlns="http://ibatis.apache.org/mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<alias>
<typeAlias alias="Institution" type="signin.domain.Organization.Institution,signin.domain"/>
<typeAlias alias="UsersInInstitutions" type="signin.domain.Organization.UsersInInstitutions,signin.domain"/>
</alias>
<statements>
<insert id="InsertInstitution" parameterClass="Institution">
INSERT INTO [signin].[dbo].[Institution] ([Id],[Name],[Type]
<isNotEqual prepend="," property="SuperiorId" compareValue="00000000-0000-0000-0000-000000000000">[SuperiorId]</isNotEqual>)
VALUES (#Id#,#Name#,#Type#
<isNotEqual prepend="," property="SuperiorId" compareValue="00000000-0000-0000-0000-000000000000">#SuperiorId#</isNotEqual>)
</insert>
<delete id="DeleteInstitution" parameterClass="Institution" resultClass="Int">
DELETE FROM [signin].[dbo].[Institution] WHERE [Id] LIKE '%$Id$%'
<isNotEmpty prepend="OR" property="Name">[Name] = #Name#</isNotEmpty>
</delete>
<update id="UpdateInstitution" parameterClass="Institution" resultClass="Int">
UPDATE [signin].[dbo].[Institution] SET [IsUpdated] = 1
<isNotEmpty prepend="," property="Name">[Name] = #Name#</isNotEmpty>
<isNotEmpty prepend="," property="Type">[Type] = #Type#</isNotEmpty>
<isNotEqual prepend="," property="SuperiorId" compareValue="00000000-0000-0000-0000-000000000000">SuperiorId = #SuperiorId#</isNotEqual>WHERE [Id] LIKE '%$Id$%'
</update>
<select id="SelectInstitutionById" parameterClass="string" resultClass="Institution">
SELECT [Id],[Name],[Type],[SuperiorId] FROM [signin].[dbo].[Institution] WHERE [Id] LIKE '%$Id$%'
</select>
<select id="SelectInstitutionByName" parameterClass="string" resultClass="Institution">
SELECT [Id],[Name],[Type],[SuperiorId] FROM [signin].[dbo].[Institution] WHERE [Name] LIKE '%'+#Name#+'%'
</select>
<select id="SelectInstitutionsByType" parameterClass="string" resultClass="Institution">
SELECT [Id],[Name],[Type],[SuperiorId] FROM [signin].[dbo].[Institution] WHERE [Type] LIKE '%'+#Type#+'%'
</select>
<select id="SelectInstitutionsBySuperiorId" parameterClass="string" resultClass="Institution">
SELECT [Id],[Name],[Type],[SuperiorId] FROM [signin].[dbo].[Institution] WHERE [SuperiorId] LIKE '%$SuperiorId$%'
</select>
<select id="SelectAllInstitutions" resultClass="Institution">
SELECT [Id],[Name],[Type],[SuperiorId] FROM [signin].[dbo].[Institution]
</select>
<select id="IsInstitutionNameExists" parameterClass="string" resultClass="Int">
SELECT COUNT([Name]) FROM [signin].[dbo].[Institution] WHERE [Name] = #Name#
</select> <insert id="AddUserToInstitution" parameterClass="System.Collections.IDictionary">
INSERT INTO [signin].[dbo].[UsersInInstitutions] ([UserId],[InstitutionId]) SELECT [UserId],[Id] FROM [signin].[dbo].[Profile],[signin].[dbo].[Institution] WHERE [signin].[dbo].[Profile].[No] = #UserNo# AND [signin].[dbo].[Institution].[Name] = #InstitutionName#
</insert>
<select id="GetStuffsInInstitution" parameterClass="string" resultClass="signin.domain.Membership.Profile">
SELECT [signin].[dbo].[Profile].* FROM [signin].[dbo].[Institution] JOIN [signin].[dbo].[UsersInInstitutions] ON [UsersInInstitutions].[InstitutionId] = [Institution].[Id] JOIN [signin].[dbo].[Profile] ON [Profile].[UserId] =[UsersInInstitutions].[UserId] JOIN [signin].[dbo].[UsersInRoles] ON [UsersInRoles].[UserId] = [Profile].[UserId] JOIN [signin].[dbo].[Role] ON [Role].[RoleId] = [UsersInRoles].[RoleId] WHERE [Institution].[Name] = #Name# AND [Role].[RoleName] = '教职工'
</select>
<select id="GetStudentsInClass" parameterClass="String" resultClass="signin.domain.Membership.Profile">
SELECT [signin].[dbo].[Profile].* FROM [signin].[dbo].[Institution] JOIN [signin].[dbo].[UsersInInstitutions] ON [UsersInInstitutions].[InstitutionId] = [Institution].[Id] JOIN [signin].[dbo].[Profile] ON [Profile].[UserId] =[UsersInInstitutions].[UserId] JOIN [signin].[dbo].[UsersInRoles] ON [UsersInRoles].[UserId] = [Profile].[UserId] JOIN [signin].[dbo].[Role] ON [Role].[RoleId] = [UsersInRoles].[RoleId] WHERE [Institution].[Name] = #Name# AND [Role].[RoleName] = '学生'
</select>
<select id="IsUserInInstitution" parameterClass="System.Collections.IDictionary" resultClass="Boolean">
SELECT COUNT([signin].[dbo].[Profile].[Nickname]) FROM [signin].[dbo].[Institution] JOIN [signin].[dbo].[StuffsInInstitutions] ON [Institution].Id = [StuffsInInstitutions].InstitutionId JOIN [signin].[dbo].[Profile] ON [StuffsInInstitutions].UserId = [Profile].UserId WHERE [Institution].Name = #InstitutionName# AND [Profile].[No] = #UserNo#
</select>
<delete id="RemoveUserFromInstitution" parameterClass="System.Collections.IDictionary" resultClass="Int">
DELETE FROM [signin].[dbo].[StuffsInInstitutions] FROM [signin].[dbo].[Institution] JOIN [signin].[dbo].[StuffsInInstitutions] ON [Institution].Id = [StuffsInInstitutions].InstitutionId JOIN [signin].[dbo].[Profile] ON [StuffsInInstitutions].UserId = [Profile].UserId WHERE [Institution].Name = #InstitutionName# AND [Profile].[No] = #UserNo#
</delete>
</statements>
</sqlMap>

Institution.xml

<?xml version="1.0" encoding="utf-8" ?>
<sqlMap namespace="signin.domain" xmlns="http://ibatis.apache.org/mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<alias>
<typeAlias alias="Class" type="signin.domain.Organization.Class,signin.domain"/>
</alias>
<statements>
<insert id="InsertClass" parameterClass="Class">
INSERT INTO [signin].[dbo].[Institution] ([Id],[Name],[Type]
<isNotEqual prepend="," property="SuperiorId" compareValue="00000000-0000-0000-0000-000000000000">[SuperiorId]</isNotEqual>)
VALUES (#Id#,#Name#,'班级'
<isNotEqual prepend="," property="SuperiorId" compareValue="00000000-0000-0000-0000-000000000000">#SuperiorId#</isNotEqual>)
INSERT INTO [signin].[dbo].[Class] ([Id],[ClassCode],[Grade],[ClassNo]
<isNotEqual prepend="," property="StartDate" compareValue="0001/1/1 0:00:00">[StartDate]</isNotEqual>
<isNotEqual prepend="," property="GraduationDate" compareValue="0001/1/1 0:00:00">[GraduationDate]</isNotEqual>
<isNotEmpty prepend="," property="Semester">[Semesters]</isNotEmpty>) VALUES (#Id#,#ClassCode#,#Grade#,#ClassNo#
<isNotEqual prepend="," property="StartDate" compareValue="0001/1/1 0:00:00">#StartDate#</isNotEqual>
<isNotEqual prepend="," property="GraduationDate" compareValue="0001/1/1 0:00:00">#GraduationDate#</isNotEqual>
<isNotEmpty prepend="," property="Semester">#Semesters#</isNotEmpty>)
</insert>
<delete id="DeleteClass" parameterClass="Class" resultClass="Int">
DELETE FROM [signin].[dbo].[Institution],[signin].[dbo].[Class] JOIN [signin].[dbo].[Class] ON [Institution].Id = [Class].Id WHERE [Institution].Id LIKE '%$Id$%'
<isNotEmpty prepend="OR" property="Name">[Institution].[Name] = #Name#</isNotEmpty>
<isNotEmpty prepend="OR" property="No">[Class].[ClassCode] = #ClassCode#</isNotEmpty>
</delete>
<update id="UpdateClass" parameterClass="Class" resultClass="Int">
UPDATE [signin].[dbo].[Institution] SET [IsUpdated] = 1
<isNotEmpty prepend="," property="Name">[Name] = #Name#</isNotEmpty>
<isNotEmpty prepend="," property="Type">[Type] = #Type#</isNotEmpty>
<isNotEqual prepend="," property="SuperiorId" compareValue="00000000-0000-0000-0000-000000000000">SuperiorId = #SuperiorId#</isNotEqual>WHERE [Id] LIKE '%$Id$%'
UPDATE [signin].[dbo].[Class] SET [IsUpdated] = 1
<isNotEmpty prepend="," property="No">[ClassCode] = #ClassCode#</isNotEmpty>
<isNotEmpty prepend="," property="Grade">[Grade] = #Grade#</isNotEmpty>
<isNotNull prepend="," property="ClassNo">[ClassNo] = #ClassNo#</isNotNull>
<isNotEqual prepend="," property="StartDate" compareValue="0001/1/1 0:00:00">[StartDate] = #StartDate#</isNotEqual>
<isNotEqual prepend="," property="GraduationDate" compareValue="0001/1/1 0:00:00">[GraduationDate] = #GraduationDate#</isNotEqual>
<isNotEmpty prepend="," property="Semester">[Semesters] = #Semesters#</isNotEmpty>
WHERE [Id] LIKE '%$Id$%'
</update>
<select id="SelectClassById" parameterClass="string" resultClass="Class">
SELECT [Institution].[Id],[ClassCode],[Name],[SuperiorId],[Grade],[ClassNo],[StartDate],[GraduationDate],[Semesters] FROM [signin].[dbo].[Class] JOIN [signin].[dbo].[Institution] ON [Institution].Id = [Class].Id WHERE [Institution].[Id] LIKE '%$Id$%'
</select>
<select id="SelectClassByNo" parameterClass="string" resultClass="Class">
SELECT [Institution].[Id],[ClassCode],[Name],[SuperiorId],[Grade],[ClassNo],[StartDate],[GraduationDate],[Semesters] FROM [signin].[dbo].[Class] JOIN [signin].[dbo].[Institution] ON [Institution].Id = [Class].Id WHERE [Class].[ClassCode] = #ClassCode#
</select>
<select id="SelectClassByName" parameterClass="string" resultClass="Class">
SELECT [Institution].[Id],[ClassCode],[Name],[SuperiorId],[Grade],[ClassNo],[StartDate],[GraduationDate],[Semesters] FROM [signin].[dbo].[Class] JOIN [signin].[dbo].[Institution] ON [Institution].Id = [Class].Id WHERE [Institution].[Name] LIKE '%'+#Name#+'%'
</select>
<select id="SelectClassesBySuperiorId" parameterClass="string" resultClass="Class">
SELECT [Institution].[Id],[ClassCode],[Name],[SuperiorId],[Grade],[ClassNo],[StartDate],[GraduationDate],[Semesters] FROM [signin].[dbo].[Class] JOIN [signin].[dbo].[Institution] ON [Institution].Id = [Class].Id WHERE [Institution].[SuperiorId] LIKE '%$SuperiorId$%'
</select>
<select id="SelectAllClasses" resultClass="Class">
SELECT [Id],[ClassCode],[Name],[SuperiorId],[Grade],[ClassNo],[StartDate],[GraduationDate],[Semesters] FROM [signin].[dbo].[Class] JOIN [signin].[dbo].[Institution] ON [Institution].Id = [Class].Id
</select>
<select id="IsClassCodeExists" parameterClass="string" resultClass="Int">
SELECT COUNT([ClassCode]) FROM [signin].[dbo].[Class] WHERE [ClassCode] = #ClassCode#
</select>
<select id="IsClassNameExists" parameterClass="string" resultClass="Int">
SELECT COUNT([Name]) FROM [signin].[dbo].[Institution] WHERE [Name] = #Name#
</select>
</statements>
</sqlMap>

Class.xml

  Dao层,先说说Mybatis怎么回事儿。做Jsp的时候接触到了Mybatis,原来开发.net的时候orm都是自带的ef,后来知道了Mybatis也有.net的版本才开始使用。两者性能方面没有比较过,只是ef的linq查询个人觉得还是没sql方便。Mybatis配置:

<?xml version="1.0" encoding="utf-8"?>
<sqlMapConfig
xmlns="http://ibatis.apache.org/dataMapper"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <settings>
<setting useStatementNamespaces="false"/>
</settings> <providers embedded="signin.dao.providers.config,signin.dao"/> <!-- Database connection information -->
<database>
<provider name="sqlServer2008"/>
<dataSource name="iBatisNet" connectionString="data source=.;database=signin;user id=root;password=123456;Connect Timeout=2000"/>
</database> <sqlMaps>
<sqlMap embedded="signin.domain.Membership.Mapper.Profile.xml,signin.domain" />
<sqlMap embedded="signin.domain.Membership.Mapper.Role.xml,signin.domain" />
<sqlMap embedded="signin.domain.Membership.Mapper.User.xml,signin.domain" />
<sqlMap embedded="signin.domain.Organization.Mapper.Class.xml,signin.domain" />
<sqlMap embedded="signin.domain.Organization.Mapper.Institution.xml,signin.domain" />
<sqlMap embedded="signin.domain.CurriculumSchedule.Mapper.Course.xml,signin.domain" />
<sqlMap embedded="signin.domain.CurriculumSchedule.Mapper.Selection.xml,signin.domain" />
<sqlMap embedded="signin.domain.CurriculumSchedule.Mapper.Schedule.xml,signin.domain" />
<sqlMap embedded="signin.domain.Signin.Mapper.Sign.xml,signin.domain" />
</sqlMaps> </sqlMapConfig>

SqlMapper.config

MybatisUtil:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; using IBatisNet.DataMapper;
using IBatisNet.DataMapper.Configuration; namespace signin.dao
{
public abstract class MybatisUtil
{
private static ISqlMapper sqlMapper; public static ISqlMapper SqlMapper
{
get { return MybatisUtil.sqlMapper; }
set { MybatisUtil.sqlMapper = value; }
} static MybatisUtil()
{ string path = "";
String AssemblyPath = System.Reflection.Assembly.GetExecutingAssembly().CodeBase;
String AssemblyDir = System.IO.Path.GetDirectoryName(AssemblyPath);
AssemblyDir = AssemblyDir.Replace("file:\\", "");
path = AssemblyDir + "\\"; try
{
DomSqlMapBuilder builder = new DomSqlMapBuilder();
String filePath=path+ @"SqlMap.config";
sqlMapper = builder.Configure(filePath);
}
catch (Exception ex)
{
throw new Exception("SqlMap.config文件错误", ex);
}
}
}
}

MybatisUtil.cs

数据访问接口:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using signin.domain.Membership;
using Web.Util;
using signin.domain.Organization;
using System.Web.Script.Serialization; namespace signin.dao.Membership
{
public class UserDao:MybatisUtil
{
#region 增
/// <summary>
/// 添加一个用户
/// </summary>
/// <param name="user">用户实例</param>
/// <returns>返回用户Id</returns>
public Guid Insert(User user)
{
user.UserId = Guid.NewGuid();
string userName = user.UserName;
SecUtility.CheckParameter(ref userName, true, true, true, , "user.UserName");
if (IsUserNameExists(userName))
throw new Exception("there is a user named " + userName);
if (IsEmailExists(user.Email))
throw new Exception("there is a user whose email is:" + user.Email);
SqlMapper.Insert("InsertUser", user);
return user.UserId;
}
#endregion #region 删
/// <summary>
/// 删除一个用户
/// </summary>
/// <param name="user">用户实例</param>
/// <returns>返回受影响行数</returns>
public int Delete(User user)
{
if (user.UserId == Guid.Empty)
{
if (user.UserName == null)
{
throw new ArgumentNullException("user.UserId and user.UserName");
}
else
{
user.UserName = user.UserName.Trim();
if (user.UserName.Length < )
{throw new ArgumentException("user.UserId and user.UserName_can_not_be_empty");
}
}
}
return (int)SqlMapper.Delete("DeleteUser", user);
} /// <summary>
/// 删除一个用户
/// </summary>
/// <param name="userId">用户Id</param>
/// <returns>返回受影响行数</returns>
public int Delete(Guid userId)
{
if (userId == Guid.Empty)
throw new ArgumentNullException("userId");
User user = new User { UserId = userId };
return Delete(user);
} /// <summary>
/// 删除一个用户
/// </summary>
/// <param name="userName">用户名</param>
/// <returns>返回受影响行数</returns>
public int Delete(string userName)
{
SecUtility.CheckParameter(ref userName, true, true, true, , "userName");
User user = new User { UserName = userName };
return Delete(user);
}
#endregion #region 查
/// <summary>
/// 通过用户Id得到一个用户实例
/// </summary>
/// <param name="userId">用户Id</param>
/// <returns>User</returns>
public T SelectById<T>(Guid userId) where T : User
{
if (userId == Guid.Empty)
throw new ArgumentNullException("userId");
return SqlMapper.QueryForObject<T>("SelectUserById", userId.ToString());
} /// <summary>
/// 通过编号获得用户实例
/// </summary>
/// <param name="no">编号</param>
/// <returns></returns>
public IList<T> SelectByNo<T>(string no) where T : User
{
SecUtility.CheckParameter(ref no, true, true, true, , "no");
return SqlMapper.QueryForList<T>("SelectUserByUserNo", no);
} /// <summary>
/// 通过用户名获得用户实例
/// </summary>
/// <param name="userName">用户名</param>
/// <returns></returns>
public IList<T> SelectByName<T>(string userName) where T : User
{
SecUtility.CheckParameter(ref userName, true, true, true, , "userName");
return SqlMapper.QueryForList<T>("SelectUserByUserName", userName);
} /// <summary>
/// 通过昵称获得用户实例
/// </summary>
/// <param name="nickname">昵称</param>
/// <returns></returns>
public IList<T> SelectByNickname<T>(string nickname) where T : User
{
SecUtility.CheckParameter(ref nickname, true, true, true, , "nickname");
return SqlMapper.QueryForList<T>("SelectUserByNickname", nickname);
} /// <summary>
/// 得到所用的用户实例
/// </summary>
/// <returns></returns>
public IList<T> SelectAll<T>() where T : User
{
return SqlMapper.QueryForList<T>("SelectAllUsers", null);
} /// <summary>
/// SelectAllStuffs
/// </summary>
/// <returns></returns>
public IList<T> SelectAllStuffs<T>() where T : User
{
return SqlMapper.QueryForList<T>("SelectAllStuffs", null);
} /// <summary>
/// SelectStuffsByPage
/// </summary>
/// <returns></returns>
public IList<T> SelectStuffsByPage<T>(Profile profile) where T : User
{
return SqlMapper.QueryForList<T>("SelectStuffsByPage", profile);
} /// <summary>
/// SelectAllStudents
/// </summary>
/// <returns></returns>
public IList<T> SelectAllStudents<T>() where T : User
{
return SqlMapper.QueryForList<T>("SelectAllStudents", null);
} /// <summary>
/// SelectStudentsByPage
/// </summary>
/// <returns></returns>
public IList<T> SelectStudentsByPage<T>(Profile profile) where T : User
{
return SqlMapper.QueryForList<T>("SelectStudentsByPage", profile);
}
#endregion #region 改
/// <summary>
/// 修改密码
/// </summary>
/// <param name="user">用户实例</param>
/// <returns>返回受影响行数</returns>
public int ChangePassword(User user)
{
if (user.UserId == Guid.Empty)
{
if (user.UserName == null)
{
throw new ArgumentNullException("user.UserId and user.UserName");
}
else
{
user.UserName = user.UserName.Trim();
if (user.UserName.Length < )
{
              throw new ArgumentException("user.UserId and user.UserName_can_not_be_empty");
}
}
}
return (int)SqlMapper.Update("ChangePassword", user);
} /// <summary>
/// 修改密码
/// </summary>
/// <param name="userId">用户Id</param>
/// <param name="password">密码</param>
/// <param name="passwordSalt">密钥</param>
/// <returns>返回受影响行数</returns>
public int ChangePassword(Guid userId,string password,string passwordSalt)
{
if (userId == Guid.Empty)
throw new ArgumentNullException("userId");
SecUtility.CheckPasswordParameter(ref password, , "password");
SecUtility.CheckPasswordParameter(ref passwordSalt, , "passwordSalt");
User user = new User { UserId = userId, Password = password, PasswordSalt = passwordSalt };
return ChangePassword(user);
} /// <summary>
/// 修改密码
/// </summary>
/// <param name="userName">用户名</param>
/// <param name="password">密码</param>
/// <param name="passwordSalt">密钥</param>
/// <returns>返回受影响行数</returns>
public int ChangePassword(string userName, string password, string passwordSalt)
{
SecUtility.CheckParameter(ref userName, true, true, true, , "userName");
SecUtility.CheckPasswordParameter(ref password, , "password");
SecUtility.CheckPasswordParameter(ref passwordSalt, , "passwordSalt");
User user = new User { UserName=userName, Password = password, PasswordSalt = passwordSalt };
return ChangePassword(user);
} /// <summary>
/// 登录记录
/// </summary>
/// <param name="user">用户实例</param>
/// <returns>返回受影响行数</returns>
public int UpdateLoginRecord(User user)
{
if (user.UserId == Guid.Empty)
{
if (user.UserName == null)
{throw new ArgumentNullException("user.UserId and user.UserName");
}
else
{
user.UserName = user.UserName.Trim();
if (user.UserName.Length < )
{throw new ArgumentException("user.UserId and user.UserName_can_not_be_empty");
}
}
}
return (int)SqlMapper.Update("UpdateLoginRecord", user);
} /// <summary>
/// 登录记录
/// </summary>
/// <param name="userId">用户Id</param>
/// <returns>返回受影响行数</returns>
public int UpdateLoginRecord(Guid userId)
{
if (userId == Guid.Empty)
throw new ArgumentNullException("userId");
User user = new User { UserId = userId };
return UpdateLoginRecord(user);
} /// <summary>
/// 登录记录
/// </summary>
/// <param name="userName">用户名</param>
/// <returns>返回受影响行数</returns>
public int UpdateLoginRecord(string userName)
{
SecUtility.CheckParameter(ref userName, true, true, true, , "userName");
User user = new User { UserName=userName };
return UpdateLoginRecord(user);
} /// <summary>
/// 密码错误记录
/// </summary>
/// <param name="user">用户实例</param>
/// <returns>返回受影响行数</returns>
public int UpdateFailedPasswordRecord(User user)
{
if (user.UserId == Guid.Empty)
{
if (user.UserName == null)
{
throw new ArgumentNullException("user.UserId and user.UserName");
}
else
{
user.UserName = user.UserName.Trim();
if (user.UserName.Length < )
{throw new ArgumentException("user.UserId and user.UserName_can_not_be_empty");
}
}
}
return (int)SqlMapper.Update("UpdateFailedPasswordRecord", user);
} /// <summary>
/// 密码错误记录
/// </summary>
/// <param name="userId">用户Id</param>
/// <returns>返回受影响行数</returns>
public int UpdateFailedPasswordRecord(Guid userId)
{
if (userId == Guid.Empty)
throw new ArgumentNullException("userId");
User user = new User { UserId = userId };
return (int)UpdateFailedPasswordRecord(user);
} /// <summary>
/// 密码错误记录
/// </summary>
/// <param name="userId">用户名</param>
/// <returns>返回受影响行数</returns>
public int UpdateFailedPasswordRecord(string userName)
{
SecUtility.CheckParameter(ref userName, true, true, true, , "userName");
User user = new User { UserName=userName };
return (int)UpdateFailedPasswordRecord(user);
} /// <summary>
/// 密保答案错误记录
/// </summary>
/// <param name="user">用户实例</param>
/// <returns>返回受影响行数</returns>
public int UpdateFailedPasswordAnswerRecord(User user)
{
if (user.UserId == Guid.Empty)
{
if (user.UserName == null)
{throw new ArgumentNullException("user.UserId and user.UserName");
}
else
{
user.UserName = user.UserName.Trim();
if (user.UserName.Length < )
{throw new ArgumentException("user.UserId and user.UserName_can_not_be_empty");
}
}
}
return (int)SqlMapper.Update("UpdateFailedPasswordAnswerRecord", user);
} /// <summary>
/// 密保答案错误记录
/// </summary>
/// <param name="userId">用户Id</param>
/// <returns>返回受影响行数</returns>
public int UpdateFailedPasswordAnswerRecord(Guid userId)
{
if (userId == Guid.Empty)
throw new ArgumentNullException("userId");
User user = new User { UserId = userId };
return (int)UpdateFailedPasswordAnswerRecord(user);
} /// <summary>
/// 密保答案错误记录
/// </summary>
/// <param name="userId">用户名</param>
/// <returns>返回受影响行数</returns>
public int UpdateFailedPasswordAnswerRecord(string userName)
{
SecUtility.CheckParameter(ref userName, true, true, true, , "userName");
User user = new User { UserName=userName };
return (int)UpdateFailedPasswordAnswerRecord(user);
}
#endregion #region 唯一性判断
/// <summary>
/// 用户名是否存在
/// </summary>
/// <param name="userName">用户名</param>
/// <returns>存在返回true,否则返回false</returns>
public bool IsUserNameExists(string userName)
{
SecUtility.CheckParameter(ref userName, true, true, true, , "userName");
if (SqlMapper.QueryForObject<int>("IsUserNameExists", userName) > )
return true;
else
return false;
} /// <summary>
/// 电子邮箱是否存在
/// </summary>
/// <param name="userName">电子邮箱</param>
/// <returns>存在返回true,否则返回false</returns>
public bool IsEmailExists(string email)
{
SecUtility.CheckParameter(ref email, true, true, true, , "email");
if (SqlMapper.QueryForObject<int>("IsEmailExists", email) > )
return true;
else
return false;
}
#endregion #region 机构查询
public IList<Institution> GetInstitutionsForUser(string userName)
{
SecUtility.CheckParameter(ref userName, true, true, true, , "userName");
return SqlMapper.QueryForList<Institution>("GetInstitutionsForUser", userName);
} public IList<Class> GetClassesForUser(string userName)
{
SecUtility.CheckParameter(ref userName, true, true, true, , "userName");
IList<Class> classes = SqlMapper.QueryForList<Class>("GetClassesForUser", userName);
JavaScriptSerializer ser = new JavaScriptSerializer();
foreach (Class cls in classes)
{
if (cls.Semesters != null)
cls.Sems = ser.Deserialize<IList<Semester>>(cls.Semesters);
else
{
cls.Sems = new List<Semester>();
for (int i = ; i < ; i++)
{
Semester semester = new Semester();
semester.No = i + ;
cls.Sems.Add(semester);
}
}
}
return classes;
}
#endregion
}
}

如上public T SelectById<T>(Guid userId) where T : User等查询方法使用了泛型来在我需要的时候返回User或者Profile。

  限于时间和篇幅第一篇就在这里结束了,权限系统的后台部分就是如此。下次更新前台部分的内容。如前所述,完整的项目稍后才能开源,在这之前有需要的请邮箱联系,欢迎大家和我来一起完成这个签到系统。

高校手机签到系统——第一部分Authority权限系统(上)的更多相关文章

  1. 高校手机签到系统——第一部分Authority权限系统(下)

    很抱歉,之前寝室光纤断了,所以到现在才更新这个系列的第二篇博客.点击访问高校手机签到系统——第一部分Authority权限系统(上) 这几天我反思了一下上一篇写博上的方式,一味的贴代码式的,是否应该更 ...

  2. 高校手机签到系统——Ksoap2的一些使用心得(补充)

    高校手机签到系统系列: 高校手机签到系统——第一部分Authority权限系统(上) 高校手机签到系统——第一部分Authority权限系统(下) 高校手机签到系统——手机客户端 高校手机签到系统—— ...

  3. 高校手机签到系统——zxing.net生成二维码(补充)

    高校手机签到系统——第一部分Authority权限系统(上) 高校手机签到系统——第一部分Authority权限系统(下) 高校手机签到系统——手机客户端 关于zxing.net的使用网上已有很多说明 ...

  4. S2SH商用后台权限系统第一讲

    各位博友: 您好!从今天开始我们做一套商用的权限系统.功能包含用户管理.角色管理.模块管理.权限管理.大家知道每个商用系统肯定会拥有一套后台系统,我们所讲的权限系统是整个系统核心部分.本套系统技术有s ...

  5. MySQL权限系统(三).权限表 Grant Tables

    7.2.2 Grant Tables 授权表 The mysql system database includes several grant tables that contain informat ...

  6. 用户管理 之 Linux 系统中的超级权限的控制

    在Linux操作系统中,root的权限是最高的,也被称为超级权限的拥有者.普通用户无法执行的操作,root用户都能完成,所以也被称之为超级管理用户. 在系统中,每个文件.目录和进程,都归属于某一个用户 ...

  7. MIUI11系统怎么样启用root权限的教程

    MIUI11系统如何启用了ROOT超级权限?做开发的人都知道,安卓机器有ROOT超级权限,一旦手机启用了root相关权限,可以实现更多的功能,举个例子做开发的人公司的营销部门的妹纸,使用较多营销工具都 ...

  8. 如何获得MIUI10系统的root超级权限

    MIUI10系统有没有办法拥有root超级权限?做开发的人都清楚,android手机有root超级权限,如果手机拥有root相关权限,能够实现更强的功能,举个栗子做开发的人企业的营销部门,使用某些营销 ...

  9. MIUI系统如何获取ROOT权限

    MIUI系统有么好方法启用了Root超级权限?各位都清楚,Android手机有Root超级权限,一旦手机启用了root相关权限,就能够实现更多的功能,举例子,各位公司的营销部门的同事,使用大多数营销工 ...

随机推荐

  1. bootstrap之编译CSS和Javascript-0基础安装grunt教程

    昨天晚上看到 bootstrap 全局CSS样式中 使用Less 章节中提到的通过grunt重新编译CSS和Javascript文件,对于我这样从未接触过windows cmd node控制台 npm ...

  2. dos语法

    一)MD——建立子目录 1.功能:创建新的子目录 2.类型:内部命令 3.格式:MD[盘符:][路径名]〈子目录名〉 4.使用说明: (1)“盘符”:指定要建立子目录的磁盘驱动器字母,若省略,则为当前 ...

  3. What is the RESTful API ?

    REST 是 RepresentationalStateTransfer 的缩写,一般中文译为 “表征状态转移”,Roy Thomas Fielding 在他2000年的PhD论文中发明了这个概念.首 ...

  4. pycharm 的调试模式 MAC版

    进入调试模式 运行和调试快捷键 control +R 运行程序 control +alt +R 快速选择运行/调试配置并运行或编辑它 command +R 重新运行 control +R 重复执行相同 ...

  5. java.lang.ClassNotFoundException:oracle.jdbc.OracleDriver

    在使用JDBC时经常碰到java.lang.ClassNotFoundException:oracle.jdbc.OracleDriver问题 这是jvm找不到驱动类文件,可能是以下原因: 没有导入驱 ...

  6. jQuery-2.DOM---节点的复制与替换

    DOM拷贝clone() 克隆节点是DOM的常见操作,jQuery提供一个clone方法,专门用于处理dom的克隆 .clone()方法深度 复制所有匹配的元素集合,包括所有匹配元素.匹配元素的下级元 ...

  7. 【leetcode】448. Find All Numbers Disappeared in an Array

    problem 448. Find All Numbers Disappeared in an Array solution: class Solution { public: vector<i ...

  8. JAVA高级篇(二、JVM内存模型、内存管理之第二篇)

    本文转自https://zhuanlan.zhihu.com/p/25713880. JVM的基础概念 JVM的中文名称叫Java虚拟机,它是由软件技术模拟出计算机运行的一个虚拟的计算机. JVM也充 ...

  9. 基于SPA的网页授权流程(微信OAuth2)

    先说传统MVC网站的网页授权流程. 1.用户发起了某个需要登录执行的操作 2.收集AppId等信息重定向到微信服务器 3.微信服务器回调到网站某个Controller的Action 4.在此Actio ...

  10. Windows安装Anaconda出现failed to create menus

    当出现上述问题时,有以下的解决办法: (1)默认安装,即一直next: (2)安装路径里不要包含英文以外的语言,即安装路径全部用英文命名: (3)先不要安装python,或者将安装的python配置好 ...