private void DeleteStanderImage(PictureStandard item) { try { var index = PStandardList.IndexOf(item); if (index > -1) { PStandardList.Insert(index, new PictureStandard() { StandardPicId = item.StandardPicId, StandardPicName = item.StandardPicName, TIId = item.TIId, TPId = item.TPId, SeqNo = item.SeqNo, Url = "", SuccessImage = "", Id = item.StrPicId }); PStandardList.Remove(item); } } catch (Exception) { _commonFun.AlertLongText("操作异常,请重试。-->LocalRegistScoreViewModel"); return; } }
private async void UploadStandPic(int picId) { try { var imageUrl = ""; var imageType = "G"; 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; Device.BeginInvokeOnMainThread(() => { var item = PStandardList.FirstOrDefault(p => p.StandardPicId == picId); var index = PStandardList.IndexOf(item); if (index > -1) { PStandardList.Insert(index, new PictureStandard() { StandardPicId = item.StandardPicId, StandardPicName = item.StandardPicName, TIId = item.TIId, TPId = item.TPId, SeqNo = item.SeqNo, Url = imageUrl, SuccessImage = "icon_success" }); PStandardList.Remove(item); } }); } 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; } }