Main.cs 91 KB

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