Exemple #1
0
        public static List <AssetsMain> ReadData(string filePath, ref ProgressInfo importProgress, IImportHistoryService importHistoryService, IUnImportAssetsService unImportAssetsService)
        {
            DataTable data = ReadFromFile(filePath);

            try
            {
                importProgress.TotalAssetsNum = data.Rows.Count;
            }
            catch (Exception)
            {
            }
            var list = new List <AssetsMain>();

            double total   = data.Rows.Count;
            double percent = 0.5;
            int    idx     = 0;

            foreach (DataRow row in data.Rows)
            {
                var assetsMain     = new AssetsMain();
                var unImportAssets = new UnImportAssets();
                try
                {
                    assetsMain.SchoolNum = Convert.ToString(row[Mappings.BxAssetsMapping["SchoolNumber"]]);
                    assetsMain.UsedNum2  = Convert.ToString(row[Mappings.BxAssetsMapping["StockNumber"]]);
                    // assetsMain.StockNumber = Convert.ToString(row[Mappings.BxAssetsMapping["StockNumber"]]);
                    assetsMain.GoodsName  = Convert.ToString(row[Mappings.BxAssetsMapping["GoodsName"]]);
                    assetsMain.GoodsName2 = Convert.ToString(row[Mappings.BxAssetsMapping["GoodsName2"]]);
                    #region 如果资产名称以其它开头就以扩展名为资产名称,如果存在扩展名,则以扩展名为资产名称

                    //if (assetsMain.GoodsName.Contains("其它"))
                    //  assetsMain.GoodsName = Convert.ToString(row[Mappings.BxAssetsMapping["GoodsName2"]]);
                    if (!assetsMain.GoodsName2.Equals(""))
                    {
                        assetsMain.GoodsName = Convert.ToString(row[Mappings.BxAssetsMapping["GoodsName2"]]);
                    }

                    #endregion

                    #region 抽取数据
                    assetsMain.CatCode            = Convert.ToString(row[Mappings.BxAssetsMapping["CatCode"]]).PadRight(9, '0');
                    assetsMain.AssetBlonged       = Convert.ToString(row[Mappings.BxAssetsMapping["AssetBlonged"]]);
                    assetsMain.AddType            = Convert.ToString(row[Mappings.BxAssetsMapping["AddType"]]);
                    assetsMain.Memo               = Convert.ToString(row[Mappings.BxAssetsMapping["GoodsName"]]);
                    assetsMain.ModelSpecification = Convert.ToString(row[Mappings.BxAssetsMapping["ModelSpecification"]]);
                    assetsMain.Brand              = Convert.ToString(row[Mappings.BxAssetsMapping["Brand"]]) + assetsMain.ModelSpecification;
                    assetsMain.MeasurementUnits   = Convert.ToString(row[Mappings.BxAssetsMapping["MeasurementUnits"]]);
                    assetsMain.AcountDocNum       = Convert.ToString(row[Mappings.BxAssetsMapping["AcountDocNum"]]);
                    assetsMain.InstNum            = Convert.ToString(row[Mappings.BxAssetsMapping["InstNum"]]);
                    assetsMain.IsFixAssets        = Convert.ToString(row[Mappings.BxAssetsMapping["IsFixAssets"]]) == "是" ? 1 : 0;
                    assetsMain.GetDate            = Convert.ToDateTime(row[Mappings.BxAssetsMapping["GetDate"]]);
                    assetsMain.PostingDate        = Convert.ToDateTime(row[Mappings.BxAssetsMapping["PostingDate"]]);
                    assetsMain.CeqmtNum           = Convert.ToString(row[Mappings.BxAssetsMapping["CeqmtNum"]]);
                    if (!string.IsNullOrEmpty(row[Mappings.BxAssetsMapping["Price"]].ToString()))
                    {
                        assetsMain.Price = Convert.ToDecimal(row[Mappings.BxAssetsMapping["Price"]]);
                    }
                    if (!string.IsNullOrEmpty(row[Mappings.BxAssetsMapping["EngineeringMaterial"]].ToString()))
                    {
                        assetsMain.EngineeringMaterial = Convert.ToDecimal(row[Mappings.BxAssetsMapping["EngineeringMaterial"]]);
                    }
                    if (!string.IsNullOrEmpty(row[Mappings.BxAssetsMapping["GovMoney"]].ToString()))
                    {
                        assetsMain.GovMoney = Convert.ToDecimal(row[Mappings.BxAssetsMapping["GovMoney"]]);
                    }
                    if (!string.IsNullOrEmpty(row[Mappings.BxAssetsMapping["Counts"]].ToString()))
                    {
                        assetsMain.Counts = Convert.ToInt32(row[Mappings.BxAssetsMapping["Counts"]]);
                    }
                    assetsMain.Agent       = Convert.ToString(row[Mappings.BxAssetsMapping["Agent"]]);
                    assetsMain.CanapplyNum = Convert.ToInt32(row[Mappings.BxAssetsMapping["CanapplyNum"]]);

                    assetsMain.NetWorth = assetsMain.Money = assetsMain.GovMoney;

                    #endregion

                    #region 填充默认值

                    assetsMain.UsingAttribute         = "01|办公设备";
                    assetsMain.UsingState             = "01|在用";
                    assetsMain.UsingStyle             = "01|自用";
                    assetsMain.GetWay                 = "01|购置";
                    assetsMain.ValueType              = "01|原值";
                    assetsMain.NoneGovMoney           = 0;
                    assetsMain.AccumulateDepreciation = 0;
                    assetsMain.Depreciation           = 0;
                    assetsMain.Memo = "";                       // 将备注栏清空

                    #endregion

                    #region 处理特殊设备

                    //
                    // 所有专用设备和通用设备全部拆分
                    //
                    if ((assetsMain.CatCode.StartsWith("3") || assetsMain.CatCode.StartsWith("2")) && assetsMain.Counts > 1)
                    {
                        //
                        // 价值、财政性资金、净值全部均分
                        //
                        assetsMain.GovMoney = assetsMain.NetWorth = assetsMain.Money
                                                                        = assetsMain.GovMoney = assetsMain.GovMoney / assetsMain.Counts;

                        //
                        // 数量为1
                        //
                        int loopTime = assetsMain.Counts;
                        assetsMain.Counts = 1;
                        //int fillSaterIndex = list.Count;
                        for (int count = 0; count < loopTime; count++)
                        {
                            //
                            // 对于需要做拆分的资产,需要在备注栏里面填写库存号和拆分序号
                            // 借助备注栏里的信息,当重复数据导入到系统后,系统是做覆盖的
                            // 而判重的标准如果只有库存号,被拆分的资产库存号都是一样的,所以借助备注栏信息进行二次判重:
                            // 首先判断库存号是否已经存在,如果已近存在,则做覆盖,在做覆盖之前,再进行备注栏信息判重
                            // 如果备注栏里没有信息则直接覆盖,如果备注栏有信息则进行二次判重
                            // 备注栏信息在数据库中存在该条目,则对该条目进行覆盖
                            // 否则就新增条目。通过上述机制,既能够保证数据拆分能够完全录入到系统,又能保证数据二次倒入的覆盖。
                            //

                            list.Add(new AssetsMain()
                            {
                                AssetsNum              = assetsMain.AssetsNum,
                                GoodsName              = assetsMain.GoodsName,
                                CatCode                = assetsMain.CatCode,
                                UsedNum1               = assetsMain.UsedNum1,
                                UsedNum2               = assetsMain.UsedNum2,
                                GetWay                 = assetsMain.GetWay,
                                GetDate                = assetsMain.GetDate,
                                Agent                  = assetsMain.Agent,
                                UsingAttribute         = assetsMain.UsingAttribute,
                                UsingState             = assetsMain.UsingState,
                                UsingStyle             = assetsMain.UsingStyle,
                                StorePlace             = assetsMain.StorePlace,
                                ValueType              = assetsMain.ValueType,
                                Money                  = assetsMain.Money,
                                GovMoney               = assetsMain.GovMoney,
                                NoneGovMoney           = assetsMain.NoneGovMoney,
                                PostingDate            = assetsMain.PostingDate,
                                Depreciation           = assetsMain.Depreciation,
                                AccumulateDepreciation = assetsMain.AccumulateDepreciation,
                                NetWorth               = assetsMain.NetWorth,
                                AcountDocNum           = assetsMain.AcountDocNum,
                                MeasurementUnits       = assetsMain.MeasurementUnits,
                                InputPerson            = assetsMain.InputPerson,
                                StockNumber            = assetsMain.StockNumber,
                                Counts                 = assetsMain.Counts,
                                Price                  = assetsMain.Price,
                                Brand                  = assetsMain.Brand,
                                ModelSpecification     = assetsMain.ModelSpecification,
                                EngineeringMaterial    = assetsMain.EngineeringMaterial,
                                IsFixAssets            = assetsMain.IsFixAssets,
                                IsDelete               = assetsMain.IsDelete,
                                IsUse                  = assetsMain.IsUse,
                                IsBorrow               = assetsMain.IsBorrow,
                                AssetsPicPath          = assetsMain.AssetsPicPath,
                                Memo         = assetsMain.UsedNum2 + "@" + count.ToString(CultureInfo.InvariantCulture),
                                InputTime    = assetsMain.InputTime,
                                ExtDataTable = assetsMain.ExtDataTable,
                                UsePeople    = assetsMain.UsePeople,
                                ImportId     = assetsMain.ImportId,
                                ImportType   = assetsMain.ImportType
                            });
                            idx++;
                        }
                        continue;
                    }

                    #endregion

                    list.Add(assetsMain);
                    idx++;
                    //percent = percent + 40.0/total;
                    //importProgress.ImportedPercentVal = (int)percent;
                }
                catch (Exception ex)
                {
                    unImportAssets.Exception    = ex.ToString();
                    unImportAssets.GoodsName    = assetsMain.GoodsName;
                    unImportAssets.StoreNum     = assetsMain.UsedNum2;
                    unImportAssets.TableName    = data.TableName;
                    unImportAssets.TableRow     = idx + 1;
                    unImportAssets.ImportType   = 1;                                             //(int) assetsMain.ImportType;
                    unImportAssets.ImportPerson = importHistoryService.LastHistory().UserId;
                    unImportAssets.ImportId     = importHistoryService.LastHistory().EntityId;   //Id
                    unImportAssets.ImportType   = importHistoryService.LastHistory().ImportType; //type
                    unImportAssets.ImportTime   = importHistoryService.LastHistory().ImportTime;
                    unImportAssets.Exception    = unImportAssets.Exception.Substring(0, 255);    // += ex.ToString();
                    unImportAssetsService.Add(unImportAssets);                                   //增加为导入资产
                    unImportAssetsService.Update(unImportAssets);
                }
                //异常仍然算进度
                percent = percent + 40.0 / total;
                try
                {
                    importProgress.ImportedPercentVal = (int)percent;
                }
                catch (Exception)
                {
                }

                rows = idx;
            } //for each

            return(list);
        }
