/// <summary> /// 保存借用单 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSave_Press(object sender, EventArgs e) { try { if (AssIdList.Count == 0) { throw new Exception("请添加借用的资产!"); } AssBorrowOrderRowInputDto row = new AssBorrowOrderRowInputDto { Sns = AssIdList, use_log_id = BoId }; ReturnInfo returnInfo = _autofacConfig.AssetsService.AddAssBorrowOrderRow(row); if (returnInfo.IsSuccess) { ShowResult = ShowResult.Yes; Toast("添加成功"); Close(); } else { Toast(returnInfo.ErrorInfo); } } catch (Exception ex) { Toast(ex.Message); } }
/// <summary> /// 删除借用单,一键归还全部资产 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnDelete_Press(object sender, EventArgs e) { try { if (AssIdList.Count == 0) { throw new Exception("没有要归还的资产!"); } DataTable rowsTable = _autofacConfig.AssetsService.GetRowsByBoid(BoId); List <string> SnList = new List <string>(); for (int i = 0; i < rowsTable.Rows.Count; i++) { SnList.Add(rowsTable.Rows[i][0].ToString()); } AssBorrowOrderRowInputDto row = new AssBorrowOrderRowInputDto { Sns = SnList, use_log_id = BoId }; ReturnInfo returnInfo = _autofacConfig.AssetsService.ReturnAss(row); if (returnInfo.IsSuccess) { ShowResult = ShowResult.Yes; ClearInfo(); Toast("归还成功"); Close(); } else { Toast(returnInfo.ErrorInfo); } } catch (Exception ex) { Toast(ex.Message); } }
/// <summary> /// 归还借用资产 /// </summary> /// <param name="borrowOrderInputrow">借用单信息</param> /// <returns></returns> public ReturnInfo ReturnAss(AssBorrowOrderRowInputDto borrowOrderInputrow) { //验证 ReturnInfo rInfo = new ReturnInfo(); StringBuilder sb = new StringBuilder(); if (sb.Length == 0) { cmdb_uselog use_row = _assBorrowOrderRepository.GetById(borrowOrderInputrow.use_log_id).FirstOrDefault(); use_row.expired = 0; _unitOfWork.RegisterDirty(use_row); try { foreach (var sn in borrowOrderInputrow.Sns) { //修改Asset的状态 cmdb_asset assets = _assetsRepository.GetByID(sn).FirstOrDefault(); if (assets != null) { assets.status = (int)STATUS.闲置; assets.use_man_id = null; assets.project_id = null; assets.team_id = null; assets.role_id = null; assets.give_time = null; assets.return_time = null; _unitOfWork.RegisterDirty(assets); } } ////删除行项 List <cmdb_assettouselog> Rows = _assBorrowOrderRowRepository.GetByBoId(borrowOrderInputrow.use_log_id).ToList(); foreach (var row in Rows) { _unitOfWork.RegisterDeleted(row); } ////添加处理记录 //var pr = new AssProcessRecord //{ // ASSID = assId, // CREATEDATE = DateTime.Now, // CREATEUSER = borrowOrderInput.CREATEUSER, // HANDLEDATE = DateTime.Now, // HANDLEMAN = borrowOrderInput.BRHANDLEMAN, // MODIFYDATE = DateTime.Now, // MODIFYUSER = borrowOrderInput.MODIFYUSER, // PROCESSCONTENT = borrowOrderInput.BORROWER + "借用了" + assId, // PROCESSMODE = (int)PROCESSMODE.借用, // QUANTITY = 1 //}; //_unitOfWork.RegisterNew(pr); bool result = _unitOfWork.Commit(); rInfo.IsSuccess = result; rInfo.ErrorInfo = sb.ToString(); return(rInfo); } catch (Exception ex) { _unitOfWork.Rollback(); sb.Append(ex.Message); rInfo.IsSuccess = false; rInfo.ErrorInfo = sb.ToString(); return(rInfo); } } else { rInfo.IsSuccess = false; rInfo.ErrorInfo = sb.ToString(); return(rInfo); } }
/// <summary> /// 添加借用资产条目 /// </summary> /// <param name="borrowOrderInputrow">借用单信息</param> /// <returns></returns> public ReturnInfo AddAssBorrowOrderRow(AssBorrowOrderRowInputDto borrowOrderInputrow) { //验证 ReturnInfo rInfo = new ReturnInfo(); StringBuilder sb = new StringBuilder(); sb.Append(Helper.BasicValidate(borrowOrderInputrow).ToString()); if (sb.Length == 0) { var assbo = Mapper.Map <AssBorrowOrderRowInputDto, cmdb_assettouselog>(borrowOrderInputrow); try { AssBorrowOrderOutputDto assBorrowOrderOutput = GetBobyId(borrowOrderInputrow.use_log_id);//fixme //_unitOfWork.RegisterNew(assbo); foreach (var sn in borrowOrderInputrow.Sns) { //修改Asset的状态 cmdb_asset assets = _assetsRepository.GetByID(sn).FirstOrDefault(); if (assets != null) { assets.status = (int)STATUS.外借; assets.use_man_id = assBorrowOrderOutput.use_man_id; assets.project_id = assBorrowOrderOutput.project_id; assets.team_id = assBorrowOrderOutput.team_id; assets.give_time = assBorrowOrderOutput.give_time; assets.return_time = assBorrowOrderOutput.return_time; _unitOfWork.RegisterDirty(assets); } //添加行项 var corow = new cmdb_assettouselog { asset_id = assets.id, use_log_id = borrowOrderInputrow.use_log_id }; _unitOfWork.RegisterNew(corow); ////添加处理记录 //var pr = new AssProcessRecord //{ // ASSID = assId, // CREATEDATE = DateTime.Now, // CREATEUSER = borrowOrderInput.CREATEUSER, // HANDLEDATE = DateTime.Now, // HANDLEMAN = borrowOrderInput.BRHANDLEMAN, // MODIFYDATE = DateTime.Now, // MODIFYUSER = borrowOrderInput.MODIFYUSER, // PROCESSCONTENT = borrowOrderInput.BORROWER + "借用了" + assId, // PROCESSMODE = (int)PROCESSMODE.借用, // QUANTITY = 1 //}; //_unitOfWork.RegisterNew(pr); } bool result = _unitOfWork.Commit(); rInfo.IsSuccess = result; rInfo.ErrorInfo = sb.ToString(); return(rInfo); } catch (Exception ex) { _unitOfWork.Rollback(); sb.Append(ex.Message); rInfo.IsSuccess = false; rInfo.ErrorInfo = sb.ToString(); return(rInfo); } } else { rInfo.IsSuccess = false; rInfo.ErrorInfo = sb.ToString(); return(rInfo); } }