Main.cs 74 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895
  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 (rxString.Contains(startStr))
  449. {
  450. rxString = rxString.Substring(rxString.IndexOf(startStr));
  451. if (rxString.Contains(endStr))
  452. {
  453. this.Invoke(new StringSend(Data_Recv_Str), rxString);
  454. //program.dataReceived(rxString, "Receive");
  455. offset = 0;
  456. }
  457. }
  458. }
  459. }
  460. private void label_Port_MouseClick(object sender, MouseEventArgs e)
  461. {
  462. }
  463. int LineLimit = 500;
  464. [DllImport("user32.dll")]
  465. public static extern int SendMessage(IntPtr hWnd, Int32 wMsg, bool wParam, Int32 lParam);
  466. private const int WM_SETREDRAW = 11;
  467. public void Data_Recv_Str(string text)
  468. {
  469. System.Windows.Forms.RichTextBox tbReceived = null;
  470. if (panel_GpsTest.Visible == true) {
  471. tbReceived = richTextBox_Gps;
  472. }
  473. else if (panel_Catm1Test.Visible == true) {
  474. tbReceived = richTextBox_catm1;
  475. }
  476. else if (panel_SensorTest.Visible == true) {
  477. tbReceived = richTextBox_Sensor;
  478. }
  479. int nLimitLines = Convert.ToInt32(LineLimit); //제한 라인 수
  480. try
  481. {
  482. try
  483. {
  484. SendMessage(this.Handle, WM_SETREDRAW, false, 0);
  485. }
  486. catch (Exception e) { MessageBox.Show(e.StackTrace); }
  487. if (tbReceived.Lines.Length > nLimitLines)
  488. {
  489. LinkedList<string> tempLines = new LinkedList<string>(tbReceived.Lines);
  490. while ((tempLines.Count - nLimitLines) > 0)
  491. {
  492. tempLines.RemoveFirst();
  493. }
  494. tbReceived.Lines = tempLines.ToArray();
  495. }
  496. try
  497. {
  498. SendMessage(this.Handle, WM_SETREDRAW, true, 0);
  499. }
  500. catch { return; }
  501. if (checkBox_GPGSV.Checked == true && panel_GpsTest.Visible == true)
  502. {
  503. tbReceived.AppendText(GPS_TestFunc(text));
  504. }
  505. else if(panel_SensorTest.Visible == true)
  506. {
  507. Sensor_TestFunc(text);
  508. tbReceived.AppendText(text);
  509. }
  510. else
  511. {
  512. tbReceived.AppendText(text);
  513. }
  514. tbReceived.SelectionStart = tbReceived.Text.Length;//맨 마지막 선택...
  515. tbReceived.ScrollToCaret();
  516. }
  517. catch { try { SendMessage(this.Handle, WM_SETREDRAW, true, 0); } catch { return; } }
  518. }
  519. public void Data_Recv_Str(byte[] text)
  520. {
  521. string strtext = Encoding.Default.GetString(text);
  522. System.Windows.Forms.RichTextBox tbReceived = null;
  523. if (panel_GpsTest.Visible == true)
  524. {
  525. tbReceived = richTextBox_Gps;
  526. }
  527. else if (panel_Catm1Test.Visible == true)
  528. {
  529. tbReceived = richTextBox_catm1;
  530. }
  531. else if (panel_SensorTest.Visible == true)
  532. {
  533. tbReceived = richTextBox_Sensor;
  534. }
  535. int nLimitLines = Convert.ToInt32(LineLimit); //제한 라인 수
  536. try
  537. {
  538. try
  539. {
  540. SendMessage(this.Handle, WM_SETREDRAW, false, 0);
  541. }
  542. catch (Exception e) { MessageBox.Show(e.StackTrace); }
  543. if (tbReceived.Lines.Length > nLimitLines)
  544. {
  545. LinkedList<string> tempLines = new LinkedList<string>(tbReceived.Lines);
  546. while ((tempLines.Count - nLimitLines) > 0)
  547. {
  548. tempLines.RemoveFirst();
  549. }
  550. tbReceived.Lines = tempLines.ToArray();
  551. }
  552. try
  553. {
  554. SendMessage(this.Handle, WM_SETREDRAW, true, 0);
  555. }
  556. catch { return; }
  557. if (checkBox_GPGSV.Checked == true && panel_GpsTest.Visible == true)
  558. {
  559. tbReceived.AppendText(GPS_TestFunc(Encoding.Default.GetString(text)));
  560. }
  561. else if (panel_SensorTest.Visible == true)
  562. {
  563. Sensor_TestFunc(strtext);
  564. tbReceived.AppendText(strtext);
  565. }
  566. else
  567. {
  568. tbReceived.AppendText(strtext);
  569. }
  570. tbReceived.SelectionStart = tbReceived.Text.Length;//맨 마지막 선택...
  571. tbReceived.ScrollToCaret();
  572. }
  573. catch { try { SendMessage(this.Handle, WM_SETREDRAW, true, 0); } catch { return; } }
  574. }
  575. public int WordNum(String data, String fixdata)
  576. {
  577. MatchCollection matches = Regex.Matches(data, fixdata);
  578. return matches.Count;
  579. }
  580. double GPS_TestSnRValue = 0;
  581. int Gps_CurrentCount = 0;
  582. int TestVal = 0;
  583. private string GPS_TestFunc(string data)
  584. {
  585. int Gps_Count, Sentence, SnrIndex = 3;
  586. // 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";
  587. // string tmpstr1 = "$GPGSV,2,2,08,24,36,052,37,25,48,159,42,31,17,245,,32,46,312,45*74\r\n";
  588. string[] tmpstr = new String[3];
  589. string splitstr = null, str = data;
  590. string[] sp = str.Split(',');
  591. int Losscount = 0;
  592. int location1, location2, LastLocation, SentenceCount;
  593. try
  594. {
  595. /*
  596. if(TestVal == 0)
  597. {
  598. str = tmpstr;
  599. TestVal++;
  600. }
  601. else
  602. {
  603. str = tmpstr1;
  604. TestVal = 0;
  605. }
  606. */
  607. location1 = str.IndexOf("$GPGSV");
  608. SentenceCount = WordNum(str, "GPGSV");
  609. GPS_TestSnRValue = 0;
  610. Gps_CurrentCount = 0;
  611. if (location1 != -1)
  612. {
  613. for (int ii = 0; ii < SentenceCount; ii++)
  614. {
  615. SnrIndex = 3;
  616. if (ii != 0)
  617. str = splitstr;
  618. location1 = str.IndexOf("$GPGSV");
  619. str = str.Substring(location1);
  620. location2 = str.IndexOf("\r\n");
  621. splitstr = str.Substring(location2 + 2);
  622. tmpstr[ii] = str = str.Substring(0, location2 + 2);
  623. sp = str.Split(',');
  624. if (sp[3].Contains("*"))
  625. {
  626. sp[3] = sp[3].Substring(0, 2);
  627. dataGridView_Gps.Rows[0].Cells[1].Value = sp[3];
  628. return str;
  629. }
  630. else
  631. {
  632. Sentence = Convert.ToInt32(sp[2]);
  633. Gps_Count = Convert.ToInt32(sp[3]);
  634. for (int i = 0; i < 4; i++)
  635. {
  636. SnrIndex += 4;
  637. if (sp[SnrIndex].Contains("*"))
  638. {
  639. LastLocation = sp[SnrIndex].IndexOf("*") - 2;
  640. sp[SnrIndex] = sp[SnrIndex].Substring(0, 2);
  641. GPS_TestSnRValue += Convert.ToInt32(sp[SnrIndex]);
  642. }
  643. else
  644. {
  645. if (sp[SnrIndex] == "")
  646. {
  647. sp[SnrIndex] = "0";
  648. Losscount++;
  649. }
  650. GPS_TestSnRValue += Convert.ToInt32(sp[SnrIndex]);
  651. }
  652. Gps_CurrentCount++;
  653. if (Gps_CurrentCount == Gps_Count)
  654. {
  655. GPS_TestSnRValue /= (Gps_Count - Losscount);
  656. GPS_TestSnRValue = Math.Round(GPS_TestSnRValue, 1);
  657. dataGridView_Gps.Rows[0].Cells[1].Value = GPS_TestSnRValue.ToString();
  658. break;
  659. }
  660. }
  661. }
  662. }
  663. str = null;
  664. for (int a = 0; a < SentenceCount; a++)
  665. str += tmpstr[a];
  666. if (dataGridView_Sensor.Rows[0].Cells[0].Value != null)
  667. {
  668. button_GpsTestSave_Click(null, null);
  669. }
  670. return str;
  671. }
  672. return "";
  673. }
  674. catch (Exception e) { /*MessageBox.Show(e.StackTrace); */}
  675. return "";
  676. }
  677. string SensorData = null;
  678. private void Sensor_TestFunc(string data)
  679. {
  680. string str = data;
  681. string[] sp = new string[11];
  682. try
  683. {
  684. if (data.Contains("\r\n") == false)
  685. {
  686. return;
  687. }
  688. else
  689. {
  690. SensorData += data;
  691. str = SensorData;
  692. }
  693. if (dataGridView_Sensor.Rows[0].Cells[0].Value != null)
  694. {
  695. //location1 = str.IndexOf("\r\n");
  696. //str = str.Substring(0, location1);
  697. sp = str.Split(',');
  698. if (sp[0].Contains("V") == false/* || sp.Length != 11*/)
  699. {
  700. SensorData = null;
  701. return;
  702. }
  703. dataGridView_Sensor.Rows[0].Cells[5].Value = sp[0]; //version
  704. dataGridView_Sensor.Rows[0].Cells[2].Value = sp[2]; //,IMEI
  705. dataGridView_Sensor.Rows[0].Cells[3].Value = sp[3];//, Phone Number,
  706. dataGridView_Sensor.Rows[0].Cells[4].Value = sp[4];//USIM Number
  707. dataGridView_Sensor.Rows[0].Cells[6].Value = sp[5];//, Battery Voltage,
  708. dataGridView_Sensor.Rows[0].Cells[7].Value = sp[6];// System Voltage,
  709. dataGridView_Sensor.Rows[0].Cells[8].Value = sp[7];//Temp, BMA400 값 출력 x, y, z
  710. dataGridView_Sensor.Rows[0].Cells[9].Value = sp[8];//Temp, BMA400 값 출력 x, y, z
  711. dataGridView_Sensor.Rows[0].Cells[10].Value = sp[9];//Temp, BMA400 값 출력 x, y, z
  712. if (sp[10].Contains("\r"))
  713. {
  714. int loc = sp[10].IndexOf("\r");
  715. sp[10] = sp[10].Substring(0, loc);
  716. }
  717. dataGridView_Sensor.Rows[0].Cells[11].Value = sp[10];//Temp, BMA400 값 출력 x, y, z
  718. SensorData = null;
  719. string value = "";
  720. if (checkBox_Edit.Checked == false)
  721. {
  722. if (InputBox("번호 입력", "일련 번호:", ref value) == DialogResult.OK)
  723. {
  724. // SN
  725. dataGridView_Sensor.Rows[0].Cells[1].Value = Name = value;
  726. serialPort.Write("APLSN Write:" + value + "\r\n");
  727. button_SensorTestSave();
  728. for (int i = 0; i < 12; i++)
  729. dataGridView_Sensor.Rows[0].Cells[i].Value = null;
  730. }
  731. }
  732. dataGridView_Sensor.Refresh();
  733. }
  734. return;
  735. }
  736. catch (Exception ex) { /*MessageBox.Show(ex.StackTrace); */ }
  737. }
  738. private void label_Port_MouseLeave(object sender, EventArgs e)
  739. {
  740. panel_Port.BackColor = Color.FromArgb(0, 159, 200);
  741. }
  742. private void label_Port_MouseMove(object sender, MouseEventArgs e)
  743. {
  744. panel_Port.BackColor = Color.FromArgb(0, 159, 255);
  745. }
  746. private void label_Port_Click(object sender, EventArgs e)
  747. {
  748. // Boolean ret = false;
  749. try
  750. {
  751. if (serialPort.IsOpen) // 이미 포트가 열려 있을 때
  752. { //When the port is open
  753. serialPort.Close();
  754. label_Port.Text = "Port Open";
  755. //ret = true;
  756. }
  757. else//When the port is close //포트가 열려 있지 않을 때
  758. {
  759. if (comboBox_Port.Text != "")
  760. {
  761. serialPort.PortName = Serial_Name = comboBox_Port.SelectedItem.ToString();
  762. serialPort.BaudRate = Convert.ToInt32(comboBox_bps.Text);
  763. serialPort.Open();
  764. label_Port.Text = "Port Close";
  765. // Debug.Debug_Main_Form_Get(this.main_form);
  766. }
  767. else
  768. {
  769. MessageBox.Show("Port is not set");
  770. // ret = true;
  771. }
  772. }
  773. }
  774. catch
  775. {
  776. MessageBox.Show("Port Open Faile" + Serial_Name);
  777. }
  778. // return ret;
  779. }
  780. public static DialogResult InputBox(string title, string promptText, ref string value)
  781. {
  782. Form form = new Form();
  783. System.Windows.Forms.Label label = new System.Windows.Forms.Label();
  784. System.Windows.Forms.TextBox textBox = new System.Windows.Forms.TextBox();
  785. System.Windows.Forms.Button buttonOk = new System.Windows.Forms.Button();
  786. System.Windows.Forms.Button buttonCancel = new System.Windows.Forms.Button();
  787. form.Text = title;
  788. label.Text = promptText;
  789. textBox.Text = value;
  790. buttonOk.Text = "OK";
  791. buttonCancel.Text = "Cancel";
  792. buttonOk.DialogResult = DialogResult.OK;
  793. buttonCancel.DialogResult = DialogResult.Cancel;
  794. label.SetBounds(9, 20, 372, 13);
  795. textBox.SetBounds(12, 36, 372, 20);
  796. buttonOk.SetBounds(228, 72, 75, 23);
  797. buttonCancel.SetBounds(309, 72, 75, 23);
  798. label.AutoSize = true;
  799. textBox.Anchor = textBox.Anchor | AnchorStyles.Right;
  800. buttonOk.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
  801. buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
  802. form.ClientSize = new Size(396, 107);
  803. form.Controls.AddRange(new Control[] { label, textBox, buttonOk, buttonCancel });
  804. form.ClientSize = new Size(Math.Max(300, label.Right + 10), form.ClientSize.Height);
  805. form.FormBorderStyle = FormBorderStyle.FixedDialog;
  806. form.StartPosition = FormStartPosition.CenterScreen;
  807. form.MinimizeBox = false;
  808. form.MaximizeBox = false;
  809. form.AcceptButton = buttonOk;
  810. form.CancelButton = buttonCancel;
  811. DialogResult dialogResult = form.ShowDialog();
  812. value = textBox.Text;
  813. return dialogResult;
  814. }
  815. private void button_Clear_Click(object sender, EventArgs e)
  816. {
  817. System.Windows.Forms.RichTextBox tbReceived = null;
  818. if (panel_GpsTest.Visible == true)
  819. {
  820. tbReceived = richTextBox_Gps;
  821. }
  822. else if (panel_Catm1Test.Visible == true)
  823. {
  824. tbReceived = richTextBox_catm1;
  825. }
  826. else if (panel_SensorTest.Visible == true)
  827. {
  828. tbReceived = richTextBox_Sensor;
  829. }
  830. tbReceived.Text = "";
  831. }
  832. string FileSaveSet = null;
  833. //private Thread rTh_Gps;
  834. private void button_GpsTestSave_Click(object sender, EventArgs e)
  835. {
  836. // rTh_Gps = new Thread(new ParameterizedThreadStart(Gps_DataxlsWrite));
  837. Thread.Sleep(1000);
  838. AutoClosingMessageBox.Show("저장 중.....", "알림", 1000);
  839. string CheckProductionNum = null;
  840. try
  841. {
  842. CheckProductionNum = dataGridView_Gps.Rows[0].Cells[0].Value.ToString();
  843. }
  844. catch
  845. {
  846. }
  847. try
  848. {
  849. if (!CheckProductionNum.Contains("BL-VITE00-V"))
  850. {
  851. MessageBox.Show("잘못된 생산 번호 입니다.");
  852. return;
  853. }
  854. }catch
  855. {
  856. MessageBox.Show("생산번호를 적어주세요.");
  857. }
  858. string Ref_Xls_File = new System.IO.DirectoryInfo(System.Windows.Forms.Application.StartupPath).ToString();
  859. string Dst_Xls_File = null;
  860. Ref_Xls_File = Ref_Xls_File + @"\APL_200221.xls";
  861. FileInfo SrcfileInfo = new FileInfo(Ref_Xls_File);
  862. FileInfo DstfileInfo;
  863. if (dataGridView_Gps.Rows[0].Cells[0].Value != null
  864. && dataGridView_Gps.Rows[0].Cells[1].Value != null)
  865. {
  866. if (SrcfileInfo.Exists)
  867. {
  868. if (FileSaveSet == null)
  869. {
  870. button_Path_Click(null, null);
  871. return;
  872. // MessageBox.Show("레퍼런스 엑셀 파일이 존재하지 않습니다. \r\n강차장님에게 문의 하세요.");
  873. }
  874. else
  875. {
  876. // File Copy 후 Data 입력
  877. Dst_Xls_File = FileSaveSet + @"\" + dataGridView_Gps.Rows[0].Cells[0].Value.ToString() + @".xls";
  878. DstfileInfo = new FileInfo(Dst_Xls_File);
  879. if (DstfileInfo.Exists)
  880. {
  881. if (MessageBox.Show("이미 파일이 있습니다.\r\n 덮어씌우겠습니까?", "YesOrNo", MessageBoxButtons.YesNo) == DialogResult.Yes)
  882. {
  883. try
  884. {
  885. // File.Copy(Ref_Xls_File, Dst_Xls_File, true);
  886. }
  887. catch (Exception ex)
  888. {
  889. MessageBox.Show(ex.StackTrace);
  890. return;
  891. }
  892. }
  893. else
  894. {
  895. //MessageBox.Show("아니요 클릭");
  896. return; // 아니오시 Return;
  897. }
  898. }
  899. else
  900. {
  901. File.Copy(Ref_Xls_File, Dst_Xls_File);
  902. }
  903. }
  904. }
  905. else
  906. {
  907. MessageBox.Show("레퍼런스 엑셀 파일이 존재하지 않습니다. \r\n강차장님에게 문의 하세요.");
  908. return;
  909. }
  910. }
  911. else
  912. {
  913. MessageBox.Show("생산번호/GPS SNR 값이 제대로 입력 되지 않았습니다.\r\n확인후 다시 저장하세요.");
  914. return;
  915. }
  916. // rTh_Gps.Start();
  917. Gps_DataxlsWrite(Dst_Xls_File);
  918. //rTh_Gps.Start(Dst_Xls_File);
  919. dataGridView_Gps.Rows[0].Cells[0].Value = null;
  920. dataGridView_Gps.Rows[0].Cells[1].Value = null;
  921. dataGridView_Gps.Refresh();
  922. // if (!di.Exists) { di.Create(); }
  923. //string tmppath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
  924. #if false
  925. if (dataGridView_Gps.Rows[0].Cells[1].Value != null)
  926. {
  927. string path = @"xxxx.txt";
  928. FileInfo file = new FileInfo(path);
  929. if (file.Exists)
  930. { //파일이 있는지
  931. //복사(경로,덮어쓰기 옵션 기본값 false)
  932. //만약 덮어쓰기 false일 때 파일이 존재하면 에러남.
  933. file.CopyTo(@"xxx2.txt", true);
  934. }
  935. }
  936. #endif
  937. AutoClosingMessageBox.Show("완료 되었습니다.", "알림", 1000);
  938. //this.Close();
  939. //MessageBox.
  940. }
  941. private void button_SensorTestSave()
  942. {
  943. string CheckProductionNum = null;
  944. try
  945. {
  946. CheckProductionNum = dataGridView_Sensor.Rows[0].Cells[0].Value.ToString();
  947. }
  948. catch
  949. {
  950. }
  951. try
  952. {
  953. if (!CheckProductionNum.Contains("BL-VITE00-V"))
  954. {
  955. MessageBox.Show("잘못된 생산 번호 입니다.");
  956. return;
  957. }
  958. }
  959. catch
  960. {
  961. MessageBox.Show("생산번호를 적어주세요.");
  962. }
  963. string Ref_Xls_File = new System.IO.DirectoryInfo(System.Windows.Forms.Application.StartupPath).ToString();
  964. string Dst_Xls_File = null;
  965. Ref_Xls_File = Ref_Xls_File + @"\APL_200221.xls";
  966. FileInfo SrcfileInfo = new FileInfo(Ref_Xls_File);
  967. FileInfo DstfileInfo;
  968. if (dataGridView_Sensor.Rows[0].Cells[0].Value != null)
  969. {
  970. if (SrcfileInfo.Exists)
  971. {
  972. if (FileSaveSet == null)
  973. {
  974. button_Path_Click(null, null);
  975. return;
  976. // MessageBox.Show("레퍼런스 엑셀 파일이 존재하지 않습니다. \r\n강차장님에게 문의 하세요.");
  977. }
  978. else
  979. {
  980. // File Copy 후 Data 입력
  981. Dst_Xls_File = FileSaveSet + @"\" + dataGridView_Sensor.Rows[0].Cells[0].Value.ToString() + @".xls";
  982. DstfileInfo = new FileInfo(Dst_Xls_File);
  983. if (DstfileInfo.Exists)
  984. {
  985. if (MessageBox.Show("이미 파일이 있습니다.\r\n 덮어씌우겠습니까?", "YesOrNo", MessageBoxButtons.YesNo) == DialogResult.Yes)
  986. {
  987. try
  988. {
  989. // File.Copy(Ref_Xls_File, Dst_Xls_File, true);
  990. }
  991. catch (Exception ex)
  992. {
  993. MessageBox.Show(ex.StackTrace);
  994. return;
  995. }
  996. }
  997. else
  998. {
  999. //MessageBox.Show("아니요 클릭");
  1000. return; // 아니오시 Return;
  1001. }
  1002. }
  1003. else
  1004. {
  1005. File.Copy(Ref_Xls_File, Dst_Xls_File);
  1006. }
  1007. }
  1008. }
  1009. else
  1010. {
  1011. MessageBox.Show("레퍼런스 엑셀 파일이 존재하지 않습니다. \r\n강차장님에게 문의 하세요.");
  1012. return;
  1013. }
  1014. }
  1015. else
  1016. {
  1017. MessageBox.Show("생산번호 값이 제대로 입력 되지 않았습니다.\r\n확인후 다시 저장하세요.");
  1018. return;
  1019. }
  1020. Sensor_DataxlsWrite(Dst_Xls_File);
  1021. // dataGridView_Sensor.Rows[0].Cells[0].Value = null;
  1022. // dataGridView_Sensor.Rows[0].Cells[1].Value = null;
  1023. // if (!di.Exists) { di.Create(); }
  1024. //string tmppath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
  1025. #if false
  1026. if (dataGridView_Gps.Rows[0].Cells[1].Value != null)
  1027. {
  1028. string path = @"xxxx.txt";
  1029. FileInfo file = new FileInfo(path);
  1030. if (file.Exists)
  1031. { //파일이 있는지
  1032. //복사(경로,덮어쓰기 옵션 기본값 false)
  1033. //만약 덮어쓰기 false일 때 파일이 존재하면 에러남.
  1034. file.CopyTo(@"xxx2.txt", true);
  1035. }
  1036. }
  1037. #endif
  1038. }
  1039. Excel.Application ExcelApp = null;
  1040. Excel.Workbook wb = null;
  1041. Excel.Worksheet ws = null;
  1042. private void Gps_DataxlsWrite(object dst)
  1043. {
  1044. #region // 프로세스 얻기
  1045. System.Diagnostics.Process[] BeforeExcelProcess;
  1046. BeforeExcelProcess = System.Diagnostics.Process.GetProcessesByName("EXCEL");
  1047. ArrayList arlProcessID = new ArrayList();
  1048. for (int i = 0; i < BeforeExcelProcess.Length; i++)
  1049. {
  1050. arlProcessID.Add(BeforeExcelProcess[i].Id);
  1051. }
  1052. #endregion
  1053. //Write
  1054. //파일이 존재 한다면..삭제 하고..
  1055. /*if (File.Exists("C:\\Test.xls"))
  1056. {
  1057. File.Delete("C:\\Test.xls");
  1058. }*/
  1059. try
  1060. {
  1061. ExcelApp = new Excel.Application();
  1062. wb = ExcelApp.Workbooks.Open(dst.ToString(), 0, false, 5, Missing.Value, Missing.Value, false, Missing.Value,
  1063. Missing.Value, true, false, Missing.Value, false, false, false);
  1064. ws = wb.Worksheets["Sheet1"] as Excel.Worksheet;
  1065. //엑셀 시트 인덱스 번호는 0,0 부터 시작 하는 것이 아니라 1,1 A1 부터 시작 함. 0,0 으로 시작하면 오류...
  1066. //시트에 값 쓰기...
  1067. ws.Cells[8, 9] = dataGridView_Gps.Rows[0].Cells[0].Value;
  1068. ws.Cells[8, 11] = dataGridView_Gps.Rows[0].Cells[1].Value;
  1069. /*ws.Cells[1, 3] = "123";
  1070. ws.Cells[1, 4] = "1234";
  1071. ws.Cells[2, 1] = "Test1"; //A2
  1072. ws.Cells[3, 1] = "Test12"; //A3
  1073. ws.Cells[4, 1] = "Test123"; //A4*/
  1074. //다른 이름으로 저장하기...
  1075. wb.Save(); // => 오픈한 파일 그대로 저장...
  1076. /* wb.SaveAs("C:\\Test.xls",
  1077. Excel.XlFileFormat.xlWorkbookNormal,
  1078. Type.Missing,
  1079. Type.Missing,
  1080. Type.Missing,
  1081. Type.Missing,
  1082. Excel.XlSaveAsAccessMode.xlNoChange,
  1083. Type.Missing,
  1084. Type.Missing,
  1085. Type.Missing,
  1086. Type.Missing,
  1087. Type.Missing);
  1088. */
  1089. //파일 닫기...
  1090. wb.Close(false, Type.Missing, Type.Missing);
  1091. // wb = null;
  1092. ExcelApp.Quit();
  1093. }
  1094. catch (Exception ex)
  1095. {
  1096. //객체들 메모리 해제
  1097. ReleaseExcelObject(ws);
  1098. ReleaseExcelObject(wb);
  1099. ReleaseExcelObject(ExcelApp);
  1100. #region // 프로세스 죽이기
  1101. System.Diagnostics.Process[] AfterExcelProcess;
  1102. AfterExcelProcess = System.Diagnostics.Process.GetProcessesByName("EXCEL");
  1103. for (int i = 0; i < AfterExcelProcess.Length; i++)
  1104. {
  1105. try
  1106. {
  1107. if (!arlProcessID.Contains(AfterExcelProcess[i].Id))
  1108. AfterExcelProcess[i].Kill();
  1109. }
  1110. catch { }
  1111. }
  1112. #endregion
  1113. GC.Collect();
  1114. }
  1115. finally
  1116. {
  1117. //객체들 메모리 해제
  1118. ReleaseExcelObject(ws);
  1119. ReleaseExcelObject(wb);
  1120. ReleaseExcelObject(ExcelApp);
  1121. #region // 프로세스 죽이기
  1122. System.Diagnostics.Process[] AfterExcelProcess;
  1123. AfterExcelProcess = System.Diagnostics.Process.GetProcessesByName("EXCEL");
  1124. for (int i = 0; i < AfterExcelProcess.Length; i++)
  1125. {
  1126. try
  1127. {
  1128. if (!arlProcessID.Contains(AfterExcelProcess[i].Id))
  1129. AfterExcelProcess[i].Kill();
  1130. }
  1131. catch { }
  1132. }
  1133. #endregion
  1134. //ExcelApp = null;
  1135. GC.Collect();
  1136. }
  1137. }
  1138. private void Sensor_DataxlsWrite(string dst)
  1139. {
  1140. #region // 프로세스 얻기
  1141. System.Diagnostics.Process[] BeforeExcelProcess;
  1142. BeforeExcelProcess = System.Diagnostics.Process.GetProcessesByName("EXCEL");
  1143. ArrayList arlProcessID = new ArrayList();
  1144. for (int i = 0; i < BeforeExcelProcess.Length; i++)
  1145. {
  1146. arlProcessID.Add(BeforeExcelProcess[i].Id);
  1147. }
  1148. #endregion
  1149. //Write
  1150. //파일이 존재 한다면..삭제 하고..
  1151. /*if (File.Exists("C:\\Test.xls"))
  1152. {
  1153. File.Delete("C:\\Test.xls");
  1154. }*/
  1155. try
  1156. {
  1157. ExcelApp = new Excel.Application();
  1158. wb = ExcelApp.Workbooks.Open(dst, 0, false, 5, Missing.Value, Missing.Value, false, Missing.Value,
  1159. Missing.Value, true, false, Missing.Value, false, false, false);
  1160. ws = wb.Worksheets["Sheet1"] as Excel.Worksheet;
  1161. //엑셀 시트 인덱스 번호는 0,0 부터 시작 하는 것이 아니라 1,1 A1 부터 시작 함. 0,0 으로 시작하면 오류...
  1162. //시트에 값 쓰기...
  1163. ws.Cells[8, 9] = dataGridView_Sensor.Rows[0].Cells[0].Value; // 제조 번호
  1164. ws.Cells[8, 4] = dataGridView_Sensor.Rows[0].Cells[1].Value; // 일련번호
  1165. ws.Cells[8, 6] = dataGridView_Sensor.Rows[0].Cells[2].Value; //IMEI
  1166. ws.Cells[8, 7] = dataGridView_Sensor.Rows[0].Cells[3].Value;// PHONE
  1167. ws.Cells[8, 8] = dataGridView_Sensor.Rows[0].Cells[4].Value;//USIM
  1168. ws.Cells[8, 10] = dataGridView_Sensor.Rows[0].Cells[5].Value;//VER
  1169. ws.Cells[8, 13] = dataGridView_Sensor.Rows[0].Cells[6].Value;//BATT
  1170. ws.Cells[8, 14] = dataGridView_Sensor.Rows[0].Cells[7].Value;//SYS
  1171. ws.Cells[8, 15] = dataGridView_Sensor.Rows[0].Cells[8].Value;//TEMP
  1172. ws.Cells[8, 16] = dataGridView_Sensor.Rows[0].Cells[9].Value;//BMA
  1173. ws.Cells[8, 17] = dataGridView_Sensor.Rows[0].Cells[10].Value;//BMA
  1174. ws.Cells[8, 18] = dataGridView_Sensor.Rows[0].Cells[11].Value;//BMA
  1175. /*ws.Cells[1, 3] = "123";
  1176. ws.Cells[1, 4] = "1234";
  1177. ws.Cells[2, 1] = "Test1"; //A2
  1178. ws.Cells[3, 1] = "Test12"; //A3
  1179. ws.Cells[4, 1] = "Test123"; //A4*/
  1180. //다른 이름으로 저장하기...
  1181. wb.Save(); // => 오픈한 파일 그대로 저장...
  1182. /* wb.SaveAs("C:\\Test.xls",
  1183. Excel.XlFileFormat.xlWorkbookNormal,
  1184. Type.Missing,
  1185. Type.Missing,
  1186. Type.Missing,
  1187. Type.Missing,
  1188. Excel.XlSaveAsAccessMode.xlNoChange,
  1189. Type.Missing,
  1190. Type.Missing,
  1191. Type.Missing,
  1192. Type.Missing,
  1193. Type.Missing);
  1194. */
  1195. //파일 닫기...
  1196. wb.Close(false, Type.Missing, Type.Missing);
  1197. // wb = null;
  1198. ExcelApp.Quit();
  1199. //ExcelApp = null;
  1200. }
  1201. catch (Exception ex)
  1202. {
  1203. //객체들 메모리 해제
  1204. ReleaseExcelObject(ws);
  1205. ReleaseExcelObject(wb);
  1206. ReleaseExcelObject(ExcelApp);
  1207. #region // 프로세스 죽이기
  1208. System.Diagnostics.Process[] AfterExcelProcess;
  1209. AfterExcelProcess = System.Diagnostics.Process.GetProcessesByName("EXCEL");
  1210. for (int i = 0; i < AfterExcelProcess.Length; i++)
  1211. {
  1212. try
  1213. {
  1214. if (!arlProcessID.Contains(AfterExcelProcess[i].Id))
  1215. AfterExcelProcess[i].Kill();
  1216. }
  1217. catch { }
  1218. }
  1219. #endregion
  1220. GC.Collect();
  1221. }
  1222. finally
  1223. {
  1224. //객체들 메모리 해제
  1225. ReleaseExcelObject(ws);
  1226. ReleaseExcelObject(wb);
  1227. ReleaseExcelObject(ExcelApp);
  1228. #region // 프로세스 죽이기
  1229. System.Diagnostics.Process[] AfterExcelProcess;
  1230. AfterExcelProcess = System.Diagnostics.Process.GetProcessesByName("EXCEL");
  1231. for (int i = 0; i < AfterExcelProcess.Length; i++)
  1232. {
  1233. try
  1234. {
  1235. if (!arlProcessID.Contains(AfterExcelProcess[i].Id))
  1236. AfterExcelProcess[i].Kill();
  1237. }
  1238. catch { }
  1239. }
  1240. #endregion
  1241. GC.Collect();
  1242. }
  1243. }
  1244. private void ReleaseExcelObject(object obj)
  1245. {
  1246. try
  1247. {
  1248. if (obj != null)
  1249. {
  1250. Marshal.ReleaseComObject(obj);
  1251. obj = null;
  1252. }
  1253. }
  1254. catch (Exception ex)
  1255. {
  1256. obj = null;
  1257. throw ex;
  1258. }
  1259. finally
  1260. {
  1261. GC.Collect();
  1262. }
  1263. }
  1264. // CommonOpenFileDialog 클래스 생성
  1265. CommonOpenFileDialog dialog = new CommonOpenFileDialog();
  1266. private void button_Path_Click(object sender, EventArgs e)
  1267. {
  1268. // 처음 보여줄 폴더 설정(안해도 됨)
  1269. //dialog.InitialDirectory = "";
  1270. dialog.IsFolderPicker = true;
  1271. if (dialog.ShowDialog() == CommonFileDialogResult.Ok)
  1272. {
  1273. FileSaveSet = dialog.FileName;
  1274. // label.Text = dialog.FileName;
  1275. // 테스트용, 폴더 선택이 완료되면 선택된 폴더를 label에 출력
  1276. }
  1277. }
  1278. private void dataGridView_Gps_KeyDown(object sender, KeyEventArgs e)
  1279. {
  1280. if (e.KeyCode == Keys.Enter)
  1281. {
  1282. button_GpsTestSave_Click(null,null);
  1283. //to do
  1284. }
  1285. else
  1286. {
  1287. return;
  1288. }
  1289. }
  1290. private void button_PrevFile_Click(object sender, EventArgs e)
  1291. {
  1292. if (openFileDialog.ShowDialog() == DialogResult.OK)
  1293. {
  1294. foreach (string x in openFileDialog.FileNames)
  1295. {
  1296. listBox_PreviousFile.Items.Add(x);
  1297. }
  1298. }
  1299. }
  1300. private void button_AfterFile_Click(object sender, EventArgs e)
  1301. {
  1302. if (openFileDialog.ShowDialog() == DialogResult.OK)
  1303. {
  1304. foreach (string x in openFileDialog.FileNames)
  1305. {
  1306. listBox_AfterFile.Items.Add(x);
  1307. }
  1308. }
  1309. }
  1310. private void label_Merge_Click(object sender, EventArgs e)
  1311. {
  1312. panel_GpsTest.Visible = false;
  1313. panel_SensorTest.Visible = false;
  1314. panel_Catm1Test.Visible = false;
  1315. panel_MergeMain.Visible = true;
  1316. panel_SnCheckMain.Visible = false;
  1317. }
  1318. private void label_SnCheck_Click(object sender, EventArgs e)
  1319. {
  1320. panel_GpsTest.Visible = false;
  1321. panel_SensorTest.Visible = false;
  1322. panel_Catm1Test.Visible = false;
  1323. panel_MergeMain.Visible = false;
  1324. panel_SnCheckMain.Visible = true;
  1325. }
  1326. private string Excel03ConString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties='Excel 8.0;HDR={1}'";
  1327. private string Excel07ConString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties='Excel 8.0;HDR={1}'";
  1328. List<string> list1 = new List<string>();
  1329. List<string> list2 = new List<string>();
  1330. private void readExcel()
  1331. {
  1332. /*Excel.Application xlApp;
  1333. Excel.Workbook xlWorkBook;
  1334. Excel.Worksheet xlWorkSheet;
  1335. Excel.Range range;
  1336. string str;
  1337. int rCnt = 0; // 열 갯수
  1338. int cCnt = 0; // 행 갯수
  1339. xlApp = new Excel.Application();
  1340. xlWorkBook = xlApp.Workbooks.Open("d:\\test.xlsx", 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
  1341. xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); // 첫번째 시트를 가져 옴.
  1342. range = xlWorkSheet.UsedRange; // 가져 온 시트의 데이터 범위 값
  1343. for (rCnt = 1; rCnt <= range.Rows.Count; rCnt++)
  1344. {
  1345. for (cCnt = 1; cCnt <= range.Columns.Count; cCnt++)
  1346. {
  1347. str = (string)(range.Cells[rCnt, cCnt] as Excel.Range).Value2; // 열과 행에 해당하는 데이터를 문자열로 반환
  1348. MessageBox.Show(str);
  1349. }
  1350. }
  1351. xlWorkBook.Close(true, null, null);
  1352. xlApp.Quit();
  1353. ReleaseExcelObject(xlWorkSheet);
  1354. ReleaseExcelObject(xlWorkBook);
  1355. ReleaseExcelObject(xlApp);
  1356. GC.Collect();*/
  1357. // 엑셀 문서 내용 추출
  1358. openFileDialog1_FileOk(null,null);
  1359. }
  1360. private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
  1361. {
  1362. string filePath = openFileDialog.FileName;
  1363. string fileExtension = Path.GetExtension(filePath);
  1364. string header = "No";//rbHeaderYes.Checked ? "Yes" : "No";
  1365. string connectionString = string.Empty;
  1366. string sheetName = string.Empty;
  1367. list1.Clear();
  1368. list2.Clear();
  1369. // 확장자로 구분하여 커넥션 스트링을 가져옮
  1370. switch (fileExtension)
  1371. {
  1372. case ".xls": //Excel 97-03
  1373. connectionString = string.Format(Excel03ConString, filePath, header);
  1374. break;
  1375. case ".xlsx": //Excel 07
  1376. connectionString = string.Format(Excel07ConString, filePath, header);
  1377. break;
  1378. }
  1379. // 첫 번째 시트의 이름을 가져옮
  1380. using (OleDbConnection con = new OleDbConnection(connectionString))
  1381. {
  1382. using (OleDbCommand cmd = new OleDbCommand())
  1383. {
  1384. cmd.Connection = con;
  1385. con.Open();
  1386. DataTable dtExcelSchema = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
  1387. sheetName = dtExcelSchema.Rows[0]["TABLE_NAME"].ToString();
  1388. con.Close();
  1389. }
  1390. }
  1391. //Console.WriteLine("sheetName = " + sheetName);
  1392. // 첫 번째 쉬트의 데이타를 읽어서 datagridview 에 보이게 함.
  1393. using (OleDbConnection con = new OleDbConnection(connectionString))
  1394. {
  1395. using (OleDbCommand cmd = new OleDbCommand())
  1396. {
  1397. using (OleDbDataAdapter oda = new OleDbDataAdapter())
  1398. {
  1399. DataTable dt = new DataTable();
  1400. cmd.CommandText = "SELECT * From [" + sheetName + "]";
  1401. cmd.Connection = con;
  1402. con.Open();
  1403. oda.SelectCommand = cmd;
  1404. oda.Fill(dt);
  1405. con.Close();
  1406. //Populate DataGridView.
  1407. dataGridView_Chk.DataSource = dt;
  1408. }
  1409. }
  1410. }
  1411. //dataGridView_Chk.Rows.Remove(1);
  1412. /* for (int i = 0; i < 54; i++)
  1413. {
  1414. dataGridView_Chk.Rows.Remove(dataGridView_Chk.Rows[i]);
  1415. }*/
  1416. for (int i = 1; i <= 18; i++)
  1417. {
  1418. if (i == 3 || i == 8)
  1419. continue;
  1420. dataGridView_Chk.Columns.Remove("F" + i.ToString());
  1421. }
  1422. dataGridView_Chk.Sort(dataGridView_Chk.Columns.GetFirstColumn(DataGridViewElementStates.Visible, DataGridViewElementStates.None), ListSortDirection.Descending);
  1423. for (int i = 0; i < dataGridView_Chk.RowCount; i++)
  1424. {
  1425. if(dataGridView_Chk.Rows[i].Cells[0].Value.ToString() == ""
  1426. || dataGridView_Chk.Rows[i].Cells[1].Value.ToString() == "")
  1427. {
  1428. break;
  1429. }
  1430. list1.Add(dataGridView_Chk.Rows[i].Cells[0].Value.ToString());
  1431. list2.Add(dataGridView_Chk.Rows[i].Cells[1].Value.ToString());
  1432. }
  1433. }
  1434. private void button_FileFindLoad_Click(object sender, EventArgs e)
  1435. {
  1436. if (openFileDialog.ShowDialog() == DialogResult.OK)
  1437. {
  1438. openFileDialog1_FileOk(null,null);
  1439. /*foreach (string x in openFileDialog.FileNames)
  1440. {
  1441. listBox_Previous.Items.Add(x);
  1442. }*/
  1443. }
  1444. }
  1445. private Thread rTh;
  1446. private void button_Merge_Click(object sender, EventArgs e)
  1447. {
  1448. rTh = new Thread(OpenExcelFile);
  1449. rTh.Start();
  1450. //OpenExcelFile();
  1451. }
  1452. // progress bar
  1453. private delegate void myDelegate(int theValue, int theMax);
  1454. delegate void SetTextCallback(string text);
  1455. // 컨트롤의 접근은 따로 함수를 만들어서 접근하도록 한다.
  1456. private void SetText(string text)
  1457. {
  1458. // InvokeRequired required compares the thread ID of the
  1459. // calling thread to the thread ID of the creating thread.
  1460. // If these threads are different, it returns true.
  1461. if (this.label_Cnt.InvokeRequired)
  1462. {
  1463. SetTextCallback d = new SetTextCallback(SetText);
  1464. this.Invoke(d, new object[] { text });
  1465. }
  1466. else
  1467. {
  1468. this.label_Cnt.Text = "Count : " + text;
  1469. }
  1470. }
  1471. private void LabelChkSetText(string text)
  1472. {
  1473. // InvokeRequired required compares the thread ID of the
  1474. // calling thread to the thread ID of the creating thread.
  1475. // If these threads are different, it returns true.
  1476. if (this.label_Cnt.InvokeRequired)
  1477. {
  1478. SetTextCallback d = new SetTextCallback(SetText);
  1479. this.Invoke(d, new object[] { text });
  1480. }
  1481. else
  1482. {
  1483. this.label_Cnt.Text = "Count : " + text;
  1484. }
  1485. }
  1486. //스레드에서 아래 함수를 호출하면 된다.
  1487. private void updateProgress(int theValue, int theMax)
  1488. {
  1489. if (theMax != 0)
  1490. progressBar_Merge.Maximum = theMax;
  1491. progressBar_Merge.Value = theValue;
  1492. }
  1493. #region
  1494. /// <summary>
  1495. /// 엑셀 정식 파일 형식이 아닌 파일 읽기
  1496. /// </summary>
  1497. /// <param name="FileName">파일명.확장자</param>
  1498. /// <returns></returns>
  1499. public void OpenExcelFile()
  1500. {
  1501. string[] APL_CopyArray =
  1502. {
  1503. "D8","E8", "F8", "G8", "H8",//SKT 일련번호 ,VC생산번호,IMEI,PHONE,USIM
  1504. "I8", "J8", "K8", "L8", "M8",//블루셀 제조번호,Ver,SNR,RSRP,BATT
  1505. "N8", "O8", "P8", "Q8", "R8",//SySVolt,TEMP,BMAX,BMAY,BMAZ
  1506. };
  1507. for (int index = 0; index < listBox_PreviousFile.Items.Count; index++)
  1508. {
  1509. Excel.Workbook xlWorkbook_copy = null;
  1510. Excel.Workbook xlWorkbook_paste = null;
  1511. Excel.Worksheet xlWorksheet_copy = null;
  1512. Excel.Worksheet xlWorksheet_paste = null;
  1513. Excel.Application xlApp_paste = null;
  1514. Excel.Application xlApp_copy = null;
  1515. Excel.Range range = null;
  1516. object data = null;
  1517. string PrevFile = listBox_PreviousFile.Items[index].ToString();
  1518. string AfterFile = listBox_AfterFile.Items[0].ToString();
  1519. try
  1520. {
  1521. xlApp_copy = new Excel.Application();
  1522. xlApp_paste = new Excel.Application();
  1523. xlWorkbook_copy = xlApp_copy.Workbooks.Open(PrevFile);
  1524. // xlWorkbook_paste = xlApp_paste.Workbooks.Open(listBox_AfterFile.Items[0].ToString());
  1525. /* Data 붙여넣을 Excel 파일 변수 초기화 */
  1526. xlWorkbook_paste = xlApp_paste.Workbooks.Open(AfterFile, 0, false, 5, Missing.Value, Missing.Value, false, Missing.Value,
  1527. Missing.Value, true, false, Missing.Value, false, false, false);
  1528. // xlWorksheet_paste = xlApp_paste.Worksheets.Item["2-1 NR 100MHz DL"]; // 특정시트 불러오기.
  1529. /* 2-1 NR 100MHz DL Copy area*/
  1530. xlWorksheet_paste = xlApp_paste.Worksheets.Item[1]; // 특정시트 불러오기.
  1531. xlWorksheet_copy = xlApp_copy.Worksheets.Item[1]; // 특정시트 불러오기.
  1532. for (int i = 0; i < APL_CopyArray.Length; i++)
  1533. {
  1534. range = xlWorksheet_copy.Range[APL_CopyArray[i]];
  1535. data = range.Value;
  1536. xlWorksheet_paste.Cells[8 + index, 4 + i] = data; // 블루셀 제조번호
  1537. }
  1538. xlWorkbook_paste.Save();
  1539. xlWorkbook_paste.Close(true);
  1540. xlApp_paste.Quit();
  1541. xlWorkbook_copy.Close(true);
  1542. xlApp_copy.Quit();
  1543. xlWorkbook_copy = null;
  1544. //xlWorkbook_copy.Save();
  1545. //xlWorkbook_paste = null;
  1546. //
  1547. }
  1548. catch (Exception ex)
  1549. {
  1550. //객체들 메모리 해제
  1551. xlWorkbook_paste.Close(true);
  1552. xlWorkbook_copy.Close(true);
  1553. xlApp_paste.Quit();
  1554. xlApp_copy.Quit();
  1555. ReleaseExcelObject(xlWorksheet_paste);
  1556. ReleaseExcelObject(xlWorkbook_paste);
  1557. ReleaseExcelObject(xlApp_paste);
  1558. ReleaseExcelObject(xlWorksheet_copy);
  1559. ReleaseExcelObject(xlWorkbook_copy);
  1560. ReleaseExcelObject(xlApp_copy);
  1561. GC.Collect();
  1562. rTh.Abort(); //쓰레드 강제 종료
  1563. }
  1564. finally
  1565. {
  1566. //객체들 메모리 해제
  1567. ReleaseExcelObject(xlWorksheet_paste);
  1568. ReleaseExcelObject(xlWorkbook_paste);
  1569. ReleaseExcelObject(xlApp_paste);
  1570. ReleaseExcelObject(xlWorksheet_copy);
  1571. ReleaseExcelObject(xlWorkbook_copy);
  1572. ReleaseExcelObject(xlApp_copy);
  1573. GC.Collect();
  1574. this.Invoke(new myDelegate(updateProgress), new object[] { index + 1, listBox_PreviousFile.Items.Count });
  1575. SetText((index + 1).ToString());
  1576. }
  1577. }
  1578. rTh.Abort(); //쓰레드 강제 종료
  1579. }
  1580. #endregion
  1581. private void button_ChkStart_Click(object sender, EventArgs e)
  1582. {
  1583. string value = "";
  1584. int Chkcnt = 0;
  1585. bool Failed = false;
  1586. int index1 = 0;
  1587. int index2 = 0;
  1588. string data1 ="", data2 ="";
  1589. if (InputBox("번호 입력", "일련 번호:", ref value) == DialogResult.OK)
  1590. {
  1591. for (int i = 0; i < list1.Count; i++)
  1592. {
  1593. if(value == list1[i])
  1594. {
  1595. Chkcnt++;
  1596. index1 = i;
  1597. data1 = value;
  1598. }
  1599. }
  1600. if (Chkcnt > 1)
  1601. {
  1602. listBox_SNDuplicate.Items.Add(value + " Cnt : " + Chkcnt.ToString());
  1603. Failed = true;
  1604. }
  1605. Chkcnt = 0;
  1606. if (InputBox("번호 입력", "생산 번호", ref value) == DialogResult.OK)
  1607. {
  1608. for (int i = 0; i < list2.Count; i++)
  1609. {
  1610. if (value == list2[i])
  1611. {
  1612. Chkcnt++;
  1613. index2 = i;
  1614. data2 = value;
  1615. }
  1616. }
  1617. if (Chkcnt > 1)
  1618. {
  1619. listBox_ProductDuplicate.Items.Add(value + " Cnt : " + Chkcnt.ToString());
  1620. Failed = true;
  1621. }
  1622. Chkcnt = 0;
  1623. }
  1624. if (Failed == true)
  1625. {
  1626. MessageBox.Show("중복항목을 제거 한 후 다시 시도해주세요.", "Error Check", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
  1627. return;
  1628. }
  1629. if (index1 != index2)
  1630. {
  1631. MessageBox.Show("서로 다른 짝 입니다. 확인해주세요.\r" + "\r일련번호 : " + list1[index1] + "\r생산번호 : " + list2[index2],"Error Check" ,MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
  1632. return;
  1633. }
  1634. else
  1635. {
  1636. if (list1[index1] == data1)
  1637. {
  1638. if (list2[index2] == data2)
  1639. {
  1640. MessageBox.Show("서로 맞는 짝입니다.\r" + "\r일련번호 : " + list1[index1] + "\r생산번호 : " + list2[index2]);
  1641. }
  1642. }
  1643. }
  1644. // SN
  1645. /*dataGridView_Sensor.Rows[0].Cells[1].Value = Name = value;
  1646. serialPort.Write(value);
  1647. button_SensorTestSave();
  1648. for (int i = 0; i < 12; i++)
  1649. dataGridView_Sensor.Rows[0].Cells[i].Value = null;*/
  1650. }
  1651. }
  1652. private void button_SNClear_Click(object sender, EventArgs e)
  1653. {
  1654. listBox_SNDuplicate.Items.Clear();
  1655. }
  1656. private void button_DuplicateClear_Click(object sender, EventArgs e)
  1657. {
  1658. listBox_ProductDuplicate.Items.Clear();
  1659. }
  1660. private void button_DiffClear_Click(object sender, EventArgs e)
  1661. {
  1662. listBox_Diff.Items.Clear();
  1663. }
  1664. private void dataGridView_Gps_CellClick(object sender, DataGridViewCellEventArgs e)
  1665. {
  1666. string value = "";
  1667. //BL-VITE00-V
  1668. if (InputBox("번호 입력", "일련 번호:", ref value) == DialogResult.OK && dataGridView_Gps.Rows[0].Cells[1].Value != null)
  1669. {
  1670. // SN
  1671. dataGridView_Gps.Rows[0].Cells[0].Value = Name = value;
  1672. button_GpsTestSave_Click(null, null);
  1673. dataGridView_Gps_CellClick(null, null);
  1674. }
  1675. }
  1676. }
  1677. class AutoClosingMessageBox
  1678. {
  1679. [System.Runtime.InteropServices.DllImport("user32.dll", SetLastError = true)]
  1680. static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
  1681. [System.Runtime.InteropServices.DllImport("user32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto)]
  1682. static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);
  1683. System.Threading.Timer _timeoutTimer; //쓰레드 타이머
  1684. string _caption;
  1685. const int WM_CLOSE = 0x0010; //close 명령
  1686. AutoClosingMessageBox(string text, string caption, int timeout)
  1687. {
  1688. _caption = caption;
  1689. _timeoutTimer = new System.Threading.Timer(OnTimerElapsed,
  1690. null, timeout, System.Threading.Timeout.Infinite);
  1691. MessageBox.Show(text, caption);
  1692. }
  1693. //생성자 함수
  1694. public static void Show(string text, string caption, int timeout)
  1695. {
  1696. new AutoClosingMessageBox(text, caption, timeout);
  1697. }
  1698. //시간이 다되면 close 메세지를 보냄
  1699. void OnTimerElapsed(object state)
  1700. {
  1701. IntPtr mbWnd = FindWindow(null, _caption);
  1702. if (mbWnd != IntPtr.Zero)
  1703. SendMessage(mbWnd, WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
  1704. _timeoutTimer.Dispose();
  1705. }
  1706. }
  1707. }