private void Return(Dictionary <string, object> row) { var returnNumber = 0; int.TryParse(row.GetValue("ReturnNumber"), out returnNumber); var id = row.GetValue("ID"); var borrowDetail = this.entities.Set <S_BorrowDetail>().FirstOrDefault(a => a.ID == id); if (returnNumber > 0 && borrowDetail != null) { borrowDetail.ReturnUserID = row.GetValue("ReturnUserID"); borrowDetail.ReturnUser = row.GetValue("ReturnUser"); borrowDetail.ReturnDeptID = row.GetValue("ReturnDeptID"); borrowDetail.ReturnDeptName = row.GetValue("ReturnDeptName"); borrowDetail.ReturnNumber = (borrowDetail.ReturnNumber ?? 0) + returnNumber; borrowDetail.ReturnDate = Convert.ToDateTime(row.GetValue("ReturnDate")); var isFinish = ((borrowDetail.LendNumber ?? 0) - (borrowDetail.ReturnNumber ?? 0) - (borrowDetail.LostNumber ?? 0)) == 0; if (isFinish) { borrowDetail.BorrowState = BorrowDetailState.Finish.ToString(); } if (borrowDetail.DetailType == NodeType.Node.ToString()) { var space = DocConfigHelper.CreateConfigSpaceByID(borrowDetail.SpaceID); var nodeInfo = new S_NodeInfo(borrowDetail.RelateID, space); InventoryFO.CreateInventoryLedger(nodeInfo, InventoryType.Return, 0, returnNumber, borrowDetail.ID, borrowDetail.ReturnUserID, borrowDetail.ReturnUser, EnumBaseHelper.GetEnumDescription(InventoryType.Return.GetType(), InventoryType.Return.ToString()) + "份数:" + returnNumber + "份"); if (isFinish) { nodeInfo.DataEntity.SetValue("BorrowState", BorrowReturnState.Return.ToString()); } nodeInfo.Save(false); } else { var space = DocConfigHelper.CreateConfigSpaceByID(borrowDetail.SpaceID); var fileInfo = new S_FileInfo(borrowDetail.RelateID, space); InventoryFO.CreateInventoryLedger(fileInfo, InventoryType.Return, 0, returnNumber, borrowDetail.ID, borrowDetail.ReturnUserID, borrowDetail.ReturnUser, EnumBaseHelper.GetEnumDescription(InventoryType.Return.GetType(), InventoryType.Return.ToString()) + "份数:" + returnNumber + "份"); if (isFinish) { fileInfo.DataEntity.SetValue("BorrowState", BorrowReturnState.Return.ToString()); } fileInfo.Save(false); } } }
public static void CreateInventoryLedger(S_NodeInfo node, InventoryType type, int totalAmount, int inventoryAmount, string relateDetailInfoID, string targetUserID = "", string targetUserName = "", string detail = "") { DocConstEntities entities = FormulaHelper.GetEntities <DocConstEntities>(); var currentUser = FormulaHelper.GetUserInfo(); var InventoryLedger = new S_A_InventoryLedger { CarItemName = "", CreateDate = System.DateTime.Now, CreateUserID = currentUser.UserID, CreateUserName = currentUser.UserName, SpaceID = node.Space.ID, Type = type.ToString(), Detail = detail, CreateDept = currentUser.UserDeptNames, InventoryAmount = inventoryAmount, TotalAmount = totalAmount, RelateID = node.ID, RelateName = node.Name, RelateType = ListConfigType.File.ToString(), RelateDetailInfoID = relateDetailInfoID, TargetUserID = targetUserID, TargetUserName = targetUserName }; var qNum = int.Parse(string.IsNullOrEmpty(node.DataEntity.GetValue("Quantity")) ? "0" : node.DataEntity.GetValue("Quantity")) + totalAmount; node.DataEntity.SetValue("Quantity", qNum); var sNum = int.Parse(string.IsNullOrEmpty(node.DataEntity.GetValue("StorageNum")) ? "0" : node.DataEntity.GetValue("StorageNum")) + inventoryAmount; node.DataEntity.SetValue("StorageNum", sNum); if (qNum < 0 || sNum < 0) { throw new Formula.Exceptions.BusinessException("遗失份数大于库存,请重新填写"); } node.Save(false); entities.Set <S_A_InventoryLedger>().Add(InventoryLedger); entities.SaveChanges(); }
public JsonResult ReturnNode() { var ids = this.GetQueryString("ListIDs").Split(','); if (ids.Length == 0) { ids = this.GetQueryString("ID").Split(','); } var spaceID = this.GetQueryString("SpaceID"); var user = FormulaHelper.GetUserInfo(); var space = DocConfigHelper.CreateConfigSpaceByID(spaceID); foreach (var nodeID in ids) { var node = new S_NodeInfo(nodeID, space); node.DataEntity.SetValue("BorrowState", ""); node.DataEntity.SetValue("BorrowUserID", ""); node.DataEntity.SetValue("BorrowUserName", ""); node.Save(false); } var list = this.BusinessEntities.Set <S_BorrowDetail>().Where(a => ids.Contains(a.RelateID)).ToList(); foreach (var item in list) { if (item.BorrowState == BorrowReturnState.Return.ToString()) { continue; } item.ReturnDate = DateTime.Now; item.ReturnUserID = user.UserID; item.ReturnUser = user.UserName; item.BorrowState = BorrowReturnState.Return.ToString(); } this.BusinessEntities.SaveChanges(); return(Json("")); }
private void Lend(Dictionary <string, object> row) { var lendNumber = 0; int.TryParse(row.GetValue("LendNumber"), out lendNumber); var id = row.GetValue("ID"); var borrowDetail = this.entities.Set <S_BorrowDetail>().FirstOrDefault(a => a.ID == id); var isNew = false; if (lendNumber > 0) { #region 部分借阅 if (borrowDetail == null) { if (string.IsNullOrEmpty(id)) { id = FormulaHelper.CreateGuid(); } borrowDetail = new S_BorrowDetail { ID = id, SpaceID = row.GetValue("SpaceID"), SpaceName = row.GetValue("SpaceName"), DataType = row.GetValue("DataType"), DetailType = row.GetValue("DetailType"), RelateID = row.GetValue("RelateID"), ConfigID = row.GetValue("ConfigID"), Name = row.GetValue("Name"), Code = row.GetValue("Code"), LendUserID = row.GetValue("LendUserID"), LendUserName = row.GetValue("LendUserName"), LendDeptID = row.GetValue("LendDeptID"), LendDeptName = row.GetValue("LendDeptName"), ParentID = row.GetValue("ParentID") }; var applyNumber = 0; int.TryParse(row.GetValue("ApplyNumber"), out applyNumber); borrowDetail.ApplyNumber = applyNumber; this.entities.Set <S_BorrowDetail>().Add(borrowDetail); isNew = true; var parent = this.entities.Set <S_BorrowDetail>().FirstOrDefault(a => a.ID == borrowDetail.ParentID); if (parent != null) { parent.HasChild = TrueOrFalse.True.ToString(); } } #endregion borrowDetail.LendUserID = row.GetValue("LendUserID"); borrowDetail.LendUserName = row.GetValue("LendUserName"); borrowDetail.LendDeptID = row.GetValue("LendDeptID"); borrowDetail.LendDeptName = row.GetValue("LendDeptName"); borrowDetail.LendNumber = (borrowDetail.LendNumber ?? 0) + lendNumber; if (borrowDetail.LendDate == null) { borrowDetail.LendDate = Convert.ToDateTime(row.GetValue("LendDate")); borrowDetail.BorrowExpireDate = Convert.ToDateTime(row.GetValue("BorrowExpireDate")); } borrowDetail.BorrowState = BorrowDetailState.ToReturn.ToString(); if (borrowDetail.DetailType == NodeType.Node.ToString()) { var space = DocConfigHelper.CreateConfigSpaceByID(borrowDetail.SpaceID); var nodeInfo = new S_NodeInfo(borrowDetail.RelateID, space); InventoryFO.CreateInventoryLedger(nodeInfo, InventoryType.Lend, 0, (0 - lendNumber), borrowDetail.ID, borrowDetail.LendUserID, borrowDetail.LendUserName, EnumBaseHelper.GetEnumDescription(InventoryType.Lend.GetType(), InventoryType.Lend.ToString()) + "份数:" + lendNumber + "份"); nodeInfo.DataEntity.SetValue("BorrowState", BorrowReturnState.Borrow.ToString()); nodeInfo.Save(false); if (isNew) { borrowDetail.Name = nodeInfo.CreateCarName(); } } else { var space = DocConfigHelper.CreateConfigSpaceByID(borrowDetail.SpaceID); var fileInfo = new S_FileInfo(borrowDetail.RelateID, space); InventoryFO.CreateInventoryLedger(fileInfo, InventoryType.Lend, 0, (0 - lendNumber), borrowDetail.ID, borrowDetail.LendUserID, borrowDetail.LendUserName, EnumBaseHelper.GetEnumDescription(InventoryType.Lend.GetType(), InventoryType.Lend.ToString()) + "份数:" + lendNumber + "份"); fileInfo.DataEntity.SetValue("BorrowState", BorrowReturnState.Borrow.ToString()); fileInfo.Save(false); if (isNew) { borrowDetail.Name = fileInfo.CreateCarName(); } } } else if (borrowDetail != null) { if (borrowDetail.LendDate == null) { borrowDetail.LendDate = Convert.ToDateTime(row.GetValue("LendDate")); } if (borrowDetail.BorrowExpireDate == null) { borrowDetail.BorrowExpireDate = Convert.ToDateTime(row.GetValue("BorrowExpireDate")); } } }