Beispiel #1
0
        public FunctionResult <Project> Create(Project info)
        {
            var r  = new FunctionResult <Project>();
            int id = ProjectDal.Add(info);

            if (id > 0)
            {
                r.Data           = info;
                r.Data.ProjectID = id;
            }
            return(r);
        }
        private bool AddProject()
        {
            if (string.IsNullOrWhiteSpace(ProjectType))
            {
                MessageBox.Show("请选择项目类型", "提示");
                return(false);
            }
            if (!canExecute())
            {
                MessageBox.Show("验证失败", "提示");
                return(false);
            }
            // 新增项目的初始化
            Project.ID         = Guid.NewGuid();
            Project.UptateTime = DateTime.Now;
            Project.State      = "0";
            switch (int.Parse(ProjectType))
            {
            case (int)EProjectType.RealEstate:
                //Project.Type = EProjectType.RealEstate.ToString();
                break;

            case (int)EProjectType.Registration:
                // Project.Type = EProjectType.Registration.ToString();
                // 同时新增转移信息
                TransferDal transferDal = new TransferDal();
                Transfer    transfer    = new Transfer();
                transfer.ID         = Guid.NewGuid();
                transfer.ProjectID  = Project.ID;
                transfer.UpdateTime = DateTime.Now;
                transferDal.Add(transfer);
                break;

            default:
                //Project.Type = EProjectType.Default.ToString();
                break;
            }

            projectDal.Add(Project);

            RefreshProjectList();

            return(true);
        }
        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;
            }
        }