Main.cs 119 KB

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