private void DelBusiness()
        {
            try
            {
                switch (NavigatePath)
                {
                case ERealEstatePage.NaturalBuildingPage:
                    NaturalBuilding    naturalBuilding    = Business.NaturalBuilding;
                    NaturalBuildingDal naturalBuildingDal = new NaturalBuildingDal();
                    naturalBuildingDal.Del(naturalBuilding);
                    break;

                case ERealEstatePage.LogicalBuildingPage:
                    LogicalBuilding    logicalBuilding    = Business.LogicalBuilding;
                    LogicalBuildingDal logicalBuildingDal = new LogicalBuildingDal();
                    logicalBuildingDal.Del(logicalBuilding);
                    break;

                case ERealEstatePage.FloorPage:
                    Floor    floor    = Business.Floor;
                    FloorDal floorDal = new FloorDal();
                    floorDal.Del(floor);
                    break;

                case ERealEstatePage.HouseholdPage:
                    Household    household    = Business.Household;
                    HouseholdDal householdDal = new HouseholdDal();
                    householdDal.Del(household);
                    break;

                case ERealEstatePage.ObligeePage:
                    Obligee    obligee    = Business.Obligee;
                    ObligeeDal obligeeDal = new ObligeeDal();
                    obligeeDal.Del(obligee);
                    break;

                case ERealEstatePage.MortgagePage:
                    Mortgage    mortgage    = Business.Mortgage;
                    MortgageDal mortgageDal = new MortgageDal();
                    mortgageDal.Del(mortgage);
                    break;

                case ERealEstatePage.SequestrationPage:
                    Sequestration    sequestration    = Business.Sequestration;
                    SequestrationDal sequestrationDal = new SequestrationDal();
                    sequestrationDal.Del(sequestration);
                    break;

                default:
                    break;
                }
                BusinessNavCommand.Execute(NavigatePath);
            }
            catch (Exception ex)
            {
                ErrorDialogViewModel.getInstance().show(ex);
                return;
            }
        }
        /// <summary>
        /// 删除项目
        /// </summary>
        private void DelProject()
        {
            if (Project == null)
            {
                MessageBox.Show("请选择一个项目", "提示");
                return;
            }
            try
            {
                if ("1".Equals(Project.Type)) // 楼盘表项目
                {
                    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();

                    naturalBuildingDal.DelBy(t => t.ProjectID == Project.ID);
                    logicalBuildingDal.DelBy(t => t.ProjectID == Project.ID);
                    floorDal.DelBy(t => t.ProjectID == Project.ID);
                    householdDal.DelBy(t => t.ProjectID == Project.ID);
                    obligeeDal.DelBy(t => t.ProjectID == Project.ID);
                    mortgageDal.DelBy(t => t.ProjectID == Project.ID);
                    sequestrationDal.DelBy(t => t.ProjectID == Project.ID);
                }
                else if ("2".Equals(Project.Type)) // 登记业务项目
                {
                    TransferDal  transferDal  = new TransferDal();
                    ApplicantDal applicantDal = new ApplicantDal();

                    transferDal.DelBy(t => t.ProjectID == Project.ID);
                    applicantDal.DelBy(t => t.ProjectID == Project.ID);
                    FileHelper.DelDir(Project);
                }
                projectDal.Del(Project);
            }
            catch (Exception ex)
            {
                ErrorDialogViewModel.getInstance().show(ex);
                return;
            }

            RefreshProjectList();
        }
        public ICollection <LogicalBuilding> InitialLogicalBuildings(Project project)
        {
            LogicalBuildingDal logicalBuildingDal = new LogicalBuildingDal();

            return(logicalBuildingDal.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;
            }
        }
        public void Ongo()
        {
            try
            {
                TaskInfoDialog = TaskInfoDialogViewModel.getInstance();
                String FileName = Path.GetFileName(FullPath);
                //TaskInfoDialog.Messages.Add("开始导入:" + FileName);
                TaskMessage taskMessage = new TaskMessage();
                taskMessage.Title    = "导入项目:" + FileName;
                taskMessage.Progress = 0.0;
                TaskInfoDialog.Messages.Insert(0, taskMessage);
                Task task = new Task(() =>
                {
                    ImportRealEstateBook import = new ImportRealEstateBook();
                    import.FileName             = FullPath;
                    import.Read();

                    bool canContinue = import.ReadInformation();

                    if (canContinue)
                    {
                        taskMessage.Progress = 50.00;
                        //var naturalEffective = NaturalEffective(import.ZRZList);
                        var isNaturalBuildingUnique = IsNaturalBuildingUnique(import.NaturalBuildings);
                        var isHouseholdUnique       = IsHouseholdUnique(import.Households);
                        if (isNaturalBuildingUnique && isHouseholdUnique)
                        {
                            Project project       = InitialProject();
                            ProjectDal projectDal = new ProjectDal();
                            NaturalBuildingDal naturalBuildingDal = new NaturalBuildingDal();
                            LogicalBuildingDal logicalBuildingDal = new LogicalBuildingDal();
                            FloorDal floorDal         = new FloorDal();
                            HouseholdDal householdDal = new HouseholdDal();
                            ObligeeDal obligeeDal     = new ObligeeDal();
                            try
                            {
                                foreach (var naturalBuilding in import.NaturalBuildings)
                                {
                                    naturalBuilding.ID         = Guid.NewGuid();
                                    naturalBuilding.ProjectID  = project.ID;
                                    naturalBuilding.UpdateTime = DateTime.Now;
                                    naturalBuildingDal.Add(naturalBuilding);
                                }
                            }
                            catch (Exception ex)
                            {
                                ErrorMsg.Add("自然幢数据异常:" + ex.Message);
                            }
                            try
                            {
                                foreach (var logicalBuilding in import.LogicalBuildings)
                                {
                                    logicalBuilding.ID         = Guid.NewGuid();
                                    logicalBuilding.ProjectID  = project.ID;
                                    logicalBuilding.UpdateTime = DateTime.Now;
                                    logicalBuildingDal.Add(logicalBuilding);
                                }
                            }
                            catch (Exception ex)
                            {
                                ErrorMsg.Add("逻辑幢数据异常:" + ex.Message);
                            }
                            try
                            {
                                foreach (var floor in import.Floors)
                                {
                                    floor.ID         = Guid.NewGuid();
                                    floor.ProjectID  = project.ID;
                                    floor.UpdateTime = DateTime.Now;
                                    floorDal.Add(floor);
                                }
                            }
                            catch (Exception ex)
                            {
                                ErrorMsg.Add("层数据异常:" + ex.Message);
                            }
                            try
                            {
                                foreach (var household in import.Households)
                                {
                                    household.ID         = Guid.NewGuid();
                                    household.ProjectID  = project.ID;
                                    household.UpdateTime = DateTime.Now;
                                    householdDal.Add(household);
                                }
                            }
                            catch (Exception ex)
                            {
                                ErrorMsg.Add("户数据异常:" + ex.Message);
                            }
                            try
                            {
                                foreach (var obligee in import.Obligees)
                                {
                                    obligee.ID         = Guid.NewGuid();
                                    obligee.ProjectID  = project.ID;
                                    obligee.UpdateTime = DateTime.Now;
                                    obligeeDal.Add(obligee);
                                }
                            }
                            catch (Exception ex)
                            {
                                ErrorMsg.Add("权利人数据异常:" + ex.Message);
                            }
                            try
                            {
                                projectDal.Add(project);
                            }
                            catch (Exception ex)
                            {
                                ErrorMsg.Add("项目数据异常:" + ex.Message);
                            }
                        }
                    }
                    ErrorMsg.AddRange(import.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
                            {
                                taskMessage.Progress = 100.00;
                                taskMessage.DetailMessages.Add("导入成功");
                                // 刷新项目列表
                            }
                        }, null);
                    });
                });
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }