Skip to content

Commit

Permalink
写完了,有几个todo
Browse files Browse the repository at this point in the history
  • Loading branch information
mrbian committed Jul 18, 2016
1 parent dc7c2b5 commit 5943ce9
Show file tree
Hide file tree
Showing 15 changed files with 677 additions and 8 deletions.
152 changes: 152 additions & 0 deletions AssetSystem/Adaptor/EquipmentAdaptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,95 @@ public Equipment GetEquipmentById(int Id)
.FirstOrDefault(e => e.Id == Id);
}

/// <summary>
/// 更新所给equipment
/// </summary>
/// <param name="equipment"></param>
/// <returns></returns>
public int UpdateEquipment(Equipment equipment)
{
DbCtx.Entry(equipment).State = EntityState.Modified;
DbCtx.SaveChanges();
return 1;
}

/// <summary>
/// 根据大类查找设备
/// </summary>
/// <param name="bigTypeId"></param>
/// <returns>设备List数组</returns>
public List<Equipment> FindEquipmentsByBigType(int bigTypeId)
{
List<Equipment> equipments = new List<Equipment>();
var bigEquipmentType = DbCtx.EquipmentTypes
.FirstOrDefault(et => et.Id == bigTypeId);
if (bigEquipmentType == null || bigEquipmentType.Type == 1) //如果没有或者是小类,返回空
{
return equipments; //返回空
}
List<EquipmentType> smallEquipmentTypes = DbCtx.EquipmentTypes
.Where(et => et.BigEquipmentType.Id == bigTypeId)
.ToList(); //根据大类Id获得所有小类
if (smallEquipmentTypes.Count == 0) //如果没有小类
{
return equipments; //返回空
}
foreach (var smallEquipment in smallEquipmentTypes) //向结果中加入每个小类下的设备
{
equipments.AddRange(DbCtx.Equipments
.Where(e => e.EquipmentType.Id == smallEquipment.Id)
.ToList());
}
return equipments;
}

/// <summary>
/// 根据小类的Id查找
/// </summary>
/// <param name="smallTypeId"></param>
/// <returns>查找的List结果集</returns>
public List<Equipment> FindEquipmentsBySmallType(int smallTypeId)
{
List<Equipment> equipments = new List<Equipment>();
var smallEquipmentType = DbCtx.EquipmentTypes
.FirstOrDefault(et => et.Id == smallTypeId);
if (smallEquipmentType == null || smallEquipmentType.Type == 0) //如果没有或者是大类,返回空List
{
return equipments;
}
equipments = DbCtx.Equipments
.Where(e => e.EquipmentType.Id == smallTypeId)
.ToList(); //按照小类查找设备
return equipments;
}

/// <summary>
/// 按照逻辑Id查找
/// </summary>
/// <param name="logicId">设备的逻辑Id</param>
/// <returns>查询的结果List</returns>
public List<Equipment> FindEquipmentsByLogicId(string logicId)
{
List<Equipment> equipments = new List<Equipment>();
equipments.Add(DbCtx.Equipments
.FirstOrDefault(e => e.LogicId == logicId));
return equipments;
}

/// <summary>
/// 根据用户的Id查询并返回结果集
/// </summary>
/// <param name="userId">用户的Id</param>
/// <returns>查询结果</returns>
public List<Equipment> FindEquipmentByUserId(int userId)
{
List<Equipment> equipments = new List<Equipment>();
equipments = DbCtx.Equipments
.Where(e => e.User.Id == userId)
.ToList();
return equipments;
}

/// <summary>
/// 得到数据库中的所有的设备
/// </summary>
Expand All @@ -110,5 +192,75 @@ public List<Equipment> GetAllEquipments()
{
return DbCtx.Equipments.ToList();
}

/// <summary>
/// 领用某一设备
/// </summary>
/// <param name="userId">要领用设备的用户Id</param>
/// <param name="equipmentId">被领用设备的Id</param>
/// <returns>
/// 1 : 操作成功
/// 0 : 没有对应的user或者没有对应的设备
/// -1 : 设备已经被占用
/// -2 : 设备在维修或已经报废
/// </returns>
public int BorrowEquipment(int userId, int equipmentId)
{
var user = DbCtx.Users
.FirstOrDefault(u => u.Id == userId); //得到用户
var equipment = DbCtx.Equipments
.FirstOrDefault(e => e.Id == equipmentId); //得到设备
if (user == null || equipment == null)
{
return 0;
}
if (equipment.User != null) //设备被占用
{
return -1;
}
if (equipment.State != 0) //设备在维修或者报废
{
return -2;
}
equipment.User = user; //修改用户为指定用户
DbCtx.Entry(equipment).State = EntityState.Modified;
DbCtx.SaveChanges();
return 1;
}

