Main.cs 107 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710
  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.Refresh();
  964. // if (!di.Exists) { di.Create(); }
  965. //string tmppath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
  966. #if false
  967. if (dataGridView_Gps.Rows[0].Cells[1].Value != null)
  968. {
  969. string path = @"xxxx.txt";
  970. FileInfo file = new FileInfo(path);
  971. if (file.Exists)
  972. { //파일이 있는지
  973. //복사(경로,덮어쓰기 옵션 기본값 false)
  974. //만약 덮어쓰기 false일 때 파일이 존재하면 에러남.
  975. file.CopyTo(@"xxx2.txt", true);
  976. }
  977. }
  978. #endif
  979. //this.Close();
  980. //MessageBox.
  981. }
  982. private void button_SensorTestSave()
  983. {
  984. string CheckProductionNum = null;
  985. object[] data = new object[13];// 0 :파일위치
  986. AutoClosingMessageBox.Show("저장 중.....", "알림", 1000);
  987. try
  988. {
  989. CheckProductionNum = dataGridView_Sensor.Rows[0].Cells[0].Value.ToString();
  990. }
  991. catch
  992. {
  993. }
  994. try
  995. {
  996. if (!CheckProductionNum.Contains("BL-VITE00-V"))
  997. {
  998. MessageBox.Show("잘못된 생산 번호 입니다.");
  999. return;
  1000. }
  1001. }
  1002. catch
  1003. {
  1004. MessageBox.Show("생산번호를 적어주세요.");
  1005. }
  1006. string Ref_Xls_File = new System.IO.DirectoryInfo(System.Windows.Forms.Application.StartupPath).ToString();
  1007. string Dst_Xls_File = null;
  1008. Ref_Xls_File = Ref_Xls_File + @"\APL_200305.xls";
  1009. FileInfo SrcfileInfo = new FileInfo(Ref_Xls_File);
  1010. FileInfo DstfileInfo;
  1011. if (dataGridView_Sensor.Rows[0].Cells[0].Value != null)
  1012. {
  1013. if (SrcfileInfo.Exists)
  1014. {
  1015. if (FileSaveSet == null)
  1016. {
  1017. button_Path_Click(null, null);
  1018. return;
  1019. // MessageBox.Show("레퍼런스 엑셀 파일이 존재하지 않습니다. \r\n강차장님에게 문의 하세요.");
  1020. }
  1021. else
  1022. {
  1023. // File Copy 후 Data 입력
  1024. Dst_Xls_File = FileSaveSet + @"\" + dataGridView_Sensor.Rows[0].Cells[0].Value.ToString() + @".xls";
  1025. DstfileInfo = new FileInfo(Dst_Xls_File);
  1026. if (DstfileInfo.Exists)
  1027. {
  1028. if (MessageBox.Show("이미 파일이 있습니다.\r\n 덮어씌우겠습니까?", "YesOrNo", MessageBoxButtons.YesNo) == DialogResult.Yes)
  1029. {
  1030. try
  1031. {
  1032. // File.Copy(Ref_Xls_File, Dst_Xls_File, true);
  1033. }
  1034. catch (Exception ex)
  1035. {
  1036. MessageBox.Show(ex.StackTrace);
  1037. return;
  1038. }
  1039. }
  1040. else
  1041. {
  1042. //MessageBox.Show("아니요 클릭");
  1043. return; // 아니오시 Return;
  1044. }
  1045. }
  1046. else
  1047. {
  1048. File.Copy(Ref_Xls_File, Dst_Xls_File);
  1049. Thread.Sleep(2000);
  1050. }
  1051. }
  1052. }
  1053. else
  1054. {
  1055. MessageBox.Show("레퍼런스 엑셀 파일이 존재하지 않습니다. \r\n강차장님에게 문의 하세요.");
  1056. return;
  1057. }
  1058. }
  1059. else
  1060. {
  1061. MessageBox.Show("생산번호 값이 제대로 입력 되지 않았습니다.\r\n확인후 다시 저장하세요.");
  1062. return;
  1063. }
  1064. //
  1065. data[0] = Dst_Xls_File;
  1066. for (int i = 0; i < 12; i++)
  1067. data[i + 1] = dataGridView_Sensor.Rows[0].Cells[i].Value;
  1068. //Sensor_DataxlsWrite();
  1069. Sensor_ThreadRun(data);
  1070. AutoClosingMessageBox.Show("완료 되었습니다.", "알림", 1000);
  1071. for (int i = 0; i < 12; i++)
  1072. dataGridView_Sensor.Rows[0].Cells[i].Value = null;
  1073. dataGridView_Sensor.Refresh();
  1074. // dataGridView_Sensor.Rows[0].Cells[0].Value = null;
  1075. // dataGridView_Sensor.Rows[0].Cells[1].Value = null;
  1076. // if (!di.Exists) { di.Create(); }
  1077. //string tmppath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
  1078. #if false
  1079. if (dataGridView_Gps.Rows[0].Cells[1].Value != null)
  1080. {
  1081. string path = @"xxxx.txt";
  1082. FileInfo file = new FileInfo(path);
  1083. if (file.Exists)
  1084. { //파일이 있는지
  1085. //복사(경로,덮어쓰기 옵션 기본값 false)
  1086. //만약 덮어쓰기 false일 때 파일이 존재하면 에러남.
  1087. file.CopyTo(@"xxx2.txt", true);
  1088. }
  1089. }
  1090. #endif
  1091. }
  1092. private void button_Catm1TestSave()
  1093. {
  1094. string CheckProductionNum = null;
  1095. AutoClosingMessageBox.Show("저장 중.....", "알림", 1000);
  1096. try
  1097. {
  1098. CheckProductionNum = dataGridView_Catm1.Rows[0].Cells[0].Value.ToString();
  1099. }
  1100. catch
  1101. {
  1102. }
  1103. try
  1104. {
  1105. if (!CheckProductionNum.Contains("BL-VITE00-V"))
  1106. {
  1107. MessageBox.Show("잘못된 생산 번호 입니다.");
  1108. return;
  1109. }
  1110. }
  1111. catch
  1112. {
  1113. MessageBox.Show("생산번호를 적어주세요.");
  1114. }
  1115. string Ref_Xls_File = new System.IO.DirectoryInfo(System.Windows.Forms.Application.StartupPath).ToString();
  1116. string Dst_Xls_File = null;
  1117. Ref_Xls_File = Ref_Xls_File + @"\APL_200305.xls";
  1118. FileInfo SrcfileInfo = new FileInfo(Ref_Xls_File);
  1119. FileInfo DstfileInfo;
  1120. if (dataGridView_Catm1.Rows[0].Cells[0].Value != null)
  1121. {
  1122. if (SrcfileInfo.Exists)
  1123. {
  1124. if (FileSaveSet == null)
  1125. {
  1126. button_Path_Click(null, null);
  1127. return;
  1128. // MessageBox.Show("레퍼런스 엑셀 파일이 존재하지 않습니다. \r\n강차장님에게 문의 하세요.");
  1129. }
  1130. else
  1131. {
  1132. // File Copy 후 Data 입력
  1133. Dst_Xls_File = FileSaveSet + @"\" + dataGridView_Catm1.Rows[0].Cells[0].Value.ToString() + @".xls";
  1134. DstfileInfo = new FileInfo(Dst_Xls_File);
  1135. if (DstfileInfo.Exists)
  1136. {
  1137. if (MessageBox.Show("이미 파일이 있습니다.\r\n 덮어씌우겠습니까?", "YesOrNo", MessageBoxButtons.YesNo) == DialogResult.Yes)
  1138. {
  1139. try
  1140. {
  1141. // File.Copy(Ref_Xls_File, Dst_Xls_File, true);
  1142. }
  1143. catch (Exception ex)
  1144. {
  1145. MessageBox.Show(ex.StackTrace);
  1146. return;
  1147. }
  1148. }
  1149. else
  1150. {
  1151. //MessageBox.Show("아니요 클릭");
  1152. return; // 아니오시 Return;
  1153. }
  1154. }
  1155. else
  1156. {
  1157. File.Copy(Ref_Xls_File, Dst_Xls_File);
  1158. Thread.Sleep(2000);
  1159. }
  1160. }
  1161. }
  1162. else
  1163. {
  1164. MessageBox.Show("레퍼런스 엑셀 파일이 존재하지 않습니다. \r\n강차장님에게 문의 하세요.");
  1165. return;
  1166. }
  1167. }
  1168. else
  1169. {
  1170. MessageBox.Show("생산번호 값이 제대로 입력 되지 않았습니다.\r\n확인후 다시 저장하세요.");
  1171. return;
  1172. }
  1173. 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);
  1174. for (int i = 0; i < 4; i++)
  1175. dataGridView_Catm1.Rows[0].Cells[i].Value = null;
  1176. dataGridView_Catm1.Refresh();
  1177. AutoClosingMessageBox.Show("완료 되었습니다.", "알림", 1000);
  1178. //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);
  1179. // dataGridView_Catm1.Rows[0].Cells[0].Value = null;
  1180. // dataGridView_Catm1.Rows[0].Cells[1].Value = null;
  1181. // if (!di.Exists) { di.Create(); }
  1182. //string tmppath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
  1183. #if false
  1184. if (dataGridView_Gps.Rows[0].Cells[1].Value != null)
  1185. {
  1186. string path = @"xxxx.txt";
  1187. FileInfo file = new FileInfo(path);
  1188. if (file.Exists)
  1189. { //파일이 있는지
  1190. //복사(경로,덮어쓰기 옵션 기본값 false)
  1191. //만약 덮어쓰기 false일 때 파일이 존재하면 에러남.
  1192. file.CopyTo(@"xxx2.txt", true);
  1193. }
  1194. }
  1195. #endif
  1196. }
  1197. private void button_SninsertTestSave()
  1198. {
  1199. string CheckProductionNum = null;
  1200. object[] data = new object[4];// 0 :파일위치
  1201. AutoClosingMessageBox.Show("저장 중.....", "알림", 1000);
  1202. try
  1203. {
  1204. CheckProductionNum = dataGridView_SnInsert.Rows[0].Cells[0].Value.ToString();
  1205. }
  1206. catch
  1207. {
  1208. }
  1209. try
  1210. {
  1211. if (!CheckProductionNum.Contains("BL-VITE00-V"))
  1212. {
  1213. MessageBox.Show("잘못된 생산 번호 입니다.");
  1214. return;
  1215. }
  1216. }
  1217. catch
  1218. {
  1219. MessageBox.Show("생산번호를 적어주세요.");
  1220. }
  1221. string Ref_Xls_File = new System.IO.DirectoryInfo(System.Windows.Forms.Application.StartupPath).ToString();
  1222. string Dst_Xls_File = null;
  1223. Ref_Xls_File = Ref_Xls_File + @"\APL_200305.xls";
  1224. FileInfo SrcfileInfo = new FileInfo(Ref_Xls_File);
  1225. FileInfo DstfileInfo;
  1226. if (dataGridView_SnInsert.Rows[0].Cells[0].Value != null)
  1227. {
  1228. if (SrcfileInfo.Exists)
  1229. {
  1230. if (FileSaveSet == null)
  1231. {
  1232. button_Path_Click(null, null);
  1233. return;
  1234. // MessageBox.Show("레퍼런스 엑셀 파일이 존재하지 않습니다. \r\n강차장님에게 문의 하세요.");
  1235. }
  1236. else
  1237. {
  1238. // File Copy 후 Data 입력
  1239. Dst_Xls_File = FileSaveSet + @"\" + dataGridView_SnInsert.Rows[0].Cells[0].Value.ToString() + @".xls";
  1240. DstfileInfo = new FileInfo(Dst_Xls_File);
  1241. if (DstfileInfo.Exists)
  1242. {
  1243. if (MessageBox.Show("이미 파일이 있습니다.\r\n 덮어씌우겠습니까?", "YesOrNo", MessageBoxButtons.YesNo) == DialogResult.Yes)
  1244. {
  1245. try
  1246. {
  1247. // File.Copy(Ref_Xls_File, Dst_Xls_File, true);
  1248. }
  1249. catch (Exception ex)
  1250. {
  1251. MessageBox.Show(ex.StackTrace);
  1252. return;
  1253. }
  1254. }
  1255. else
  1256. {
  1257. //MessageBox.Show("아니요 클릭");
  1258. return; // 아니오시 Return;
  1259. }
  1260. }
  1261. else
  1262. {
  1263. File.Copy(Ref_Xls_File, Dst_Xls_File);
  1264. Thread.Sleep(2000);
  1265. }
  1266. }
  1267. }
  1268. else
  1269. {
  1270. MessageBox.Show("레퍼런스 엑셀 파일이 존재하지 않습니다. \r\n강차장님에게 문의 하세요.");
  1271. return;
  1272. }
  1273. }
  1274. else
  1275. {
  1276. MessageBox.Show("생산번호 값이 제대로 입력 되지 않았습니다.\r\n확인후 다시 저장하세요.");
  1277. return;
  1278. }
  1279. //
  1280. data[0] = Dst_Xls_File;
  1281. for (int i = 0; i < 3; i++)
  1282. data[i + 1] = dataGridView_SnInsert.Rows[0].Cells[i].Value;
  1283. //Sensor_DataxlsWrite();
  1284. Sninsert_ThreadRun(data);
  1285. AutoClosingMessageBox.Show("완료 되었습니다.", "알림", 1000);
  1286. for (int i = 0; i < 3; i++)
  1287. dataGridView_SnInsert.Rows[0].Cells[i].Value = null;
  1288. dataGridView_SnInsert.Refresh();
  1289. // dataGridView_Sensor.Rows[0].Cells[0].Value = null;
  1290. // dataGridView_Sensor.Rows[0].Cells[1].Value = null;
  1291. // if (!di.Exists) { di.Create(); }
  1292. //string tmppath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
  1293. #if false
  1294. if (dataGridView_Gps.Rows[0].Cells[1].Value != null)
  1295. {
  1296. string path = @"xxxx.txt";
  1297. FileInfo file = new FileInfo(path);
  1298. if (file.Exists)
  1299. { //파일이 있는지
  1300. //복사(경로,덮어쓰기 옵션 기본값 false)
  1301. //만약 덮어쓰기 false일 때 파일이 존재하면 에러남.
  1302. file.CopyTo(@"xxx2.txt", true);
  1303. }
  1304. }
  1305. #endif
  1306. }
  1307. private void ExcelKill()
  1308. {
  1309. System.Diagnostics.Process[] process = System.Diagnostics.Process.GetProcessesByName("EXCEL");
  1310. foreach (System.Diagnostics.Process p in process)
  1311. {
  1312. if (!string.IsNullOrEmpty(p.ProcessName))
  1313. {
  1314. try
  1315. {
  1316. p.Kill();
  1317. }
  1318. catch { }
  1319. }
  1320. }
  1321. }
  1322. Excel.Application ExcelApp = null;
  1323. Excel.Workbook wb = null;
  1324. Excel.Worksheet ws = null;
  1325. private void Gps_DataxlsWrite(object dst, object Value1, object Value2)
  1326. {
  1327. /* #region // 프로세스 얻기
  1328. System.Diagnostics.Process[] BeforeExcelProcess;
  1329. BeforeExcelProcess = System.Diagnostics.Process.GetProcessesByName("EXCEL");
  1330. ArrayList arlProcessID = new ArrayList();
  1331. for (int i = 0; i < BeforeExcelProcess.Length; i++)
  1332. {
  1333. arlProcessID.Add(BeforeExcelProcess[i].Id);
  1334. }
  1335. #endregion
  1336. */
  1337. ExcelKill();
  1338. //Write
  1339. //파일이 존재 한다면..삭제 하고..
  1340. /*if (File.Exists("C:\\Test.xls"))
  1341. {
  1342. File.Delete("C:\\Test.xls");
  1343. }*/
  1344. try
  1345. {
  1346. ExcelApp = new Excel.Application();
  1347. Thread.Sleep(1);
  1348. try
  1349. {
  1350. wb = ExcelApp.Workbooks.Open(dst.ToString(), 0, false, 5, Missing.Value, Missing.Value, false, Missing.Value,
  1351. Missing.Value, true, false, Missing.Value, false, false, false);
  1352. }
  1353. catch { ExcelKill(); return; }
  1354. Thread.Sleep(1);
  1355. ws = wb.Worksheets["Sheet1"] as Excel.Worksheet;
  1356. Thread.Sleep(1);
  1357. /*ExcelApp = new Excel.Application();
  1358. wb = ExcelApp.Workbooks.Open(dst.ToString(), 0, false, 5, Missing.Value, Missing.Value, false, Missing.Value,
  1359. Missing.Value, true, false, Missing.Value, false, false, false);
  1360. wb = ExcelApp.Workbooks.Open(dst.ToString());*/
  1361. ws = wb.Worksheets["Sheet1"] as Excel.Worksheet;
  1362. //엑셀 시트 인덱스 번호는 0,0 부터 시작 하는 것이 아니라 1,1 A1 부터 시작 함. 0,0 으로 시작하면 오류...
  1363. //시트에 값 쓰기...
  1364. ws.Cells[8, 9] = Value1.ToString();//dataGridView_Gps.Rows[0].Cells[0].Value;
  1365. ws.Cells[8, 11] = Value2.ToString();//dataGridView_Gps.Rows[0].Cells[1].Value;
  1366. /*ws.Cells[1, 3] = "123";
  1367. ws.Cells[1, 4] = "1234";
  1368. ws.Cells[2, 1] = "Test1"; //A2
  1369. ws.Cells[3, 1] = "Test12"; //A3
  1370. ws.Cells[4, 1] = "Test123"; //A4*/
  1371. //다른 이름으로 저장하기...
  1372. wb.Save(); // => 오픈한 파일 그대로 저장...
  1373. /* wb.SaveAs("C:\\Test.xls",
  1374. Excel.XlFileFormat.xlWorkbookNormal,
  1375. Type.Missing,
  1376. Type.Missing,
  1377. Type.Missing,
  1378. Type.Missing,
  1379. Excel.XlSaveAsAccessMode.xlNoChange,
  1380. Type.Missing,
  1381. Type.Missing,
  1382. Type.Missing,
  1383. Type.Missing,
  1384. Type.Missing);
  1385. */
  1386. //파일 닫기...
  1387. wb.Close(false, Type.Missing, Type.Missing);
  1388. // wb = null;
  1389. ExcelApp.Quit();
  1390. }
  1391. catch (Exception ex)
  1392. {
  1393. //객체들 메모리 해제
  1394. ReleaseExcelObject(ws);
  1395. ReleaseExcelObject(wb);
  1396. ReleaseExcelObject(ExcelApp);
  1397. /* #region // 프로세스 죽이기
  1398. System.Diagnostics.Process[] AfterExcelProcess;
  1399. AfterExcelProcess = System.Diagnostics.Process.GetProcessesByName("EXCEL");
  1400. for (int i = 0; i < AfterExcelProcess.Length; i++)
  1401. {
  1402. try
  1403. {
  1404. if (!arlProcessID.Contains(AfterExcelProcess[i].Id))
  1405. AfterExcelProcess[i].Kill();
  1406. }
  1407. catch { }
  1408. }
  1409. #endregion*/
  1410. GC.Collect();
  1411. }
  1412. finally
  1413. {
  1414. //객체들 메모리 해제
  1415. ReleaseExcelObject(ws);
  1416. ReleaseExcelObject(wb);
  1417. ReleaseExcelObject(ExcelApp);
  1418. /* #region // 프로세스 죽이기
  1419. System.Diagnostics.Process[] AfterExcelProcess;
  1420. AfterExcelProcess = System.Diagnostics.Process.GetProcessesByName("EXCEL");
  1421. for (int i = 0; i < AfterExcelProcess.Length; i++)
  1422. {
  1423. try
  1424. {
  1425. if (!arlProcessID.Contains(AfterExcelProcess[i].Id))
  1426. AfterExcelProcess[i].Kill();
  1427. }
  1428. catch { }
  1429. }
  1430. #endregion*/
  1431. //ExcelApp = null;
  1432. GC.Collect();
  1433. }
  1434. }
  1435. private void Sensor_DataxlsWrite(object[] data)
  1436. {
  1437. ExcelKill();
  1438. /* #region // 프로세스 얻기
  1439. System.Diagnostics.Process[] BeforeExcelProcess;
  1440. BeforeExcelProcess = System.Diagnostics.Process.GetProcessesByName("EXCEL");
  1441. ArrayList arlProcessID = new ArrayList();
  1442. for (int i = 0; i < BeforeExcelProcess.Length; i++)
  1443. {
  1444. arlProcessID.Add(BeforeExcelProcess[i].Id);
  1445. }
  1446. #endregion*/
  1447. //Write
  1448. //파일이 존재 한다면..삭제 하고..
  1449. /*if (File.Exists("C:\\Test.xls"))
  1450. {
  1451. File.Delete("C:\\Test.xls");
  1452. }*/
  1453. try
  1454. {
  1455. ExcelApp = new Excel.Application();
  1456. Thread.Sleep(1);
  1457. try
  1458. {
  1459. wb = ExcelApp.Workbooks.Open(data[0].ToString(), 0, false, 5, Missing.Value, Missing.Value, false, Missing.Value,
  1460. Missing.Value, true, false, Missing.Value, false, false, false);
  1461. }
  1462. catch { ExcelKill(); return; }
  1463. Thread.Sleep(1);
  1464. ws = wb.Worksheets["Sheet1"] as Excel.Worksheet;
  1465. Thread.Sleep(1);
  1466. //엑셀 시트 인덱스 번호는 0,0 부터 시작 하는 것이 아니라 1,1 A1 부터 시작 함. 0,0 으로 시작하면 오류...
  1467. //시트에 값 쓰기...
  1468. ws.Cells[8, 9] = data[1].ToString();//dataGridView_Sensor.Rows[0].Cells[0].Value; // 제조 번호
  1469. ws.Cells[8, 4] = data[2].ToString();//dataGridView_Sensor.Rows[0].Cells[1].Value; // 일련번호
  1470. ws.Cells[8, 6] = data[3].ToString();//dataGridView_Sensor.Rows[0].Cells[2].Value; //IMEI
  1471. ws.Cells[8, 7] = data[4].ToString();//dataGridView_Sensor.Rows[0].Cells[3].Value;// PHONE
  1472. ws.Cells[8, 8] = data[5].ToString();//dataGridView_Sensor.Rows[0].Cells[4].Value;//USIM
  1473. ws.Cells[8, 10] = data[6].ToString();//dataGridView_Sensor.Rows[0].Cells[5].Value;//FIRM VER
  1474. ws.Cells[8, 18] = data[7].ToString();//dataGridView_Sensor.Rows[0].Cells[6].Value;//BATT
  1475. ws.Cells[8, 19] = data[8].ToString();//dataGridView_Sensor.Rows[0].Cells[7].Value;//SYS
  1476. ws.Cells[8, 20] = data[9].ToString();//dataGridView_Sensor.Rows[0].Cells[8].Value;//TEMP
  1477. ws.Cells[8, 21] = data[10].ToString();//dataGridView_Sensor.Rows[0].Cells[9].Value;//BMA
  1478. ws.Cells[8, 22] = data[11].ToString();//dataGridView_Sensor.Rows[0].Cells[10].Value;//BMA
  1479. ws.Cells[8, 23] = data[12].ToString();//dataGridView_Sensor.Rows[0].Cells[11].Value;//BMA
  1480. /*ws.Cells[1, 3] = "123";
  1481. ws.Cells[1, 4] = "1234";
  1482. ws.Cells[2, 1] = "Test1"; //A2
  1483. ws.Cells[3, 1] = "Test12"; //A3
  1484. ws.Cells[4, 1] = "Test123"; //A4*/
  1485. //다른 이름으로 저장하기...
  1486. wb.Save(); // => 오픈한 파일 그대로 저장...
  1487. /* wb.SaveAs("C:\\Test.xls",
  1488. Excel.XlFileFormat.xlWorkbookNormal,
  1489. Type.Missing,
  1490. Type.Missing,
  1491. Type.Missing,
  1492. Type.Missing,
  1493. Excel.XlSaveAsAccessMode.xlNoChange,
  1494. Type.Missing,
  1495. Type.Missing,
  1496. Type.Missing,
  1497. Type.Missing,
  1498. Type.Missing);
  1499. */
  1500. //파일 닫기...
  1501. wb.Close(false, Type.Missing, Type.Missing);
  1502. // wb = null;
  1503. ExcelApp.Quit();
  1504. //ExcelApp = null;
  1505. }
  1506. catch (Exception ex)
  1507. {
  1508. //객체들 메모리 해제
  1509. ReleaseExcelObject(ws);
  1510. ReleaseExcelObject(wb);
  1511. ReleaseExcelObject(ExcelApp);
  1512. /* #region // 프로세스 죽이기
  1513. System.Diagnostics.Process[] AfterExcelProcess;
  1514. AfterExcelProcess = System.Diagnostics.Process.GetProcessesByName("EXCEL");
  1515. for (int i = 0; i < AfterExcelProcess.Length; i++)
  1516. {
  1517. try
  1518. {
  1519. if (!arlProcessID.Contains(AfterExcelProcess[i].Id))
  1520. AfterExcelProcess[i].Kill();
  1521. }
  1522. catch { }
  1523. }
  1524. #endregion*/
  1525. GC.Collect();
  1526. }
  1527. finally
  1528. {
  1529. //객체들 메모리 해제
  1530. ReleaseExcelObject(ws);
  1531. ReleaseExcelObject(wb);
  1532. ReleaseExcelObject(ExcelApp);
  1533. /* #region // 프로세스 죽이기
  1534. System.Diagnostics.Process[] AfterExcelProcess;
  1535. AfterExcelProcess = System.Diagnostics.Process.GetProcessesByName("EXCEL");
  1536. for (int i = 0; i < AfterExcelProcess.Length; i++)
  1537. {
  1538. try
  1539. {
  1540. if (!arlProcessID.Contains(AfterExcelProcess[i].Id))
  1541. AfterExcelProcess[i].Kill();
  1542. }
  1543. catch { }
  1544. }
  1545. #endregion*/
  1546. GC.Collect();
  1547. }
  1548. }
  1549. private void Catm1_DataxlsWrite(object dst, object Product, object Modemver, object Rsrp, object Rsrq)
  1550. {
  1551. ExcelKill();
  1552. /* #region // 프로세스 얻기
  1553. System.Diagnostics.Process[] BeforeExcelProcess;
  1554. BeforeExcelProcess = System.Diagnostics.Process.GetProcessesByName("EXCEL");
  1555. ArrayList arlProcessID = new ArrayList();
  1556. for (int i = 0; i < BeforeExcelProcess.Length; i++)
  1557. {
  1558. arlProcessID.Add(BeforeExcelProcess[i].Id);
  1559. }
  1560. #endregion*/
  1561. //Write
  1562. //파일이 존재 한다면..삭제 하고..
  1563. /*if (File.Exists("C:\\Test.xls"))
  1564. {
  1565. File.Delete("C:\\Test.xls");
  1566. }*/
  1567. try
  1568. {
  1569. ExcelApp = new Excel.Application();
  1570. Thread.Sleep(1);
  1571. try
  1572. {
  1573. wb = ExcelApp.Workbooks.Open(dst.ToString(), 0, false, 5, Missing.Value, Missing.Value, false, Missing.Value,
  1574. Missing.Value, true, false, Missing.Value, false, false, false);
  1575. }
  1576. catch { ExcelKill(); return; }
  1577. Thread.Sleep(1);
  1578. ws = wb.Worksheets["Sheet1"] as Excel.Worksheet;
  1579. Thread.Sleep(1);
  1580. //엑셀 시트 인덱스 번호는 0,0 부터 시작 하는 것이 아니라 1,1 A1 부터 시작 함. 0,0 으로 시작하면 오류...
  1581. //시트에 값 쓰기...
  1582. ws.Cells[8, 9] = Product.ToString();//dataGridView_Catm1.Rows[0].Cells[0].Value; //Bluecell 제조 번호
  1583. ws.Cells[8, 12] = Modemver.ToString(); //dataGridView_Catm1.Rows[0].Cells[5].Value;//RSRP
  1584. ws.Cells[8, 13] = Rsrp.ToString(); //dataGridView_Catm1.Rows[0].Cells[6].Value;//RSRQ
  1585. ws.Cells[8, 14] = Rsrq.ToString(); //dataGridView_Catm1.Rows[0].Cells[6].Value;//RSRQ
  1586. /*ws.Cells[1, 3] = "123";
  1587. ws.Cells[1, 4] = "1234";
  1588. ws.Cells[2, 1] = "Test1"; //A2
  1589. ws.Cells[3, 1] = "Test12"; //A3
  1590. ws.Cells[4, 1] = "Test123"; //A4*/
  1591. //다른 이름으로 저장하기...
  1592. wb.Save(); // => 오픈한 파일 그대로 저장...
  1593. /* wb.SaveAs("C:\\Test.xls",
  1594. Excel.XlFileFormat.xlWorkbookNormal,
  1595. Type.Missing,
  1596. Type.Missing,
  1597. Type.Missing,
  1598. Type.Missing,
  1599. Excel.XlSaveAsAccessMode.xlNoChange,
  1600. Type.Missing,
  1601. Type.Missing,
  1602. Type.Missing,
  1603. Type.Missing,
  1604. Type.Missing);
  1605. */
  1606. //파일 닫기...
  1607. wb.Close(false, Type.Missing, Type.Missing);
  1608. // wb = null;
  1609. ExcelApp.Quit();
  1610. //ExcelApp = null;
  1611. }
  1612. catch (Exception ex)
  1613. {
  1614. //객체들 메모리 해제
  1615. ReleaseExcelObject(ws);
  1616. ReleaseExcelObject(wb);
  1617. ReleaseExcelObject(ExcelApp);
  1618. /* #region // 프로세스 죽이기
  1619. System.Diagnostics.Process[] AfterExcelProcess;
  1620. AfterExcelProcess = System.Diagnostics.Process.GetProcessesByName("EXCEL");
  1621. for (int i = 0; i < AfterExcelProcess.Length; i++)
  1622. {
  1623. try
  1624. {
  1625. if (!arlProcessID.Contains(AfterExcelProcess[i].Id))
  1626. AfterExcelProcess[i].Kill();
  1627. }
  1628. catch { }
  1629. }
  1630. #endregion*/
  1631. GC.Collect();
  1632. }
  1633. finally
  1634. {
  1635. //객체들 메모리 해제
  1636. ReleaseExcelObject(ws);
  1637. ReleaseExcelObject(wb);
  1638. ReleaseExcelObject(ExcelApp);
  1639. /* #region // 프로세스 죽이기
  1640. System.Diagnostics.Process[] AfterExcelProcess;
  1641. AfterExcelProcess = System.Diagnostics.Process.GetProcessesByName("EXCEL");
  1642. for (int i = 0; i < AfterExcelProcess.Length; i++)
  1643. {
  1644. try
  1645. {
  1646. if (!arlProcessID.Contains(AfterExcelProcess[i].Id))
  1647. AfterExcelProcess[i].Kill();
  1648. }
  1649. catch { }
  1650. }
  1651. #endregion*/
  1652. GC.Collect();
  1653. }
  1654. }
  1655. private void Sninsert_DataxlsWrite(object[] data)
  1656. {
  1657. ExcelKill();
  1658. /* #region // 프로세스 얻기
  1659. System.Diagnostics.Process[] BeforeExcelProcess;
  1660. BeforeExcelProcess = System.Diagnostics.Process.GetProcessesByName("EXCEL");
  1661. ArrayList arlProcessID = new ArrayList();
  1662. for (int i = 0; i < BeforeExcelProcess.Length; i++)
  1663. {
  1664. arlProcessID.Add(BeforeExcelProcess[i].Id);
  1665. }
  1666. #endregion*/
  1667. //Write
  1668. //파일이 존재 한다면..삭제 하고..
  1669. /*if (File.Exists("C:\\Test.xls"))
  1670. {
  1671. File.Delete("C:\\Test.xls");
  1672. }*/
  1673. try
  1674. {
  1675. ExcelApp = new Excel.Application();
  1676. Thread.Sleep(1);
  1677. try
  1678. {
  1679. wb = ExcelApp.Workbooks.Open(data[0].ToString(), 0, false, 5, Missing.Value, Missing.Value, false, Missing.Value,
  1680. Missing.Value, true, false, Missing.Value, false, false, false);
  1681. }
  1682. catch { ExcelKill(); return; }
  1683. Thread.Sleep(1);
  1684. ws = wb.Worksheets["Sheet1"] as Excel.Worksheet;
  1685. Thread.Sleep(1);
  1686. //엑셀 시트 인덱스 번호는 0,0 부터 시작 하는 것이 아니라 1,1 A1 부터 시작 함. 0,0 으로 시작하면 오류...
  1687. //시트에 값 쓰기...
  1688. ws.Cells[8, 9] = data[1].ToString();// 제조 번호
  1689. ws.Cells[8, 4] = data[2].ToString();// 일련번호
  1690. ws.Cells[8, 6] = data[3].ToString();//IMEI
  1691. //다른 이름으로 저장하기...
  1692. wb.Save(); // => 오픈한 파일 그대로 저장...
  1693. /* wb.SaveAs("C:\\Test.xls",
  1694. Excel.XlFileFormat.xlWorkbookNormal,
  1695. Type.Missing,
  1696. Type.Missing,
  1697. Type.Missing,
  1698. Type.Missing,
  1699. Excel.XlSaveAsAccessMode.xlNoChange,
  1700. Type.Missing,
  1701. Type.Missing,
  1702. Type.Missing,
  1703. Type.Missing,
  1704. Type.Missing);
  1705. */
  1706. //파일 닫기...
  1707. wb.Close(false, Type.Missing, Type.Missing);
  1708. // wb = null;
  1709. ExcelApp.Quit();
  1710. //ExcelApp = null;
  1711. }
  1712. catch (Exception ex)
  1713. {
  1714. //객체들 메모리 해제
  1715. ReleaseExcelObject(ws);
  1716. ReleaseExcelObject(wb);
  1717. ReleaseExcelObject(ExcelApp);
  1718. /* #region // 프로세스 죽이기
  1719. System.Diagnostics.Process[] AfterExcelProcess;
  1720. AfterExcelProcess = System.Diagnostics.Process.GetProcessesByName("EXCEL");
  1721. for (int i = 0; i < AfterExcelProcess.Length; i++)
  1722. {
  1723. try
  1724. {
  1725. if (!arlProcessID.Contains(AfterExcelProcess[i].Id))
  1726. AfterExcelProcess[i].Kill();
  1727. }
  1728. catch { }
  1729. }
  1730. #endregion*/
  1731. GC.Collect();
  1732. }
  1733. finally
  1734. {
  1735. //객체들 메모리 해제
  1736. ReleaseExcelObject(ws);
  1737. ReleaseExcelObject(wb);
  1738. ReleaseExcelObject(ExcelApp);
  1739. /* #region // 프로세스 죽이기
  1740. System.Diagnostics.Process[] AfterExcelProcess;
  1741. AfterExcelProcess = System.Diagnostics.Process.GetProcessesByName("EXCEL");
  1742. for (int i = 0; i < AfterExcelProcess.Length; i++)
  1743. {
  1744. try
  1745. {
  1746. if (!arlProcessID.Contains(AfterExcelProcess[i].Id))
  1747. AfterExcelProcess[i].Kill();
  1748. }
  1749. catch { }
  1750. }
  1751. #endregion*/
  1752. GC.Collect();
  1753. }
  1754. }
  1755. private void ExportExcel(bool captions)
  1756. {
  1757. this.openFileDialog.FileName = "TempName";
  1758. this.openFileDialog.DefaultExt = "xls";
  1759. this.openFileDialog.Filter = "Excel files (*.xls)|*.xls";
  1760. this.openFileDialog.InitialDirectory = "c:\\";
  1761. DialogResult result = openFileDialog.ShowDialog();
  1762. if (result == DialogResult.OK)
  1763. {
  1764. int num = 0;
  1765. object missingType = Type.Missing;
  1766. Excel.Application objApp;
  1767. Excel._Workbook objBook;
  1768. Excel.Workbooks objBooks;
  1769. Excel.Sheets objSheets;
  1770. Excel._Worksheet objSheet;
  1771. Excel.Range range;
  1772. string[] headers = new string[dataGridView_SnInsert.ColumnCount];
  1773. string[] columns = new string[dataGridView_SnInsert.ColumnCount];
  1774. for (int c = 0; c < dataGridView_SnInsert.ColumnCount; c++)
  1775. {
  1776. headers[c] = dataGridView_SnInsert.Rows[0].Cells[c].OwningColumn.HeaderText.ToString();
  1777. num = c + 65;
  1778. columns[c] = Convert.ToString((char)num);
  1779. }
  1780. try
  1781. {
  1782. objApp = new Excel.Application();
  1783. objBooks = objApp.Workbooks;
  1784. objBook = objBooks.Add(Missing.Value);
  1785. objSheets = objBook.Worksheets;
  1786. objSheet = (Excel._Worksheet)objSheets.get_Item(1);
  1787. if (captions)
  1788. {
  1789. for (int c = 0; c < dataGridView_SnInsert.ColumnCount; c++)
  1790. {
  1791. range = objSheet.get_Range(columns[c] + "1", Missing.Value);
  1792. range.set_Value(Missing.Value, headers[c]);
  1793. }
  1794. }
  1795. for (int i = 0; i < dataGridView_SnInsert.RowCount - 1; i++)
  1796. {
  1797. for (int j = 0; j < dataGridView_SnInsert.ColumnCount; j++)
  1798. {
  1799. range = objSheet.get_Range(columns[j] + Convert.ToString(i + 2),
  1800. Missing.Value);
  1801. range.set_Value(Missing.Value,
  1802. dataGridView_SnInsert.Rows[i].Cells[j].Value.ToString());
  1803. }
  1804. }
  1805. objApp.Visible = false;
  1806. objApp.UserControl = false;
  1807. objBook.SaveAs(@openFileDialog.FileName,
  1808. Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookNormal,
  1809. missingType, missingType, missingType, missingType,
  1810. Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange,
  1811. missingType, missingType, missingType, missingType, missingType);
  1812. objBook.Close(false, missingType, missingType);
  1813. Cursor.Current = Cursors.Default;
  1814. MessageBox.Show("Save Success!!!");
  1815. }
  1816. catch (Exception theException)
  1817. {
  1818. String errorMessage;
  1819. errorMessage = "Error: ";
  1820. errorMessage = String.Concat(errorMessage, theException.Message);
  1821. errorMessage = String.Concat(errorMessage, " Line: ");
  1822. errorMessage = String.Concat(errorMessage, theException.Source);
  1823. MessageBox.Show(errorMessage, "Error");
  1824. }
  1825. }
  1826. }
  1827. private void ReleaseExcelObject(object obj)
  1828. {
  1829. try
  1830. {
  1831. if (obj != null)
  1832. {
  1833. Marshal.ReleaseComObject(obj);
  1834. obj = null;
  1835. }
  1836. }
  1837. catch (Exception ex)
  1838. {
  1839. obj = null;
  1840. throw ex;
  1841. }
  1842. finally
  1843. {
  1844. GC.Collect();
  1845. }
  1846. }
  1847. // CommonOpenFileDialog 클래스 생성
  1848. CommonOpenFileDialog dialog = new CommonOpenFileDialog();
  1849. private void button_Path_Click(object sender, EventArgs e)
  1850. {
  1851. // 처음 보여줄 폴더 설정(안해도 됨)
  1852. //dialog.InitialDirectory = "";
  1853. dialog.IsFolderPicker = true;
  1854. if (dialog.ShowDialog() == CommonFileDialogResult.Ok)
  1855. {
  1856. FileSaveSet = dialog.FileName;
  1857. // label.Text = dialog.FileName;
  1858. // 테스트용, 폴더 선택이 완료되면 선택된 폴더를 label에 출력
  1859. }
  1860. }
  1861. private void dataGridView_Gps_KeyDown(object sender, KeyEventArgs e)
  1862. {
  1863. if (e.KeyCode == Keys.Enter)
  1864. {
  1865. button_GpsTestSave_Click(null, null);
  1866. //to do
  1867. }
  1868. else
  1869. {
  1870. return;
  1871. }
  1872. }
  1873. private void button_PrevFile_Click(object sender, EventArgs e)
  1874. {
  1875. if (openFileDialog.ShowDialog() == DialogResult.OK)
  1876. {
  1877. foreach (string x in openFileDialog.FileNames)
  1878. {
  1879. listBox_PreviousFile.Items.Add(x);
  1880. }
  1881. }
  1882. }
  1883. private void button_AfterFile_Click(object sender, EventArgs e)
  1884. {
  1885. if (openFileDialog.ShowDialog() == DialogResult.OK)
  1886. {
  1887. foreach (string x in openFileDialog.FileNames)
  1888. {
  1889. listBox_AfterFile.Items.Add(x);
  1890. }
  1891. }
  1892. }
  1893. private void label_Merge_Click(object sender, EventArgs e)
  1894. {
  1895. panel_GpsTest.Visible = false;
  1896. panel_SensorTest.Visible = false;
  1897. panel_Catm1Test.Visible = false;
  1898. panel_MergeMain.Visible = true;
  1899. panel_SnCheckMain.Visible = false;
  1900. panel_SnTest.Visible = false;
  1901. }
  1902. private void label_SnCheck_Click(object sender, EventArgs e)
  1903. {
  1904. panel_GpsTest.Visible = false;
  1905. panel_SensorTest.Visible = false;
  1906. panel_Catm1Test.Visible = false;
  1907. panel_MergeMain.Visible = false;
  1908. panel_SnCheckMain.Visible = true;
  1909. panel_SnTest.Visible = false;
  1910. }
  1911. private string Excel03ConString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties='Excel 8.0;HDR={1}'";
  1912. private string Excel07ConString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties='Excel 8.0;HDR={1}'";
  1913. List<string> list1 = new List<string>();
  1914. List<string> list2 = new List<string>();
  1915. private void readExcel()
  1916. {
  1917. /*Excel.Application xlApp;
  1918. Excel.Workbook xlWorkBook;
  1919. Excel.Worksheet xlWorkSheet;
  1920. Excel.Range range;
  1921. string str;
  1922. int rCnt = 0; // 열 갯수
  1923. int cCnt = 0; // 행 갯수
  1924. xlApp = new Excel.Application();
  1925. xlWorkBook = xlApp.Workbooks.Open("d:\\test.xlsx", 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
  1926. xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); // 첫번째 시트를 가져 옴.
  1927. range = xlWorkSheet.UsedRange; // 가져 온 시트의 데이터 범위 값
  1928. for (rCnt = 1; rCnt <= range.Rows.Count; rCnt++)
  1929. {
  1930. for (cCnt = 1; cCnt <= range.Columns.Count; cCnt++)
  1931. {
  1932. str = (string)(range.Cells[rCnt, cCnt] as Excel.Range).Value2; // 열과 행에 해당하는 데이터를 문자열로 반환
  1933. MessageBox.Show(str);
  1934. }
  1935. }
  1936. xlWorkBook.Close(true, null, null);
  1937. xlApp.Quit();
  1938. ReleaseExcelObject(xlWorkSheet);
  1939. ReleaseExcelObject(xlWorkBook);
  1940. ReleaseExcelObject(xlApp);
  1941. GC.Collect();*/
  1942. // 엑셀 문서 내용 추출
  1943. openFileDialog1_FileOk(null, null);
  1944. }
  1945. private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
  1946. {
  1947. string filePath = openFileDialog.FileName;
  1948. string fileExtension = Path.GetExtension(filePath);
  1949. string header = "No";//rbHeaderYes.Checked ? "Yes" : "No";
  1950. string connectionString = string.Empty;
  1951. string sheetName = string.Empty;
  1952. list1.Clear();
  1953. list2.Clear();
  1954. // 확장자로 구분하여 커넥션 스트링을 가져옮
  1955. switch (fileExtension)
  1956. {
  1957. case ".xls": //Excel 97-03
  1958. connectionString = string.Format(Excel03ConString, filePath, header);
  1959. break;
  1960. case ".xlsx": //Excel 07
  1961. connectionString = string.Format(Excel07ConString, filePath, header);
  1962. break;
  1963. }
  1964. // 첫 번째 시트의 이름을 가져옮
  1965. using (OleDbConnection con = new OleDbConnection(connectionString))
  1966. {
  1967. using (OleDbCommand cmd = new OleDbCommand())
  1968. {
  1969. cmd.Connection = con;
  1970. con.Open();
  1971. DataTable dtExcelSchema = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
  1972. sheetName = dtExcelSchema.Rows[0]["TABLE_NAME"].ToString();
  1973. con.Close();
  1974. }
  1975. }
  1976. //Console.WriteLine("sheetName = " + sheetName);
  1977. // 첫 번째 쉬트의 데이타를 읽어서 datagridview 에 보이게 함.
  1978. using (OleDbConnection con = new OleDbConnection(connectionString))
  1979. {
  1980. using (OleDbCommand cmd = new OleDbCommand())
  1981. {
  1982. using (OleDbDataAdapter oda = new OleDbDataAdapter())
  1983. {
  1984. DataTable dt = new DataTable();
  1985. cmd.CommandText = "SELECT * From [" + sheetName + "]";
  1986. cmd.Connection = con;
  1987. con.Open();
  1988. oda.SelectCommand = cmd;
  1989. oda.Fill(dt);
  1990. con.Close();
  1991. //Populate DataGridView.
  1992. dataGridView_Chk.DataSource = dt;
  1993. }
  1994. }
  1995. }
  1996. //dataGridView_Chk.Rows.Remove(1);
  1997. /* for (int i = 0; i < 54; i++)
  1998. {
  1999. dataGridView_Chk.Rows.Remove(dataGridView_Chk.Rows[i]);
  2000. }*/
  2001. for (int i = 1; i <= 18; i++)
  2002. {
  2003. if (i == 3 || i == 8)
  2004. continue;
  2005. dataGridView_Chk.Columns.Remove("F" + i.ToString());
  2006. }
  2007. dataGridView_Chk.Sort(dataGridView_Chk.Columns.GetFirstColumn(DataGridViewElementStates.Visible, DataGridViewElementStates.None), ListSortDirection.Descending);
  2008. for (int i = 0; i < dataGridView_Chk.RowCount; i++)
  2009. {
  2010. if (dataGridView_Chk.Rows[i].Cells[0].Value.ToString() == ""
  2011. || dataGridView_Chk.Rows[i].Cells[1].Value.ToString() == "")
  2012. {
  2013. break;
  2014. }
  2015. list1.Add(dataGridView_Chk.Rows[i].Cells[0].Value.ToString());
  2016. list2.Add(dataGridView_Chk.Rows[i].Cells[1].Value.ToString());
  2017. }
  2018. }
  2019. private void button_FileFindLoad_Click(object sender, EventArgs e)
  2020. {
  2021. if (openFileDialog.ShowDialog() == DialogResult.OK)
  2022. {
  2023. openFileDialog1_FileOk(null, null);
  2024. /*foreach (string x in openFileDialog.FileNames)
  2025. {
  2026. listBox_Previous.Items.Add(x);
  2027. }*/
  2028. }
  2029. }
  2030. private Thread rTh;
  2031. private void button_Merge_Click(object sender, EventArgs e)
  2032. {
  2033. rTh = new Thread(OpenExcelFile);
  2034. rTh.Start();
  2035. //OpenExcelFile();
  2036. }
  2037. // progress bar
  2038. private delegate void myDelegate(int theValue, int theMax);
  2039. delegate void SetTextCallback(string text);
  2040. // 컨트롤의 접근은 따로 함수를 만들어서 접근하도록 한다.
  2041. private void SetText(string text)
  2042. {
  2043. // InvokeRequired required compares the thread ID of the
  2044. // calling thread to the thread ID of the creating thread.
  2045. // If these threads are different, it returns true.
  2046. if (this.label_Cnt.InvokeRequired)
  2047. {
  2048. SetTextCallback d = new SetTextCallback(SetText);
  2049. this.Invoke(d, new object[] { text });
  2050. }
  2051. else
  2052. {
  2053. this.label_Cnt.Text = "Count : " + text;
  2054. }
  2055. }
  2056. private void LabelChkSetText(string text)
  2057. {
  2058. // InvokeRequired required compares the thread ID of the
  2059. // calling thread to the thread ID of the creating thread.
  2060. // If these threads are different, it returns true.
  2061. if (this.label_Cnt.InvokeRequired)
  2062. {
  2063. SetTextCallback d = new SetTextCallback(SetText);
  2064. this.Invoke(d, new object[] { text });
  2065. }
  2066. else
  2067. {
  2068. this.label_Cnt.Text = "Count : " + text;
  2069. }
  2070. }
  2071. //스레드에서 아래 함수를 호출하면 된다.
  2072. private void updateProgress(int theValue, int theMax)
  2073. {
  2074. if (theMax != 0)
  2075. progressBar_Merge.Maximum = theMax;
  2076. progressBar_Merge.Value = theValue;
  2077. }
  2078. #region
  2079. /// <summary>
  2080. /// 엑셀 정식 파일 형식이 아닌 파일 읽기
  2081. /// </summary>
  2082. /// <param name="FileName">파일명.확장자</param>
  2083. /// <returns></returns>
  2084. public void OpenExcelFile()
  2085. {
  2086. string[] APL_CopyArray =
  2087. {
  2088. "D8", "E8", "F8", "G8", "H8",//SKT 일련번호 ,VC생산번호 ,IMEI ,PHONE ,USIM
  2089. "I8", "J8", "K8", "L8", "M8",//블루셀 제조번호,Ver ,SNR ,모뎀 버전 ,RSRP,
  2090. "N8", "O8", "P8", "Q8", "R8",//RSRQ ,"숨기기1" ,"숨기기2" ,"숨기기3" ,BATT,
  2091. "S8", "T8", "U8", "V8", "W8",//SySVolt ,TEMP ,BMAX ,BMAY ,BMAZ
  2092. };
  2093. for (int index = 0; index < listBox_PreviousFile.Items.Count; index++)
  2094. {
  2095. Excel.Workbook xlWorkbook_copy = null;
  2096. Excel.Workbook xlWorkbook_paste = null;
  2097. Excel.Worksheet xlWorksheet_copy = null;
  2098. Excel.Worksheet xlWorksheet_paste = null;
  2099. Excel.Application xlApp_paste = null;
  2100. Excel.Application xlApp_copy = null;
  2101. Excel.Range range = null;
  2102. object data = null;
  2103. string PrevFile = listBox_PreviousFile.Items[index].ToString();
  2104. string AfterFile = listBox_AfterFile.Items[0].ToString();
  2105. try
  2106. {
  2107. xlApp_copy = new Excel.Application();
  2108. xlApp_paste = new Excel.Application();
  2109. xlWorkbook_copy = xlApp_copy.Workbooks.Open(PrevFile);
  2110. // xlWorkbook_paste = xlApp_paste.Workbooks.Open(listBox_AfterFile.Items[0].ToString());
  2111. /* Data 붙여넣을 Excel 파일 변수 초기화 */
  2112. xlWorkbook_paste = xlApp_paste.Workbooks.Open(AfterFile, 0, false, 5, Missing.Value, Missing.Value, false, Missing.Value,
  2113. Missing.Value, true, false, Missing.Value, false, false, false);
  2114. // xlWorksheet_paste = xlApp_paste.Worksheets.Item["2-1 NR 100MHz DL"]; // 특정시트 불러오기.
  2115. /* 2-1 NR 100MHz DL Copy area*/
  2116. xlWorksheet_paste = xlApp_paste.Worksheets.Item[1]; // 특정시트 불러오기.
  2117. xlWorksheet_copy = xlApp_copy.Worksheets.Item[1]; // 특정시트 불러오기.
  2118. for (int i = 0; i < APL_CopyArray.Length; i++)
  2119. {
  2120. range = xlWorksheet_copy.Range[APL_CopyArray[i]];
  2121. data = range.Value;
  2122. xlWorksheet_paste.Cells[8 + index, 4 + i] = data; // 블루셀 제조번호
  2123. }
  2124. xlWorkbook_paste.Save();
  2125. xlWorkbook_paste.Close(true);
  2126. xlApp_paste.Quit();
  2127. xlWorkbook_copy.Close(true);
  2128. xlApp_copy.Quit();
  2129. xlWorkbook_copy = null;
  2130. //xlWorkbook_copy.Save();
  2131. //xlWorkbook_paste = null;
  2132. //
  2133. }
  2134. catch (Exception ex)
  2135. {
  2136. //객체들 메모리 해제
  2137. xlWorkbook_paste.Close(true);
  2138. xlWorkbook_copy.Close(true);
  2139. xlApp_paste.Quit();
  2140. xlApp_copy.Quit();
  2141. ReleaseExcelObject(xlWorksheet_paste);
  2142. ReleaseExcelObject(xlWorkbook_paste);
  2143. ReleaseExcelObject(xlApp_paste);
  2144. ReleaseExcelObject(xlWorksheet_copy);
  2145. ReleaseExcelObject(xlWorkbook_copy);
  2146. ReleaseExcelObject(xlApp_copy);
  2147. GC.Collect();
  2148. rTh.Abort(); //쓰레드 강제 종료
  2149. }
  2150. finally
  2151. {
  2152. //객체들 메모리 해제
  2153. ReleaseExcelObject(xlWorksheet_paste);
  2154. ReleaseExcelObject(xlWorkbook_paste);
  2155. ReleaseExcelObject(xlApp_paste);
  2156. ReleaseExcelObject(xlWorksheet_copy);
  2157. ReleaseExcelObject(xlWorkbook_copy);
  2158. ReleaseExcelObject(xlApp_copy);
  2159. GC.Collect();
  2160. this.Invoke(new myDelegate(updateProgress), new object[] { index + 1, listBox_PreviousFile.Items.Count });
  2161. SetText((index + 1).ToString());
  2162. }
  2163. }
  2164. rTh.Abort(); //쓰레드 강제 종료
  2165. }
  2166. #endregion
  2167. private void button_ChkStart_Click(object sender, EventArgs e)
  2168. {
  2169. string value = "";
  2170. int Chkcnt = 0;
  2171. bool Failed = false;
  2172. int index1 = 0;
  2173. int index2 = 0;
  2174. string data1 = "", data2 = "";
  2175. if (InputBox("번호 입력", "일련 번호:", ref value) == DialogResult.OK)
  2176. {
  2177. for (int i = 0; i < list1.Count; i++)
  2178. {
  2179. if (value == list1[i])
  2180. {
  2181. Chkcnt++;
  2182. index1 = i;
  2183. data1 = value;
  2184. }
  2185. }
  2186. if (Chkcnt > 1)
  2187. {
  2188. listBox_SNDuplicate.Items.Add(value + " Cnt : " + Chkcnt.ToString());
  2189. Failed = true;
  2190. }
  2191. Chkcnt = 0;
  2192. if (InputBox("번호 입력", "생산 번호", ref value) == DialogResult.OK)
  2193. {
  2194. for (int i = 0; i < list2.Count; i++)
  2195. {
  2196. if (value == list2[i])
  2197. {
  2198. Chkcnt++;
  2199. index2 = i;
  2200. data2 = value;
  2201. }
  2202. }
  2203. if (Chkcnt > 1)
  2204. {
  2205. listBox_ProductDuplicate.Items.Add(value + " Cnt : " + Chkcnt.ToString());
  2206. Failed = true;
  2207. }
  2208. Chkcnt = 0;
  2209. }
  2210. if (Failed == true)
  2211. {
  2212. MessageBox.Show("중복항목을 제거 한 후 다시 시도해주세요.", "Error Check", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
  2213. return;
  2214. }
  2215. if (index1 != index2)
  2216. {
  2217. MessageBox.Show("서로 다른 짝 입니다. 확인해주세요.\r" + "\r일련번호 : " + list1[index1] + "\r생산번호 : " + list2[index2], "Error Check", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
  2218. return;
  2219. }
  2220. else
  2221. {
  2222. if (list1[index1] == data1)
  2223. {
  2224. if (list2[index2] == data2)
  2225. {
  2226. MessageBox.Show("서로 맞는 짝입니다.\r" + "\r일련번호 : " + list1[index1] + "\r생산번호 : " + list2[index2]);
  2227. }
  2228. }
  2229. }
  2230. // SN
  2231. /*dataGridView_Sensor.Rows[0].Cells[1].Value = Name = value;
  2232. serialPort.Write(value);
  2233. button_SensorTestSave();
  2234. for (int i = 0; i < 12; i++)
  2235. dataGridView_Sensor.Rows[0].Cells[i].Value = null;*/
  2236. }
  2237. }
  2238. private void button_SNClear_Click(object sender, EventArgs e)
  2239. {
  2240. listBox_SNDuplicate.Items.Clear();
  2241. }
  2242. private void button_DuplicateClear_Click(object sender, EventArgs e)
  2243. {
  2244. listBox_ProductDuplicate.Items.Clear();
  2245. }
  2246. private void button_DiffClear_Click(object sender, EventArgs e)
  2247. {
  2248. listBox_Diff.Items.Clear();
  2249. }
  2250. private void dataGridView_Gps_CellClick(object sender, DataGridViewCellEventArgs e)
  2251. {
  2252. string value = "";
  2253. //BL-VITE00-V
  2254. if (InputBox("번호 입력", "생산 번호:", ref value) == DialogResult.OK)
  2255. {
  2256. // SN
  2257. dataGridView_Sensor.Rows[0].Cells[0].Value = value;
  2258. if (dataGridView_Sensor.Rows[0].Cells[0].Value != null)
  2259. {
  2260. Double SnrMinref = Convert.ToDouble(dataGridView_Gps.Rows[0].Cells[3].Value);
  2261. Double SnrValue = Convert.ToDouble(dataGridView_Gps.Rows[0].Cells[1].Value);
  2262. Double SecValue = Convert.ToDouble(dataGridView_Gps.Rows[0].Cells[4].Value);
  2263. Double SecMaxref = Convert.ToDouble(dataGridView_Gps.Rows[0].Cells[3].Value);
  2264. if (SnrMinref > SnrValue || SecMaxref <= SecValue)
  2265. {
  2266. MessageBox.Show("APL 부적합 Device 입니다.");
  2267. return;
  2268. }
  2269. button_GpsTestSave_Click(null, null);
  2270. gps_arrangecnt = 0;
  2271. ColdCnt = 0;
  2272. dataGridView_Gps.Rows[0].Cells[0].Value = Name = value;
  2273. button_GpsTestSave_Click(null, null);
  2274. dataGridView_Gps_CellClick(null, null);
  2275. }
  2276. }
  2277. }
  2278. private void dataGridView_Catm1_CellClick(object sender, DataGridViewCellEventArgs e)
  2279. {
  2280. string value = "";
  2281. //BL-VITE00-V
  2282. if (InputBox("번호 입력", "생산 번호:", ref value) == DialogResult.OK)
  2283. {
  2284. // SN
  2285. dataGridView_Catm1.Rows[0].Cells[0].Value = Name = value;
  2286. button_Catm1TestSave();
  2287. dataGridView_Catm1_CellClick(null, null);
  2288. }
  2289. }
  2290. private void dataGridView_Sensor_CellClick(object sender, DataGridViewCellEventArgs e)
  2291. {
  2292. string value = "";
  2293. string value1 = "";
  2294. //BL-VITE00-V
  2295. if (InputBox("번호 입력", "생산 번호:", ref value) == DialogResult.OK)
  2296. {
  2297. // SN
  2298. dataGridView_Sensor.Rows[0].Cells[0].Value = Name = value;
  2299. if (InputBox("번호 입력", "SKT SN:", ref value1) == DialogResult.OK)
  2300. {
  2301. dataGridView_Sensor.Rows[0].Cells[1].Value = value1;
  2302. dataGridView_Sensor.Refresh();
  2303. button_SensorTestSave();
  2304. dataGridView_Sensor_CellClick(null, null);
  2305. }
  2306. }
  2307. }
  2308. private void label_SnInsert_Click(object sender, EventArgs e)
  2309. {
  2310. panel_GpsTest.Visible = false;
  2311. panel_SensorTest.Visible = false;
  2312. panel_Catm1Test.Visible = false;
  2313. panel_MergeMain.Visible = false;
  2314. panel_SnCheckMain.Visible = false;
  2315. panel_SnTest.Visible = true;
  2316. }
  2317. private void label_SnInsert_MouseMove(object sender, MouseEventArgs e)
  2318. {
  2319. panel_Sninsert.BackColor = Color.FromArgb(0, 159, 255);
  2320. }
  2321. private void label_Check_MouseLeave(object sender, EventArgs e)
  2322. {
  2323. if (panel_GpsTest.Visible == true)
  2324. {
  2325. panel_Catm1Mode.BackColor = Color.FromArgb(0, 159, 200);
  2326. panel_SensorMode.BackColor = Color.FromArgb(0, 159, 200);
  2327. panel_GpsMode.BackColor = Color.FromArgb(0, 159, 255);
  2328. panel_Merge.BackColor = Color.FromArgb(0, 159, 200);
  2329. panel_SnCheck.BackColor = Color.FromArgb(0, 159, 200);
  2330. panel_Sninsert.BackColor = Color.FromArgb(0, 159, 200);
  2331. }
  2332. else if (panel_Catm1Test.Visible == true)
  2333. {
  2334. panel_Catm1Mode.BackColor = Color.FromArgb(0, 159, 255);
  2335. panel_SensorMode.BackColor = Color.FromArgb(0, 159, 200);
  2336. panel_GpsMode.BackColor = Color.FromArgb(0, 159, 200);
  2337. panel_Merge.BackColor = Color.FromArgb(0, 159, 200);
  2338. panel_SnCheck.BackColor = Color.FromArgb(0, 159, 200);
  2339. panel_Sninsert.BackColor = Color.FromArgb(0, 159, 200);
  2340. }
  2341. else if (panel_SensorTest.Visible == true)
  2342. {
  2343. panel_Catm1Mode.BackColor = Color.FromArgb(0, 159, 200);
  2344. panel_SensorMode.BackColor = Color.FromArgb(0, 159, 255);
  2345. panel_GpsMode.BackColor = Color.FromArgb(0, 159, 200);
  2346. panel_Merge.BackColor = Color.FromArgb(0, 159, 200);
  2347. panel_SnCheck.BackColor = Color.FromArgb(0, 159, 200);
  2348. panel_Sninsert.BackColor = Color.FromArgb(0, 159, 200);
  2349. }
  2350. else if (panel_MergeMain.Visible == true)
  2351. {
  2352. panel_Merge.BackColor = Color.FromArgb(0, 159, 255);
  2353. panel_Catm1Mode.BackColor = Color.FromArgb(0, 159, 200);
  2354. panel_SensorMode.BackColor = Color.FromArgb(0, 159, 200);
  2355. panel_GpsMode.BackColor = Color.FromArgb(0, 159, 200);
  2356. panel_SnCheck.BackColor = Color.FromArgb(0, 159, 200);
  2357. panel_Sninsert.BackColor = Color.FromArgb(0, 159, 200);
  2358. }
  2359. else if (panel_SnCheckMain.Visible == true)
  2360. {
  2361. panel_Merge.BackColor = Color.FromArgb(0, 159, 200);
  2362. panel_Catm1Mode.BackColor = Color.FromArgb(0, 159, 200);
  2363. panel_SensorMode.BackColor = Color.FromArgb(0, 159, 200);
  2364. panel_GpsMode.BackColor = Color.FromArgb(0, 159, 200);
  2365. panel_SnCheck.BackColor = Color.FromArgb(0, 159, 255);
  2366. panel_Sninsert.BackColor = Color.FromArgb(0, 159, 200);
  2367. }
  2368. else if (panel_SnTest.Visible == true)
  2369. {
  2370. panel_Merge.BackColor = Color.FromArgb(0, 159, 200);
  2371. panel_Catm1Mode.BackColor = Color.FromArgb(0, 159, 200);
  2372. panel_SensorMode.BackColor = Color.FromArgb(0, 159, 200);
  2373. panel_GpsMode.BackColor = Color.FromArgb(0, 159, 200);
  2374. panel_SnCheck.BackColor = Color.FromArgb(0, 159, 200);
  2375. panel_Sninsert.BackColor = Color.FromArgb(0, 159, 255);
  2376. }
  2377. }
  2378. private void label_Check_MouseMove(object sender, MouseEventArgs e)
  2379. {
  2380. }
  2381. private void dataGridView_SnInsert_CellClick(object sender, DataGridViewCellEventArgs e)
  2382. {
  2383. string ProductNum = "";
  2384. string SKTNUM = "";
  2385. string IMEI = "";
  2386. if (InputBox("번호 입력", "생산 번호:", ref ProductNum) == DialogResult.OK)
  2387. {
  2388. // SN
  2389. dataGridView_SnInsert.Rows[0].Cells[0].Value = Name = ProductNum;
  2390. if (InputBox("번호 입력", "SKT SN:", ref SKTNUM) == DialogResult.OK)
  2391. {
  2392. dataGridView_SnInsert.Rows[0].Cells[1].Value = SKTNUM;
  2393. if (InputBox("번호 입력", "IMEI:", ref IMEI) == DialogResult.OK)
  2394. {
  2395. dataGridView_SnInsert.Rows[0].Cells[2].Value = IMEI;
  2396. button_SninsertTestSave();
  2397. dataGridView_Sensor.Refresh();
  2398. dataGridView_SnInsert_CellClick(null, null);
  2399. }
  2400. }
  2401. }
  2402. }
  2403. class AutoClosingMessageBox
  2404. {
  2405. [System.Runtime.InteropServices.DllImport("user32.dll", SetLastError = true)]
  2406. static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
  2407. [System.Runtime.InteropServices.DllImport("user32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto)]
  2408. static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);
  2409. System.Threading.Timer _timeoutTimer; //쓰레드 타이머
  2410. string _caption;
  2411. const int WM_CLOSE = 0x0010; //close 명령
  2412. AutoClosingMessageBox(string text, string caption, int timeout)
  2413. {
  2414. _caption = caption;
  2415. _timeoutTimer = new System.Threading.Timer(OnTimerElapsed,
  2416. null, timeout, System.Threading.Timeout.Infinite);
  2417. MessageBox.Show(text, caption);
  2418. }
  2419. //생성자 함수
  2420. public static void Show(string text, string caption, int timeout)
  2421. {
  2422. new AutoClosingMessageBox(text, caption, timeout);
  2423. }
  2424. //시간이 다되면 close 메세지를 보냄
  2425. void OnTimerElapsed(object state)
  2426. {
  2427. IntPtr mbWnd = FindWindow(null, _caption);
  2428. if (mbWnd != IntPtr.Zero)
  2429. SendMessage(mbWnd, WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
  2430. _timeoutTimer.Dispose();
  2431. }
  2432. }
  2433. private void timer1_Tick(object sender, EventArgs e)
  2434. {
  2435. }
  2436. }
  2437. }