星火微课系统客户端
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

XHMicroLessonSystemWindow.xaml.cs 132KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135
  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. using XHWK.WKTool.Config;
  26. using System.Windows.Threading;
  27. using System.Diagnostics;
  28. namespace XHWK.WKTool
  29. {
  30. /// <summary>
  31. /// 主页面
  32. /// </summary>
  33. public partial class XHMicroLessonSystemWindow : Window
  34. {
  35. #region 字段
  36. /// <summary>
  37. /// 文件目录窗口
  38. /// </summary>
  39. //private CountdownWindow FileDirectoryWindows = null;
  40. private FolderBrowserDialog Ofd;
  41. private DialogResult Result;
  42. public readonly BlackboardNew myblackboard;
  43. private System.Windows.Forms.DialogResult result;
  44. private System.Windows.Forms.OpenFileDialog ofd;
  45. //声明一个 DrawingAttributes 类型的变量
  46. DrawingAttributes drawingAttributes;
  47. Model_Video VideoInfo = null;
  48. //定义事件
  49. public event ChangeTextHandler ChangeTextEvent;
  50. //定义委托
  51. public delegate void ChangeTextHandler(string text);
  52. /// <summary>
  53. /// 图片
  54. /// </summary>
  55. string[] ImgPDFPath = new string[300];
  56. /// <summary>
  57. /// 当前颜色
  58. /// </summary>
  59. private System.Windows.Media.Color Color = System.Windows.Media.Colors.Red;
  60. /// <summary>
  61. /// 笔迹粗细
  62. /// </summary>
  63. private int PenSize = 2;
  64. private DispatcherTimer t = null;
  65. /// <summary>
  66. /// 计时器状态
  67. /// </summary>
  68. private enum State
  69. {
  70. Start,
  71. Pause,
  72. End
  73. }
  74. /// <summary>
  75. /// 状态
  76. /// </summary>
  77. private State _state = State.End;
  78. /// <summary>
  79. /// 计时用
  80. /// </summary>
  81. private TimeSpan _timeSpan = new TimeSpan(0, 0, 0, 0, 0);
  82. #region 上传
  83. /// <summary>
  84. /// 视频模型
  85. /// </summary>
  86. List<Model_Video> model_VideoList = null;
  87. /// <summary>
  88. /// 数据列表
  89. /// </summary>
  90. internal FileDirectoryData pageData = new FileDirectoryData();
  91. /// <summary>
  92. /// 下标
  93. /// </summary>
  94. private int Subscript = 0;
  95. /// <summary>
  96. /// 是否是修改状态
  97. /// </summary>
  98. private bool IsModify = false;
  99. #endregion
  100. #endregion
  101. #region 初始化
  102. /// <summary>
  103. /// 主页面
  104. /// </summary>
  105. public XHMicroLessonSystemWindow()
  106. {
  107. 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=")));
  108. InitializeComponent();
  109. this.ResizeMode = System.Windows.ResizeMode.CanMinimize;
  110. btnPrint.IsEnabled = false;
  111. myblackboard = new BlackboardNew(blackboard_canvas);
  112. APP.pageData.pagenum = 0;
  113. APP.pageData.currpage = 0;
  114. DataContext = APP.pageData;
  115. //APP.SaveDraw();//画板模型第一页初始化
  116. APP.PageDrawList = new List<Model_DrawData>();
  117. Model_DrawData model_DrawData = new Model_DrawData();
  118. model_DrawData.PageNum = APP.pageData.currpage;
  119. APP.PageDrawList.Add(model_DrawData);
  120. txbv.Text = "v"+ZConfig.versionName;
  121. txbStoragePath.Content = FileToolsCommon.GetConfigValue("VideoType");
  122. if (FileToolsCommon.GetConfigValue("IsSound").Equals("true"))
  123. {
  124. rbnY.IsChecked = true;
  125. }
  126. else
  127. {
  128. rbnN.IsChecked = true;
  129. }
  130. txbStoragePath.Content = FileToolsCommon.GetConfigValue("VideoSavePath");
  131. Initialize();
  132. InitPen();
  133. }
  134. /// <summary>
  135. /// 初始化
  136. /// </summary>
  137. public void Initialize()
  138. {
  139. #region 数据初始化
  140. APP.pageData.pagenum = 0;
  141. APP.pageData.currpage = APP.pageData.pagenum;
  142. btnStop.IsEnabled = false;//停止录制按钮不可点击
  143. #endregion
  144. APP.CameraPosition = FileToolsCommon.GetConfigValue("CameraPosition");
  145. //创建 DrawingAttributes 类的一个实例
  146. drawingAttributes = new DrawingAttributes();
  147. //将 InkCanvas 的 DefaultDrawingAttributes 属性的值赋成创建的 DrawingAttributes 类的对象的引用
  148. //InkCanvas 通过 DefaultDrawingAttributes 属性来获取墨迹的各种设置,该属性的类型为 DrawingAttributes 型
  149. blackboard_canvas.DefaultDrawingAttributes = drawingAttributes;
  150. blackboard_canvas.UseCustomCursor = true;
  151. drawingAttributes.FitToCurve = true;
  152. drawingAttributes.IgnorePressure = false;
  153. drawingAttributes.Width = PenSize;
  154. drawingAttributes.Height = PenSize;
  155. drawingAttributes.Color = Color;
  156. blackboard_canvas.Cursor = System.Windows.Input.Cursors.Pen;
  157. //wfhCamera.Visibility = Visibility.Hidden;
  158. ImgPDFPath = null;
  159. ImgPDFPath = new string[300];
  160. }
  161. /// <summary>
  162. /// 开始
  163. /// </summary>
  164. /// <param name="sender"></param>
  165. /// <param name="e"></param>
  166. private void Stack()
  167. {
  168. _state = State.Start;
  169. }
  170. /// <summary>
  171. /// 暂停
  172. /// </summary>
  173. private void TimeOut()
  174. {
  175. _state = State.Pause;
  176. }
  177. /// <summary>
  178. /// 结束
  179. /// </summary>
  180. /// <param name="sender"></param>
  181. /// <param name="e"></param>
  182. private void End()
  183. {
  184. _state = State.End;
  185. }
  186. /// <summary>
  187. /// 时钟回调
  188. /// </summary>
  189. /// <param name="sender"></param>
  190. /// <param name="e"></param>
  191. private void OnTimer(object sender, EventArgs e)
  192. {
  193. switch (_state)
  194. {
  195. case State.Start:
  196. {
  197. _timeSpan += new TimeSpan(0, 0, 0, 1);
  198. }
  199. break;
  200. case State.Pause:
  201. {
  202. }
  203. break;
  204. case State.End:
  205. {
  206. _timeSpan = new TimeSpan();
  207. //_timeSpan = new TimeSpan(0, 23, 12, 45, 54);
  208. }
  209. break;
  210. }
  211. string time = string.Format("{0:D2}:{1:D2}",/* _timeSpan.Hours,*/ _timeSpan.Minutes, _timeSpan.Seconds);
  212. txbTime.Text = time;
  213. //txbTime.Text = time;
  214. }
  215. /// <summary>
  216. /// 修改布局
  217. /// </summary>
  218. public void SetUpLayout()
  219. {
  220. //宽高比1276,1040
  221. //double AspectRatio = 1276.0 / 1040.0;
  222. ////System.Drawing.Size des = PrimaryScreen.DESKTOP;
  223. //System.Drawing.Size workingArea = PrimaryScreen.WorkingArea;
  224. //this.Height = workingArea.Height;
  225. }
  226. #endregion
  227. #region 事件
  228. /// <summary>
  229. /// 窗体移动
  230. /// </summary>
  231. /// <param name="sender"></param>
  232. /// <param name="e"></param>
  233. private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  234. {
  235. DragMove();
  236. }
  237. #region 摄像头
  238. System.Timers.Timer times;
  239. List<string> RbnOpen;
  240. bool IsRbnOpen = false;
  241. /// <summary>
  242. /// 摄像头打开事件
  243. /// </summary>
  244. /// <param name="sender"></param>
  245. /// <param name="e"></param>
  246. private void RbnOpen_Click(object sender, RoutedEventArgs e)
  247. {
  248. //UCCamera win = new UCCamera();
  249. ////win.Topmost = true;
  250. //win.ShowDialog();
  251. //wfhCamera.Visibility = Visibility.Visible;
  252. //CameraHelper.IsDisplay = true;
  253. //CameraHelper.SourcePlayer = player;
  254. CameraHelper.UpdateCameraDevices();
  255. if (CameraHelper.CameraDevices.Count > 0)
  256. {
  257. CameraHelper.SetCameraDevice(0);
  258. RbnOpen = new List<string>();
  259. times = new System.Timers.Timer(300);//设置执行一次(false)还是一直执行(true)
  260. times.AutoReset = true;//设置是否执行System.Timers.Timer.Elapsed事件
  261. times.Elapsed += new System.Timers.ElapsedEventHandler(Times_Elapsed);
  262. times.Enabled = true; //启动计时器
  263. IsRbnOpen = true;
  264. string imgPath = FileToolsCommon.GetFileAbsolutePath("Temp/imgplayer");
  265. FileToolsCommon.CreateDirectory(imgPath);
  266. }
  267. }
  268. int I = 9999;
  269. private void Times_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
  270. {
  271. if (IsRbnOpen)
  272. {
  273. try
  274. {
  275. Dispatcher.Invoke(() =>
  276. {
  277. if (I > 10010)
  278. {
  279. long time = Timestamp();
  280. string imgPath = FileToolsCommon.GetFileAbsolutePath("Temp/imgplayer");
  281. //string FilePathName = ImgPath + RsImgName.Count + ".png";
  282. string path = CameraHelper.CaptureImage(imgPath, time.ToString());
  283. if (!string.IsNullOrWhiteSpace(path))
  284. {
  285. RbnOpen.Add(path);
  286. imgPlayerRight.Visibility = Visibility.Visible;
  287. /// < !--摄像头位置 1.右上 2.左上 3.右下 4.左下-- >
  288. if ("1".Equals(APP.CameraPosition))
  289. {
  290. imgPlayerRight.Visibility = Visibility.Visible;
  291. imgPlayerLeft.Visibility = Visibility.Collapsed;
  292. imgPlayerRightUnder.Visibility = Visibility.Collapsed;
  293. imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
  294. imgPlayerRight.Source = new BitmapImage(new Uri(path));
  295. }
  296. else if ("2".Equals(APP.CameraPosition))
  297. {
  298. imgPlayerRight.Visibility = Visibility.Collapsed;
  299. imgPlayerLeft.Visibility = Visibility.Visible;
  300. imgPlayerRightUnder.Visibility = Visibility.Collapsed;
  301. imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
  302. imgPlayerLeft.Source = new BitmapImage(new Uri(path));
  303. }
  304. else if ("3".Equals(APP.CameraPosition))
  305. {
  306. imgPlayerRight.Visibility = Visibility.Collapsed;
  307. imgPlayerLeft.Visibility = Visibility.Collapsed;
  308. imgPlayerRightUnder.Visibility = Visibility.Visible;
  309. imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
  310. imgPlayerRightUnder.Source = new BitmapImage(new Uri(path));
  311. }
  312. else if ("4".Equals(APP.CameraPosition))
  313. {
  314. imgPlayerRight.Visibility = Visibility.Collapsed;
  315. imgPlayerLeft.Visibility = Visibility.Collapsed;
  316. imgPlayerRightUnder.Visibility = Visibility.Collapsed;
  317. imgPlayerLeftUnder.Visibility = Visibility.Visible;
  318. imgPlayerLeftUnder.Source = new BitmapImage(new Uri(path));
  319. }
  320. else
  321. {
  322. imgPlayerLeft.Visibility = Visibility.Collapsed;
  323. imgPlayerRightUnder.Visibility = Visibility.Collapsed;
  324. imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
  325. imgPlayerRight.Source = new BitmapImage(new Uri(path));
  326. }
  327. }
  328. }
  329. I++;
  330. });
  331. }
  332. catch (Exception ex)
  333. {
  334. LogHelper.WriteErrLog("【摄像】(Times_Elapsed)生成图片错误:" + ex.Message, ex);
  335. }
  336. }
  337. }
  338. /// <summary>
  339. /// 摄像头关闭事件
  340. /// </summary>
  341. /// <param name="sender"></param>
  342. /// <param name="e"></param>
  343. private void RbnTurnOff_Click(object sender, RoutedEventArgs e)
  344. {
  345. IsRbnOpen = false;
  346. imgPlayerRight.Visibility = Visibility.Collapsed;
  347. imgPlayerLeft.Visibility = Visibility.Collapsed;
  348. imgPlayerRightUnder.Visibility = Visibility.Collapsed;
  349. imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
  350. CameraHelper.CloseDevice();
  351. I = 9999;
  352. }
  353. #endregion
  354. #endregion
  355. /// <summary>
  356. /// 录屏事件
  357. /// </summary>
  358. /// <param name="sender"></param>
  359. /// <param name="e"></param>
  360. private void BtnScreenRecording_Click(object sender, RoutedEventArgs e)
  361. {
  362. #region 限制只允许录制一个录屏 废弃
  363. //string RecordScreenPathName = APP.WKData.WkPath + APP.WKData.WkName + "_录屏." + ((Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType"))).ToString();
  364. //if (FileToolsCommon.IsExistFile(RecordScreenPathName))
  365. //{
  366. // MessageBoxResult dr = System.Windows.MessageBox.Show("已存在录屏,是否覆盖?", "提示", MessageBoxButton.OKCancel);
  367. // if (dr == MessageBoxResult.OK)
  368. // {
  369. // try
  370. // {
  371. // FileToolsCommon.DeleteFile(RecordScreenPathName);
  372. // APP.VideoList.RemoveAll(x => x.VideoPath == RecordScreenPathName);
  373. // }
  374. // catch (Exception ex)
  375. // {
  376. // LogHelper.WriteErrLog("【录屏】(BtnRecordingScreen_Click)无法移除视频," + ex.Message, ex);
  377. // }
  378. // }
  379. // else
  380. // {
  381. // return;
  382. // }
  383. //}
  384. #endregion
  385. if (APP.W_ScreenRecordingToolbarWindow == null)
  386. {
  387. APP.W_ScreenRecordingToolbarWindow = new ScreenRecordingToolbarWindow
  388. {
  389. Topmost = true
  390. };
  391. APP.W_ScreenRecordingToolbarWindow.Initialize();
  392. }
  393. else
  394. {
  395. APP.W_ScreenRecordingToolbarWindow.Initialize();
  396. }
  397. APP.W_ScreenRecordingToolbarWindow.Click_stopRecordingScreen += W_ScreenRecordingToolbarWindow_Click_stopRecordingScreen;
  398. //显示在右下角
  399. APP.W_ScreenRecordingToolbarWindow.WindowStartupLocation = WindowStartupLocation.Manual;
  400. APP.W_ScreenRecordingToolbarWindow.Left = PrimaryScreen.DESKTOP.Width - APP.W_ScreenRecordingToolbarWindow.Width - 60;
  401. APP.W_ScreenRecordingToolbarWindow.Top = PrimaryScreen.DESKTOP.Height - APP.W_ScreenRecordingToolbarWindow.Height - 30;
  402. APP.W_ScreenRecordingToolbarWindow.Topmost = true;
  403. APP.W_ScreenRecordingToolbarWindow.Show();
  404. Hide();
  405. }
  406. /// <summary>
  407. /// 保存录屏中
  408. /// </summary>
  409. private void W_ScreenRecordingToolbarWindow_Click_stopRecordingScreen()
  410. {
  411. TxbRecordScreenWord.Text = "保存中";//
  412. btnScreenRecording.IsEnabled = false;
  413. new Thread(new ThreadStart(new Action(() =>
  414. {
  415. while (FileToolsCommon.IsExistDirectory(APP.WKData.WkPath + "temprs/"))
  416. {
  417. Thread.Sleep(100);
  418. }
  419. Dispatcher.Invoke(() =>
  420. {
  421. btnScreenRecording.IsEnabled = true;
  422. TxbRecordScreenWord.Text = "录屏";
  423. });
  424. }))).Start();
  425. }
  426. /// <summary>
  427. /// 上传事件
  428. /// </summary>
  429. /// <param name="sender"></param>
  430. /// <param name="e"></param>
  431. private void BtnUpload_Click(object sender, RoutedEventArgs e)
  432. {
  433. if (APP.IsLoginType == false)
  434. {
  435. Login();
  436. return;
  437. }
  438. if(gridUpload.Visibility == Visibility.Visible)
  439. {
  440. gridUpload.Visibility = Visibility.Collapsed;
  441. GridMain.Visibility = Visibility.Visible;
  442. }
  443. else
  444. {
  445. gridUpload.Visibility = Visibility.Visible;
  446. GridMain.Visibility = Visibility.Collapsed;
  447. InitializeUpload();
  448. }
  449. }
  450. /// <summary>
  451. /// 关闭事件
  452. /// </summary>
  453. /// <param name="sender"></param>
  454. /// <param name="e"></param>
  455. private void BtnDown_Click(object sender, RoutedEventArgs e)
  456. {
  457. if (IsFirstR)
  458. {
  459. APP.Killffmpeg();
  460. APP.SaveWkData();
  461. APP.SaveDraw();
  462. Thread.Sleep(100);
  463. System.Environment.Exit(0);
  464. }
  465. else
  466. {
  467. System.Windows.MessageBox.Show("当前正在录制,请先停止录制。");
  468. return;
  469. //MessageBoxResult dr = System.Windows.MessageBox.Show("当前正在录制,是否停止录制?", "提示", MessageBoxButton.OKCancel);
  470. //if (dr == MessageBoxResult.OK)
  471. //{
  472. // APP.SaveWkData();
  473. // APP.SaveDraw();
  474. // BtnStop_Click(null, null);
  475. // while (!IsFirstR)
  476. // {
  477. // Thread.Sleep(100);
  478. // }
  479. // System.Environment.Exit(0);
  480. //}
  481. //else
  482. //{
  483. // return;
  484. //}
  485. }
  486. }
  487. /// <summary>
  488. /// 设置 保存事件
  489. /// </summary>
  490. /// <param name="sender"></param>
  491. /// <param name="e"></param>
  492. private void BtnSave_Click(object sender, RoutedEventArgs e)
  493. {
  494. #region 合法性判断
  495. //if (string.IsNullOrWhiteSpace(txbStoragePath.Text.Trim()))
  496. //{
  497. // System.Windows.MessageBox.Show("路径不可为空!");
  498. // return;
  499. //}
  500. //string temp = FileToolsCommon.GetLegalPath(txbStoragePath.Text) + APP.WKData.WkName.Trim() + "/";
  501. //if (!APP.WKData.WkPath.Equals(temp))
  502. //{
  503. // APP.WKData.WkPath = FileToolsCommon.GetLegalPath(txbStoragePath.Text) + APP.WKData.WkName.Trim() + "/";
  504. // if (FileToolsCommon.IsExistDirectory(APP.WKData.WkPath))
  505. // {
  506. // //微课已存在
  507. // MessageBoxResult dr = System.Windows.MessageBox.Show("讲解已存在是否覆盖?", "提示", MessageBoxButton.OKCancel);
  508. // if (dr == MessageBoxResult.OK)
  509. // {
  510. // FileToolsCommon.DeleteDirectory(APP.WKData.WkPath);
  511. // }
  512. // else
  513. // {
  514. // return;
  515. // }
  516. // }
  517. // //创建文件夹
  518. // FileToolsCommon.CreateDirectory(APP.WKData.WkPath);
  519. //}
  520. #endregion
  521. ImgRecord.Visibility = Visibility.Visible;//设置结束时可录制
  522. ImgRecordTwo.Visibility = Visibility.Collapsed;//设置结束时可录制
  523. BtnRecord.IsEnabled = true;//设置结束时可录制
  524. if (rbnMP4.IsChecked == true)
  525. {
  526. //存储文件
  527. FileToolsCommon.SetConfigValue("VideoType", "1");
  528. }
  529. else if (rbnFLV.IsChecked == true)
  530. {
  531. FileToolsCommon.SetConfigValue("VideoType", "2");
  532. }
  533. else
  534. {
  535. FileToolsCommon.SetConfigValue("VideoType", "3");
  536. }
  537. if (rbnY.IsChecked == true)
  538. {
  539. FileToolsCommon.SetConfigValue("IsSound", "true");
  540. }
  541. else
  542. {
  543. FileToolsCommon.SetConfigValue("IsSound", "false");
  544. }
  545. /// < !--摄像头位置 1.右上 2.左上 3.右下 4.左下-- >
  546. if (rbnRight.IsChecked == true)
  547. {
  548. FileToolsCommon.SetConfigValue("CameraPosition", "1");
  549. }
  550. else if (rbnLeft.IsChecked == true)
  551. {
  552. FileToolsCommon.SetConfigValue("CameraPosition", "2");
  553. }
  554. else if (rbnRightUnder.IsChecked == true)
  555. {
  556. FileToolsCommon.SetConfigValue("CameraPosition", "3");
  557. }
  558. else if (rbnLeftUnder.IsChecked == true)
  559. {
  560. FileToolsCommon.SetConfigValue("CameraPosition", "4");
  561. }
  562. APP.CameraPosition = FileToolsCommon.GetConfigValue("CameraPosition");
  563. GridMain.Visibility = Visibility.Visible;
  564. gridSetUp.Visibility = Visibility.Collapsed;
  565. imgPlayerRight.Visibility = Visibility.Collapsed;
  566. imgPlayerLeft.Visibility = Visibility.Collapsed;
  567. imgPlayerRightUnder.Visibility = Visibility.Collapsed;
  568. imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
  569. if(!txbStoragePath.Content.ToString().Equals(APP.WKData.WkPath))
  570. {
  571. //存储文件
  572. FileToolsCommon.SetConfigValue("VideoSavePath", txbStoragePath.Content.ToString());
  573. System.Windows.MessageBox.Show("路径已变更,下次创建微课时自动生效!!!");
  574. }
  575. }
  576. /// <summary>
  577. /// 设置事件
  578. /// </summary>
  579. /// <param name="sender"></param>
  580. /// <param name="e"></param>
  581. private void BtnSetUp_Click(object sender, RoutedEventArgs e)
  582. {
  583. if (!TxbRecordingWord.Text.Equals("暂停"))
  584. {
  585. GridMain.Visibility = Visibility.Collapsed;
  586. gridSetUp.Visibility = Visibility.Visible;
  587. txbStoragePath.Content = APP.WKData.WkPath;
  588. ImgRecord.Visibility = Visibility.Collapsed;//设置时不可录制
  589. ImgRecordTwo.Visibility = Visibility.Visible;//设置时不可录制
  590. BtnRecord.IsEnabled = false;//设置时不可录制
  591. /// < !--摄像头位置 1.右上 2.左上 3.右下 4.左下-- >
  592. if ("1".Equals(APP.CameraPosition))
  593. {
  594. rbnRight.IsChecked = true;
  595. }
  596. else if ("2".Equals(APP.CameraPosition))
  597. {
  598. rbnLeft.IsChecked = true;
  599. }
  600. else if ("3".Equals(APP.CameraPosition))
  601. {
  602. rbnRightUnder.IsChecked = true;
  603. }
  604. else if ("4".Equals(APP.CameraPosition))
  605. {
  606. rbnLeftUnder.IsChecked = true;
  607. }
  608. }
  609. }
  610. /// <summary>
  611. /// 设置 浏览事件
  612. /// </summary>
  613. /// <param name="sender"></param>
  614. /// <param name="e"></param>
  615. private void BtnBrowse_Click(object sender, RoutedEventArgs e)
  616. {
  617. //System.Diagnostics.Process.Start(APP.WKData.WkPath);
  618. string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
  619. Ofd = new System.Windows.Forms.FolderBrowserDialog();
  620. Result = Ofd.ShowDialog();
  621. if (Result == System.Windows.Forms.DialogResult.OK)
  622. {
  623. if (Ofd.SelectedPath != "")
  624. {
  625. txbStoragePath.Content = Ofd.SelectedPath;
  626. //string ApplicationData = ZConfig.dataPath + "fileStorageAddress.txt";
  627. //string temp = ofd.SelectedPath;
  628. //System.IO.File.WriteAllText(ApplicationData, temp, Encoding.Default);
  629. }
  630. }
  631. }
  632. /// <summary>
  633. /// 画笔颜色事件 白色
  634. /// </summary>
  635. /// <param name="sender"></param>
  636. /// <param name="e"></param>
  637. private void BtnWhite_Click(object sender, RoutedEventArgs e)
  638. {
  639. ////创建 DrawingAttributes 类的一个实例
  640. //drawingAttributes = new DrawingAttributes();
  641. ////将 InkCanvas 的 DefaultDrawingAttributes 属性的值赋成创建的 DrawingAttributes 类的对象的引用
  642. ////InkCanvas 通过 DefaultDrawingAttributes 属性来获取墨迹的各种设置,该属性的类型为 DrawingAttributes 型
  643. //blackboard_canvas.DefaultDrawingAttributes = drawingAttributes;
  644. ////设置 DrawingAttributes 的 Color 属性设置颜色
  645. drawingAttributes.Color = Colors.White;
  646. Color = Colors.White;
  647. }
  648. /// <summary>
  649. /// 画笔颜色事件 红色
  650. /// </summary>
  651. /// <param name="sender"></param>
  652. /// <param name="e"></param>
  653. private void BtnRed_Click(object sender, RoutedEventArgs e)
  654. {
  655. //设置 DrawingAttributes 的 Color 属性设置颜色
  656. drawingAttributes.Color = Colors.Red;
  657. Color = Colors.Red;
  658. imgRed.Visibility = Visibility.Visible;
  659. imgGray.Visibility = Visibility.Collapsed;
  660. imgCyanBlue.Visibility = Visibility.Collapsed;
  661. imgYellow.Visibility = Visibility.Collapsed;
  662. imgBlue.Visibility = Visibility.Collapsed;
  663. }
  664. /// <summary>
  665. /// 画笔颜色事件 黑色
  666. /// </summary>
  667. /// <param name="sender"></param>
  668. /// <param name="e"></param>
  669. private void BtnGray_Click(object sender, RoutedEventArgs e)
  670. {
  671. drawingAttributes.Color = Colors.Black;
  672. Color = Colors.Black;
  673. imgRed.Visibility = Visibility.Collapsed;
  674. imgGray.Visibility = Visibility.Visible;
  675. imgCyanBlue.Visibility = Visibility.Collapsed;
  676. imgYellow.Visibility = Visibility.Collapsed;
  677. imgBlue.Visibility = Visibility.Collapsed;
  678. }
  679. /// <summary>
  680. /// 画笔颜色事件 青色
  681. /// </summary>
  682. /// <param name="sender"></param>
  683. /// <param name="e"></param>
  684. private void BtnCyanBlue_Click(object sender, RoutedEventArgs e)
  685. {
  686. drawingAttributes.Color = Colors.LimeGreen;
  687. Color = Colors.LimeGreen;
  688. imgRed.Visibility = Visibility.Collapsed;
  689. imgGray.Visibility = Visibility.Collapsed;
  690. imgCyanBlue.Visibility = Visibility.Visible;
  691. imgYellow.Visibility = Visibility.Collapsed;
  692. imgBlue.Visibility = Visibility.Collapsed;
  693. }
  694. /// <summary>
  695. /// 画笔颜色事件 黄色
  696. /// </summary>
  697. /// <param name="sender"></param>
  698. /// <param name="e"></param>
  699. private void BtnYellow_Click(object sender, RoutedEventArgs e)
  700. {
  701. drawingAttributes.Color = Colors.Gold;
  702. Color = Colors.Gold;
  703. imgRed.Visibility = Visibility.Collapsed;
  704. imgGray.Visibility = Visibility.Collapsed;
  705. imgCyanBlue.Visibility = Visibility.Collapsed;
  706. imgYellow.Visibility = Visibility.Visible;
  707. imgBlue.Visibility = Visibility.Collapsed;
  708. }
  709. /// <summary>
  710. /// 画笔颜色事件 蓝色
  711. /// </summary>
  712. /// <param name="sender"></param>
  713. /// <param name="e"></param>
  714. private void BtnBlue_Click(object sender, RoutedEventArgs e)
  715. {
  716. drawingAttributes.Color = Colors.DeepSkyBlue;
  717. Color = Colors.DeepSkyBlue;
  718. imgRed.Visibility = Visibility.Collapsed;
  719. imgGray.Visibility = Visibility.Collapsed;
  720. imgCyanBlue.Visibility = Visibility.Collapsed;
  721. imgYellow.Visibility = Visibility.Collapsed;
  722. imgBlue.Visibility = Visibility.Visible;
  723. }
  724. /// <summary>
  725. /// 画笔粗细事件 细
  726. /// </summary>
  727. /// <param name="sender"></param>
  728. /// <param name="e"></param>
  729. private void RbnFine_Click(object sender, RoutedEventArgs e)
  730. {
  731. drawingAttributes.Width = 1;
  732. drawingAttributes.Height = 1;
  733. PenSize = 1;
  734. }
  735. /// <summary>
  736. /// 画笔粗细事件 中
  737. /// </summary>
  738. /// <param name="sender"></param>
  739. /// <param name="e"></param>
  740. private void RbnIn_Click(object sender, RoutedEventArgs e)
  741. {
  742. drawingAttributes.Width = 3;
  743. drawingAttributes.Height = 3;
  744. PenSize = 3;
  745. }
  746. /// <summary>
  747. /// 画笔粗细事件 粗
  748. /// </summary>
  749. /// <param name="sender"></param>
  750. /// <param name="e"></param>
  751. private void RbnCrude_Click(object sender, RoutedEventArgs e)
  752. {
  753. drawingAttributes.Width = 5;
  754. drawingAttributes.Height = 5;
  755. PenSize = 5;
  756. }
  757. /// <summary>
  758. /// 登陆事件
  759. /// </summary>
  760. /// <param name="sender"></param>
  761. /// <param name="e"></param>
  762. private void BtnLoginType_Click(object sender, RoutedEventArgs e)
  763. {
  764. Login();
  765. }
  766. /// <summary>
  767. /// 登陆
  768. /// </summary>
  769. private void Login()
  770. {
  771. if (APP.W_LoginWindow == null)
  772. {
  773. APP.W_LoginWindow = new LoginWindow();
  774. APP.W_LoginWindow.WindowStartupLocation = WindowStartupLocation.CenterOwner;
  775. APP.W_LoginWindow.Owner = this;
  776. }
  777. else
  778. {
  779. APP.W_LoginWindow.Initialize();
  780. }
  781. APP.W_LoginWindow.ShowDialog();
  782. if (APP.IsLoginType)
  783. {
  784. txbLoginType.Text = APP.UserInfo.Username;
  785. ImgUpload.Visibility = Visibility.Visible;
  786. ImgUploadTwo.Visibility = Visibility.Collapsed;
  787. }
  788. else
  789. {
  790. txbLoginType.Text = "未登录";
  791. ImgUpload.Visibility = Visibility.Collapsed;
  792. ImgUploadTwo.Visibility = Visibility.Visible;
  793. }
  794. }
  795. /// <summary>
  796. /// 截图事件
  797. /// </summary>
  798. /// <param name="sender"></param>
  799. /// <param name="e"></param>
  800. private void BtnScreenshot_Click(object sender, RoutedEventArgs e)
  801. {
  802. APP.ImgPath = string.Empty;
  803. string time = GetTimeStamp();
  804. string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + time + ".jpg";
  805. APP.ImgPath = desktopPath;
  806. ImageHelper.GetScreenshot(new System.Drawing.Rectangle(0, 0, 0, 0), desktopPath,false,out BitmapImage bitmap);
  807. if (this.WindowState == WindowState.Normal)//截图隐藏窗口
  808. {
  809. this.WindowState = WindowState.Minimized;
  810. }
  811. if (APP.W_JieTuWindow != null)
  812. {
  813. APP.W_JieTuWindow.initialization();
  814. APP.W_JieTuWindow.Screenshot();
  815. APP.W_JieTuWindow.WindowState = WindowState.Maximized;
  816. APP.W_JieTuWindow.Visibility = Visibility.Visible;
  817. }
  818. else
  819. {
  820. APP.W_JieTuWindow = new JieTuWindow();
  821. // 订阅事件
  822. APP.W_JieTuWindow.ChangeTextEvent += new ChangeTextHandler(frm_ChangeTextEvent);
  823. APP.W_JieTuWindow.click_closeJietuWindowClick += JietuWindow_click_closeJietuWindowClick;
  824. APP.W_JieTuWindow.Show();
  825. }
  826. //imgCanvas.Source = new BitmapImage(new Uri(desktopPath));
  827. }
  828. /// <summary>
  829. /// 截图关闭窗口
  830. /// </summary>
  831. /// <param name="text"></param>
  832. private void frm_ChangeTextEvent(string text)
  833. {
  834. if ("关闭窗口".Equals(text))
  835. {
  836. if (this.WindowState == WindowState.Minimized)//截图完恢复窗口
  837. {
  838. this.Topmost = true;
  839. this.WindowState = WindowState.Normal;
  840. }
  841. if (!string.IsNullOrWhiteSpace(APP.ImgPath) && File.Exists(APP.ImgPath))
  842. {
  843. if (APP.pageData.currpage == 0)
  844. {
  845. APP.pageData.pagenum += 1;
  846. APP.pageData.currpage = APP.pageData.pagenum;
  847. gridPage.Visibility = Visibility.Visible;//页码大于0 显示
  848. }
  849. if (APP.PageDrawList.Count >= APP.pageData.currpage)
  850. {
  851. APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath = APP.ImgPath;//zxycs
  852. APP.PageDrawList[APP.pageData.currpage - 1].PdfImagePath = APP.ImgPath;
  853. }
  854. else
  855. {
  856. Model_DrawData model_DrawData = new Model_DrawData();
  857. model_DrawData.PageImagePath = APP.ImgPath;
  858. model_DrawData.PdfImagePath = APP.ImgPath;
  859. APP.PageDrawList.Add(model_DrawData);
  860. }
  861. if (APP.PageDrawList.Count >= APP.pageData.currpage && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath))
  862. {
  863. imgDocumentation.Source = null;
  864. imgCanvas.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  865. APP.PageDrawList[APP.pageData.currpage - 1].ImgDocumentation = false;
  866. ImgPrint.Visibility = Visibility.Visible;//截图成功可打印
  867. ImgPrintTwo.Visibility = Visibility.Collapsed;
  868. btnPrint.IsEnabled = true;
  869. }
  870. }
  871. this.Topmost = false;
  872. }
  873. }
  874. /// <summary>
  875. /// 截图关闭 非正常关闭截图时,截图清空
  876. /// </summary>
  877. private void JietuWindow_click_closeJietuWindowClick()
  878. {
  879. if (this.WindowState == WindowState.Minimized)//截图完恢复窗口
  880. {
  881. this.WindowState = WindowState.Normal;
  882. }
  883. APP.W_JieTuWindow = null;
  884. }
  885. /// <summary>
  886. /// 获取时间戳
  887. /// </summary>
  888. /// <returns></returns>
  889. public string GetTimeStamp()
  890. {
  891. TimeSpan ts = DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0);
  892. return Convert.ToInt64(ts.TotalSeconds).ToString();
  893. }
  894. /// <summary>
  895. /// 导入事件
  896. /// </summary>
  897. /// <param name="sender"></param>
  898. /// <param name="e"></param>
  899. private void BtnImport_Click(object sender, RoutedEventArgs e)
  900. {
  901. try
  902. {
  903. string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
  904. ofd = new System.Windows.Forms.OpenFileDialog
  905. {
  906. Filter = "文档|*.docx;*.doc;*ppt",
  907. InitialDirectory = desktopPath,
  908. Multiselect = false,
  909. AddExtension = true,
  910. DereferenceLinks = true
  911. };
  912. new Thread(
  913. o =>
  914. {
  915. Thread.Sleep(400);
  916. Dispatcher.Invoke(new Action(() =>
  917. {
  918. OpenDialog();
  919. }
  920. ));
  921. })
  922. {
  923. IsBackground = true
  924. }.Start();
  925. }
  926. catch (Exception ex)
  927. {
  928. LogHelper.WriteErrLog("【导入(BtnImport_Click)" + ex.Message, ex);
  929. }
  930. }
  931. /// <summary>
  932. /// 导入文档
  933. /// </summary>
  934. private void OpenDialog()
  935. {
  936. result = ofd.ShowDialog();
  937. if (result == System.Windows.Forms.DialogResult.OK)
  938. {
  939. if (ofd.FileName != "")
  940. {
  941. APP.myloading.Show();
  942. #region PPT转PDF
  943. string filepath = ofd.FileName;
  944. string path = ofd.SafeFileName.Replace(".ppt", "").Trim();
  945. string type = ofd.SafeFileName.Replace(".ppt", "typezsygppt").Trim();
  946. if (type.Contains("typezsygppt"))//ppt
  947. {
  948. try
  949. {
  950. string pathTemp = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  951. path = pathTemp + path + ".pdf";
  952. //PPT转PDF
  953. Presentation ppt = new Presentation(filepath);
  954. ppt.Save(path, Aspose.Slides.Export.SaveFormat.Pdf);
  955. #endregion
  956. #region PDF转图片
  957. // 图片绝对路径集合
  958. List<string> images = new List<string>();
  959. string directoryPath = pathTemp;
  960. //aspose许可证
  961. //Aspose.Pdf.License l = new Aspose.Pdf.License();
  962. //string licenseName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Aspose.Total.Product.Family.lic");
  963. //l.SetLicense(licenseName);
  964. //定义Jpeg转换设备
  965. Aspose.Pdf.Document document = new Aspose.Pdf.Document(path);
  966. var device = new Aspose.Pdf.Devices.JpegDevice();
  967. //int quality = int.Parse(this.comboBox1.SelectedItem.ToString());
  968. //directoryPath += quality;
  969. Directory.CreateDirectory(directoryPath);
  970. //默认质量为100,设置质量的好坏与处理速度不成正比,甚至是设置的质量越低反而花的时间越长,怀疑处理过程是先生成高质量的再压缩
  971. device = new Aspose.Pdf.Devices.JpegDevice(100);
  972. //遍历每一页转为jpg
  973. for (var i = 1; i <= document.Pages.Count; i++)
  974. {
  975. long ii = Timestamp();
  976. string filePathOutPut = Path.Combine(directoryPath, string.Format("{0}{1}.jpg", ii, i));
  977. images.Add(filePathOutPut);
  978. FileStream fs = new FileStream(filePathOutPut, FileMode.OpenOrCreate);
  979. try
  980. {
  981. device.Process(document.Pages[i], fs);
  982. fs.Close();
  983. }
  984. catch (Exception ex)
  985. {
  986. fs.Close();
  987. File.Delete(filePathOutPut);
  988. }
  989. }
  990. #endregion
  991. string[] page = images.ToArray();
  992. int num = 0;
  993. for (int i = 0 + APP.pageData.pagenum; i < page.Length + APP.pageData.pagenum; i++)//给画板模型加图片路径
  994. {
  995. if (APP.PageDrawList != null && APP.PageDrawList.Count > i)
  996. {
  997. APP.PageDrawList[i].PageImagePath = page[i - APP.pageData.pagenum]; //zxycs
  998. APP.PageDrawList[i].PdfImagePath = page[i - APP.pageData.pagenum];
  999. APP.PageDrawList[i].PageNum = i + 1;
  1000. APP.PageDrawList[i].ImgDocumentation = true;
  1001. }
  1002. else
  1003. {
  1004. Model_DrawData model_DrawData = new Model_DrawData();
  1005. model_DrawData.PageImagePath = page[i - APP.pageData.pagenum];
  1006. model_DrawData.PdfImagePath = page[i - APP.pageData.pagenum];
  1007. model_DrawData.PageNum = i + 1;
  1008. model_DrawData.ImgDocumentation = true;
  1009. APP.PageDrawList.Add(model_DrawData);
  1010. }
  1011. ImgPrint.Visibility = Visibility.Visible;//导入成功可打印
  1012. ImgPrintTwo.Visibility = Visibility.Collapsed;
  1013. btnPrint.IsEnabled = true;
  1014. APP.SaveDraw();
  1015. num++;
  1016. }
  1017. if (num > 0)
  1018. {
  1019. APP.pageData.currpage = APP.pageData.pagenum + 1;
  1020. APP.pageData.pagenum += num;
  1021. gridPage.Visibility = Visibility.Visible;//页码大于0 显示
  1022. }
  1023. if (APP.pageData.currpage > 0 && APP.pageData.currpage < APP.PageDrawList.Count)
  1024. {
  1025. imgCanvas.Source = null;
  1026. ImgScreenshot.Visibility = Visibility.Collapsed;//当前页为导入时不可截图
  1027. ImgScreenshotTwo.Visibility = Visibility.Visible;
  1028. btnScreenshot.IsEnabled = false;
  1029. imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));//给当前页面展示图片
  1030. }
  1031. else
  1032. {
  1033. imgDocumentation.Source = null;
  1034. imgCanvas.Source = null;
  1035. ///截图可用
  1036. ImgScreenshot.Visibility = Visibility.Visible;
  1037. ImgScreenshotTwo.Visibility = Visibility.Collapsed;
  1038. btnScreenshot.IsEnabled = true;
  1039. }
  1040. APP.myloading.Hide();
  1041. }
  1042. catch (Exception ex)
  1043. {
  1044. APP.myloading.Hide();
  1045. LogHelper.WriteErrLog("【XHMicroLessonSystemWindow】(OpenDialog PPT)" + ex.Message, ex);
  1046. }
  1047. }
  1048. else//word
  1049. {
  1050. try
  1051. {
  1052. string paths = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  1053. string[] page = ConvertWordToImage(filepath, paths, "", 0, 0, null, 0).ToArray();
  1054. int num = 0;
  1055. for (int i = 0 + APP.pageData.pagenum; i < page.Length + APP.pageData.pagenum; i++)//给画板模型加图片路径
  1056. {
  1057. if (APP.PageDrawList != null && APP.PageDrawList.Count > i)
  1058. {
  1059. APP.PageDrawList[i].PageImagePath = page[i - APP.pageData.pagenum]; //zxycs
  1060. APP.PageDrawList[i].PdfImagePath = page[i - APP.pageData.pagenum];
  1061. APP.PageDrawList[i].PageNum = i + 1;
  1062. APP.PageDrawList[i].ImgDocumentation = true;
  1063. }
  1064. else
  1065. {
  1066. Model_DrawData model_DrawData = new Model_DrawData();
  1067. model_DrawData.PageImagePath = page[i - APP.pageData.pagenum];
  1068. model_DrawData.PdfImagePath = page[i - APP.pageData.pagenum];
  1069. model_DrawData.PageNum = i + 1;
  1070. model_DrawData.ImgDocumentation = true;
  1071. APP.PageDrawList.Add(model_DrawData);
  1072. }
  1073. ImgPrint.Visibility = Visibility.Visible;//导入成功可打印
  1074. ImgPrintTwo.Visibility = Visibility.Collapsed;
  1075. btnPrint.IsEnabled = true;
  1076. APP.SaveDraw();
  1077. num++;
  1078. }
  1079. if (num > 0)
  1080. {
  1081. APP.pageData.currpage = APP.pageData.pagenum + 1;
  1082. APP.pageData.pagenum += num;
  1083. gridPage.Visibility = Visibility.Visible;//页码大于0 显示
  1084. }
  1085. if (APP.pageData.currpage > 0 && APP.pageData.currpage < APP.PageDrawList.Count)
  1086. {
  1087. imgCanvas.Source = null;
  1088. ImgScreenshot.Visibility = Visibility.Collapsed;//当前页为导入时不可截图
  1089. ImgScreenshotTwo.Visibility = Visibility.Visible;
  1090. btnScreenshot.IsEnabled = false;
  1091. imgDocumentation.Visibility = Visibility.Visible;
  1092. imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));//给当前页面展示图片
  1093. }
  1094. else
  1095. {
  1096. imgDocumentation.Source = null;
  1097. imgCanvas.Source = null;
  1098. ///截图可用
  1099. ImgScreenshot.Visibility = Visibility.Visible;
  1100. ImgScreenshotTwo.Visibility = Visibility.Collapsed;
  1101. btnScreenshot.IsEnabled = true;
  1102. }
  1103. APP.myloading.Hide();
  1104. }
  1105. catch (Exception ex)
  1106. {
  1107. APP.myloading.Hide();
  1108. LogHelper.WriteErrLog("【XHMicroLessonSystemWindow】(OpenDialog 导入文档)" + ex.Message, ex);
  1109. }
  1110. }
  1111. }
  1112. }
  1113. }
  1114. /// <summary>
  1115. /// 返回一个时间戳到毫秒
  1116. /// </summary>
  1117. /// <returns></returns>
  1118. public static long Timestamp()
  1119. {
  1120. TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
  1121. long timestr = Convert.ToInt64(ts.TotalMilliseconds);
  1122. return timestr;
  1123. }
  1124. #region 录制窗口
  1125. #region 变量
  1126. /// <summary>
  1127. /// 视频保存路径
  1128. /// </summary>
  1129. //string RecordingPath;
  1130. /// <summary>
  1131. /// 图片保存路径
  1132. /// </summary>
  1133. string ImgPath;
  1134. /// <summary>
  1135. /// 音频保存路径名
  1136. /// </summary>
  1137. string AudioPathName;
  1138. /// <summary>
  1139. /// 视频保存路径名
  1140. /// </summary>
  1141. string VideoSavePathName;
  1142. /// <summary>
  1143. /// 暂停录制
  1144. /// </summary>
  1145. bool IsSuspendR = true;
  1146. /// <summary>
  1147. /// 录制是否已停止
  1148. /// </summary>
  1149. bool IsFirstR = true;
  1150. /// <summary>
  1151. /// 图片
  1152. /// </summary>
  1153. List<string> RsImgName = null;
  1154. /// <summary>
  1155. /// 是否开始截图计数
  1156. /// </summary>
  1157. bool IsStartCount = false;
  1158. #endregion
  1159. /// <summary>
  1160. /// 录制窗口内容
  1161. /// </summary>
  1162. /// <param name="sender"></param>
  1163. /// <param name="e"></param>
  1164. private void BtnRecord_Click(object sender, RoutedEventArgs e)
  1165. {
  1166. if (APP.pageData.currpage > 0)
  1167. {
  1168. blackboard_canvas.Visibility = Visibility.Visible;
  1169. }
  1170. else
  1171. {
  1172. System.Windows.MessageBox.Show("请先导入文档或截图!");
  1173. return;
  1174. }
  1175. //btnStop.IsEnabled = true;//停止录制按钮可点击
  1176. StartRecord();
  1177. }
  1178. /// <summary>
  1179. /// 停止录制窗口内容
  1180. /// </summary>
  1181. /// <param name="sender"></param>
  1182. /// <param name="e"></param>
  1183. private void BtnStop_Click(object sender, RoutedEventArgs e)
  1184. {
  1185. blackboard_canvas.Visibility = Visibility.Collapsed;
  1186. EndRecord();
  1187. }
  1188. System.Timers.Timer timer;
  1189. /// <summary>
  1190. /// 设置录屏文件地址
  1191. /// </summary>
  1192. void SetUpVideoPathName()
  1193. {
  1194. }
  1195. /// <summary>
  1196. /// 开始录制和暂停录制
  1197. /// </summary>
  1198. void StartRecord()
  1199. {
  1200. if (IsSuspendR)
  1201. {
  1202. if (IsFirstR)//是否第一次录制 初始化录制
  1203. {
  1204. #region 计时器初始化
  1205. if (t == null)
  1206. {
  1207. t = new DispatcherTimer();
  1208. t.Tick += OnTimer;
  1209. t.Interval = new TimeSpan(0, 0, 0, 1);
  1210. t.IsEnabled = true;
  1211. t.Start();
  1212. }
  1213. t.Interval = new TimeSpan(0, 0, 0, 1);
  1214. txbTime.Visibility = Visibility.Visible;
  1215. Stack();
  1216. #endregion
  1217. VideoInfo = new Model_Video();
  1218. VideoInfo.VideoType = (Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType"));
  1219. VideoInfo.WkType = Enum_WKVidetype.RecordingLessons;
  1220. ImgPath = APP.WKData.WkPath + "temp/Image/";
  1221. AudioPathName = APP.WKData.WkPath + "temp/audio/";
  1222. FileToolsCommon.DeleteDirectory(APP.WKData.WkPath + "temp/");
  1223. FileToolsCommon.CreateDirectory(APP.WKData.WkPath);
  1224. FileToolsCommon.CreateDirectory(ImgPath);
  1225. FileToolsCommon.CreateDirectory(AudioPathName);
  1226. AudioPathName += APP.WKData.WkName + ".MP3";
  1227. VideoSavePathName = APP.WKData.WkPath + APP.WKData.WkName + "_录制." + VideoInfo.VideoType.ToString();
  1228. int num = 1;
  1229. while (FileToolsCommon.IsExistFile(VideoSavePathName))
  1230. {
  1231. VideoSavePathName = APP.WKData.WkPath + APP.WKData.WkName + "_录制_" + num + "." + VideoInfo.VideoType.ToString();
  1232. num++;
  1233. }
  1234. #region 设置录屏唯一 废弃
  1235. //if (FileToolsCommon.IsExistFile(VideoSavePathName))
  1236. //{
  1237. // MessageBoxResult dr = System.Windows.MessageBox.Show("课程已录制,是否覆盖?", "提示", MessageBoxButton.OKCancel);
  1238. // if (dr == MessageBoxResult.OK)
  1239. // {
  1240. // try
  1241. // {
  1242. // FileToolsCommon.DeleteFile(VideoSavePathName);
  1243. // APP.VideoList.RemoveAll(x => x.VideoPath == VideoSavePathName);
  1244. // }
  1245. // catch (Exception ex)
  1246. // {
  1247. // LogHelper.WriteErrLog("【录制】(StartRecord)无法移除视频," + ex.Message, ex);
  1248. // }
  1249. // }
  1250. // else
  1251. // {
  1252. // return;
  1253. // }
  1254. //}
  1255. #endregion
  1256. #region 禁用按钮
  1257. ImgPrint.Visibility = Visibility.Collapsed;//录制中不可打印
  1258. ImgPrintTwo.Visibility = Visibility.Visible;
  1259. btnPrint.IsEnabled = false;
  1260. ImgScreenshot.Visibility = Visibility.Collapsed;//录制中不可截图
  1261. ImgScreenshotTwo.Visibility = Visibility.Visible;
  1262. btnScreenshot.IsEnabled = false;
  1263. ImgImport.Visibility = Visibility.Collapsed;//录制中不可导入文档
  1264. ImgImportTwo.Visibility = Visibility.Visible;
  1265. btnImport.IsEnabled = false;
  1266. ImgScreenRecording.Visibility = Visibility.Collapsed;//录制中不可录屏
  1267. ImgScreenRecordingTwo.Visibility = Visibility.Visible;
  1268. btnScreenRecording.IsEnabled = false;
  1269. ImgUpload.Visibility = Visibility.Collapsed;//录制中不可上传
  1270. ImgUploadTwo.Visibility = Visibility.Visible;
  1271. btnUpload.IsEnabled = false;
  1272. ImgSetUp.Visibility = Visibility.Collapsed;//录制中不可设置
  1273. ImgSetUpTwo.Visibility = Visibility.Visible;
  1274. btnSetUp.IsEnabled = false;
  1275. btnLoginType.IsEnabled = false;
  1276. #endregion
  1277. #region 录像倒计时
  1278. if (APP.W_CountdownWindow == null)
  1279. {
  1280. APP.W_CountdownWindow = new CountdownWindow();
  1281. //APP.W_CountdownWindow.Topmost = true;
  1282. }
  1283. else
  1284. {
  1285. APP.W_CountdownWindow.Initialize();
  1286. //APP.W_CountdownWindow.Topmost = true;
  1287. }
  1288. APP.W_CountdownWindow.Show();
  1289. #endregion
  1290. IsFirstR = false;
  1291. RsImgName = new List<string>();
  1292. timer = new System.Timers.Timer(200);//设置执行一次(false)还是一直执行(true)
  1293. timer.AutoReset = true;//设置是否执行System.Timers.Timer.Elapsed事件
  1294. timer.Elapsed += new System.Timers.ElapsedEventHandler(Timer_Elapsed);
  1295. timer.Enabled = true; //启动计时器
  1296. }
  1297. //继续录制
  1298. IsSuspendR = false;
  1299. //BtnRecording.Content = "暂停录制";
  1300. ImgRecord.Source = new BitmapImage(new Uri("pack://application:,,,/Images/microLessonSystem_23.png"));
  1301. ImgStop.Visibility = Visibility.Collapsed;
  1302. ImgStopTwo.Visibility = Visibility.Visible;
  1303. TxbRecordingWord.Text = "暂停";
  1304. Stack();
  1305. #region 2秒内不可点击
  1306. new Thread(new ThreadStart(new Action(() =>
  1307. {
  1308. Dispatcher.Invoke(() =>
  1309. {
  1310. BtnRecord.IsEnabled = false;
  1311. btnStop.IsEnabled = false;
  1312. });
  1313. Thread.Sleep(2000);
  1314. Dispatcher.Invoke(() =>
  1315. {
  1316. BtnRecord.IsEnabled = true;
  1317. btnStop.IsEnabled = true;
  1318. });
  1319. }))).Start();
  1320. #endregion
  1321. try
  1322. {
  1323. APP.FFmpeg.StartRecordingAudio(AudioPathName);
  1324. new Thread(new ThreadStart(new Action(() =>
  1325. {
  1326. Thread.Sleep(1000);
  1327. Dispatcher.Invoke(() =>
  1328. {
  1329. IsStartCount = true;
  1330. //timer.Start();
  1331. });
  1332. }))).Start();
  1333. }
  1334. catch (Exception ex)
  1335. {
  1336. System.Windows.MessageBox.Show(ex.Message);
  1337. }
  1338. }
  1339. else
  1340. {
  1341. //暂停
  1342. IsSuspendR = true;
  1343. ImgRecord.Source = new BitmapImage(new Uri("pack://application:,,,/Images/microLessonSystem_14.png"));
  1344. ImgStop.Visibility = Visibility.Visible;
  1345. ImgStopTwo.Visibility = Visibility.Collapsed;
  1346. TxbRecordingWord.Text = "继续";
  1347. TimeOut();
  1348. #region 2秒内不可点击
  1349. new Thread(new ThreadStart(new Action(() =>
  1350. {
  1351. Dispatcher.Invoke(() =>
  1352. {
  1353. BtnRecord.IsEnabled = false;
  1354. btnStop.IsEnabled = false;
  1355. });
  1356. Thread.Sleep(2000);
  1357. Dispatcher.Invoke(() =>
  1358. {
  1359. BtnRecord.IsEnabled = true;
  1360. btnStop.IsEnabled = true;
  1361. });
  1362. }))).Start();
  1363. #endregion
  1364. try
  1365. {
  1366. APP.FFmpeg.SuspendFFmpeg();
  1367. new Thread(new ThreadStart(new Action(() =>
  1368. {
  1369. while (APP.FFmpeg.myProcess != null)
  1370. {
  1371. Thread.Sleep(100);
  1372. }
  1373. IsStartCount = false;
  1374. }))).Start();
  1375. }
  1376. catch (Exception ex)
  1377. {
  1378. System.Windows.MessageBox.Show(ex.Message);
  1379. }
  1380. }
  1381. }
  1382. /// <summary>
  1383. /// 录制保存图片
  1384. /// </summary>
  1385. /// <param name="sender"></param>
  1386. /// <param name="e"></param>
  1387. private void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
  1388. {
  1389. if (IsStartCount)
  1390. {
  1391. try
  1392. {
  1393. Dispatcher.Invoke(() =>
  1394. {
  1395. string FilePathName = ImgPath + RsImgName.Count + ".png";
  1396. ImageHelper.SaveUIToImage(GridMain, FilePathName, (int)this.ActualWidth, (int)this.ActualHeight);
  1397. RsImgName.Add(FilePathName);
  1398. });
  1399. }
  1400. catch (Exception ex)
  1401. {
  1402. LogHelper.WriteErrLog("【录制】(Timer_Elapsed)生成图片错误:" + ex.Message, ex);
  1403. }
  1404. }
  1405. }
  1406. /// <summary>
  1407. /// 停止录制并生成录制文件
  1408. /// </summary>
  1409. void EndRecord()
  1410. {
  1411. if (!IsFirstR)
  1412. {
  1413. #region 恢复被禁用的按钮
  1414. ImgPrint.Visibility = Visibility.Visible;
  1415. ImgPrintTwo.Visibility = Visibility.Collapsed;
  1416. btnPrint.IsEnabled = true;
  1417. ImgScreenshot.Visibility = Visibility.Visible;
  1418. ImgScreenshotTwo.Visibility = Visibility.Collapsed;
  1419. btnScreenshot.IsEnabled = true;
  1420. ImgImport.Visibility = Visibility.Visible;
  1421. ImgImportTwo.Visibility = Visibility.Collapsed;
  1422. btnImport.IsEnabled = true;
  1423. ImgScreenRecording.Visibility = Visibility.Visible;
  1424. ImgScreenRecordingTwo.Visibility = Visibility.Collapsed;
  1425. btnScreenRecording.IsEnabled = true;
  1426. ImgUpload.Visibility = Visibility.Visible;
  1427. ImgUploadTwo.Visibility = Visibility.Collapsed;
  1428. btnUpload.IsEnabled = true;
  1429. ImgSetUp.Visibility = Visibility.Visible;
  1430. ImgSetUpTwo.Visibility = Visibility.Collapsed;
  1431. btnSetUp.IsEnabled = true;
  1432. btnLoginType.IsEnabled = true;
  1433. //btnStop.IsEnabled = false;//停止录制按钮不可点击
  1434. #endregion
  1435. IsSuspendR = true;
  1436. ImgRecord.Source = new BitmapImage(new Uri("pack://application:,,,/Images/microLessonSystem_14.png"));
  1437. ImgStop.Visibility = Visibility.Visible;
  1438. ImgStopTwo.Visibility = Visibility.Collapsed;
  1439. TimeOut();
  1440. txbType.Text = "保存中";
  1441. #region 2秒内不可点击
  1442. new Thread(new ThreadStart(new Action(() =>
  1443. {
  1444. Dispatcher.Invoke(() =>
  1445. {
  1446. BtnRecord.IsEnabled = false;
  1447. btnStop.IsEnabled = false;
  1448. });
  1449. }))).Start();
  1450. #endregion
  1451. try
  1452. {
  1453. #region 清空画板数据
  1454. APP.pageData.currpage = 0;
  1455. APP.pageData.pagenum = 0;
  1456. myblackboard.clear();
  1457. APP.PageDrawList.Clear();
  1458. imgCanvas.Source = null;
  1459. imgDocumentation.Source = null;
  1460. #endregion
  1461. //缩略图
  1462. string ThumbnailPath = FileToolsCommon.GetDirectoryName(VideoSavePathName) + "ThumbnailPath/";
  1463. FileToolsCommon.CreateDirectory(ThumbnailPath);
  1464. //缩略图存储位置
  1465. string ThumbnailPathName = ThumbnailPath + FileToolsCommon.GetIOFileNameNoExtension(VideoSavePathName) + ".JPG";
  1466. int gridActWidth = (int)GridMain.ActualWidth;
  1467. int gridActHeight = (int)GridMain.ActualHeight;
  1468. APP.FFmpeg.StopFFmpeg(AudioPathName);
  1469. new Thread(new ThreadStart(new Action(() =>
  1470. {
  1471. //停止截图
  1472. while (APP.FFmpeg.myProcess != null)
  1473. {
  1474. Thread.Sleep(100);
  1475. }
  1476. Dispatcher.Invoke(() =>
  1477. {
  1478. IsStartCount = false;
  1479. timer.Stop();
  1480. });
  1481. //}))).Start();
  1482. //new Thread(new ThreadStart(new Action(() =>
  1483. //{
  1484. //判断音频是否存在 判断音频临时文件夹是否存在
  1485. if (!FileToolsCommon.IsExistFile(AudioPathName))
  1486. {
  1487. Thread.Sleep(100);
  1488. }
  1489. if (FileToolsCommon.IsExistDirectory(FileToolsCommon.GetDirectoryName(AudioPathName) + "temp/"))
  1490. {
  1491. Thread.Sleep(100);
  1492. }
  1493. APP.FFmpeg.SynthesisVideo(ImgPath, AudioPathName, VideoSavePathName, 5, gridActWidth, gridActHeight);
  1494. //}))).Start();
  1495. //new Thread(new ThreadStart(new Action(() =>
  1496. //{
  1497. while (!FileToolsCommon.IsExistFile(VideoSavePathName))
  1498. {
  1499. Thread.Sleep(100);
  1500. }
  1501. while (FileToolsCommon.IsExistDirectory(FileToolsCommon.GetDirectoryName(VideoSavePathName) + "temp/"))
  1502. {
  1503. Thread.Sleep(100);
  1504. }
  1505. Dispatcher.Invoke(() =>
  1506. {
  1507. BtnRecord.IsEnabled = true;
  1508. btnStop.IsEnabled = true;
  1509. TxbRecordingWord.Text = "录制";
  1510. End();
  1511. txbTime.Text = "";
  1512. txbTime.Visibility = Visibility.Hidden;
  1513. txbType.Text = "";
  1514. });
  1515. FileToolsCommon.DeleteFile(ThumbnailPathName);
  1516. VideoInfo.RSTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  1517. Thread.Sleep(500);
  1518. //VideoInfo.VideoSize = FileToolsCommon.GetFileSizeByMB(VideoSavePathName).ToString() + " MB";
  1519. VideoInfo.VideoPath = VideoSavePathName;
  1520. VideoInfo.ThumbnailPath = ThumbnailPathName;
  1521. APP.FFmpeg.GenerateThumbnails(VideoSavePathName, ThumbnailPathName);
  1522. VideoInfo.FileGuid = Guid.NewGuid().ToString();
  1523. VideoInfo.IsUpload = false;
  1524. VideoInfo.Uploaded = 0;
  1525. VideoInfo.Savefolder = APP.UserInfo.Schoolid + "/resource";
  1526. APP.VideoList.Add(VideoInfo);
  1527. //保存数据
  1528. APP.SaveWkData();
  1529. IsFirstR = true;
  1530. }))).Start();
  1531. //List<Model_Video> VideoList
  1532. }
  1533. catch (Exception ex)
  1534. {
  1535. System.Windows.MessageBox.Show(ex.Message);
  1536. }
  1537. }
  1538. }
  1539. #endregion
  1540. /// <summary>
  1541. /// 增加事件
  1542. /// </summary>
  1543. /// <param name="sender"></param>
  1544. /// <param name="e"></param>
  1545. private void BtnAdd_Click(object sender, RoutedEventArgs e)
  1546. {
  1547. if (APP.pageData.currpage > 0)
  1548. {
  1549. APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = true;
  1550. }
  1551. if (IsStartCount && blackboard_canvas.Visibility == Visibility.Collapsed)
  1552. {
  1553. blackboard_canvas.Visibility = Visibility.Visible;
  1554. }
  1555. APP.pageData.pagenum += 1;
  1556. gridPage.Visibility = Visibility.Visible;//页码大于0 显示
  1557. APP.pageData.currpage = APP.pageData.pagenum;
  1558. //myblackboard.changepage(APP.pageData.currpage - 1);
  1559. ///清空页面图片UI
  1560. imgCanvas.Source = null;
  1561. imgDocumentation.Source = null;
  1562. ///画板模型增加一页
  1563. Model_DrawData model_DrawData = new Model_DrawData();
  1564. model_DrawData.PageNum = APP.pageData.currpage;
  1565. APP.PageDrawList.Add(model_DrawData);
  1566. //APP.SaveDraw();
  1567. if (btnImport.IsEnabled == true)
  1568. {
  1569. ///截图可用
  1570. ImgScreenshot.Visibility = Visibility.Visible;
  1571. ImgScreenshotTwo.Visibility = Visibility.Collapsed;
  1572. btnScreenshot.IsEnabled = true;
  1573. }
  1574. }
  1575. /// <summary>
  1576. /// 打印事件
  1577. /// </summary>
  1578. /// <param name="sender"></param>
  1579. /// <param name="e"></param>
  1580. private void BtnPrint_Click(object sender, RoutedEventArgs e)
  1581. {
  1582. try
  1583. {
  1584. //3种情况 1.文档图片 2.截图图片 3.没有图片
  1585. iTextSharp.text.Document document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 25, 25, 25, 25);
  1586. //iTextSharp.text.Rectangle page = new iTextSharp.text.Rectangle(iTextSharp.text.PageSize.A4., 250f);//cs
  1587. ////设置纸张横向
  1588. //document.SetPageSize(iTextSharp.text.PageSize.A4.Rotate());
  1589. string imgPath = FileToolsCommon.GetFileAbsolutePath("temp");
  1590. FileToolsCommon.CreateFile(imgPath);
  1591. imgPath += "\\101.pdf";
  1592. iTextSharp.text.pdf.PdfWriter.GetInstance(document, new FileStream(imgPath, FileMode.Create, FileAccess.ReadWrite));
  1593. document.Open();
  1594. iTextSharp.text.Image image;
  1595. for (int i = 0; i < APP.PageDrawList.Count; i++)
  1596. {
  1597. long ii = Timestamp();
  1598. string directoryPath = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  1599. string filePathOutPut = Path.Combine(directoryPath, string.Format("print{0}{1}.jpg", ii, i));
  1600. RectangleF rectangleFs = new RectangleF();
  1601. MergerImg("", filePathOutPut, rectangleFs, out string errmsg);
  1602. image = iTextSharp.text.Image.GetInstance(filePathOutPut);
  1603. if (String.IsNullOrEmpty(APP.PageDrawList[i].PageImagePath))//没有图片
  1604. {
  1605. }
  1606. else if (APP.PageDrawList[i].ImgDocumentation == true)
  1607. {
  1608. image = iTextSharp.text.Image.GetInstance(APP.PageDrawList[i].PageImagePath);
  1609. }
  1610. else
  1611. {
  1612. RectangleF rectangleF = new RectangleF();
  1613. rectangleF.Width = (float)APP.PageDrawList[i].ImageSizes.CenterX;
  1614. rectangleF.Height = (float)APP.PageDrawList[i].ImageSizes.CenterY;
  1615. rectangleF.X = (float)APP.PageDrawList[i].ImageLocation.X;
  1616. rectangleF.Y = (float)APP.PageDrawList[i].ImageLocation.Y;
  1617. string msg = string.Empty;
  1618. bool isImg = MergerImg(APP.PageDrawList[i].PageImagePath, filePathOutPut, rectangleF, out msg);
  1619. if (isImg)
  1620. {
  1621. image = iTextSharp.text.Image.GetInstance(filePathOutPut);
  1622. }
  1623. else
  1624. {
  1625. image = iTextSharp.text.Image.GetInstance(APP.PageDrawList[i].PageImagePath);
  1626. }
  1627. }
  1628. if (image.Height > iTextSharp.text.PageSize.A4.Height - 25)
  1629. {
  1630. image.ScaleToFit(iTextSharp.text.PageSize.A4.Width - 25, iTextSharp.text.PageSize.A4.Height - 25);
  1631. }
  1632. else if (image.Width > iTextSharp.text.PageSize.A4.Width - 25)
  1633. {
  1634. image.ScaleToFit(iTextSharp.text.PageSize.A4.Width - 25, iTextSharp.text.PageSize.A4.Height - 25);
  1635. }
  1636. image.Alignment = iTextSharp.text.Image.ALIGN_MIDDLE;
  1637. document.NewPage();
  1638. document.Add(image);
  1639. //iTextSharp.text.Chunk c1 = new iTextSharp.text.Chunk("Hello World");
  1640. //iTextSharp.text.Phrase p1 = new iTextSharp.text.Phrase();
  1641. //p1.Leading = 150; //行间距
  1642. //document.Add(p1);
  1643. }
  1644. Console.WriteLine("转换成功!");
  1645. document.Close();
  1646. }
  1647. catch (Exception ex)
  1648. {
  1649. Console.WriteLine("转换失败,原因:" + ex.Message);
  1650. }
  1651. //document.Close();
  1652. ////Console.ReadKey();
  1653. if (APP.W_PrintWindow == null)
  1654. {
  1655. APP.W_PrintWindow = new PrintWindow();
  1656. //APP.W_PrintWindow.Topmost = true;
  1657. APP.W_PrintWindow.Owner = this;
  1658. }
  1659. if (APP.PageDrawList.Count > 0 && !string.IsNullOrWhiteSpace(APP.PageDrawList[0].PageImagePath))
  1660. {
  1661. APP.W_PrintWindow.Initialize(APP.PageDrawList[0].PageImagePath);
  1662. }
  1663. else
  1664. {
  1665. APP.W_PrintWindow.Initialize("");
  1666. }
  1667. APP.W_PrintWindow.ShowDialog();
  1668. //int pr = 1;
  1669. //string msg = string.Empty;
  1670. //string outPut = string.Empty;
  1671. //LatticeFileHelper.GeneratingPDF(@"G:\101.pdf", @"G:\102.TPF",out pr, out msg, out outPut);
  1672. //if(pr==0)
  1673. //{
  1674. // outPut = outPut.Replace("[", "").Replace("]","").Replace("\"","").Trim();
  1675. // APP.OutPut = outPut.Split(',');
  1676. // string defa = string.Empty;
  1677. // List<string>defaList= LatticeFileHelper.GetPrinterList(out defa);
  1678. // int printResult = 1;
  1679. // string standardError = string.Empty;
  1680. // string standardOutput = string.Empty;
  1681. // LatticeFileHelper.PrinterTPFFile(@"G:\102.TPF",1, /*defa*/"导出为WPS PDF", out printResult,out standardError,out standardOutput);
  1682. //}
  1683. }
  1684. /// 上一页
  1685. /// </summary>
  1686. /// <param name="sender"></param>
  1687. /// <param name="e"></param>
  1688. private void last_button_Click(object sender, RoutedEventArgs e)
  1689. {
  1690. if (APP.pageData.currpage > 1)
  1691. {
  1692. APP.pageData.currpage -= 1;
  1693. myblackboard.changepage(APP.pageData.currpage - 1);
  1694. if (btnImport.IsEnabled == true)
  1695. {
  1696. ///截图可用
  1697. ImgScreenshot.Visibility = Visibility.Visible;
  1698. ImgScreenshotTwo.Visibility = Visibility.Collapsed;
  1699. btnScreenshot.IsEnabled = true;
  1700. }
  1701. if (APP.pageData.currpage <= APP.PageDrawList.Count)
  1702. {
  1703. if (APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation != null)
  1704. {
  1705. APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = true;
  1706. }
  1707. if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage <= APP.PageDrawList.Count && APP.pageData.currpage > 0 && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath))
  1708. {
  1709. //imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage - 1]));//cs
  1710. if (APP.PageDrawList[APP.pageData.currpage - 1].ImgDocumentation)
  1711. {
  1712. imgCanvas.Source = null;
  1713. imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  1714. ImgScreenshot.Visibility = Visibility.Collapsed;//当前页为导入时不可截图
  1715. ImgScreenshotTwo.Visibility = Visibility.Visible;
  1716. btnScreenshot.IsEnabled = false;
  1717. }
  1718. else
  1719. {
  1720. imgDocumentation.Source = null;
  1721. imgCanvas.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  1722. APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = false;
  1723. if (APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation != null && APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.X > 0)
  1724. {
  1725. var group = IMG.FindResource("Imageview") as TransformGroup;
  1726. var transform = group.Children[1] as TranslateTransform;
  1727. #region 高低 缩放比例
  1728. if (APP.PageDrawList[APP.pageData.currpage - 1].ImageSize != null)
  1729. {
  1730. var transform1 = group.Children[0] as ScaleTransform;
  1731. transform1.ScaleX = APP.PageDrawList[APP.pageData.currpage - 1].ImageSize.ScaleX;
  1732. transform1.ScaleY = APP.PageDrawList[APP.pageData.currpage - 1].ImageSize.ScaleY;
  1733. imgCanvas.Width = APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes.CenterX;
  1734. imgCanvas.Height = APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes.CenterY;
  1735. }
  1736. #endregion
  1737. #region XY轴
  1738. transform.X = APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.X;
  1739. transform.Y = APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.Y;
  1740. #endregion
  1741. mouseDown = false;
  1742. }
  1743. }
  1744. }
  1745. else
  1746. {
  1747. imgCanvas.Source = null;
  1748. imgDocumentation.Source = null;
  1749. }
  1750. }
  1751. }
  1752. }
  1753. /// <summary>
  1754. /// 下一页
  1755. /// </summary>
  1756. /// <param name="sender"></param>
  1757. /// <param name="e"></param>
  1758. private void next_btn_Click(object sender, RoutedEventArgs e)
  1759. {
  1760. if (APP.pageData.currpage < APP.pageData.pagenum)
  1761. {
  1762. APP.pageData.currpage += 1;
  1763. myblackboard.changepage(APP.pageData.currpage - 1);
  1764. if (btnImport.IsEnabled == true)
  1765. {
  1766. ///截图可用
  1767. ImgScreenshot.Visibility = Visibility.Visible;
  1768. ImgScreenshotTwo.Visibility = Visibility.Collapsed;
  1769. btnScreenshot.IsEnabled = true;
  1770. }
  1771. if (APP.pageData.currpage <= APP.PageDrawList.Count)
  1772. {
  1773. if (APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation != null)
  1774. {
  1775. APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = true;
  1776. }
  1777. if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage <= APP.PageDrawList.Count && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath))
  1778. {
  1779. if (APP.PageDrawList[APP.pageData.currpage - 1].ImgDocumentation)
  1780. {
  1781. imgCanvas.Source = null;
  1782. imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  1783. ImgScreenshot.Visibility = Visibility.Collapsed;//当前页为导入时不可截图
  1784. ImgScreenshotTwo.Visibility = Visibility.Visible;
  1785. btnScreenshot.IsEnabled = false;
  1786. }
  1787. else
  1788. {
  1789. imgDocumentation.Source = null;
  1790. imgCanvas.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  1791. APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = false;
  1792. if (APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation != null && APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.X > 0)
  1793. {
  1794. var group = IMG.FindResource("Imageview") as TransformGroup;
  1795. #region 高低 缩放比例
  1796. if (APP.PageDrawList[APP.pageData.currpage - 1].ImageSize != null)
  1797. {
  1798. var transform1 = group.Children[0] as ScaleTransform;
  1799. transform1.ScaleX = APP.PageDrawList[APP.pageData.currpage - 1].ImageSize.ScaleX;
  1800. transform1.ScaleY = APP.PageDrawList[APP.pageData.currpage - 1].ImageSize.ScaleY;
  1801. imgCanvas.Width = APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes.CenterX;
  1802. imgCanvas.Height = APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes.CenterY;
  1803. }
  1804. #endregion
  1805. #region 坐标XY轴
  1806. var transform = group.Children[1] as TranslateTransform;
  1807. transform.X = APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.X;
  1808. transform.Y = APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.Y;
  1809. #endregion
  1810. mouseDown = false;
  1811. }
  1812. }
  1813. }
  1814. else
  1815. {
  1816. imgCanvas.Source = null;
  1817. imgDocumentation.Source = null;
  1818. }
  1819. }
  1820. }
  1821. }
  1822. /// <summary>
  1823. /// 生成图片
  1824. /// </summary>
  1825. /// <param name="_path">图片地址</param>
  1826. /// <param name="_saveimg">保存位置</param>
  1827. /// <param name="_rectangle">图片位置</param>
  1828. /// <param name="errmsg">错误消息</param>
  1829. /// <returns></returns>
  1830. private bool MergerImg(string _path, string _saveimg, RectangleF _rectangle, out string errmsg)
  1831. {
  1832. errmsg = null;
  1833. try
  1834. {
  1835. Bitmap bitmap = null;
  1836. //创建要显示的图片对象,根据参数的个数设置宽度
  1837. Bitmap backgroudImg = new Bitmap((int)gridM.ActualWidth, (int)gridM.ActualHeight);
  1838. Graphics g = Graphics.FromImage(backgroudImg);
  1839. //清除画布,背景设置为白色
  1840. g.Clear(System.Drawing.Color.White);
  1841. if (!string.IsNullOrWhiteSpace(_path))
  1842. {
  1843. bitmap = ImageHelper.ReadBitmapFile(_path);
  1844. g.DrawImage(bitmap, _rectangle);
  1845. }
  1846. backgroudImg.Save(_saveimg);
  1847. g.Dispose();
  1848. backgroudImg.Dispose();
  1849. if (bitmap != null)
  1850. {
  1851. bitmap.Dispose();
  1852. }
  1853. GC.Collect();
  1854. return true;
  1855. }
  1856. catch (Exception ex)
  1857. {
  1858. errmsg = ex.Message;
  1859. LogHelper.WriteErrLog("【截图合成】(MergerImg)图片合成失败:" + ex.Message, ex);
  1860. return false;
  1861. }
  1862. }
  1863. /// <summary>
  1864. /// 将Word文档转换为图片的方法(该方法基于第三方DLL),你可以像这样调用该方法: ConvertPDF2Image("F:\\PdfFile.doc", "F:\\",
  1865. /// "ImageFile", 1, 20, ImageFormat.Png, 256);
  1866. /// </summary>
  1867. /// <param name="pdfInputPath">Word文件路径</param>
  1868. /// <param name="imageOutputPath">图片输出路径,如果为空,默认值为Word所在路径</param>
  1869. /// <param name="imageName">图片的名字,不需要带扩展名,如果为空,默认值为Word的名称</param>
  1870. /// <param name="startPageNum">从PDF文档的第几页开始转换,如果为0,默认值为1</param>
  1871. /// <param name="endPageNum">从PDF文档的第几页开始停止转换,如果为0,默认值为Word总页数</param>
  1872. /// <param name="imageFormat">设置所需图片格式,如果为null,默认格式为PNG</param>
  1873. /// <param name="resolution">设置图片的像素,数字越大越清晰,如果为0,默认值为128,建议最大值不要超过1024</param>
  1874. public List<string> ConvertWordToImage(string wordInputPath, string imageOutputPath,
  1875. string imageName, int startPageNum, int endPageNum, ImageFormat imageFormat, float resolution)
  1876. {
  1877. // 返回的图片绝对路径集合
  1878. List<string> images = new List<string>();
  1879. try
  1880. {
  1881. // open word file
  1882. Aspose.Words.Document doc = new Aspose.Words.Document(wordInputPath);
  1883. // validate parameter
  1884. if (doc == null) { throw new Exception("Word文件无效或者Word文件被加密!"); }
  1885. if (imageOutputPath.Trim().Length == 0) { imageOutputPath = System.IO.Path.GetDirectoryName(wordInputPath); }
  1886. if (!Directory.Exists(imageOutputPath)) { Directory.CreateDirectory(imageOutputPath); }
  1887. if (imageName.Trim().Length == 0) { imageName = System.IO.Path.GetFileNameWithoutExtension(wordInputPath); }
  1888. if (startPageNum <= 0) { startPageNum = 1; }
  1889. if (endPageNum > doc.PageCount || endPageNum <= 0) { endPageNum = doc.PageCount; }
  1890. if (startPageNum > endPageNum) { int tempPageNum = startPageNum; startPageNum = endPageNum; endPageNum = startPageNum; }
  1891. if (imageFormat == null) { imageFormat = ImageFormat.Png; }
  1892. if (resolution <= 0) { resolution = 128; }
  1893. ImageSaveOptions imageSaveOptions = new ImageSaveOptions(GetSaveFormat(imageFormat))
  1894. {
  1895. Resolution = resolution
  1896. };
  1897. // start to convert each page
  1898. for (int i = startPageNum; i <= endPageNum; i++)
  1899. {
  1900. imageSaveOptions.PageIndex = i - 1;
  1901. doc.Save(System.IO.Path.Combine(imageOutputPath, imageName) + "_" + APP.num.ToString() + "." + imageFormat.ToString(), imageSaveOptions);
  1902. images.Add(System.IO.Path.Combine(imageOutputPath, imageName) + "_" + APP.num.ToString() + "." + imageFormat.ToString());
  1903. APP.num++;
  1904. }
  1905. imageSaveOptions = null;
  1906. doc = null;
  1907. }
  1908. catch (Exception ex)
  1909. {
  1910. System.Windows.MessageBox.Show("文档已打开,请关闭后重试!");
  1911. LogHelper.WriteErrLog("【课堂考试(ExamWindow)】错误日志:" + ex.Message, ex);
  1912. }
  1913. return images;
  1914. }
  1915. private static SaveFormat GetSaveFormat(ImageFormat imageFormat)
  1916. {
  1917. SaveFormat sf;// = SaveFormat.Unknown;
  1918. if (imageFormat.Equals(ImageFormat.Png))
  1919. {
  1920. sf = SaveFormat.Png;
  1921. }
  1922. else if (imageFormat.Equals(ImageFormat.Jpeg))
  1923. {
  1924. sf = SaveFormat.Jpeg;
  1925. }
  1926. else if (imageFormat.Equals(ImageFormat.Tiff))
  1927. {
  1928. sf = SaveFormat.Tiff;
  1929. }
  1930. else if (imageFormat.Equals(ImageFormat.Bmp))
  1931. {
  1932. sf = SaveFormat.Bmp;
  1933. }
  1934. else
  1935. {
  1936. sf = SaveFormat.Unknown;
  1937. }
  1938. return sf;
  1939. }
  1940. #region 图像缩放,移动
  1941. private bool mouseDown;
  1942. private System.Windows.Point mouseXY;
  1943. private void IMG1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  1944. {
  1945. var img = sender as ContentControl;
  1946. if (img == null)
  1947. {
  1948. return;
  1949. }
  1950. img.CaptureMouse();
  1951. mouseDown = true;
  1952. mouseXY = e.GetPosition(img);
  1953. Console.WriteLine("mouseXY.X = " + mouseXY.X + "; mouseXY.Y = " + mouseXY.Y);
  1954. }
  1955. private void PicEMap_MouseDown(object sender, MouseButtonEventArgs e)
  1956. {
  1957. System.Windows.Point point = e.GetPosition(imgCanvas);
  1958. //Console.WriteLine("PicEmap.X = " + point.X + "; PicEmap.Y = " + point.Y);
  1959. //if ((point.X - 304) * (point.X - 304) + (point.Y - 86) * (point.Y - 86) < 100)
  1960. //{
  1961. // Console.WriteLine("在范围内");
  1962. //}
  1963. }
  1964. private void IMG1_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  1965. {
  1966. var img = sender as ContentControl;
  1967. if (img == null)
  1968. {
  1969. return;
  1970. }
  1971. img.ReleaseMouseCapture();
  1972. mouseDown = false;
  1973. }
  1974. private void IMG1_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
  1975. {
  1976. var img = sender as ContentControl;
  1977. if (img == null)
  1978. {
  1979. return;
  1980. }
  1981. if (mouseDown)
  1982. {
  1983. Domousemove(img, e);
  1984. }
  1985. }
  1986. /// <summary>
  1987. /// x y轴
  1988. /// </summary>
  1989. /// <param name="img"></param>
  1990. /// <param name="e"></param>
  1991. private void Domousemove(ContentControl img, System.Windows.Input.MouseEventArgs e)
  1992. {
  1993. if (e.LeftButton != MouseButtonState.Pressed)
  1994. {
  1995. return;
  1996. }
  1997. if (APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation != null && APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation)
  1998. {
  1999. return;
  2000. }
  2001. var group = IMG.FindResource("Imageview") as TransformGroup;
  2002. var transform = group.Children[1] as TranslateTransform;
  2003. var position = e.GetPosition(img);
  2004. transform.X -= mouseXY.X - position.X;
  2005. transform.Y -= mouseXY.Y - position.Y;
  2006. mouseXY = position;
  2007. APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation = new TranslateTransform();
  2008. APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.X = transform.X;
  2009. APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.Y = transform.Y;
  2010. //APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = false;
  2011. }
  2012. private void IMG1_MouseWheel(object sender, MouseWheelEventArgs e)
  2013. {
  2014. var img = sender as ContentControl;
  2015. if (img == null)
  2016. {
  2017. return;
  2018. }
  2019. var point = e.GetPosition(img);
  2020. Console.WriteLine("point.X = " + point.X + "; point.Y=" + point.Y);
  2021. var PicLocate = e.GetPosition(imgCanvas);
  2022. Console.WriteLine("PicEmap.X = " + PicLocate.X + "; PicEmap.Y=" + PicLocate.Y);
  2023. var group = IMG.FindResource("Imageview") as TransformGroup;
  2024. var delta = e.Delta * 0.001;
  2025. DowheelZoom(group, point, delta);
  2026. }
  2027. private void DowheelZoom(TransformGroup group, System.Windows.Point point, double delta)
  2028. {
  2029. var pointToContent = group.Inverse.Transform(point);
  2030. var transform = group.Children[0] as ScaleTransform;
  2031. if (transform.ScaleX + delta < 0.1) return;
  2032. transform.ScaleX += delta;
  2033. transform.ScaleY += delta;
  2034. var transform1 = group.Children[1] as TranslateTransform;
  2035. transform1.X = -1 * ((pointToContent.X * transform.ScaleX) - point.X);
  2036. transform1.Y = -1 * ((pointToContent.Y * transform.ScaleY) - point.Y);
  2037. LogHelper.WriteInfoLog("【img宽高】" + imgCanvas.ActualWidth.ToString() + ":"
  2038. + imgCanvas.ActualHeight.ToString() + "百分比:" + transform.ScaleX.ToString() + ":" + transform.ScaleY.ToString()
  2039. );
  2040. //Console.WriteLine("transform.ScaleX = " + transform.ScaleX + "; transform.ScaleY = " + transform.ScaleY);
  2041. APP.PageDrawList[APP.pageData.currpage - 1].ImageSize = new ScaleTransform();
  2042. APP.PageDrawList[APP.pageData.currpage - 1].ImageSize.ScaleX = transform.ScaleX;
  2043. APP.PageDrawList[APP.pageData.currpage - 1].ImageSize.ScaleY = transform.ScaleY;
  2044. APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation = new TranslateTransform();
  2045. APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.X = transform1.X;
  2046. APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.Y = transform1.Y;
  2047. APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes = new ScaleTransform();
  2048. APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes.CenterX = imgCanvas.ActualWidth;
  2049. APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes.CenterY = imgCanvas.ActualHeight;
  2050. APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = false;
  2051. }
  2052. #endregion
  2053. #region 点阵笔相关
  2054. #region 值初始化
  2055. // 不同尺寸点阵纸点阵宽高尺寸计算方法为:纸张物理尺寸(毫米)/0.3 *8,详见 开发必读.pdf 文档
  2056. /// <summary>
  2057. /// A4点阵纸点阵宽度
  2058. /// </summary>
  2059. private const int A4_WIDTH = 5600;
  2060. /// <summary>
  2061. /// A4点阵纸点阵高度
  2062. /// </summary>
  2063. private const int A4_HEIGHT = 7920;
  2064. /// <summary>
  2065. /// 画板
  2066. /// </summary>
  2067. private Graphics graphics;
  2068. /// <summary>
  2069. /// 笔画坐标数组
  2070. /// </summary>
  2071. private List<System.Drawing.Point> stroke;
  2072. /// <summary>
  2073. /// 笔序列号
  2074. /// </summary>
  2075. private string penSerial;
  2076. /// <summary>
  2077. /// 笔是否在点
  2078. /// </summary>
  2079. private bool isPenDown;
  2080. //当前点阵地址
  2081. private string currentPageSerial = string.Empty;
  2082. //不同点阵地址对应的笔迹绘制图片,用于实现在不同点阵地址书写切换时,显示书写内容自动切换
  2083. //本例图片放在内存中存储,对于大量或者需要在多个点阵地址对应图片进行切换演示,建议将图片存储到文件,以免内存溢出
  2084. private Dictionary<string, System.Drawing.Image> pagesDic = new Dictionary<string, System.Drawing.Image>();
  2085. #endregion
  2086. public void InitPen()
  2087. {
  2088. stroke = new List<System.Drawing.Point>();
  2089. //获取点阵笔实例,并绑定点阵笔事件
  2090. //将授权文件内容传入,获取点阵笔对象实例
  2091. APP.digitalPen = DigitalPenHID.GetInstance(certificates.MyLicense.Bytes);
  2092. //绑定笔连接事件
  2093. APP.digitalPen.PenConnected += OnPenConnect;
  2094. //绑定笔断开事件
  2095. APP.digitalPen.PenDisconnect += OnPenDisconnect;
  2096. //绑定笔书写输出坐标事件
  2097. APP.digitalPen.PenCoordinate += OnPenCoordinate;
  2098. //绑定抬笔事件
  2099. APP.digitalPen.PenUp += OnPenUp;
  2100. //绑定落笔事件
  2101. APP.digitalPen.PenDown += OnPenDown;
  2102. APP.digitalPen.PenBatteryCapacity += OnBatteryCapacity;
  2103. APP.digitalPen.PenMemoryFillLevel += OnMemoryFillLevel;
  2104. //完成初始化点阵笔,开始与点阵笔通信
  2105. ERROR_CODE ER = APP.digitalPen.Start();
  2106. ////绑定笔在新的点阵地址页面书写事件
  2107. //APP.digitalPen.PenNewPage += APP.digitalPen_OnPenNewPage;
  2108. ////绑定笔信息事件
  2109. //APP.digitalPen.PenInfo += APP.digitalPen_OnPenInfo;
  2110. //启动接收笔数据,完成初始化工作
  2111. ERROR_CODE rc = APP.digitalPen.Start();
  2112. //判断是否成功
  2113. if (ER != ERROR_CODE.ERROR_OK)
  2114. {
  2115. System.Windows.MessageBox.Show("初始化失败,授权过期,返回值:" + ER.ToString());
  2116. }
  2117. }
  2118. /// <summary>
  2119. /// 落笔
  2120. /// </summary>
  2121. /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
  2122. /// <param name="penSerial">点阵笔序列号</param>
  2123. /// <param name="penType">点阵笔型号编号</param>
  2124. private void OnPenDown(ulong time, string penSerial, int penType)
  2125. {
  2126. if (this.CheckAccess())
  2127. {
  2128. Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenDown);
  2129. this.Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
  2130. }
  2131. else
  2132. {
  2133. //labPenSerial.Text = penSerial;
  2134. //labPenStatus.Text = "PenDown";
  2135. isPenDown = true;
  2136. //Dispatcher.Invoke(new Action(() =>
  2137. //{
  2138. // for (int i = 0; i < APP.PageDrawList.Count; i++)
  2139. // {
  2140. // if (APP.PageDrawList[i].PageCode == penSerial)
  2141. // {
  2142. // if (i < APP.pageData.pagenum)
  2143. // {
  2144. // if (i < APP.pageData.currpage)
  2145. // {
  2146. // int num = APP.pageData.currpage - i;
  2147. // APP.pageData.currpage -= num;
  2148. // myblackboard.changepage(APP.pageData.currpage - 1);
  2149. // if (APP.PageDrawList.Count > 0)
  2150. // {
  2151. // if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage <= APP.PageDrawList.Count && APP.pageData.currpage > 0 && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath))
  2152. // {
  2153. // //imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage - 1]));//cs
  2154. // imgCanvas.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  2155. // }
  2156. // else
  2157. // {
  2158. // imgCanvas.Source = null;
  2159. // }
  2160. // }
  2161. // }
  2162. // else
  2163. // {
  2164. // int num = i - APP.pageData.currpage;
  2165. // APP.pageData.currpage += num;
  2166. // myblackboard.changepage(APP.pageData.currpage - 1);
  2167. // if (APP.PageDrawList.Count > 0)
  2168. // {
  2169. // if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage <= APP.PageDrawList.Count && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath))
  2170. // {
  2171. // //imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage-1]));
  2172. // imgCanvas.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  2173. // }
  2174. // else
  2175. // {
  2176. // imgCanvas.Source = null;
  2177. // }
  2178. // }
  2179. // }
  2180. // }
  2181. // return;
  2182. // }
  2183. // }
  2184. // //myblackboard.changepages(0, 0, true);
  2185. // //myblackboard.changepaget(0, 0, true, blackboard_canvas);
  2186. //}));
  2187. }
  2188. //myblackboard.changepages(0, 0, true);
  2189. }
  2190. /// <summary>
  2191. /// 抬笔
  2192. /// </summary>
  2193. /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
  2194. /// <param name="penSerial">点阵笔序列号</param>
  2195. /// <param name="penType">点阵笔型号编号</param>
  2196. private void OnPenUp(ulong time, string penSerial, int penType)
  2197. {
  2198. if (this.CheckAccess())
  2199. {
  2200. Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenUp);
  2201. this.Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
  2202. }
  2203. else
  2204. {
  2205. isPenDown = false;
  2206. APP.PenSerial = penSerial;
  2207. //int leftPoints = stroke.Count % 3;
  2208. //if (0 != leftPoints)
  2209. //{
  2210. // int from = stroke.Count - leftPoints - 1;
  2211. // if (from < 0)
  2212. // from = 0;
  2213. // int to = stroke.Count - 1;
  2214. // DrawCoordinates(from, to);
  2215. //}
  2216. stroke.Clear();
  2217. }
  2218. if (APP.pageData.currpage > 0)
  2219. {
  2220. Dispatcher.Invoke(new Action(() =>
  2221. {
  2222. myblackboard.changepages(0, 0, true, Color, PenSize, APP.pageData.currpage - 1);
  2223. }));
  2224. }
  2225. }
  2226. /// <summary>
  2227. /// 笔断开
  2228. /// </summary>
  2229. /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
  2230. /// <param name="penSerial">点阵笔序列号</param>
  2231. /// <param name="penType">点阵笔型号编号</param>
  2232. private void OnPenDisconnect(ulong time, string penSerial, int penType)
  2233. {
  2234. if (this.CheckAccess())
  2235. {
  2236. Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenDisconnect);
  2237. this.Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
  2238. }
  2239. else
  2240. {
  2241. APP.PenSerial = penSerial;
  2242. APP.PenStatus = false;
  2243. Dispatcher.Invoke(new Action(() =>
  2244. {
  2245. txbNotConnected.Text = "未连接";
  2246. txbNotConnecteds.Text = "未连接";
  2247. }));
  2248. }
  2249. }
  2250. /// <summary>
  2251. /// 笔连接
  2252. /// </summary>
  2253. /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
  2254. /// <param name="penSerial">点阵笔序列号</param>
  2255. /// <param name="penType">点阵笔型号编号</param>
  2256. private void OnPenConnect(ulong time, string penSerial, int penType)
  2257. {
  2258. if (this.CheckAccess())
  2259. {
  2260. Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenConnect);
  2261. this.Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
  2262. }
  2263. else
  2264. {
  2265. APP.PenSerial = penSerial;
  2266. APP.PenStatus = true;
  2267. this.penSerial = penSerial;
  2268. //连接后,在获取笔数据前,可以清除笔内的历史数据
  2269. //APP.digitalPen.ClearMemory(penSerial);
  2270. //开始接收笔数据
  2271. APP.digitalPen.GetPenData(penSerial);
  2272. Dispatcher.Invoke(new Action(() =>
  2273. {
  2274. txbNotConnected.Text = "已连接";
  2275. txbNotConnecteds.Text = "已连接";
  2276. }));
  2277. }
  2278. }
  2279. /// <summary>
  2280. /// 电池电量
  2281. /// </summary>
  2282. /// <param name="time"></param>
  2283. /// <param name="penSerial"></param>
  2284. /// <param name="penType"></param>
  2285. /// <param name="capacity"></param>
  2286. private void OnBatteryCapacity(ulong time, string penSerial, int penType, byte capacity)
  2287. {
  2288. if (this.CheckAccess())
  2289. {
  2290. Action<ulong, string, int, byte> action = new Action<ulong, string, int, byte>(OnBatteryCapacity);
  2291. this.Dispatcher.Invoke(action, new object[] { time, penSerial, penType, capacity });
  2292. }
  2293. else
  2294. {
  2295. //System.Windows.MessageBox.Show("电池电量:" + capacity.ToString());
  2296. }
  2297. }
  2298. /// <summary>
  2299. /// 已用存储
  2300. /// </summary>
  2301. /// <param name="time"></param>
  2302. /// <param name="penSerial"></param>
  2303. /// <param name="penType"></param>
  2304. /// <param name="fillLevel"></param>
  2305. private void OnMemoryFillLevel(ulong time, string penSerial, int penType, byte fillLevel)
  2306. {
  2307. if (this.CheckAccess())
  2308. {
  2309. Action<ulong, string, int, byte> action = new Action<ulong, string, int, byte>(OnMemoryFillLevel);
  2310. this.Dispatcher.Invoke(action, new object[] { time, penSerial, penType, fillLevel });
  2311. }
  2312. else
  2313. {
  2314. //System.Windows.MessageBox.Show("存储:" + fillLevel.ToString());
  2315. }
  2316. }
  2317. /// <summary>
  2318. /// 笔书写,收到坐标
  2319. /// </summary>
  2320. /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
  2321. /// <param name="penSerial">点阵笔序列号</param>
  2322. /// <param name="penType">点阵笔型号编号</param>
  2323. /// <param name="pageSerial">点阵地址</param>
  2324. /// <param name="cx">x坐标</param>
  2325. /// <param name="cy">y坐标</param>
  2326. /// <param name="force">压力值</param>
  2327. private void OnPenCoordinate(ulong time, string penSerial, int penType, string pageSerial, int cx, int cy, byte force)
  2328. {
  2329. if (this.CheckAccess())
  2330. {
  2331. Action<ulong, string, int, string, int, int, byte> ac = new Action<ulong, string, int, string, int, int, byte>(OnPenCoordinate);
  2332. this.Dispatcher.Invoke(ac, new object[] { time, pageSerial, penType, pageSerial, cx, cy, force });
  2333. }
  2334. else
  2335. {
  2336. //判断是否是落笔后输出的坐标,在设置悬浮模式下,落笔前的悬浮坐标不绘制
  2337. if (!isPenDown)
  2338. {
  2339. return;
  2340. }
  2341. stroke.Add(new System.Drawing.Point(cx, cy));
  2342. double PropW = blackboard_canvas.ActualWidth / A4_WIDTH;
  2343. double PropH = blackboard_canvas.ActualHeight / A4_HEIGHT;
  2344. //点
  2345. double testX = (double)cx * PropW;
  2346. double testY = (double)cy * PropH;
  2347. //pageSerial //点阵IP地址 与打印的页面关联
  2348. if (APP.pageData.currpage > 0)
  2349. {
  2350. Dispatcher.Invoke(new Action(() =>
  2351. {
  2352. //myblackboard.changepages(testX, testY,false);
  2353. myblackboard.changepages(testX, testY, false, Color, PenSize, APP.pageData.currpage - 1);
  2354. #region 设置滚动条位置
  2355. //点在显示页面上方
  2356. if (testY < scroMain.VerticalOffset)
  2357. {
  2358. //滚动条当前位置
  2359. double RollCurrentLocation = scroMain.VerticalOffset;
  2360. //向上滚动至以点为中心需要滚动的距离
  2361. double UpRoll = (RollCurrentLocation - testY) + (scroMain.ActualHeight / 2);
  2362. //如果小于0则等于0
  2363. double RollLocation = RollCurrentLocation - UpRoll;
  2364. if (RollLocation < 0)
  2365. {
  2366. RollLocation = 0;
  2367. }
  2368. ////滚动条实际偏移量
  2369. //double RollOffset = RollCurrentLocation - RollLocation;
  2370. scroMain.ScrollToVerticalOffset(RollLocation);
  2371. }
  2372. //点在显示页面下方
  2373. if (testY > scroMain.VerticalOffset + scroMain.ActualHeight)
  2374. {
  2375. //滚动条当前位置
  2376. double RollCurrentLocation = scroMain.VerticalOffset;
  2377. //向下滚动至以点为中心需要滚动的距离
  2378. double DownRoll = (testY - RollCurrentLocation) - (scroMain.ActualHeight / 2);
  2379. //如果小于0则等于0
  2380. double RollLocation = RollCurrentLocation + DownRoll;
  2381. //滚动条最大滚动值
  2382. double ScrollbarMaxNum = gridM.ActualHeight - scroMain.ActualHeight;
  2383. if (RollLocation > ScrollbarMaxNum)
  2384. {
  2385. RollLocation = ScrollbarMaxNum;
  2386. }
  2387. ////滚动条实际偏移量
  2388. //double RollOffset = RollLocation-RollCurrentLocation;
  2389. scroMain.ScrollToVerticalOffset(RollLocation);
  2390. }
  2391. #endregion
  2392. //gridM.Height //A4高度
  2393. //scroMain.VerticalOffset;//获取滚动条位置
  2394. //scroMain.ActualHeight//A4纸显示高度
  2395. //scroMain.ScrollToHorizontalOffset()//设置滚动条位置
  2396. //Mouse.GetPosition(this)
  2397. if (testX > 0 && testY > 0)
  2398. {
  2399. //System.Windows.Point getP = blackboard_canvas.PointToScreen(new System.Windows.Point(testX, testY));
  2400. System.Windows.Point getP = scroMain.PointToScreen(new System.Windows.Point(testX, testY - scroMain.VerticalOffset));
  2401. SetCursorPos((int)getP.X, (int)getP.Y);
  2402. }
  2403. }));
  2404. }
  2405. ////每3个点画一条曲线
  2406. //if (stroke.Count % 3 == 0)
  2407. //{
  2408. // int from = stroke.Count - 3 - 1;
  2409. // if (from < 0)
  2410. // from = 0;
  2411. // int to = stroke.Count - 1;
  2412. // DrawCoordinates(from, to);
  2413. //}
  2414. }
  2415. }
  2416. /// <summary>
  2417. /// 停止笔
  2418. /// </summary>
  2419. public void StopDigitalPen()
  2420. {
  2421. //停止,释放资源
  2422. APP.digitalPen.Stop();
  2423. }
  2424. /// <summary>
  2425. /// 清空笔内存储
  2426. /// </summary>
  2427. public void ClearPenStorage()
  2428. {
  2429. if (!string.IsNullOrEmpty(penSerial))
  2430. APP.digitalPen.ClearMemory(penSerial);
  2431. }
  2432. /// <summary>
  2433. /// 获取剩余电量
  2434. /// </summary>
  2435. public void GetPenElectricityQuantity()
  2436. {
  2437. if (!string.IsNullOrEmpty(penSerial))
  2438. APP.digitalPen.GetBatteryCapacity(penSerial);
  2439. }
  2440. /// <summary>
  2441. /// 获取存储空间
  2442. /// </summary>
  2443. public void GetUsedStorage()
  2444. {
  2445. if (!string.IsNullOrEmpty(penSerial))
  2446. APP.digitalPen.GetMemoryFillLevel(penSerial);
  2447. }
  2448. /// <summary>
  2449. /// 开启悬浮
  2450. /// </summary>
  2451. public void 开启悬浮()
  2452. {
  2453. if (!string.IsNullOrEmpty(penSerial))
  2454. APP.digitalPen.SetPenHoverMode(true, penSerial);
  2455. }
  2456. /// <summary>
  2457. /// 关闭悬浮
  2458. /// </summary>
  2459. public void 关闭悬浮()
  2460. {
  2461. if (!string.IsNullOrEmpty(penSerial))
  2462. APP.digitalPen.SetPenHoverMode(false, penSerial);
  2463. }
  2464. #endregion
  2465. /// <summary>
  2466. /// 最小化
  2467. /// </summary>
  2468. /// <param name="sender"></param>
  2469. /// <param name="e"></param>
  2470. private void BtnShrink_Click(object sender, RoutedEventArgs e)
  2471. {
  2472. if (this.WindowState == WindowState.Minimized)
  2473. {
  2474. this.WindowState = WindowState.Normal;
  2475. }
  2476. else
  2477. {
  2478. this.WindowState = WindowState.Minimized;
  2479. }
  2480. }
  2481. /// <summary>
  2482. /// 位置确定
  2483. /// </summary>
  2484. /// <param name="sender"></param>
  2485. /// <param name="e"></param>
  2486. private void BtnOk_Click(object sender, RoutedEventArgs e)
  2487. {
  2488. //APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = true;
  2489. //btnOk.Visibility = Visibility.Collapsed;
  2490. //blackboard_canvas.Visibility = Visibility.Visible;
  2491. }
  2492. /// <summary>
  2493. /// 引用user32.dll动态链接库(windows api),
  2494. /// 使用库中定义 API:SetCursorPos
  2495. /// 设置光标位置
  2496. /// </summary>
  2497. [System.Runtime.InteropServices.DllImport("user32.dll")]
  2498. private static extern int SetCursorPos(int x, int y);
  2499. /// 截图的图片鼠标右键事件
  2500. /// </summary>
  2501. /// <param name="sender"></param>
  2502. /// <param name="e"></param>
  2503. private void imgCanvas_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
  2504. {
  2505. imgCanvas.Source = null;
  2506. }
  2507. #region 上传
  2508. /// <summary>
  2509. /// 初始化上传
  2510. /// </summary>
  2511. public void InitializeUpload()
  2512. {
  2513. APP.myloading.Show();
  2514. MouseNumber = 0;
  2515. IsModify = false;
  2516. //加载视频列表
  2517. LoadingVideoList();
  2518. int i = 1;
  2519. bool isColour = true;
  2520. pageData.menuList.Clear();
  2521. //显示视频
  2522. foreach (Model_Video videoinfo in model_VideoList)
  2523. {
  2524. //是否已上传
  2525. //videoinfo.IsUpload;
  2526. //录制时间
  2527. //videoinfo.RSTime;
  2528. //文件大小
  2529. //videoinfo.VideoSize;
  2530. //文件缩略图路径
  2531. //videoinfo.ThumbnailPath;
  2532. //文件唯一标示 上传事件筛选需要上传的视频
  2533. //videoinfo.FileGuid;
  2534. //文件存储路径
  2535. //videoinfo.VidePath;
  2536. string colour = "#FFFFFF";
  2537. if (isColour == true)
  2538. {
  2539. colour = "#FFFFFF";
  2540. isColour = false;
  2541. }
  2542. else
  2543. {
  2544. colour = "#E6F1FF";
  2545. isColour = true;
  2546. }
  2547. string vis = "Visible";
  2548. string cos = "Collapsed";
  2549. if (!videoinfo.IsUpload)
  2550. {
  2551. vis = "Collapsed";
  2552. cos = "Visible";
  2553. }
  2554. if (i <= 16)
  2555. {
  2556. pageData.menuList.Add(new FileDirectoryModel()
  2557. {
  2558. SerialNumber = i,
  2559. VideoName = Common.system.FileToolsCommon.GetIOFileName(videoinfo.VideoPath).Replace(".MP4", "").Replace(".FLV", "").Replace(".AVI", "").Trim(),
  2560. Name = Common.system.FileToolsCommon.GetIOFileName(videoinfo.VideoPath).Replace(".MP4", "").Replace(".FLV", "").Replace(".AVI", "").Trim(),
  2561. FilePath = videoinfo.VideoPath.Replace(FileToolsCommon.GetIOFileName(videoinfo.VideoPath), "").Trim(),
  2562. VideoDuration = 0,
  2563. VideoSize = videoinfo.VideoSize,
  2564. VideoTime = videoinfo.RSTime,
  2565. IsEnabled = false,
  2566. Path = videoinfo.VideoPath,
  2567. Colour = colour,
  2568. Visi = vis,
  2569. Coll = cos,
  2570. FileGuid = videoinfo.FileGuid,
  2571. VideoType = videoinfo.VideoType.ToString()
  2572. }); ;
  2573. }
  2574. i++;
  2575. }
  2576. Currpage = 0;
  2577. PageNum = 0;
  2578. if (pageData.menuList.Count>0)
  2579. {
  2580. Currpage = 1;
  2581. txbCurrpageTwo.Text = Currpage.ToString();
  2582. stpUp.Visibility = Visibility.Visible;
  2583. }
  2584. else
  2585. {
  2586. stpUp.Visibility = Visibility.Hidden;
  2587. }
  2588. PageNum = model_VideoList.Count;
  2589. if (PageNum > 0)
  2590. {
  2591. int t = 1;
  2592. while (PageNum > 16 * t)
  2593. {
  2594. t++;
  2595. }
  2596. PageNum = t;
  2597. }
  2598. else
  2599. {
  2600. PageNum = 0;
  2601. }
  2602. txbPageNumTwo.Text = PageNum.ToString();
  2603. APP.myloading.Hide();
  2604. DataContext = pageData;
  2605. }
  2606. /// <summary>
  2607. /// 当前页
  2608. /// </summary>
  2609. int Currpage = 0;
  2610. /// <summary>
  2611. /// 总页码
  2612. /// </summary>
  2613. int PageNum = 0;
  2614. /// <summary>
  2615. /// 加载视频列表
  2616. /// </summary>
  2617. public void LoadingVideoList()
  2618. {
  2619. try
  2620. {
  2621. model_VideoList = new List<Model_Video>();
  2622. foreach (Model_WKData Vdata in APP.WKDataList)
  2623. {
  2624. if (Vdata.VideoList == null)
  2625. continue;
  2626. foreach (Model_Video videoinfo in Vdata.VideoList)
  2627. {
  2628. try
  2629. {
  2630. if (string.IsNullOrWhiteSpace(videoinfo.VideoPath))
  2631. {
  2632. continue;
  2633. }
  2634. if (string.IsNullOrWhiteSpace(videoinfo.VideoSize) || videoinfo.VideoSize == "0 MB")
  2635. {
  2636. videoinfo.VideoSize = FileToolsCommon.GetFileSizeByMB(videoinfo.VideoPath).ToString() + " MB";
  2637. }
  2638. model_VideoList.Add(videoinfo);
  2639. }
  2640. catch (Exception ex)
  2641. {
  2642. LogHelper.WriteErrLog("【加载视频列表】(LoadingVideoList)" + ex.Message, ex);
  2643. }
  2644. }
  2645. }
  2646. }
  2647. catch (Exception ex)
  2648. {
  2649. LogHelper.WriteErrLog("【加载视频列表】(LoadingVideoList)" + ex.Message, ex);
  2650. }
  2651. }
  2652. /// <summary>
  2653. /// 上传
  2654. /// </summary>
  2655. /// <param name="sender"></param>
  2656. /// <param name="e"></param>
  2657. private void BtnUploads_Click(object sender, RoutedEventArgs e)
  2658. {
  2659. pageData.menuList[Subscript].IsEnabled = false;
  2660. List<System.Windows.Controls.Button> buttons = FindChilds<System.Windows.Controls.Button>(listView1, "btnUpload");
  2661. for (int i = 0; i < buttons.Count; i++)
  2662. {
  2663. if (buttons[i] == sender)
  2664. {
  2665. DAL_Upload dAL_Upload = new DAL_Upload();
  2666. if (dAL_Upload.UploadVideo(pageData.menuList[i].FileGuid, out string ErrMessage))
  2667. {
  2668. pageData.menuList[i].Visi = "Visible";
  2669. pageData.menuList[i].Coll = "Collapsed";
  2670. DataContext = pageData;
  2671. System.Windows.MessageBox.Show("视频上传成功!");
  2672. }
  2673. else
  2674. {
  2675. System.Windows.MessageBox.Show(ErrMessage);
  2676. }
  2677. }
  2678. }
  2679. }
  2680. /// <summary>
  2681. /// 删除
  2682. /// </summary>
  2683. /// <param name="sender"></param>
  2684. /// <param name="e"></param>
  2685. private void BtnDelete_Click(object sender, RoutedEventArgs e)
  2686. {
  2687. pageData.menuList[Subscript].IsEnabled = false;
  2688. List<System.Windows.Controls.Button> buttons = FindChilds<System.Windows.Controls.Button>(listView1, "btnDelete");
  2689. for (int i = 0; i < buttons.Count; i++)
  2690. {
  2691. if (buttons[i] == sender)
  2692. {
  2693. //if (APP.W_PromptWindow == null)
  2694. //{
  2695. // APP.W_PromptWindow = new PromptWindow();
  2696. // APP.W_PromptWindow.Owner = this;
  2697. //}
  2698. //APP.W_PromptWindow.Initialize(pageData.menuList[i].VideoName);
  2699. //APP.W_PromptWindow.ShowDialog();
  2700. foreach (Model_WKData wKData in APP.WKDataList)
  2701. {
  2702. if (wKData.VideoList == null)
  2703. continue;
  2704. if (wKData.VideoList.Exists(x => x.FileGuid == pageData.menuList[i].FileGuid))
  2705. {
  2706. try
  2707. {
  2708. FileToolsCommon.DeleteFile(wKData.VideoList.Find(x => x.FileGuid == pageData.menuList[i].FileGuid).VideoPath);
  2709. FileToolsCommon.DeleteFile(wKData.VideoList.Find(x => x.FileGuid == pageData.menuList[i].FileGuid).ThumbnailPath);
  2710. wKData.VideoList.Remove(wKData.VideoList.Find(x => x.FileGuid == pageData.menuList[i].FileGuid));
  2711. InitializeUpload();
  2712. return;
  2713. }
  2714. catch (Exception ex)
  2715. {
  2716. System.Windows.MessageBox.Show("无法删除视频!" + ex.Message);
  2717. return;
  2718. }
  2719. }
  2720. }
  2721. }
  2722. }
  2723. }
  2724. /// <summary>
  2725. /// 播放
  2726. /// </summary>
  2727. /// <param name="sender"></param>
  2728. /// <param name="e"></param>
  2729. private void BtnPlay_Click(object sender, RoutedEventArgs e)
  2730. {
  2731. pageData.menuList[Subscript].IsEnabled = false;
  2732. List<System.Windows.Controls.Button> buttons = FindChilds<System.Windows.Controls.Button>(listView1, "btnPlay");
  2733. for (int i = 0; i < buttons.Count; i++)
  2734. {
  2735. if (buttons[i] == sender)
  2736. {
  2737. try
  2738. {
  2739. ProcessStartInfo psi = new ProcessStartInfo(pageData.menuList[i].Path);
  2740. Process pro = new Process
  2741. {
  2742. StartInfo = psi
  2743. };
  2744. pro.Start();
  2745. }
  2746. catch (Exception ex)
  2747. {
  2748. LogHelper.WriteErrLog("FileDirectoryWindow【BtnPlay_Click】" + ex.Message, ex);
  2749. System.Windows.MessageBox.Show(ex.Message);
  2750. return;
  2751. }
  2752. }
  2753. }
  2754. }
  2755. /// <summary>
  2756. /// 搜索集合匹配的索引
  2757. /// </summary>
  2758. /// <typeparam name="T"></typeparam>
  2759. /// <param name="parent"></param>
  2760. /// <param name="childName"></param>
  2761. /// <returns></returns>
  2762. public static List<T> FindChilds<T>(DependencyObject parent, string childName)
  2763. where T : DependencyObject
  2764. {
  2765. List<T> list = new List<T>();
  2766. if (parent == null)
  2767. {
  2768. return list;
  2769. }
  2770. int childrenCount = VisualTreeHelper.GetChildrenCount(parent);
  2771. for (int i = 0; i < childrenCount; i++)
  2772. {
  2773. DependencyObject child = VisualTreeHelper.GetChild(parent, i);
  2774. // 如果子控件不是需查找的控件类型
  2775. T childType = child as T;
  2776. if (childType == null)
  2777. {
  2778. // 在下一级控件中递归查找
  2779. List<T> findChildList = FindChilds<T>(child, childName);
  2780. for (int j = 0; j < findChildList.Count; j++)
  2781. {
  2782. }
  2783. list.AddRange(FindChilds<T>(child, childName));
  2784. }
  2785. else if (!string.IsNullOrEmpty(childName))
  2786. {
  2787. FrameworkElement frameworkElement = child as FrameworkElement;
  2788. // 如果控件名称符合参数条件
  2789. if (frameworkElement != null && frameworkElement.Name == childName)
  2790. {
  2791. list.Add((T)child);
  2792. }
  2793. }
  2794. else
  2795. {
  2796. // 查找到了控件
  2797. list.Add((T)child);
  2798. }
  2799. }
  2800. return list;
  2801. }
  2802. /// <summary>
  2803. /// 修改
  2804. /// </summary>
  2805. /// <param name="sender"></param>
  2806. /// <param name="e"></param>
  2807. private void BtnModify_Click(object sender, RoutedEventArgs e)
  2808. {
  2809. if (IsModify)
  2810. {
  2811. pageData.menuList[Subscript].IsEnabled = false;
  2812. }
  2813. List<System.Windows.Controls.Button> buttons = FindChilds<System.Windows.Controls.Button>(listView1, "btnModify");
  2814. for (int i = 0; i < buttons.Count; i++)
  2815. {
  2816. if (buttons[i] == sender)
  2817. {
  2818. pageData.menuList[i].IsEnabled = true;
  2819. Subscript = i;
  2820. IsModify = true;
  2821. }
  2822. }
  2823. }
  2824. int MouseNumber = 0;
  2825. /// <summary>
  2826. /// 上传 上页
  2827. /// </summary>
  2828. /// <param name="sender"></param>
  2829. /// <param name="e"></param>
  2830. private void BtnLastPage_Click(object sender, RoutedEventArgs e)
  2831. {
  2832. if (Currpage >1)
  2833. {
  2834. Currpage -= 1;
  2835. txbCurrpageTwo.Text = Currpage.ToString();
  2836. int i = 1;
  2837. bool isColour = true;
  2838. pageData.menuList.Clear();
  2839. //显示视频
  2840. foreach (Model_Video videoinfo in model_VideoList)
  2841. {
  2842. //是否已上传
  2843. //videoinfo.IsUpload;
  2844. //录制时间
  2845. //videoinfo.RSTime;
  2846. //文件大小
  2847. //videoinfo.VideoSize;
  2848. //文件缩略图路径
  2849. //videoinfo.ThumbnailPath;
  2850. //文件唯一标示 上传事件筛选需要上传的视频
  2851. //videoinfo.FileGuid;
  2852. //文件存储路径
  2853. //videoinfo.VidePath;
  2854. string colour = "#FFFFFF";
  2855. if (isColour == true)
  2856. {
  2857. colour = "#FFFFFF";
  2858. isColour = false;
  2859. }
  2860. else
  2861. {
  2862. colour = "#E6F1FF";
  2863. isColour = true;
  2864. }
  2865. string vis = "Visible";
  2866. string cos = "Collapsed";
  2867. if (!videoinfo.IsUpload)
  2868. {
  2869. vis = "Collapsed";
  2870. cos = "Visible";
  2871. }
  2872. if (i <= Currpage * 16 && i >= (Currpage - 1) * 16)
  2873. {
  2874. pageData.menuList.Add(new FileDirectoryModel()
  2875. {
  2876. SerialNumber = i,
  2877. VideoName = Common.system.FileToolsCommon.GetIOFileName(videoinfo.VideoPath).Replace(".MP4", "").Replace(".FLV", "").Replace(".AVI", "").Trim(),
  2878. Name = Common.system.FileToolsCommon.GetIOFileName(videoinfo.VideoPath).Replace(".MP4", "").Replace(".FLV", "").Replace(".AVI", "").Trim(),
  2879. FilePath = videoinfo.VideoPath.Replace(FileToolsCommon.GetIOFileName(videoinfo.VideoPath), "").Trim(),
  2880. VideoDuration = 0,
  2881. VideoSize = videoinfo.VideoSize,
  2882. VideoTime = videoinfo.RSTime,
  2883. IsEnabled = false,
  2884. Path = videoinfo.VideoPath,
  2885. Colour = colour,
  2886. Visi = vis,
  2887. Coll = cos,
  2888. FileGuid = videoinfo.FileGuid,
  2889. VideoType = videoinfo.VideoType.ToString()
  2890. }); ;
  2891. }
  2892. i++;
  2893. }
  2894. APP.myloading.Hide();
  2895. }
  2896. }
  2897. /// <summary>
  2898. /// 上传 下页
  2899. /// </summary>
  2900. /// <param name="sender"></param>
  2901. /// <param name="e"></param>
  2902. private void BtnNextPage_Click(object sender, RoutedEventArgs e)
  2903. {
  2904. if(Currpage< PageNum)
  2905. {
  2906. Currpage += 1;
  2907. txbCurrpageTwo.Text = Currpage.ToString();
  2908. int i = 1;
  2909. bool isColour = true;
  2910. pageData.menuList.Clear();
  2911. //显示视频
  2912. foreach (Model_Video videoinfo in model_VideoList)
  2913. {
  2914. //是否已上传
  2915. //videoinfo.IsUpload;
  2916. //录制时间
  2917. //videoinfo.RSTime;
  2918. //文件大小
  2919. //videoinfo.VideoSize;
  2920. //文件缩略图路径
  2921. //videoinfo.ThumbnailPath;
  2922. //文件唯一标示 上传事件筛选需要上传的视频
  2923. //videoinfo.FileGuid;
  2924. //文件存储路径
  2925. //videoinfo.VidePath;
  2926. string colour = "#FFFFFF";
  2927. if (isColour == true)
  2928. {
  2929. colour = "#FFFFFF";
  2930. isColour = false;
  2931. }
  2932. else
  2933. {
  2934. colour = "#E6F1FF";
  2935. isColour = true;
  2936. }
  2937. string vis = "Visible";
  2938. string cos = "Collapsed";
  2939. if (!videoinfo.IsUpload)
  2940. {
  2941. vis = "Collapsed";
  2942. cos = "Visible";
  2943. }
  2944. if (i <= Currpage*16&&i>(Currpage-1)*16)
  2945. {
  2946. pageData.menuList.Add(new FileDirectoryModel()
  2947. {
  2948. SerialNumber = i,
  2949. VideoName = Common.system.FileToolsCommon.GetIOFileName(videoinfo.VideoPath).Replace(".MP4", "").Replace(".FLV", "").Replace(".AVI", "").Trim(),
  2950. Name = Common.system.FileToolsCommon.GetIOFileName(videoinfo.VideoPath).Replace(".MP4", "").Replace(".FLV", "").Replace(".AVI", "").Trim(),
  2951. FilePath = videoinfo.VideoPath.Replace(FileToolsCommon.GetIOFileName(videoinfo.VideoPath), "").Trim(),
  2952. VideoDuration = 0,
  2953. VideoSize = videoinfo.VideoSize,
  2954. VideoTime = videoinfo.RSTime,
  2955. IsEnabled = false,
  2956. Path = videoinfo.VideoPath,
  2957. Colour = colour,
  2958. Visi = vis,
  2959. Coll = cos,
  2960. FileGuid = videoinfo.FileGuid,
  2961. VideoType = videoinfo.VideoType.ToString()
  2962. }); ;
  2963. }
  2964. i++;
  2965. }
  2966. APP.myloading.Hide();
  2967. }
  2968. }
  2969. #endregion
  2970. }
  2971. }