|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419 |
- using Common.system;
- using Org.BouncyCastle.Asn1.Crmf;
- 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>
- List<Model_Video> model_VideoList =null;
- internal FileDirectoryData pageData = new FileDirectoryData();
- /// <summary>
- /// 文件目录
- /// </summary>
- public FileDirectoryWindow()
- {
- InitializeComponent();
- Initialize();
- }
- /// <summary>
- /// 初始化
- /// </summary>
- public void Initialize()
- {
- //加载视频列表
- 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";
- }
- pageData.menuList.Add(new FileDirectoryModel()
- {
- SerialNumber = i,
- VideoName = Common.system.FileToolsCommon.GetIOFileName(videoinfo.VideoPath),
- VideoDuration = 0,
- VideoSize = videoinfo.VideoSize,
- VideoTime = videoinfo.RSTime,
- IsEnabled = false,
- Path = videoinfo.VideoPath,
- Colour = colour,
- Visi = vis,
- Coll=cos,
- FileGuid= videoinfo.FileGuid,
- }) ; ;
- i++;
- }
- txbSum.Text = pageData.menuList.Count.ToString();
- DataContext = pageData;
- }
- /// <summary>
- /// 加载视频列表
- /// </summary>
- public void LoadingVideoList()
- {
- 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)
- {
- model_VideoList.Add(videoinfo);
- }
- }
- }
- /// <summary>
- /// 关闭
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnDown_Click(object sender, RoutedEventArgs e)
- {
- this.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)
- {
- 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))
- {
- MessageBox.Show("视频上传成功!");
- }
- else
- {
- MessageBox.Show(ErrMessage);
- }
-
- }
- }
- }
- /// <summary>
- /// 删除
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnDelete_Click(object sender, RoutedEventArgs e)
- {
- List<Button> buttons = FindChilds<Button>(listView1, "btnDelete");
- for (int i = 0; i < buttons.Count; i++)
- {
- if (buttons[i] == sender)
- {
- 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)
- {
- MessageBox.Show("无法删除视频!"+ex.Message);
- return;
- }
- }
- }
- }
- }
- }
- /// <summary>
- /// 播放
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnPlay_Click(object sender, RoutedEventArgs e)
- {
- 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);
- MessageBox.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)
- {
- List<Button> buttons = FindChilds<Button>(listView1, "btnModify");
- for (int i = 0; i < buttons.Count; i++)
- {
- if (buttons[i] == sender)
- {
- pageData.menuList[i].IsEnabled = 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 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; }
- }
- }
|