星火微课系统客户端
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

XHMicroLessonSystemWindow.xaml.cs 65KB

4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658
  1. using Aspose.Words;
  2. using Aspose.Words.Saving;
  3. using Common.system;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Drawing.Imaging;
  7. using System.IO;
  8. using System.Threading;
  9. using System.Windows;
  10. using System.Windows.Forms;
  11. using System.Windows.Ink;
  12. using System.Windows.Input;
  13. using System.Windows.Media;
  14. using System.Windows.Media.Imaging;
  15. using XHWK.Model;
  16. using System.Windows.Controls;
  17. using ComeCapture;
  18. using Aspose.Slides;
  19. using static Common.system.PdfTrunImage;
  20. using TStudyDigitalPen.HID;
  21. using System.Drawing;
  22. namespace XHWK.WKTool
  23. {
  24. /// <summary>
  25. /// 主页面
  26. /// </summary>
  27. public partial class XHMicroLessonSystemWindow : Window
  28. {
  29. #region 字段
  30. /// <summary>
  31. /// 文件目录窗口
  32. /// </summary>
  33. //private CountdownWindow FileDirectoryWindows = null;
  34. private FolderBrowserDialog Ofd;
  35. private DialogResult Result;
  36. public readonly BlackboardNew myblackboard;
  37. private System.Windows.Forms.DialogResult result;
  38. private System.Windows.Forms.OpenFileDialog ofd;
  39. //声明一个 DrawingAttributes 类型的变量
  40. DrawingAttributes drawingAttributes;
  41. Model_Video VideoInfo = null;
  42. //定义事件
  43. public event ChangeTextHandler ChangeTextEvent;
  44. //定义委托
  45. public delegate void ChangeTextHandler(string text);
  46. /// <summary>
  47. /// 图片
  48. /// </summary>
  49. string [] ImgPDFPath = new string[300];
  50. #endregion
  51. #region 初始化
  52. /// <summary>
  53. /// 主页面
  54. /// </summary>
  55. public XHMicroLessonSystemWindow()
  56. {
  57. new Aspose.Pdf.License().SetLicense(new MemoryStream(Convert.FromBase64String("PExpY2Vuc2U+CiAgPERhdGE+CiAgICA8TGljZW5zZWRUbz5TdXpob3UgQXVuYm94IFNvZnR3YXJlIENvLiwgTHRkLjwvTGljZW5zZWRUbz4KICAgIDxFbWFpbFRvPnNhbGVzQGF1bnRlYy5jb208L0VtYWlsVG8+CiAgICA8TGljZW5zZVR5cGU+RGV2ZWxvcGVyIE9FTTwvTGljZW5zZVR5cGU+CiAgICA8TGljZW5zZU5vdGU+TGltaXRlZCB0byAxIGRldmVsb3BlciwgdW5saW1pdGVkIHBoeXNpY2FsIGxvY2F0aW9uczwvTGljZW5zZU5vdGU+CiAgICA8T3JkZXJJRD4xOTA4MjYwODA3NTM8L09yZGVySUQ+CiAgICA8VXNlcklEPjEzNDk3NjAwNjwvVXNlcklEPgogICAgPE9FTT5UaGlzIGlzIGEgcmVkaXN0cmlidXRhYmxlIGxpY2Vuc2U8L09FTT4KICAgIDxQcm9kdWN0cz4KICAgICAgPFByb2R1Y3Q+QXNwb3NlLlRvdGFsIGZvciAuTkVUPC9Qcm9kdWN0PgogICAgPC9Qcm9kdWN0cz4KICAgIDxFZGl0aW9uVHlwZT5FbnRlcnByaXNlPC9FZGl0aW9uVHlwZT4KICAgIDxTZXJpYWxOdW1iZXI+M2U0NGRlMzAtZmNkMi00MTA2LWIzNWQtNDZjNmEzNzE1ZmMyPC9TZXJpYWxOdW1iZXI+CiAgICA8U3Vic2NyaXB0aW9uRXhwaXJ5PjIwMjAwODI3PC9TdWJzY3JpcHRpb25FeHBpcnk+CiAgICA8TGljZW5zZVZlcnNpb24+My4wPC9MaWNlbnNlVmVyc2lvbj4KICAgIDxMaWNlbnNlSW5zdHJ1Y3Rpb25zPmh0dHBzOi8vcHVyY2hhc2UuYXNwb3NlLmNvbS9wb2xpY2llcy91c2UtbGljZW5zZTwvTGljZW5zZUluc3RydWN0aW9ucz4KICA8L0RhdGE+CiAgPFNpZ25hdHVyZT53UGJtNUt3ZTYvRFZXWFNIY1o4d2FiVEFQQXlSR0pEOGI3L00zVkV4YWZpQnd5U2h3YWtrNGI5N2c2eGtnTjhtbUFGY3J0c0cwd1ZDcnp6MytVYk9iQjRYUndTZWxsTFdXeXNDL0haTDNpN01SMC9jZUFxaVZFOU0rWndOQkR4RnlRbE9uYTFQajhQMzhzR1grQ3ZsemJLZFZPZXk1S3A2dDN5c0dqYWtaL1E9PC9TaWduYXR1cmU+CjwvTGljZW5zZT4=")));
  58. InitializeComponent();
  59. myblackboard = new BlackboardNew(blackboard_canvas);
  60. APP.pageData.pagenum = 1;
  61. APP.pageData.currpage = 1;
  62. DataContext = APP.pageData;
  63. txbStoragePath.Text = FileToolsCommon.GetConfigValue("VideoType");
  64. if (FileToolsCommon.GetConfigValue("IsSound").Equals("true"))
  65. {
  66. rbnY.IsChecked = true;
  67. }
  68. else
  69. {
  70. rbnN.IsChecked = true;
  71. }
  72. txbStoragePath.Text = FileToolsCommon.GetConfigValue("VideoSavePath");
  73. Initialize();
  74. InitPen();
  75. }
  76. /// <summary>
  77. /// 初始化
  78. /// </summary>
  79. public void Initialize()
  80. {
  81. //创建 DrawingAttributes 类的一个实例
  82. drawingAttributes = new DrawingAttributes();
  83. //将 InkCanvas 的 DefaultDrawingAttributes 属性的值赋成创建的 DrawingAttributes 类的对象的引用
  84. //InkCanvas 通过 DefaultDrawingAttributes 属性来获取墨迹的各种设置,该属性的类型为 DrawingAttributes 型
  85. blackboard_canvas.DefaultDrawingAttributes = drawingAttributes;
  86. blackboard_canvas.UseCustomCursor = true;
  87. drawingAttributes.FitToCurve = true;
  88. drawingAttributes.IgnorePressure = false;
  89. blackboard_canvas.Cursor = System.Windows.Input.Cursors.Pen;
  90. //wfhCamera.Visibility = Visibility.Hidden;
  91. ImgPDFPath = null;
  92. ImgPDFPath = new string[300];
  93. }
  94. #endregion
  95. #region 事件
  96. /// <summary>
  97. /// 窗体移动
  98. /// </summary>
  99. /// <param name="sender"></param>
  100. /// <param name="e"></param>
  101. private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  102. {
  103. DragMove();
  104. }
  105. #region 摄像头
  106. System.Timers.Timer times;
  107. List<string> RbnOpen;
  108. bool IsRbnOpen = false;
  109. /// <summary>
  110. /// 摄像头打开事件
  111. /// </summary>
  112. /// <param name="sender"></param>
  113. /// <param name="e"></param>
  114. private void RbnOpen_Click(object sender, RoutedEventArgs e)
  115. {
  116. //UCCamera win = new UCCamera();
  117. ////win.Topmost = true;
  118. //win.ShowDialog();
  119. //wfhCamera.Visibility = Visibility.Visible;
  120. //CameraHelper.IsDisplay = true;
  121. //CameraHelper.SourcePlayer = player;
  122. CameraHelper.UpdateCameraDevices();
  123. if (CameraHelper.CameraDevices.Count > 0)
  124. {
  125. CameraHelper.SetCameraDevice(0);
  126. //wfhCamera.Visibility = Visibility.Hidden;
  127. RbnOpen = new List<string>();
  128. times = new System.Timers.Timer(200);//设置执行一次(false)还是一直执行(true)
  129. times.AutoReset = true;//设置是否执行System.Timers.Timer.Elapsed事件
  130. times.Elapsed += new System.Timers.ElapsedEventHandler(Times_Elapsed);
  131. times.Enabled = true; //启动计时器
  132. IsRbnOpen = true;
  133. }
  134. }
  135. int I = 9999;
  136. private void Times_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
  137. {
  138. if (IsRbnOpen)
  139. {
  140. try
  141. {
  142. Dispatcher.Invoke(() =>
  143. {
  144. if(I>10006)
  145. {
  146. //string FilePathName = ImgPath + RsImgName.Count + ".png";
  147. string path = CameraHelper.CaptureImage(@"G:\103", I.ToString());
  148. if (!string.IsNullOrWhiteSpace(path))
  149. {
  150. RbnOpen.Add(path);
  151. imgPlayer.Source = new BitmapImage(new Uri(path));
  152. }
  153. }
  154. I++;
  155. });
  156. }
  157. catch (Exception ex)
  158. {
  159. LogHelper.WriteErrLog("【摄像】(Times_Elapsed)生成图片错误:" + ex.Message, ex);
  160. }
  161. }
  162. }
  163. /// <summary>
  164. /// 摄像头关闭事件
  165. /// </summary>
  166. /// <param name="sender"></param>
  167. /// <param name="e"></param>
  168. private void RbnTurnOff_Click(object sender, RoutedEventArgs e)
  169. {
  170. IsRbnOpen = false;
  171. //wfhCamera.Visibility = Visibility.Hidden;
  172. CameraHelper.CloseDevice();
  173. }
  174. #endregion
  175. #endregion
  176. /// <summary>
  177. /// 录屏事件
  178. /// </summary>
  179. /// <param name="sender"></param>
  180. /// <param name="e"></param>
  181. private void BtnScreenRecording_Click(object sender, RoutedEventArgs e)
  182. {
  183. if (APP.IsLoginType == false)
  184. {
  185. Login();
  186. return;
  187. }
  188. if (APP.W_ScreenRecordingToolbarWindow == null)
  189. {
  190. APP.W_ScreenRecordingToolbarWindow = new ScreenRecordingToolbarWindow
  191. {
  192. Topmost = true
  193. };
  194. APP.W_ScreenRecordingToolbarWindow.Initialize();
  195. }
  196. else
  197. {
  198. APP.W_ScreenRecordingToolbarWindow.Initialize();
  199. }
  200. //显示在右下角
  201. APP.W_ScreenRecordingToolbarWindow.Left = PrimaryScreen.DESKTOP.Width - APP.W_ScreenRecordingToolbarWindow.Width - 10;
  202. APP.W_ScreenRecordingToolbarWindow.Top = PrimaryScreen.DESKTOP.Height - APP.W_ScreenRecordingToolbarWindow.Height - 160;
  203. APP.W_ScreenRecordingToolbarWindow.Topmost = true;
  204. APP.W_ScreenRecordingToolbarWindow.Show();
  205. Hide();
  206. }
  207. /// <summary>
  208. /// 上传事件
  209. /// </summary>
  210. /// <param name="sender"></param>
  211. /// <param name="e"></param>
  212. private void BtnUpload_Click(object sender, RoutedEventArgs e)
  213. {
  214. if (APP.IsLoginType == false)
  215. {
  216. Login();
  217. return;
  218. }
  219. FileDirectoryWindow fileDirectoryWindow = new FileDirectoryWindow();
  220. fileDirectoryWindow.Show();
  221. }
  222. /// <summary>
  223. /// 关闭事件
  224. /// </summary>
  225. /// <param name="sender"></param>
  226. /// <param name="e"></param>
  227. private void BtnDown_Click(object sender, RoutedEventArgs e)
  228. {
  229. APP.SaveWkData();
  230. System.Environment.Exit(0);
  231. }
  232. /// <summary>
  233. /// 设置 保存事件
  234. /// </summary>
  235. /// <param name="sender"></param>
  236. /// <param name="e"></param>
  237. private void BtnSave_Click(object sender, RoutedEventArgs e)
  238. {
  239. #region 合法性判断
  240. if (string.IsNullOrWhiteSpace(txbStoragePath.Text.Trim()))
  241. {
  242. System.Windows.MessageBox.Show("路径不可为空!");
  243. return;
  244. }
  245. string temp = FileToolsCommon.GetLegalPath(txbStoragePath.Text) + APP.WKData.WkName.Trim() + "/";
  246. if (!APP.WKData.WkPath.Equals(temp))
  247. {
  248. APP.WKData.WkPath = FileToolsCommon.GetLegalPath(txbStoragePath.Text) + APP.WKData.WkName.Trim() + "/";
  249. if (FileToolsCommon.IsExistDirectory(APP.WKData.WkPath))
  250. {
  251. //微课已存在
  252. MessageBoxResult dr = System.Windows.MessageBox.Show("讲解已存在是否覆盖?", "提示", MessageBoxButton.OKCancel);
  253. if (dr == MessageBoxResult.OK)
  254. {
  255. FileToolsCommon.DeleteDirectory(APP.WKData.WkPath);
  256. }
  257. else
  258. {
  259. return;
  260. }
  261. }
  262. //创建文件夹
  263. FileToolsCommon.CreateDirectory(APP.WKData.WkPath);
  264. }
  265. #endregion
  266. if (rbnMP4.IsChecked == true)
  267. {
  268. //存储文件
  269. FileToolsCommon.SetConfigValue("VideoType", "1");
  270. }
  271. else if (rbnFLV.IsChecked == true)
  272. {
  273. FileToolsCommon.SetConfigValue("VideoType", "2");
  274. }
  275. else
  276. {
  277. FileToolsCommon.SetConfigValue("VideoType", "3");
  278. }
  279. if (rbnY.IsChecked == true)
  280. {
  281. FileToolsCommon.SetConfigValue("IsSound", "true");
  282. }
  283. else
  284. {
  285. FileToolsCommon.SetConfigValue("IsSound", "false");
  286. }
  287. GridMain.Visibility = Visibility.Visible;
  288. gridSetUp.Visibility = Visibility.Collapsed;
  289. }
  290. /// <summary>
  291. /// 设置事件
  292. /// </summary>
  293. /// <param name="sender"></param>
  294. /// <param name="e"></param>
  295. private void BtnSetUp_Click(object sender, RoutedEventArgs e)
  296. {
  297. GridMain.Visibility = Visibility.Collapsed;
  298. gridSetUp.Visibility = Visibility.Visible;
  299. }
  300. /// <summary>
  301. /// 设置 浏览事件
  302. /// </summary>
  303. /// <param name="sender"></param>
  304. /// <param name="e"></param>
  305. private void BtnBrowse_Click(object sender, RoutedEventArgs e)
  306. {
  307. string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
  308. Ofd = new System.Windows.Forms.FolderBrowserDialog();
  309. Result = Ofd.ShowDialog();
  310. if (Result == System.Windows.Forms.DialogResult.OK)
  311. {
  312. if (Ofd.SelectedPath != "")
  313. {
  314. txbStoragePath.Text = Ofd.SelectedPath;
  315. //string ApplicationData = ZConfig.dataPath + "fileStorageAddress.txt";
  316. //string temp = ofd.SelectedPath;
  317. //System.IO.File.WriteAllText(ApplicationData, temp, Encoding.Default);
  318. }
  319. }
  320. }
  321. /// <summary>
  322. /// 画笔颜色事件 白色
  323. /// </summary>
  324. /// <param name="sender"></param>
  325. /// <param name="e"></param>
  326. private void BtnWhite_Click(object sender, RoutedEventArgs e)
  327. {
  328. ////创建 DrawingAttributes 类的一个实例
  329. //drawingAttributes = new DrawingAttributes();
  330. ////将 InkCanvas 的 DefaultDrawingAttributes 属性的值赋成创建的 DrawingAttributes 类的对象的引用
  331. ////InkCanvas 通过 DefaultDrawingAttributes 属性来获取墨迹的各种设置,该属性的类型为 DrawingAttributes 型
  332. //blackboard_canvas.DefaultDrawingAttributes = drawingAttributes;
  333. ////设置 DrawingAttributes 的 Color 属性设置颜色
  334. drawingAttributes.Color = Colors.White;
  335. }
  336. /// <summary>
  337. /// 画笔颜色事件 红色
  338. /// </summary>
  339. /// <param name="sender"></param>
  340. /// <param name="e"></param>
  341. private void BtnRed_Click(object sender, RoutedEventArgs e)
  342. {
  343. //设置 DrawingAttributes 的 Color 属性设置颜色
  344. drawingAttributes.Color = Colors.Red;
  345. }
  346. /// <summary>
  347. /// 画笔颜色事件 灰色
  348. /// </summary>
  349. /// <param name="sender"></param>
  350. /// <param name="e"></param>
  351. private void BtnGray_Click(object sender, RoutedEventArgs e)
  352. {
  353. drawingAttributes.Color = Colors.Gray;
  354. }
  355. /// <summary>
  356. /// 画笔颜色事件 青色
  357. /// </summary>
  358. /// <param name="sender"></param>
  359. /// <param name="e"></param>
  360. private void BtnCyanBlue_Click(object sender, RoutedEventArgs e)
  361. {
  362. drawingAttributes.Color = Colors.LimeGreen;
  363. }
  364. /// <summary>
  365. /// 画笔颜色事件 黄色
  366. /// </summary>
  367. /// <param name="sender"></param>
  368. /// <param name="e"></param>
  369. private void BtnYellow_Click(object sender, RoutedEventArgs e)
  370. {
  371. drawingAttributes.Color = Colors.Gold;
  372. }
  373. /// <summary>
  374. /// 画笔颜色事件 蓝色
  375. /// </summary>
  376. /// <param name="sender"></param>
  377. /// <param name="e"></param>
  378. private void BtnBlue_Click(object sender, RoutedEventArgs e)
  379. {
  380. drawingAttributes.Color = Colors.DeepSkyBlue;
  381. }
  382. /// <summary>
  383. /// 画笔粗细事件 细
  384. /// </summary>
  385. /// <param name="sender"></param>
  386. /// <param name="e"></param>
  387. private void RbnFine_Click(object sender, RoutedEventArgs e)
  388. {
  389. drawingAttributes.Width = 1;
  390. drawingAttributes.Height = 1;
  391. }
  392. /// <summary>
  393. /// 画笔粗细事件 中
  394. /// </summary>
  395. /// <param name="sender"></param>
  396. /// <param name="e"></param>
  397. private void RbnIn_Click(object sender, RoutedEventArgs e)
  398. {
  399. drawingAttributes.Width = 3;
  400. drawingAttributes.Height = 3;
  401. }
  402. /// <summary>
  403. /// 画笔粗细事件 粗
  404. /// </summary>
  405. /// <param name="sender"></param>
  406. /// <param name="e"></param>
  407. private void RbnCrude_Click(object sender, RoutedEventArgs e)
  408. {
  409. drawingAttributes.Width = 5;
  410. drawingAttributes.Height = 5;
  411. }
  412. /// <summary>
  413. /// 登陆事件
  414. /// </summary>
  415. /// <param name="sender"></param>
  416. /// <param name="e"></param>
  417. private void BtnLoginType_Click(object sender, RoutedEventArgs e)
  418. {
  419. Login();
  420. }
  421. /// <summary>
  422. /// 登陆
  423. /// </summary>
  424. private void Login()
  425. {
  426. if (APP.W_LoginWindow == null)
  427. {
  428. APP.W_LoginWindow = new LoginWindow();
  429. }
  430. else
  431. {
  432. APP.W_LoginWindow.Initialize();
  433. }
  434. APP.W_LoginWindow.ShowDialog();
  435. if (APP.IsLoginType)
  436. {
  437. txbLoginType.Text = APP.UserInfo.Username;
  438. }
  439. else
  440. {
  441. txbLoginType.Text = "未登录";
  442. }
  443. }
  444. /// <summary>
  445. /// 截图事件
  446. /// </summary>
  447. /// <param name="sender"></param>
  448. /// <param name="e"></param>
  449. private void BtnScreenshot_Click(object sender, RoutedEventArgs e)
  450. {
  451. if (APP.IsLoginType == false)
  452. {
  453. Login();
  454. return;
  455. }
  456. string time = GetTimeStamp();
  457. string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + time + ".jpg";
  458. ImageHelper.GetScreenshot(new System.Drawing.Rectangle(0, 0, 0, 0), desktopPath);
  459. if (APP.W_JieTuWindow != null)
  460. {
  461. APP.W_JieTuWindow.initialization();
  462. APP.W_JieTuWindow.Screenshot();
  463. APP.W_JieTuWindow.WindowState = WindowState.Maximized;
  464. APP.W_JieTuWindow.Visibility = Visibility.Visible;
  465. }
  466. else
  467. {
  468. APP.W_JieTuWindow = new JieTuWindow();
  469. // 订阅事件
  470. APP.W_JieTuWindow.ChangeTextEvent += new ChangeTextHandler(frm_ChangeTextEvent);
  471. APP.W_JieTuWindow.click_closeJietuWindowClick += JietuWindow_click_closeJietuWindowClick;
  472. APP.W_JieTuWindow.Show();
  473. }
  474. //imgCanvas.Source = new BitmapImage(new Uri(desktopPath));
  475. }
  476. /// <summary>
  477. /// 截图关闭窗口
  478. /// </summary>
  479. /// <param name="text"></param>
  480. private void frm_ChangeTextEvent(string text)
  481. {
  482. if ("关闭窗口".Equals(text))
  483. {
  484. if(!string.IsNullOrWhiteSpace(APP.ImgPath)&&File.Exists(APP.ImgPath))
  485. {
  486. APP.JPaths[APP.pageData.currpage]= APP.ImgPath;
  487. if(!string.IsNullOrWhiteSpace(APP.JPaths[APP.pageData.currpage]))
  488. {
  489. imgCanvas.Source = new BitmapImage(new Uri(APP.JPaths[APP.pageData.currpage]));
  490. }
  491. }
  492. }
  493. }
  494. /// <summary>
  495. /// 截图关闭 非正常关闭截图时,截图清空
  496. /// </summary>
  497. private void JietuWindow_click_closeJietuWindowClick()
  498. {
  499. APP.W_JieTuWindow = null;
  500. }
  501. /// <summary>
  502. /// 获取时间戳
  503. /// </summary>
  504. /// <returns></returns>
  505. public string GetTimeStamp()
  506. {
  507. TimeSpan ts = DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0);
  508. return Convert.ToInt64(ts.TotalSeconds).ToString();
  509. }
  510. /// <summary>
  511. /// 导入事件
  512. /// </summary>
  513. /// <param name="sender"></param>
  514. /// <param name="e"></param>
  515. private void BtnImport_Click(object sender, RoutedEventArgs e)
  516. {
  517. if (APP.IsLoginType == false)
  518. {
  519. Login();
  520. return;
  521. }
  522. try
  523. {
  524. string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
  525. ofd = new System.Windows.Forms.OpenFileDialog
  526. {
  527. Filter = "文档|*.docx;*.doc;*ppt",
  528. InitialDirectory = desktopPath,
  529. Multiselect = false,
  530. AddExtension = true,
  531. DereferenceLinks = true
  532. };
  533. new Thread(
  534. o =>
  535. {
  536. Thread.Sleep(400);
  537. Dispatcher.Invoke(new Action(() =>
  538. {
  539. OpenDialog();
  540. }
  541. ));
  542. })
  543. {
  544. IsBackground = true
  545. }.Start();
  546. }
  547. catch (Exception ex)
  548. {
  549. LogHelper.WriteErrLog("【导入(BtnImport_Click)" + ex.Message, ex);
  550. }
  551. }
  552. private void OpenDialog()
  553. {
  554. result = ofd.ShowDialog();
  555. if (result == System.Windows.Forms.DialogResult.OK)
  556. {
  557. if (ofd.FileName != "")
  558. {
  559. #region PPT转PDF
  560. string filepath = ofd.FileName;
  561. string path = ofd.SafeFileName.Replace(".ppt", "").Trim();
  562. string type = ofd.SafeFileName.Replace(".ppt", "typezsygppt").Trim();
  563. if (type.Contains("typezsygppt"))
  564. {
  565. try
  566. {
  567. string pathTemp = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  568. path = pathTemp + path + ".pdf";
  569. //PPT转PDF
  570. Presentation ppt = new Presentation(filepath);
  571. ppt.Save(path, Aspose.Slides.Export.SaveFormat.Pdf);
  572. #endregion
  573. #region PDF转图片
  574. // 图片绝对路径集合
  575. List<string> images = new List<string>();
  576. string directoryPath = pathTemp;
  577. //aspose许可证
  578. //Aspose.Pdf.License l = new Aspose.Pdf.License();
  579. //string licenseName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Aspose.Total.Product.Family.lic");
  580. //l.SetLicense(licenseName);
  581. //定义Jpeg转换设备
  582. Aspose.Pdf.Document document = new Aspose.Pdf.Document(path);
  583. var device = new Aspose.Pdf.Devices.JpegDevice();
  584. //int quality = int.Parse(this.comboBox1.SelectedItem.ToString());
  585. //directoryPath += quality;
  586. Directory.CreateDirectory(directoryPath);
  587. //默认质量为100,设置质量的好坏与处理速度不成正比,甚至是设置的质量越低反而花的时间越长,怀疑处理过程是先生成高质量的再压缩
  588. device = new Aspose.Pdf.Devices.JpegDevice(100);
  589. //遍历每一页转为jpg
  590. for (var i = 1; i <= document.Pages.Count; i++)
  591. {
  592. long ii = Timestamp();
  593. string filePathOutPut = Path.Combine(directoryPath, string.Format("{0}{1}.jpg", ii, i));
  594. images.Add(filePathOutPut);
  595. FileStream fs = new FileStream(filePathOutPut, FileMode.OpenOrCreate);
  596. try
  597. {
  598. device.Process(document.Pages[i], fs);
  599. fs.Close();
  600. }
  601. catch (Exception ex)
  602. {
  603. fs.Close();
  604. File.Delete(filePathOutPut);
  605. }
  606. }
  607. #endregion
  608. APP.Paths = images.ToArray();
  609. ImgPDFPath = images.ToArray();
  610. for (int i = 0; i < APP.Paths.Length; i++)
  611. {
  612. APP.pageData.pagenum += 1;
  613. }
  614. if (APP.pageData.pagenum > 1)
  615. {
  616. APP.pageData.pagenum -= 1;
  617. }
  618. if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage < APP.Paths.Length)
  619. {
  620. imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage - 1]));
  621. }
  622. else
  623. {
  624. imgCanvas.Source = null;
  625. }
  626. }
  627. catch (Exception ex)
  628. {
  629. LogHelper.WriteErrLog("【XHMicroLessonSystemWindow】(OpenDialog PPT)" + ex.Message, ex);
  630. }
  631. }
  632. else
  633. {
  634. try
  635. {
  636. string paths = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  637. APP.Paths = ConvertWordToImage(filepath, paths, "", 0, 0, null, 0).ToArray();
  638. for (int i = 0; i < APP.Paths.Length; i++)
  639. {
  640. APP.pageData.pagenum += 1;
  641. }
  642. if (APP.pageData.pagenum > 1)
  643. {
  644. APP.pageData.pagenum -= 1;
  645. }
  646. if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage < APP.Paths.Length)
  647. {
  648. imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage - 1]));
  649. }
  650. else
  651. {
  652. imgCanvas.Source = null;
  653. }
  654. }
  655. catch (Exception ex)
  656. {
  657. LogHelper.WriteErrLog("【XHMicroLessonSystemWindow】(OpenDialog PDF)" + ex.Message, ex);
  658. }
  659. }
  660. }
  661. }
  662. }
  663. /// <summary>
  664. /// 返回一个时间戳到毫秒
  665. /// </summary>
  666. /// <returns></returns>
  667. public static long Timestamp()
  668. {
  669. TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
  670. long timestr = Convert.ToInt64(ts.TotalMilliseconds);
  671. return timestr;
  672. }
  673. #region 录制窗口
  674. #region 变量
  675. /// <summary>
  676. /// 视频保存路径
  677. /// </summary>
  678. string RecordingPath;
  679. /// <summary>
  680. /// 图片保存路径
  681. /// </summary>
  682. string ImgPath;
  683. /// <summary>
  684. /// 音频保存路径名
  685. /// </summary>
  686. string AudioPathName;
  687. /// <summary>
  688. /// 视频保存路径名
  689. /// </summary>
  690. string VideoSavePathName;
  691. /// <summary>
  692. /// 暂停录制
  693. /// </summary>
  694. bool IsSuspendR = true;
  695. /// <summary>
  696. /// 是否首次录制
  697. /// </summary>
  698. bool IsFirstR = true;
  699. /// <summary>
  700. /// 图片
  701. /// </summary>
  702. List<string> RsImgName = null;
  703. /// <summary>
  704. /// 是否开始截图计数
  705. /// </summary>
  706. bool IsStartCount = false;
  707. #endregion
  708. /// <summary>
  709. /// 录制窗口内容
  710. /// </summary>
  711. /// <param name="sender"></param>
  712. /// <param name="e"></param>
  713. private void BtnRecord_Click(object sender, RoutedEventArgs e)
  714. {
  715. if (APP.IsLoginType == false)
  716. {
  717. Login();
  718. return;
  719. }
  720. blackboard_canvas.Visibility = Visibility.Visible;
  721. StartRecord();
  722. }
  723. /// <summary>
  724. /// 停止录制窗口内容
  725. /// </summary>
  726. /// <param name="sender"></param>
  727. /// <param name="e"></param>
  728. private void BtnStop_Click(object sender, RoutedEventArgs e)
  729. {
  730. if (APP.IsLoginType == false)
  731. {
  732. Login();
  733. return;
  734. }
  735. blackboard_canvas.Visibility = Visibility.Collapsed;
  736. EndRecord();
  737. }
  738. System.Timers.Timer timer;
  739. /// <summary>
  740. /// 开始录制和暂停录制
  741. /// </summary>
  742. void StartRecord()
  743. {
  744. if (IsSuspendR)
  745. {
  746. if (IsFirstR)//是否第一次录制 初始化录制
  747. {
  748. VideoInfo = new Model_Video();
  749. VideoInfo.VideoType = (Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType"));
  750. VideoInfo.WkType = Enum_WKVidetype.RecordingLessons;
  751. RecordingPath = APP.WKData.WkPath;
  752. ImgPath = APP.WKData.WkPath + "temp/Image/";
  753. AudioPathName = APP.WKData.WkPath + "temp/audio/";
  754. FileToolsCommon.DeleteDirectory(APP.WKData.WkPath + "temp/");
  755. FileToolsCommon.CreateDirectory(RecordingPath);
  756. FileToolsCommon.CreateDirectory(ImgPath);
  757. FileToolsCommon.CreateDirectory(AudioPathName);
  758. AudioPathName += APP.WKData.WkName + ".MP3";
  759. VideoSavePathName = RecordingPath + APP.WKData.WkName + "_录制." + VideoInfo.VideoType.ToString();
  760. if (FileToolsCommon.IsExistFile(VideoSavePathName))
  761. {
  762. MessageBoxResult dr = System.Windows.MessageBox.Show("课程已录制,是否覆盖?", "提示", MessageBoxButton.OKCancel);
  763. if (dr == MessageBoxResult.OK)
  764. {
  765. try
  766. {
  767. FileToolsCommon.DeleteFile(VideoSavePathName);
  768. APP.VideoList.RemoveAll(x => x.VidePath == VideoSavePathName);
  769. }
  770. catch (Exception ex)
  771. {
  772. LogHelper.WriteErrLog("【录制】(StartRecord)无法移除视频," + ex.Message, ex);
  773. }
  774. }
  775. else
  776. {
  777. return;
  778. }
  779. }
  780. IsFirstR = false;
  781. RsImgName = new List<string>();
  782. timer = new System.Timers.Timer(200);//设置执行一次(false)还是一直执行(true)
  783. timer.AutoReset = true;//设置是否执行System.Timers.Timer.Elapsed事件
  784. timer.Elapsed += new System.Timers.ElapsedEventHandler(Timer_Elapsed);
  785. timer.Enabled = true; //启动计时器
  786. }
  787. #region 录像倒计时
  788. if (APP.W_CountdownWindow == null)
  789. {
  790. APP.W_CountdownWindow = new CountdownWindow();
  791. //APP.W_CountdownWindow.Topmost = true;
  792. }
  793. else
  794. {
  795. APP.W_CountdownWindow.Initialize();
  796. APP.W_CountdownWindow.Topmost = true;
  797. }
  798. APP.W_CountdownWindow.Show();
  799. #endregion
  800. //继续录制
  801. IsSuspendR = false;
  802. //BtnRecording.Content = "暂停录制";
  803. ImgRecord.Source = new BitmapImage(new Uri("pack://application:,,,/Images/microLessonSystem_23.png"));
  804. TxbRecordingWord.Text = "暂停";
  805. try
  806. {
  807. APP.FFmpeg.StartRecordingAudio(AudioPathName);
  808. new Thread(new ThreadStart(new Action(() =>
  809. {
  810. Thread.Sleep(1000);
  811. Dispatcher.Invoke(() =>
  812. {
  813. IsStartCount = true;
  814. //timer.Start();
  815. });
  816. }))).Start();
  817. }
  818. catch (Exception ex)
  819. {
  820. System.Windows.MessageBox.Show(ex.Message);
  821. }
  822. }
  823. else
  824. {
  825. //暂停
  826. IsSuspendR = true;
  827. ImgRecord.Source = new BitmapImage(new Uri("pack://application:,,,/Images/microLessonSystem_14.png"));
  828. TxbRecordingWord.Text = "继续";
  829. try
  830. {
  831. APP.FFmpeg.SuspendFFmpeg();
  832. new Thread(new ThreadStart(new Action(() =>
  833. {
  834. while (APP.FFmpeg.myProcess != null)
  835. {
  836. Thread.Sleep(100);
  837. }
  838. IsStartCount = false;
  839. }))).Start();
  840. }
  841. catch (Exception ex)
  842. {
  843. System.Windows.MessageBox.Show(ex.Message);
  844. }
  845. }
  846. }
  847. /// <summary>
  848. /// 录制保存图片
  849. /// </summary>
  850. /// <param name="sender"></param>
  851. /// <param name="e"></param>
  852. private void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
  853. {
  854. if (IsStartCount)
  855. {
  856. try
  857. {
  858. Dispatcher.Invoke(() =>
  859. {
  860. string FilePathName = ImgPath + RsImgName.Count + ".png";
  861. ImageHelper.SaveUIToImage(GridMain, FilePathName, (int)this.ActualWidth, (int)this.ActualHeight);
  862. RsImgName.Add(FilePathName);
  863. });
  864. }
  865. catch (Exception ex)
  866. {
  867. LogHelper.WriteErrLog("【录制】(Timer_Elapsed)生成图片错误:" + ex.Message, ex);
  868. }
  869. }
  870. }
  871. /// <summary>
  872. /// 停止录制并生成录制文件
  873. /// </summary>
  874. void EndRecord()
  875. {
  876. if (!IsFirstR)
  877. {
  878. IsFirstR = true;
  879. IsSuspendR = true;
  880. ImgRecord.Source = new BitmapImage(new Uri("pack://application:,,,/Images/microLessonSystem_14.png"));
  881. TxbRecordingWord.Text = "录制";
  882. try
  883. {
  884. APP.FFmpeg.StopFFmpeg(AudioPathName);
  885. new Thread(new ThreadStart(new Action(() =>
  886. {
  887. while (APP.FFmpeg.myProcess != null)
  888. {
  889. Thread.Sleep(100);
  890. }
  891. Dispatcher.Invoke(() =>
  892. {
  893. IsStartCount = false;
  894. timer.Stop();
  895. });
  896. }))).Start();
  897. new Thread(new ThreadStart(new Action(() =>
  898. {
  899. while (APP.FFmpeg.myProcess != null)
  900. {
  901. Thread.Sleep(100);
  902. }
  903. }))).Start();
  904. APP.FFmpeg.SynthesisVideo(ImgPath, AudioPathName, VideoSavePathName, 5, (int)GridMain.Width, (int)GridMain.Height);
  905. //生成缩略图
  906. string ThumbnailPath = FileToolsCommon.GetDirectoryName(VideoSavePathName) + "ThumbnailPath/";
  907. FileToolsCommon.CreateDirectory(ThumbnailPath);
  908. //缩略图存储位置
  909. string ThumbnailPathName = ThumbnailPath + FileToolsCommon.GetIOFileNameNoExtension(VideoSavePathName) + ".JPG";
  910. new Thread(new ThreadStart(new Action(() =>
  911. {
  912. while (!FileToolsCommon.IsExistFile(VideoSavePathName))
  913. {
  914. Thread.Sleep(100);
  915. }
  916. FileToolsCommon.DeleteFile(ThumbnailPathName);
  917. VideoInfo.VideoSize = FileToolsCommon.GetFileSizeByMB(VideoSavePathName).ToString() + " MB";
  918. VideoInfo.RSTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  919. VideoInfo.VidePath = VideoSavePathName;
  920. VideoInfo.ThumbnailPath = ThumbnailPathName;
  921. APP.FFmpeg.GenerateThumbnails(VideoSavePathName, ThumbnailPathName);
  922. APP.VideoList.Add(VideoInfo);
  923. //保存数据
  924. APP.SaveWkData();
  925. }))).Start();
  926. //List<Model_Video> VideoList
  927. }
  928. catch (Exception ex)
  929. {
  930. System.Windows.MessageBox.Show(ex.Message);
  931. }
  932. }
  933. }
  934. #endregion
  935. /// <summary>
  936. /// 增加事件
  937. /// </summary>
  938. /// <param name="sender"></param>
  939. /// <param name="e"></param>
  940. private void BtnAdd_Click(object sender, RoutedEventArgs e)
  941. {
  942. if (APP.IsLoginType == false)
  943. {
  944. Login();
  945. return;
  946. }
  947. APP.pageData.pagenum += 1;
  948. APP.pageData.currpage = APP.pageData.pagenum;
  949. myblackboard.changepage(APP.pageData.currpage - 1);
  950. imgCanvas.Source = null;
  951. }
  952. /// <summary>
  953. /// 打印事件
  954. /// </summary>
  955. /// <param name="sender"></param>
  956. /// <param name="e"></param>
  957. private void BtnPrint_Click(object sender, RoutedEventArgs e)
  958. {
  959. if (APP.IsLoginType == false)
  960. {
  961. Login();
  962. return;
  963. }
  964. //for(int i=0;i< APP.pageData.pagenum; i++)
  965. //{
  966. //}
  967. ////string[] files = { @"C:\101\1.jpg", @"C:\101\2.jpg" };
  968. iTextSharp.text.Document document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 25, 25, 25, 25);
  969. try
  970. {
  971. //iTextSharp.text.Rectangle page = new iTextSharp.text.Rectangle(iTextSharp.text.PageSize.A4., 250f);//cs
  972. //设置纸张横向
  973. document.SetPageSize(iTextSharp.text.PageSize.A4.Rotate());
  974. iTextSharp.text.pdf.PdfWriter.GetInstance(document, new FileStream(@"G:\101.pdf", FileMode.Create, FileAccess.ReadWrite));
  975. document.Open();
  976. iTextSharp.text.Image image;
  977. for (int i = 0; i < 10/*ImgPDFPath.Length*/; i++)
  978. {
  979. if (String.IsNullOrEmpty(ImgPDFPath[i])) break;
  980. image = iTextSharp.text.Image.GetInstance(ImgPDFPath[i]);
  981. if (image.Height > iTextSharp.text.PageSize.A4.Height - 25)
  982. {
  983. image.ScaleToFit(iTextSharp.text.PageSize.A4.Width - 25, iTextSharp.text.PageSize.A4.Height - 25);
  984. }
  985. else if (image.Width > iTextSharp.text.PageSize.A4.Width - 25)
  986. {
  987. image.ScaleToFit(iTextSharp.text.PageSize.A4.Width - 25, iTextSharp.text.PageSize.A4.Height - 25);
  988. }
  989. image.Alignment = iTextSharp.text.Image.ALIGN_MIDDLE;
  990. document.NewPage();
  991. document.Add(image);
  992. //iTextSharp.text.Chunk c1 = new iTextSharp.text.Chunk("Hello World");
  993. //iTextSharp.text.Phrase p1 = new iTextSharp.text.Phrase();
  994. //p1.Leading = 150; //行间距
  995. //document.Add(p1);
  996. }
  997. Console.WriteLine("转换成功!");
  998. document.Close();
  999. }
  1000. catch (Exception ex)
  1001. {
  1002. Console.WriteLine("转换失败,原因:" + ex.Message);
  1003. }
  1004. //document.Close();
  1005. ////Console.ReadKey();
  1006. int pr = 1;
  1007. string msg = string.Empty;
  1008. string outPut = string.Empty;
  1009. LatticeFileHelper.GeneratingPDF(@"G:\101.pdf", @"G:\102.TPF",out pr, out msg, out outPut);
  1010. if(pr==0)
  1011. {
  1012. outPut = outPut.Replace("[", "").Replace("]","").Replace("\"","").Trim();
  1013. APP.OutPut = outPut.Split(',');
  1014. string defa = string.Empty;
  1015. List<string>defaList= LatticeFileHelper.GetPrinterList(out defa);
  1016. int printResult = 1;
  1017. string standardError = string.Empty;
  1018. string standardOutput = string.Empty;
  1019. LatticeFileHelper.PrinterTPFFile(@"G:\102.TPF",1, /*defa*/"导出为WPS PDF", out printResult,out standardError,out standardOutput);
  1020. }
  1021. }
  1022. /// <summary>
  1023. /// 我的
  1024. /// </summary>
  1025. /// <param name="sender"></param>
  1026. /// <param name="e"></param>
  1027. private void BtnMyMine_Click(object sender, RoutedEventArgs e)
  1028. {
  1029. if (APP.IsLoginType == false)
  1030. {
  1031. Login();
  1032. return;
  1033. }
  1034. }
  1035. /// <summary>
  1036. /// 上一页
  1037. /// </summary>
  1038. /// <param name="sender"></param>
  1039. /// <param name="e"></param>
  1040. private void last_button_Click(object sender, RoutedEventArgs e)
  1041. {
  1042. if (APP.pageData.currpage > 1)
  1043. {
  1044. try
  1045. {
  1046. Dispatcher.Invoke(() =>
  1047. {
  1048. string filePath = FileToolsCommon.GetFileAbsolutePath("/Data/" + APP.UserInfo.Username + "/pdfimagetemp/");
  1049. FileToolsCommon.CreateDirectory(filePath);
  1050. string filePathName = filePath + APP.pageData.currpage.ToString() + ".jpg";
  1051. ImageHelper.SaveUIToImage(GridMain, filePathName, (int)GridMain.ActualWidth, (int)GridMain.ActualHeight);
  1052. ImgPDFPath[APP.pageData.currpage - 1] = filePathName;
  1053. });
  1054. }
  1055. catch (Exception ex)
  1056. {
  1057. LogHelper.WriteErrLog("【XHMicroLessonSystemWindow】(last_button_Click)生成图片错误:" + ex.Message, ex);
  1058. }
  1059. APP.pageData.currpage -= 1;
  1060. myblackboard.changepage(APP.pageData.currpage - 1);
  1061. if (APP.Paths.Length > 0)
  1062. {
  1063. if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage < APP.Paths.Length&& APP.pageData.currpage > 0)
  1064. {
  1065. imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage - 1]));
  1066. }
  1067. else
  1068. {
  1069. imgCanvas.Source = null;
  1070. }
  1071. }
  1072. if (!string.IsNullOrWhiteSpace(APP.JPaths[APP.pageData.currpage]))
  1073. {
  1074. imgCanvas.Source = new BitmapImage(new Uri(APP.JPaths[APP.pageData.currpage]));
  1075. }
  1076. }
  1077. }
  1078. /// <summary>
  1079. /// 下一页
  1080. /// </summary>
  1081. /// <param name="sender"></param>
  1082. /// <param name="e"></param>
  1083. private void next_btn_Click(object sender, RoutedEventArgs e)
  1084. {
  1085. if (APP.pageData.currpage < APP.pageData.pagenum)
  1086. {
  1087. try
  1088. {
  1089. Dispatcher.Invoke(() =>
  1090. {
  1091. string filePath = FileToolsCommon.GetFileAbsolutePath("/Data/" + APP.UserInfo.Username + "/pdfimagetemp/");
  1092. FileToolsCommon.CreateDirectory(filePath);
  1093. string filePathName = filePath + APP.pageData.currpage.ToString() + ".jpg";
  1094. ImageHelper.SaveUIToImage(GridMain, filePathName, (int)GridMain.ActualWidth, (int)GridMain.ActualHeight);
  1095. ImgPDFPath[APP.pageData.currpage - 1] = filePathName;
  1096. });
  1097. }
  1098. catch (Exception ex)
  1099. {
  1100. LogHelper.WriteErrLog("【XHMicroLessonSystemWindow】(next_btn_Click)生成图片错误:" + ex.Message, ex);
  1101. }
  1102. APP.pageData.currpage += 1;
  1103. myblackboard.changepage(APP.pageData.currpage - 1);
  1104. if (APP.Paths.Length > 0)
  1105. {
  1106. if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage <= APP.Paths.Length)
  1107. {
  1108. imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage-1]));
  1109. }
  1110. else
  1111. {
  1112. imgCanvas.Source = null;
  1113. }
  1114. }
  1115. if (!string.IsNullOrWhiteSpace(APP.JPaths[APP.pageData.currpage]))
  1116. {
  1117. imgCanvas.Source = new BitmapImage(new Uri(APP.JPaths[APP.pageData.currpage]));
  1118. }
  1119. }
  1120. }
  1121. /// <summary>
  1122. /// 将Word文档转换为图片的方法(该方法基于第三方DLL),你可以像这样调用该方法: ConvertPDF2Image("F:\\PdfFile.doc", "F:\\",
  1123. /// "ImageFile", 1, 20, ImageFormat.Png, 256);
  1124. /// </summary>
  1125. /// <param name="pdfInputPath">Word文件路径</param>
  1126. /// <param name="imageOutputPath">图片输出路径,如果为空,默认值为Word所在路径</param>
  1127. /// <param name="imageName">图片的名字,不需要带扩展名,如果为空,默认值为Word的名称</param>
  1128. /// <param name="startPageNum">从PDF文档的第几页开始转换,如果为0,默认值为1</param>
  1129. /// <param name="endPageNum">从PDF文档的第几页开始停止转换,如果为0,默认值为Word总页数</param>
  1130. /// <param name="imageFormat">设置所需图片格式,如果为null,默认格式为PNG</param>
  1131. /// <param name="resolution">设置图片的像素,数字越大越清晰,如果为0,默认值为128,建议最大值不要超过1024</param>
  1132. public List<string> ConvertWordToImage(string wordInputPath, string imageOutputPath,
  1133. string imageName, int startPageNum, int endPageNum, ImageFormat imageFormat, float resolution)
  1134. {
  1135. // 返回的图片绝对路径集合
  1136. List<string> images = new List<string>();
  1137. try
  1138. {
  1139. // open word file
  1140. Aspose.Words.Document doc = new Aspose.Words.Document(wordInputPath);
  1141. // validate parameter
  1142. if (doc == null) { throw new Exception("Word文件无效或者Word文件被加密!"); }
  1143. if (imageOutputPath.Trim().Length == 0) { imageOutputPath = System.IO.Path.GetDirectoryName(wordInputPath); }
  1144. if (!Directory.Exists(imageOutputPath)) { Directory.CreateDirectory(imageOutputPath); }
  1145. if (imageName.Trim().Length == 0) { imageName = System.IO.Path.GetFileNameWithoutExtension(wordInputPath); }
  1146. if (startPageNum <= 0) { startPageNum = 1; }
  1147. if (endPageNum > doc.PageCount || endPageNum <= 0) { endPageNum = doc.PageCount; }
  1148. if (startPageNum > endPageNum) { int tempPageNum = startPageNum; startPageNum = endPageNum; endPageNum = startPageNum; }
  1149. if (imageFormat == null) { imageFormat = ImageFormat.Png; }
  1150. if (resolution <= 0) { resolution = 128; }
  1151. ImageSaveOptions imageSaveOptions = new ImageSaveOptions(GetSaveFormat(imageFormat))
  1152. {
  1153. Resolution = resolution
  1154. };
  1155. // start to convert each page
  1156. for (int i = startPageNum; i <= endPageNum; i++)
  1157. {
  1158. imageSaveOptions.PageIndex = i - 1;
  1159. doc.Save(System.IO.Path.Combine(imageOutputPath, imageName) + "_" + APP.num.ToString() + "." + imageFormat.ToString(), imageSaveOptions);
  1160. images.Add(System.IO.Path.Combine(imageOutputPath, imageName) + "_" + APP.num.ToString() + "." + imageFormat.ToString());
  1161. APP.num++;
  1162. }
  1163. imageSaveOptions = null;
  1164. doc = null;
  1165. }
  1166. catch (Exception ex)
  1167. {
  1168. System.Windows.MessageBox.Show("文档已打开,请关闭后重试!");
  1169. LogHelper.WriteErrLog("【课堂考试(ExamWindow)】错误日志:" + ex.Message, ex);
  1170. }
  1171. return images;
  1172. }
  1173. private static SaveFormat GetSaveFormat(ImageFormat imageFormat)
  1174. {
  1175. SaveFormat sf;// = SaveFormat.Unknown;
  1176. if (imageFormat.Equals(ImageFormat.Png))
  1177. {
  1178. sf = SaveFormat.Png;
  1179. }
  1180. else if (imageFormat.Equals(ImageFormat.Jpeg))
  1181. {
  1182. sf = SaveFormat.Jpeg;
  1183. }
  1184. else if (imageFormat.Equals(ImageFormat.Tiff))
  1185. {
  1186. sf = SaveFormat.Tiff;
  1187. }
  1188. else if (imageFormat.Equals(ImageFormat.Bmp))
  1189. {
  1190. sf = SaveFormat.Bmp;
  1191. }
  1192. else
  1193. {
  1194. sf = SaveFormat.Unknown;
  1195. }
  1196. return sf;
  1197. }
  1198. #region 图像缩放,移动
  1199. private bool mouseDown;
  1200. private System.Windows.Point mouseXY;
  1201. private void IMG1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  1202. {
  1203. var img = sender as ContentControl;
  1204. if (img == null)
  1205. {
  1206. return;
  1207. }
  1208. img.CaptureMouse();
  1209. mouseDown = true;
  1210. mouseXY = e.GetPosition(img);
  1211. Console.WriteLine("mouseXY.X = " + mouseXY.X + "; mouseXY.Y = " + mouseXY.Y);
  1212. }
  1213. private void PicEMap_MouseDown(object sender, MouseButtonEventArgs e)
  1214. {
  1215. System.Windows.Point point = e.GetPosition(imgCanvas);
  1216. //Console.WriteLine("PicEmap.X = " + point.X + "; PicEmap.Y = " + point.Y);
  1217. //if ((point.X - 304) * (point.X - 304) + (point.Y - 86) * (point.Y - 86) < 100)
  1218. //{
  1219. // Console.WriteLine("在范围内");
  1220. //}
  1221. }
  1222. private void IMG1_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  1223. {
  1224. var img = sender as ContentControl;
  1225. if (img == null)
  1226. {
  1227. return;
  1228. }
  1229. img.ReleaseMouseCapture();
  1230. mouseDown = false;
  1231. }
  1232. private void IMG1_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
  1233. {
  1234. var img = sender as ContentControl;
  1235. if (img == null)
  1236. {
  1237. return;
  1238. }
  1239. if (mouseDown)
  1240. {
  1241. Domousemove(img, e);
  1242. }
  1243. }
  1244. private void Domousemove(ContentControl img, System.Windows.Input.MouseEventArgs e)
  1245. {
  1246. if (e.LeftButton != MouseButtonState.Pressed)
  1247. {
  1248. return;
  1249. }
  1250. var group = IMG.FindResource("Imageview") as TransformGroup;
  1251. var transform = group.Children[1] as TranslateTransform;
  1252. var position = e.GetPosition(img);
  1253. transform.X -= mouseXY.X - position.X;
  1254. transform.Y -= mouseXY.Y - position.Y;
  1255. mouseXY = position;
  1256. }
  1257. private void IMG1_MouseWheel(object sender, MouseWheelEventArgs e)
  1258. {
  1259. var img = sender as ContentControl;
  1260. if (img == null)
  1261. {
  1262. return;
  1263. }
  1264. var point = e.GetPosition(img);
  1265. Console.WriteLine("point.X = " + point.X + "; point.Y=" + point.Y);
  1266. var PicLocate = e.GetPosition(imgCanvas);
  1267. Console.WriteLine("PicEmap.X = " + PicLocate.X + "; PicEmap.Y=" + PicLocate.Y);
  1268. var group = IMG.FindResource("Imageview") as TransformGroup;
  1269. var delta = e.Delta * 0.001;
  1270. DowheelZoom(group, point, delta);
  1271. }
  1272. private void DowheelZoom(TransformGroup group, System.Windows.Point point, double delta)
  1273. {
  1274. var pointToContent = group.Inverse.Transform(point);
  1275. var transform = group.Children[0] as ScaleTransform;
  1276. if (transform.ScaleX + delta < 0.1) return;
  1277. transform.ScaleX += delta;
  1278. transform.ScaleY += delta;
  1279. var transform1 = group.Children[1] as TranslateTransform;
  1280. transform1.X = -1 * ((pointToContent.X * transform.ScaleX) - point.X);
  1281. transform1.Y = -1 * ((pointToContent.Y * transform.ScaleY) - point.Y);
  1282. //Console.WriteLine("transform.ScaleX = " + transform.ScaleX + "; transform.ScaleY = " + transform.ScaleY);
  1283. }
  1284. #endregion
  1285. #region 点阵笔相关
  1286. #region 值初始化
  1287. // 不同尺寸点阵纸点阵宽高尺寸计算方法为:纸张物理尺寸(毫米)/0.3 *8,详见 开发必读.pdf 文档
  1288. /// <summary>
  1289. /// A4点阵纸点阵宽度
  1290. /// </summary>
  1291. private const int A4_WIDTH = 5600;
  1292. /// <summary>
  1293. /// A4点阵纸点阵高度
  1294. /// </summary>
  1295. private const int A4_HEIGHT = 7920;
  1296. /// <summary>
  1297. /// 画板
  1298. /// </summary>
  1299. private Graphics graphics;
  1300. /// <summary>
  1301. /// 笔画坐标数组
  1302. /// </summary>
  1303. private List<System.Drawing.Point> stroke;
  1304. /// <summary>
  1305. /// 笔序列号
  1306. /// </summary>
  1307. private string penSerial;
  1308. /// <summary>
  1309. /// 笔是否在点
  1310. /// </summary>
  1311. private bool isPenDown;
  1312. //当前点阵地址
  1313. private string currentPageSerial = string.Empty;
  1314. //不同点阵地址对应的笔迹绘制图片,用于实现在不同点阵地址书写切换时,显示书写内容自动切换
  1315. //本例图片放在内存中存储,对于大量或者需要在多个点阵地址对应图片进行切换演示,建议将图片存储到文件,以免内存溢出
  1316. private Dictionary<string, System.Drawing.Image> pagesDic = new Dictionary<string, System.Drawing.Image>();
  1317. #endregion
  1318. public void InitPen()
  1319. {
  1320. stroke = new List<System.Drawing.Point>();
  1321. //获取点阵笔实例,并绑定点阵笔事件
  1322. //将授权文件内容传入,获取点阵笔对象实例
  1323. APP.digitalPen = DigitalPenHID.GetInstance(certificates.MyLicense.Bytes);
  1324. //绑定笔连接事件
  1325. APP.digitalPen.PenConnected += OnPenConnect;
  1326. //绑定笔断开事件
  1327. APP.digitalPen.PenDisconnect += OnPenDisconnect;
  1328. //绑定笔书写输出坐标事件
  1329. APP.digitalPen.PenCoordinate += OnPenCoordinate;
  1330. //绑定抬笔事件
  1331. APP.digitalPen.PenUp += OnPenUp;
  1332. //绑定落笔事件
  1333. APP.digitalPen.PenDown += OnPenDown;
  1334. APP.digitalPen.PenBatteryCapacity += OnBatteryCapacity;
  1335. APP.digitalPen.PenMemoryFillLevel += OnMemoryFillLevel;
  1336. //完成初始化点阵笔,开始与点阵笔通信
  1337. ERROR_CODE ER = APP.digitalPen.Start();
  1338. ////绑定笔在新的点阵地址页面书写事件
  1339. //APP.digitalPen.PenNewPage += APP.digitalPen_OnPenNewPage;
  1340. ////绑定笔信息事件
  1341. //APP.digitalPen.PenInfo += APP.digitalPen_OnPenInfo;
  1342. //启动接收笔数据,完成初始化工作
  1343. ERROR_CODE rc = APP.digitalPen.Start();
  1344. //判断是否成功
  1345. if (ER != ERROR_CODE.ERROR_OK)
  1346. {
  1347. System.Windows.MessageBox.Show("初始化失败,授权过期,返回值:" + ER.ToString());
  1348. }
  1349. }
  1350. /// <summary>
  1351. /// 落笔
  1352. /// </summary>
  1353. /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
  1354. /// <param name="penSerial">点阵笔序列号</param>
  1355. /// <param name="penType">点阵笔型号编号</param>
  1356. private void OnPenDown(ulong time, string penSerial, int penType)
  1357. {
  1358. if (this.CheckAccess())
  1359. {
  1360. Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenDown);
  1361. this.Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
  1362. }
  1363. else
  1364. {
  1365. //labPenSerial.Text = penSerial;
  1366. //labPenStatus.Text = "PenDown";
  1367. isPenDown = true;
  1368. }
  1369. }
  1370. /// <summary>
  1371. /// 抬笔
  1372. /// </summary>
  1373. /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
  1374. /// <param name="penSerial">点阵笔序列号</param>
  1375. /// <param name="penType">点阵笔型号编号</param>
  1376. private void OnPenUp(ulong time, string penSerial, int penType)
  1377. {
  1378. if (this.CheckAccess())
  1379. {
  1380. Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenUp);
  1381. this.Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
  1382. }
  1383. else
  1384. {
  1385. isPenDown = false;
  1386. APP.PenSerial = penSerial;
  1387. //int leftPoints = stroke.Count % 3;
  1388. //if (0 != leftPoints)
  1389. //{
  1390. // int from = stroke.Count - leftPoints - 1;
  1391. // if (from < 0)
  1392. // from = 0;
  1393. // int to = stroke.Count - 1;
  1394. // DrawCoordinates(from, to);
  1395. //}
  1396. stroke.Clear();
  1397. }
  1398. }
  1399. /// <summary>
  1400. /// 笔断开
  1401. /// </summary>
  1402. /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
  1403. /// <param name="penSerial">点阵笔序列号</param>
  1404. /// <param name="penType">点阵笔型号编号</param>
  1405. private void OnPenDisconnect(ulong time, string penSerial, int penType)
  1406. {
  1407. if (this.CheckAccess())
  1408. {
  1409. Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenDisconnect);
  1410. this.Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
  1411. }
  1412. else
  1413. {
  1414. APP.PenSerial = penSerial;
  1415. APP.PenStatus = false;
  1416. }
  1417. }
  1418. /// <summary>
  1419. /// 笔连接
  1420. /// </summary>
  1421. /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
  1422. /// <param name="penSerial">点阵笔序列号</param>
  1423. /// <param name="penType">点阵笔型号编号</param>
  1424. private void OnPenConnect(ulong time, string penSerial, int penType)
  1425. {
  1426. if (this.CheckAccess())
  1427. {
  1428. Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenConnect);
  1429. this.Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
  1430. }
  1431. else
  1432. {
  1433. APP.PenSerial = penSerial;
  1434. APP.PenStatus = true;
  1435. this.penSerial = penSerial;
  1436. //连接后,在获取笔数据前,可以清除笔内的历史数据
  1437. //APP.digitalPen.ClearMemory(penSerial);
  1438. //开始接收笔数据
  1439. APP.digitalPen.GetPenData(penSerial);
  1440. }
  1441. }
  1442. /// <summary>
  1443. /// 电池电量
  1444. /// </summary>
  1445. /// <param name="time"></param>
  1446. /// <param name="penSerial"></param>
  1447. /// <param name="penType"></param>
  1448. /// <param name="capacity"></param>
  1449. private void OnBatteryCapacity(ulong time, string penSerial, int penType, byte capacity)
  1450. {
  1451. if (this.CheckAccess())
  1452. {
  1453. Action<ulong, string, int, byte> action = new Action<ulong, string, int, byte>(OnBatteryCapacity);
  1454. this.Dispatcher.Invoke(action, new object[] { time, penSerial, penType, capacity });
  1455. }
  1456. else
  1457. {
  1458. //System.Windows.MessageBox.Show("电池电量:" + capacity.ToString());
  1459. }
  1460. }
  1461. /// <summary>
  1462. /// 已用存储
  1463. /// </summary>
  1464. /// <param name="time"></param>
  1465. /// <param name="penSerial"></param>
  1466. /// <param name="penType"></param>
  1467. /// <param name="fillLevel"></param>
  1468. private void OnMemoryFillLevel(ulong time, string penSerial, int penType, byte fillLevel)
  1469. {
  1470. if (this.CheckAccess())
  1471. {
  1472. Action<ulong, string, int, byte> action = new Action<ulong, string, int, byte>(OnMemoryFillLevel);
  1473. this.Dispatcher.Invoke(action, new object[] { time, penSerial, penType, fillLevel });
  1474. }
  1475. else
  1476. {
  1477. //System.Windows.MessageBox.Show("存储:" + fillLevel.ToString());
  1478. }
  1479. }
  1480. /// <summary>
  1481. /// 笔书写,收到坐标
  1482. /// </summary>
  1483. /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
  1484. /// <param name="penSerial">点阵笔序列号</param>
  1485. /// <param name="penType">点阵笔型号编号</param>
  1486. /// <param name="pageSerial">点阵地址</param>
  1487. /// <param name="cx">x坐标</param>
  1488. /// <param name="cy">y坐标</param>
  1489. /// <param name="force">压力值</param>
  1490. private void OnPenCoordinate(ulong time, string penSerial, int penType, string pageSerial, int cx, int cy, byte force)
  1491. {
  1492. if (this.CheckAccess())
  1493. {
  1494. Action<ulong, string, int, string, int, int, byte> ac = new Action<ulong, string, int, string, int, int, byte>(OnPenCoordinate);
  1495. this.Dispatcher.Invoke(ac, new object[] { time, pageSerial, penType, pageSerial, cx, cy, force });
  1496. }
  1497. else
  1498. {
  1499. //判断是否是落笔后输出的坐标,在设置悬浮模式下,落笔前的悬浮坐标不绘制
  1500. if (!isPenDown)
  1501. {
  1502. return;
  1503. }
  1504. stroke.Add(new System.Drawing.Point(cx, cy));
  1505. double PropW = blackboard_canvas.ActualWidth / A4_WIDTH;
  1506. double PropH = blackboard_canvas.ActualHeight / A4_HEIGHT;
  1507. //点
  1508. double testX=(double)cx * PropW;
  1509. double testY=(double)cy * PropH;
  1510. //pageSerial //点阵IP地址 与打印的页面关联
  1511. ////每3个点画一条曲线
  1512. //if (stroke.Count % 3 == 0)
  1513. //{
  1514. // int from = stroke.Count - 3 - 1;
  1515. // if (from < 0)
  1516. // from = 0;
  1517. // int to = stroke.Count - 1;
  1518. // DrawCoordinates(from, to);
  1519. //}
  1520. }
  1521. }
  1522. /// <summary>
  1523. /// 停止笔
  1524. /// </summary>
  1525. public void StopDigitalPen()
  1526. {
  1527. //停止,释放资源
  1528. APP.digitalPen.Stop();
  1529. }
  1530. /// <summary>
  1531. /// 清空笔内存储
  1532. /// </summary>
  1533. public void ClearPenStorage()
  1534. {
  1535. if (!string.IsNullOrEmpty(penSerial))
  1536. APP.digitalPen.ClearMemory(penSerial);
  1537. }
  1538. /// <summary>
  1539. /// 获取剩余电量
  1540. /// </summary>
  1541. public void GetPenElectricityQuantity()
  1542. {
  1543. if (!string.IsNullOrEmpty(penSerial))
  1544. APP.digitalPen.GetBatteryCapacity(penSerial);
  1545. }
  1546. /// <summary>
  1547. /// 获取存储空间
  1548. /// </summary>
  1549. public void GetUsedStorage()
  1550. {
  1551. if (!string.IsNullOrEmpty(penSerial))
  1552. APP.digitalPen.GetMemoryFillLevel(penSerial);
  1553. }
  1554. /// <summary>
  1555. /// 开启悬浮
  1556. /// </summary>
  1557. public void 开启悬浮()
  1558. {
  1559. if (!string.IsNullOrEmpty(penSerial))
  1560. APP.digitalPen.SetPenHoverMode(true, penSerial);
  1561. }
  1562. /// <summary>
  1563. /// 关闭悬浮
  1564. /// </summary>
  1565. public void 关闭悬浮()
  1566. {
  1567. if (!string.IsNullOrEmpty(penSerial))
  1568. APP.digitalPen.SetPenHoverMode(false, penSerial);
  1569. }
  1570. #endregion
  1571. }
  1572. }