/// <summary> /// 根据模具号获得库位号 /// </summary> /// <param name="posiNr">库位号</param> /// <returns>模具号</returns> public string GetMoldNrByPosiNr(string posiNr) { using (IUnitOfWork unitwork = MSSqlHelper.DataContext()) { IMoldRepository moldRep = new MoldRepository(unitwork); return(moldRep.GetMoldNrByPosiNr(posiNr)); } }
/// <summary> /// 模具移库 /// </summary> /// <param name="moldNR">模具号</param> /// <param name="sourcePosiNr">源位置号</param> /// <param name="desiPosiNr">目标位置号</param> /// <returns>移库信息</returns> public Message MoldMoveStore(string moldNR, string warehouseNR, string sourcePosiNr, string desiPosiNr) { try { using (IUnitOfWork unitwork = MSSqlHelper.DataContext()) { IPositionRepository posiRep = new PositionRepository(unitwork); if (!posiRep.PositionExsit(desiPosiNr)) { return new Message() { MsgType = MsgType.Warn, Content = "目标库位不存在,请核实!" } } ; IMoldRepository moldRep = new MoldRepository(unitwork); if (moldRep.GetMoldNrByPosiNr(desiPosiNr).Length == 0) { // there is no mold in desitination position // add new uniqstorage Position position = posiRep.GetByWarehouseNRAndPositionNR(warehouseNR, desiPosiNr); // add new uniqstorage IUniqStorageRepository uniqStroageRep = new UniqStorageRepository(unitwork); uniqStroageRep.DeleteByMoldNr(moldNR); UniqStorage uniqStorage = new UniqStorage() { UniqStorageId = GuidUtil.GenerateGUID(), UniqNR = moldNR, PositionId = position.PositionID, Quantity = 1 }; uniqStroageRep.Add(uniqStorage); //set value of storage record StorageRecord storageRecord = new StorageRecord(); storageRecord.PositionId = position.PositionID; storageRecord.StorageRecordNR = GuidUtil.GenerateGUID(); storageRecord.Source = sourcePosiNr; storageRecord.Destination = desiPosiNr; storageRecord.Date = DateTime.Now; storageRecord.Quantity = 1; storageRecord.TargetNR = moldNR; storageRecord.RecordType = StorageRecordType.MoveStore; // add new storage record IStorageRecordRepository recordRep = new StorageRecordRepository(unitwork); recordRep.Add(storageRecord); IMoldLastRecordRepository moldLastRecord = new MoldLastRecordRepository(unitwork); moldLastRecord.GetByMoldNR(moldNR).StorageRecordNR = storageRecord.StorageRecordNR; } else { Position sourcePosi = posiRep.GetByWarehouseNRAndPositionNR(warehouseNR, sourcePosiNr); Position desiPosi = posiRep.GetByWarehouseNRAndPositionNR(warehouseNR, desiPosiNr); UniqStorage sourceU = sourcePosi.UniqStorage.First(); UniqStorage desiU = desiPosi.UniqStorage.First(); string desiMoldNr = desiU.UniqNR; sourceU.UniqNR = desiMoldNr; desiU.UniqNR = moldNR; // add new storage record IStorageRecordRepository recordRep = new StorageRecordRepository(unitwork); StorageRecord sourcestorageRecord = new StorageRecord(); sourcestorageRecord.PositionId = sourcePosi.PositionID; sourcestorageRecord.StorageRecordNR = GuidUtil.GenerateGUID(); sourcestorageRecord.Source = sourcePosiNr; sourcestorageRecord.Destination = desiPosiNr; sourcestorageRecord.Date = DateTime.Now; sourcestorageRecord.Quantity = 1; sourcestorageRecord.TargetNR = moldNR; sourcestorageRecord.RecordType = StorageRecordType.MoveStore; recordRep.Add(sourcestorageRecord); StorageRecord desistorageRecord = new StorageRecord(); desistorageRecord.PositionId = desiPosi.PositionID; desistorageRecord.StorageRecordNR = GuidUtil.GenerateGUID(); desistorageRecord.Source = desiPosiNr; desistorageRecord.Destination = sourcePosiNr; desistorageRecord.Date = DateTime.Now; desistorageRecord.Quantity = 1; desistorageRecord.TargetNR = desiMoldNr; desistorageRecord.RecordType = StorageRecordType.MoveStore; recordRep.Add(desistorageRecord); IMoldLastRecordRepository moldLastRecord = new MoldLastRecordRepository(unitwork); moldLastRecord.GetByMoldNR(moldNR).StorageRecordNR = sourcestorageRecord.StorageRecordNR; moldLastRecord.GetByMoldNR(desiMoldNr).StorageRecordNR = desistorageRecord.StorageRecordNR; } unitwork.Submit(); return(new Message() { MsgType = MsgType.OK, Content = "移库成功" }); } } catch (Exception ex) { LogUtil.log.Error(ex.ToString()); return(new Message() { MsgType = MsgType.Error, Content = ex.Message }); } }