CyclicScroller.xaml.cs 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857
  1. using HistoryDLL.Json;
  2. using MediaViewerLib.Utilities;
  3. using Newtonsoft.Json;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Diagnostics;
  7. using System.IO;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading;
  11. using System.Threading.Tasks;
  12. using System.Windows;
  13. using System.Windows.Controls;
  14. using System.Windows.Data;
  15. using System.Windows.Documents;
  16. using System.Windows.Input;
  17. using System.Windows.Media;
  18. using System.Windows.Media.Animation;
  19. using System.Windows.Media.Imaging;
  20. using System.Windows.Navigation;
  21. using System.Windows.Shapes;
  22. using System.Windows.Threading;
  23. namespace HistoryDLL
  24. {
  25. /// <summary>
  26. /// CyclicScroller.xaml 的互動邏輯
  27. /// </summary>
  28. public partial class CyclicScroller : UserControl
  29. {
  30. public enum HistoryControlMode
  31. {
  32. Boot = 0x001,
  33. Manual = 0x010,
  34. AutoRun = 0x100,
  35. };
  36. public enum TouchorManipulation
  37. {
  38. TouchEvent = 0x01,
  39. ManipulationEvent = 0x10,
  40. };
  41. public enum MonitorFlag
  42. {
  43. Monitor1_1 = 0x000001,
  44. Monitor2_1 = 0x000010,
  45. Monitor3_1 = 0x000100,
  46. Monitor4_1 = 0x001000,
  47. Monitor5_1 = 0x010000,
  48. Monitor6_1 = 0x100000,
  49. };
  50. public enum StoryBoardStatus
  51. {
  52. StoryBoardIsRun = 0x01,
  53. StoryBoardIsStop = 0x10,
  54. };
  55. public delegate void HomeBackInforDelegate();
  56. public event HomeBackInforDelegate HomeBackInforEvent;
  57. public event EventHandler OnDataLoadCompeleted;
  58. //創造 LiveContainer 物件的Delegate
  59. private delegate void CreateLiveContainerDelegate();
  60. //從xml 中取得時際實際有多少個年份資料
  61. private List<XmlData> xmlDataList = new List<XmlData>();
  62. //透過取得的年份將MainEvent建立出來後放到該Buffer中
  63. private List<LiveContainer> LiveContainerList = new List<LiveContainer>();
  64. //Get Windows Resolution (根據 n * 1的螢幕取得windows的寬高)
  65. private static WindowsResolution CurrentMonitorCount = new WindowsResolution();
  66. //public static ConfigSettingClass config = new ConfigSettingClass(GlobalFunction.ConfigSettingFilePath, CurrentMonitorCount);
  67. //當前載入的起始位置 0 : 代表當前第一個年份是xml資料的首年
  68. private int currentLoadIndex = 0;
  69. //是否需要"當前"年份顯示在正中間
  70. private bool NeedToGetCenter = true;
  71. private int CenterIndexValue = 0;
  72. //是否要有首頁動畫
  73. private bool RunHomePageAnimation = true;
  74. //TouchDown 事件是否有發生 ?
  75. private bool isTouchDown = false;
  76. private bool isManipulatonEvent = false;
  77. private bool isAutoRun = false;
  78. //移動前 Horizontal.X的值
  79. double MoveStartHorizontalX = 0.0;
  80. //移動後 Horizontal.X的值
  81. double MoveEndHorizontalX = 0.0;
  82. //從開始到結束全部的移動距離
  83. double MoveTotalDistance = 0.0;
  84. //容許開始到結束的全部移動量小於該值則為點擊事件
  85. double AllowMaxDistance = 8000;
  86. //重新定位的Storyboard
  87. private Storyboard storyboardForLocate = new Storyboard();
  88. private StoryBoardStatus storyboardStatus = StoryBoardStatus.StoryBoardIsStop;
  89. //重新定位的 Storyboard 速度調整係數
  90. private int StorySmoothValue = 300;
  91. //輪播的Storyboard
  92. private Storyboard autoRunStoryboard = new Storyboard();
  93. //當前歷史牆載入完成
  94. private bool isHistoryWallLoadComplete = false;
  95. //狀態為手動或者輪播模式
  96. public HistoryControlMode ControlMode = HistoryControlMode.Boot;
  97. //Loading~
  98. HomePage hp;
  99. public CyclicScroller(int languageIndex)
  100. {
  101. InitializeComponent();
  102. if (ConfigSettingClass.MainBackCollect == null)
  103. {
  104. MessageBox.Show("設定錯誤,請透過後台更新設定!!");
  105. Application.Current.Shutdown();
  106. return;
  107. }
  108. //初始化除了Spec外的基本設定
  109. //refresh setting
  110. new ConfigSettingClass(GlobalFunction.ConfigSettingFilePath, CurrentMonitorCount);
  111. InitialWholeSetting();
  112. if (GlobalFunction.isSolutionUsing4K)
  113. {
  114. MainEventWidth *= 2;
  115. MainEventHeight *= 2;
  116. YearEventHeight *= 2;
  117. this.uxMyScroll.Margin = new Thickness(this.uxMyScroll.Margin.Left, this.uxMyScroll.Margin.Top, this.uxMyScroll.Margin.Right, this.uxMyScroll.Margin.Bottom * 2);
  118. }
  119. if (CurrentMonitorCount.ncm == 0)
  120. {
  121. MessageBox.Show("螢幕解析度取得失敗, 可能會造成載入異常!!");
  122. Application.Current.Shutdown();
  123. return;
  124. }
  125. this.Loaded += new RoutedEventHandler(CyclicScroller_Loaded);
  126. this.KeyDown += new KeyEventHandler(CyclicScroller_KeyDown);
  127. }
  128. private void CyclicScroller_KeyDown(object sender, KeyEventArgs e)
  129. {
  130. //取得Ctrl + s進入後台設定
  131. if (e.Key == Key.S && Keyboard.Modifiers == ModifierKeys.Shift)
  132. {
  133. Exception closeEx = CloseProcess("nLightenHistoryWallEdit");
  134. if (closeEx != null)
  135. {
  136. Debug.WriteLine(closeEx.Message);
  137. }
  138. Thread.Sleep(100);
  139. Exception ex = OpenProcess(AppDomain.CurrentDomain.BaseDirectory + "nLightenHistoryWallEdit.exe");
  140. if (ex != null)
  141. {
  142. MessageBox.Show(ex.Message);
  143. }
  144. }
  145. }
  146. void CyclicScroller_Loaded(object sender, RoutedEventArgs e)
  147. {
  148. //取得資料
  149. if (!GetHistoryData())
  150. {
  151. MessageBox.Show("資料準備中,敬請期待!");
  152. Application.Current.Shutdown();
  153. return;
  154. }
  155. //*設定規範值請參閱 SpecificationValue.cs file.
  156. SetSpecValue();
  157. //設定當前語系
  158. SetLanguage();
  159. //設定回正被中斷時~應該回到的顯示位置
  160. SetReturnPos();
  161. //根據螢幕數量~顯示螢幕中會有幾個內容(children)
  162. ChildrenCount = GetChildrenCount();
  163. //根據可以顯示的 Children 數量~新建出 Grid For 裝載DetailViewer
  164. CreateExtraUnitGrid();
  165. //初始化該 ExtraUnitGrid ~包括 狀態 位置
  166. InitializeExtraUnitGrid();
  167. //拖動隱藏區塊顯示設定
  168. SetDisplayPart();
  169. //將首頁輪播 LoadBar 加到畫面中
  170. AddHomePageAnimation();
  171. //計算總事件~並將該直傳到Homepage中
  172. CalcCountToHomePage();
  173. //延遲載入~避免程式咬死
  174. WpfDelayDoWork.DoBackgroundWork(CreateLiveConainer, 1000);
  175. }
  176. private void CreateLiveConainer()
  177. {
  178. if (xmlDataList.Count <= 0)
  179. { return; }
  180. //Loading Start
  181. LoadingStart();
  182. //總共會有多少筆 MainEvent ? 透過 YearList 中的個數將 MainEvent 預先建立起來
  183. CreatMainEvent();
  184. //是否需要將首年顯示在中間
  185. if (NeedToGetCenter)
  186. {
  187. CenterIndexValue = GetCenterIndexValue();
  188. }
  189. //之後代表會有 ChildrenCount 個數量會在 Scrollviewer 當中
  190. currentLoadIndex = GetIndexFromLeftSide();
  191. currentLoadIndex -= CenterIndexValue;
  192. AddEventBlock(currentLoadIndex, false);
  193. //回正Storyboard
  194. BackToPosFromCurrentLoadIndex(currentLoadIndex);
  195. //自動輪播
  196. GlobalFunction.CheckAutoRunTimer.Start();
  197. isHistoryWallLoadComplete = true;
  198. }
  199. //回正
  200. private void BackToPosFromCurrentLoadIndex(int currentLoadIndex)
  201. {
  202. isTouchDown = false;
  203. double dd = Math.Abs(MainEventWidth + NoneUseRange - uxMyScroll.HorizontalOffset) / StorySmoothValue;
  204. if (dd <= 0.3)
  205. {
  206. dd = 0.3;
  207. }
  208. else if (dd >= 0.5)
  209. {
  210. dd = 0.5;
  211. }
  212. //完成後由 storyboard 回到中間位置
  213. DoubleAnimation dbOffset = new DoubleAnimation()
  214. {
  215. Duration = TimeSpan.FromSeconds(dd),
  216. EasingFunction = new PowerEase()
  217. {
  218. EasingMode = EasingMode.EaseOut,
  219. Power = 2
  220. },
  221. };
  222. ScrollViewerUtilities.UseMotionStop = false;
  223. Storyboard.SetTarget(dbOffset, (DependencyObject)this.FindName("uxMyScroll"));
  224. Storyboard.SetTargetProperty(dbOffset, new PropertyPath(ScrollViewerUtilities.HorizontalOffsetProperty));
  225. storyboardForLocate.Children.Add(dbOffset);
  226. storyboardForLocate.FillBehavior = FillBehavior.HoldEnd;
  227. dbOffset.From = uxMyScroll.HorizontalOffset;
  228. dbOffset.To = MainEventWidth + NoneUseRange;
  229. SetStoryBoardStatus(StoryBoardStatus.StoryBoardIsRun);
  230. }
  231. void storyboardForLocate_Completed(object sender, EventArgs e)
  232. {
  233. SetStoryBoardStatus(StoryBoardStatus.StoryBoardIsStop);
  234. if (ControlMode == HistoryControlMode.Boot)
  235. {
  236. ControlMode = HistoryControlMode.Manual;
  237. }
  238. //確實停止後才開始判斷是否為點擊sdlu
  239. if (storyboardStatus == StoryBoardStatus.StoryBoardIsStop)
  240. {
  241. if (MoveTotalDistance <= AllowMaxDistance)
  242. {
  243. //通知 判斷為點擊
  244. SendInfoToLiveContainer(TouchorManipulation.TouchEvent);
  245. }
  246. else
  247. {
  248. //通知 判斷為Manipulation
  249. SendInfoToLiveContainer(TouchorManipulation.ManipulationEvent);
  250. }
  251. MoveTotalDistance = 0.0;
  252. //改變被點擊開的兩旁資訊
  253. ChangeDetailSide();
  254. }
  255. }
  256. //啟動或停止回正的storyboard
  257. private void SetStoryBoardStatus(StoryBoardStatus sbs)
  258. {
  259. if (sbs == StoryBoardStatus.StoryBoardIsRun)
  260. {
  261. storyboardForLocate.Begin();
  262. storyboardStatus = sbs;
  263. }
  264. else if (sbs == StoryBoardStatus.StoryBoardIsStop)
  265. {
  266. storyboardForLocate.Stop();
  267. storyboardStatus = sbs;
  268. }
  269. }
  270. #region 將每個年份事件區塊加到 Scrollviewer 中
  271. /// <summary>
  272. /// 將要顯示的事件區塊加到 StackPanel 中
  273. /// </summary>
  274. /// <param name="startIndex">從事件包(LiveContainerList)中取出事件的起始索引位置</param>
  275. /// <param name="IsRightSide">往左邊改變或者往右邊改變</param>
  276. private void AddEventBlock(int startIndex, bool IsRightSide)
  277. {
  278. if (ClearScrollChildren(IsRightSide))
  279. {
  280. for (int index = 0; index < ChildrenCount + 2; index++)
  281. {
  282. int addcount = (startIndex + index) % LiveContainerList.Count;
  283. AddGridIntoScroll(addcount, index, true);
  284. }
  285. }
  286. else //如果不是第一次載入~代表該狀況為移動畫面造成改變~所以依照移動的方向做區塊的改變
  287. {
  288. int index = 0;
  289. //由右到左
  290. if (IsRightSide)
  291. {
  292. index = ChildrenCount + 1;
  293. }
  294. else //由左到右
  295. {
  296. index = 0;
  297. }
  298. int addcount = (startIndex + index) % LiveContainerList.Count;
  299. AddGridIntoScroll(addcount, index, IsRightSide);
  300. }
  301. //改變年份區塊的索引值與顏色
  302. ChangeBlockColor();
  303. //**改變視角位置 (移動到中間的區塊)**
  304. if (IsRightSide)
  305. {
  306. uxMyScroll.ScrollToHorizontalOffset(uxMyScroll.HorizontalOffset - MainEventWidth);
  307. }
  308. else
  309. {
  310. uxMyScroll.ScrollToHorizontalOffset(uxMyScroll.HorizontalOffset + MainEventWidth);
  311. }
  312. }
  313. private void ChangeBlockColor()
  314. {
  315. //更新物件在Scroller中的索引位置~並改變其顏色
  316. for (int count = 0; count < uxMyStackPanel.Children.Count; count++)
  317. {
  318. ((LiveContainer)uxMyStackPanel.Children[count]).Set_Get_ContainerIndex = count;
  319. if (count <= 1 || count >= ChildrenCount)
  320. {
  321. ((LiveContainer)uxMyStackPanel.Children[count]).ChangeControlColor(false);
  322. }
  323. else
  324. ((LiveContainer)uxMyStackPanel.Children[count]).ChangeControlColor(true);
  325. }
  326. }
  327. private bool ClearScrollChildren(bool IsRightSide)
  328. {
  329. //如果整個Panel都沒有物件的話代表這是第一次載入物件~所以不須執行任何移除物件的動作
  330. if (uxMyStackPanel.Children.Count > 0)
  331. {
  332. if (IsRightSide)
  333. {
  334. //移除第一個
  335. ((LiveContainer)uxMyStackPanel.Children[0]).Set_Get_ContainerIndex = -1;
  336. uxMyStackPanel.Children.RemoveAt(0);
  337. }
  338. else
  339. {
  340. //移除最後一個
  341. ((LiveContainer)uxMyStackPanel.Children[uxMyStackPanel.Children.Count - 1]).Set_Get_ContainerIndex = -1;
  342. uxMyStackPanel.Children.RemoveAt(uxMyStackPanel.Children.Count - 1);
  343. }
  344. return false;
  345. }
  346. return true;
  347. }
  348. /// <summary>
  349. /// 新增一個區塊到 Stackpanel 中
  350. /// </summary>
  351. /// <param name="addcount">要新增的區塊是事件包 (LiveContainerList)中的哪一個</param>
  352. /// <param name="index">主要是回報給Homepage, 是哪幾個年份區塊在stackpanel 中</param>
  353. /// <param name="IsAddBlock">新增的方式是 Add or Insert</param>
  354. private void AddGridIntoScroll(int addcount, int index, bool IsAddBlock)
  355. {
  356. if (IsAddBlock)
  357. {
  358. uxMyStackPanel.Children.Add(LiveContainerList[addcount]);
  359. }
  360. else
  361. {
  362. uxMyStackPanel.Children.Insert(0, LiveContainerList[addcount]);
  363. }
  364. //將初始完成後~顯示在畫面中的年份資料傳給Homepage
  365. if (RunHomePageAnimation)
  366. {
  367. if (index >= 1 && index <= ChildrenCount)
  368. {
  369. hp.xmlDataList.Add(LiveContainerList[addcount].xmlData);
  370. }
  371. }
  372. }
  373. #endregion
  374. /// <summary>
  375. /// 透過 YearList 中的個數將 MainEvent 預先建立起來"如不足則循環"
  376. /// </summary>
  377. private void CreatMainEvent()
  378. {
  379. //"如不足則循環"方式為~依照各螢幕數量不同給予不同的常數值
  380. int staticvalue = GetCycleCount();
  381. for (int index = 0; index < staticvalue; index++)
  382. {
  383. for (int count = 0; count < xmlDataList.Count; count++)
  384. {
  385. LiveContainer liveContainer = new LiveContainer(xmlDataList[count], MainEventWidth, MainEventHeight);
  386. //通知 LiveContainer 通道
  387. liveContainer.ListenFromCyclicTouchStatus(this);
  388. //接收來自 LiveContainer 通道
  389. liveContainer.LiveContainerBubbleToCyclicScrollerEvent += new LiveContainer.LiveContainerBubbleToCyclicScroller(ReceiveFromLiveContainerInfo);
  390. liveContainer.CreateLiveContainer();
  391. LiveContainerList.Add(liveContainer);
  392. }
  393. }
  394. }
  395. /// <summary>
  396. /// 這邊的計算方式為~
  397. /// 如果是單螢幕則全部需要ChildrenCount個加四個備份所以是ChildrenCount + 4個,
  398. /// 雙螢幕需要ChildrenCount個加四個備份所以是ChildrenCount + 4個,
  399. /// 三螢幕需要ChildrenCount個加四個備份所以是ChildrenCount + 4個
  400. /// 如果xml中的年份不足, 則必須進行循環. 此result則為循環次數
  401. /// </summary>
  402. /// <returns></returns>
  403. private int GetCycleCount()
  404. {
  405. int result = 0;
  406. //如果設定的年份少於全部需要的則必須
  407. switch (CurrentMonitorCount.ncm)
  408. {
  409. case MonitorFlag.Monitor1_1:
  410. case MonitorFlag.Monitor2_1:
  411. case MonitorFlag.Monitor3_1:
  412. case MonitorFlag.Monitor4_1:
  413. case MonitorFlag.Monitor5_1:
  414. case MonitorFlag.Monitor6_1:
  415. {
  416. result = (TotalShowChildren / xmlDataList.Count) + 1;
  417. break;
  418. }
  419. }
  420. return result;
  421. }
  422. public static T DeserializeFromJson<T>(string json)
  423. {
  424. T deserializedProduct = JsonConvert.DeserializeObject<T>(json);
  425. return deserializedProduct;
  426. }
  427. /// <summary>
  428. /// //取得 ini 中的資料
  429. /// </summary>
  430. /// <returns></returns>
  431. private bool GetHistoryData()
  432. {
  433. List<EventGroup> eventgroups = new List<EventGroup>();
  434. HistoryWallEventJson hweventJson = new HistoryWallEventJson();
  435. if (File.Exists(GlobalFunction.JsonFilePath))
  436. {
  437. string jsonResult;
  438. xmlDataList.Clear();
  439. using (StreamReader sr = new StreamReader(GlobalFunction.JsonFilePath))
  440. {
  441. jsonResult = sr.ReadToEnd();
  442. }
  443. hweventJson = DeserializeFromJson<HistoryWallEventJson>(jsonResult);
  444. eventgroups = hweventJson.EventGroups;
  445. if (hweventJson.EventGroups.Count <= 0)
  446. {
  447. return false;
  448. }
  449. for (int index = 0; index < hweventJson.EventGroups.Count; index++)
  450. {
  451. if (hweventJson.EventGroups[index].ListDates.Count > 0)
  452. {
  453. XmlData xmldata = new XmlData(hweventJson.EventGroups[index]);
  454. xmlDataList.Add(xmldata);
  455. }
  456. }
  457. }
  458. else
  459. {
  460. return false;
  461. }
  462. return true;
  463. }
  464. /// <summary>
  465. /// 自動移動
  466. /// </summary>
  467. /// <param name="sender"></param>
  468. /// <param name="e"></param>
  469. void AutoRunTimer_Tick(object sender, EventArgs e)
  470. {
  471. uxMyScroll.ScrollToHorizontalOffset(uxMyScroll.HorizontalOffset + 1);
  472. }
  473. private void uxMyScroll_ManipulationStarted(object sender, ManipulationStartedEventArgs e)
  474. {
  475. if (isHistoryWallLoadComplete)
  476. {
  477. SetStoryBoardStatus(StoryBoardStatus.StoryBoardIsStop);
  478. isTouchDown = true;
  479. isManipulatonEvent = false;
  480. MoveStartHorizontalX = uxMyScroll.HorizontalOffset;
  481. }
  482. e.Handled = true;
  483. }
  484. private void uxMyScroll_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
  485. {
  486. if (isTouchDown)
  487. {
  488. uxMyScroll.ScrollToHorizontalOffset(uxMyScroll.HorizontalOffset - e.DeltaManipulation.Translation.X);
  489. MoveTotalDistance += Math.Abs(uxMyScroll.HorizontalOffset - e.DeltaManipulation.Translation.X);
  490. }
  491. e.Handled = true;
  492. }
  493. private void uxMyScroll_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
  494. {
  495. if (isTouchDown)
  496. {
  497. isTouchDown = false;
  498. BackToPosFromCurrentLoadIndex(currentLoadIndex);
  499. }
  500. isManipulatonEvent = false;
  501. e.Handled = true;
  502. }
  503. private void uxMyScroll_ManipulationInertiaStarting(object sender, ManipulationInertiaStartingEventArgs e)
  504. {
  505. e.TranslationBehavior = new InertiaTranslationBehavior()
  506. {
  507. InitialVelocity = e.InitialVelocities.LinearVelocity,
  508. DesiredDeceleration = 20.0 * 96.0 / (1000.0 * 1000.0)
  509. };
  510. e.Handled = true;
  511. }
  512. /// <summary>
  513. /// 改變被點擊開的兩旁資訊
  514. /// </summary>
  515. private void ChangeDetailSide()
  516. {
  517. int count = ExtraUnitGridList.Count;
  518. for (int index = 0; index < count; index++)
  519. {
  520. if (ExtraUnitGridList[index].IsUsing != 0 &&
  521. ExtraUnitGridList[index].Get_Set_BlockControlMode != ExtraUnitGrid.ControlMode.Extend)
  522. {
  523. int mappingStackpanel = index + 1;
  524. if (((LiveContainer)uxMyStackPanel.Children[mappingStackpanel]).uxYearStr.Text != ExtraUnitGridList[index].textblock.Text)
  525. {
  526. if (ExtraUnitGridList[index].Get_Set_BlockControlMode != ExtraUnitGrid.ControlMode.MinStatus)
  527. {
  528. ExtraUnitGridList[index].textblock.Text = ((LiveContainer)uxMyStackPanel.Children[mappingStackpanel]).uxYearStr.Text;
  529. }
  530. ThumbnailContainer thumbnailControl = new ThumbnailContainer();
  531. List<string> folderPaths = new List<string>();
  532. ExtraUnitGridList[index].DetailViewerControlHide();
  533. folderPaths = GetThumbnailControl(mappingStackpanel);
  534. thumbnailControl.ImgPath = MediaUtilties.GetImageFromFolders(folderPaths.ToArray());
  535. ExtraUnitGridList[index].BorderUp.VerticalAlignment = System.Windows.VerticalAlignment.Bottom;
  536. ExtraUnitGridList[index].BorderUp.Child = thumbnailControl;
  537. ExtraUnitGridList[index].DetailViewerControlShow(null, null);
  538. }
  539. }
  540. }
  541. }
  542. private Exception OpenProcess(string exePath)
  543. {
  544. if (File.Exists(exePath))
  545. {
  546. ProcessStartInfo startInfo = new ProcessStartInfo();
  547. startInfo.FileName = exePath;
  548. try
  549. {
  550. Process startProcess = Process.Start(startInfo);
  551. return null;
  552. }
  553. catch (Exception ex)
  554. {
  555. return ex;
  556. }
  557. }
  558. else
  559. {
  560. return new Exception(exePath + "檔案不存在!");
  561. }
  562. }
  563. private Exception CloseProcess(string processName)
  564. {
  565. try
  566. {
  567. bool isKill = false;
  568. System.Diagnostics.Process[] myProcesses = System.Diagnostics.Process.GetProcesses();
  569. foreach (System.Diagnostics.Process myProcess in myProcesses)
  570. {
  571. if (myProcess.ProcessName == processName)
  572. {
  573. Debug.WriteLine(myProcess.ProcessName + " " + myProcess.MainWindowHandle.ToString());
  574. myProcess.Kill();
  575. isKill = true;
  576. }
  577. }
  578. if (isKill)
  579. {
  580. return null;
  581. }
  582. else
  583. {
  584. return new Exception("Cannot find " + processName);
  585. }
  586. }
  587. catch (Exception ex)
  588. {
  589. return ex;
  590. }
  591. }
  592. private void Window_PreviewTouchDown(object sender, TouchEventArgs e)
  593. {
  594. //停止輪播
  595. StopAutoRunTheWall();
  596. GlobalFunction.CheckAutoRunTimer.Stop();
  597. }
  598. //避免點擊在非歷史軸的時, 歷史軸會因為輪播停止而卡住的狀況
  599. private void Window_PreviewTouchUp(object sender, TouchEventArgs e)
  600. {
  601. if (!isManipulatonEvent && isHistoryWallLoadComplete && isAutoRun)
  602. {
  603. BackToPosFromCurrentLoadIndex(currentLoadIndex);
  604. }
  605. isAutoRun = false;
  606. if (!GlobalFunction.isVideoPlay)
  607. GlobalFunction.CheckAutoRunTimer.Start();
  608. }
  609. private void uxMyScroll_ScrollChanged(object sender, System.Windows.Controls.ScrollChangedEventArgs e)
  610. {
  611. if (ControlMode == HistoryControlMode.Boot)
  612. {
  613. return;
  614. }
  615. MoveEndHorizontalX = uxMyScroll.HorizontalOffset;
  616. //手指頭往左邊的移動
  617. if (MoveEndHorizontalX > MainEventWidth * 2 + NoneUseRange - (MainEventWidth / 2))
  618. {
  619. autoRunStoryboard.Stop();
  620. //判斷當前的Index是否超出"最大"容許範圍~進行調整
  621. currentLoadIndex = GetIndexFromRightSide();
  622. //重新加入EventBlock
  623. AddEventBlock(currentLoadIndex, true);
  624. if (ControlMode == HistoryControlMode.AutoRun)
  625. {
  626. SetAutoRunStoryBoard(MoveEndHorizontalX - MainEventWidth, MoveEndHorizontalX - MainEventWidth + MainEventWidth);
  627. autoRunStoryboard.Begin();
  628. }
  629. }
  630. //手指頭往右邊的移動
  631. else if (MoveEndHorizontalX < MainEventWidth + NoneUseRange - (MainEventWidth / 2))
  632. {
  633. //判斷當前的Index是否低於"最小"容許範圍~進行調整
  634. currentLoadIndex = GetIndexFromLeftSide();
  635. //重新加入EventBlock
  636. AddEventBlock(currentLoadIndex, false);
  637. }
  638. }
  639. #region 切換語系與回首頁按鈕
  640. private void ChangeLangBtn_Click(object sender, RoutedEventArgs e)
  641. {
  642. int changeLanIndex = 0;
  643. if (ConfigSettingClass.MainBackCollect.DefaultLangIndex == 0)
  644. {
  645. if (canUsingLangList[1])
  646. {
  647. changeLanIndex = 1;
  648. }
  649. else if (canUsingLangList[2])
  650. {
  651. changeLanIndex = 2;
  652. }
  653. else if (canUsingLangList[3])
  654. {
  655. changeLanIndex = 3;
  656. }
  657. }
  658. else if (ConfigSettingClass.MainBackCollect.DefaultLangIndex == 1)
  659. {
  660. if (canUsingLangList[2])
  661. {
  662. changeLanIndex = 2;
  663. }
  664. else if (canUsingLangList[3])
  665. {
  666. changeLanIndex = 3;
  667. }
  668. else if (canUsingLangList[0])
  669. {
  670. changeLanIndex = 0;
  671. }
  672. }
  673. else if (ConfigSettingClass.MainBackCollect.DefaultLangIndex == 2)
  674. {
  675. if (canUsingLangList[3])
  676. {
  677. changeLanIndex = 3;
  678. }
  679. else if (canUsingLangList[0])
  680. {
  681. changeLanIndex = 0;
  682. }
  683. else if (canUsingLangList[1])
  684. {
  685. changeLanIndex = 1;
  686. }
  687. }
  688. else if (ConfigSettingClass.MainBackCollect.DefaultLangIndex == 3)
  689. {
  690. if (canUsingLangList[0])
  691. {
  692. changeLanIndex = 0;
  693. }
  694. else if (canUsingLangList[1])
  695. {
  696. changeLanIndex = 1;
  697. }
  698. else if (canUsingLangList[2])
  699. {
  700. changeLanIndex = 2;
  701. }
  702. }
  703. if (changeLanIndex == 0)
  704. {
  705. ConfigSettingClass.MainBackCollect.DefaultLangIndex = changeLanIndex;
  706. System.Windows.Application.Current.Properties["Language"] = "Language1";
  707. }
  708. else if (changeLanIndex == 1)
  709. {
  710. ConfigSettingClass.MainBackCollect.DefaultLangIndex = changeLanIndex;
  711. System.Windows.Application.Current.Properties["Language"] = "Language2";
  712. }
  713. else if (changeLanIndex == 2)
  714. {
  715. ConfigSettingClass.MainBackCollect.DefaultLangIndex = changeLanIndex;
  716. System.Windows.Application.Current.Properties["Language"] = "Language3";
  717. }
  718. else if (changeLanIndex == 3)
  719. {
  720. ConfigSettingClass.MainBackCollect.DefaultLangIndex = changeLanIndex;
  721. System.Windows.Application.Current.Properties["Language"] = "Language0";
  722. }
  723. uxMainLangBtnL.Content = ConfigSettingClass.MainBackCollect.LangText[ConfigSettingClass.MainBackCollect.DefaultLangIndex];
  724. uxMainLangBtnR.Content = ConfigSettingClass.MainBackCollect.LangText[ConfigSettingClass.MainBackCollect.DefaultLangIndex];
  725. for (int i = 0; i < LiveContainerList.Count; i++)
  726. {
  727. LiveContainerList[i].WriteYearBarStr();
  728. //改變事件區塊中顯示文字分兩部分
  729. //1. 已經在事件區塊中顯示的 Planerotate
  730. LiveContainerList[i].ChangeCurPlaneRotateLan();
  731. //2. 在緩衝區中待顯示的 Planerotate
  732. //LiveContainerList[i].ChangePlaneRotateLan();
  733. }
  734. for (int j = 0; j < ExtraUnitGridList.Count; j++)
  735. {
  736. if (ExtraUnitGridList[j].curDataIndex != -1)
  737. {
  738. ExtraUnitGridList[j].textblock.Text = ((LiveContainer)uxMyStackPanel.Children[j + 1]).uxYearStr.Text;
  739. }
  740. }
  741. }
  742. private void HomeBtn_Click(object sender, RoutedEventArgs e)
  743. {
  744. if (HomeBackInforEvent != null)
  745. this.Dispatcher.BeginInvoke(HomeBackInforEvent, DispatcherPriority.Background);
  746. }
  747. #endregion
  748. }
  749. public class WpfDelayDoWork
  750. {
  751. public static void DoWork(Action action, int millisecond = 300)
  752. {
  753. new Action<Dispatcher, Action, int>(DoWorkAsync).BeginInvoke(Dispatcher.CurrentDispatcher, action, millisecond, null, null);
  754. }
  755. public static void DoBackgroundWork(Action action, int millisecond = 300)
  756. {
  757. new Action<Dispatcher, Action, int>(DoBackgroundWorkAsync).BeginInvoke(Dispatcher.CurrentDispatcher, action, millisecond, null, null);
  758. }
  759. static void DoWorkAsync(Dispatcher dispatcher, Action action, int millisecond)
  760. {
  761. System.Threading.Thread.Sleep(millisecond);
  762. dispatcher.BeginInvoke(action);
  763. }
  764. static void DoBackgroundWorkAsync(Dispatcher dispatcher, Action action, int millisecond)
  765. {
  766. System.Threading.Thread.Sleep(millisecond);
  767. dispatcher.Invoke(action, DispatcherPriority.Background);
  768. }
  769. }
  770. }