예제 #1
0
        async public Task <object> ExportWhenBudgetProjectOfEnter(IEnumerable <int> listOfId, string BudgetTypeName)
        {
            if (listOfId.Count() == 0)
            {
                throw new Exception("没有选中项目");
            }

            //后台指定归口部门的过滤条件;
            var filterExtend = new BudgetProjectExtendFilter
            {
                WhereInId = listOfId.ToStringIdWithSpacer()
            };

            var list = (await Db.GetListSpAsync <VBudgetProject, BudgetProjectExtendFilter>(filterExtend)).ToList();
            var listOfExportWhenBudgetProjectOfEnter = new List <ExportWhenBudgetProjectOfEnter>();

            for (int i = 0, count = list.Count(); i < count; i++)
            {
                var vBudgetProject = list[i];
                var exportWhenBudgetProjectOfEnter = Tool.ModelToModel <ExportWhenBudgetProjectOfEnter, VBudgetProject>(vBudgetProject);
                exportWhenBudgetProjectOfEnter.Id = i + 1;
                exportWhenBudgetProjectOfEnter.IsCenterPurchase = vBudgetProject.IsCenterPurchase == true ? "是" : "否";
                exportWhenBudgetProjectOfEnter.BudgetTypeName   = BudgetTypeName;
                listOfExportWhenBudgetProjectOfEnter.Add(exportWhenBudgetProjectOfEnter);
            }
            var fileName = $"导出进入预算项目_{DateTime.Now.ToString("yyyyMMddHHmmss")}.xlsx";
            var filePath = MyPath.Combine(Env.WebRootPath, "Download");

            var result = MyXls.Export(filePath, listOfExportWhenBudgetProjectOfEnter, fileName);

            return(MyPath.Combine("Download", result));
        }
예제 #2
0
        async public Task <object> ExportWhenBudgetProjectOfArgument(BudgetProjectFilter filter, IEnumerable <int> listOfId)
        {
            //后台指定归口部门的过滤条件;
            var filterExtend = Tool.ModelToModel <BudgetProjectExtendFilter, BudgetProjectFilter>(filter);

            filterExtend.RelevantDepartmentId = CurrentUser.DepartmentId;
            filterExtend.WhereInId            = listOfId.Count() == 0 ? null : listOfId.ToStringIdWithSpacer();

            var list = (await Db.GetListSpAsync <VBudgetProjectNotInFlow, BudgetProjectExtendFilter>(filterExtend)).ToList();

            var listOfPackage = (await Db.GetListSpAsync <VPackageOfDeclareProject, PackageOfBudgetProjectFilter>(
                                     new PackageOfBudgetProjectFilter()
            {
                WhereInBudgetProjectId = list.Select(i => i.Id).ToStringIdWithSpacer()
            })).ToList();

            var zipFileName = $"导出待论证项目_{DateTime.Now.ToString("yyyyMMddHHmmss")}";
            var zipPathName = MyPath.Combine(Env.WebRootPath, "Download", zipFileName);

            Directory.CreateDirectory(zipPathName);

            zipFileName = $"{zipFileName}.zip";
            var zipPathFileName     = MyPath.Combine(Env.WebRootPath, "Download", zipFileName);
            var relativeZipPathName = MyPath.Combine("Download", zipFileName);

            for (int i = 0, countOfList = list.Count(); i < countOfList; i++)
            {
                var item             = list[i];
                var itemName         = $"{item.Name}-{item.MergeTypeWhenBudget}";
                var zipChildPathName = MyPath.Combine(zipPathName, itemName);
                Directory.CreateDirectory(zipChildPathName);
                //如果是集采-货物,则生成一个容纳了各个包为ExportWhenBudgetProjectOfArgumentCaseGoods的excel
                if (item.IsCenterPurchase && item.ProjectType == "货物")
                {
                    var packages = from itemOfPackage in listOfPackage
                                   where itemOfPackage.BudgetProjectId.Equals(item.Id)
                                   select Tool.ModelToModel <ExportWhenBudgetProjectOfArgumentCaseGoods, VPackageOfDeclareProject>(itemOfPackage);

                    MyXls.Export(zipChildPathName, packages, itemName);
                }
                else
                {
                    var packages = (from itemOfPackage in listOfPackage
                                    where itemOfPackage.BudgetProjectId.Equals(item.Id)
                                    select Tool.ModelToModel <ExportWhenBudgetProjectOfArgumentCaseOther, VPackageOfDeclareProject>(itemOfPackage)).ToList();

                    for (int j = 0, countOfPackages = packages.Count(); j < countOfPackages; j++)
                    {
                        var itemOfPackage = packages[j];
                        itemOfPackage.Id = j + 1;
                        //itemOfPackage.Attachment = Path.GetFileName(itemOfPackage.Attachment);

                        System.IO.File.Copy(
                            MyPath.Combine(Env.WebRootPath, itemOfPackage.Attachment),
                            MyPath.Combine(zipChildPathName, $"第{itemOfPackage.Id }包-{Path.GetFileName(itemOfPackage.Attachment)}"));
                    }

                    MyXls.Export(zipChildPathName, packages, itemName);
                }
            }
            ZipFile.CreateFromDirectory(zipPathName, zipPathFileName);
            return(relativeZipPathName);
        }