VisitLog(登录日志)
ColumnName | Data Type | Required | Memo |
Id | nvarchar(36) | Y | GUID |
VisitTime | datetime | Y | |
UserId | nvarchar(30) | Y | |
IpAddress | nvarchar(32) | Y | |
Category | nvarchar(10) | Y | Login/SignOut |
create table VisitLog
(
Id nvarchar(36) primary key,
VisitTime datetime not null,
UserId nvarchar(36) not null,
IpAddress nvarchar(32) not null,
Category nvarchar(10) not null
);
OperateLog(操作日志)
ColumnName | Data Type | Required | Memo |
Id | nvarchar(36) | Y | GUID |
OperateTime | datetime | Y | |
UserId | nvarchar(30) | Y | |
TableName | nvarchar(30) | Y | |
RecordId | nvarchar(36) | Y | 所修改表的主键值 |
Category | nvarchar(10) | Y | View/Add/Edit/Delete |
create table OperateLog
(
Id nvarchar(36) primary key,
OperateTime datetime not null,
UserId nvarchar(36) not null,
TableName nvarchar(30) not null,
RecordId nvarchar(36) not null,
Category nvarchar(10) not null
);
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Runtime.Serialization;
//using System.Collections.ObjectModel;//Collection
using QhrServiceProject.Data;
namespace QhrServiceProject.MyEntity
{
[DataContract]
public static class VisitCategory
{
[DataMember]
public static string Login = "Login";
[DataMember]
public static string SignOut = "SignOut";
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Runtime.Serialization;
//using System.Collections.ObjectModel;//Collection
using QhrServiceProject.Data;
namespace QhrServiceProject.MyEntity
{
[DataContract]
public static class OperateCategory
{
[DataMember]
public static string View = "View";
[DataMember]
public static string Add = "Add";
[DataMember]
public static string Edit = "Edit";
[DataMember]
public static string Delete = "Delete";
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Runtime.Serialization;
using System.Collections.ObjectModel;//Collection
using QhrServiceProject.Data;
namespace QhrServiceProject.MyEntity
{
[CollectionDataContract]
public class MyOperateLogCollection : Collection<MyOperateLog>
{
}
[DataContract]
public class MyOperateLog
{
string id;
DateTime operateTime;
string userId;
string tableName;
string recordId;
string category;
[DataMember]
public string Id
{ get; set; }
[DataMember]
public DateTime OperateTime
{ get; set; }
[DataMember]
public string UserId
{ get; set; }
[DataMember]
public string TableName
{ get; set; }
[DataMember]
public string RecordId
{ get; set; }
[DataMember]
public string Category
{ get; set; }
public MyOperateLog(Data.OperateLog oLog)
{
if (oLog == null)
return;
Id = oLog.Id;
OperateTime = oLog.OperateTime;
UserId = oLog.UserId;
TableName = oLog.TableName;
RecordId = oLog.RecordId;
Category = oLog.Category;
}
public MyOperateLog()
{ }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Runtime.Serialization;
using System.Collections.ObjectModel;//Collection
using QhrServiceProject.Data;
namespace QhrServiceProject.MyEntity
{
[CollectionDataContract]
public class MyVisitLogCollection : Collection<MyVisitLog>
{
}
[DataContract]
public class MyVisitLog
{
string id;
DateTime visitTime;
string userId;
string ipAddress;
string category;
[DataMember]
public string Id
{ get; set; }
[DataMember]
public DateTime VisitTime
{ get; set; }
[DataMember]
public string UserId
{ get; set; }
[DataMember]
public string IpAddress
{ get; set; }
[DataMember]
public string Category
{ get; set; }
public MyVisitLog(Data.VisitLog vLog)
{
if (vLog == null)
return;
Id = vLog.Id;
VisitTime = vLog.VisitTime;
UserId = vLog.UserId;
IpAddress = vLog.IpAddress;
Category = vLog.Category;
}
public MyVisitLog()
{ }
}
}
#region VisitLog
[OperationContract]
[FaultContract(typeof(MyEntity.MyServiceError))]
int CreateVisitLog(MyVisitLog my);
#endregion VisitLog
#region VisitLog 2011-08-31 quietwalk
private VisitLog ConvertMyVisitLogToVisitLog(MyVisitLog my)
{
if (my == null)
{
ShowException("ConvertMyVisitLogToVisitLog", "Input parameter isnull.");
return null;
}
VisitLog vLog = new VisitLog();
vLog.Id = my.Id;
vLog.VisitTime = my.VisitTime;
vLog.UserId = my.UserId;
vLog.IpAddress = my.IpAddress;
vLog.Category = my.Category;
return vLog;
}
public int CreateVisitLog(MyVisitLog my)
{
if (my == null)
{
ShowException("CreateVisitLog", "Input parameter isnull.");
return -1;
}
if (my.Category != VisitCategory.Login && my.Category != VisitCategory.SignOut)
{
ShowException("CreateVisitLog", "Visit category must be " + VisitCategory.Login + "or " + VisitCategory.SignOut + " .");
return -1;
}
if (my.VisitTime == null)
{
ShowException("CreateVisitLog", "VisitTime should not be null.");
return -1;
}
if (my.UserId == "")
{
ShowException("CreateVisitLog", "UserId should not be empty.");
return -1;
}
if (my.IpAddress == string.Empty)
{
ShowException("CreateVisitLog", "IpAddress should not be empty.");
return -1;
}
ModelContainer container = ModelContext.Container == null ? null : ModelContext.Container;
if (container == null)
{
return -1;
}
MyLogin myLogin = GetMyLoginByUserId(my.UserId);
if (myLogin == null)
{
ShowException("CreateVisitLog", "UserId is not exist.");
return -1;
}
VisitLog vLog = ConvertMyVisitLogToVisitLog(my);
container.VisitLogs.AddObject(vLog);
return container.SaveChanges();
}
#endregion