Пример #1
0
        /// <summary>
        /// 将导入文件中的数据写入到数据库 2017-05-26 wnn
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="importProgress"></param>
        /// <returns></returns>
        public ImportResult DoUImport(string filePath, ref ProgressInfo importProgress, IImportHistoryService importHistoryService, IUnImportAssetsService unImportAssetsService, IRoleService roleService)
        {
            //
            // 创建导入编号和导入类型
            //
            int crntId   = _importHistoryService.LastHistory().EntityId;
            int crntType = _importHistoryService.LastHistory().ImportType;

            ImportResult result = new ImportResult();

            //
            // 从导入文件中提取数据
            //
            var list = DtReader.ReadUData(filePath, ref importProgress, _importHistoryService, _unImportAssetsService);

            //
            // 导入进度信息
            //
            double percent      = 0.5;
            int    idx          = 0;
            int    idxErr       = 1;
            int    percentStep1 = importProgress.ImportedPercentVal;

            //
            // 导入异常信息记录
            //
            var unInportAssets = new UnImportAssets();

            //
            // 开始向数据库写入数据
            //
            foreach (UserInfo userInfo in list)
            {
                try
                {
                    //
                    // 首先判断用户ID栏是否有数据
                    //
                    if (!string.IsNullOrEmpty(userInfo.UserId))
                    {
                        userInfo.Password = _userService.GetEncryptPwd(userInfo.Password);


                        Role role = _roleService.GetRole(userInfo.Role);
                        userInfo.Permissions = role.Permissions;


                        _userService.AddUser(userInfo);
                    }
                }
                //
                // 如果数据导入异常则记录导入异常问题
                //
                catch (Exception ex)
                {
                    //
                    // 保存异常信息
                    //
                    unInportAssets.Exception = ex.ToString();
                    //unInportAssets.GoodsName = assetsExt.GoodsName;
                    //unInportAssets.DynamicNum = assetsExt.UsedNum1;
                    //unInportAssets.TableName = data.TableName;
                    unInportAssets.TableRow     = idxErr;
                    unInportAssets.ImportType   = 1;                                             //(int) assetsMain.ImportType;
                    unInportAssets.ImportPerson = importHistoryService.LastHistory().UserId;
                    unInportAssets.ImportId     = importHistoryService.LastHistory().EntityId;   //Id
                    unInportAssets.ImportType   = importHistoryService.LastHistory().ImportType; //type
                    unInportAssets.ImportTime   = importHistoryService.LastHistory().ImportTime;
                    unInportAssets.Exception    = unInportAssets.Exception.Substring(0, 255);    // += ex.ToString();
                    //unImportAssetsService.Add(unInportAssets); //增加为导入资产
                    idxErr++;
                    //
                    // 继续执行下一条记录
                    //
                    continue;
                }
                //进度
                percent = percent + 60.0 / list.Count;

                try
                {
                    importProgress.ImportedPercentVal = percentStep1 + (int)percent;;
                    idx++;
                    importProgress.ImportedAssetsNum = idx;
                }
                catch (Exception)
                {
                }
            }
            return(result);
        }
