Main.cs 118 KB

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