partial void DeleteMoldLastRecord(MoldLastRecord instance);
 /// <summary>
 /// 新建单个模具最新记录
 /// </summary>
 /// <param name="record">模具最新记录</param>
 public void Add(MoldLastRecord record)
 {
     context.MoldLastRecord.InsertOnSubmit(record);
 }
 partial void UpdateMoldLastRecord(MoldLastRecord instance);
 partial void InsertMoldLastRecord(MoldLastRecord instance);
		private void detach_MoldLastRecord(MoldLastRecord entity)
		{
			this.SendPropertyChanging();
			entity.Mold = null;
		}
		private void attach_MoldLastRecord(MoldLastRecord entity)
		{
			this.SendPropertyChanging();
			entity.Mold = this;
		}
        /// <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 = "请核实所填数据的准确性" };
            }
        }