Main.cs 68 KB

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