public bool Save() { try { if (string.IsNullOrEmpty(PlaylistModel.Num)) { ErrorMessage = "播放列表的编号不能为空!"; return(false); } if (string.IsNullOrEmpty(PlaylistModel.Name)) { ErrorMessage = "播放列表的名称不能为空!"; return(false); } if (PlaylistModel.EffectDate == null) { ErrorMessage = "播放列表的开始时间不能为空!"; return(false); } if (PlaylistModel.EndDate == null) { ErrorMessage = "播放列表的结束时间不能为空!"; return(false); } if (PlaylistModel.EndDate < PlaylistModel.EffectDate) { ErrorMessage = "播放列表的结束时间要大于开始时间!"; return(false); } if (VideoItems.Count == 0) { ErrorMessage = "当前没有需要播放的文件!"; return(false); } if (!IsEdit && SeatManage.Bll.AdvertisementOperation.GetAdModel(PlaylistModel.Num, SeatManage.EnumType.AdType.TitleAd) != null) { ErrorMessage = "已存在存在相同名称或编号的播放列表!"; return(false); } PlaylistModel.ImageFilePath.Clear(); PlaylistModel.MediaPlayList.Clear(); foreach (ViewModel_VideoItem item in VideoItems) { SeatManage.ClassModel.PlaylistItemInfo newItem = new SeatManage.ClassModel.PlaylistItemInfo(); newItem = item.VideoItemModel; newItem.MediaFileName = PlaylistModel.Num + "_" + newItem.MediaFileName.Substring(newItem.MediaFileName.LastIndexOf("\\") + 1); PlaylistModel.MediaPlayList.Add(newItem); bool isnew = true; foreach (string samefile in PlaylistModel.ImageFilePath) { if (samefile == item.VideoFliePath) { isnew = false; break; } } if (isnew) { PlaylistModel.ImageFilePath.Add(item.VideoFliePath); } } string resultstr = ""; //TODO:保存&文件上传 SeatManage.Bll.FileOperate fileUpload = new SeatManage.Bll.FileOperate(); foreach (string upFileItem in PlaylistModel.ImageFilePath) { if (!fileUpload.UpdateFile(upFileItem, PlaylistModel.Num + "_" + upFileItem.Substring(upFileItem.LastIndexOf("\\") + 1), SeatManage.EnumType.SeatManageSubsystem.PlaylistAd)) { ErrorMessage = string.Format("文件{0}上传失败!{1}", upFileItem, resultstr); return(false); } } //更换文件名 for (int i = 0; i < PlaylistModel.ImageFilePath.Count; i++) { PlaylistModel.ImageFilePath[i] = PlaylistModel.Num + "_" + PlaylistModel.ImageFilePath[i].Substring(PlaylistModel.ImageFilePath[i].LastIndexOf("\\") + 1); } PlaylistModel.Type = SeatManage.EnumType.AdType.PlaylistAd; SeatManage.ClassModel.AMS_Advertisement model = new SeatManage.ClassModel.AMS_Advertisement(); model.Type = SeatManage.EnumType.AdType.PlaylistAd; model.ID = PlaylistModel.ID; model.Name = PlaylistModel.Name; model.Num = PlaylistModel.Num; model.AdContent = PlaylistModel.ToXml(); model.EffectDate = PlaylistModel.EffectDate; model.EndDate = PlaylistModel.EndDate; if (IsEdit) { //TODO:更新 resultstr = SeatManage.Bll.AdvertisementOperation.UpdateAdModel(model); } else { //DOTO:添加 resultstr = SeatManage.Bll.AdvertisementOperation.AddAdModel(model); } if (!string.IsNullOrEmpty(resultstr)) { ErrorMessage = string.Format("保存失败!{0}", resultstr); return(false); } MessageBoxWindow mbw = new MessageBoxWindow(); mbw.viewModel.Message = "保存成功!"; mbw.viewModel.Type = Code.MessageBoxType.Success; mbw.ShowDialog(); return(true); } catch (Exception ex) { ErrorMessage = ex.Message; return(false); } }
public bool Save() { string functionName = "save"; try { if (string.IsNullOrEmpty(PlaylistModel.Num)) { ErrorMessage = "播放列表的编号不能为空!"; return(false); } if (string.IsNullOrEmpty(PlaylistModel.Name)) { ErrorMessage = "播放列表的名称不能为空!"; return(false); } if (PlaylistModel.EffectDate == null) { ErrorMessage = "播放列表的开始时间不能为空!"; return(false); } if (PlaylistModel.EndDate == null) { ErrorMessage = "播放列表的结束时间不能为空!"; return(false); } if (PlaylistModel.EndDate < PlaylistModel.EffectDate) { ErrorMessage = "播放列表的结束时间要大于开始时间!"; return(false); } if (VideoItems.Count == 0) { ErrorMessage = "当前没有需要播放的文件!"; return(false); } if (!IsEdit && AMS.ServiceProxy.AdvertisementOperationService.ExistSameAdvert(PlaylistModel.Num, PlaylistModel.Name, Model.Enum.AdType.PlaylistAd)) { ErrorMessage = "已存在存在相同名称或编号的播放列表!"; return(false); } PlaylistModel.OperatorID = User.ID; PlaylistModel.ImageFilePath.Clear(); PlaylistModel.MediaPlayList.Clear(); foreach (ViewModel_VideoItem item in VideoItems) { AMS.Model.PlaylistItemInfo newItem = new Model.PlaylistItemInfo(); newItem = item.VideoItemModel; newItem.MediaFileName = PlaylistModel.Num + "_" + newItem.MediaFileName.Substring(newItem.MediaFileName.LastIndexOf("\\") + 1); PlaylistModel.MediaPlayList.Add(newItem); bool isnew = true; foreach (string samefile in PlaylistModel.ImageFilePath) { if (samefile == item.VideoFliePath) { isnew = false; break; } } if (isnew) { PlaylistModel.ImageFilePath.Add(item.VideoFliePath); } } string resultstr = ""; //TODO:保存&文件上传 AMS.ServiceProxy.FileOperate fileUpload = new ServiceProxy.FileOperate(); fileUpload.HandleProgress += new ServiceProxy.EventHandleFileTransport(fileUpload_HandleProgress); Vm_ProgressBar.ProgressType = "上传媒体文件"; Vm_ProgressBar.FullProgress = PlaylistModel.ImageFilePath.Count; foreach (string upFileItem in PlaylistModel.ImageFilePath) { Vm_ProgressBar.ProgressName = "正在上传\"" + upFileItem + "\"……"; resultstr = fileUpload.UpdateFile(upFileItem, PlaylistModel.Num + "_" + upFileItem.Substring(upFileItem.LastIndexOf("\\") + 1), SeatManage.EnumType.SeatManageSubsystem.PlaylistAd); if (!string.IsNullOrEmpty(resultstr)) { ErrorMessage = string.Format("文件{0}上传失败!{1}", upFileItem, resultstr); Vm_ProgressBar.IsFinish(); return(false); } } //更换文件名 for (int i = 0; i < PlaylistModel.ImageFilePath.Count; i++) { PlaylistModel.ImageFilePath[i] = PlaylistModel.Num + "_" + PlaylistModel.ImageFilePath[i].Substring(PlaylistModel.ImageFilePath[i].LastIndexOf("\\") + 1); } PlaylistModel.Type = Model.Enum.AdType.PlaylistAd; AMS.Model.AMS_Advertisement model = new Model.AMS_Advertisement(); model.Type = Model.Enum.AdType.PlaylistAd; model.ID = PlaylistModel.ID; model.Name = PlaylistModel.Name; model.Num = PlaylistModel.Num; model.OperatorID = PlaylistModel.OperatorID; model.AdContent = PlaylistModel.ToXml(); model.EffectDate = PlaylistModel.EffectDate; model.EndDate = PlaylistModel.EndDate; if (IsEdit) { //TODO:更新 return(AMS.ServiceProxy.AdvertisementOperationService.UpdateAdvertisement(model)); } else { //DOTO:添加 return(AMS.ServiceProxy.AdvertisementOperationService.AddAdvertisement(model)); } if (!string.IsNullOrEmpty(resultstr)) { ErrorMessage = string.Format("保存播放列表失败!{0}", resultstr); return(false); } return(true); } catch (AMS.Model.CustomerException ex) { ErrorMessage = string.Format("{0} 出自{1}.{2}", ex.Message, ex.ErrorSourcesClass, ex.ErrorSourcesFunction); return(false); } catch (Exception ex) { ErrorMessage = string.Format("{0} 出自{1}.{2}", ex.Message, CLASSNAME, functionName); return(false); } }