Ejemplo n.º 1
0
        public ICollection <Obligee> InitialObligees(Project project)
        {
            ObligeeDal obligeeDal = new ObligeeDal();

            return(obligeeDal.GetListBy((t) => t.ProjectID == project.ID));
        }
        public void Ongo()
        {
            try
            {
                TaskInfoDialog = TaskInfoDialogViewModel.getInstance();
                TaskMessage taskMessage = new TaskMessage();
                taskMessage.Title    = "导出项目:" + Project.ProjectName;
                taskMessage.Progress = 0.0;
                TaskInfoDialog.Messages.Insert(0, taskMessage);

                NaturalBuildingDal naturalBuildingDal = new NaturalBuildingDal();
                LogicalBuildingDal logicalBuildingDal = new LogicalBuildingDal();
                FloorDal           floorDal           = new FloorDal();
                HouseholdDal       householdDal       = new HouseholdDal();
                ObligeeDal         obligeeDal         = new ObligeeDal();
                MortgageDal        mortgageDal        = new MortgageDal();
                SequestrationDal   sequestrationDal   = new SequestrationDal();

                Task task = new Task(() =>
                {
                    try
                    {
                        book.Project          = Project;
                        book.TaskMessage      = taskMessage;
                        book.NaturalBuildings = naturalBuildingDal.GetListBy(t => t.ProjectID == Project.ID);
                        book.LogicalBuildings = logicalBuildingDal.GetListBy(t => t.ProjectID == Project.ID);
                        book.Floors           = floorDal.GetListBy(t => t.ProjectID == Project.ID);
                        book.Households       = householdDal.GetListBy(t => t.ProjectID == Project.ID);
                        book.Obligees         = obligeeDal.GetListBy(t => t.ProjectID == Project.ID);
                        if ("2".Equals(Project.OwnershipType))
                        {
                            book.Mortgages      = mortgageDal.GetListBy(t => t.ProjectID == Project.ID);
                            book.Sequestrations = sequestrationDal.GetListBy(t => t.ProjectID == Project.ID);
                        }

                        book.Open(TemplateFileName);
                        book.Write();
                        //book.SaveAsExcel(SaveFileName);
                    }
                    catch (Exception ex)
                    {
                        ErrorMsg.Add(ex.Message);
                    }
                    ErrorMsg.AddRange(book.ErrorMsg);
                });
                task.Start();
                task.ContinueWith(t =>
                {
                    ThreadPool.QueueUserWorkItem(delegate
                    {
                        SynchronizationContext.SetSynchronizationContext(new
                                                                         System.Windows.Threading.DispatcherSynchronizationContext(System.Windows.Application.Current.Dispatcher));
                        SynchronizationContext.Current.Post(pl =>
                        {
                            foreach (var error in ErrorMsg)
                            {
                                taskMessage.DetailMessages.Add(error);
                            }
                            if (ErrorMsg != null && ErrorMsg.Count > 0)
                            {
                                taskMessage.DetailMessages.Add("导出失败");
                            }
                            else
                            {
                                string bufferPath = System.AppDomain.CurrentDomain.BaseDirectory + @"Buffer\" + Path.GetFileName(SaveFileName);
                                try
                                {
                                    book.SaveAsExcel(bufferPath);

                                    //// 压缩成报盘
                                    //ZipHelper zipHelper = new ZipHelper();
                                    //zipHelper.ZipFile(SaveFileName.Replace(".bpf", ".xls"), SaveFileName, 5, 500);
                                    //// 删除excel
                                    //File.Delete(SaveFileName.Replace(".bpf", ".xls"));

                                    if (Path.GetExtension(bufferPath) == ".xls")
                                    {
                                        File.Copy(bufferPath, SaveFileName, true);
                                        File.Delete(bufferPath);
                                    }
                                    else if (Path.GetExtension(bufferPath) == ".bpf")
                                    {
                                        File.Copy(bufferPath.Replace(".xls", ".bpf"), SaveFileName.Replace(".xls", ".bpf"), true);
                                        File.Delete(bufferPath.Replace(".xls", ".bpf"));
                                    }

                                    taskMessage.Progress = 100.00;
                                    taskMessage.DetailMessages.Add("导出成功");
                                }
                                catch (Exception ex)
                                {
                                    taskMessage.DetailMessages.Add(ex.Message + ex.StackTrace);
                                }
                            }
                        }, null);
                    });
                });
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }