123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649 |
- using Common.system;
-
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Diagnostics;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Input;
- using System.Windows.Media;
-
- using XHWK.Model;
- using XHWK.WKTool.DAL;
-
- namespace XHWK.WKTool
- {
- /// <summary>
- /// 文件目录
- /// </summary>
- public partial class FileDirectoryWindow : Window
- {
- /// <summary>
- /// 视频模型
- /// </summary>
- private List<Model_Video> model_VideoList = null;
- /// <summary>
- /// 数据列表
- /// </summary>
- internal FileDirectoryData pageData = new FileDirectoryData();
- /// <summary>
- /// 下标
- /// </summary>
- private int Subscript = 0;
- /// <summary>
- /// 是否是修改状态
- /// </summary>
- private bool IsModify = false;
- /// <summary>
- /// 文件目录
- /// </summary>
- public FileDirectoryWindow()
- {
- InitializeComponent();
- Initialize();
- }
- /// <summary>
- /// 初始化
- /// </summary>
- public void Initialize()
- {
- APP.myloading.Show();
- //MouseNumber = 0;
- IsModify = false;
- //加载视频列表
- LoadingVideoList();
- int i = 1;
- bool isColour = true;
- pageData.menuList.Clear();
- //显示视频
- foreach (Model_Video videoinfo in model_VideoList)
- {
- //是否已上传
- //videoinfo.IsUpload;
- //录制时间
- //videoinfo.RSTime;
- //文件大小
- //videoinfo.VideoSize;
- //文件缩略图路径
- //videoinfo.ThumbnailPath;
- //文件唯一标示 上传事件筛选需要上传的视频
- //videoinfo.FileGuid;
- //文件存储路径
- //videoinfo.VidePath;
-
- string colour = "#FFFFFF";
- if (isColour == true)
- {
- colour = "#FFFFFF";
- isColour = false;
- }
- else
- {
- colour = "#E6F1FF";
- isColour = true;
- }
- string vis = "Visible";
- string cos = "Collapsed";
- if (!videoinfo.IsUpload)
- {
- vis = "Collapsed";
- cos = "Visible";
- }
- if (i <= 16)
- {
- pageData.menuList.Add(new FileDirectoryModel()
- {
- SerialNumber = i,
- VideoName = Common.system.FileToolsCommon.GetIOFileName(videoinfo.VideoPath).Replace(".MP4", "").Replace(".FLV", "").Replace(".AVI", "").Trim(),
- Name = Common.system.FileToolsCommon.GetIOFileName(videoinfo.VideoPath).Replace(".MP4", "").Replace(".FLV", "").Replace(".AVI", "").Trim(),
- FilePath = videoinfo.VideoPath.Replace(FileToolsCommon.GetIOFileName(videoinfo.VideoPath), "").Trim(),
- VideoDuration = 0,
- VideoSize = videoinfo.VideoSize,
- VideoTime = videoinfo.RSTime,
- IsEnabled = false,
- Path = videoinfo.VideoPath,
- Colour = colour,
- Visi = vis,
- Coll = cos,
- FileGuid = videoinfo.FileGuid,
- VideoType = videoinfo.VideoType.ToString()
- }); ;
- }
-
-
-
- i++;
- }
- txbSum.Text = pageData.menuList.Count.ToString();
- APP.myloading.Hide();
- DataContext = pageData;
- }
- /// <summary>
- /// 加载视频列表
- /// </summary>
- public void LoadingVideoList()
- {
- try
- {
- model_VideoList = new List<Model_Video>();
- foreach (Model_WKData Vdata in APP.WKDataList)
- {
- if (Vdata.VideoList == null)
- {
- continue;
- }
-
- foreach (Model_Video videoinfo in Vdata.VideoList)
- {
- try
- {
- if (string.IsNullOrWhiteSpace(videoinfo.VideoPath))
- {
- continue;
- }
- if (string.IsNullOrWhiteSpace(videoinfo.VideoSize) || videoinfo.VideoSize == "0 MB")
- {
- videoinfo.VideoSize = FileToolsCommon.GetFileSizeByMB(videoinfo.VideoPath).ToString() + " MB";
- videoinfo.VideoSizebyte = FileToolsCommon.GetFileSize(videoinfo.VideoPath);
- }
- model_VideoList.Add(videoinfo);
- }
- catch (Exception ex)
- {
- LogHelper.WriteErrLog("【加载视频列表】(LoadingVideoList)" + ex.Message, ex);
- }
- }
- }
- }
- catch (Exception ex)
- {
- LogHelper.WriteErrLog("【加载视频列表】(LoadingVideoList)" + ex.Message, ex);
- }
- }
- /// <summary>
- /// 关闭
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnDown_Click(object sender, RoutedEventArgs e)
- {
- APP.SaveWkData();
- Hide();
- }
- /// <summary>
- /// 窗口移动
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
- {
- DragMove();
- }
- /// <summary>
- /// 上传
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnUpload_Click(object sender, RoutedEventArgs e)
- {
- pageData.menuList[Subscript].IsEnabled = false;
- List<Button> buttons = FindChilds<Button>(listView1, "btnUpload");
- for (int i = 0; i < buttons.Count; i++)
- {
- if (buttons[i] == sender)
- {
- DAL_Upload dAL_Upload = new DAL_Upload();
-
- if (dAL_Upload.UploadVideo(pageData.menuList[i].FileGuid, out string ErrMessage))
- {
- pageData.menuList[i].Visi = "Visible";
- pageData.menuList[i].Coll = "Collapsed";
-
- DataContext = pageData;
-
- MessageWindow.Show("视频上传成功!");
- }
- else
- {
- MessageWindow.Show(ErrMessage);
- }
-
-
- }
- }
- }
- /// <summary>
- /// 删除
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnDelete_Click(object sender, RoutedEventArgs e)
- {
-
- pageData.menuList[Subscript].IsEnabled = false;
- List<Button> buttons = FindChilds<Button>(listView1, "btnDelete");
- for (int i = 0; i < buttons.Count; i++)
- {
- if (buttons[i] == sender)
- {
-
- //if (APP.W_PromptWindow == null)
- //{
- // APP.W_PromptWindow = new PromptWindow();
- // APP.W_PromptWindow.Owner = this;
- //}
- //APP.W_PromptWindow.Initialize(pageData.menuList[i].VideoName);
- //APP.W_PromptWindow.ShowDialog();
-
- foreach (Model_WKData wKData in APP.WKDataList)
- {
- if (wKData.VideoList == null)
- {
- continue;
- }
-
- if (wKData.VideoList.Exists(x => x.FileGuid == pageData.menuList[i].FileGuid))
- {
- try
- {
- FileToolsCommon.DeleteFile(wKData.VideoList.Find(x => x.FileGuid == pageData.menuList[i].FileGuid).VideoPath);
- FileToolsCommon.DeleteFile(wKData.VideoList.Find(x => x.FileGuid == pageData.menuList[i].FileGuid).ThumbnailPath);
- wKData.VideoList.Remove(wKData.VideoList.Find(x => x.FileGuid == pageData.menuList[i].FileGuid));
- Initialize();
- return;
- }
- catch (Exception ex)
- {
- MessageWindow.Show("无法删除视频!" + ex.Message);
- return;
- }
- }
- }
- }
- }
- }
- /// <summary>
- /// 播放
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnPlay_Click(object sender, RoutedEventArgs e)
- {
- pageData.menuList[Subscript].IsEnabled = false;
- List<Button> buttons = FindChilds<Button>(listView1, "btnPlay");
- for (int i = 0; i < buttons.Count; i++)
- {
- if (buttons[i] == sender)
- {
- try
- {
- ProcessStartInfo psi = new ProcessStartInfo(pageData.menuList[i].Path);
- Process pro = new Process
- {
- StartInfo = psi
- };
- pro.Start();
- }
- catch (Exception ex)
- {
- LogHelper.WriteErrLog("FileDirectoryWindow【BtnPlay_Click】" + ex.Message, ex);
- MessageWindow.Show(ex.Message);
- return;
- }
- }
- }
- }
-
- public static List<T> FindChilds<T>(DependencyObject parent, string childName)
- where T : DependencyObject
- {
- List<T> list = new List<T>();
- if (parent == null)
- {
- return list;
- }
-
- int childrenCount = VisualTreeHelper.GetChildrenCount(parent);
- for (int i = 0; i < childrenCount; i++)
- {
- DependencyObject child = VisualTreeHelper.GetChild(parent, i);
- // 如果子控件不是需查找的控件类型
- T childType = child as T;
- if (childType == null)
- {
- // 在下一级控件中递归查找
- List<T> findChildList = FindChilds<T>(child, childName);
- for (int j = 0; j < findChildList.Count; j++)
- {
- }
- list.AddRange(FindChilds<T>(child, childName));
- }
- else if (!string.IsNullOrEmpty(childName))
- {
- FrameworkElement frameworkElement = child as FrameworkElement;
- // 如果控件名称符合参数条件
- if (frameworkElement != null && frameworkElement.Name == childName)
- {
- list.Add((T)child);
- }
- }
- else
- {
- // 查找到了控件
- list.Add((T)child);
- }
- }
-
- return list;
- }
- /// <summary>
- /// 修改
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnModify_Click(object sender, RoutedEventArgs e)
- {
- if (IsModify)
- {
- pageData.menuList[Subscript].IsEnabled = false;
- }
- List<Button> buttons = FindChilds<Button>(listView1, "btnModify");
- for (int i = 0; i < buttons.Count; i++)
- {
- if (buttons[i] == sender)
- {
- pageData.menuList[i].IsEnabled = true;
- Subscript = i;
- IsModify = true;
- }
- }
- }
-
- //private int MouseNumber = 0;
- /// <summary>
- /// 鼠标按下
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void Window_MouseLeftButtonDown_1(object sender, MouseButtonEventArgs e)
- {
- //if (IsModify)
- //{
- // if (MouseNumber > 0 && pageData.menuList.Count > Subscript)
- // {
- // pageData.menuList[Subscript].IsEnabled = false;
- // try
- // {
- // if (!pageData.menuList[Subscript].Name.Equals(pageData.menuList[Subscript].VideoName))
- // {
- // string tempPath = pageData.menuList[Subscript].VideoName + pageData.menuList[Subscript].VideoType;
- // tempPath = pageData.menuList[Subscript].Path.Replace(tempPath, "").Trim();
- // tempPath = tempPath + pageData.menuList[Subscript].Name;
- // FileToolsCommon.MoveDirectory(pageData.menuList[Subscript].Path, tempPath, out string Message);
- // }
- // }
- // catch (Exception ex)
- // {
- // MessageWindow.Show("无法修改视频名称!" + ex.Message);
- // return;
- // }
- // }
- // MouseNumber++;
- //}
- }
-
- private void Window_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
- {
- // if (IsModify)
- // {
- // if (MouseNumber > 0 && pageData.menuList.Count > Subscript)
- // {
- // MouseNumber = 0;
- // pageData.menuList[Subscript].IsEnabled = false;
- // try
- // {
- // if (!pageData.menuList[Subscript].Name.Equals(pageData.menuList[Subscript].VideoName))
- // {
- // MouseNumber = 0;
- // string tempPath = pageData.menuList[Subscript].FilePath + pageData.menuList[Subscript].VideoName + "." + pageData.menuList[Subscript].VideoType;
- // if (FileToolsCommon.IsExistFile(tempPath))
- // {
- // MessageWindow.Show("文件名已存在!");
- // return;
- // }
- // foreach (Model_WKData wKData in APP.WKDataList)
- // {
- // if (wKData.VideoList == null)
- // continue;
- // if (wKData.VideoList.Exists(x => x.FileGuid == pageData.menuList[Subscript].FileGuid))
- // {
- // try
- // {
- // //FileToolsCommon.DeleteFile(wKData.VideoList.Find(x => x.FileGuid == pageData.menuList[Subscript].FileGuid).VideoPath);
- // //FileToolsCommon.DeleteFile(wKData.VideoList.Find(x => x.FileGuid == pageData.menuList[Subscript].FileGuid).ThumbnailPath);
- // //wKData.VideoList.Remove(wKData.VideoList.Find(x => x.FileGuid == pageData.menuList[Subscript].FileGuid));
- // //Initialize();
- // //return;
- // }
- // catch (Exception ex)
- // {
- // MessageWindow.Show("无法删除视频!" + ex.Message);
- // return;
- // }
- // }
- // }
- // FileToolsCommon.Copy(pageData.menuList[Subscript].Path, tempPath);
- // }
- // }
- // catch (Exception ex)
- // {
- // MessageWindow.Show("无法修改视频名称!" + ex.Message);
- // return;
- // }
- // }
- // MouseNumber++;
- // }
- }
-
- /// <summary>
- /// 修改文件名
- /// </summary>
- /// <param name="Guid">唯一编号</param>
- /// <param name="NewName">新文件名带后缀 不带路径</param>
- /// <param name="Errmessage">错误信息</param>
- /// <returns></returns>
- private bool ModifyPathName(string FileGuid, string NewName, out string Errmessage)
- {
- Errmessage = "";
- Model_Video model_Video = APP.VideoList.Find(x => x.FileGuid == FileGuid);
- string filePathName = model_Video.VideoPath;
- string filePath = FileToolsCommon.GetDirectoryName(filePathName);
- string newFilePathName = filePath + NewName;
- //缩略图
- string ThumbnailPath = filePath + "ThumbnailPath/";
- FileToolsCommon.CreateDirectory(ThumbnailPath);
- //缩略图存储位置
- string ThumbnailPathName = ThumbnailPath + NewName.Replace(".", "") + ".JPG";
- if (FileToolsCommon.IsExistFile(newFilePathName))
- {
- Errmessage = "文件已存在,请重新修改文件名!";
- return false;
- }
- else
- {
- //修改文件名
- FileToolsCommon.Copy(filePathName, newFilePathName);
- model_Video.VideoPath = newFilePathName;
- //修改缩略图名
- FileToolsCommon.DeleteFile(ThumbnailPathName);
- FileToolsCommon.Copy(model_Video.ThumbnailPath, ThumbnailPathName);
- model_Video.ThumbnailPath = ThumbnailPathName;
- APP.SaveWkData();
- return true;
- }
- }
-
- }
-
- public class FileDirectoryData : NotifyModel
- {
- public ObservableCollection<FileDirectoryModel> menuList { get; set; }
-
- public FileDirectoryData()
- {
- menuList = new ObservableCollection<FileDirectoryModel>();
- }
- }
-
- public class FileDirectoryModel : NotifyModel
- {
- private int _serialNumber;
- /// <summary>
- /// 序号
- /// </summary>
- public int SerialNumber
- {
- get => _serialNumber;
- set
- {
- _serialNumber = value;
- OnPropertyChanged("SerialNumber");
- }
- }
- private string _videoName;
- /// <summary>
- /// 视频名称
- /// </summary>
- public string VideoName
- {
- get => _videoName;
- set
- {
- _videoName = value;
- OnPropertyChanged("VideoName");
- }
- }
- private int _videoDuration;
- /// <summary>
- /// 视频时长
- /// </summary>
- public int VideoDuration
- {
- get => _videoDuration;
- set
- {
- _videoDuration = value;
- OnPropertyChanged("VideoDuration");
- }
- }
- private string _videoSize;
- /// <summary>
- /// 视频大小
- /// </summary>
- public string VideoSize
- {
- get => _videoSize;
- set
- {
- _videoSize = value;
- OnPropertyChanged("VideoSize");
- }
- }
- private long _videoSizes;
- /// <summary>
- /// 视频大小
- /// </summary>
- public long VideoSizes
- {
- get => _videoSizes;
- set
- {
- _videoSizes = value;
- OnPropertyChanged("VideoSizes");
- }
- }
- private string _videoTime;
- /// <summary>
- /// 日期
- /// </summary>
- public string VideoTime
- {
- get => _videoTime;
- set
- {
- _videoTime = value;
- OnPropertyChanged("VideoTime");
- }
- }
- private string _colour;
- /// <summary>
- /// 颜色
- /// </summary>
- public string Colour
- {
- get => _colour;
- set
- {
- _colour = value;
- OnPropertyChanged("Colour");
- }
- }
- private bool _isEnabled;
- /// <summary>
- /// 是否可编辑
- /// </summary>
- public bool IsEnabled
- {
- get => _isEnabled;
- set
- {
- _isEnabled = value;
- OnPropertyChanged("IsEnabled");
- }
- }
- public string Path { get; set; }
- private string _visi;
- /// <summary>
- /// 显示
- /// </summary>
- public string Visi
- {
- get => _visi;
- set
- {
- _visi = value;
- OnPropertyChanged("Visi");
- }
- }
- private string _coll;
- /// <summary>
- /// 显示
- /// </summary>
- public string Coll
- {
- get => _coll;
- set
- {
- _coll = value;
- OnPropertyChanged("Coll");
- }
- }
- /// <summary>
- /// 唯一编号
- /// </summary>
- public string FileGuid { get; set; }
- /// <summary>
- /// 视频类型
- /// </summary>
- public string VideoType { get; set; }
- /// <summary>
- /// 初始名称
- /// </summary>
- public string Name { get; set; }
- /// <summary>
- /// 文件路径
- /// </summary>
- public string FilePath { get; set; }
- }
- }
|