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)); }
/// <summary> /// 点击标签的事件 /// </summary> /// <param name="model"></param> private void OnIsCheckedTag(TagInfoModel model) { var tagName = model.Name.Trim(); if (model.TagIsChecked) { if (_changeFlag) { _changeFlag = false; return; } _changeFlag = true; if (string.IsNullOrEmpty(PostilTag)) { PostilTag = tagName; } else { PostilTag += "," + tagName; } } else { if (_changeFlag) { _changeFlag = false; return; } if (string.IsNullOrEmpty(PostilTag)) { return; } _changeFlag = true; var index = PostilTag.IndexOf(tagName, StringComparison.Ordinal); switch (index) { case -1: break; case 0: PostilTag = PostilTag.Remove(index, tagName.Length); var i = PostilTag.IndexOf(','); if (i != -1) { PostilTag = PostilTag.Remove(i, 1); } break; default: var name = "," + tagName; PostilTag = PostilTag.Remove(index - 1, name.Length); break; } } }
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); }