/// <summary> /// 手动盘点 /// </summary> /// <param name="assetId">资产id</param> /// <param name="stockId">盘点id</param> /// <param name="result">盘点结果</param> /// <param name="method">盘点方式,1扫码盘点|2手动盘点</param> /// <param name="checkor">盘点人</param> /// <returns></returns> public Result DirectCheck(int assetId, int stockId, int result, int method, string checkor) { var util = MySearchUtil.New() .AndEqual("IsDel", false) .AndEqual("IsFinish", false) .AndEqual("StockId", stockId) .AndEqual("AssetId", assetId); var item = _db.Load <StockItem>(util); if (item == null) { return(ResultUtil.Do(ResultCodes.验证失败, "请求的资产未记录在本次盘点内")); } if (item.CheckResult > 0) { return(ResultUtil.Do(ResultCodes.验证失败, "该资产已经盘点")); } const string sql = @" UPDATE [Asset_StockItem] SET CheckAt=GETDATE(),Checkor=@Checkor,CheckResult=@Result, CheckMethod=@Method,UpdateAt=GETDATE(),Updator=@Checkor WHERE Id=@Id; UPDATE [Asset_Asset] SET LastCheckTime=GETDATE() WHERE Id=@AssetId;"; var row = _db.Execute(sql, new { Checkor = checkor, Result = result, Method = method, item.Id, item.AssetId }); return(row > 0 ? ResultUtil.Success() : ResultUtil.Do(ResultCodes.数据库操作失败, "操作失败")); }
/// <summary> /// 移除数据 /// </summary> /// <param name="id"></param> /// <param name="user"></param> /// <returns></returns> public Result Delete(int id, IAppUser user) { try { var entity = _db.Load <Account>(id); if (entity == null) { return(ResultUtil.Do(ResultCodes.数据不存在, "请求的数据不存在")); } var assetCount = _db.GetCount <Asset>(MySearchUtil.New() .AndEqual("AccountId", id) .AndEqual("IsDel", false)); if (assetCount > 0) { return(ResultUtil.Do(ResultCodes.验证失败, "此用户下资产不为空,禁止删除")); } var row = _db.Remove <Account>(id); return(row > 0 ? ResultUtil.Success() : ResultUtil.Do(ResultCodes.数据库操作失败, "数据库写入失败")); } catch (Exception ex) { return(ResultUtil.Exception(ex)); } }
public T Load(int id) { var entity = db.Load <T>(id); if (entity == null || entity.IsDel) { return(null); } return(entity); }
/// <summary> /// 盘点详情 /// </summary> /// <param name="id"></param> /// <returns></returns> public IActionResult Details(int id) { var entity = _db.Load <Stock>(id); if (entity == null) { return(RedirectToAction("Error", new { title = "403", message = "您无权查看此数据" })); } return(View(entity)); }
public Result Delete(int id, IAppUser user) { try { var entity = _db.Load <Dept>(id); if (entity == null) { return(ResultUtil.Do(ResultCodes.数据不存在, "请求的数据不存在")); } var childrenCount = _db.GetCount <Dept>(MySearchUtil.New() .AndEqual("ParentId", id) .AndEqual("IsDel", false)); if (childrenCount > 0) { return(ResultUtil.Do(ResultCodes.验证失败, "下属部门不为空,禁止删除")); } var accountCount = _db.GetCount <Account>(MySearchUtil.New() .AndEqual("DeptId", id) .AndEqual("IsDel", false)); if (accountCount > 0) { return(ResultUtil.Do(ResultCodes.验证失败, "部门内员工不为空,禁止删除")); } var row = _db.Remove <Dept>(id); if (row > 0) { DeptUtil.Clear(); return(ResultUtil.Success()); } else { return(ResultUtil.Do(ResultCodes.数据库操作失败, "数据库写入失败")); } } catch (Exception ex) { return(ResultUtil.Exception(ex)); } }
public Result Remove(int id, BaseAppUser user) { if (user == null) { throw new ArgumentNullException(nameof(user)); } var entity = _db.Load <RoleEntity>(id); if (entity == null) { return(ResultUtil.AuthFail("请求的数据不存在")); } if (entity.IsDel) { return(ResultUtil.Success()); } using (var conn = _db.GetConnection()) { conn.Open(); using (var trans = conn.BeginTransaction()) { try { var row = conn.Remove(entity, user); conn.Delete <RolePowerEntity>(MySearchUtil.New().AndEqual("RoleId", entity.Id)); trans.Commit(); return(row > 0 ? ResultUtil.Success() : ResultUtil.Fail()); } catch (Exception e) { trans.Rollback(); conn.Close(); return(ResultUtil.Fail(e.Message)); } } } }
/// <summary> /// 加载一个服务申请 /// </summary> /// <param name="id">申请id</param> /// <returns></returns> public ServiceApply Load(int id) { return(_db.Load <ServiceApply>(id)); }
/// <summary> /// 加载一个实体 /// </summary> /// <param name="id">实体ID</param> /// <returns></returns> public virtual T Load(int id) { return(db.Load <T>(id)); }
public User Load(int id) { return(_db.Load <User>(id)); }
public T Load(int id) { return(Db.Load <T>(id)); }