星火微课系统客户端
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

XHMicroLessonSystemWindow.xaml.cs 98KB

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