/// <summary> /// 归还模具 /// </summary> /// <param name="moldNR">模具号</param> /// <param name="applicantNR">申请员工工号</param> /// <param name="operatorNR">操作员工工号</param> /// <param name="remark">备注</param> /// <param name="moldState">模具状态</param> /// <returns>归还信息</returns> public Message ReturnMold(string moldNR, string applicantNR, string operatorNR, string remark, MoldReturnStateType moldState) { try { using (IUnitOfWork unitwork = MSSqlHelper.DataContext()) { IMoldRepository moldRep = new MoldRepository(unitwork); Mold mold = moldRep.GetById(moldNR); if (mold.State != MoldStateType.NotReturned) { return new Message() { MsgType = MsgType.Warn, Content = "模具已归还!" } } ; StorageRecord storageRecord = new StorageRecord(); //set value of storage record IPositionRepository positionRep = new PositionRepository(unitwork); //Position position = positionRep.GetByFacilictyNR(moldNR); Position position = positionRep.GetPartPoolPosition(Settings.Default.MoldPoolPosiNr); storageRecord.PositionId = position.PositionID; storageRecord.StorageRecordNR = GuidUtil.GenerateGUID(); storageRecord.Source = moldRep.GetMoldCurrPosiByMoldNR(moldNR); storageRecord.Destination = position.PositionNR; storageRecord.OperatorId = operatorNR; storageRecord.ApplicantId = applicantNR; storageRecord.Date = DateTime.Now; storageRecord.Quantity = 1; storageRecord.TargetNR = moldNR; storageRecord.Remark = remark; storageRecord.RecordType = StorageRecordType.Return; // add new storage record IStorageRecordRepository recordRep = new StorageRecordRepository(unitwork); recordRep.Add(storageRecord); // update mold last apply storage record nr IMoldLastRecordRepository lastRecordRep = new MoldLastRecordRepository(unitwork); MoldLastRecord lastRecord = lastRecordRep.GetByMoldNR(moldNR); lastRecord.StorageRecordNR = storageRecord.StorageRecordNR; // update mold state mold = moldRep.GetById(storageRecord.TargetNR); mold.State = (MoldStateType)moldState; // update workstation mold count IWorkstationRepository workstationRep = new WorkstationRepository(unitwork); Workstation workstation = workstationRep.GetById(storageRecord.Source); if (workstation != null) { workstation.CurrentMoldCount--; } 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 }); } }
/// <summary> /// 归还模具 /// </summary> /// <param name="moldNR">模具号</param> /// <param name="applicantNR">申请员工工号</param> /// <param name="operatorNR">操作员工工号</param> /// <param name="remark">备注</param> /// <param name="moldState">模具状态</param> /// <returns>归还信息</returns> public Message ReturnMold(string moldNR, string applicantNR, string operatorNR, string remark, MoldReturnStateType moldState) { try { using (IUnitOfWork unitwork = MSSqlHelper.DataContext()) { IMoldRepository moldRep = new MoldRepository(unitwork); Mold mold = moldRep.GetById(moldNR); if (mold.State != MoldStateType.NotReturned) return new Message() {MsgType= MsgType.Warn, Content = "模具已归还!" }; StorageRecord storageRecord = new StorageRecord(); //set value of storage record IPositionRepository positionRep = new PositionRepository(unitwork); //Position position = positionRep.GetByFacilictyNR(moldNR); Position position = positionRep.GetPartPoolPosition(Settings.Default.MoldPoolPosiNr); storageRecord.PositionId = position.PositionID; storageRecord.StorageRecordNR = GuidUtil.GenerateGUID(); storageRecord.Source = moldRep.GetMoldCurrPosiByMoldNR(moldNR); storageRecord.Destination = position.PositionNR; storageRecord.OperatorId = operatorNR; storageRecord.ApplicantId = applicantNR; storageRecord.Date = DateTime.Now; storageRecord.Quantity = 1; storageRecord.TargetNR = moldNR; storageRecord.Remark = remark; storageRecord.RecordType = StorageRecordType.Return; // add new storage record IStorageRecordRepository recordRep = new StorageRecordRepository(unitwork); recordRep.Add(storageRecord); // update mold last apply storage record nr IMoldLastRecordRepository lastRecordRep = new MoldLastRecordRepository(unitwork); MoldLastRecord lastRecord = lastRecordRep.GetByMoldNR(moldNR); lastRecord.StorageRecordNR = storageRecord.StorageRecordNR; // update mold state mold = moldRep.GetById(storageRecord.TargetNR); mold.State =(MoldStateType)moldState; // update workstation mold count IWorkstationRepository workstationRep = new WorkstationRepository(unitwork); Workstation workstation = workstationRep.GetById(storageRecord.Source); if(workstation!=null) workstation.CurrentMoldCount--; 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 }; } }