private void DeleteImage(StandardPic item) { try { var index = CurrentSystem.SPicList.IndexOf(item); if (CurrentSystem.SPicList != null && CurrentSystem.SPicList.Count > 0 && index > -1) { //StandardPic dto = new StandardPic(); //dto.TIId = item.TIId; //dto.TPId = item.TPId; //CurrentSystem.SPicList.Insert(index, dto); CurrentSystem.SPicList.Remove(item); CurrentSystem.ParamSPicList.FirstOrDefault(p => p.PicId == item.PicId).Url = string.Empty; LossImageList = CurrentSystem.SPicList.Count * 50; //_deleteList.RemoveAt(index); } } catch (Exception) { _commonFun.AlertLongText("操作异常,请重试。-->RegistScoreViewModel"); return; } }
void Preview(StandardPic dto) { try { //if (CurrentSystem.SPicList != null && CurrentSystem.SPicList.Count > 0) //{ List <ImagePreviewDto> list = new List <ImagePreviewDto>() { new ImagePreviewDto() { Url = LossPicAttachItem.Url } }; //ImagePreviewDto dto; //foreach (var item in CurrentSystem.SPicList) //{ // dto = new ImagePreviewDto(); // dto.Url = item.Url; // list.Add(dto); //} Device.BeginInvokeOnMainThread(async() => { if (_previewTimer) { _previewTimer = false; await PopupNavigation.PushAsync(new PreviewImagePage(list, 0), true); Device.StartTimer(TimeSpan.FromSeconds(3), () => { _previewTimer = true; return(false); }); } }); } catch (Exception) { _commonFun.AlertLongText("操作异常,请重试。-->RegistScoreViewModel"); return; } //} //else //{ // _commonFun.AlertLongText("没有可预览的照片"); //} }
//private RelayCommand _itemTappedCommand; //public RelayCommand ItemTappedCommand //{ // get { return _itemTappedCommand ?? (_itemTappedCommand = new RelayCommand(PicItemTapped)); } //} #endregion #region action 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" }, "ResetTaskID"); file = await CrossMedia.Current.PickPhotoAsync(); } else if (action == "拍照") { MessagingCenter.Send <CommonMessage>(new CommonMessage() { TaskID = "-1" }, "ResetTaskID"); 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" }, "ResetTaskID"); IsLoading = false; return; } imageName = file.Path.Substring(file.Path.LastIndexOf('/') + 1); filePath = file.Path; //upload file to server //if (_commonHelper.IsNetWorkConnected() == true) //{ try { //var result = await _tourService.UploadFiletoOss(file.GetStream(), file.Path); 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 = CurrentSystem.SPicList.Count == 0 ? 1 : CurrentSystem.SPicList.Max(p => p.PicId) + 1 }; CurrentSystem.SPicList.Add(addDto); CurrentSystem.ParamSPicList.Add(addDto); LossImageList = CurrentSystem.SPicList.Count * 50; } else { _commonFun.AlertLongText("上传失败"); return; } //if (result != null) //{ // var resultInfo = JsonConvert.DeserializeObject<AttachDto>(result.Body); // if (result.ResultCode == ResultType.Success) // { // imageUrl = resultInfo.Url; // var addDto = new StandardPic() // { // //ImageStream = ImageSource.FromStream(() => { return displayStream; }),//resource, // StandardPicId = 0, // PicName = imageName, // PicType = imageType, //L,G 失分照片/得分照片 // TIId = CurrentSystem.TIId, // Url = imageUrl, // FilePath = filePath, // PicId = CurrentSystem.SPicList.Count == 0 ? 1 : CurrentSystem.SPicList.Max(p => p.PicId) + 1 // }; // CurrentSystem.SPicList.Add(addDto); // CurrentSystem.ParamSPicList.Add(addDto); // LossImageList = CurrentSystem.SPicList.Count * 50; // } // else // { // _commonFun.AlertLongText(result.Msg); // return; // } //} //else //{ // _commonFun.AlertLongText("上传失败"); // return; //} } catch (OperationCanceledException) { _commonFun.AlertLongText("上传超时,请重试"); return; } catch (Exception) { _commonFun.AlertLongText("上传异常,请重试"); return; } finally { IsLoading = false; MessagingCenter.Send <CommonMessage>(new CommonMessage() { TaskID = "0" }, "ResetTaskID"); } } catch (Exception) { _commonFun.AlertLongText("操作异常,请重试。-->RegistScoreViewModel"); return; } //} //else //{ // MessagingCenter.Send<CommonMessage>(new CommonMessage() { TaskID = 0 }, "ResetTaskID"); // file.Dispose(); // _commonFun.AlertLongText("网络连接异常"); // IsLoading = false; // return; //} }
void Preview(StandardPic dto) { try { //if (CurrentSystem.SPicList != null && CurrentSystem.SPicList.Count > 0) //{ List <ImagePreviewDto> list = new List <ImagePreviewDto>() { new ImagePreviewDto() { Url = LossPicAttachItem.Url } }; //ImagePreviewDto dto; //foreach (var item in CurrentSystem.SPicList) //{ // dto = new ImagePreviewDto(); // dto.Url = item.Url; // list.Add(dto); //} /* * Device.BeginInvokeOnMainThread(async () => * { * if (_previewTimer) * { * _previewTimer = false; * await PopupNavigation.PushAsync(new PreviewImagePage(list, 0), true); * Device.StartTimer(TimeSpan.FromSeconds(3), () => * { * _previewTimer = true; * return false; * }); * } * });*/ try { string url = LossPicAttachItem.Url; string filename = url.LastIndexOf("/") > 0 ? url.Substring(url.LastIndexOf("/") + 1) : ""; if (String.IsNullOrEmpty(filename)) { return; } if (CrossFilePicker.Current.IsExistFile(filename, "RMMT_IMAGE")) { //本地预览 CrossFilePicker.Current.OpenFile(filename, "RMMT_IMAGE"); } else if (CrossFilePicker.Current.IsExistFile(filename, "RMMTIMAGEVIEW")) { //已从服务器上缓存的图片。 CrossFilePicker.Current.OpenFile(filename, "RMMTIMAGEVIEW"); } else { _commonFun.DownLoadFileFromOss(url, filename, "RMMTIMAGEVIEW"); } } catch (Exception) { _commonFun.AlertLongText("加载异常,请重试"); } } catch (Exception) { _commonFun.AlertLongText("操作异常,请重试。-->ViewRegistScoreViewModel"); return; } }