Main.cs 70 KB

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