/// <summary>
        /// 根据模具警报类型获得模具警报信息
        /// </summary>
        /// <param name="type">模具警报类型</param>
        /// <returns>模具警报信息列表</returns>
        public List<MoldWarnInfo> GetMoldWarnInfo(MoldWarnType type)
        {
            using (IUnitOfWork unitwork = MSSqlHelper.DataContext())
            {
                IMoldRepository moldRepostitory = new MoldRepository(unitwork);
                List<MoldView> molds = moldRepostitory.GetByWarnType(type);
                List<MoldWarnInfo> moldWarnInfos = new List<MoldWarnInfo>();

                foreach (MoldView m in molds)
                {
                    MoldWarnInfo moldWarnInfo = new MoldWarnInfo()
                    {
                        MoldNR = m.MoldNR,
                        Type = m.TypeName,
                        ProjectName = m.ProjectName,
                        MaxLendHour = (double)m.MaxLendHour,
                        LendTime = (DateTime)m.LastRecordDate,
                        CurrentPosition = m.StorageRecordNR.HasValue ? moldRepostitory.GetMoldCurrPosiByRecordNR((Guid)m.StorageRecordNR) : string.Empty
                    };
                    moldWarnInfos.Add(moldWarnInfo);
                }

                return moldWarnInfos;
            }
        }
        /// <summary>
        /// 根据模具号获得模具动态信息
        /// </summary>
        /// <param name="moldNR">模具号</param>
        /// <returns>模具基本信息</returns>
        public MoldDynamicInfo GetMoldDynamicInfoByMoldNR(string moldNR)
        {
            using (IUnitOfWork unitwork = MSSqlHelper.DataContext())
            {
                IMoldRepository moldRepostitory = new MoldRepository(unitwork);

                MoldView moldview = moldRepostitory.GetMoldViewByMoldNR(moldNR);

                if (moldview == null)
                    return null;

                IStorageRecordRepository storageRep = new StorageRecordRepository(unitwork);
                StorageRecord storageRecord = null;
                if (moldview.StorageRecordNR != null)
                {
                    storageRecord = storageRep.GetByStorageNR((Guid)moldview.StorageRecordNR);
                }

                MoldDynamicInfo moldDynamicInfo = new MoldDynamicInfo()
                {
                    CurrentPosition = moldview.StorageRecordNR == null ? string.Empty : moldRepostitory.GetMoldCurrPosiByRecordNR((Guid)moldview.StorageRecordNR),
                    Operator = storageRecord == null ? string.Empty : storageRecord.OperatorId,
                    OperateTime = storageRecord == null ? string.Empty : storageRecord.Date.ToString(),
                    AllowedCuttedTime = moldview.MaxCuttimes,
                    CurrentCuttedTime = moldview.CurrentCuttimes,
                    ReleaseCycle = moldview.ReleaseCycle,
                    LastReleasedTime = moldview.LastReleasedDate.ToString(),
                    MantainCycle = moldview.MaintainCycle,
                    LastMantainTime = moldview.LastMainedDate.ToString(),
                    State = moldview.State,
                    StateCN = EnumUtil.GetEnumDescriptionByEnumValue(moldview.State),
                    ProjectId = moldview.ProjectID,
                    ProjectName = moldview.ProjectName
                };
                return moldDynamicInfo;
            }
        }
        /// <summary>
        /// 根据搜索条件获得模具基本信息
        /// </summary>
        /// <param name="conditions">搜索条件</param>
        /// <returns>模具基本信息列表</returns>
        public List<MoldBaseInfo> GetMoldByMutiConditions(MoldSearchCondition conditions)
        {
            using (IUnitOfWork unitwork = MSSqlHelper.DataContext())
            {
                IMoldRepository moldRepostitory = new MoldRepository(unitwork);
                List<MoldView> molds = moldRepostitory.GetByMutiConditions(conditions);
                List<MoldBaseInfo> moldBaseInfos = new List<MoldBaseInfo>();

                foreach (MoldView m in molds)
                {
                    MoldBaseInfo moldBaseInfo = new MoldBaseInfo()
                    {
                        MoldNR = m.MoldNR,
                        Name = m.Name,
                        Type = m.TypeName,
                        State = m.State,
                        StateCN = m.StateCN,
                        ProjectId = m.ProjectID,
                        ProjectName = m.ProjectName,
                        CurrentPosition = m.StorageRecordNR.HasValue ? moldRepostitory.GetMoldCurrPosiByRecordNR((Guid)m.StorageRecordNR) : string.Empty
                    };
                    moldBaseInfos.Add(moldBaseInfo);
                }

                return moldBaseInfos;
            }
        }
 /// <summary>
 /// 根据模具号获得库位号
 /// </summary>
 /// <param name="moldNR">模具号</param>
 /// <returns>库位号</returns>
 public string GetMoldCurrentPosition(string moldNR)
 {
     using (IUnitOfWork unitwork = MSSqlHelper.DataContext())
     {
         IMoldRepository moldRepostitory = new MoldRepository(unitwork);
         MoldView moldview = moldRepostitory.GetMoldViewByMoldNR(moldNR);
         return moldview.StorageRecordNR == null ? string.Empty : moldRepostitory.GetMoldCurrPosiByRecordNR((Guid)moldview.StorageRecordNR);
     }
 }
        /// <summary>
        /// 模具移动工作台
        /// </summary>
        /// <param name="moldNR">模具号</param>
        /// <param name="operatorNR">操作员工号</param>
        /// <param name="targetWStationNR">目标工作台号</param>
        /// <returns>移动信息</returns> 
        public Message MoldMoveWorkStation(string moldNR, string operatorNR, string targetWStationNR)
        {
            try
            {
                using (IUnitOfWork unitwork = MSSqlHelper.DataContext())
                {
                    IWorkstationRepository workstationRep = new WorkstationRepository(unitwork);
                    IMoldRepository moldRep = new MoldRepository(unitwork);
                    IEmployeeRepository empRep = new EmployeeRepository(unitwork);

                    Mold mold = moldRep.GetById(moldNR);

                    if (!empRep.Exist(operatorNR))
                        return new Message() { MsgType = MsgType.Warn, Content = "操作员不存在!" };
                    if(mold==null)
                        return new Message() { MsgType = MsgType.Warn, Content = "模具不存在!" };
                    Workstation tworkstation=workstationRep.GetById(targetWStationNR);
                    if (tworkstation == null)
                      return new Message() { MsgType = MsgType.Warn, Content = "目标工作台不存在!" };

                      // check mold is available for move
                    if (mold.State != MoldStateType.NotReturned)
                        return new Message() { MsgType = MsgType.Warn, Content = "模具未被借用,请先借用!" };

                    MoldView moldview = moldRep.GetMoldViewByMoldNR(moldNR);

                    string currentWorkPosi = moldview.StorageRecordNR == null ? string.Empty : moldRep.GetMoldCurrPosiByRecordNR((Guid)moldview.StorageRecordNR);

                 //   if(workstationRep.GetById(currentWorkPosi)==null)
                  //      return new Message() { MsgType = MsgType.Warn, Content = "模具正在使用的工作台号已经被修改,请先归还此模具再做后续操作!" };

                    if (currentWorkPosi.Equals(targetWStationNR))
                        return new Message() { MsgType = MsgType.Warn, Content = "模具已经在此工作台,不可重复移动!" };

                    // check workstaition reach the max mold apply number
                    if (workstationRep.OverAppliedMold(targetWStationNR) == false && Settings.Default.AllowOverApply == false)
                        return new Message() { MsgType = MsgType.Warn, Content = "目标工作台已经到达模具使用上限!" };

                    IPositionRepository positionRep = new PositionRepository(unitwork);
                    Position position = positionRep.GetByFacilictyNR(moldNR);

                    //set value of storage record
                    IStorageRecordRepository recordRep = new StorageRecordRepository(unitwork);
                    StorageRecord storageRecord = new StorageRecord();
                    storageRecord.StorageRecordNR = GuidUtil.GenerateGUID();
                    storageRecord.PositionId = position.PositionID;
                    storageRecord.Source = currentWorkPosi;
                    storageRecord.Destination = targetWStationNR;
                    storageRecord.OperatorId = operatorNR;
                    storageRecord.Quantity = 1;
                    storageRecord.Date = DateTime.Now;
                    storageRecord.TargetNR = moldNR;
                    storageRecord.RecordType = StorageRecordType.MoveWStation;

                    // add new storage record
                    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 the workstation current mold count
                    //Workstation tworkstation = workstationRep.GetById(storageRecord.Destination);
                    //if(tworkstation!=null)
                      tworkstation.CurrentMoldCount++;

                    Workstation sworkstation = workstationRep.GetById(storageRecord.Source);
                    if(sworkstation!=null)
                       sworkstation.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 = "请核实所填数据的准确性" };
            }
        }