Main.cs 89 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.IO;
  7. using System.IO.Ports;
  8. using System.Linq;
  9. using System.Runtime.InteropServices;
  10. using System.Text;
  11. using System.Text.RegularExpressions;
  12. using System.Threading.Tasks;
  13. using System.Windows.Forms;
  14. using Excel = Microsoft.Office.Interop.Excel;
  15. using System.Reflection;
  16. using Microsoft.WindowsAPICodePack.Dialogs;
  17. using System.Threading;
  18. using System.Data.OleDb;
  19. using System.Collections;
  20. //using Microsoft.Office.Interop.Excel;
  21. namespace APL_TestCheck
  22. {
  23. public partial class Main : Form
  24. {
  25. public string Serial_Name { get => serialPort.PortName; set => serialPort.PortName = value; }
  26. public Main()
  27. {
  28. InitializeComponent();
  29. }
  30. private void panel_PanelMode_MouseLeave(object sender, EventArgs e)
  31. {
  32. System.Windows.Forms.Panel Panel = (System.Windows.Forms.Panel)sender;
  33. Panel.BackColor = Color.FromArgb(0, 159, 200);
  34. label_GPSTest_MouseLeave(null, null);
  35. }
  36. private void panel_PanelMode_MouseMove(object sender, MouseEventArgs e)
  37. {
  38. System.Windows.Forms.Panel Panel = (System.Windows.Forms.Panel)sender;
  39. Panel.BackColor = Color.FromArgb(0, 159, 255);
  40. }
  41. private void label_GPSTest_MouseLeave(object sender, EventArgs e)
  42. {
  43. if (panel_GpsTest.Visible == true)
  44. {
  45. panel_Catm1Mode.BackColor = Color.FromArgb(0, 159, 200);
  46. panel_SensorMode.BackColor = Color.FromArgb(0, 159, 200);
  47. panel_GpsMode.BackColor = Color.FromArgb(0, 159, 255);
  48. panel_Merge.BackColor = Color.FromArgb(0, 159, 200);
  49. panel_SnCheck.BackColor = Color.FromArgb(0, 159, 200);
  50. }
  51. else if (panel_Catm1Test.Visible == true)
  52. {
  53. panel_Catm1Mode.BackColor = Color.FromArgb(0, 159, 255);
  54. panel_SensorMode.BackColor = Color.FromArgb(0, 159, 200);
  55. panel_GpsMode.BackColor = Color.FromArgb(0, 159, 200);
  56. panel_Merge.BackColor = Color.FromArgb(0, 159, 200);
  57. panel_SnCheck.BackColor = Color.FromArgb(0, 159, 200);
  58. }
  59. else if (panel_SensorTest.Visible == true)
  60. {
  61. panel_Catm1Mode.BackColor = Color.FromArgb(0, 159, 200);
  62. panel_SensorMode.BackColor = Color.FromArgb(0, 159, 255);
  63. panel_GpsMode.BackColor = Color.FromArgb(0, 159, 200);
  64. panel_Merge.BackColor = Color.FromArgb(0, 159, 200);
  65. panel_SnCheck.BackColor = Color.FromArgb(0, 159, 200);
  66. }
  67. else if (panel_MergeMain.Visible == true)
  68. {
  69. panel_Merge.BackColor = Color.FromArgb(0, 159, 255);
  70. panel_Catm1Mode.BackColor = Color.FromArgb(0, 159, 200);
  71. panel_SensorMode.BackColor = Color.FromArgb(0, 159, 200);
  72. panel_GpsMode.BackColor = Color.FromArgb(0, 159, 200);
  73. panel_SnCheck.BackColor = Color.FromArgb(0, 159, 200);
  74. }
  75. else if (panel_SnCheckMain.Visible == true)
  76. {
  77. panel_Merge.BackColor = Color.FromArgb(0, 159, 200);
  78. panel_Catm1Mode.BackColor = Color.FromArgb(0, 159, 200);
  79. panel_SensorMode.BackColor = Color.FromArgb(0, 159, 200);
  80. panel_GpsMode.BackColor = Color.FromArgb(0, 159, 200);
  81. panel_SnCheck.BackColor = Color.FromArgb(0, 159, 255);
  82. }
  83. }
  84. private void label_Catm1Test_MouseLeave(object sender, EventArgs e)
  85. {
  86. if (panel_GpsTest.Visible == true)
  87. {
  88. panel_Catm1Mode.BackColor = Color.FromArgb(0, 159, 200);
  89. panel_SensorMode.BackColor = Color.FromArgb(0, 159, 200);
  90. panel_GpsMode.BackColor = Color.FromArgb(0, 159, 255);
  91. panel_Merge.BackColor = Color.FromArgb(0, 159, 200);
  92. panel_SnCheck.BackColor = Color.FromArgb(0, 159, 200);
  93. }
  94. else if (panel_Catm1Test.Visible == true)
  95. {
  96. panel_Catm1Mode.BackColor = Color.FromArgb(0, 159, 255);
  97. panel_SensorMode.BackColor = Color.FromArgb(0, 159, 200);
  98. panel_GpsMode.BackColor = Color.FromArgb(0, 159, 200);
  99. panel_Merge.BackColor = Color.FromArgb(0, 159, 200);
  100. panel_SnCheck.BackColor = Color.FromArgb(0, 159, 200);
  101. }
  102. else if (panel_SensorTest.Visible == true)
  103. {
  104. panel_Catm1Mode.BackColor = Color.FromArgb(0, 159, 200);
  105. panel_SensorMode.BackColor = Color.FromArgb(0, 159, 255);
  106. panel_GpsMode.BackColor = Color.FromArgb(0, 159, 200);
  107. panel_Merge.BackColor = Color.FromArgb(0, 159, 200);
  108. panel_SnCheck.BackColor = Color.FromArgb(0, 159, 200);
  109. }
  110. else if (panel_MergeMain.Visible == true)
  111. {
  112. panel_Merge.BackColor = Color.FromArgb(0, 159, 255);
  113. panel_Catm1Mode.BackColor = Color.FromArgb(0, 159, 200);
  114. panel_SensorMode.BackColor = Color.FromArgb(0, 159, 200);
  115. panel_GpsMode.BackColor = Color.FromArgb(0, 159, 200);
  116. panel_SnCheck.BackColor = Color.FromArgb(0, 159, 200);
  117. }
  118. else if (panel_SnCheckMain.Visible == true)
  119. {
  120. panel_Merge.BackColor = Color.FromArgb(0, 159, 200);
  121. panel_Catm1Mode.BackColor = Color.FromArgb(0, 159, 200);
  122. panel_SensorMode.BackColor = Color.FromArgb(0, 159, 200);
  123. panel_GpsMode.BackColor = Color.FromArgb(0, 159, 200);
  124. panel_SnCheck.BackColor = Color.FromArgb(0, 159, 255);
  125. }
  126. }
  127. private void label_SensorTest_MouseLeave(object sender, EventArgs e)
  128. {
  129. if (panel_GpsTest.Visible == true)
  130. {
  131. panel_Catm1Mode.BackColor = Color.FromArgb(0, 159, 200);
  132. panel_SensorMode.BackColor = Color.FromArgb(0, 159, 200);
  133. panel_GpsMode.BackColor = Color.FromArgb(0, 159, 255);
  134. panel_Merge.BackColor = Color.FromArgb(0, 159, 200);
  135. panel_SnCheck.BackColor = Color.FromArgb(0, 159, 200);
  136. }
  137. else if (panel_Catm1Test.Visible == true)
  138. {
  139. panel_Catm1Mode.BackColor = Color.FromArgb(0, 159, 255);
  140. panel_SensorMode.BackColor = Color.FromArgb(0, 159, 200);
  141. panel_GpsMode.BackColor = Color.FromArgb(0, 159, 200);
  142. panel_Merge.BackColor = Color.FromArgb(0, 159, 200);
  143. panel_SnCheck.BackColor = Color.FromArgb(0, 159, 200);
  144. }
  145. else if (panel_SensorTest.Visible == true)
  146. {
  147. panel_Catm1Mode.BackColor = Color.FromArgb(0, 159, 200);
  148. panel_SensorMode.BackColor = Color.FromArgb(0, 159, 255);
  149. panel_GpsMode.BackColor = Color.FromArgb(0, 159, 200);
  150. panel_Merge.BackColor = Color.FromArgb(0, 159, 200);
  151. panel_SnCheck.BackColor = Color.FromArgb(0, 159, 200);
  152. }
  153. else if (panel_MergeMain.Visible == true)
  154. {
  155. panel_Merge.BackColor = Color.FromArgb(0, 159, 255);
  156. panel_Catm1Mode.BackColor = Color.FromArgb(0, 159, 200);
  157. panel_SensorMode.BackColor = Color.FromArgb(0, 159, 200);
  158. panel_GpsMode.BackColor = Color.FromArgb(0, 159, 200);
  159. panel_SnCheck.BackColor = Color.FromArgb(0, 159, 200);
  160. }
  161. else if (panel_SnCheckMain.Visible == true)
  162. {
  163. panel_Merge.BackColor = Color.FromArgb(0, 159, 200);
  164. panel_Catm1Mode.BackColor = Color.FromArgb(0, 159, 200);
  165. panel_SensorMode.BackColor = Color.FromArgb(0, 159, 200);
  166. panel_GpsMode.BackColor = Color.FromArgb(0, 159, 200);
  167. panel_SnCheck.BackColor = Color.FromArgb(0, 159, 255);
  168. }
  169. }
  170. private void label_Merge_MouseLeave(object sender, EventArgs e)
  171. {
  172. if (panel_GpsTest.Visible == true)
  173. {
  174. panel_Catm1Mode.BackColor = Color.FromArgb(0, 159, 200);
  175. panel_SensorMode.BackColor = Color.FromArgb(0, 159, 200);
  176. panel_GpsMode.BackColor = Color.FromArgb(0, 159, 255);
  177. panel_Merge.BackColor = Color.FromArgb(0, 159, 200);
  178. panel_SnCheck.BackColor = Color.FromArgb(0, 159, 200);
  179. }
  180. else if (panel_Catm1Test.Visible == true)
  181. {
  182. panel_Catm1Mode.BackColor = Color.FromArgb(0, 159, 255);
  183. panel_SensorMode.BackColor = Color.FromArgb(0, 159, 200);
  184. panel_GpsMode.BackColor = Color.FromArgb(0, 159, 200);
  185. panel_Merge.BackColor = Color.FromArgb(0, 159, 200);
  186. panel_SnCheck.BackColor = Color.FromArgb(0, 159, 200);
  187. }
  188. else if (panel_SensorTest.Visible == true)
  189. {
  190. panel_Catm1Mode.BackColor = Color.FromArgb(0, 159, 200);
  191. panel_SensorMode.BackColor = Color.FromArgb(0, 159, 255);
  192. panel_GpsMode.BackColor = Color.FromArgb(0, 159, 200);
  193. panel_Merge.BackColor = Color.FromArgb(0, 159, 200);
  194. panel_SnCheck.BackColor = Color.FromArgb(0, 159, 200);
  195. }
  196. else if (panel_MergeMain.Visible == true)
  197. {
  198. panel_Merge.BackColor = Color.FromArgb(0, 159, 255);
  199. panel_Catm1Mode.BackColor = Color.FromArgb(0, 159, 200);
  200. panel_SensorMode.BackColor = Color.FromArgb(0, 159, 200);
  201. panel_GpsMode.BackColor = Color.FromArgb(0, 159, 200);
  202. panel_SnCheck.BackColor = Color.FromArgb(0, 159, 200);
  203. }
  204. else if(panel_SnCheckMain.Visible == true)
  205. {
  206. panel_Merge.BackColor = Color.FromArgb(0, 159, 200);
  207. panel_Catm1Mode.BackColor = Color.FromArgb(0, 159, 200);
  208. panel_SensorMode.BackColor = Color.FromArgb(0, 159, 200);
  209. panel_GpsMode.BackColor = Color.FromArgb(0, 159, 200);
  210. panel_SnCheck.BackColor = Color.FromArgb(0, 159, 255);
  211. }
  212. }
  213. private void label_SnCheck_MouseLeave(object sender, EventArgs e)
  214. {
  215. if (panel_GpsTest.Visible == true)
  216. {
  217. panel_Catm1Mode.BackColor = Color.FromArgb(0, 159, 200);
  218. panel_SensorMode.BackColor = Color.FromArgb(0, 159, 200);
  219. panel_GpsMode.BackColor = Color.FromArgb(0, 159, 255);
  220. panel_Merge.BackColor = Color.FromArgb(0, 159, 200);
  221. panel_SnCheck.BackColor = Color.FromArgb(0, 159, 200);
  222. }
  223. else if (panel_Catm1Test.Visible == true)
  224. {
  225. panel_Catm1Mode.BackColor = Color.FromArgb(0, 159, 255);
  226. panel_SensorMode.BackColor = Color.FromArgb(0, 159, 200);
  227. panel_GpsMode.BackColor = Color.FromArgb(0, 159, 200);
  228. panel_Merge.BackColor = Color.FromArgb(0, 159, 200);
  229. panel_SnCheck.BackColor = Color.FromArgb(0, 159, 200);
  230. }
  231. else if (panel_SensorTest.Visible == true)
  232. {
  233. panel_Catm1Mode.BackColor = Color.FromArgb(0, 159, 200);
  234. panel_SensorMode.BackColor = Color.FromArgb(0, 159, 255);
  235. panel_GpsMode.BackColor = Color.FromArgb(0, 159, 200);
  236. panel_Merge.BackColor = Color.FromArgb(0, 159, 200);
  237. panel_SnCheck.BackColor = Color.FromArgb(0, 159, 200);
  238. }
  239. else if (panel_MergeMain.Visible == true)
  240. {
  241. panel_Merge.BackColor = Color.FromArgb(0, 159, 255);
  242. panel_Catm1Mode.BackColor = Color.FromArgb(0, 159, 200);
  243. panel_SensorMode.BackColor = Color.FromArgb(0, 159, 200);
  244. panel_GpsMode.BackColor = Color.FromArgb(0, 159, 200);
  245. panel_SnCheck.BackColor = Color.FromArgb(0, 159, 200);
  246. }
  247. else if (panel_SnCheckMain.Visible == true)
  248. {
  249. panel_Merge.BackColor = Color.FromArgb(0, 159, 200);
  250. panel_Catm1Mode.BackColor = Color.FromArgb(0, 159, 200);
  251. panel_SensorMode.BackColor = Color.FromArgb(0, 159, 200);
  252. panel_GpsMode.BackColor = Color.FromArgb(0, 159, 200);
  253. panel_SnCheck.BackColor = Color.FromArgb(0, 159, 255);
  254. }
  255. }
  256. private void label_SnCheck_MouseMove(object sender, MouseEventArgs e)
  257. {
  258. panel_SnCheck.BackColor = Color.FromArgb(0, 159, 255);
  259. }
  260. private void label_Merge_MouseMove(object sender, MouseEventArgs e)
  261. {
  262. panel_Merge.BackColor = Color.FromArgb(0, 159, 255);
  263. }
  264. private void label_Catm1Test_MouseMove(object sender, MouseEventArgs e)
  265. {
  266. panel_Catm1Mode.BackColor = Color.FromArgb(0, 159, 255);
  267. }
  268. private void label_SensorTest_MouseMove(object sender, MouseEventArgs e)
  269. {
  270. panel_SensorMode.BackColor = Color.FromArgb(0, 159, 255);
  271. }
  272. private void label_GPSTest_MouseMove(object sender, MouseEventArgs e)
  273. {
  274. panel_GpsMode.BackColor = Color.FromArgb(0, 159, 255);
  275. }
  276. public struct POINT { public int X, Y; }
  277. [DllImport("user32.dll")] // 현재 마우스 위치를 얻기위한 API함수.
  278. public extern static void GetCursorPos(out POINT point);
  279. System.Drawing.Point FormLocation; // 현재 폼 위치
  280. POINT LastLocation = new POINT(); // 방금 전의 마우스 위치
  281. POINT CurrentLocation = new POINT(); // 현재 마우스 위치
  282. // 폼이 움직일 양 = CurrentLocation - LastLocation.
  283. bool IsMouseMoveStart = false; // 현재 마우스 움직이기 기능이 켜져있는가.
  284. // 만약 이게 없으면 그냥 폼위에서
  285. private void panel_Main_MouseDown(object sender, MouseEventArgs e)
  286. {
  287. GetCursorPos(out CurrentLocation);
  288. FormLocation = this.Location;
  289. IsMouseMoveStart = true;
  290. }
  291. private void panel_Main_MouseMove(object sender, MouseEventArgs e)
  292. {
  293. if (!IsMouseMoveStart) return;
  294. GetCursorPos(out LastLocation);
  295. FormLocation.X -= (CurrentLocation.X - LastLocation.X);
  296. FormLocation.Y -= (CurrentLocation.Y - LastLocation.Y);
  297. this.Location = FormLocation;
  298. CurrentLocation = LastLocation;
  299. }
  300. private void panel_Main_MouseUp(object sender, MouseEventArgs e)
  301. {
  302. IsMouseMoveStart = false;
  303. }
  304. private void pictureBox_min_red_Click(object sender, EventArgs e)
  305. {
  306. this.WindowState = FormWindowState.Minimized;
  307. }
  308. private void pictureBox_X_red_Click(object sender, EventArgs e)
  309. {
  310. //Application.Exit();
  311. }
  312. private void label_GPSTest_Click(object sender, EventArgs e)
  313. {
  314. panel_GpsTest.Visible = true;
  315. panel_SensorTest.Visible = false;
  316. panel_Catm1Test.Visible = false;
  317. panel_MergeMain.Visible = false;
  318. panel_SnCheckMain.Visible = false;
  319. }
  320. private void label_Catm1Test_Click(object sender, EventArgs e)
  321. {
  322. panel_GpsTest.Visible = false;
  323. panel_SensorTest.Visible = false;
  324. panel_Catm1Test.Visible = true;
  325. panel_MergeMain.Visible = false;
  326. panel_SnCheckMain.Visible = false;
  327. }
  328. private void label_SensorTest_Click(object sender, EventArgs e)
  329. {
  330. panel_GpsTest.Visible = false;
  331. panel_SensorTest.Visible = true;
  332. panel_Catm1Test.Visible = false;
  333. panel_MergeMain.Visible = false;
  334. panel_SnCheckMain.Visible = false;
  335. }
  336. private void Main_Load(object sender, EventArgs e)
  337. {
  338. Serial_Initialize(ref comboBox_Port);
  339. dataGridView_Gps.RowCount = 1;
  340. dataGridView_Catm1.RowCount = 1;
  341. dataGridView_Sensor.RowCount = 1;
  342. panel_GpsTest.Visible = true;
  343. panel_SensorTest.Visible = false;
  344. panel_Catm1Test.Visible = false;
  345. panel_MergeMain.Visible = false;
  346. panel_SnCheckMain.Visible = false;
  347. pictureBox_Check1.Visible = false;
  348. pictureBox_Check2.Visible = false;
  349. pictureBox_Check3.Visible = false;
  350. pictureBox_Check4.Visible = false;
  351. button_Path_Click(null,null);
  352. }
  353. public void Serial_Initialize(ref ComboBox cb_port)
  354. {
  355. this.serialPort = new System.IO.Ports.SerialPort();
  356. this.serialPort.DataReceived += new System.IO.Ports.SerialDataReceivedEventHandler(this.sPort_DataReceived);
  357. cb_port.BeginUpdate();
  358. foreach (string comport in SerialPort.GetPortNames())//foreach (string comport in SerialPort_TestProgram.GetPortNames())
  359. {
  360. cb_port.Items.Add(comport);
  361. }
  362. cb_port.EndUpdate();
  363. //SerialPort 초기 설정.
  364. // serialPort.Encoding = Encoding.GetEncoding("Windows-1252");
  365. cb_port.DataSource = SerialPort.GetPortNames();
  366. try
  367. {
  368. serialPort.PortName = Serial_Name = cb_port.SelectedItem.ToString();
  369. serialPort.BaudRate = (int)115200;
  370. serialPort.DataBits = (int)8;
  371. serialPort.Parity = System.IO.Ports.Parity.None;
  372. serialPort.StopBits = StopBits.One;
  373. }
  374. catch { }
  375. }
  376. private delegate void StringSend(string Text);
  377. private delegate void ByteSend(byte[] Text);
  378. string startStr ="V";
  379. string endStr = "\n";
  380. public void Serial_DataRecvFunction(object sender, SerialDataReceivedEventArgs e)
  381. {
  382. int TmpLength = 0;
  383. //System.Threading.Thread.Sleep(50);
  384. int nLnegth = serialPort.BytesToRead;
  385. byte[] btdata = new byte[nLnegth];
  386. serialPort.Read(btdata, 0, nLnegth);
  387. string data = Encoding.Default.GetString(btdata);
  388. if (checkBox_TerminalStop.Checked == true)
  389. return;
  390. // string data = serialPort.ReadExisting();
  391. if (panel_SensorTest.Visible == true)
  392. {
  393. if (data.Contains(startStr))
  394. {
  395. data = data.Substring(data.IndexOf(startStr));
  396. if (data.Contains(endStr))
  397. {
  398. this.Invoke(new StringSend(Data_Recv_Str), data);
  399. }
  400. }
  401. else
  402. {
  403. if (data.Contains("No need write SN"))
  404. {
  405. MessageBox.Show("이미 시리얼 넘버가 등록되어 있습니다.");
  406. }
  407. else
  408. {
  409. this.Invoke(new StringSend(Data_Recv_Str), data);
  410. }
  411. }
  412. }
  413. else
  414. {
  415. this.Invoke(new StringSend(Data_Recv_Str), data);
  416. }
  417. /*try
  418. {
  419. this.Invoke(new ByteSend(Data_Recv_Str), btdata);
  420. }
  421. catch
  422. {
  423. }*/
  424. /****
  425. *메모리 누수 방지용 코드
  426. */
  427. System.GC.Collect(0, GCCollectionMode.Forced);
  428. System.GC.WaitForFullGCComplete();
  429. }
  430. int offset = 0;
  431. byte[] rxBuffer;
  432. private void sPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
  433. {
  434. if (offset == 0)
  435. {
  436. rxBuffer = new byte[4096];
  437. }
  438. string rxString = "";
  439. int intRecSize = serialPort.BytesToRead;
  440. if (intRecSize != 0)
  441. {
  442. serialPort.Read(rxBuffer, offset, intRecSize);
  443. offset += intRecSize;
  444. for (int iTemp = 0; iTemp < offset; iTemp++)
  445. {
  446. rxString += Convert.ToChar(rxBuffer[iTemp]);
  447. }
  448. if (panel_SensorTest.Visible == true)
  449. {
  450. startStr = "V";
  451. endStr = "\n";
  452. if (rxString.Contains(startStr))
  453. {
  454. rxString = rxString.Substring(rxString.IndexOf(startStr));
  455. if (rxString.Contains(endStr))
  456. {
  457. this.Invoke(new StringSend(Data_Recv_Str), rxString);
  458. //program.dataReceived(rxString, "Receive");
  459. offset = 0;
  460. }
  461. }
  462. }
  463. else if (panel_Catm1Test.Visible == true)
  464. {
  465. startStr = "B";
  466. endStr = "\n";
  467. if (rxString.Contains(startStr))
  468. {
  469. rxString = rxString.Substring(rxString.IndexOf(startStr));
  470. if (rxString.Contains(endStr))
  471. {
  472. this.Invoke(new StringSend(Data_Recv_Str), rxString);
  473. //program.dataReceived(rxString, "Receive");
  474. offset = 0;
  475. }
  476. }
  477. }
  478. else
  479. {
  480. this.Invoke(new StringSend(Data_Recv_Str), rxString);
  481. }
  482. }
  483. }
  484. private void label_Port_MouseClick(object sender, MouseEventArgs e)
  485. {
  486. }
  487. int LineLimit = 500;
  488. [DllImport("user32.dll")]
  489. public static extern int SendMessage(IntPtr hWnd, Int32 wMsg, bool wParam, Int32 lParam);
  490. private const int WM_SETREDRAW = 11;
  491. public void Data_Recv_Str(string text)
  492. {
  493. System.Windows.Forms.RichTextBox tbReceived = null;
  494. if (panel_GpsTest.Visible == true) {
  495. tbReceived = richTextBox_Gps;
  496. }
  497. else if (panel_Catm1Test.Visible == true) {
  498. tbReceived = richTextBox_catm1;
  499. }
  500. else if (panel_SensorTest.Visible == true) {
  501. tbReceived = richTextBox_Sensor;
  502. }
  503. int nLimitLines = Convert.ToInt32(LineLimit); //제한 라인 수
  504. try
  505. {
  506. try
  507. {
  508. SendMessage(this.Handle, WM_SETREDRAW, false, 0);
  509. }
  510. catch (Exception e) { MessageBox.Show(e.StackTrace); }
  511. if (tbReceived.Lines.Length > nLimitLines)
  512. {
  513. LinkedList<string> tempLines = new LinkedList<string>(tbReceived.Lines);
  514. while ((tempLines.Count - nLimitLines) > 0)
  515. {
  516. tempLines.RemoveFirst();
  517. }
  518. tbReceived.Lines = tempLines.ToArray();
  519. }
  520. try
  521. {
  522. SendMessage(this.Handle, WM_SETREDRAW, true, 0);
  523. }
  524. catch { return; }
  525. if (checkBox_GPGSV.Checked == true && panel_GpsTest.Visible == true)
  526. {
  527. tbReceived.AppendText(GPS_TestFunc(text));
  528. }
  529. else if(panel_SensorTest.Visible == true)
  530. {
  531. Sensor_TestFunc(text);
  532. tbReceived.AppendText(text);
  533. }
  534. else if (panel_Catm1Test.Visible == true)
  535. {
  536. Catm1_TestFunc(text);
  537. tbReceived.AppendText(text);
  538. }
  539. else
  540. {
  541. tbReceived.AppendText(text);
  542. }
  543. tbReceived.SelectionStart = tbReceived.Text.Length;//맨 마지막 선택...
  544. tbReceived.ScrollToCaret();
  545. }
  546. catch { try { SendMessage(this.Handle, WM_SETREDRAW, true, 0); } catch { return; } }
  547. }
  548. public void Data_Recv_Str(byte[] text)
  549. {
  550. string strtext = Encoding.Default.GetString(text);
  551. System.Windows.Forms.RichTextBox tbReceived = null;
  552. if (panel_GpsTest.Visible == true)
  553. {
  554. tbReceived = richTextBox_Gps;
  555. }
  556. else if (panel_Catm1Test.Visible == true)
  557. {
  558. tbReceived = richTextBox_catm1;
  559. }
  560. else if (panel_SensorTest.Visible == true)
  561. {
  562. tbReceived = richTextBox_Sensor;
  563. }
  564. int nLimitLines = Convert.ToInt32(LineLimit); //제한 라인 수
  565. try
  566. {
  567. try
  568. {
  569. SendMessage(this.Handle, WM_SETREDRAW, false, 0);
  570. }
  571. catch (Exception e) { MessageBox.Show(e.StackTrace); }
  572. if (tbReceived.Lines.Length > nLimitLines)
  573. {
  574. LinkedList<string> tempLines = new LinkedList<string>(tbReceived.Lines);
  575. while ((tempLines.Count - nLimitLines) > 0)
  576. {
  577. tempLines.RemoveFirst();
  578. }
  579. tbReceived.Lines = tempLines.ToArray();
  580. }
  581. try
  582. {
  583. SendMessage(this.Handle, WM_SETREDRAW, true, 0);
  584. }
  585. catch { return; }
  586. if (checkBox_GPGSV.Checked == true && panel_GpsTest.Visible == true)
  587. {
  588. tbReceived.AppendText(GPS_TestFunc(Encoding.Default.GetString(text)));
  589. }
  590. else if (panel_SensorTest.Visible == true)
  591. {
  592. Sensor_TestFunc(strtext);
  593. tbReceived.AppendText(strtext);
  594. }
  595. else
  596. {
  597. tbReceived.AppendText(strtext);
  598. }
  599. tbReceived.SelectionStart = tbReceived.Text.Length;//맨 마지막 선택...
  600. tbReceived.ScrollToCaret();
  601. }
  602. catch { try { SendMessage(this.Handle, WM_SETREDRAW, true, 0); } catch { return; } }
  603. }
  604. public int WordNum(String data, String fixdata)
  605. {
  606. MatchCollection matches = Regex.Matches(data, fixdata);
  607. return matches.Count;
  608. }
  609. double GPS_TestSnRValue = 0;
  610. int Gps_CurrentCount = 0;
  611. int TestVal = 0;
  612. private string GPS_TestFunc(string data)
  613. {
  614. int Gps_Count, Sentence, SnrIndex = 3;
  615. // string tmpstr = "$GPGSV,2,1,08,10,69,246,47,12,50,082,43,15,12,108,29,20,49,190,45*77\r\n";
  616. // string tmpstr1 = "$GPGSV,2,2,08,24,36,052,37,25,48,159,42,31,17,245,,32,46,312,45*74\r\n";
  617. string[] tmpstr = new String[3];
  618. string splitstr = null, str = data;
  619. string[] sp = str.Split(',');
  620. int Losscount = 0;
  621. int location1, location2, LastLocation, SentenceCount;
  622. try
  623. {
  624. /*
  625. if(TestVal == 0)
  626. {
  627. str = tmpstr;
  628. TestVal++;
  629. }
  630. else
  631. {
  632. str = tmpstr1;
  633. TestVal = 0;
  634. }
  635. */
  636. location1 = str.IndexOf("$GPGSV");
  637. SentenceCount = WordNum(str, "GPGSV");
  638. GPS_TestSnRValue = 0;
  639. Gps_CurrentCount = 0;
  640. if (location1 != -1)
  641. {
  642. for (int ii = 0; ii < SentenceCount; ii++)
  643. {
  644. SnrIndex = 3;
  645. if (ii != 0)
  646. str = splitstr;
  647. location1 = str.IndexOf("$GPGSV");
  648. str = str.Substring(location1);
  649. location2 = str.IndexOf("\r\n");
  650. splitstr = str.Substring(location2 + 2);
  651. tmpstr[ii] = str = str.Substring(0, location2 + 2);
  652. sp = str.Split(',');
  653. if (sp[3].Contains("*"))
  654. {
  655. sp[3] = sp[3].Substring(0, 2);
  656. dataGridView_Gps.Rows[0].Cells[1].Value = sp[3];
  657. return str;
  658. }
  659. else
  660. {
  661. Sentence = Convert.ToInt32(sp[2]);
  662. Gps_Count = Convert.ToInt32(sp[3]);
  663. for (int i = 0; i < 4; i++)
  664. {
  665. SnrIndex += 4;
  666. if (sp[SnrIndex].Contains("*"))
  667. {
  668. LastLocation = sp[SnrIndex].IndexOf("*") - 2;
  669. sp[SnrIndex] = sp[SnrIndex].Substring(0, 2);
  670. GPS_TestSnRValue += Convert.ToInt32(sp[SnrIndex]);
  671. }
  672. else
  673. {
  674. if (sp[SnrIndex] == "")
  675. {
  676. sp[SnrIndex] = "0";
  677. Losscount++;
  678. }
  679. GPS_TestSnRValue += Convert.ToInt32(sp[SnrIndex]);
  680. }
  681. Gps_CurrentCount++;
  682. if (Gps_CurrentCount == Gps_Count)
  683. {
  684. GPS_TestSnRValue /= (Gps_Count - Losscount);
  685. GPS_TestSnRValue = Math.Round(GPS_TestSnRValue, 1);
  686. dataGridView_Gps.Rows[0].Cells[1].Value = GPS_TestSnRValue.ToString();
  687. break;
  688. }
  689. }
  690. }
  691. }
  692. str = null;
  693. for (int a = 0; a < SentenceCount; a++)
  694. str += tmpstr[a];
  695. if (dataGridView_Sensor.Rows[0].Cells[0].Value != null)
  696. {
  697. button_GpsTestSave_Click(null, null);
  698. }
  699. return str;
  700. }
  701. return "";
  702. }
  703. catch (Exception e) { /*MessageBox.Show(e.StackTrace); */}
  704. return "";
  705. }
  706. string SensorData = null;
  707. private void Sensor_TestFunc(string data)
  708. {
  709. string str = data;
  710. string[] sp = new string[11];
  711. try
  712. {
  713. if (data.Contains("\r\n") == false)
  714. {
  715. return;
  716. }
  717. else
  718. {
  719. SensorData += data;
  720. str = SensorData;
  721. }
  722. if (dataGridView_Sensor.Rows[0].Cells[0].Value != null)
  723. {
  724. //location1 = str.IndexOf("\r\n");
  725. //str = str.Substring(0, location1);
  726. sp = str.Split(',');
  727. if (sp[0].Contains("V") == false/* || sp.Length != 11*/)
  728. {
  729. SensorData = null;
  730. return;
  731. }
  732. dataGridView_Sensor.Rows[0].Cells[5].Value = sp[0]; //version
  733. dataGridView_Sensor.Rows[0].Cells[2].Value = sp[2]; //,IMEI
  734. dataGridView_Sensor.Rows[0].Cells[3].Value = sp[3];//, Phone Number,
  735. dataGridView_Sensor.Rows[0].Cells[4].Value = sp[4];//USIM Number
  736. dataGridView_Sensor.Rows[0].Cells[6].Value = sp[5];//, Battery Voltage,
  737. dataGridView_Sensor.Rows[0].Cells[7].Value = sp[6];// System Voltage,
  738. dataGridView_Sensor.Rows[0].Cells[8].Value = sp[7];//Temp, BMA400 값 출력 x, y, z
  739. dataGridView_Sensor.Rows[0].Cells[9].Value = sp[8];//Temp, BMA400 값 출력 x, y, z
  740. dataGridView_Sensor.Rows[0].Cells[10].Value = sp[9];//Temp, BMA400 값 출력 x, y, z
  741. if (sp[10].Contains("\r"))
  742. {
  743. int loc = sp[10].IndexOf("\r");
  744. sp[10] = sp[10].Substring(0, loc);
  745. }
  746. dataGridView_Sensor.Rows[0].Cells[11].Value = sp[10];//Temp, BMA400 값 출력 x, y, z
  747. SensorData = null;
  748. string value = "";
  749. if (checkBox_Edit.Checked == false)
  750. {
  751. if (InputBox("번호 입력", "일련 번호:", ref value) == DialogResult.OK)
  752. {
  753. // SN
  754. dataGridView_Sensor.Rows[0].Cells[1].Value = Name = value;
  755. serialPort.Write("APLSN Write:" + value + "\r\n");
  756. button_SensorTestSave();
  757. for (int i = 0; i < 12; i++)
  758. dataGridView_Sensor.Rows[0].Cells[i].Value = null;
  759. }
  760. }
  761. dataGridView_Sensor.Refresh();
  762. }
  763. return;
  764. }
  765. catch (Exception ex) { /*MessageBox.Show(ex.StackTrace); */ }
  766. }
  767. string Catm1Data = null;
  768. private void Catm1_TestFunc(string data)
  769. {
  770. string str = data;
  771. string[] sp = new string[4];
  772. try
  773. {
  774. if (data.Contains("\r\n") == false)
  775. {
  776. return;
  777. }
  778. else
  779. {
  780. Catm1Data += data;
  781. str = Catm1Data;
  782. }
  783. //if (dataGridView_Catm1.Rows[0].Cells[0].Value != null)
  784. {
  785. //location1 = str.IndexOf("\r\n");
  786. //str = str.Substring(0, location1);
  787. sp = str.Split(',');
  788. if (sp[0].Contains("B") == false/* || sp.Length != 11*/)
  789. {
  790. Catm1Data = null;
  791. return;
  792. }
  793. dataGridView_Catm1.Rows[0].Cells[1].Value = sp[0]; //Modem Ver
  794. dataGridView_Catm1.Rows[0].Cells[2].Value = sp[1];//RSRP
  795. if (sp[2].Contains("\r"))
  796. {
  797. int loc = sp[2].IndexOf("\r");
  798. sp[2] = sp[2].Substring(0, loc);
  799. }
  800. dataGridView_Catm1.Rows[0].Cells[3].Value = sp[2];//RSRQ
  801. Catm1Data = null;
  802. dataGridView_Catm1.Refresh();
  803. }
  804. return;
  805. }
  806. catch (Exception ex) { /*MessageBox.Show(ex.StackTrace); */ }
  807. }
  808. private void label_Port_MouseLeave(object sender, EventArgs e)
  809. {
  810. panel_Port.BackColor = Color.FromArgb(0, 159, 200);
  811. }
  812. private void label_Port_MouseMove(object sender, MouseEventArgs e)
  813. {
  814. panel_Port.BackColor = Color.FromArgb(0, 159, 255);
  815. }
  816. private void label_Port_Click(object sender, EventArgs e)
  817. {
  818. // Boolean ret = false;
  819. try
  820. {
  821. if (serialPort.IsOpen) // 이미 포트가 열려 있을 때
  822. { //When the port is open
  823. serialPort.Close();
  824. label_Port.Text = "Port Open";
  825. //ret = true;
  826. }
  827. else//When the port is close //포트가 열려 있지 않을 때
  828. {
  829. if (comboBox_Port.Text != "")
  830. {
  831. serialPort.PortName = Serial_Name = comboBox_Port.SelectedItem.ToString();
  832. serialPort.BaudRate = Convert.ToInt32(comboBox_bps.Text);
  833. serialPort.Open();
  834. label_Port.Text = "Port Close";
  835. // Debug.Debug_Main_Form_Get(this.main_form);
  836. }
  837. else
  838. {
  839. MessageBox.Show("Port is not set");
  840. // ret = true;
  841. }
  842. }
  843. }
  844. catch
  845. {
  846. MessageBox.Show("Port Open Faile" + Serial_Name);
  847. }
  848. // return ret;
  849. }
  850. public static DialogResult InputBox(string title, string promptText, ref string value)
  851. {
  852. Form form = new Form();
  853. System.Windows.Forms.Label label = new System.Windows.Forms.Label();
  854. System.Windows.Forms.TextBox textBox = new System.Windows.Forms.TextBox();
  855. System.Windows.Forms.Button buttonOk = new System.Windows.Forms.Button();
  856. System.Windows.Forms.Button buttonCancel = new System.Windows.Forms.Button();
  857. form.Text = title;
  858. label.Text = promptText;
  859. textBox.Text = value;
  860. buttonOk.Text = "OK";
  861. buttonCancel.Text = "Cancel";
  862. buttonOk.DialogResult = DialogResult.OK;
  863. buttonCancel.DialogResult = DialogResult.Cancel;
  864. label.SetBounds(9, 20, 372, 13);
  865. textBox.SetBounds(12, 36, 372, 20);
  866. buttonOk.SetBounds(228, 72, 75, 23);
  867. buttonCancel.SetBounds(309, 72, 75, 23);
  868. label.AutoSize = true;
  869. textBox.Anchor = textBox.Anchor | AnchorStyles.Right;
  870. buttonOk.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
  871. buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
  872. form.ClientSize = new Size(396, 107);
  873. form.Controls.AddRange(new Control[] { label, textBox, buttonOk, buttonCancel });
  874. form.ClientSize = new Size(Math.Max(300, label.Right + 10), form.ClientSize.Height);
  875. form.FormBorderStyle = FormBorderStyle.FixedDialog;
  876. form.StartPosition = FormStartPosition.CenterScreen;
  877. form.MinimizeBox = false;
  878. form.MaximizeBox = false;
  879. form.AcceptButton = buttonOk;
  880. form.CancelButton = buttonCancel;
  881. DialogResult dialogResult = form.ShowDialog();
  882. value = textBox.Text;
  883. return dialogResult;
  884. }
  885. private void button_Clear_Click(object sender, EventArgs e)
  886. {
  887. System.Windows.Forms.RichTextBox tbReceived = null;
  888. if (panel_GpsTest.Visible == true)
  889. {
  890. tbReceived = richTextBox_Gps;
  891. }
  892. else if (panel_Catm1Test.Visible == true)
  893. {
  894. tbReceived = richTextBox_catm1;
  895. }
  896. else if (panel_SensorTest.Visible == true)
  897. {
  898. tbReceived = richTextBox_Sensor;
  899. }
  900. tbReceived.Text = "";
  901. }
  902. string FileSaveSet = null;
  903. void Gps_ThreadRun(string dst,object Value1, object Value2)
  904. {
  905. //DST : 위치
  906. //Value1 : 생산 번호
  907. //Value2 : SNR
  908. Thread Gps_thread = new Thread(delegate ()
  909. {
  910. Gps_DataxlsWrite(dst, Value1, Value2);
  911. });
  912. Gps_thread.Start();
  913. }
  914. void Catm1_ThreadRun(object dst, object Product, object Modemver, object Rsrp, object Rsrq)
  915. {
  916. //DST : 위치
  917. //Value1 : 생산 번호
  918. //Value2 : Modem Ver
  919. //Value3 : RSRP
  920. //Value4 : RSRQ
  921. Thread Catm1_thread = new Thread(delegate ()
  922. {
  923. Catm1_DataxlsWrite(dst, Product, Modemver, Rsrp, Rsrq);
  924. });
  925. Catm1_thread.Start();
  926. }
  927. //Thread rTh_Gps;
  928. private void button_GpsTestSave_Click(object sender, EventArgs e)
  929. {
  930. //rTh_Gps = new Thread(new ParameterizedThreadStart(Gps_DataxlsWrite));
  931. //Thread.Sleep(1000);
  932. AutoClosingMessageBox.Show("저장 중.....", "알림", 1000);
  933. string CheckProductionNum = null;
  934. try
  935. {
  936. CheckProductionNum = dataGridView_Gps.Rows[0].Cells[0].Value.ToString();
  937. }
  938. catch
  939. {
  940. }
  941. try
  942. {
  943. if (!CheckProductionNum.Contains("BL-VITE00-V"))
  944. {
  945. MessageBox.Show("잘못된 생산 번호 입니다.");
  946. return;
  947. }
  948. }catch
  949. {
  950. MessageBox.Show("생산번호를 적어주세요.");
  951. }
  952. string Ref_Xls_File = new System.IO.DirectoryInfo(System.Windows.Forms.Application.StartupPath).ToString();
  953. string Dst_Xls_File = null;
  954. Ref_Xls_File = Ref_Xls_File + @"\APL_200303.xls";
  955. FileInfo SrcfileInfo = new FileInfo(Ref_Xls_File);
  956. FileInfo DstfileInfo;
  957. if (dataGridView_Gps.Rows[0].Cells[0].Value != null
  958. && dataGridView_Gps.Rows[0].Cells[1].Value != null)
  959. {
  960. if (SrcfileInfo.Exists)
  961. {
  962. if (FileSaveSet == null)
  963. {
  964. button_Path_Click(null, null);
  965. return;
  966. // MessageBox.Show("레퍼런스 엑셀 파일이 존재하지 않습니다. \r\n강차장님에게 문의 하세요.");
  967. }
  968. else
  969. {
  970. // File Copy 후 Data 입력
  971. Dst_Xls_File = FileSaveSet + @"\" + dataGridView_Gps.Rows[0].Cells[0].Value.ToString() + @".xls";
  972. DstfileInfo = new FileInfo(Dst_Xls_File);
  973. if (DstfileInfo.Exists)
  974. {
  975. if (MessageBox.Show("이미 파일이 있습니다.\r\n 덮어씌우겠습니까?", "YesOrNo", MessageBoxButtons.YesNo) == DialogResult.Yes)
  976. {
  977. try
  978. {
  979. // File.Copy(Ref_Xls_File, Dst_Xls_File, true);
  980. }
  981. catch (Exception ex)
  982. {
  983. MessageBox.Show(ex.StackTrace);
  984. return;
  985. }
  986. }
  987. else
  988. {
  989. //MessageBox.Show("아니요 클릭");
  990. return; // 아니오시 Return;
  991. }
  992. }
  993. else
  994. {
  995. File.Copy(Ref_Xls_File, Dst_Xls_File);
  996. Thread.Sleep(2000);
  997. }
  998. }
  999. }
  1000. else
  1001. {
  1002. MessageBox.Show("레퍼런스 엑셀 파일이 존재하지 않습니다. \r\n강차장님에게 문의 하세요.");
  1003. return;
  1004. }
  1005. }
  1006. else
  1007. {
  1008. MessageBox.Show("생산번호/GPS SNR 값이 제대로 입력 되지 않았습니다.\r\n확인후 다시 저장하세요.");
  1009. return;
  1010. }
  1011. // rTh_Gps.Start();
  1012. //Gps_DataxlsWrite(Dst_Xls_File, dataGridView_Gps.Rows[0].Cells[0].Value, dataGridView_Gps.Rows[0].Cells[1].Value);
  1013. Gps_ThreadRun(Dst_Xls_File, dataGridView_Gps.Rows[0].Cells[0].Value, dataGridView_Gps.Rows[0].Cells[1].Value);
  1014. dataGridView_Gps.Rows[0].Cells[0].Value = null;
  1015. dataGridView_Gps.Rows[0].Cells[1].Value = null;
  1016. dataGridView_Gps.Refresh();
  1017. // if (!di.Exists) { di.Create(); }
  1018. //string tmppath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
  1019. #if false
  1020. if (dataGridView_Gps.Rows[0].Cells[1].Value != null)
  1021. {
  1022. string path = @"xxxx.txt";
  1023. FileInfo file = new FileInfo(path);
  1024. if (file.Exists)
  1025. { //파일이 있는지
  1026. //복사(경로,덮어쓰기 옵션 기본값 false)
  1027. //만약 덮어쓰기 false일 때 파일이 존재하면 에러남.
  1028. file.CopyTo(@"xxx2.txt", true);
  1029. }
  1030. }
  1031. #endif
  1032. AutoClosingMessageBox.Show("완료 되었습니다.", "알림", 1000);
  1033. //this.Close();
  1034. //MessageBox.
  1035. }
  1036. private void button_SensorTestSave()
  1037. {
  1038. string CheckProductionNum = null;
  1039. try
  1040. {
  1041. CheckProductionNum = dataGridView_Sensor.Rows[0].Cells[0].Value.ToString();
  1042. }
  1043. catch
  1044. {
  1045. }
  1046. try
  1047. {
  1048. if (!CheckProductionNum.Contains("BL-VITE00-V"))
  1049. {
  1050. MessageBox.Show("잘못된 생산 번호 입니다.");
  1051. return;
  1052. }
  1053. }
  1054. catch
  1055. {
  1056. MessageBox.Show("생산번호를 적어주세요.");
  1057. }
  1058. string Ref_Xls_File = new System.IO.DirectoryInfo(System.Windows.Forms.Application.StartupPath).ToString();
  1059. string Dst_Xls_File = null;
  1060. Ref_Xls_File = Ref_Xls_File + @"\APL_200303.xls";
  1061. FileInfo SrcfileInfo = new FileInfo(Ref_Xls_File);
  1062. FileInfo DstfileInfo;
  1063. if (dataGridView_Sensor.Rows[0].Cells[0].Value != null)
  1064. {
  1065. if (SrcfileInfo.Exists)
  1066. {
  1067. if (FileSaveSet == null)
  1068. {
  1069. button_Path_Click(null, null);
  1070. return;
  1071. // MessageBox.Show("레퍼런스 엑셀 파일이 존재하지 않습니다. \r\n강차장님에게 문의 하세요.");
  1072. }
  1073. else
  1074. {
  1075. // File Copy 후 Data 입력
  1076. Dst_Xls_File = FileSaveSet + @"\" + dataGridView_Sensor.Rows[0].Cells[0].Value.ToString() + @".xls";
  1077. DstfileInfo = new FileInfo(Dst_Xls_File);
  1078. if (DstfileInfo.Exists)
  1079. {
  1080. if (MessageBox.Show("이미 파일이 있습니다.\r\n 덮어씌우겠습니까?", "YesOrNo", MessageBoxButtons.YesNo) == DialogResult.Yes)
  1081. {
  1082. try
  1083. {
  1084. // File.Copy(Ref_Xls_File, Dst_Xls_File, true);
  1085. }
  1086. catch (Exception ex)
  1087. {
  1088. MessageBox.Show(ex.StackTrace);
  1089. return;
  1090. }
  1091. }
  1092. else
  1093. {
  1094. //MessageBox.Show("아니요 클릭");
  1095. return; // 아니오시 Return;
  1096. }
  1097. }
  1098. else
  1099. {
  1100. File.Copy(Ref_Xls_File, Dst_Xls_File);
  1101. Thread.Sleep(2000);
  1102. }
  1103. }
  1104. }
  1105. else
  1106. {
  1107. MessageBox.Show("레퍼런스 엑셀 파일이 존재하지 않습니다. \r\n강차장님에게 문의 하세요.");
  1108. return;
  1109. }
  1110. }
  1111. else
  1112. {
  1113. MessageBox.Show("생산번호 값이 제대로 입력 되지 않았습니다.\r\n확인후 다시 저장하세요.");
  1114. return;
  1115. }
  1116. Sensor_DataxlsWrite(Dst_Xls_File);
  1117. // dataGridView_Sensor.Rows[0].Cells[0].Value = null;
  1118. // dataGridView_Sensor.Rows[0].Cells[1].Value = null;
  1119. // if (!di.Exists) { di.Create(); }
  1120. //string tmppath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
  1121. #if false
  1122. if (dataGridView_Gps.Rows[0].Cells[1].Value != null)
  1123. {
  1124. string path = @"xxxx.txt";
  1125. FileInfo file = new FileInfo(path);
  1126. if (file.Exists)
  1127. { //파일이 있는지
  1128. //복사(경로,덮어쓰기 옵션 기본값 false)
  1129. //만약 덮어쓰기 false일 때 파일이 존재하면 에러남.
  1130. file.CopyTo(@"xxx2.txt", true);
  1131. }
  1132. }
  1133. #endif
  1134. }
  1135. private void button_Catm1TestSave()
  1136. {
  1137. string CheckProductionNum = null;
  1138. try
  1139. {
  1140. CheckProductionNum = dataGridView_Catm1.Rows[0].Cells[0].Value.ToString();
  1141. }
  1142. catch
  1143. {
  1144. }
  1145. try
  1146. {
  1147. if (!CheckProductionNum.Contains("BL-VITE00-V"))
  1148. {
  1149. MessageBox.Show("잘못된 생산 번호 입니다.");
  1150. return;
  1151. }
  1152. }
  1153. catch
  1154. {
  1155. MessageBox.Show("생산번호를 적어주세요.");
  1156. }
  1157. string Ref_Xls_File = new System.IO.DirectoryInfo(System.Windows.Forms.Application.StartupPath).ToString();
  1158. string Dst_Xls_File = null;
  1159. Ref_Xls_File = Ref_Xls_File + @"\APL_200303.xls";
  1160. FileInfo SrcfileInfo = new FileInfo(Ref_Xls_File);
  1161. FileInfo DstfileInfo;
  1162. if (dataGridView_Catm1.Rows[0].Cells[0].Value != null)
  1163. {
  1164. if (SrcfileInfo.Exists)
  1165. {
  1166. if (FileSaveSet == null)
  1167. {
  1168. button_Path_Click(null, null);
  1169. return;
  1170. // MessageBox.Show("레퍼런스 엑셀 파일이 존재하지 않습니다. \r\n강차장님에게 문의 하세요.");
  1171. }
  1172. else
  1173. {
  1174. // File Copy 후 Data 입력
  1175. Dst_Xls_File = FileSaveSet + @"\" + dataGridView_Catm1.Rows[0].Cells[0].Value.ToString() + @".xls";
  1176. DstfileInfo = new FileInfo(Dst_Xls_File);
  1177. if (DstfileInfo.Exists)
  1178. {
  1179. if (MessageBox.Show("이미 파일이 있습니다.\r\n 덮어씌우겠습니까?", "YesOrNo", MessageBoxButtons.YesNo) == DialogResult.Yes)
  1180. {
  1181. try
  1182. {
  1183. // File.Copy(Ref_Xls_File, Dst_Xls_File, true);
  1184. }
  1185. catch (Exception ex)
  1186. {
  1187. MessageBox.Show(ex.StackTrace);
  1188. return;
  1189. }
  1190. }
  1191. else
  1192. {
  1193. //MessageBox.Show("아니요 클릭");
  1194. return; // 아니오시 Return;
  1195. }
  1196. }
  1197. else
  1198. {
  1199. File.Copy(Ref_Xls_File, Dst_Xls_File);
  1200. Thread.Sleep(2000);
  1201. }
  1202. }
  1203. }
  1204. else
  1205. {
  1206. MessageBox.Show("레퍼런스 엑셀 파일이 존재하지 않습니다. \r\n강차장님에게 문의 하세요.");
  1207. return;
  1208. }
  1209. }
  1210. else
  1211. {
  1212. MessageBox.Show("생산번호 값이 제대로 입력 되지 않았습니다.\r\n확인후 다시 저장하세요.");
  1213. return;
  1214. }
  1215. Catm1_ThreadRun(Dst_Xls_File, dataGridView_Catm1.Rows[0].Cells[0].Value, dataGridView_Catm1.Rows[0].Cells[1].Value, dataGridView_Catm1.Rows[0].Cells[2].Value, dataGridView_Catm1.Rows[0].Cells[3].Value);
  1216. for (int i = 0; i < 4; i++)
  1217. dataGridView_Catm1.Rows[0].Cells[i].Value = null;
  1218. //Catm1_DataxlsWrite(Dst_Xls_File, dataGridView_Catm1.Rows[0].Cells[0].Value, dataGridView_Catm1.Rows[0].Cells[1].Value, dataGridView_Catm1.Rows[0].Cells[2].Value, dataGridView_Catm1.Rows[0].Cells[3].Value);
  1219. // dataGridView_Catm1.Rows[0].Cells[0].Value = null;
  1220. // dataGridView_Catm1.Rows[0].Cells[1].Value = null;
  1221. // if (!di.Exists) { di.Create(); }
  1222. //string tmppath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
  1223. #if false
  1224. if (dataGridView_Gps.Rows[0].Cells[1].Value != null)
  1225. {
  1226. string path = @"xxxx.txt";
  1227. FileInfo file = new FileInfo(path);
  1228. if (file.Exists)
  1229. { //파일이 있는지
  1230. //복사(경로,덮어쓰기 옵션 기본값 false)
  1231. //만약 덮어쓰기 false일 때 파일이 존재하면 에러남.
  1232. file.CopyTo(@"xxx2.txt", true);
  1233. }
  1234. }
  1235. #endif
  1236. }
  1237. private void ExcelKill()
  1238. {
  1239. System.Diagnostics.Process[] process = System.Diagnostics.Process.GetProcessesByName("EXCEL");
  1240. foreach (System.Diagnostics.Process p in process)
  1241. {
  1242. if (!string.IsNullOrEmpty(p.ProcessName))
  1243. {
  1244. try
  1245. {
  1246. p.Kill();
  1247. }
  1248. catch { }
  1249. }
  1250. }
  1251. }
  1252. Excel.Application ExcelApp = null;
  1253. Excel.Workbook wb = null;
  1254. Excel.Worksheet ws = null;
  1255. private void Gps_DataxlsWrite(object dst, object Value1, object Value2)
  1256. {
  1257. /* #region // 프로세스 얻기
  1258. System.Diagnostics.Process[] BeforeExcelProcess;
  1259. BeforeExcelProcess = System.Diagnostics.Process.GetProcessesByName("EXCEL");
  1260. ArrayList arlProcessID = new ArrayList();
  1261. for (int i = 0; i < BeforeExcelProcess.Length; i++)
  1262. {
  1263. arlProcessID.Add(BeforeExcelProcess[i].Id);
  1264. }
  1265. #endregion
  1266. */
  1267. ExcelKill();
  1268. //Write
  1269. //파일이 존재 한다면..삭제 하고..
  1270. /*if (File.Exists("C:\\Test.xls"))
  1271. {
  1272. File.Delete("C:\\Test.xls");
  1273. }*/
  1274. try
  1275. {
  1276. ExcelApp = new Excel.Application();
  1277. Thread.Sleep(1);
  1278. try
  1279. {
  1280. wb = ExcelApp.Workbooks.Open(dst.ToString(), 0, false, 5, Missing.Value, Missing.Value, false, Missing.Value,
  1281. Missing.Value, true, false, Missing.Value, false, false, false);
  1282. }
  1283. catch { ExcelKill(); return; }
  1284. Thread.Sleep(1);
  1285. ws = wb.Worksheets["Sheet1"] as Excel.Worksheet;
  1286. Thread.Sleep(1);
  1287. /*ExcelApp = new Excel.Application();
  1288. wb = ExcelApp.Workbooks.Open(dst.ToString(), 0, false, 5, Missing.Value, Missing.Value, false, Missing.Value,
  1289. Missing.Value, true, false, Missing.Value, false, false, false);
  1290. wb = ExcelApp.Workbooks.Open(dst.ToString());*/
  1291. ws = wb.Worksheets["Sheet1"] as Excel.Worksheet;
  1292. //엑셀 시트 인덱스 번호는 0,0 부터 시작 하는 것이 아니라 1,1 A1 부터 시작 함. 0,0 으로 시작하면 오류...
  1293. //시트에 값 쓰기...
  1294. ws.Cells[8, 9] = Value1.ToString();//dataGridView_Gps.Rows[0].Cells[0].Value;
  1295. ws.Cells[8, 11] = Value2.ToString();//dataGridView_Gps.Rows[0].Cells[1].Value;
  1296. /*ws.Cells[1, 3] = "123";
  1297. ws.Cells[1, 4] = "1234";
  1298. ws.Cells[2, 1] = "Test1"; //A2
  1299. ws.Cells[3, 1] = "Test12"; //A3
  1300. ws.Cells[4, 1] = "Test123"; //A4*/
  1301. //다른 이름으로 저장하기...
  1302. wb.Save(); // => 오픈한 파일 그대로 저장...
  1303. /* wb.SaveAs("C:\\Test.xls",
  1304. Excel.XlFileFormat.xlWorkbookNormal,
  1305. Type.Missing,
  1306. Type.Missing,
  1307. Type.Missing,
  1308. Type.Missing,
  1309. Excel.XlSaveAsAccessMode.xlNoChange,
  1310. Type.Missing,
  1311. Type.Missing,
  1312. Type.Missing,
  1313. Type.Missing,
  1314. Type.Missing);
  1315. */
  1316. //파일 닫기...
  1317. wb.Close(false, Type.Missing, Type.Missing);
  1318. // wb = null;
  1319. ExcelApp.Quit();
  1320. }
  1321. catch (Exception ex)
  1322. {
  1323. //객체들 메모리 해제
  1324. ReleaseExcelObject(ws);
  1325. ReleaseExcelObject(wb);
  1326. ReleaseExcelObject(ExcelApp);
  1327. /* #region // 프로세스 죽이기
  1328. System.Diagnostics.Process[] AfterExcelProcess;
  1329. AfterExcelProcess = System.Diagnostics.Process.GetProcessesByName("EXCEL");
  1330. for (int i = 0; i < AfterExcelProcess.Length; i++)
  1331. {
  1332. try
  1333. {
  1334. if (!arlProcessID.Contains(AfterExcelProcess[i].Id))
  1335. AfterExcelProcess[i].Kill();
  1336. }
  1337. catch { }
  1338. }
  1339. #endregion*/
  1340. GC.Collect();
  1341. }
  1342. finally
  1343. {
  1344. //객체들 메모리 해제
  1345. ReleaseExcelObject(ws);
  1346. ReleaseExcelObject(wb);
  1347. ReleaseExcelObject(ExcelApp);
  1348. /* #region // 프로세스 죽이기
  1349. System.Diagnostics.Process[] AfterExcelProcess;
  1350. AfterExcelProcess = System.Diagnostics.Process.GetProcessesByName("EXCEL");
  1351. for (int i = 0; i < AfterExcelProcess.Length; i++)
  1352. {
  1353. try
  1354. {
  1355. if (!arlProcessID.Contains(AfterExcelProcess[i].Id))
  1356. AfterExcelProcess[i].Kill();
  1357. }
  1358. catch { }
  1359. }
  1360. #endregion*/
  1361. //ExcelApp = null;
  1362. GC.Collect();
  1363. }
  1364. }
  1365. private void Sensor_DataxlsWrite(object dst)
  1366. {
  1367. ExcelKill();
  1368. /* #region // 프로세스 얻기
  1369. System.Diagnostics.Process[] BeforeExcelProcess;
  1370. BeforeExcelProcess = System.Diagnostics.Process.GetProcessesByName("EXCEL");
  1371. ArrayList arlProcessID = new ArrayList();
  1372. for (int i = 0; i < BeforeExcelProcess.Length; i++)
  1373. {
  1374. arlProcessID.Add(BeforeExcelProcess[i].Id);
  1375. }
  1376. #endregion*/
  1377. //Write
  1378. //파일이 존재 한다면..삭제 하고..
  1379. /*if (File.Exists("C:\\Test.xls"))
  1380. {
  1381. File.Delete("C:\\Test.xls");
  1382. }*/
  1383. try
  1384. {
  1385. ExcelApp = new Excel.Application();
  1386. Thread.Sleep(1);
  1387. try
  1388. {
  1389. wb = ExcelApp.Workbooks.Open(dst.ToString(), 0, false, 5, Missing.Value, Missing.Value, false, Missing.Value,
  1390. Missing.Value, true, false, Missing.Value, false, false, false);
  1391. }
  1392. catch { ExcelKill(); return; }
  1393. Thread.Sleep(1);
  1394. ws = wb.Worksheets["Sheet1"] as Excel.Worksheet;
  1395. Thread.Sleep(1);
  1396. //엑셀 시트 인덱스 번호는 0,0 부터 시작 하는 것이 아니라 1,1 A1 부터 시작 함. 0,0 으로 시작하면 오류...
  1397. //시트에 값 쓰기...
  1398. ws.Cells[8, 9] = dataGridView_Sensor.Rows[0].Cells[0].Value; // 제조 번호
  1399. ws.Cells[8, 4] = dataGridView_Sensor.Rows[0].Cells[1].Value; // 일련번호
  1400. ws.Cells[8, 6] = dataGridView_Sensor.Rows[0].Cells[2].Value; //IMEI
  1401. ws.Cells[8, 7] = dataGridView_Sensor.Rows[0].Cells[3].Value;// PHONE
  1402. ws.Cells[8, 8] = dataGridView_Sensor.Rows[0].Cells[4].Value;//USIM
  1403. ws.Cells[8, 10] = dataGridView_Sensor.Rows[0].Cells[5].Value;//FIRM VER
  1404. ws.Cells[8, 18] = dataGridView_Sensor.Rows[0].Cells[6].Value;//BATT
  1405. ws.Cells[8, 19] = dataGridView_Sensor.Rows[0].Cells[7].Value;//SYS
  1406. ws.Cells[8, 20] = dataGridView_Sensor.Rows[0].Cells[8].Value;//TEMP
  1407. ws.Cells[8, 21] = dataGridView_Sensor.Rows[0].Cells[9].Value;//BMA
  1408. ws.Cells[8, 22] = dataGridView_Sensor.Rows[0].Cells[10].Value;//BMA
  1409. ws.Cells[8, 23] = dataGridView_Sensor.Rows[0].Cells[11].Value;//BMA
  1410. /*ws.Cells[1, 3] = "123";
  1411. ws.Cells[1, 4] = "1234";
  1412. ws.Cells[2, 1] = "Test1"; //A2
  1413. ws.Cells[3, 1] = "Test12"; //A3
  1414. ws.Cells[4, 1] = "Test123"; //A4*/
  1415. //다른 이름으로 저장하기...
  1416. wb.Save(); // => 오픈한 파일 그대로 저장...
  1417. /* wb.SaveAs("C:\\Test.xls",
  1418. Excel.XlFileFormat.xlWorkbookNormal,
  1419. Type.Missing,
  1420. Type.Missing,
  1421. Type.Missing,
  1422. Type.Missing,
  1423. Excel.XlSaveAsAccessMode.xlNoChange,
  1424. Type.Missing,
  1425. Type.Missing,
  1426. Type.Missing,
  1427. Type.Missing,
  1428. Type.Missing);
  1429. */
  1430. //파일 닫기...
  1431. wb.Close(false, Type.Missing, Type.Missing);
  1432. // wb = null;
  1433. ExcelApp.Quit();
  1434. //ExcelApp = null;
  1435. }
  1436. catch (Exception ex)
  1437. {
  1438. //객체들 메모리 해제
  1439. ReleaseExcelObject(ws);
  1440. ReleaseExcelObject(wb);
  1441. ReleaseExcelObject(ExcelApp);
  1442. /* #region // 프로세스 죽이기
  1443. System.Diagnostics.Process[] AfterExcelProcess;
  1444. AfterExcelProcess = System.Diagnostics.Process.GetProcessesByName("EXCEL");
  1445. for (int i = 0; i < AfterExcelProcess.Length; i++)
  1446. {
  1447. try
  1448. {
  1449. if (!arlProcessID.Contains(AfterExcelProcess[i].Id))
  1450. AfterExcelProcess[i].Kill();
  1451. }
  1452. catch { }
  1453. }
  1454. #endregion*/
  1455. GC.Collect();
  1456. }
  1457. finally
  1458. {
  1459. //객체들 메모리 해제
  1460. ReleaseExcelObject(ws);
  1461. ReleaseExcelObject(wb);
  1462. ReleaseExcelObject(ExcelApp);
  1463. /* #region // 프로세스 죽이기
  1464. System.Diagnostics.Process[] AfterExcelProcess;
  1465. AfterExcelProcess = System.Diagnostics.Process.GetProcessesByName("EXCEL");
  1466. for (int i = 0; i < AfterExcelProcess.Length; i++)
  1467. {
  1468. try
  1469. {
  1470. if (!arlProcessID.Contains(AfterExcelProcess[i].Id))
  1471. AfterExcelProcess[i].Kill();
  1472. }
  1473. catch { }
  1474. }
  1475. #endregion*/
  1476. GC.Collect();
  1477. }
  1478. }
  1479. private void Catm1_DataxlsWrite(object dst, object Product, object Modemver, object Rsrp, object Rsrq)
  1480. {
  1481. ExcelKill();
  1482. /* #region // 프로세스 얻기
  1483. System.Diagnostics.Process[] BeforeExcelProcess;
  1484. BeforeExcelProcess = System.Diagnostics.Process.GetProcessesByName("EXCEL");
  1485. ArrayList arlProcessID = new ArrayList();
  1486. for (int i = 0; i < BeforeExcelProcess.Length; i++)
  1487. {
  1488. arlProcessID.Add(BeforeExcelProcess[i].Id);
  1489. }
  1490. #endregion*/
  1491. //Write
  1492. //파일이 존재 한다면..삭제 하고..
  1493. /*if (File.Exists("C:\\Test.xls"))
  1494. {
  1495. File.Delete("C:\\Test.xls");
  1496. }*/
  1497. try
  1498. {
  1499. ExcelApp = new Excel.Application();
  1500. Thread.Sleep(1);
  1501. try
  1502. {
  1503. wb = ExcelApp.Workbooks.Open(dst.ToString(), 0, false, 5, Missing.Value, Missing.Value, false, Missing.Value,
  1504. Missing.Value, true, false, Missing.Value, false, false, false);
  1505. }
  1506. catch { ExcelKill(); return; }
  1507. Thread.Sleep(1);
  1508. ws = wb.Worksheets["Sheet1"] as Excel.Worksheet;
  1509. Thread.Sleep(1);
  1510. //엑셀 시트 인덱스 번호는 0,0 부터 시작 하는 것이 아니라 1,1 A1 부터 시작 함. 0,0 으로 시작하면 오류...
  1511. //시트에 값 쓰기...
  1512. ws.Cells[8, 9] = Product.ToString();//dataGridView_Catm1.Rows[0].Cells[0].Value; //Bluecell 제조 번호
  1513. ws.Cells[8, 12] = Modemver.ToString(); //dataGridView_Catm1.Rows[0].Cells[5].Value;//RSRP
  1514. ws.Cells[8, 13] = Rsrp.ToString(); //dataGridView_Catm1.Rows[0].Cells[6].Value;//RSRQ
  1515. ws.Cells[8, 14] = Rsrq.ToString(); //dataGridView_Catm1.Rows[0].Cells[6].Value;//RSRQ
  1516. /*ws.Cells[1, 3] = "123";
  1517. ws.Cells[1, 4] = "1234";
  1518. ws.Cells[2, 1] = "Test1"; //A2
  1519. ws.Cells[3, 1] = "Test12"; //A3
  1520. ws.Cells[4, 1] = "Test123"; //A4*/
  1521. //다른 이름으로 저장하기...
  1522. wb.Save(); // => 오픈한 파일 그대로 저장...
  1523. /* wb.SaveAs("C:\\Test.xls",
  1524. Excel.XlFileFormat.xlWorkbookNormal,
  1525. Type.Missing,
  1526. Type.Missing,
  1527. Type.Missing,
  1528. Type.Missing,
  1529. Excel.XlSaveAsAccessMode.xlNoChange,
  1530. Type.Missing,
  1531. Type.Missing,
  1532. Type.Missing,
  1533. Type.Missing,
  1534. Type.Missing);
  1535. */
  1536. //파일 닫기...
  1537. wb.Close(false, Type.Missing, Type.Missing);
  1538. // wb = null;
  1539. ExcelApp.Quit();
  1540. //ExcelApp = null;
  1541. }
  1542. catch (Exception ex)
  1543. {
  1544. //객체들 메모리 해제
  1545. ReleaseExcelObject(ws);
  1546. ReleaseExcelObject(wb);
  1547. ReleaseExcelObject(ExcelApp);
  1548. /* #region // 프로세스 죽이기
  1549. System.Diagnostics.Process[] AfterExcelProcess;
  1550. AfterExcelProcess = System.Diagnostics.Process.GetProcessesByName("EXCEL");
  1551. for (int i = 0; i < AfterExcelProcess.Length; i++)
  1552. {
  1553. try
  1554. {
  1555. if (!arlProcessID.Contains(AfterExcelProcess[i].Id))
  1556. AfterExcelProcess[i].Kill();
  1557. }
  1558. catch { }
  1559. }
  1560. #endregion*/
  1561. GC.Collect();
  1562. }
  1563. finally
  1564. {
  1565. //객체들 메모리 해제
  1566. ReleaseExcelObject(ws);
  1567. ReleaseExcelObject(wb);
  1568. ReleaseExcelObject(ExcelApp);
  1569. /* #region // 프로세스 죽이기
  1570. System.Diagnostics.Process[] AfterExcelProcess;
  1571. AfterExcelProcess = System.Diagnostics.Process.GetProcessesByName("EXCEL");
  1572. for (int i = 0; i < AfterExcelProcess.Length; i++)
  1573. {
  1574. try
  1575. {
  1576. if (!arlProcessID.Contains(AfterExcelProcess[i].Id))
  1577. AfterExcelProcess[i].Kill();
  1578. }
  1579. catch { }
  1580. }
  1581. #endregion*/
  1582. GC.Collect();
  1583. }
  1584. }
  1585. private void ReleaseExcelObject(object obj)
  1586. {
  1587. try
  1588. {
  1589. if (obj != null)
  1590. {
  1591. Marshal.ReleaseComObject(obj);
  1592. obj = null;
  1593. }
  1594. }
  1595. catch (Exception ex)
  1596. {
  1597. obj = null;
  1598. throw ex;
  1599. }
  1600. finally
  1601. {
  1602. GC.Collect();
  1603. }
  1604. }
  1605. // CommonOpenFileDialog 클래스 생성
  1606. CommonOpenFileDialog dialog = new CommonOpenFileDialog();
  1607. private void button_Path_Click(object sender, EventArgs e)
  1608. {
  1609. // 처음 보여줄 폴더 설정(안해도 됨)
  1610. //dialog.InitialDirectory = "";
  1611. dialog.IsFolderPicker = true;
  1612. if (dialog.ShowDialog() == CommonFileDialogResult.Ok)
  1613. {
  1614. FileSaveSet = dialog.FileName;
  1615. // label.Text = dialog.FileName;
  1616. // 테스트용, 폴더 선택이 완료되면 선택된 폴더를 label에 출력
  1617. }
  1618. }
  1619. private void dataGridView_Gps_KeyDown(object sender, KeyEventArgs e)
  1620. {
  1621. if (e.KeyCode == Keys.Enter)
  1622. {
  1623. button_GpsTestSave_Click(null,null);
  1624. //to do
  1625. }
  1626. else
  1627. {
  1628. return;
  1629. }
  1630. }
  1631. private void button_PrevFile_Click(object sender, EventArgs e)
  1632. {
  1633. if (openFileDialog.ShowDialog() == DialogResult.OK)
  1634. {
  1635. foreach (string x in openFileDialog.FileNames)
  1636. {
  1637. listBox_PreviousFile.Items.Add(x);
  1638. }
  1639. }
  1640. }
  1641. private void button_AfterFile_Click(object sender, EventArgs e)
  1642. {
  1643. if (openFileDialog.ShowDialog() == DialogResult.OK)
  1644. {
  1645. foreach (string x in openFileDialog.FileNames)
  1646. {
  1647. listBox_AfterFile.Items.Add(x);
  1648. }
  1649. }
  1650. }
  1651. private void label_Merge_Click(object sender, EventArgs e)
  1652. {
  1653. panel_GpsTest.Visible = false;
  1654. panel_SensorTest.Visible = false;
  1655. panel_Catm1Test.Visible = false;
  1656. panel_MergeMain.Visible = true;
  1657. panel_SnCheckMain.Visible = false;
  1658. }
  1659. private void label_SnCheck_Click(object sender, EventArgs e)
  1660. {
  1661. panel_GpsTest.Visible = false;
  1662. panel_SensorTest.Visible = false;
  1663. panel_Catm1Test.Visible = false;
  1664. panel_MergeMain.Visible = false;
  1665. panel_SnCheckMain.Visible = true;
  1666. }
  1667. private string Excel03ConString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties='Excel 8.0;HDR={1}'";
  1668. private string Excel07ConString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties='Excel 8.0;HDR={1}'";
  1669. List<string> list1 = new List<string>();
  1670. List<string> list2 = new List<string>();
  1671. private void readExcel()
  1672. {
  1673. /*Excel.Application xlApp;
  1674. Excel.Workbook xlWorkBook;
  1675. Excel.Worksheet xlWorkSheet;
  1676. Excel.Range range;
  1677. string str;
  1678. int rCnt = 0; // 열 갯수
  1679. int cCnt = 0; // 행 갯수
  1680. xlApp = new Excel.Application();
  1681. xlWorkBook = xlApp.Workbooks.Open("d:\\test.xlsx", 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
  1682. xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); // 첫번째 시트를 가져 옴.
  1683. range = xlWorkSheet.UsedRange; // 가져 온 시트의 데이터 범위 값
  1684. for (rCnt = 1; rCnt <= range.Rows.Count; rCnt++)
  1685. {
  1686. for (cCnt = 1; cCnt <= range.Columns.Count; cCnt++)
  1687. {
  1688. str = (string)(range.Cells[rCnt, cCnt] as Excel.Range).Value2; // 열과 행에 해당하는 데이터를 문자열로 반환
  1689. MessageBox.Show(str);
  1690. }
  1691. }
  1692. xlWorkBook.Close(true, null, null);
  1693. xlApp.Quit();
  1694. ReleaseExcelObject(xlWorkSheet);
  1695. ReleaseExcelObject(xlWorkBook);
  1696. ReleaseExcelObject(xlApp);
  1697. GC.Collect();*/
  1698. // 엑셀 문서 내용 추출
  1699. openFileDialog1_FileOk(null,null);
  1700. }
  1701. private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
  1702. {
  1703. string filePath = openFileDialog.FileName;
  1704. string fileExtension = Path.GetExtension(filePath);
  1705. string header = "No";//rbHeaderYes.Checked ? "Yes" : "No";
  1706. string connectionString = string.Empty;
  1707. string sheetName = string.Empty;
  1708. list1.Clear();
  1709. list2.Clear();
  1710. // 확장자로 구분하여 커넥션 스트링을 가져옮
  1711. switch (fileExtension)
  1712. {
  1713. case ".xls": //Excel 97-03
  1714. connectionString = string.Format(Excel03ConString, filePath, header);
  1715. break;
  1716. case ".xlsx": //Excel 07
  1717. connectionString = string.Format(Excel07ConString, filePath, header);
  1718. break;
  1719. }
  1720. // 첫 번째 시트의 이름을 가져옮
  1721. using (OleDbConnection con = new OleDbConnection(connectionString))
  1722. {
  1723. using (OleDbCommand cmd = new OleDbCommand())
  1724. {
  1725. cmd.Connection = con;
  1726. con.Open();
  1727. DataTable dtExcelSchema = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
  1728. sheetName = dtExcelSchema.Rows[0]["TABLE_NAME"].ToString();
  1729. con.Close();
  1730. }
  1731. }
  1732. //Console.WriteLine("sheetName = " + sheetName);
  1733. // 첫 번째 쉬트의 데이타를 읽어서 datagridview 에 보이게 함.
  1734. using (OleDbConnection con = new OleDbConnection(connectionString))
  1735. {
  1736. using (OleDbCommand cmd = new OleDbCommand())
  1737. {
  1738. using (OleDbDataAdapter oda = new OleDbDataAdapter())
  1739. {
  1740. DataTable dt = new DataTable();
  1741. cmd.CommandText = "SELECT * From [" + sheetName + "]";
  1742. cmd.Connection = con;
  1743. con.Open();
  1744. oda.SelectCommand = cmd;
  1745. oda.Fill(dt);
  1746. con.Close();
  1747. //Populate DataGridView.
  1748. dataGridView_Chk.DataSource = dt;
  1749. }
  1750. }
  1751. }
  1752. //dataGridView_Chk.Rows.Remove(1);
  1753. /* for (int i = 0; i < 54; i++)
  1754. {
  1755. dataGridView_Chk.Rows.Remove(dataGridView_Chk.Rows[i]);
  1756. }*/
  1757. for (int i = 1; i <= 18; i++)
  1758. {
  1759. if (i == 3 || i == 8)
  1760. continue;
  1761. dataGridView_Chk.Columns.Remove("F" + i.ToString());
  1762. }
  1763. dataGridView_Chk.Sort(dataGridView_Chk.Columns.GetFirstColumn(DataGridViewElementStates.Visible, DataGridViewElementStates.None), ListSortDirection.Descending);
  1764. for (int i = 0; i < dataGridView_Chk.RowCount; i++)
  1765. {
  1766. if(dataGridView_Chk.Rows[i].Cells[0].Value.ToString() == ""
  1767. || dataGridView_Chk.Rows[i].Cells[1].Value.ToString() == "")
  1768. {
  1769. break;
  1770. }
  1771. list1.Add(dataGridView_Chk.Rows[i].Cells[0].Value.ToString());
  1772. list2.Add(dataGridView_Chk.Rows[i].Cells[1].Value.ToString());
  1773. }
  1774. }
  1775. private void button_FileFindLoad_Click(object sender, EventArgs e)
  1776. {
  1777. if (openFileDialog.ShowDialog() == DialogResult.OK)
  1778. {
  1779. openFileDialog1_FileOk(null,null);
  1780. /*foreach (string x in openFileDialog.FileNames)
  1781. {
  1782. listBox_Previous.Items.Add(x);
  1783. }*/
  1784. }
  1785. }
  1786. private Thread rTh;
  1787. private void button_Merge_Click(object sender, EventArgs e)
  1788. {
  1789. rTh = new Thread(OpenExcelFile);
  1790. rTh.Start();
  1791. //OpenExcelFile();
  1792. }
  1793. // progress bar
  1794. private delegate void myDelegate(int theValue, int theMax);
  1795. delegate void SetTextCallback(string text);
  1796. // 컨트롤의 접근은 따로 함수를 만들어서 접근하도록 한다.
  1797. private void SetText(string text)
  1798. {
  1799. // InvokeRequired required compares the thread ID of the
  1800. // calling thread to the thread ID of the creating thread.
  1801. // If these threads are different, it returns true.
  1802. if (this.label_Cnt.InvokeRequired)
  1803. {
  1804. SetTextCallback d = new SetTextCallback(SetText);
  1805. this.Invoke(d, new object[] { text });
  1806. }
  1807. else
  1808. {
  1809. this.label_Cnt.Text = "Count : " + text;
  1810. }
  1811. }
  1812. private void LabelChkSetText(string text)
  1813. {
  1814. // InvokeRequired required compares the thread ID of the
  1815. // calling thread to the thread ID of the creating thread.
  1816. // If these threads are different, it returns true.
  1817. if (this.label_Cnt.InvokeRequired)
  1818. {
  1819. SetTextCallback d = new SetTextCallback(SetText);
  1820. this.Invoke(d, new object[] { text });
  1821. }
  1822. else
  1823. {
  1824. this.label_Cnt.Text = "Count : " + text;
  1825. }
  1826. }
  1827. //스레드에서 아래 함수를 호출하면 된다.
  1828. private void updateProgress(int theValue, int theMax)
  1829. {
  1830. if (theMax != 0)
  1831. progressBar_Merge.Maximum = theMax;
  1832. progressBar_Merge.Value = theValue;
  1833. }
  1834. #region
  1835. /// <summary>
  1836. /// 엑셀 정식 파일 형식이 아닌 파일 읽기
  1837. /// </summary>
  1838. /// <param name="FileName">파일명.확장자</param>
  1839. /// <returns></returns>
  1840. public void OpenExcelFile()
  1841. {
  1842. string[] APL_CopyArray =
  1843. {
  1844. "D8","E8", "F8", "G8", "H8",//SKT 일련번호 ,VC생산번호,IMEI,PHONE,USIM
  1845. "I8", "J8", "K8", "L8", "M8",//블루셀 제조번호,Ver,SNR,RSRP,BATT
  1846. "N8", "O8", "P8", "Q8", "R8",//SySVolt,TEMP,BMAX,BMAY,BMAZ
  1847. };
  1848. for (int index = 0; index < listBox_PreviousFile.Items.Count; index++)
  1849. {
  1850. Excel.Workbook xlWorkbook_copy = null;
  1851. Excel.Workbook xlWorkbook_paste = null;
  1852. Excel.Worksheet xlWorksheet_copy = null;
  1853. Excel.Worksheet xlWorksheet_paste = null;
  1854. Excel.Application xlApp_paste = null;
  1855. Excel.Application xlApp_copy = null;
  1856. Excel.Range range = null;
  1857. object data = null;
  1858. string PrevFile = listBox_PreviousFile.Items[index].ToString();
  1859. string AfterFile = listBox_AfterFile.Items[0].ToString();
  1860. try
  1861. {
  1862. xlApp_copy = new Excel.Application();
  1863. xlApp_paste = new Excel.Application();
  1864. xlWorkbook_copy = xlApp_copy.Workbooks.Open(PrevFile);
  1865. // xlWorkbook_paste = xlApp_paste.Workbooks.Open(listBox_AfterFile.Items[0].ToString());
  1866. /* Data 붙여넣을 Excel 파일 변수 초기화 */
  1867. xlWorkbook_paste = xlApp_paste.Workbooks.Open(AfterFile, 0, false, 5, Missing.Value, Missing.Value, false, Missing.Value,
  1868. Missing.Value, true, false, Missing.Value, false, false, false);
  1869. // xlWorksheet_paste = xlApp_paste.Worksheets.Item["2-1 NR 100MHz DL"]; // 특정시트 불러오기.
  1870. /* 2-1 NR 100MHz DL Copy area*/
  1871. xlWorksheet_paste = xlApp_paste.Worksheets.Item[1]; // 특정시트 불러오기.
  1872. xlWorksheet_copy = xlApp_copy.Worksheets.Item[1]; // 특정시트 불러오기.
  1873. for (int i = 0; i < APL_CopyArray.Length; i++)
  1874. {
  1875. range = xlWorksheet_copy.Range[APL_CopyArray[i]];
  1876. data = range.Value;
  1877. xlWorksheet_paste.Cells[8 + index, 4 + i] = data; // 블루셀 제조번호
  1878. }
  1879. xlWorkbook_paste.Save();
  1880. xlWorkbook_paste.Close(true);
  1881. xlApp_paste.Quit();
  1882. xlWorkbook_copy.Close(true);
  1883. xlApp_copy.Quit();
  1884. xlWorkbook_copy = null;
  1885. //xlWorkbook_copy.Save();
  1886. //xlWorkbook_paste = null;
  1887. //
  1888. }
  1889. catch (Exception ex)
  1890. {
  1891. //객체들 메모리 해제
  1892. xlWorkbook_paste.Close(true);
  1893. xlWorkbook_copy.Close(true);
  1894. xlApp_paste.Quit();
  1895. xlApp_copy.Quit();
  1896. ReleaseExcelObject(xlWorksheet_paste);
  1897. ReleaseExcelObject(xlWorkbook_paste);
  1898. ReleaseExcelObject(xlApp_paste);
  1899. ReleaseExcelObject(xlWorksheet_copy);
  1900. ReleaseExcelObject(xlWorkbook_copy);
  1901. ReleaseExcelObject(xlApp_copy);
  1902. GC.Collect();
  1903. rTh.Abort(); //쓰레드 강제 종료
  1904. }
  1905. finally
  1906. {
  1907. //객체들 메모리 해제
  1908. ReleaseExcelObject(xlWorksheet_paste);
  1909. ReleaseExcelObject(xlWorkbook_paste);
  1910. ReleaseExcelObject(xlApp_paste);
  1911. ReleaseExcelObject(xlWorksheet_copy);
  1912. ReleaseExcelObject(xlWorkbook_copy);
  1913. ReleaseExcelObject(xlApp_copy);
  1914. GC.Collect();
  1915. this.Invoke(new myDelegate(updateProgress), new object[] { index + 1, listBox_PreviousFile.Items.Count });
  1916. SetText((index + 1).ToString());
  1917. }
  1918. }
  1919. rTh.Abort(); //쓰레드 강제 종료
  1920. }
  1921. #endregion
  1922. private void button_ChkStart_Click(object sender, EventArgs e)
  1923. {
  1924. string value = "";
  1925. int Chkcnt = 0;
  1926. bool Failed = false;
  1927. int index1 = 0;
  1928. int index2 = 0;
  1929. string data1 ="", data2 ="";
  1930. if (InputBox("번호 입력", "일련 번호:", ref value) == DialogResult.OK)
  1931. {
  1932. for (int i = 0; i < list1.Count; i++)
  1933. {
  1934. if(value == list1[i])
  1935. {
  1936. Chkcnt++;
  1937. index1 = i;
  1938. data1 = value;
  1939. }
  1940. }
  1941. if (Chkcnt > 1)
  1942. {
  1943. listBox_SNDuplicate.Items.Add(value + " Cnt : " + Chkcnt.ToString());
  1944. Failed = true;
  1945. }
  1946. Chkcnt = 0;
  1947. if (InputBox("번호 입력", "생산 번호", ref value) == DialogResult.OK)
  1948. {
  1949. for (int i = 0; i < list2.Count; i++)
  1950. {
  1951. if (value == list2[i])
  1952. {
  1953. Chkcnt++;
  1954. index2 = i;
  1955. data2 = value;
  1956. }
  1957. }
  1958. if (Chkcnt > 1)
  1959. {
  1960. listBox_ProductDuplicate.Items.Add(value + " Cnt : " + Chkcnt.ToString());
  1961. Failed = true;
  1962. }
  1963. Chkcnt = 0;
  1964. }
  1965. if (Failed == true)
  1966. {
  1967. MessageBox.Show("중복항목을 제거 한 후 다시 시도해주세요.", "Error Check", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
  1968. return;
  1969. }
  1970. if (index1 != index2)
  1971. {
  1972. MessageBox.Show("서로 다른 짝 입니다. 확인해주세요.\r" + "\r일련번호 : " + list1[index1] + "\r생산번호 : " + list2[index2],"Error Check" ,MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
  1973. return;
  1974. }
  1975. else
  1976. {
  1977. if (list1[index1] == data1)
  1978. {
  1979. if (list2[index2] == data2)
  1980. {
  1981. MessageBox.Show("서로 맞는 짝입니다.\r" + "\r일련번호 : " + list1[index1] + "\r생산번호 : " + list2[index2]);
  1982. }
  1983. }
  1984. }
  1985. // SN
  1986. /*dataGridView_Sensor.Rows[0].Cells[1].Value = Name = value;
  1987. serialPort.Write(value);
  1988. button_SensorTestSave();
  1989. for (int i = 0; i < 12; i++)
  1990. dataGridView_Sensor.Rows[0].Cells[i].Value = null;*/
  1991. }
  1992. }
  1993. private void button_SNClear_Click(object sender, EventArgs e)
  1994. {
  1995. listBox_SNDuplicate.Items.Clear();
  1996. }
  1997. private void button_DuplicateClear_Click(object sender, EventArgs e)
  1998. {
  1999. listBox_ProductDuplicate.Items.Clear();
  2000. }
  2001. private void button_DiffClear_Click(object sender, EventArgs e)
  2002. {
  2003. listBox_Diff.Items.Clear();
  2004. }
  2005. private void dataGridView_Gps_CellClick(object sender, DataGridViewCellEventArgs e)
  2006. {
  2007. string value = "";
  2008. //BL-VITE00-V
  2009. if (InputBox("번호 입력", "생산 번호:", ref value) == DialogResult.OK && dataGridView_Gps.Rows[0].Cells[1].Value != null)
  2010. {
  2011. // SN
  2012. dataGridView_Gps.Rows[0].Cells[0].Value = Name = value;
  2013. button_GpsTestSave_Click(null, null);
  2014. dataGridView_Gps_CellClick(null, null);
  2015. }
  2016. }
  2017. private void dataGridView_Catm1_CellClick(object sender, DataGridViewCellEventArgs e)
  2018. {
  2019. string value = "";
  2020. //BL-VITE00-V
  2021. if (InputBox("번호 입력", "생산 번호:", ref value) == DialogResult.OK && dataGridView_Catm1.Rows[0].Cells[1].Value != null)
  2022. {
  2023. // SN
  2024. dataGridView_Catm1.Rows[0].Cells[0].Value = Name = value;
  2025. button_Catm1TestSave();
  2026. dataGridView_Catm1_CellClick(null, null);
  2027. }
  2028. }
  2029. }
  2030. class AutoClosingMessageBox
  2031. {
  2032. [System.Runtime.InteropServices.DllImport("user32.dll", SetLastError = true)]
  2033. static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
  2034. [System.Runtime.InteropServices.DllImport("user32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto)]
  2035. static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);
  2036. System.Threading.Timer _timeoutTimer; //쓰레드 타이머
  2037. string _caption;
  2038. const int WM_CLOSE = 0x0010; //close 명령
  2039. AutoClosingMessageBox(string text, string caption, int timeout)
  2040. {
  2041. _caption = caption;
  2042. _timeoutTimer = new System.Threading.Timer(OnTimerElapsed,
  2043. null, timeout, System.Threading.Timeout.Infinite);
  2044. MessageBox.Show(text, caption);
  2045. }
  2046. //생성자 함수
  2047. public static void Show(string text, string caption, int timeout)
  2048. {
  2049. new AutoClosingMessageBox(text, caption, timeout);
  2050. }
  2051. //시간이 다되면 close 메세지를 보냄
  2052. void OnTimerElapsed(object state)
  2053. {
  2054. IntPtr mbWnd = FindWindow(null, _caption);
  2055. if (mbWnd != IntPtr.Zero)
  2056. SendMessage(mbWnd, WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
  2057. _timeoutTimer.Dispose();
  2058. }
  2059. }
  2060. }