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

XHMicroLessonSystemWindow.xaml.cs 96KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246
  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. using XHWK.WKTool.DAL;
  23. using System.Text;
  24. using System.Collections.Specialized;
  25. namespace XHWK.WKTool
  26. {
  27. /// <summary>
  28. /// 主页面
  29. /// </summary>
  30. public partial class XHMicroLessonSystemWindow : Window
  31. {
  32. #region 字段
  33. /// <summary>
  34. /// 文件目录窗口
  35. /// </summary>
  36. //private CountdownWindow FileDirectoryWindows = null;
  37. private FolderBrowserDialog Ofd;
  38. private DialogResult Result;
  39. public readonly BlackboardNew myblackboard;
  40. private System.Windows.Forms.DialogResult result;
  41. private System.Windows.Forms.OpenFileDialog ofd;
  42. //声明一个 DrawingAttributes 类型的变量
  43. DrawingAttributes drawingAttributes;
  44. Model_Video VideoInfo = null;
  45. //定义事件
  46. public event ChangeTextHandler ChangeTextEvent;
  47. //定义委托
  48. public delegate void ChangeTextHandler(string text);
  49. /// <summary>
  50. /// 图片
  51. /// </summary>
  52. string[] ImgPDFPath = new string[300];
  53. /// <summary>
  54. /// 当前颜色
  55. /// </summary>
  56. private System.Windows.Media.Color Color = System.Windows.Media.Colors.Black;
  57. /// <summary>
  58. /// 笔迹粗细
  59. /// </summary>
  60. private int Size = 2;
  61. #endregion
  62. #region 初始化
  63. /// <summary>
  64. /// 主页面
  65. /// </summary>
  66. public XHMicroLessonSystemWindow()
  67. {
  68. 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=")));
  69. InitializeComponent();
  70. btnPrint.IsEnabled = false;
  71. myblackboard = new BlackboardNew(blackboard_canvas);
  72. APP.pageData.pagenum = 1;
  73. APP.pageData.currpage = 1;
  74. DataContext = APP.pageData;
  75. //APP.SaveDraw();//画板模型第一页初始化
  76. APP.PageDrawList = new List<Model_DrawData>();
  77. Model_DrawData model_DrawData = new Model_DrawData();
  78. model_DrawData.PageNum = APP.pageData.currpage;
  79. APP.PageDrawList.Add(model_DrawData);
  80. txbStoragePath.Content = FileToolsCommon.GetConfigValue("VideoType");
  81. if (FileToolsCommon.GetConfigValue("IsSound").Equals("true"))
  82. {
  83. rbnY.IsChecked = true;
  84. }
  85. else
  86. {
  87. rbnN.IsChecked = true;
  88. }
  89. txbStoragePath.Content = FileToolsCommon.GetConfigValue("VideoSavePath");
  90. Initialize();
  91. InitPen();
  92. }
  93. /// <summary>
  94. /// 初始化
  95. /// </summary>
  96. public void Initialize()
  97. {
  98. APP.CameraPosition = FileToolsCommon.GetConfigValue("CameraPosition");
  99. //创建 DrawingAttributes 类的一个实例
  100. drawingAttributes = new DrawingAttributes();
  101. //将 InkCanvas 的 DefaultDrawingAttributes 属性的值赋成创建的 DrawingAttributes 类的对象的引用
  102. //InkCanvas 通过 DefaultDrawingAttributes 属性来获取墨迹的各种设置,该属性的类型为 DrawingAttributes 型
  103. blackboard_canvas.DefaultDrawingAttributes = drawingAttributes;
  104. blackboard_canvas.UseCustomCursor = true;
  105. drawingAttributes.FitToCurve = true;
  106. drawingAttributes.IgnorePressure = false;
  107. drawingAttributes.Width = Size;
  108. drawingAttributes.Height = Size;
  109. drawingAttributes.Color = Color;
  110. blackboard_canvas.Cursor = System.Windows.Input.Cursors.Pen;
  111. //wfhCamera.Visibility = Visibility.Hidden;
  112. ImgPDFPath = null;
  113. ImgPDFPath = new string[300];
  114. }
  115. #endregion
  116. #region 事件
  117. /// <summary>
  118. /// 窗体移动
  119. /// </summary>
  120. /// <param name="sender"></param>
  121. /// <param name="e"></param>
  122. private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  123. {
  124. DragMove();
  125. }
  126. #region 摄像头
  127. System.Timers.Timer times;
  128. List<string> RbnOpen;
  129. bool IsRbnOpen = false;
  130. /// <summary>
  131. /// 摄像头打开事件
  132. /// </summary>
  133. /// <param name="sender"></param>
  134. /// <param name="e"></param>
  135. private void RbnOpen_Click(object sender, RoutedEventArgs e)
  136. {
  137. //UCCamera win = new UCCamera();
  138. ////win.Topmost = true;
  139. //win.ShowDialog();
  140. //wfhCamera.Visibility = Visibility.Visible;
  141. //CameraHelper.IsDisplay = true;
  142. //CameraHelper.SourcePlayer = player;
  143. CameraHelper.UpdateCameraDevices();
  144. if (CameraHelper.CameraDevices.Count > 0)
  145. {
  146. CameraHelper.SetCameraDevice(0);
  147. RbnOpen = new List<string>();
  148. times = new System.Timers.Timer(200);//设置执行一次(false)还是一直执行(true)
  149. times.AutoReset = true;//设置是否执行System.Timers.Timer.Elapsed事件
  150. times.Elapsed += new System.Timers.ElapsedEventHandler(Times_Elapsed);
  151. times.Enabled = true; //启动计时器
  152. IsRbnOpen = true;
  153. string imgPath = FileToolsCommon.GetFileAbsolutePath("Temp/imgplayer");
  154. FileToolsCommon.CreateDirectory(imgPath);
  155. }
  156. }
  157. int I = 9999;
  158. private void Times_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
  159. {
  160. if (IsRbnOpen)
  161. {
  162. try
  163. {
  164. Dispatcher.Invoke(() =>
  165. {
  166. if (I > 10010)
  167. {
  168. long time = Timestamp();
  169. string imgPath= FileToolsCommon.GetFileAbsolutePath("Temp/imgplayer");
  170. //string FilePathName = ImgPath + RsImgName.Count + ".png";
  171. string path = CameraHelper.CaptureImage(imgPath, time.ToString());
  172. if (!string.IsNullOrWhiteSpace(path))
  173. {
  174. RbnOpen.Add(path);
  175. imgPlayerRight.Visibility = Visibility.Visible;
  176. /// < !--摄像头位置 1.右上 2.左上 3.右下 4.左下-- >
  177. if ("1".Equals(APP.CameraPosition))
  178. {
  179. imgPlayerRight.Visibility = Visibility.Visible;
  180. imgPlayerLeft.Visibility = Visibility.Collapsed;
  181. imgPlayerRightUnder.Visibility = Visibility.Collapsed;
  182. imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
  183. imgPlayerRight.Source = new BitmapImage(new Uri(path));
  184. }
  185. else if ("2".Equals(APP.CameraPosition))
  186. {
  187. imgPlayerRight.Visibility = Visibility.Collapsed;
  188. imgPlayerLeft.Visibility = Visibility.Visible;
  189. imgPlayerRightUnder.Visibility = Visibility.Collapsed;
  190. imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
  191. imgPlayerLeft.Source = new BitmapImage(new Uri(path));
  192. }
  193. else if ("3".Equals(APP.CameraPosition))
  194. {
  195. imgPlayerRight.Visibility = Visibility.Collapsed;
  196. imgPlayerLeft.Visibility = Visibility.Collapsed;
  197. imgPlayerRightUnder.Visibility = Visibility.Visible;
  198. imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
  199. imgPlayerRightUnder.Source = new BitmapImage(new Uri(path));
  200. }
  201. else if ("4".Equals(APP.CameraPosition))
  202. {
  203. imgPlayerRight.Visibility = Visibility.Collapsed;
  204. imgPlayerLeft.Visibility = Visibility.Collapsed;
  205. imgPlayerRightUnder.Visibility = Visibility.Collapsed;
  206. imgPlayerLeftUnder.Visibility = Visibility.Visible;
  207. imgPlayerLeftUnder.Source = new BitmapImage(new Uri(path));
  208. }
  209. else
  210. {
  211. imgPlayerLeft.Visibility = Visibility.Collapsed;
  212. imgPlayerRightUnder.Visibility = Visibility.Collapsed;
  213. imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
  214. imgPlayerRight.Source = new BitmapImage(new Uri(path));
  215. }
  216. }
  217. }
  218. I++;
  219. });
  220. }
  221. catch (Exception ex)
  222. {
  223. LogHelper.WriteErrLog("【摄像】(Times_Elapsed)生成图片错误:" + ex.Message, ex);
  224. }
  225. }
  226. }
  227. /// <summary>
  228. /// 摄像头关闭事件
  229. /// </summary>
  230. /// <param name="sender"></param>
  231. /// <param name="e"></param>
  232. private void RbnTurnOff_Click(object sender, RoutedEventArgs e)
  233. {
  234. IsRbnOpen = false;
  235. imgPlayerRight.Visibility = Visibility.Collapsed;
  236. imgPlayerLeft.Visibility = Visibility.Collapsed;
  237. imgPlayerRightUnder.Visibility = Visibility.Collapsed;
  238. imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
  239. CameraHelper.CloseDevice();
  240. I = 9999;
  241. }
  242. #endregion
  243. #endregion
  244. /// <summary>
  245. /// 录屏事件
  246. /// </summary>
  247. /// <param name="sender"></param>
  248. /// <param name="e"></param>
  249. private void BtnScreenRecording_Click(object sender, RoutedEventArgs e)
  250. {
  251. if (APP.IsLoginType == false)
  252. {
  253. Login();
  254. return;
  255. }
  256. string RecordScreenPathName = APP.WKData.WkPath + APP.WKData.WkName + "_录屏." + ((Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType"))).ToString();
  257. if (FileToolsCommon.IsExistFile(RecordScreenPathName))
  258. {
  259. MessageBoxResult dr = System.Windows.MessageBox.Show("已存在录屏,是否覆盖?", "提示", MessageBoxButton.OKCancel);
  260. if (dr == MessageBoxResult.OK)
  261. {
  262. try
  263. {
  264. FileToolsCommon.DeleteFile(RecordScreenPathName);
  265. APP.VideoList.RemoveAll(x => x.VideoPath == RecordScreenPathName);
  266. }
  267. catch (Exception ex)
  268. {
  269. LogHelper.WriteErrLog("【录屏】(BtnRecordingScreen_Click)无法移除视频," + ex.Message, ex);
  270. }
  271. }
  272. else
  273. {
  274. return;
  275. }
  276. }
  277. if (APP.W_ScreenRecordingToolbarWindow == null)
  278. {
  279. APP.W_ScreenRecordingToolbarWindow = new ScreenRecordingToolbarWindow
  280. {
  281. Topmost = true
  282. };
  283. APP.W_ScreenRecordingToolbarWindow.Initialize();
  284. }
  285. else
  286. {
  287. APP.W_ScreenRecordingToolbarWindow.Initialize();
  288. }
  289. //显示在右下角
  290. APP.W_ScreenRecordingToolbarWindow.WindowStartupLocation = WindowStartupLocation.Manual;
  291. APP.W_ScreenRecordingToolbarWindow.Left = PrimaryScreen.DESKTOP.Width - APP.W_ScreenRecordingToolbarWindow.Width - 60;
  292. APP.W_ScreenRecordingToolbarWindow.Top = PrimaryScreen.DESKTOP.Height - APP.W_ScreenRecordingToolbarWindow.Height - 30;
  293. APP.W_ScreenRecordingToolbarWindow.Topmost = true;
  294. APP.W_ScreenRecordingToolbarWindow.Show();
  295. Hide();
  296. TxbRecordScreenWord.Text = "已录屏";
  297. }
  298. /// <summary>
  299. /// 上传事件
  300. /// </summary>
  301. /// <param name="sender"></param>
  302. /// <param name="e"></param>
  303. private void BtnUpload_Click(object sender, RoutedEventArgs e)
  304. {
  305. if (APP.IsLoginType == false)
  306. {
  307. Login();
  308. return;
  309. }
  310. if(APP.fileDirectoryWindow==null)
  311. {
  312. APP.fileDirectoryWindow = new FileDirectoryWindow();
  313. //APP.fileDirectoryWindow.Topmost = true;
  314. APP.fileDirectoryWindow.Owner = this;
  315. }
  316. else
  317. {
  318. APP.fileDirectoryWindow.Initialize();
  319. }
  320. APP.fileDirectoryWindow.ShowDialog();
  321. }
  322. /// <summary>
  323. /// 关闭事件
  324. /// </summary>
  325. /// <param name="sender"></param>
  326. /// <param name="e"></param>
  327. private void BtnDown_Click(object sender, RoutedEventArgs e)
  328. {
  329. if (IsFirstR)
  330. {
  331. APP.Killffmpeg();
  332. APP.SaveWkData();
  333. APP.SaveDraw();
  334. Thread.Sleep(100);
  335. System.Environment.Exit(0);
  336. }
  337. else
  338. {
  339. MessageBoxResult dr = System.Windows.MessageBox.Show("当前正在录制,是否停止录制?", "提示", MessageBoxButton.OKCancel);
  340. if (dr == MessageBoxResult.OK)
  341. {
  342. APP.SaveWkData();
  343. APP.SaveDraw();
  344. BtnStop_Click(null, null);
  345. while (!IsFirstR)
  346. {
  347. Thread.Sleep(100);
  348. }
  349. System.Environment.Exit(0);
  350. }
  351. else
  352. {
  353. return;
  354. }
  355. }
  356. }
  357. /// <summary>
  358. /// 设置 保存事件
  359. /// </summary>
  360. /// <param name="sender"></param>
  361. /// <param name="e"></param>
  362. private void BtnSave_Click(object sender, RoutedEventArgs e)
  363. {
  364. //#region 合法性判断
  365. //if (string.IsNullOrWhiteSpace(txbStoragePath.Text.Trim()))
  366. //{
  367. // System.Windows.MessageBox.Show("路径不可为空!");
  368. // return;
  369. //}
  370. //string temp = FileToolsCommon.GetLegalPath(txbStoragePath.Text) + APP.WKData.WkName.Trim() + "/";
  371. //if (!APP.WKData.WkPath.Equals(temp))
  372. //{
  373. // APP.WKData.WkPath = FileToolsCommon.GetLegalPath(txbStoragePath.Text) + APP.WKData.WkName.Trim() + "/";
  374. // if (FileToolsCommon.IsExistDirectory(APP.WKData.WkPath))
  375. // {
  376. // //微课已存在
  377. // MessageBoxResult dr = System.Windows.MessageBox.Show("讲解已存在是否覆盖?", "提示", MessageBoxButton.OKCancel);
  378. // if (dr == MessageBoxResult.OK)
  379. // {
  380. // FileToolsCommon.DeleteDirectory(APP.WKData.WkPath);
  381. // }
  382. // else
  383. // {
  384. // return;
  385. // }
  386. // }
  387. // //创建文件夹
  388. // FileToolsCommon.CreateDirectory(APP.WKData.WkPath);
  389. //}
  390. //#endregion
  391. if (rbnMP4.IsChecked == true)
  392. {
  393. //存储文件
  394. FileToolsCommon.SetConfigValue("VideoType", "1");
  395. }
  396. else if (rbnFLV.IsChecked == true)
  397. {
  398. FileToolsCommon.SetConfigValue("VideoType", "2");
  399. }
  400. else
  401. {
  402. FileToolsCommon.SetConfigValue("VideoType", "3");
  403. }
  404. if (rbnY.IsChecked == true)
  405. {
  406. FileToolsCommon.SetConfigValue("IsSound", "true");
  407. }
  408. else
  409. {
  410. FileToolsCommon.SetConfigValue("IsSound", "false");
  411. }
  412. /// < !--摄像头位置 1.右上 2.左上 3.右下 4.左下-- >
  413. if (rbnRight.IsChecked == true)
  414. {
  415. FileToolsCommon.SetConfigValue("CameraPosition", "1");
  416. }
  417. else if (rbnLeft.IsChecked == true)
  418. {
  419. FileToolsCommon.SetConfigValue("CameraPosition", "2");
  420. }
  421. else if (rbnRightUnder.IsChecked == true)
  422. {
  423. FileToolsCommon.SetConfigValue("CameraPosition", "3");
  424. }
  425. else if (rbnLeftUnder.IsChecked == true)
  426. {
  427. FileToolsCommon.SetConfigValue("CameraPosition", "4");
  428. }
  429. APP.CameraPosition = FileToolsCommon.GetConfigValue("CameraPosition");
  430. GridMain.Visibility = Visibility.Visible;
  431. gridSetUp.Visibility = Visibility.Collapsed;
  432. imgPlayerRight.Visibility = Visibility.Collapsed;
  433. imgPlayerLeft.Visibility = Visibility.Collapsed;
  434. imgPlayerRightUnder.Visibility = Visibility.Collapsed;
  435. imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
  436. }
  437. /// <summary>
  438. /// 设置事件
  439. /// </summary>
  440. /// <param name="sender"></param>
  441. /// <param name="e"></param>
  442. private void BtnSetUp_Click(object sender, RoutedEventArgs e)
  443. {
  444. if (APP.IsLoginType == false)
  445. {
  446. Login();
  447. return;
  448. }
  449. if (!TxbRecordingWord.Text.Equals("暂停"))
  450. {
  451. GridMain.Visibility = Visibility.Collapsed;
  452. gridSetUp.Visibility = Visibility.Visible;
  453. txbStoragePath.Content = APP.WKData.WkPath;
  454. /// < !--摄像头位置 1.右上 2.左上 3.右下 4.左下-- >
  455. if ("1".Equals(APP.CameraPosition))
  456. {
  457. rbnRight.IsChecked = true;
  458. }
  459. else if ("2".Equals(APP.CameraPosition))
  460. {
  461. rbnLeft.IsChecked = true;
  462. }
  463. else if ("3".Equals(APP.CameraPosition))
  464. {
  465. rbnRightUnder.IsChecked = true;
  466. }
  467. else if ("4".Equals(APP.CameraPosition))
  468. {
  469. rbnLeftUnder.IsChecked = true;
  470. }
  471. }
  472. }
  473. /// <summary>
  474. /// 设置 浏览事件
  475. /// </summary>
  476. /// <param name="sender"></param>
  477. /// <param name="e"></param>
  478. private void BtnBrowse_Click(object sender, RoutedEventArgs e)
  479. {
  480. System.Diagnostics.Process.Start(APP.WKData.WkPath);
  481. //string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
  482. //Ofd = new System.Windows.Forms.FolderBrowserDialog();
  483. //Result = Ofd.ShowDialog();
  484. //if (Result == System.Windows.Forms.DialogResult.OK)
  485. //{
  486. // if (Ofd.SelectedPath != "")
  487. // {
  488. // //txbStoragePath.Text = Ofd.SelectedPath;
  489. // //string ApplicationData = ZConfig.dataPath + "fileStorageAddress.txt";
  490. // //string temp = ofd.SelectedPath;
  491. // //System.IO.File.WriteAllText(ApplicationData, temp, Encoding.Default);
  492. // }
  493. //}
  494. }
  495. /// <summary>
  496. /// 画笔颜色事件 白色
  497. /// </summary>
  498. /// <param name="sender"></param>
  499. /// <param name="e"></param>
  500. private void BtnWhite_Click(object sender, RoutedEventArgs e)
  501. {
  502. ////创建 DrawingAttributes 类的一个实例
  503. //drawingAttributes = new DrawingAttributes();
  504. ////将 InkCanvas 的 DefaultDrawingAttributes 属性的值赋成创建的 DrawingAttributes 类的对象的引用
  505. ////InkCanvas 通过 DefaultDrawingAttributes 属性来获取墨迹的各种设置,该属性的类型为 DrawingAttributes 型
  506. //blackboard_canvas.DefaultDrawingAttributes = drawingAttributes;
  507. ////设置 DrawingAttributes 的 Color 属性设置颜色
  508. drawingAttributes.Color = Colors.White;
  509. Color = Colors.White;
  510. }
  511. /// <summary>
  512. /// 画笔颜色事件 红色
  513. /// </summary>
  514. /// <param name="sender"></param>
  515. /// <param name="e"></param>
  516. private void BtnRed_Click(object sender, RoutedEventArgs e)
  517. {
  518. //设置 DrawingAttributes 的 Color 属性设置颜色
  519. drawingAttributes.Color = Colors.Red;
  520. Color = Colors.Red;
  521. }
  522. /// <summary>
  523. /// 画笔颜色事件 灰色
  524. /// </summary>
  525. /// <param name="sender"></param>
  526. /// <param name="e"></param>
  527. private void BtnGray_Click(object sender, RoutedEventArgs e)
  528. {
  529. drawingAttributes.Color = Colors.Gray;
  530. Color = Colors.Gray;
  531. }
  532. /// <summary>
  533. /// 画笔颜色事件 青色
  534. /// </summary>
  535. /// <param name="sender"></param>
  536. /// <param name="e"></param>
  537. private void BtnCyanBlue_Click(object sender, RoutedEventArgs e)
  538. {
  539. drawingAttributes.Color = Colors.LimeGreen;
  540. Color = Colors.LimeGreen;
  541. }
  542. /// <summary>
  543. /// 画笔颜色事件 黄色
  544. /// </summary>
  545. /// <param name="sender"></param>
  546. /// <param name="e"></param>
  547. private void BtnYellow_Click(object sender, RoutedEventArgs e)
  548. {
  549. drawingAttributes.Color = Colors.Gold;
  550. Color = Colors.Gold;
  551. }
  552. /// <summary>
  553. /// 画笔颜色事件 蓝色
  554. /// </summary>
  555. /// <param name="sender"></param>
  556. /// <param name="e"></param>
  557. private void BtnBlue_Click(object sender, RoutedEventArgs e)
  558. {
  559. drawingAttributes.Color = Colors.DeepSkyBlue;
  560. Color = Colors.DeepSkyBlue;
  561. }
  562. /// <summary>
  563. /// 画笔粗细事件 细
  564. /// </summary>
  565. /// <param name="sender"></param>
  566. /// <param name="e"></param>
  567. private void RbnFine_Click(object sender, RoutedEventArgs e)
  568. {
  569. drawingAttributes.Width = 1;
  570. drawingAttributes.Height = 1;
  571. Size = 1;
  572. }
  573. /// <summary>
  574. /// 画笔粗细事件 中
  575. /// </summary>
  576. /// <param name="sender"></param>
  577. /// <param name="e"></param>
  578. private void RbnIn_Click(object sender, RoutedEventArgs e)
  579. {
  580. drawingAttributes.Width = 3;
  581. drawingAttributes.Height = 3;
  582. Size = 3;
  583. }
  584. /// <summary>
  585. /// 画笔粗细事件 粗
  586. /// </summary>
  587. /// <param name="sender"></param>
  588. /// <param name="e"></param>
  589. private void RbnCrude_Click(object sender, RoutedEventArgs e)
  590. {
  591. drawingAttributes.Width = 5;
  592. drawingAttributes.Height = 5;
  593. Size = 5;
  594. }
  595. /// <summary>
  596. /// 登陆事件
  597. /// </summary>
  598. /// <param name="sender"></param>
  599. /// <param name="e"></param>
  600. private void BtnLoginType_Click(object sender, RoutedEventArgs e)
  601. {
  602. Login();
  603. }
  604. /// <summary>
  605. /// 登陆
  606. /// </summary>
  607. private void Login()
  608. {
  609. if (APP.W_LoginWindow == null)
  610. {
  611. APP.W_LoginWindow = new LoginWindow();
  612. APP.W_LoginWindow.WindowStartupLocation = WindowStartupLocation.CenterOwner;
  613. APP.W_LoginWindow.Owner = this;
  614. }
  615. else
  616. {
  617. APP.W_LoginWindow.Initialize();
  618. }
  619. APP.W_LoginWindow.ShowDialog();
  620. if (APP.IsLoginType)
  621. {
  622. txbLoginType.Text = APP.UserInfo.Username;
  623. ImgMyMine.Visibility = Visibility.Visible;
  624. ImgMyMineTwo.Visibility = Visibility.Collapsed;
  625. ImgUpload.Visibility = Visibility.Visible;
  626. ImgUploadTwo.Visibility = Visibility.Collapsed;
  627. }
  628. else
  629. {
  630. txbLoginType.Text = "未登录";
  631. ImgMyMine.Visibility = Visibility.Collapsed;
  632. ImgMyMineTwo.Visibility = Visibility.Visible;
  633. ImgUpload.Visibility = Visibility.Collapsed;
  634. ImgUploadTwo.Visibility = Visibility.Visible;
  635. }
  636. }
  637. /// <summary>
  638. /// 截图事件
  639. /// </summary>
  640. /// <param name="sender"></param>
  641. /// <param name="e"></param>
  642. private void BtnScreenshot_Click(object sender, RoutedEventArgs e)
  643. {
  644. if (APP.IsLoginType == false)
  645. {
  646. Login();
  647. return;
  648. }
  649. string time = GetTimeStamp();
  650. string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + time + ".jpg";
  651. ImageHelper.GetScreenshot(new System.Drawing.Rectangle(0, 0, 0, 0), desktopPath);
  652. if (APP.W_JieTuWindow != null)
  653. {
  654. APP.W_JieTuWindow.initialization();
  655. APP.W_JieTuWindow.Screenshot();
  656. APP.W_JieTuWindow.WindowState = WindowState.Maximized;
  657. APP.W_JieTuWindow.Visibility = Visibility.Visible;
  658. }
  659. else
  660. {
  661. APP.W_JieTuWindow = new JieTuWindow();
  662. // 订阅事件
  663. APP.W_JieTuWindow.ChangeTextEvent += new ChangeTextHandler(frm_ChangeTextEvent);
  664. APP.W_JieTuWindow.click_closeJietuWindowClick += JietuWindow_click_closeJietuWindowClick;
  665. APP.W_JieTuWindow.Show();
  666. }
  667. //imgCanvas.Source = new BitmapImage(new Uri(desktopPath));
  668. }
  669. /// <summary>
  670. /// 截图关闭窗口
  671. /// </summary>
  672. /// <param name="text"></param>
  673. private void frm_ChangeTextEvent(string text)
  674. {
  675. if ("关闭窗口".Equals(text))
  676. {
  677. if (!string.IsNullOrWhiteSpace(APP.ImgPath) && File.Exists(APP.ImgPath))
  678. {
  679. //APP.JPaths[APP.pageData.currpage]= APP.ImgPath;
  680. //APP.JPaths[APP.pageData.currpage] = APP.ImgPath;
  681. if (APP.PageDrawList.Count >= APP.pageData.currpage)
  682. {
  683. APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath = APP.ImgPath;//zxycs
  684. APP.PageDrawList[APP.pageData.currpage - 1].PdfImagePath = APP.ImgPath;
  685. }
  686. else
  687. {
  688. Model_DrawData model_DrawData = new Model_DrawData();
  689. model_DrawData.PageImagePath = APP.ImgPath;
  690. model_DrawData.PdfImagePath = APP.ImgPath;
  691. APP.PageDrawList.Add(model_DrawData);
  692. }
  693. //if (!string.IsNullOrWhiteSpace(APP.JPaths[APP.pageData.currpage]))
  694. //{
  695. // //imgCanvas.Source = new BitmapImage(new Uri(APP.JPaths[APP.pageData.currpage]));
  696. // imgCanvas.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage-1].PageImagePath));
  697. //}
  698. if (APP.PageDrawList.Count >= APP.pageData.currpage && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath))
  699. {
  700. //imgCanvas.Source = new BitmapImage(new Uri(APP.JPaths[APP.pageData.currpage]));
  701. imgDocumentation.Source = null;
  702. imgCanvas.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  703. //btnOk.Visibility = Visibility.Visible;
  704. //blackboard_canvas.Visibility = Visibility.Collapsed;
  705. APP.PageDrawList[APP.pageData.currpage - 1].ImgDocumentation = false;
  706. ImgPrint.Visibility = Visibility.Visible;//截图成功可打印
  707. ImgPrintTwo.Visibility = Visibility.Collapsed;
  708. btnPrint.IsEnabled = true;
  709. }
  710. }
  711. }
  712. }
  713. /// <summary>
  714. /// 截图关闭 非正常关闭截图时,截图清空
  715. /// </summary>
  716. private void JietuWindow_click_closeJietuWindowClick()
  717. {
  718. APP.W_JieTuWindow = null;
  719. }
  720. /// <summary>
  721. /// 获取时间戳
  722. /// </summary>
  723. /// <returns></returns>
  724. public string GetTimeStamp()
  725. {
  726. TimeSpan ts = DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0);
  727. return Convert.ToInt64(ts.TotalSeconds).ToString();
  728. }
  729. /// <summary>
  730. /// 导入事件
  731. /// </summary>
  732. /// <param name="sender"></param>
  733. /// <param name="e"></param>
  734. private void BtnImport_Click(object sender, RoutedEventArgs e)
  735. {
  736. if (APP.IsLoginType == false)
  737. {
  738. Login();
  739. return;
  740. }
  741. try
  742. {
  743. string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
  744. ofd = new System.Windows.Forms.OpenFileDialog
  745. {
  746. Filter = "文档|*.docx;*.doc;*ppt",
  747. InitialDirectory = desktopPath,
  748. Multiselect = false,
  749. AddExtension = true,
  750. DereferenceLinks = true
  751. };
  752. new Thread(
  753. o =>
  754. {
  755. Thread.Sleep(400);
  756. Dispatcher.Invoke(new Action(() =>
  757. {
  758. OpenDialog();
  759. }
  760. ));
  761. })
  762. {
  763. IsBackground = true
  764. }.Start();
  765. }
  766. catch (Exception ex)
  767. {
  768. LogHelper.WriteErrLog("【导入(BtnImport_Click)" + ex.Message, ex);
  769. }
  770. }
  771. /// <summary>
  772. /// 导入文档
  773. /// </summary>
  774. private void OpenDialog()
  775. {
  776. result = ofd.ShowDialog();
  777. if (result == System.Windows.Forms.DialogResult.OK)
  778. {
  779. if (ofd.FileName != "")
  780. {
  781. #region PPT转PDF
  782. string filepath = ofd.FileName;
  783. string path = ofd.SafeFileName.Replace(".ppt", "").Trim();
  784. string type = ofd.SafeFileName.Replace(".ppt", "typezsygppt").Trim();
  785. if (type.Contains("typezsygppt"))//ppt
  786. {
  787. try
  788. {
  789. string pathTemp = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  790. path = pathTemp + path + ".pdf";
  791. //PPT转PDF
  792. Presentation ppt = new Presentation(filepath);
  793. ppt.Save(path, Aspose.Slides.Export.SaveFormat.Pdf);
  794. #endregion
  795. #region PDF转图片
  796. // 图片绝对路径集合
  797. List<string> images = new List<string>();
  798. string directoryPath = pathTemp;
  799. //aspose许可证
  800. //Aspose.Pdf.License l = new Aspose.Pdf.License();
  801. //string licenseName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Aspose.Total.Product.Family.lic");
  802. //l.SetLicense(licenseName);
  803. //定义Jpeg转换设备
  804. Aspose.Pdf.Document document = new Aspose.Pdf.Document(path);
  805. var device = new Aspose.Pdf.Devices.JpegDevice();
  806. //int quality = int.Parse(this.comboBox1.SelectedItem.ToString());
  807. //directoryPath += quality;
  808. Directory.CreateDirectory(directoryPath);
  809. //默认质量为100,设置质量的好坏与处理速度不成正比,甚至是设置的质量越低反而花的时间越长,怀疑处理过程是先生成高质量的再压缩
  810. device = new Aspose.Pdf.Devices.JpegDevice(100);
  811. //遍历每一页转为jpg
  812. for (var i = 1; i <= document.Pages.Count; i++)
  813. {
  814. long ii = Timestamp();
  815. string filePathOutPut = Path.Combine(directoryPath, string.Format("{0}{1}.jpg", ii, i));
  816. images.Add(filePathOutPut);
  817. FileStream fs = new FileStream(filePathOutPut, FileMode.OpenOrCreate);
  818. try
  819. {
  820. device.Process(document.Pages[i], fs);
  821. fs.Close();
  822. }
  823. catch (Exception ex)
  824. {
  825. fs.Close();
  826. File.Delete(filePathOutPut);
  827. }
  828. }
  829. #endregion
  830. //APP.Paths = images.ToArray();
  831. //ImgPDFPath = images.ToArray();
  832. string[] page = images.ToArray();
  833. if(page.Length>0)
  834. {
  835. APP.PageDrawList = null;
  836. APP.PageDrawList = new List<Model_DrawData>();
  837. }
  838. for (int i = 0; i < page.Length; i++)//给画板模型加图片路径
  839. {
  840. if (APP.PageDrawList != null && APP.PageDrawList.Count > i)
  841. {
  842. APP.PageDrawList[i].PageImagePath = page[i]; //zxycs
  843. APP.PageDrawList[i].PdfImagePath = page[i];
  844. APP.PageDrawList[i].PageNum = i + 1;
  845. APP.PageDrawList[i].ImgDocumentation = true;
  846. }
  847. else
  848. {
  849. Model_DrawData model_DrawData = new Model_DrawData();
  850. model_DrawData.PageImagePath = page[i];
  851. model_DrawData.PdfImagePath = page[i];
  852. model_DrawData.PageNum = i + 1;
  853. model_DrawData.ImgDocumentation = true;
  854. APP.PageDrawList.Add(model_DrawData);
  855. }
  856. ImgPrint.Visibility = Visibility.Visible;//导入成功可打印
  857. ImgPrintTwo.Visibility = Visibility.Collapsed;
  858. btnPrint.IsEnabled = true;
  859. APP.SaveDraw();
  860. }
  861. myblackboard.clear();
  862. APP.pageData.pagenum = 1;
  863. APP.pageData.currpage = 1;
  864. for (int i = 0; i < APP.PageDrawList.Count; i++)
  865. {
  866. APP.pageData.pagenum += 1;
  867. }
  868. if (APP.pageData.pagenum > 1)
  869. {
  870. APP.pageData.pagenum -= 1;
  871. }
  872. if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage < APP.PageDrawList.Count)
  873. {
  874. //imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage - 1]));//cs
  875. imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));//给当前页面展示图片
  876. imgCanvas.Source = null;
  877. }
  878. else
  879. {
  880. imgDocumentation.Source = null;
  881. imgCanvas.Source = null;
  882. }
  883. }
  884. catch (Exception ex)
  885. {
  886. LogHelper.WriteErrLog("【XHMicroLessonSystemWindow】(OpenDialog PPT)" + ex.Message, ex);
  887. }
  888. }
  889. else//word
  890. {
  891. try
  892. {
  893. string paths = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  894. string[] page = ConvertWordToImage(filepath, paths, "", 0, 0, null, 0).ToArray();
  895. //APP.Paths = page;//cs
  896. //ImgPDFPath = page;
  897. if (page.Length > 0)
  898. {
  899. APP.PageDrawList = null;
  900. APP.PageDrawList = new List<Model_DrawData>();
  901. }
  902. for (int i = 0; i < page.Length; i++)//给画板模型加图片路径
  903. {
  904. if (APP.PageDrawList!=null&&APP.PageDrawList.Count > i)
  905. {
  906. APP.PageDrawList[i].PageImagePath = page[i]; //zxycs
  907. APP.PageDrawList[i].PdfImagePath = page[i];
  908. APP.PageDrawList[i].PageNum = i + 1;
  909. APP.PageDrawList[i].ImgDocumentation = true;
  910. }
  911. else
  912. {
  913. Model_DrawData model_DrawData = new Model_DrawData();
  914. model_DrawData.PageImagePath = page[i];
  915. model_DrawData.PdfImagePath = page[i];
  916. model_DrawData.PageNum = i + 1;
  917. model_DrawData.ImgDocumentation = true;
  918. APP.PageDrawList.Add(model_DrawData);
  919. }
  920. ImgPrint.Visibility = Visibility.Visible;//导入成功可打印
  921. ImgPrintTwo.Visibility = Visibility.Collapsed;
  922. btnPrint.IsEnabled = true;
  923. APP.SaveDraw();
  924. }
  925. APP.pageData.pagenum = 1;
  926. APP.pageData.currpage = 1;
  927. //myblackboard.clear();
  928. for (int i = 0; i < APP.PageDrawList.Count; i++)
  929. {
  930. APP.pageData.pagenum += 1;
  931. }
  932. if (APP.pageData.pagenum > 1)
  933. {
  934. APP.pageData.pagenum -= 1;
  935. }
  936. if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage < APP.PageDrawList.Count)
  937. {
  938. //imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage - 1]));//cs
  939. imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));//给当前页面展示图片
  940. imgCanvas.Source = null;
  941. }
  942. else
  943. {
  944. imgDocumentation.Source = null;
  945. imgCanvas.Source = null;
  946. }
  947. }
  948. catch (Exception ex)
  949. {
  950. LogHelper.WriteErrLog("【XHMicroLessonSystemWindow】(OpenDialog PDF)" + ex.Message, ex);
  951. }
  952. }
  953. }
  954. }
  955. }
  956. /// <summary>
  957. /// 返回一个时间戳到毫秒
  958. /// </summary>
  959. /// <returns></returns>
  960. public static long Timestamp()
  961. {
  962. TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
  963. long timestr = Convert.ToInt64(ts.TotalMilliseconds);
  964. return timestr;
  965. }
  966. #region 录制窗口
  967. #region 变量
  968. /// <summary>
  969. /// 视频保存路径
  970. /// </summary>
  971. string RecordingPath;
  972. /// <summary>
  973. /// 图片保存路径
  974. /// </summary>
  975. string ImgPath;
  976. /// <summary>
  977. /// 音频保存路径名
  978. /// </summary>
  979. string AudioPathName;
  980. /// <summary>
  981. /// 视频保存路径名
  982. /// </summary>
  983. string VideoSavePathName;
  984. /// <summary>
  985. /// 暂停录制
  986. /// </summary>
  987. bool IsSuspendR = true;
  988. /// <summary>
  989. /// 录制是否已停止
  990. /// </summary>
  991. bool IsFirstR = true;
  992. /// <summary>
  993. /// 图片
  994. /// </summary>
  995. List<string> RsImgName = null;
  996. /// <summary>
  997. /// 是否开始截图计数
  998. /// </summary>
  999. bool IsStartCount = false;
  1000. #endregion
  1001. /// <summary>
  1002. /// 录制窗口内容
  1003. /// </summary>
  1004. /// <param name="sender"></param>
  1005. /// <param name="e"></param>
  1006. private void BtnRecord_Click(object sender, RoutedEventArgs e)
  1007. {
  1008. if (APP.IsLoginType == false)
  1009. {
  1010. Login();
  1011. return;
  1012. }
  1013. blackboard_canvas.Visibility = Visibility.Visible;
  1014. StartRecord();
  1015. }
  1016. /// <summary>
  1017. /// 停止录制窗口内容
  1018. /// </summary>
  1019. /// <param name="sender"></param>
  1020. /// <param name="e"></param>
  1021. private void BtnStop_Click(object sender, RoutedEventArgs e)
  1022. {
  1023. if (APP.IsLoginType == false)
  1024. {
  1025. Login();
  1026. return;
  1027. }
  1028. blackboard_canvas.Visibility = Visibility.Collapsed;
  1029. EndRecord();
  1030. }
  1031. System.Timers.Timer timer;
  1032. /// <summary>
  1033. /// 开始录制和暂停录制
  1034. /// </summary>
  1035. void StartRecord()
  1036. {
  1037. if (IsSuspendR)
  1038. {
  1039. if (IsFirstR)//是否第一次录制 初始化录制
  1040. {
  1041. VideoInfo = new Model_Video();
  1042. VideoInfo.VideoType = (Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType"));
  1043. VideoInfo.WkType = Enum_WKVidetype.RecordingLessons;
  1044. RecordingPath = APP.WKData.WkPath;
  1045. ImgPath = APP.WKData.WkPath + "temp/Image/";
  1046. AudioPathName = APP.WKData.WkPath + "temp/audio/";
  1047. FileToolsCommon.DeleteDirectory(APP.WKData.WkPath + "temp/");
  1048. FileToolsCommon.CreateDirectory(RecordingPath);
  1049. FileToolsCommon.CreateDirectory(ImgPath);
  1050. FileToolsCommon.CreateDirectory(AudioPathName);
  1051. AudioPathName += APP.WKData.WkName + ".MP3";
  1052. VideoSavePathName = RecordingPath + APP.WKData.WkName + "_录制." + VideoInfo.VideoType.ToString();
  1053. if (FileToolsCommon.IsExistFile(VideoSavePathName))
  1054. {
  1055. MessageBoxResult dr = System.Windows.MessageBox.Show("课程已录制,是否覆盖?", "提示", MessageBoxButton.OKCancel);
  1056. if (dr == MessageBoxResult.OK)
  1057. {
  1058. try
  1059. {
  1060. FileToolsCommon.DeleteFile(VideoSavePathName);
  1061. APP.VideoList.RemoveAll(x => x.VideoPath == VideoSavePathName);
  1062. }
  1063. catch (Exception ex)
  1064. {
  1065. LogHelper.WriteErrLog("【录制】(StartRecord)无法移除视频," + ex.Message, ex);
  1066. }
  1067. }
  1068. else
  1069. {
  1070. return;
  1071. }
  1072. }
  1073. #region 禁用按钮
  1074. ImgPrint.Visibility = Visibility.Collapsed;//录制中不可打印
  1075. ImgPrintTwo.Visibility = Visibility.Visible;
  1076. btnPrint.IsEnabled = false;
  1077. ImgScreenshot.Visibility = Visibility.Collapsed;//录制中不可截图
  1078. ImgScreenshotTwo.Visibility = Visibility.Visible;
  1079. btnScreenshot.IsEnabled = false;
  1080. ImgImport.Visibility = Visibility.Collapsed;//录制中不可导入文档
  1081. ImgImportTwo.Visibility = Visibility.Visible;
  1082. btnImport.IsEnabled = false;
  1083. ImgScreenRecording.Visibility = Visibility.Collapsed;//录制中不可录屏
  1084. ImgScreenRecordingTwo.Visibility = Visibility.Visible;
  1085. btnScreenRecording.IsEnabled = false;
  1086. ImgUpload.Visibility = Visibility.Collapsed;//录制中不可上传
  1087. ImgUploadTwo.Visibility = Visibility.Visible;
  1088. btnUpload.IsEnabled = false;
  1089. ImgMyMine.Visibility = Visibility.Collapsed;//录制中不可点击我的
  1090. ImgMyMineTwo.Visibility = Visibility.Visible;
  1091. btnMyMine.IsEnabled = false;
  1092. ImgSetUp.Visibility = Visibility.Collapsed;//录制中不可设置
  1093. ImgSetUpTwo.Visibility = Visibility.Visible;
  1094. btnSetUp.IsEnabled = false;
  1095. btnLoginType.IsEnabled = false;
  1096. #endregion
  1097. IsFirstR = false;
  1098. RsImgName = new List<string>();
  1099. timer = new System.Timers.Timer(200);//设置执行一次(false)还是一直执行(true)
  1100. timer.AutoReset = true;//设置是否执行System.Timers.Timer.Elapsed事件
  1101. timer.Elapsed += new System.Timers.ElapsedEventHandler(Timer_Elapsed);
  1102. timer.Enabled = true; //启动计时器
  1103. }
  1104. #region 录像倒计时
  1105. if (APP.W_CountdownWindow == null)
  1106. {
  1107. APP.W_CountdownWindow = new CountdownWindow();
  1108. //APP.W_CountdownWindow.Topmost = true;
  1109. }
  1110. else
  1111. {
  1112. APP.W_CountdownWindow.Initialize();
  1113. APP.W_CountdownWindow.Topmost = true;
  1114. }
  1115. APP.W_CountdownWindow.Show();
  1116. #endregion
  1117. //继续录制
  1118. IsSuspendR = false;
  1119. //BtnRecording.Content = "暂停录制";
  1120. ImgRecord.Source = new BitmapImage(new Uri("pack://application:,,,/Images/microLessonSystem_23.png"));
  1121. TxbRecordingWord.Text = "暂停";
  1122. try
  1123. {
  1124. APP.FFmpeg.StartRecordingAudio(AudioPathName);
  1125. new Thread(new ThreadStart(new Action(() =>
  1126. {
  1127. Thread.Sleep(1000);
  1128. Dispatcher.Invoke(() =>
  1129. {
  1130. IsStartCount = true;
  1131. //timer.Start();
  1132. });
  1133. }))).Start();
  1134. }
  1135. catch (Exception ex)
  1136. {
  1137. System.Windows.MessageBox.Show(ex.Message);
  1138. }
  1139. }
  1140. else
  1141. {
  1142. //暂停
  1143. IsSuspendR = true;
  1144. ImgRecord.Source = new BitmapImage(new Uri("pack://application:,,,/Images/microLessonSystem_14.png"));
  1145. TxbRecordingWord.Text = "继续";
  1146. try
  1147. {
  1148. APP.FFmpeg.SuspendFFmpeg();
  1149. new Thread(new ThreadStart(new Action(() =>
  1150. {
  1151. while (APP.FFmpeg.myProcess != null)
  1152. {
  1153. Thread.Sleep(100);
  1154. }
  1155. IsStartCount = false;
  1156. }))).Start();
  1157. }
  1158. catch (Exception ex)
  1159. {
  1160. System.Windows.MessageBox.Show(ex.Message);
  1161. }
  1162. }
  1163. }
  1164. /// <summary>
  1165. /// 录制保存图片
  1166. /// </summary>
  1167. /// <param name="sender"></param>
  1168. /// <param name="e"></param>
  1169. private void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
  1170. {
  1171. if (IsStartCount)
  1172. {
  1173. try
  1174. {
  1175. Dispatcher.Invoke(() =>
  1176. {
  1177. string FilePathName = ImgPath + RsImgName.Count + ".png";
  1178. ImageHelper.SaveUIToImage(GridMain, FilePathName, (int)this.ActualWidth, (int)this.ActualHeight);
  1179. RsImgName.Add(FilePathName);
  1180. });
  1181. }
  1182. catch (Exception ex)
  1183. {
  1184. LogHelper.WriteErrLog("【录制】(Timer_Elapsed)生成图片错误:" + ex.Message, ex);
  1185. }
  1186. }
  1187. }
  1188. /// <summary>
  1189. /// 停止录制并生成录制文件
  1190. /// </summary>
  1191. void EndRecord()
  1192. {
  1193. if (!IsFirstR)
  1194. {
  1195. ImgPrint.Visibility = Visibility.Visible;
  1196. ImgPrintTwo.Visibility = Visibility.Collapsed;
  1197. btnPrint.IsEnabled = true;
  1198. ImgScreenshot.Visibility = Visibility.Visible;
  1199. ImgScreenshotTwo.Visibility = Visibility.Collapsed;
  1200. btnScreenshot.IsEnabled = true;
  1201. ImgImport.Visibility = Visibility.Visible;
  1202. ImgImportTwo.Visibility = Visibility.Collapsed;
  1203. btnImport.IsEnabled = true;
  1204. ImgScreenRecording.Visibility = Visibility.Visible;
  1205. ImgScreenRecordingTwo.Visibility = Visibility.Collapsed;
  1206. btnScreenRecording.IsEnabled = true;
  1207. ImgUpload.Visibility = Visibility.Visible;
  1208. ImgUploadTwo.Visibility = Visibility.Collapsed;
  1209. btnUpload.IsEnabled = true;
  1210. ImgMyMine.Visibility = Visibility.Visible;
  1211. ImgMyMineTwo.Visibility = Visibility.Collapsed;
  1212. btnMyMine.IsEnabled = true;
  1213. ImgSetUp.Visibility = Visibility.Visible;
  1214. ImgSetUpTwo.Visibility = Visibility.Collapsed;
  1215. btnSetUp.IsEnabled = true;
  1216. btnLoginType.IsEnabled = true;
  1217. IsSuspendR = true;
  1218. ImgRecord.Source = new BitmapImage(new Uri("pack://application:,,,/Images/microLessonSystem_14.png"));
  1219. TxbRecordingWord.Text = "已录制";
  1220. try
  1221. {
  1222. APP.FFmpeg.StopFFmpeg(AudioPathName);
  1223. new Thread(new ThreadStart(new Action(() =>
  1224. {
  1225. while (APP.FFmpeg.myProcess != null)
  1226. {
  1227. Thread.Sleep(100);
  1228. }
  1229. Dispatcher.Invoke(() =>
  1230. {
  1231. IsStartCount = false;
  1232. timer.Stop();
  1233. });
  1234. }))).Start();
  1235. new Thread(new ThreadStart(new Action(() =>
  1236. {
  1237. while (APP.FFmpeg.myProcess != null)
  1238. {
  1239. Thread.Sleep(100);
  1240. }
  1241. }))).Start();
  1242. APP.FFmpeg.SynthesisVideo(ImgPath, AudioPathName, VideoSavePathName, 5, (int)GridMain.Width, (int)GridMain.Height);
  1243. //生成缩略图
  1244. string ThumbnailPath = FileToolsCommon.GetDirectoryName(VideoSavePathName) + "ThumbnailPath/";
  1245. FileToolsCommon.CreateDirectory(ThumbnailPath);
  1246. //缩略图存储位置
  1247. string ThumbnailPathName = ThumbnailPath + FileToolsCommon.GetIOFileNameNoExtension(VideoSavePathName) + ".JPG";
  1248. new Thread(new ThreadStart(new Action(() =>
  1249. {
  1250. while (!FileToolsCommon.IsExistFile(VideoSavePathName))
  1251. {
  1252. Thread.Sleep(100);
  1253. }
  1254. FileToolsCommon.DeleteFile(ThumbnailPathName);
  1255. VideoInfo.RSTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  1256. //VideoInfo.VideoSize = FileToolsCommon.GetFileSizeByMB(VideoSavePathName).ToString() + " MB";
  1257. VideoInfo.VideoPath = VideoSavePathName;
  1258. VideoInfo.ThumbnailPath = ThumbnailPathName;
  1259. APP.FFmpeg.GenerateThumbnails(VideoSavePathName, ThumbnailPathName);
  1260. VideoInfo.FileGuid = Guid.NewGuid().ToString();
  1261. VideoInfo.IsUpload = false;
  1262. VideoInfo.Uploaded = 0;
  1263. VideoInfo.Savefolder = APP.UserInfo.Schoolid + "/resource";
  1264. APP.VideoList.Add(VideoInfo);
  1265. //保存数据
  1266. APP.SaveWkData();
  1267. IsFirstR = true;
  1268. }))).Start();
  1269. //List<Model_Video> VideoList
  1270. }
  1271. catch (Exception ex)
  1272. {
  1273. System.Windows.MessageBox.Show(ex.Message);
  1274. }
  1275. }
  1276. }
  1277. #endregion
  1278. /// <summary>
  1279. /// 增加事件
  1280. /// </summary>
  1281. /// <param name="sender"></param>
  1282. /// <param name="e"></param>
  1283. private void BtnAdd_Click(object sender, RoutedEventArgs e)
  1284. {
  1285. if (APP.IsLoginType == false)
  1286. {
  1287. Login();
  1288. return;
  1289. }
  1290. if (APP.pageData.pagenum < 200)
  1291. {
  1292. if (APP.PageDrawList != null && APP.PageDrawList.Count > 0 && APP.PageDrawList.Count > APP.pageData.currpage - 1
  1293. && APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation != null)
  1294. {
  1295. APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = true;
  1296. }
  1297. APP.pageData.pagenum += 1;
  1298. APP.pageData.currpage = APP.pageData.pagenum;
  1299. myblackboard.changepage(APP.pageData.currpage - 1);
  1300. imgCanvas.Source = null;
  1301. Model_DrawData model_DrawData = new Model_DrawData();
  1302. model_DrawData.PageNum = APP.pageData.currpage;
  1303. APP.PageDrawList.Add(model_DrawData);
  1304. APP.SaveDraw();//画板模型增加一页
  1305. }
  1306. else
  1307. {
  1308. System.Windows.Forms.MessageBox.Show("已达到最大页数无法继续增加!");
  1309. }
  1310. }
  1311. /// <summary>
  1312. /// 打印事件
  1313. /// </summary>
  1314. /// <param name="sender"></param>
  1315. /// <param name="e"></param>
  1316. private void BtnPrint_Click(object sender, RoutedEventArgs e)
  1317. {
  1318. if (APP.IsLoginType == false)
  1319. {
  1320. Login();
  1321. return;
  1322. }
  1323. //for(int i=0;i< APP.pageData.pagenum; i++)
  1324. //{
  1325. //}
  1326. ////string[] files = { @"C:\101\1.jpg", @"C:\101\2.jpg" };
  1327. try
  1328. {
  1329. iTextSharp.text.Document document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 25, 25, 25, 25);
  1330. //iTextSharp.text.Rectangle page = new iTextSharp.text.Rectangle(iTextSharp.text.PageSize.A4., 250f);//cs
  1331. ////设置纸张横向
  1332. //document.SetPageSize(iTextSharp.text.PageSize.A4.Rotate());
  1333. string imgPath = FileToolsCommon.GetFileAbsolutePath("temp");
  1334. FileToolsCommon.CreateFile(imgPath);
  1335. imgPath += "\\101.pdf";
  1336. iTextSharp.text.pdf.PdfWriter.GetInstance(document, new FileStream(imgPath, FileMode.Create, FileAccess.ReadWrite));
  1337. document.Open();
  1338. iTextSharp.text.Image image;
  1339. for (int i = 0; i < APP.PageDrawList.Count; i++)
  1340. {
  1341. if (String.IsNullOrEmpty(APP.PageDrawList[i].PdfImagePath)) break;
  1342. image = iTextSharp.text.Image.GetInstance(APP.PageDrawList[i].PdfImagePath);
  1343. if (image.Height > iTextSharp.text.PageSize.A4.Height - 25)
  1344. {
  1345. image.ScaleToFit(iTextSharp.text.PageSize.A4.Width - 25, iTextSharp.text.PageSize.A4.Height - 25);
  1346. }
  1347. else if (image.Width > iTextSharp.text.PageSize.A4.Width - 25)
  1348. {
  1349. image.ScaleToFit(iTextSharp.text.PageSize.A4.Width - 25, iTextSharp.text.PageSize.A4.Height - 25);
  1350. }
  1351. image.Alignment = iTextSharp.text.Image.ALIGN_MIDDLE;
  1352. document.NewPage();
  1353. document.Add(image);
  1354. //iTextSharp.text.Chunk c1 = new iTextSharp.text.Chunk("Hello World");
  1355. //iTextSharp.text.Phrase p1 = new iTextSharp.text.Phrase();
  1356. //p1.Leading = 150; //行间距
  1357. //document.Add(p1);
  1358. }
  1359. Console.WriteLine("转换成功!");
  1360. document.Close();
  1361. }
  1362. catch (Exception ex)
  1363. {
  1364. Console.WriteLine("转换失败,原因:" + ex.Message);
  1365. }
  1366. //document.Close();
  1367. ////Console.ReadKey();
  1368. if (APP.W_PrintWindow == null)
  1369. {
  1370. APP.W_PrintWindow = new PrintWindow();
  1371. APP.W_PrintWindow.Topmost = true;
  1372. APP.W_PrintWindow.Owner = this;
  1373. }
  1374. if (APP.PageDrawList.Count > 0 && !string.IsNullOrWhiteSpace(APP.PageDrawList[0].PdfImagePath))
  1375. {
  1376. APP.W_PrintWindow.Initialize(APP.PageDrawList[0].PdfImagePath);
  1377. }
  1378. else
  1379. {
  1380. APP.W_PrintWindow.Initialize("");
  1381. }
  1382. APP.W_PrintWindow.ShowDialog();
  1383. //int pr = 1;
  1384. //string msg = string.Empty;
  1385. //string outPut = string.Empty;
  1386. //LatticeFileHelper.GeneratingPDF(@"G:\101.pdf", @"G:\102.TPF",out pr, out msg, out outPut);
  1387. //if(pr==0)
  1388. //{
  1389. // outPut = outPut.Replace("[", "").Replace("]","").Replace("\"","").Trim();
  1390. // APP.OutPut = outPut.Split(',');
  1391. // string defa = string.Empty;
  1392. // List<string>defaList= LatticeFileHelper.GetPrinterList(out defa);
  1393. // int printResult = 1;
  1394. // string standardError = string.Empty;
  1395. // string standardOutput = string.Empty;
  1396. // LatticeFileHelper.PrinterTPFFile(@"G:\102.TPF",1, /*defa*/"导出为WPS PDF", out printResult,out standardError,out standardOutput);
  1397. //}
  1398. }
  1399. /// <summary>
  1400. /// 我的
  1401. /// </summary>
  1402. /// <param name="sender"></param>
  1403. /// <param name="e"></param>
  1404. private void BtnMyMine_Click(object sender, RoutedEventArgs e)
  1405. {
  1406. if (APP.IsLoginType == false)
  1407. {
  1408. Login();
  1409. return;
  1410. }
  1411. }
  1412. /// <summary>
  1413. /// 上一页
  1414. /// </summary>
  1415. /// <param name="sender"></param>
  1416. /// <param name="e"></param>
  1417. private void last_button_Click(object sender, RoutedEventArgs e)
  1418. {
  1419. if (APP.pageData.currpage > 1)
  1420. {
  1421. try
  1422. {
  1423. Dispatcher.Invoke(() =>
  1424. {
  1425. string filePath = FileToolsCommon.GetFileAbsolutePath("/Data/" + APP.UserInfo.Username + "/pdfimagetemp/");
  1426. FileToolsCommon.CreateDirectory(filePath);
  1427. string filePathName = filePath + APP.pageData.currpage.ToString() + ".jpg";
  1428. ImageHelper.SaveUIToImage(GridMain, filePathName, (int)GridMain.ActualWidth, (int)GridMain.ActualHeight);
  1429. //ImgPDFPath[APP.pageData.currpage - 1] = filePathName;
  1430. APP.PageDrawList[APP.pageData.currpage - 1].PdfImagePath = filePathName;
  1431. });
  1432. }
  1433. catch (Exception ex)
  1434. {
  1435. LogHelper.WriteErrLog("【XHMicroLessonSystemWindow】(last_button_Click)生成图片错误:" + ex.Message, ex);
  1436. }
  1437. APP.pageData.currpage -= 1;
  1438. myblackboard.changepage(APP.pageData.currpage - 1);
  1439. if (APP.pageData.currpage <= APP.PageDrawList.Count)
  1440. {
  1441. if (APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation != null)
  1442. {
  1443. APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = true;
  1444. }
  1445. if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage <= APP.PageDrawList.Count && APP.pageData.currpage > 0 && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath))
  1446. {
  1447. //imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage - 1]));//cs
  1448. if (APP.PageDrawList[APP.pageData.currpage - 1].ImgDocumentation)
  1449. {
  1450. imgCanvas.Source = null;
  1451. imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  1452. }
  1453. else
  1454. {
  1455. imgDocumentation.Source = null;
  1456. imgCanvas.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  1457. if (APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation != null && APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.X > 0)
  1458. {
  1459. var group = IMG.FindResource("Imageview") as TransformGroup;
  1460. var transform = group.Children[1] as TranslateTransform;
  1461. //if (APP.PageDrawList[APP.pageData.currpage - 1].ImageSize != null)
  1462. //{
  1463. // var transform1 = group.Children[0] as ScaleTransform;
  1464. // transform1.ScaleX = APP.PageDrawList[APP.pageData.currpage - 1].ImageSize.ScaleX;
  1465. // transform1.ScaleY = APP.PageDrawList[APP.pageData.currpage - 1].ImageSize.ScaleY;
  1466. //}
  1467. //var position = e.GetPosition(img);
  1468. transform.X = APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.X;
  1469. transform.Y = APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.Y;
  1470. mouseDown = false;
  1471. }
  1472. }
  1473. }
  1474. else
  1475. {
  1476. imgCanvas.Source = null;
  1477. imgDocumentation.Source = null;
  1478. }
  1479. }
  1480. //if (!string.IsNullOrWhiteSpace(APP.JPaths[APP.pageData.currpage]))
  1481. //{
  1482. // imgCanvas.Source = new BitmapImage(new Uri(APP.JPaths[APP.pageData.currpage]));
  1483. //}
  1484. }
  1485. }
  1486. /// <summary>
  1487. /// 下一页
  1488. /// </summary>
  1489. /// <param name="sender"></param>
  1490. /// <param name="e"></param>
  1491. private void next_btn_Click(object sender, RoutedEventArgs e)
  1492. {
  1493. if (APP.pageData.currpage < APP.pageData.pagenum)
  1494. {
  1495. try
  1496. {
  1497. Dispatcher.Invoke(() =>
  1498. {
  1499. string filePath = FileToolsCommon.GetFileAbsolutePath("/Data/" + APP.UserInfo.Username + "/pdfimagetemp/");
  1500. FileToolsCommon.CreateDirectory(filePath);
  1501. string filePathName = filePath + APP.pageData.currpage.ToString() + ".jpg";
  1502. ImageHelper.SaveUIToImage(GridMain, filePathName, (int)GridMain.ActualWidth, (int)GridMain.ActualHeight);
  1503. //ImgPDFPath[APP.pageData.currpage - 1] = filePathName;
  1504. APP.PageDrawList[APP.pageData.currpage - 1].PdfImagePath = filePathName;
  1505. });
  1506. }
  1507. catch (Exception ex)
  1508. {
  1509. LogHelper.WriteErrLog("【XHMicroLessonSystemWindow】(next_btn_Click)生成图片错误:" + ex.Message, ex);
  1510. }
  1511. APP.pageData.currpage += 1;
  1512. myblackboard.changepage(APP.pageData.currpage - 1);
  1513. if (APP.pageData.currpage <= APP.PageDrawList.Count)
  1514. {
  1515. if (APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation != null)
  1516. {
  1517. APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = true;
  1518. }
  1519. if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage <= APP.PageDrawList.Count && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath))
  1520. {
  1521. if(APP.PageDrawList[APP.pageData.currpage - 1].ImgDocumentation)
  1522. {
  1523. imgCanvas.Source = null;
  1524. imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  1525. }
  1526. else
  1527. {
  1528. //imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage-1]));
  1529. imgDocumentation.Source = null;
  1530. imgCanvas.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  1531. if (APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation != null && APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.X > 0)
  1532. {
  1533. var group = IMG.FindResource("Imageview") as TransformGroup;
  1534. //if (APP.PageDrawList[APP.pageData.currpage - 1].ImageSize != null)
  1535. //{
  1536. // var transform1 = group.Children[0] as ScaleTransform;
  1537. // transform1.ScaleX = APP.PageDrawList[APP.pageData.currpage - 1].ImageSize.ScaleX;
  1538. // transform1.ScaleY = APP.PageDrawList[APP.pageData.currpage - 1].ImageSize.ScaleY;
  1539. //}
  1540. var transform = group.Children[1] as TranslateTransform;
  1541. //var position = e.GetPosition(img);
  1542. transform.X = APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.X;
  1543. transform.Y = APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.Y;
  1544. mouseDown = false;
  1545. }
  1546. }
  1547. }
  1548. else
  1549. {
  1550. imgCanvas.Source = null;
  1551. imgDocumentation.Source = null;
  1552. }
  1553. }
  1554. //if (!string.IsNullOrWhiteSpace(APP.JPaths[APP.pageData.currpage]))
  1555. //{
  1556. // imgCanvas.Source = new BitmapImage(new Uri(APP.JPaths[APP.pageData.currpage]));
  1557. //}
  1558. }
  1559. }
  1560. /// <summary>
  1561. /// 将Word文档转换为图片的方法(该方法基于第三方DLL),你可以像这样调用该方法: ConvertPDF2Image("F:\\PdfFile.doc", "F:\\",
  1562. /// "ImageFile", 1, 20, ImageFormat.Png, 256);
  1563. /// </summary>
  1564. /// <param name="pdfInputPath">Word文件路径</param>
  1565. /// <param name="imageOutputPath">图片输出路径,如果为空,默认值为Word所在路径</param>
  1566. /// <param name="imageName">图片的名字,不需要带扩展名,如果为空,默认值为Word的名称</param>
  1567. /// <param name="startPageNum">从PDF文档的第几页开始转换,如果为0,默认值为1</param>
  1568. /// <param name="endPageNum">从PDF文档的第几页开始停止转换,如果为0,默认值为Word总页数</param>
  1569. /// <param name="imageFormat">设置所需图片格式,如果为null,默认格式为PNG</param>
  1570. /// <param name="resolution">设置图片的像素,数字越大越清晰,如果为0,默认值为128,建议最大值不要超过1024</param>
  1571. public List<string> ConvertWordToImage(string wordInputPath, string imageOutputPath,
  1572. string imageName, int startPageNum, int endPageNum, ImageFormat imageFormat, float resolution)
  1573. {
  1574. // 返回的图片绝对路径集合
  1575. List<string> images = new List<string>();
  1576. try
  1577. {
  1578. // open word file
  1579. Aspose.Words.Document doc = new Aspose.Words.Document(wordInputPath);
  1580. // validate parameter
  1581. if (doc == null) { throw new Exception("Word文件无效或者Word文件被加密!"); }
  1582. if (imageOutputPath.Trim().Length == 0) { imageOutputPath = System.IO.Path.GetDirectoryName(wordInputPath); }
  1583. if (!Directory.Exists(imageOutputPath)) { Directory.CreateDirectory(imageOutputPath); }
  1584. if (imageName.Trim().Length == 0) { imageName = System.IO.Path.GetFileNameWithoutExtension(wordInputPath); }
  1585. if (startPageNum <= 0) { startPageNum = 1; }
  1586. if (endPageNum > doc.PageCount || endPageNum <= 0) { endPageNum = doc.PageCount; }
  1587. if (startPageNum > endPageNum) { int tempPageNum = startPageNum; startPageNum = endPageNum; endPageNum = startPageNum; }
  1588. if (imageFormat == null) { imageFormat = ImageFormat.Png; }
  1589. if (resolution <= 0) { resolution = 128; }
  1590. ImageSaveOptions imageSaveOptions = new ImageSaveOptions(GetSaveFormat(imageFormat))
  1591. {
  1592. Resolution = resolution
  1593. };
  1594. // start to convert each page
  1595. for (int i = startPageNum; i <= endPageNum; i++)
  1596. {
  1597. imageSaveOptions.PageIndex = i - 1;
  1598. doc.Save(System.IO.Path.Combine(imageOutputPath, imageName) + "_" + APP.num.ToString() + "." + imageFormat.ToString(), imageSaveOptions);
  1599. images.Add(System.IO.Path.Combine(imageOutputPath, imageName) + "_" + APP.num.ToString() + "." + imageFormat.ToString());
  1600. APP.num++;
  1601. }
  1602. imageSaveOptions = null;
  1603. doc = null;
  1604. }
  1605. catch (Exception ex)
  1606. {
  1607. System.Windows.MessageBox.Show("文档已打开,请关闭后重试!");
  1608. LogHelper.WriteErrLog("【课堂考试(ExamWindow)】错误日志:" + ex.Message, ex);
  1609. }
  1610. return images;
  1611. }
  1612. private static SaveFormat GetSaveFormat(ImageFormat imageFormat)
  1613. {
  1614. SaveFormat sf;// = SaveFormat.Unknown;
  1615. if (imageFormat.Equals(ImageFormat.Png))
  1616. {
  1617. sf = SaveFormat.Png;
  1618. }
  1619. else if (imageFormat.Equals(ImageFormat.Jpeg))
  1620. {
  1621. sf = SaveFormat.Jpeg;
  1622. }
  1623. else if (imageFormat.Equals(ImageFormat.Tiff))
  1624. {
  1625. sf = SaveFormat.Tiff;
  1626. }
  1627. else if (imageFormat.Equals(ImageFormat.Bmp))
  1628. {
  1629. sf = SaveFormat.Bmp;
  1630. }
  1631. else
  1632. {
  1633. sf = SaveFormat.Unknown;
  1634. }
  1635. return sf;
  1636. }
  1637. #region 图像缩放,移动
  1638. private bool mouseDown;
  1639. private System.Windows.Point mouseXY;
  1640. private void IMG1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  1641. {
  1642. var img = sender as ContentControl;
  1643. if (img == null)
  1644. {
  1645. return;
  1646. }
  1647. img.CaptureMouse();
  1648. mouseDown = true;
  1649. mouseXY = e.GetPosition(img);
  1650. Console.WriteLine("mouseXY.X = " + mouseXY.X + "; mouseXY.Y = " + mouseXY.Y);
  1651. }
  1652. private void PicEMap_MouseDown(object sender, MouseButtonEventArgs e)
  1653. {
  1654. System.Windows.Point point = e.GetPosition(imgCanvas);
  1655. //Console.WriteLine("PicEmap.X = " + point.X + "; PicEmap.Y = " + point.Y);
  1656. //if ((point.X - 304) * (point.X - 304) + (point.Y - 86) * (point.Y - 86) < 100)
  1657. //{
  1658. // Console.WriteLine("在范围内");
  1659. //}
  1660. }
  1661. private void IMG1_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  1662. {
  1663. var img = sender as ContentControl;
  1664. if (img == null)
  1665. {
  1666. return;
  1667. }
  1668. img.ReleaseMouseCapture();
  1669. mouseDown = false;
  1670. }
  1671. private void IMG1_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
  1672. {
  1673. var img = sender as ContentControl;
  1674. if (img == null)
  1675. {
  1676. return;
  1677. }
  1678. if (mouseDown)
  1679. {
  1680. Domousemove(img, e);
  1681. }
  1682. }
  1683. /// <summary>
  1684. /// x y轴
  1685. /// </summary>
  1686. /// <param name="img"></param>
  1687. /// <param name="e"></param>
  1688. private void Domousemove(ContentControl img, System.Windows.Input.MouseEventArgs e)
  1689. {
  1690. if (e.LeftButton != MouseButtonState.Pressed)
  1691. {
  1692. return;
  1693. }
  1694. if (APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation != null && APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation)
  1695. {
  1696. return;
  1697. }
  1698. var group = IMG.FindResource("Imageview") as TransformGroup;
  1699. var transform = group.Children[1] as TranslateTransform;
  1700. var position = e.GetPosition(img);
  1701. transform.X -= mouseXY.X - position.X;
  1702. transform.Y -= mouseXY.Y - position.Y;
  1703. mouseXY = position;
  1704. APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation = new TranslateTransform();
  1705. APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.X = transform.X;
  1706. APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.Y = transform.Y;
  1707. //APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = false;
  1708. }
  1709. private void IMG1_MouseWheel(object sender, MouseWheelEventArgs e)
  1710. {
  1711. var img = sender as ContentControl;
  1712. if (img == null)
  1713. {
  1714. return;
  1715. }
  1716. var point = e.GetPosition(img);
  1717. Console.WriteLine("point.X = " + point.X + "; point.Y=" + point.Y);
  1718. var PicLocate = e.GetPosition(imgCanvas);
  1719. Console.WriteLine("PicEmap.X = " + PicLocate.X + "; PicEmap.Y=" + PicLocate.Y);
  1720. var group = IMG.FindResource("Imageview") as TransformGroup;
  1721. var delta = e.Delta * 0.001;
  1722. DowheelZoom(group, point, delta);
  1723. }
  1724. private void DowheelZoom(TransformGroup group, System.Windows.Point point, double delta)
  1725. {
  1726. var pointToContent = group.Inverse.Transform(point);
  1727. var transform = group.Children[0] as ScaleTransform;
  1728. if (transform.ScaleX + delta < 0.1) return;
  1729. transform.ScaleX += delta;
  1730. transform.ScaleY += delta;
  1731. var transform1 = group.Children[1] as TranslateTransform;
  1732. transform1.X = -1 * ((pointToContent.X * transform.ScaleX) - point.X);
  1733. transform1.Y = -1 * ((pointToContent.Y * transform.ScaleY) - point.Y);
  1734. //Console.WriteLine("transform.ScaleX = " + transform.ScaleX + "; transform.ScaleY = " + transform.ScaleY);
  1735. //APP.PageDrawList[APP.pageData.currpage - 1].ImageSize = new ScaleTransform();
  1736. //APP.PageDrawList[APP.pageData.currpage - 1].ImageSize.ScaleX = transform.ScaleX;
  1737. //APP.PageDrawList[APP.pageData.currpage - 1].ImageSize.ScaleY = transform.ScaleY;
  1738. //APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation = new TranslateTransform();
  1739. //APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.X = transform1.X;
  1740. //APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.Y = transform1.Y;
  1741. //APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = false;
  1742. }
  1743. #endregion
  1744. #region 点阵笔相关
  1745. #region 值初始化
  1746. // 不同尺寸点阵纸点阵宽高尺寸计算方法为:纸张物理尺寸(毫米)/0.3 *8,详见 开发必读.pdf 文档
  1747. /// <summary>
  1748. /// A4点阵纸点阵宽度
  1749. /// </summary>
  1750. private const int A4_WIDTH = 5600;
  1751. /// <summary>
  1752. /// A4点阵纸点阵高度
  1753. /// </summary>
  1754. private const int A4_HEIGHT = 7920;
  1755. /// <summary>
  1756. /// 画板
  1757. /// </summary>
  1758. private Graphics graphics;
  1759. /// <summary>
  1760. /// 笔画坐标数组
  1761. /// </summary>
  1762. private List<System.Drawing.Point> stroke;
  1763. /// <summary>
  1764. /// 笔序列号
  1765. /// </summary>
  1766. private string penSerial;
  1767. /// <summary>
  1768. /// 笔是否在点
  1769. /// </summary>
  1770. private bool isPenDown;
  1771. //当前点阵地址
  1772. private string currentPageSerial = string.Empty;
  1773. //不同点阵地址对应的笔迹绘制图片,用于实现在不同点阵地址书写切换时,显示书写内容自动切换
  1774. //本例图片放在内存中存储,对于大量或者需要在多个点阵地址对应图片进行切换演示,建议将图片存储到文件,以免内存溢出
  1775. private Dictionary<string, System.Drawing.Image> pagesDic = new Dictionary<string, System.Drawing.Image>();
  1776. #endregion
  1777. public void InitPen()
  1778. {
  1779. stroke = new List<System.Drawing.Point>();
  1780. //获取点阵笔实例,并绑定点阵笔事件
  1781. //将授权文件内容传入,获取点阵笔对象实例
  1782. APP.digitalPen = DigitalPenHID.GetInstance(certificates.MyLicense.Bytes);
  1783. //绑定笔连接事件
  1784. APP.digitalPen.PenConnected += OnPenConnect;
  1785. //绑定笔断开事件
  1786. APP.digitalPen.PenDisconnect += OnPenDisconnect;
  1787. //绑定笔书写输出坐标事件
  1788. APP.digitalPen.PenCoordinate += OnPenCoordinate;
  1789. //绑定抬笔事件
  1790. APP.digitalPen.PenUp += OnPenUp;
  1791. //绑定落笔事件
  1792. APP.digitalPen.PenDown += OnPenDown;
  1793. APP.digitalPen.PenBatteryCapacity += OnBatteryCapacity;
  1794. APP.digitalPen.PenMemoryFillLevel += OnMemoryFillLevel;
  1795. //完成初始化点阵笔,开始与点阵笔通信
  1796. ERROR_CODE ER = APP.digitalPen.Start();
  1797. ////绑定笔在新的点阵地址页面书写事件
  1798. //APP.digitalPen.PenNewPage += APP.digitalPen_OnPenNewPage;
  1799. ////绑定笔信息事件
  1800. //APP.digitalPen.PenInfo += APP.digitalPen_OnPenInfo;
  1801. //启动接收笔数据,完成初始化工作
  1802. ERROR_CODE rc = APP.digitalPen.Start();
  1803. //判断是否成功
  1804. if (ER != ERROR_CODE.ERROR_OK)
  1805. {
  1806. System.Windows.MessageBox.Show("初始化失败,授权过期,返回值:" + ER.ToString());
  1807. }
  1808. }
  1809. /// <summary>
  1810. /// 落笔
  1811. /// </summary>
  1812. /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
  1813. /// <param name="penSerial">点阵笔序列号</param>
  1814. /// <param name="penType">点阵笔型号编号</param>
  1815. private void OnPenDown(ulong time, string penSerial, int penType)
  1816. {
  1817. if (this.CheckAccess())
  1818. {
  1819. Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenDown);
  1820. this.Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
  1821. }
  1822. else
  1823. {
  1824. //labPenSerial.Text = penSerial;
  1825. //labPenStatus.Text = "PenDown";
  1826. isPenDown = true;
  1827. Dispatcher.Invoke(new Action(() =>
  1828. {
  1829. for (int i = 0; i < APP.PageDrawList.Count; i++)
  1830. {
  1831. if (APP.PageDrawList[i].PageCode == penSerial)
  1832. {
  1833. if (i < APP.pageData.pagenum)
  1834. {
  1835. if (i < APP.pageData.currpage)
  1836. {
  1837. int num = APP.pageData.currpage - i;
  1838. APP.pageData.currpage -= num;
  1839. myblackboard.changepage(APP.pageData.currpage - 1);
  1840. if (APP.PageDrawList.Count > 0)
  1841. {
  1842. if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage <= APP.PageDrawList.Count && APP.pageData.currpage > 0 && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath))
  1843. {
  1844. //imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage - 1]));//cs
  1845. imgCanvas.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  1846. }
  1847. else
  1848. {
  1849. imgCanvas.Source = null;
  1850. }
  1851. }
  1852. }
  1853. else
  1854. {
  1855. int num = i - APP.pageData.currpage;
  1856. APP.pageData.currpage += num;
  1857. myblackboard.changepage(APP.pageData.currpage - 1);
  1858. if (APP.PageDrawList.Count > 0)
  1859. {
  1860. if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage <= APP.PageDrawList.Count && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath))
  1861. {
  1862. //imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage-1]));
  1863. imgCanvas.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  1864. }
  1865. else
  1866. {
  1867. imgCanvas.Source = null;
  1868. }
  1869. }
  1870. }
  1871. }
  1872. return;
  1873. }
  1874. }
  1875. //myblackboard.changepages(0, 0, true);
  1876. //myblackboard.changepaget(0, 0, true, blackboard_canvas);
  1877. }));
  1878. }
  1879. //myblackboard.changepages(0, 0, true);
  1880. }
  1881. /// <summary>
  1882. /// 抬笔
  1883. /// </summary>
  1884. /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
  1885. /// <param name="penSerial">点阵笔序列号</param>
  1886. /// <param name="penType">点阵笔型号编号</param>
  1887. private void OnPenUp(ulong time, string penSerial, int penType)
  1888. {
  1889. if (this.CheckAccess())
  1890. {
  1891. Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenUp);
  1892. this.Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
  1893. }
  1894. else
  1895. {
  1896. isPenDown = false;
  1897. APP.PenSerial = penSerial;
  1898. //int leftPoints = stroke.Count % 3;
  1899. //if (0 != leftPoints)
  1900. //{
  1901. // int from = stroke.Count - leftPoints - 1;
  1902. // if (from < 0)
  1903. // from = 0;
  1904. // int to = stroke.Count - 1;
  1905. // DrawCoordinates(from, to);
  1906. //}
  1907. stroke.Clear();
  1908. }
  1909. Dispatcher.Invoke(new Action(() =>
  1910. {
  1911. //myblackboard.changepages(0, 0, true);
  1912. myblackboard.changepages(0, 0, true, Color, Size);
  1913. }));
  1914. }
  1915. /// <summary>
  1916. /// 笔断开
  1917. /// </summary>
  1918. /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
  1919. /// <param name="penSerial">点阵笔序列号</param>
  1920. /// <param name="penType">点阵笔型号编号</param>
  1921. private void OnPenDisconnect(ulong time, string penSerial, int penType)
  1922. {
  1923. if (this.CheckAccess())
  1924. {
  1925. Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenDisconnect);
  1926. this.Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
  1927. }
  1928. else
  1929. {
  1930. APP.PenSerial = penSerial;
  1931. APP.PenStatus = false;
  1932. Dispatcher.Invoke(new Action(() =>
  1933. {
  1934. txbNotConnected.Text = "未连接";
  1935. txbNotConnecteds.Text = "未连接";
  1936. }));
  1937. }
  1938. }
  1939. /// <summary>
  1940. /// 笔连接
  1941. /// </summary>
  1942. /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
  1943. /// <param name="penSerial">点阵笔序列号</param>
  1944. /// <param name="penType">点阵笔型号编号</param>
  1945. private void OnPenConnect(ulong time, string penSerial, int penType)
  1946. {
  1947. if (this.CheckAccess())
  1948. {
  1949. Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenConnect);
  1950. this.Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
  1951. }
  1952. else
  1953. {
  1954. APP.PenSerial = penSerial;
  1955. APP.PenStatus = true;
  1956. this.penSerial = penSerial;
  1957. //连接后,在获取笔数据前,可以清除笔内的历史数据
  1958. //APP.digitalPen.ClearMemory(penSerial);
  1959. //开始接收笔数据
  1960. APP.digitalPen.GetPenData(penSerial);
  1961. Dispatcher.Invoke(new Action(() =>
  1962. {
  1963. txbNotConnected.Text = "已连接";
  1964. txbNotConnecteds.Text = "已连接";
  1965. }));
  1966. }
  1967. }
  1968. /// <summary>
  1969. /// 电池电量
  1970. /// </summary>
  1971. /// <param name="time"></param>
  1972. /// <param name="penSerial"></param>
  1973. /// <param name="penType"></param>
  1974. /// <param name="capacity"></param>
  1975. private void OnBatteryCapacity(ulong time, string penSerial, int penType, byte capacity)
  1976. {
  1977. if (this.CheckAccess())
  1978. {
  1979. Action<ulong, string, int, byte> action = new Action<ulong, string, int, byte>(OnBatteryCapacity);
  1980. this.Dispatcher.Invoke(action, new object[] { time, penSerial, penType, capacity });
  1981. }
  1982. else
  1983. {
  1984. //System.Windows.MessageBox.Show("电池电量:" + capacity.ToString());
  1985. }
  1986. }
  1987. /// <summary>
  1988. /// 已用存储
  1989. /// </summary>
  1990. /// <param name="time"></param>
  1991. /// <param name="penSerial"></param>
  1992. /// <param name="penType"></param>
  1993. /// <param name="fillLevel"></param>
  1994. private void OnMemoryFillLevel(ulong time, string penSerial, int penType, byte fillLevel)
  1995. {
  1996. if (this.CheckAccess())
  1997. {
  1998. Action<ulong, string, int, byte> action = new Action<ulong, string, int, byte>(OnMemoryFillLevel);
  1999. this.Dispatcher.Invoke(action, new object[] { time, penSerial, penType, fillLevel });
  2000. }
  2001. else
  2002. {
  2003. //System.Windows.MessageBox.Show("存储:" + fillLevel.ToString());
  2004. }
  2005. }
  2006. /// <summary>
  2007. /// 笔书写,收到坐标
  2008. /// </summary>
  2009. /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
  2010. /// <param name="penSerial">点阵笔序列号</param>
  2011. /// <param name="penType">点阵笔型号编号</param>
  2012. /// <param name="pageSerial">点阵地址</param>
  2013. /// <param name="cx">x坐标</param>
  2014. /// <param name="cy">y坐标</param>
  2015. /// <param name="force">压力值</param>
  2016. private void OnPenCoordinate(ulong time, string penSerial, int penType, string pageSerial, int cx, int cy, byte force)
  2017. {
  2018. if (this.CheckAccess())
  2019. {
  2020. Action<ulong, string, int, string, int, int, byte> ac = new Action<ulong, string, int, string, int, int, byte>(OnPenCoordinate);
  2021. this.Dispatcher.Invoke(ac, new object[] { time, pageSerial, penType, pageSerial, cx, cy, force });
  2022. }
  2023. else
  2024. {
  2025. //判断是否是落笔后输出的坐标,在设置悬浮模式下,落笔前的悬浮坐标不绘制
  2026. if (!isPenDown)
  2027. {
  2028. return;
  2029. }
  2030. stroke.Add(new System.Drawing.Point(cx, cy));
  2031. double PropW = blackboard_canvas.ActualWidth / A4_WIDTH;
  2032. double PropH = blackboard_canvas.ActualHeight / A4_HEIGHT;
  2033. //点
  2034. double testX = (double)cx * PropW;
  2035. double testY = (double)cy * PropH;
  2036. //pageSerial //点阵IP地址 与打印的页面关联
  2037. Dispatcher.Invoke(new Action(() =>
  2038. {
  2039. //myblackboard.changepages(testX, testY,false);
  2040. myblackboard.changepages(testX, testY, false, Color, Size);
  2041. }));
  2042. ////每3个点画一条曲线
  2043. //if (stroke.Count % 3 == 0)
  2044. //{
  2045. // int from = stroke.Count - 3 - 1;
  2046. // if (from < 0)
  2047. // from = 0;
  2048. // int to = stroke.Count - 1;
  2049. // DrawCoordinates(from, to);
  2050. //}
  2051. }
  2052. }
  2053. /// <summary>
  2054. /// 停止笔
  2055. /// </summary>
  2056. public void StopDigitalPen()
  2057. {
  2058. //停止,释放资源
  2059. APP.digitalPen.Stop();
  2060. }
  2061. /// <summary>
  2062. /// 清空笔内存储
  2063. /// </summary>
  2064. public void ClearPenStorage()
  2065. {
  2066. if (!string.IsNullOrEmpty(penSerial))
  2067. APP.digitalPen.ClearMemory(penSerial);
  2068. }
  2069. /// <summary>
  2070. /// 获取剩余电量
  2071. /// </summary>
  2072. public void GetPenElectricityQuantity()
  2073. {
  2074. if (!string.IsNullOrEmpty(penSerial))
  2075. APP.digitalPen.GetBatteryCapacity(penSerial);
  2076. }
  2077. /// <summary>
  2078. /// 获取存储空间
  2079. /// </summary>
  2080. public void GetUsedStorage()
  2081. {
  2082. if (!string.IsNullOrEmpty(penSerial))
  2083. APP.digitalPen.GetMemoryFillLevel(penSerial);
  2084. }
  2085. /// <summary>
  2086. /// 开启悬浮
  2087. /// </summary>
  2088. public void 开启悬浮()
  2089. {
  2090. if (!string.IsNullOrEmpty(penSerial))
  2091. APP.digitalPen.SetPenHoverMode(true, penSerial);
  2092. }
  2093. /// <summary>
  2094. /// 关闭悬浮
  2095. /// </summary>
  2096. public void 关闭悬浮()
  2097. {
  2098. if (!string.IsNullOrEmpty(penSerial))
  2099. APP.digitalPen.SetPenHoverMode(false, penSerial);
  2100. }
  2101. #endregion
  2102. /// <summary>
  2103. /// 最小化
  2104. /// </summary>
  2105. /// <param name="sender"></param>
  2106. /// <param name="e"></param>
  2107. private void BtnShrink_Click(object sender, RoutedEventArgs e)
  2108. {
  2109. if (Visibility == Visibility.Hidden)
  2110. Visibility = Visibility.Visible;
  2111. else
  2112. Visibility = Visibility.Hidden;
  2113. }
  2114. /// <summary>
  2115. /// 位置确定
  2116. /// </summary>
  2117. /// <param name="sender"></param>
  2118. /// <param name="e"></param>
  2119. private void BtnOk_Click(object sender, RoutedEventArgs e)
  2120. {
  2121. //APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = true;
  2122. //btnOk.Visibility = Visibility.Collapsed;
  2123. //blackboard_canvas.Visibility = Visibility.Visible;
  2124. }
  2125. }
  2126. }