@@ -0,0 +1,192 @@ | |||
/* Describtion : Class for Data Send From Client / Server | |||
* Company : Wuxi Xinje | |||
* Author : Somuns | |||
* DateTime : 2021/1/18 | |||
*/ | |||
using System; | |||
using System.Collections.Generic; | |||
namespace StuMgmLib | |||
{ | |||
public enum ClientFunc | |||
{ | |||
// 普通用户允许的操作 | |||
/// <summary> | |||
/// 验证登录 | |||
/// </summary> | |||
VerifyLogin = 1, | |||
/// <summary> | |||
/// 获取所有课程信息 | |||
/// </summary> | |||
GetCourseInfo, | |||
/// <summary> | |||
/// 获取用户信息 | |||
/// </summary> | |||
GetUserInfo, | |||
/// <summary> | |||
/// 修改课程状态 | |||
/// </summary> | |||
ChangeCourseStatus, | |||
// 老师允许的操作 | |||
//100 | |||
//// 管理员允许的操作 | |||
//200 | |||
//GetSomeoneUserCInfo = 6, | |||
//SUpdateCourse = 4, | |||
//TUpdateCourse = 5, | |||
} | |||
public enum Lvl | |||
{ | |||
NotFound = -1, | |||
Error = -2, | |||
Student = 99, | |||
Teacher = 199, | |||
Admin = 299, | |||
} | |||
public enum CourseStatus | |||
{ | |||
} | |||
#region 基本收发类 | |||
[Serializable] | |||
public class Request | |||
{ | |||
public ClientFunc Func; | |||
public short JobId; | |||
public string Token; | |||
public Request() { } | |||
public Request(ClientFunc func) | |||
{ | |||
Func = func; | |||
} | |||
} | |||
[Serializable] | |||
public class Response | |||
{ | |||
public bool Res; | |||
public string ErrMsg; | |||
public Response() | |||
{ | |||
Res = true; | |||
} | |||
public Response(string errMsg) | |||
{ | |||
Res = false; | |||
ErrMsg = errMsg; | |||
} | |||
} | |||
#endregion | |||
#region 用户登录 | |||
[Serializable] | |||
public class LoginReq : Request | |||
{ | |||
public string Password; | |||
public LoginReq(string password) // Changed | |||
{ | |||
Password = password; | |||
} | |||
} | |||
[Serializable] | |||
public class LoginRes : Response | |||
{ | |||
public string Token; | |||
public Lvl Level; | |||
public LoginRes(string token, Lvl level) | |||
{ | |||
Token = token; | |||
Level = level; | |||
} | |||
} | |||
#endregion | |||
#region 获取所有课程信息 | |||
[Serializable] | |||
public class CourseInfoReq : Request | |||
{ | |||
} | |||
[Serializable] | |||
public class CourseInfoRes : Response | |||
{ | |||
/// <summary> | |||
/// 课程ID | |||
/// </summary> | |||
public short Id; | |||
public short Pid; | |||
/// <summary> | |||
/// 该题所需用时(单位s) | |||
/// </summary> | |||
public int Time; | |||
public string Name; | |||
public string Content; | |||
public CourseInfoRes(short id, short pid, int time, string name, string content) | |||
{ | |||
Id = id; | |||
Pid = pid; | |||
Time = time; | |||
Name = name; | |||
Content = content; | |||
} | |||
} | |||
#endregion | |||
#region 用户信息 | |||
[Serializable] | |||
public class UserInfoReq : Request | |||
{ | |||
public short User; | |||
public UserInfoReq(short user) | |||
{ | |||
short User = user; | |||
} | |||
} | |||
[Serializable] | |||
public class UserInfoRes : Response | |||
{ | |||
public short JobId;//工号 | |||
public string Name;//姓名 | |||
/// <summary> | |||
/// 各课程的当前状态 | |||
/// </summary> | |||
public string Status; | |||
public UserInfoRes(short jobId, string name, string status) | |||
{ | |||
short JobId = jobId; | |||
string Name = name; | |||
string Status = status; | |||
} | |||
// ..public DateTime Entry; | |||
//public string Details;//老师对于该生的描述 | |||
} | |||
#endregion | |||
#region 用户课程状态修改 | |||
public class CrsStasReq : Request | |||
{ | |||
/// <summary> | |||
/// 需要修改者的工号 | |||
/// </summary> | |||
public short User; | |||
/// <summary> | |||
/// 需要修改的课程 | |||
/// </summary> | |||
public short Id; | |||
public CourseStatus Status; | |||
public CrsStasReq(short user, short id, CourseStatus status) | |||
{ | |||
short User = user; | |||
short Id = id; | |||
CourseStatus Status = status; | |||
} | |||
} | |||
public class CrsStasRes : Response | |||
{ | |||
} | |||
#endregion | |||
} | |||
@@ -1,140 +0,0 @@ | |||
/* Describtion : Class for Data Send From Client / Server | |||
* Company : Wuxi Xinje | |||
* Author : Somuns | |||
* DateTime : 2021/1/18 | |||
*/ | |||
using System; | |||
using System.Collections.Generic; | |||
namespace StuMgmLib.MyNameSpace | |||
{ | |||
#region QuickTable | |||
internal class QTInfo | |||
{ | |||
public int Token; | |||
public Lvl Level; | |||
public QTInfo(int token, Lvl lv) | |||
{ | |||
Token = token; | |||
Level = lv; | |||
} | |||
} | |||
public class QT // quickTable | |||
{ | |||
internal const Int16 tokenMaxCount = 32767; | |||
internal static Dictionary<short, QTInfo> quickTable = new Dictionary<short, QTInfo>(); | |||
} | |||
#endregion | |||
#region ClientClass | |||
public enum ClientFunc | |||
{ | |||
VerifyLogin = 1, | |||
GetCourseInfo = 2, | |||
GetSelfUserCourseInfo = 3, | |||
GetSomeoneUserCInfo = 6, | |||
SUpdateCourse = 4, | |||
TUpdateCourse = 5, | |||
} | |||
public enum Lvl | |||
{ | |||
NotFound = -1, | |||
Error = -2, | |||
Admin = 1, | |||
Teacher = 2, | |||
Student = 3, | |||
} | |||
[Serializable] | |||
public class ClientRequest | |||
{ | |||
public ClientFunc Func; | |||
public object Object; | |||
public ClientRequest(ClientFunc func, object obj) | |||
{ | |||
Func = func; | |||
Object = obj; | |||
} | |||
} | |||
[Serializable] | |||
public class UserInfoLogin | |||
{ | |||
public short Account; | |||
public string Password; | |||
public UserInfoLogin(short account, string password) // Changed | |||
{ | |||
Account = account; | |||
Password = password; | |||
} | |||
} | |||
[Serializable] | |||
public class UserCourseInfoReq | |||
{ | |||
public short Job_Id; | |||
public int Token; | |||
} | |||
[Serializable] | |||
public class UserCourseInfoOper | |||
{ | |||
public short Job_Id; | |||
public int Token; | |||
public string Status; | |||
} | |||
#endregion | |||
#region ServerClass | |||
[Serializable] | |||
public class ServerResponse | |||
{ | |||
public bool Final; | |||
public string ErrMessage; | |||
public object Object; | |||
public ServerResponse(object obj) | |||
{ | |||
Object = obj; | |||
} | |||
} | |||
[Serializable] | |||
public class LoginResponse | |||
{ | |||
public int Token; | |||
public Lvl Level; | |||
} | |||
[Serializable] | |||
public class CourseInfo | |||
{ | |||
public short Id; | |||
public short Pid; | |||
public int Time; | |||
public string Name; | |||
public string Content; | |||
} | |||
[Serializable] | |||
public class UserCourseInfo | |||
{ | |||
public short JobId;//工号 | |||
public string Name;//姓名 | |||
public string Status; | |||
// ..public DateTime Entry; | |||
public string Details;//信息描述 | |||
} | |||
#endregion | |||
} | |||
@@ -43,12 +43,9 @@ | |||
<Reference Include="System.Xml" /> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<Compile Include="MyNameSpace\CommonData.cs" /> | |||
<Compile Include="MyNameSpace\SystemCtrl.cs"> | |||
<SubType>Code</SubType> | |||
</Compile> | |||
<Compile Include="MyNameSpace\TcpConn.cs" /> | |||
<Compile Include="CommonData.cs" /> | |||
<Compile Include="Properties\AssemblyInfo.cs" /> | |||
<Compile Include="Utility.cs" /> | |||
</ItemGroup> | |||
<ItemGroup /> | |||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | |||
@@ -0,0 +1,31 @@ | |||
using System.IO; | |||
using System.Runtime.Serialization.Formatters.Binary; | |||
namespace StuMgmLib | |||
{ | |||
class Utility | |||
{ | |||
/// <summary> | |||
/// 序列化 | |||
/// </summary> | |||
public static byte[] SerializeBin<T>(T c) | |||
{ | |||
MemoryStream ms = new MemoryStream(); | |||
BinaryFormatter iFormatter = new BinaryFormatter(); | |||
iFormatter.Serialize(ms, c); | |||
byte[] buf = ms.GetBuffer(); | |||
return buf; | |||
} | |||
/// <summary> | |||
/// 反序列化 | |||
/// </summary> | |||
public static T DeserializeBin<T>(byte[] buf) | |||
{ | |||
MemoryStream ms = new MemoryStream(buf); | |||
BinaryFormatter iFormatter = new BinaryFormatter(); | |||
var obj = (T)iFormatter.Deserialize(ms); | |||
return obj; | |||
} | |||
} | |||
} |
@@ -51,6 +51,9 @@ | |||
</Compile> | |||
<Compile Include="Program.cs" /> | |||
<Compile Include="Properties\AssemblyInfo.cs" /> | |||
<Compile Include="SystemCtrl.cs" /> | |||
<Compile Include="TcpConn.cs" /> | |||
<Compile Include="Utility.cs" /> | |||
<EmbeddedResource Include="Properties\Resources.resx"> | |||
<Generator>ResXFileCodeGenerator</Generator> | |||
<LastGenOutput>Resources.Designer.cs</LastGenOutput> | |||
@@ -14,30 +14,7 @@ namespace StuMgmLib.MyNameSpace | |||
{ | |||
public class SystemCtrl | |||
{ | |||
#region 流 | |||
/// <summary> | |||
/// 序列化 | |||
/// </summary> | |||
static byte[] Serialize<T>(T c) | |||
{ | |||
MemoryStream ms = new MemoryStream(); | |||
BinaryFormatter iFormatter = new BinaryFormatter(); | |||
iFormatter.Serialize(ms, c); | |||
byte[] buf = ms.GetBuffer(); | |||
return buf; | |||
} | |||
/// <summary> | |||
/// 反序列化 | |||
/// </summary> | |||
static T Deserialize<T>(byte[] buf) | |||
{ | |||
MemoryStream ms = new MemoryStream(buf); | |||
BinaryFormatter iFormatter = new BinaryFormatter(); | |||
var obj = (T)iFormatter.Deserialize(ms); | |||
return obj; | |||
} | |||
#endregion | |||
/// <summary> | |||
/// 获取返回数据 | |||
@@ -48,14 +25,14 @@ namespace StuMgmLib.MyNameSpace | |||
{ | |||
var cr = Deserialize<ClientRequest>(clientRequset); | |||
ServerResponse sr = new ServerResponse(null); | |||
Response sr = new Response(null); | |||
switch (cr.Func) | |||
{ | |||
case ClientFunc.VerifyLogin: | |||
#region 登陆验证 | |||
LoginResponse lr = new LoginResponse(); | |||
sr = new ServerResponse(lr); | |||
sr = new Response(lr); | |||
UserInfoLogin login = (UserInfoLogin)cr.Object; | |||
getPerFromDB(login, out sr.Final, out sr.ErrMessage, out lr.Level); | |||
@@ -66,7 +43,7 @@ namespace StuMgmLib.MyNameSpace | |||
#endregion | |||
case ClientFunc.GetCourseInfo: | |||
#region 获取课程表 | |||
sr.Object = getCosInfo(out sr.Final, out sr.ErrMessage); | |||
sr.Data = getCosInfo(out sr.Final, out sr.ErrMessage); | |||
break; | |||
#endregion | |||
case ClientFunc.GetSelfUserCourseInfo: | |||
@@ -74,7 +51,7 @@ namespace StuMgmLib.MyNameSpace | |||
UserCourseInfoReq ucir = (UserCourseInfoReq)cr.Object; | |||
UserCourseInfo uc = new UserCourseInfo(); | |||
sr = new ServerResponse(uc); | |||
sr = new Response(uc); | |||
vrTokenFrT(ucir.Job_Id, ucir.Token, out sr.Final, out sr.ErrMessage); | |||
if (!sr.Final) | |||
@@ -98,7 +75,7 @@ namespace StuMgmLib.MyNameSpace | |||
if (!sr.Final) | |||
break; | |||
sr.Object = getUsrCosStatus(uciO.Status, out sr.Final, out sr.ErrMessage); | |||
sr.Data = getUsrCosStatus(uciO.Status, out sr.Final, out sr.ErrMessage); | |||
break; | |||
#endregion |
@@ -0,0 +1,52 @@ | |||
using System.IO; | |||
using System.Runtime.Serialization.Formatters.Binary; | |||
namespace StuMgmLib | |||
{ | |||
class Utility | |||
{ | |||
/// <summary> | |||
/// 序列化 | |||
/// </summary> | |||
static byte[] Serialize<T>(T c) | |||
{ | |||
MemoryStream ms = new MemoryStream(); | |||
BinaryFormatter iFormatter = new BinaryFormatter(); | |||
iFormatter.Serialize(ms, c); | |||
byte[] buf = ms.GetBuffer(); | |||
return buf; | |||
} | |||
/// <summary> | |||
/// 反序列化 | |||
/// </summary> | |||
static T Deserialize<T>(byte[] buf) | |||
{ | |||
MemoryStream ms = new MemoryStream(buf); | |||
BinaryFormatter iFormatter = new BinaryFormatter(); | |||
T obj = (T)iFormatter.Deserialize(ms); | |||
return obj; | |||
} | |||
} | |||
} | |||
#region QuickTable | |||
internal class QTInfo | |||
{ | |||
public int Token; | |||
public Lvl Level; | |||
public QTInfo(int token, Lvl lv) | |||
{ | |||
Token = token; | |||
Level = lv; | |||
} | |||
} | |||
public class QT // quickTable | |||
{ | |||
internal const Int16 tokenMaxCount = 32767; | |||
internal static Dictionary<short, QTInfo> quickTable = new Dictionary<short, QTInfo>(); | |||
} | |||
#endregion |