Exemple #2
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);
        }
Exemple #3
0
        public ImportResult DoImport(string filePath, ref ProgressInfo importProgress)
        {
            //
            // 最后一次导入信息
            //
            int crntId   = _importHistoryService.LastHistory().EntityId;
            int crntType = _importHistoryService.LastHistory().ImportType;

            //
            // 将数据提取到List中
            //
            var list = BxReader.ReadData(filePath, ref importProgress, _importHistoryService, _unImportAssetsService);

            if (list == null)
            {
                ImportResult resultfalse = new ImportResult();
                resultfalse.ImportMsg = false;
                return(resultfalse);
            }
            //
            // 导入进度数据
            //
            double percent = 0.5;
            int    idx     = 0;
            //idx = BxReader.GetRows();
            int percentStep1 = importProgress.ImportedPercentVal;

            //
            // 导入结果
            //
            ImportResult result = new ImportResult();

            foreach (AssetsMain assets in list)
            {
                //
                // 判断数据库中是否存在库存号
                //
                if (!_assetsService.IsExistByStockNumber(assets.UsedNum2))
                {
                    //
                    // 如果不存在该库存号则新增数据
                    // 新增资产编号生成规则如下
                    // 产资产类别加上该资产类别累计新增的数量
                    //
                    var num = _assetsService.GetNextAssetsNum(assets.CatCode);
                    assets.AssetsNum  = string.Format("{0}{1}", assets.CatCode, num.PadLeft(6, '0')); // 生成资产编号
                    assets.ImportId   = crntId;                                                       //导入id
                    assets.ImportType = crntType;                                                     //导入类型 办学

                    //
                    // 更新资产类别累计录入数量:自增1
                    //
                    _assetsService.UpdateNextAssetsNum(assets.CatCode);

                    //
                    // 默认可领用可借用
                    //
                    assets.IsBorrow = 1;
                    assets.IsUse    = 1;

                    //
                    // 将记录写入到数据库
                    //
                    _assetsService.AddAssets(assets);

                    //
                    // 新增导入记录
                    //
                    result.Imported.Add(assets);

                    idx++;
                }
                //else
                //{
                //    result.UnImported.Add(new AssetsMainMsg(assets) {Message = "已存在 " + assets.StockNumber});
                //}
                else
                {
                    //
                    // 判断备注栏是否为空
                    // 如果为空则表示该资产没有被拆分过,直接覆盖
                    // 如果不为空,则通过备注来判断数据库是否存在该条目
                    // 如果存在该条目则覆盖,如果不存在则新增
                    //
                    if (assets.Memo == "")
                    {
                        //
                        // 表明资产没有被拆分,找到原有资产进行覆盖
                        // 资产编码不变,其余信息全部覆盖
                        //
                        //
                        var _existAssets = _assetsService.Get(assets.UsedNum2);// Get(assets.CatCode);
                        assets.EntityId   = _existAssets.EntityId;
                        assets.AssetsNum  = _existAssets.AssetsNum;
                        assets.ImportId   = crntId;   //导入id
                        assets.ImportType = crntType; //导入类型 办学

                        //
                        // 默认可领用可借用
                        //
                        assets.IsBorrow = 1;
                        assets.IsUse    = 1;

                        //
                        // 将记录写入到数据库
                        //
                        _assetsService.SaveAssets(assets);

                        //
                        // 新增导入记录
                        //
                        result.Imported.Add(assets);

                        //
                        // 删除原有的导入记录?
                        //
                        idx++;
                    }
                    else
                    {
                        if (!_assetsService.IsExistByMemo(assets.Memo))
                        {
                            //
                            // 表明资产被拆分了,但是在数据库中又找不到该条目,则新增条目
                            // 新增资产编号生成规则如下
                            // 产资产类别加上该资产类别累计新增的数量
                            //
                            var num = _assetsService.GetNextAssetsNum(assets.CatCode);
                            assets.AssetsNum  = string.Format("{0}{1}", assets.CatCode, num.PadLeft(6, '0')); // 生成资产编号
                            assets.ImportId   = crntId;                                                       //导入id
                            assets.ImportType = crntType;                                                     //导入类型 办学

                            //
                            // 更新资产类别累计录入数量:自增1
                            //
                            _assetsService.UpdateNextAssetsNum(assets.CatCode);

                            //
                            // 默认可领用可借用
                            //
                            assets.IsBorrow = 1;
                            assets.IsUse    = 1;

                            //
                            // 将记录写入到数据库
                            //
                            _assetsService.AddAssets(assets);

                            //
                            // 新增导入记录
                            //
                            result.Imported.Add(assets);

                            idx++;
                        }
                        else
                        {
                            //
                            // 表明资产被拆分了,但是在数据库中存在该记录,则需要覆盖原记录
                            //
                            var _existAssets = _assetsService.GetByMemo(assets.Memo);// Get(assets.CatCode);
                            assets.EntityId   = _existAssets.EntityId;
                            assets.AssetsNum  = _existAssets.AssetsNum;
                            assets.ImportId   = crntId;   //导入id
                            assets.ImportType = crntType; //导入类型 办学

                            //
                            // 默认可领用可借用
                            //
                            assets.IsBorrow = 1;
                            assets.IsUse    = 1;

                            //
                            // 将记录写入到数据库
                            //
                            _assetsService.SaveAssets(assets);

                            //
                            // 新增导入记录
                            //
                            result.Imported.Add(assets);

                            //
                            // 删除原有的导入记录?
                            //
                            idx++;
                        }
                    }
                }

                //
                // 进度显示
                //
                percent = percent + 70.0 / list.Count;
                importProgress.ImportedPercentVal = percentStep1 + (int)percent;;
                importProgress.ImportedAssetsNum  = idx - 1;
            }
            //percent = percent + 60.0 / list.Count;
            return(result);
        }
Exemple #4
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);
        }