/// <summary> /// 创建项目 /// </summary> /// <param name="mfModel"></param> /// <param name="newMfProj"></param> /// <returns></returns> private ProjectModel CreateProject(ProjectCreateModel mfModel, out ProjectDto newMfProj) { newMfProj = null; HttpResponseMessage res; try { res = _projClient.CreateProject(mfModel, _parent.BimToken).Result; if (res.StatusCode != HttpStatusCode.Created) { var resContent = res.Content.ReadAsStringAsync().Result; IsShowAdorner = false; Application.Current.Dispatcher.Invoke( DispatcherPriority.Background, new Action(() => MetroMessageBox.Show( ResponContentUtil.GetResponResult(resContent), "新建项目", MetroMessageBoxButton.OK, MetroMessageBoxImage.Info, MetroMessageBoxDefaultButton.OK))); return(null); } } catch (WebException ex) { Application.Current.Dispatcher.Invoke( DispatcherPriority.Background, new Action(() => MetroMessageBox.Show( String.Format("新建项目“{0}”失败: {1}!", mfModel.Name, ex.Message), "新建项目", MetroMessageBoxButton.OK, MetroMessageBoxImage.Error, MetroMessageBoxDefaultButton.OK))); return(null); } catch (TaskCanceledException ex) { string err = null; var cts = new CancellationTokenSource(); if (ex.CancellationToken == cts.Token) { // a real cancellation, triggered by the caller err = "用户取消操作!"; } else { // a web request timeout (possibly other things!?) err = "操作超时!"; } Application.Current.Dispatcher.Invoke( DispatcherPriority.Background, new Action(() => MetroMessageBox.Show( String.Format("新建项目“{0}”失败: {1}", mfModel.Name, err), "新建项目", MetroMessageBoxButton.OK, MetroMessageBoxImage.Error, MetroMessageBoxDefaultButton.OK))); return(null); } catch (Exception ex) { var ex0 = ex; if (ex.InnerException != null) { ex0 = ex.InnerException; } if (ex0 is TaskCanceledException) { var tcEx = ex0 as TaskCanceledException; string err = null; var cts = new CancellationTokenSource(); if (tcEx.CancellationToken == cts.Token) { // a real cancellation, triggered by the caller err = "用户取消操作!"; } else { // a web request timeout (possibly other things!?) err = "操作超时!"; } Application.Current.Dispatcher.Invoke( DispatcherPriority.Background, new Action(() => MetroMessageBox.Show( String.Format("新建项目“{0}”异常: {1}", mfModel.Name, err), "新建项目", MetroMessageBoxButton.OK, MetroMessageBoxImage.Warning, MetroMessageBoxDefaultButton.OK))); } else if (ex0 is WebException) { Application.Current.Dispatcher.Invoke( DispatcherPriority.Background, new Action(() => MetroMessageBox.Show( String.Format("新建项目“{0}”失败: {1}!", mfModel.Name, ex0.Message), "新建项目", MetroMessageBoxButton.OK, MetroMessageBoxImage.Error, MetroMessageBoxDefaultButton.OK))); } else { Application.Current.Dispatcher.Invoke( DispatcherPriority.Background, new Action(() => MetroMessageBox.Show( String.Format("新建项目“{0}”失败或超时,请检查您的网络连接是否正常!", mfModel.Name), "新建项目", MetroMessageBoxButton.OK, MetroMessageBoxImage.Error, MetroMessageBoxDefaultButton.OK))); } return(null); } //服务端更新MFiles项目信息 var paths = res.Headers.Location.OriginalString.TrimEnd('/') .Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries); var projId = int.Parse(paths[paths.Length - 1]); res = _projClient.GetProject(projId, _parent.BimToken).Result; if (res.StatusCode != HttpStatusCode.OK) { return(null); } var projContent = res.Content.ReadAsStringAsync().Result; newMfProj = JsonConvert.DeserializeObject <ProjectDto>(projContent); //项目信息 var projModel = new ProjectModel { ProjId = newMfProj.Id, ProjName = newMfProj.Name, ProjNumber = newMfProj.Number, ProjDescription = newMfProj.Description, ProjCover = newMfProj.Cover, ProjTemplateId = newMfProj.TemplateId, ProjStatus = newMfProj.Status.Name, ProjStartTime = newMfProj.StartDateUtc.ToLocalTime(), ProjEndTime = newMfProj.EndDateUtc.ToLocalTime(), }; return(projModel); }
/// <summary> /// 修改项目状态命令 /// </summary> /// <param name="param"></param> private void SettingSelectionChanged(ExCommandParameter param) { if (param.Parameter == null) { return; } var status = param.Parameter.ToString(); //当前项目状态与修改的项目状态一致,不需要修改 if (String.Compare(_projectSelected.ProjStatus, _lastStatus, StringComparison.OrdinalIgnoreCase) == 0) { return; } //项目状态为”结束“的项目,不允许修改 if (String.Compare(_lastStatus, ProjectModel.ProjStatusOvered, StringComparison.OrdinalIgnoreCase) == 0) { MetroMessageBox.Show("已结束项目,项目状态不可修改!", "设置项目状态", MetroMessageBoxButton.OK, MetroMessageBoxImage.Info, MetroMessageBoxDefaultButton.OK); //恢复项目状态 _projectSelected.ProjStatus = _lastStatus; return; } var projId = _projectSelected.ProjId; string result = string.Empty; var msg = String.Format("确定将项目“{0}”状态修改为“{1}”?", _projectSelected.ProjName, status); if (MetroMessageBox.Show(msg, "设置项目状态", MetroMessageBoxButton.OKCancel, MetroMessageBoxImage.Question, MetroMessageBoxDefaultButton.OK) == MetroMessageBoxResult.OK) { WaitCursorUtil.SetBusyState(); if (String.Compare(status, ProjectModel.ProjStatusSetUped, StringComparison.OrdinalIgnoreCase) == 0) { result = SetSetupedStatus(projId); } else if (String.Compare(status, ProjectModel.ProjStatusStarted, StringComparison.OrdinalIgnoreCase) == 0) { result = SetStartedStatus(projId); } else if (String.Compare(status, ProjectModel.ProjStatusPaused, StringComparison.OrdinalIgnoreCase) == 0) { result = SetPausedStatus(projId); } else if (String.Compare(status, ProjectModel.ProjStatusOvered, StringComparison.OrdinalIgnoreCase) == 0) { result = SetOveredStatus(projId); } } else { //恢复项目状态 _projectSelected.ProjStatus = _lastStatus; } //显示操作结果 if (!string.IsNullOrEmpty(result)) { MetroMessageBox.Show(ResponContentUtil.GetResponResult(result), "设置项目状态", MetroMessageBoxButton.OK, MetroMessageBoxImage.Error, MetroMessageBoxDefaultButton.OK); //恢复项目状态 _projectSelected.ProjStatus = _lastStatus; } }