Main.cs 110 KB

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