Exemplo n.º 1
0
        /// <summary>
        /// 将模具从缓冲区移到库位
        /// </summary>
        /// <param name="moldNR">模具号</param>
        /// <param name="operatorNR">操作员工号</param>
        /// <param name="remark">备注</param>
        /// <returns>操作信息</returns>
        public Message ReturnMoldInPosition(string moldNR, string operatorNR, string remark)
        {
            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 = "模具还未归还,请归还后再入库!"
                               }
                    }
                    ;

                    string currentPosi = moldRep.GetMoldCurrPosiByMoldNR(moldNR);

                    if (!currentPosi.Equals(GetPartPoolPosiNr()))
                    {
                        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);
                    storageRecord.PositionId      = position.PositionID;
                    storageRecord.StorageRecordNR = GuidUtil.GenerateGUID();
                    storageRecord.Source          = currentPosi;
                    storageRecord.Destination     = position.PositionNR;
                    storageRecord.OperatorId      = operatorNR == null?string.Empty: operatorNR.ToString();
                    storageRecord.Date            = DateTime.Now;
                    storageRecord.Quantity        = 1;
                    storageRecord.TargetNR        = moldNR;
                    storageRecord.Remark          = remark == null?string.Empty:remark.ToString();
                    storageRecord.RecordType      = StorageRecordType.MoveStore;

                    // 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;
                    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
                });
            }
        }
Exemplo n.º 2
0
        /// <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
                });
            }
        }