Пример #2
0
        public List <DiffResult> Execute(string banxueFile, string dynamicFile, string diffBase)
        {
            //
            // 清空之前的比对结果
            //
            _assetsService.ClearDiffResult();

            //
            // 创建比对结果
            //
            var result = new List <DiffResult>();

            //
            // 获取本库数据
            //
            var localData = _assetsService.QueryPage(new AssetsQuery {
                PageIndex = 1, PageSize = int.MaxValue
            });

            //
            // 获取办学数据
            //
            List <AssetsMain> banxueData = null;

            if (!string.IsNullOrEmpty(banxueFile))
            {
                //double temp;
                banxueData = BxReader.ReadData(banxueFile, ref progress, _importHistoryService, _unImportAssetsService);
                banxueData = banxueData ?? new List <AssetsMain>();
            }

            //
            // 获取动态数据
            //
            List <AssetsMainExt> dynamicData = null;

            if (!string.IsNullOrEmpty(dynamicFile))
            {
                dynamicData = DtReader.ReadData(dynamicFile, ref progress, _importHistoryService, _unImportAssetsService);
                dynamicData = dynamicData ?? new List <AssetsMainExt>();
            }

            //
            // 开始比对
            //
            switch (diffBase)
            {
            case "本库":
                for (var index = 0; index < localData.Items.Count; index++)
                {
                    AssetsMain item     = localData.Items[index];
                    var        diffItem = new DiffResult
                    {
                        Index      = result.Count + 1,
                        LocalCode  = item.AssetsNum,
                        LocalName  = item.GoodsName,
                        LocalValue = item.Money,
                        LocalMode  = item.ModelSpecification,
                        LocalState = "存在"
                    };

                    //
                    // 办学比对
                    // 首先看办学数据是否存在该库存号
                    //
                    bool _tempState = banxueData.Any(x => x.UsedNum2 == item.UsedNum2);

                    //
                    // 如果存在该库存号,则比对资产名称/价值/规格
                    // 上述三项中有任意一项不匹配则表示存在但是数有差异
                    //
                    if (_tempState)
                    {
                        //
                        // 取出该条数据
                        //
                        AssetsMain _banxueData = new AssetsMain();
                        _banxueData = banxueData.FirstOrDefault(x => x.UsedNum2 == item.UsedNum2);

                        //
                        // 比对资产名称/价值/规格
                        //
                        bool _allSame = true;

                        bool _nameSame  = _banxueData.GoodsName == item.GoodsName;
                        bool _moneySame = _banxueData.Money == item.Money;
                        bool _modeSame  = _banxueData.Brand == item.Brand;
                        _allSame = _allSame & _nameSame & _moneySame & _modeSame;

                        //
                        // 填充比对结果
                        //
                        diffItem.BxState = _allSame ? "精确匹配" : "存在但有差异";
                        diffItem.BxCode  = _banxueData.UsedNum2;
                        diffItem.BxName  = _banxueData.GoodsName;
                        diffItem.BxValue = _banxueData.Money;
                        diffItem.BxMode  = _banxueData.Brand;
                    }
                    else
                    {
                        //
                        // 如果不存在该库存号,则无需对该资产进行办学比对
                        //
                        diffItem.BxState = "不存在";
                        diffItem.BxCode  = "";
                        diffItem.BxName  = "";
                        diffItem.BxValue = 0;
                        diffItem.BxMode  = "";
                    }

                    //
                    // 动态比对
                    //
                    _tempState = dynamicData.Any(x => x.UsedNum2 == item.UsedNum2);

                    //
                    // 如果存在该库存号,则比对资产名称/价值/规格
                    // 上述三项中有任意一项不匹配则表示存在但是数有差异
                    //
                    if (_tempState)
                    {
                        //
                        // 取出该条数据
                        //
                        AssetsMain _dynamicData = new AssetsMain();
                        _dynamicData = dynamicData.FirstOrDefault(x => x.UsedNum2 == item.UsedNum2);

                        //
                        // 比对资产名称/价值/规格
                        //
                        bool _allSame = true;

                        bool _nameSame  = _dynamicData.GoodsName == item.GoodsName;
                        bool _moneySame = _dynamicData.Money == item.Money;
                        bool _modeSame  = _dynamicData.Brand == item.Brand;
                        _allSame = _allSame & _nameSame & _moneySame & _modeSame;

                        //
                        // 填充比对结果
                        //
                        diffItem.DtState = _allSame ? "精确匹配" : "存在但有差异";
                        diffItem.DtCode  = _dynamicData.UsedNum2;
                        diffItem.DtName  = _dynamicData.GoodsName;
                        diffItem.DtValue = _dynamicData.Money;
                        diffItem.DtMode  = _dynamicData.Brand;
                    }
                    else
                    {
                        //
                        // 如果不存在该库存号,则无需对该资产进行办学比对
                        //
                        diffItem.DtState = "不存在";
                        diffItem.DtCode  = "";
                        diffItem.DtName  = "";
                        diffItem.DtValue = 0;
                        diffItem.DtMode  = "";
                    }

                    //
                    // 总比对结果
                    //
                    if ((diffItem.LocalState == "存在") && (diffItem.BxState == "存在") && (diffItem.DtState == "存在"))
                    {
                        diffItem.DiffState = "匹配";
                    }
                    else
                    {
                        diffItem.DiffState = "不匹配";
                    }
                    //
                    // 添加到比对结果列表
                    //
                    result.Add(diffItem);
                }
                break;

            case "办学库":
                for (var index = 0; index < banxueData.Count; index++)
                {
                    AssetsMain item     = banxueData[index];
                    var        diffItem = new DiffResult
                    {
                        Index   = result.Count + 1,
                        BxCode  = item.AssetsNum,
                        BxName  = item.GoodsName,
                        BxValue = item.Money,
                        BxMode  = item.ModelSpecification,
                        BxState = "存在"
                    };

                    //
                    // 本库比对
                    // 首先看办学数据是否存在该库存号
                    //
                    bool _tempState = localData.Items.Any(x => x.UsedNum2 == item.UsedNum2);

                    //
                    // 如果存在该库存号,则比对资产名称/价值/规格
                    // 上述三项中有任意一项不匹配则表示存在但是数有差异
                    //
                    if (_tempState)
                    {
                        //
                        // 取出该条数据
                        //
                        AssetsMain _localData = new AssetsMain();
                        _localData = localData.Items.FirstOrDefault(x => x.UsedNum2 == item.UsedNum2);

                        //
                        // 比对资产名称/价值/规格
                        //
                        bool _allSame = true;

                        bool _nameSame  = _localData.GoodsName == item.GoodsName;
                        bool _moneySame = _localData.Money == item.Money;
                        bool _modeSame  = _localData.Brand == item.Brand;
                        _allSame = _allSame & _nameSame & _moneySame & _modeSame;

                        //
                        // 填充比对结果
                        //
                        diffItem.LocalState = _allSame ? "精确匹配" : "存在但有差异";
                        diffItem.LocalCode  = _localData.UsedNum2;
                        diffItem.LocalName  = _localData.GoodsName;
                        diffItem.LocalValue = _localData.Money;
                        diffItem.LocalMode  = _localData.Brand;
                    }
                    else
                    {
                        //
                        // 如果不存在该库存号,则无需对该资产进行办学比对
                        //
                        diffItem.LocalState = "不存在";
                        diffItem.LocalCode  = "";
                        diffItem.LocalName  = "";
                        diffItem.LocalValue = 0;
                        diffItem.LocalMode  = "";
                    }

                    //
                    // 动态比对
                    //
                    _tempState = dynamicData.Any(x => x.UsedNum2 == item.UsedNum2);

                    //
                    // 如果存在该库存号,则比对资产名称/价值/规格
                    // 上述三项中有任意一项不匹配则表示存在但是数有差异
                    //
                    if (_tempState)
                    {
                        //
                        // 取出该条数据
                        //
                        AssetsMain _dynamicData = new AssetsMain();
                        _dynamicData = dynamicData.FirstOrDefault(x => x.UsedNum2 == item.UsedNum2);

                        //
                        // 比对资产名称/价值/规格
                        //
                        bool _allSame = true;

                        bool _nameSame  = _dynamicData.GoodsName == item.GoodsName;
                        bool _moneySame = _dynamicData.Money == item.Money;
                        bool _modeSame  = _dynamicData.Brand == item.Brand;
                        _allSame = _allSame & _nameSame & _moneySame & _modeSame;

                        //
                        // 填充比对结果
                        //
                        diffItem.DtState = _allSame ? "精确匹配" : "存在但有差异";
                        diffItem.DtCode  = _dynamicData.UsedNum2;
                        diffItem.DtName  = _dynamicData.GoodsName;
                        diffItem.DtValue = _dynamicData.Money;
                        diffItem.DtMode  = _dynamicData.Brand;
                    }
                    else
                    {
                        //
                        // 如果不存在该库存号,则无需对该资产进行办学比对
                        //
                        diffItem.DtState = "不存在";
                        diffItem.DtCode  = "";
                        diffItem.DtName  = "";
                        diffItem.DtValue = 0;
                        diffItem.DtMode  = "";
                    }

                    //
                    // 总比对结果
                    //
                    if ((diffItem.LocalState == "存在") && (diffItem.BxState == "存在") && (diffItem.DtState == "存在"))
                    {
                        diffItem.DiffState = "匹配";
                    }
                    else
                    {
                        diffItem.DiffState = "不匹配";
                    }

                    //
                    // 添加到比对结果列表
                    //
                    result.Add(diffItem);
                }
                break;

            case "动态库":
                for (var index = 0; index < dynamicData.Count; index++)
                {
                    AssetsMain item     = dynamicData[index];
                    var        diffItem = new DiffResult
                    {
                        Index   = result.Count + 1,
                        DtCode  = item.AssetsNum,
                        DtName  = item.GoodsName,
                        DtValue = item.Money,
                        DtMode  = item.ModelSpecification,
                        DtState = "存在"
                    };

                    //
                    // 本库比对
                    // 首先看办学数据是否存在该库存号
                    //
                    bool _tempState = localData.Items.Any(x => x.UsedNum2 == item.UsedNum2);

                    //
                    // 如果存在该库存号,则比对资产名称/价值/规格
                    // 上述三项中有任意一项不匹配则表示存在但是数有差异
                    //
                    if (_tempState)
                    {
                        //
                        // 取出该条数据
                        //
                        AssetsMain _localData = new AssetsMain();
                        _localData = localData.Items.FirstOrDefault(x => x.UsedNum2 == item.UsedNum2);

                        //
                        // 比对资产名称/价值/规格
                        //
                        bool _allSame = true;

                        bool _nameSame  = _localData.GoodsName == item.GoodsName;
                        bool _moneySame = _localData.Money == item.Money;
                        bool _modeSame  = _localData.Brand == item.Brand;
                        _allSame = _allSame & _nameSame & _moneySame & _modeSame;

                        //
                        // 填充比对结果
                        //
                        diffItem.LocalState = _allSame ? "精确匹配" : "存在但有差异";
                        diffItem.LocalCode  = _localData.UsedNum2;
                        diffItem.LocalName  = _localData.GoodsName;
                        diffItem.LocalValue = _localData.Money;
                        diffItem.LocalMode  = _localData.Brand;
                    }
                    else
                    {
                        //
                        // 如果不存在该库存号,则无需对该资产进行办学比对
                        //
                        diffItem.LocalState = "不存在";
                        diffItem.LocalCode  = "";
                        diffItem.LocalName  = "";
                        diffItem.LocalValue = 0;
                        diffItem.LocalMode  = "";
                    }

                    //
                    // 办学比对
                    // 首先看办学数据是否存在该库存号
                    //
                    _tempState = banxueData.Any(x => x.UsedNum2 == item.UsedNum2);

                    //
                    // 如果存在该库存号,则比对资产名称/价值/规格
                    // 上述三项中有任意一项不匹配则表示存在但是数有差异
                    //
                    if (_tempState)
                    {
                        //
                        // 取出该条数据
                        //
                        AssetsMain _banxueData = new AssetsMain();
                        _banxueData = banxueData.FirstOrDefault(x => x.UsedNum2 == item.UsedNum2);

                        //
                        // 比对资产名称/价值/规格
                        //
                        bool _allSame = true;

                        bool _nameSame  = _banxueData.GoodsName == item.GoodsName;
                        bool _moneySame = _banxueData.Money == item.Money;
                        bool _modeSame  = _banxueData.Brand == item.Brand;
                        _allSame = _allSame & _nameSame & _moneySame & _modeSame;

                        //
                        // 填充比对结果
                        //
                        diffItem.BxState = _allSame ? "精确匹配" : "存在但有差异";
                        diffItem.BxCode  = _banxueData.UsedNum2;
                        diffItem.BxName  = _banxueData.GoodsName;
                        diffItem.BxValue = _banxueData.Money;
                        diffItem.BxMode  = _banxueData.Brand;
                    }
                    else
                    {
                        //
                        // 如果不存在该库存号,则无需对该资产进行办学比对
                        //
                        diffItem.BxState = "不存在";
                        diffItem.BxCode  = "";
                        diffItem.BxName  = "";
                        diffItem.BxValue = 0;
                        diffItem.BxMode  = "";
                    }

                    //
                    // 总比对结果
                    //
                    if ((diffItem.LocalState == "存在") && (diffItem.BxState == "存在") && (diffItem.DtState == "存在"))
                    {
                        diffItem.DiffState = "匹配";
                    }
                    else
                    {
                        diffItem.DiffState = "不匹配";
                    }

                    //
                    // 添加到比对结果列表
                    //
                    result.Add(diffItem);
                }
                break;

            default:
                break;
            }



            //
            // 将比对结果写入比对结果表
            //
            foreach (DiffResult itemResult in result)
            {
                _assetsService.SaveDiffResult(itemResult);
            }

            return(result);
        }
