protected override string GetErrorFor(string propertyName) { if (propertyName == "PostilTitle") { if (string.IsNullOrWhiteSpace(PostilTitle)) { return("标题不能为空!"); } if (PostilTitle.Length > 20) { return("标题不能超过20个汉字!"); } } if (propertyName == "PostilTag") { if (string.IsNullOrWhiteSpace(PostilTag)) { return("标签不能为空!"); } var inputTagList = PostilTag.Split(',', ',').ToList().Select(t => t.Trim()).ToList(); if (inputTagList.Any(tag => tag.Length > 8)) { return("每个小标签不能超过8个汉字!"); } if (inputTagList.Count > 4) { return("最多只能添加4个小标签!"); } } return(base.GetErrorFor(propertyName)); }
public async void OnAddPostil() { var inputTagList = PostilTag.Split(',', ',').ToList().Select(t => t.Trim()).ToList(); var tagSet = new HashSet <string>(inputTagList.Where(t => t != "")); if (!File.Exists(_screenshotPicPath)) { return; } var result = await DataApi.UploadFilesAsync(new[] { _screenshotPicPath }, Mg.Get <IMgContext>().ProjectId); if (!result.IsOk) { Mg.Get <IMgLog>().Error("上传截图失败:" + result.Message); Mg.Get <IMgDialog>().ShowDesktopAlert("上传截图失败", result.Message); return; } var fileId = result.Data.AsList <Id>().FirstOrDefault(); var data = new DynamicRecord { [Hubs.Postil.ProjectId] = Mg.Get <IMgContext>().ProjectId, [Hubs.Postil.Title] = PostilTitle, [Hubs.Postil.CreateTime] = DateTime.Now, [Hubs.Postil.CreateUser] = Mg.Get <IMgContext>().UserId, [Hubs.Postil.Tags] = tagSet, [Hubs.Postil.IsPublic] = IsPublic, [Hubs.Postil.FileId] = fileId, [Hubs.Postil.CameraMatrix] = _matrixArray }; var createResult = await DataApi.AddAsync(Hubs.Postil.T, new IRecord[] { data }); if (!createResult.IsOk) { Mg.Get <IMgLog>().Error("添加批注失败:" + createResult.Message); Mg.Get <IMgDialog>().ShowDesktopAlert("添加批注失败", createResult.Message); return; } var originalTagList = PostilTagList.Select(tag => tag.Name.Trim()).ToList(); var tagData = (from tag in tagSet where !originalTagList.Contains(tag) select new DynamicRecord { [Hubs.Tag.ProjectId] = Mg.Get <IMgContext>().ProjectId, [Hubs.Tag.Name] = tag }).ToList(); await DataApi.AddAsync(Hubs.Tag.T, tagData.AsArray <IRecord>()); var addRecord = createResult.Data.AsList <DynamicRecord>().FirstOrDefault(); await Mg.Get <IMgWeb>().SendWebMsgAsync("demoPostil/add", addRecord?.Id.ToString(), BoardcastType.ProjectGroup);//发送广播 //Close(); }
protected override void OnPropertyChanged(string propertyName) { base.OnPropertyChanged(propertyName); if (propertyName == "PostilTag") { if (_changeFlag) { _changeFlag = false; return; } var strArray = PostilTag.Split(',', ',').ToArray(); var set = new HashSet <string>(); foreach (var t in strArray) { set.Add(t.Trim()); } foreach (var tagModel in PostilTagList) { if (set.Contains(tagModel.Name.Trim())) { if (tagModel.TagIsChecked) { continue; } _changeFlag = true; tagModel.TagIsChecked = true; } else { if (!tagModel.TagIsChecked) { continue; } _changeFlag = true; tagModel.TagIsChecked = false; } } } }
private bool CanAddPostil() { if (string.IsNullOrWhiteSpace(PostilTitle)) { return(false); } if (string.IsNullOrWhiteSpace(PostilTag)) { return(false); } if (PostilTitle.Length > 20) { return(false); } //if (PostilTag.Length > 20) // return false; var inputTagList = PostilTag.Split(',', ',').ToList().Select(t => t.Trim()).ToList(); if (inputTagList.Any(tag => tag.Length > 8) || inputTagList.Count > 4) { return(false); } return(!IsBusy); }