private void DeleteImage(StandardPic item) { try { var index = SPicList.IndexOf(item); if (SPicList != null && SPicList.Count > 0 && index > -1) { SPicList.Remove(item); //ParamSPicList.FirstOrDefault(p => p.PicId == item.PicId).Url = string.Empty; LossImageList = SPicList.Count * 50; } } catch (Exception) { _commonFun.AlertLongText("操作异常,请重试。-->LocalRegistScoreViewModel"); return; } }
private async void UploadImage() { try { var imageUrl = ""; var imageType = "L"; var imageName = ""; var filePath = ""; MediaFile file = null; await CrossMedia.Current.Initialize(); var action = await _commonFun.ShowActionSheet("从相册", "拍照"); IsLoading = true; if (action == "从相册") { MessagingCenter.Send <CommonMessage>(new CommonMessage() { TaskID = "-1" }, "LocalResetTaskID"); file = await CrossMedia.Current.PickPhotoAsync(); } else if (action == "拍照") { MessagingCenter.Send <CommonMessage>(new CommonMessage() { TaskID = "-1" }, "LocalResetTaskID"); if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported) { return; } file = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions { Directory = "RMMT", Name = DateTime.Now.ToString("yy-MM-dd").Replace("-", "") + DateTime.Now.ToString("HH:mm:ss").Replace(":", "") }); } if (file == null) { MessagingCenter.Send <CommonMessage>(new CommonMessage() { TaskID = "0" }, "LocalResetTaskID"); IsLoading = false; return; } imageName = file.Path.Substring(file.Path.LastIndexOf('/') + 1); filePath = file.Path; //upload file to server try { string result = _commonFun.SaveAttachLocal(file.GetStream(), file.Path); file.Dispose(); if (!string.IsNullOrWhiteSpace(result)) { imageUrl = result; var addDto = new StandardPic() { StandardPicId = 0, PicName = imageName, PicType = imageType, //L,G 失分照片/得分照片 TIId = CurrentSystem.TIId, Url = imageUrl, FilePath = filePath, PicId = SPicList.Count == 0 ? 1 : SPicList.Max(p => p.PicId) + 1 }; SPicList.Add(addDto); //ParamSPicList.Add(addDto); LossImageList = SPicList.Count * 50; } else { _commonFun.AlertLongText("上传失败"); return; } } catch (OperationCanceledException) { _commonFun.AlertLongText("上传超时,请重试"); return; } catch (Exception) { _commonFun.AlertLongText("上传异常,请重试"); return; } finally { IsLoading = false; MessagingCenter.Send <CommonMessage>(new CommonMessage() { TaskID = "0" }, "LocalResetTaskID"); } } catch (Exception) { _commonFun.AlertLongText("操作异常,请重试。-->LocalRegistScoreViewModel"); return; } }