Пример #3
0
        /// <summary>
        /// 将导入文件中的数据写入到数据库 2017-06-05 wnn
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="importProgress"></param>
        /// <returns></returns>
        public ImportResult DoPImport(string filePath, ref ProgressInfo importProgress, IImportHistoryService importHistoryService, IUnImportAssetsService unImportAssetsService, ISystemService sysService)
        {
            //
            // 创建导入编号和导入类型
            //
            int crntId   = _importHistoryService.LastHistory().EntityId;
            int crntType = _importHistoryService.LastHistory().ImportType;

            ImportResult result = new ImportResult();

            //
            // 从导入文件中提取数据
            //
            var list = DtReader.ReadPlData(filePath, ref importProgress, _importHistoryService, _unImportAssetsService);

            //
            // 导入进度信息
            //
            double percent      = 0.5;
            int    idx          = 0;
            int    idxErr       = 1;
            int    percentStep1 = importProgress.ImportedPercentVal;

            //
            // 导入异常信息记录
            //
            var unInportAssets = new UnImportAssets();

            //
            // 开始向数据库写入数据
            //
            foreach (Place place in list)
            {
                try
                {
                    var parentid = 0;
                    if (place.ParentName != "无")
                    {
                        var parentplace = _sysService.GetPlaceOne(place.ParentName);
                        parentid = parentplace.EntityId;
                    }

                    Place addPlace = new Place();

                    addPlace.ParentId  = parentid;
                    addPlace.PlaceName = place.PlaceName;
                    addPlace.PlaceType = place.PlaceType;

                    var temp = _sysService.GetPlaceOne(place.PlaceName);

                    if (temp == null)
                    {
                        _sysService.AddPlace(addPlace);
                    }
                    else
                    {
                        continue;
                    }
                    //}
                }
                //
                // 如果数据导入异常则记录导入异常问题
                //
                catch (Exception ex)
                {
                    //
                    // 保存异常信息
                    //
                    unInportAssets.Exception = ex.ToString();
                    //unInportAssets.GoodsName = assetsExt.GoodsName;
                    //unInportAssets.DynamicNum = assetsExt.UsedNum1;
                    //unInportAssets.TableName = data.TableName;
                    unInportAssets.TableRow     = idxErr;
                    unInportAssets.ImportType   = 1;                                             //(int) assetsMain.ImportType;
                    unInportAssets.ImportPerson = importHistoryService.LastHistory().UserId;
                    unInportAssets.ImportId     = importHistoryService.LastHistory().EntityId;   //Id
                    unInportAssets.ImportType   = importHistoryService.LastHistory().ImportType; //type
                    unInportAssets.ImportTime   = importHistoryService.LastHistory().ImportTime;
                    unInportAssets.Exception    = unInportAssets.Exception.Substring(0, 255);    // += ex.ToString();
                    //unImportAssetsService.Add(unInportAssets); //增加为导入资产
                    idxErr++;
                    //
                    // 继续执行下一条记录
                    //
                    continue;
                }
                //进度
                percent = percent + 60.0 / list.Count;

                try
                {
                    importProgress.ImportedPercentVal = percentStep1 + (int)percent;;
                    idx++;
                    importProgress.ImportedAssetsNum = idx;
                }
                catch (Exception ex)
                {
                }
            }
            return(result);
        }