コード例 #1
0
        /// <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 };
            }
        }
コード例 #2
0
        /// <summary>
        /// 模具入库
        /// </summary>
        /// <param name="moldNR">模具号</param>
        /// <param name="operatorNR">操作员工号</param>
        /// <param name="warehouseNR">仓库号</param>
        /// <param name="positionNR">库位号</param>
        /// <returns>入库信息</returns>
        public Message MoldInStore(string moldNR, string operatorNR, string warehouseNR, string positionNR)
        {
            try
            {
                using (IUnitOfWork unitwork = MSSqlHelper.DataContext())
                {
                    IPositionRepository positionRep = new PositionRepository(unitwork);
                    IMoldLastRecordRepository lastRecordRep = new MoldLastRecordRepository(unitwork);

                    // check if mold is reinstore again
                    if (lastRecordRep.MoldInStored(moldNR) == true)
                        return new Message() { MsgType = MsgType.Warn, Content = "此模具已经入库!" };
                    //check if position is available and allow over instore
                    if (positionRep.CheckPositionAvailable(warehouseNR, positionNR, 1) == false && Settings.Default.AllowOverInStore == false)
                        return new Message() { MsgType = MsgType.Warn, Content = "库位容量已打上限!" };

                    Position position = positionRep.GetByWarehouseNRAndPositionNR(warehouseNR, positionNR);

                    // add new uniqstorage
                    IUniqStorageRepository uniqStroageRep = new UniqStorageRepository(unitwork);
                    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 = moldNR;
                    storageRecord.Destination = position.PositionNR;
                    storageRecord.OperatorId = operatorNR;
                    storageRecord.Date = DateTime.Now;
                    storageRecord.Quantity = 1;
                    storageRecord.TargetNR = moldNR;
                    storageRecord.RecordType = StorageRecordType.InStore;

                    // add new storage record
                    IStorageRecordRepository recordRep = new StorageRecordRepository(unitwork);
                    recordRep.Add(storageRecord);

                    // add mold last apply
                    // add mold last apply storage record nr

                    MoldLastRecord lastRecord = new MoldLastRecord()
                    {
                        MoldNR = moldNR,
                         StorageRecordNR = storageRecord.StorageRecordNR
                    };
                   // lastRecord.StroageRecordNR = storageRecord.StorageRecordNR;
                    lastRecordRep.Add(lastRecord);

                    unitwork.Submit();
                    return new Message() { MsgType = MsgType.OK, Content = "入库成功!" };
                }
            }

            catch (Exception ex)
            {
                  LogUtil.log.Error(ex.ToString());
                  return new Message() { MsgType = MsgType.Error, Content = "请核实所填数据的准确性" };
            }
        }