/// <summary>
/// 设备的归还
/// </summary>
/// <param name="equipmentId"></param>
/// <returns>
/// 0 : 指定Id的设备不存在
/// 1 : 操作成功
/// -1 : 指定设备未被领用
/// </returns>
public int ReturnEquipment(int equipmentId,string adminAccount)
{
var equipment = DbCtx.Equipments
.FirstOrDefault(e => e.Id == equipmentId);
if (equipment == null)
{
return 0;
}
if (equipment.User == null)
{
return -1;
}
DbCtx.Histories.Add(new History()
{
ReturnDate = DateTime.Now,
EquipmentTitle = equipment.Title,
UserName = equipment.User.Name,
AdminAccount = adminAccount
}); //添加归还记录

equipment.User = null; //删除当前领用用户
DbCtx.Entry(equipment).State = EntityState.Modified;
DbCtx.SaveChanges();
return 1;
}
}
}
13 changes: 11 additions & 2 deletions AssetSystem/Adaptor/UserAdaptor.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
namespace AssetSystem.Adaptor
using System.Collections.Generic;
using System.Linq;
using AssetSystem.Models;

namespace AssetSystem.Adaptor
{
public class UserAdaptor:BaseAdaptor
{
public UserAdaptor() : base()
{


}

public List<User> GetAllUser()
{
return DbCtx.Users.ToList();
}
}
}
8 changes: 8 additions & 0 deletions AssetSystem/AssetSystem.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@
<Compile Include="Migrations\201607171316020_Migrate.Designer.cs">
<DependentUpon>201607171316020_Migrate.cs</DependentUpon>
</Compile>
<Compile Include="Migrations\201607181118147_Migrate1.cs" />
<Compile Include="Migrations\201607181118147_Migrate1.Designer.cs">
<DependentUpon>201607181118147_Migrate1.cs</DependentUpon>
</Compile>
<Compile Include="Migrations\Configuration.cs" />
<Compile Include="Models\Admin.cs" />
<Compile Include="Models\DbInitializer.cs" />
Expand All @@ -91,12 +95,16 @@
<None Include="App.config">
<SubType>Designer</SubType>
</None>
<None Include="ClassDiagram1.cd" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Migrations\201607171316020_Migrate.resx">
<DependentUpon>201607171316020_Migrate.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Migrations\201607181118147_Migrate1.resx">
<DependentUpon>201607181118147_Migrate1.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
2 changes: 2 additions & 0 deletions AssetSystem/ClassDiagram1.cd
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<ClassDiagram />
10 changes: 9 additions & 1 deletion AssetSystem/Controllers/AdminController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public AdminController() : base()
public AdminAdaptor AdminAdaptor;
public AdminViews AdminViews;

//todo : 管理员存储放在这里还是崩溃
//todo : 管理员存储放在这里不是静态的话还是会被清空

//get Auth
public void Auth()
Expand Down Expand Up @@ -70,10 +70,12 @@ public void Choose()
#endregion
#region 调用用户Controller对用户进行管理
case (int)ChooseOptions.UserCtrl:
CtrlCtx.GetUserController().UserCtrl();
break;
#endregion
#region 修改Admin的账户密码
case (int)ChooseOptions.ChangePassword:
ChangePassword();
break;
#endregion
//都不满足则让用户重新选取
Expand All @@ -84,5 +86,11 @@ public void Choose()
Choose(); //执行完毕后重新调用执行
}

public void ChangePassword()
{
string newPassword = AdminViews.ChangePassword(); //得到用户输入的新密码
AdminAdaptor.AdminChangePassword(GetCurrentAdmin().Account, GetCurrentAdmin().Password, newPassword);
AdminViews.OperatorSuccess();
}
}
}
22 changes: 21 additions & 1 deletion AssetSystem/Controllers/Enum/EnumOperator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,26 @@ public enum EnumEquipmentOpOptions
Delete = 2,
Update = 3,
PrintAll = 4,
Exit = 5
Find = 5,
Borrow = 6,
Return = 7,
Exit = 8
}

/// <summary>
/// 判断用户管理操作的enum
/// </summary>
public enum EnumUserOpOptions
{
PrintAll = 1,
Exit = 2
}

public enum EnumFindCondition
{
ByBigType = 1, //按照大类浏览
BySmallType = 2, //按照小类浏览
ByLogicId = 3, //按照设备的编号浏览
ByUser = 4, //按照使用者浏览
}
}
Loading

0 comments on commit 5943ce9

Please sign in to comment.