Main.cs 107 KB

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