/// <summary>
        /// 保存二维码信息
        /// </summary>
        /// <param name="twoDimensioncodeNum"></param>
        /// <param name="warehouseIDs"></param>
        /// <param name="speedChangeTypeID"></param>
        /// <returns></returns>
        public static CResult <bool> SaveTwoDimensioncode(string twoDimensioncodeNum, IEnumerable <int> warehouseIDs, int speedChangeTypeID)
        {
            if (string.IsNullOrWhiteSpace(twoDimensioncodeNum))
            {
                return(new CResult <bool>(false, ErrorCode.ParameterError));
            }

            using (var db = new WarehouseContext())
            {
                var twoDimensioncodeRepository = RepositoryIoc.GetTwoDimensioncodeRepository(db);
                var twoDimensionCode           = twoDimensioncodeRepository.FirstOrDefault(r => r.TwoDimensionCodeNum == twoDimensioncodeNum);
                if (twoDimensionCode == null)
                {
                    twoDimensionCode = new TwoDimensioncode();
                    twoDimensionCode.TwoDimensionCodeNum = twoDimensioncodeNum;
                    twoDimensionCode.Count = warehouseIDs.Count();
                    twoDimensionCode.SpeedChangeBoxTypeID = speedChangeTypeID;
                }
                else
                {
                    return(new CResult <bool>(false, ErrorCode.TwoDimensioncodeHasExist));
                }
                if (db.SaveChanges() > 0)
                {
                    var warehouseRepository = RepositoryIoc.GetWarehouseMRepository(db);
                    var warehouseList       = warehouseRepository.Get(r => warehouseIDs.Contains(r.WarehouseID));
                    foreach (var item in warehouseList)
                    {
                        item.TwoDimensioncodeID = twoDimensionCode.TwoDimensioncodeID;
                    }
                    return(new CResult <bool>(db.SaveChanges() > 0));
                }
                else
                {
                    return(new CResult <bool>(false, ErrorCode.SaveDbChangesFailed));
                }
            }
        }
        /// <summary>
        /// 保存入库信息
        /// </summary>
        /// <param name="barCodeList">条形码</param>
        /// <param name="twoDimensioncodeNum">二维码型号</param>
        /// <param name="speedChangeTypeID">产品类型ID</param>
        /// <param name="putInUserName">UserName</param>
        /// <param name="place">地点</param>
        /// <returns></returns>
        public static CResult <bool> SavePutInWarehouseInfo(List <string> barCodeList, string twoDimensioncodeNum, int speedChangeTypeID, string putInUserName, string place)
        {
            if (barCodeList == null)
            {
                return(new CResult <bool>(false, ErrorCode.ParameterError));
            }

            if (string.IsNullOrWhiteSpace(twoDimensioncodeNum))
            {
                return(new CResult <bool>(false, ErrorCode.ParameterError));
            }

            using (var db = new WarehouseContext())
            {
                var twoDimensioncodeRepository = RepositoryIoc.GetTwoDimensioncodeRepository(db);
                var twoDimensionCode           = twoDimensioncodeRepository.FirstOrDefault(r => r.TwoDimensionCodeNum == twoDimensioncodeNum);
                if (twoDimensionCode == null)
                {
                    twoDimensionCode = new TwoDimensioncode();
                    twoDimensionCode.TwoDimensionCodeNum = twoDimensioncodeNum;
                    twoDimensionCode.Count   = barCodeList.Count();
                    twoDimensionCode.StateID = (int)RecordState.Show;
                    twoDimensionCode.SpeedChangeBoxTypeID = speedChangeTypeID;
                    twoDimensioncodeRepository.Insert(twoDimensionCode);
                }
                else
                {
                    return(new CResult <bool>(false, ErrorCode.TwoDimensioncodeHasExist));
                }
                if (db.SaveChanges() <= 0)
                {
                    return(new CResult <bool>(false, ErrorCode.SaveDbChangesFailed));
                }
                var warehouseRepository = RepositoryIoc.GetWarehouseMRepository(db);
                foreach (var item in barCodeList)
                {
                    var warehouse = warehouseRepository.FirstOrDefault(r => r.BarCode == item);
                    if (warehouse == null)
                    {
                        warehouse                    = new WarehouseM();
                        warehouse.BarCode            = item;
                        warehouse.StateID            = (int)RecordState.Show;
                        warehouse.WarehouseTime      = DateTime.Now;
                        warehouse.PutInUserName      = putInUserName;
                        warehouse.Place              = place;
                        warehouse.TwoDimensioncodeID = twoDimensionCode.TwoDimensioncodeID;

                        var putInWare = new PutInWarehouseRecord();
                        putInWare.PutInTime     = DateTime.Now;
                        putInWare.Place         = place;
                        putInWare.PutInUserName = putInUserName;
                        putInWare.StateID       = (int)RecordState.Show;
                        putInWare.WarehouseID   = warehouse.WarehouseID;
                        warehouse.PutInWarehouseRecords.Add(putInWare);

                        warehouseRepository.Insert(warehouse);
                    }
                    else
                    {
                        if (warehouse.StateID == (int)RecordState.Show)
                        {
                            return(new CResult <bool>(false, ErrorCode.PutInInfoHasExist));
                        }
                        else
                        {
                            warehouse.WarehouseTime      = DateTime.Now;
                            warehouse.PutInUserName      = putInUserName;
                            warehouse.Place              = place;
                            warehouse.StateID            = (int)RecordState.Show;
                            warehouse.TwoDimensioncodeID = twoDimensionCode.TwoDimensioncodeID;
                            var putInWare = new PutInWarehouseRecord();
                            putInWare.PutInTime     = DateTime.Now;
                            putInWare.Place         = place;
                            putInWare.PutInUserName = putInUserName;
                            putInWare.StateID       = (int)RecordState.Show;
                            putInWare.WarehouseID   = warehouse.WarehouseID;
                            warehouse.PutInWarehouseRecords.Add(putInWare);
                        }
                    }
                }
                if (db.SaveChanges() > 0)
                {
                    return(new CResult <bool>(true));
                }
                else
                {
                    twoDimensioncodeRepository.Delete(twoDimensionCode);
                    db.SaveChanges();
                    return(new CResult <bool>(false, ErrorCode.SaveDbChangesFailed));
                }
            }
        }