12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.IO;
- using System.IO.Ports;
- using System.Linq;
- using System.Runtime.InteropServices;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using Excel = Microsoft.Office.Interop.Excel;
- using System.Reflection;
- using Microsoft.WindowsAPICodePack.Dialogs;
- using System.Threading;
- using System.Data.OleDb;
- using System.Collections;
- using System.Diagnostics;
- //using Microsoft.Office.Interop.Excel;
- namespace APL_TestCheck
- {
- public partial class Main : Form
- {
- public string Serial_Name { get => serialPort.PortName; set => serialPort.PortName = value; }
- public Main()
- {
- InitializeComponent();
- }
- private void panel_PanelMode_MouseLeave(object sender, EventArgs e)
- {
- System.Windows.Forms.Panel Panel = (System.Windows.Forms.Panel)sender;
- Panel.BackColor = Color.FromArgb(0, 159, 200);
- label_GPSTest_MouseLeave(null, null);
- }
- private void panel_PanelMode_MouseMove(object sender, MouseEventArgs e)
- {
- System.Windows.Forms.Panel Panel = (System.Windows.Forms.Panel)sender;
- Panel.BackColor = Color.FromArgb(0, 159, 255);
- }
- private void label_GPSTest_MouseLeave(object sender, EventArgs e)
- {
- if (panel_GpsTest.Visible == true)
- {
- panel_Catm1Mode.BackColor = Color.FromArgb(0, 159, 200);
- panel_SensorMode.BackColor = Color.FromArgb(0, 159, 200);
- panel_GpsMode.BackColor = Color.FromArgb(0, 159, 255);
- panel_Merge.BackColor = Color.FromArgb(0, 159, 200);
- panel_SnCheck.BackColor = Color.FromArgb(0, 159, 200);
- }
- else if (panel_Catm1Test.Visible == true)
- {
- panel_Catm1Mode.BackColor = Color.FromArgb(0, 159, 255);
- panel_SensorMode.BackColor = Color.FromArgb(0, 159, 200);
- panel_GpsMode.BackColor = Color.FromArgb(0, 159, 200);
- panel_Merge.BackColor = Color.FromArgb(0, 159, 200);
- panel_SnCheck.BackColor = Color.FromArgb(0, 159, 200);
- }
- else if (panel_SensorTest.Visible == true)
- {
- panel_Catm1Mode.BackColor = Color.FromArgb(0, 159, 200);
- panel_SensorMode.BackColor = Color.FromArgb(0, 159, 255);
- panel_GpsMode.BackColor = Color.FromArgb(0, 159, 200);
- panel_Merge.BackColor = Color.FromArgb(0, 159, 200);
- panel_SnCheck.BackColor = Color.FromArgb(0, 159, 200);
- }
- else if (panel_MergeMain.Visible == true)
- {
- panel_Merge.BackColor = Color.FromArgb(0, 159, 255);
- panel_Catm1Mode.BackColor = Color.FromArgb(0, 159, 200);
- panel_SensorMode.BackColor = Color.FromArgb(0, 159, 200);
- panel_GpsMode.BackColor = Color.FromArgb(0, 159, 200);
- panel_SnCheck.BackColor = Color.FromArgb(0, 159, 200);
- }
- else if (panel_SnCheckMain.Visible == true)
- {
- panel_Merge.BackColor = Color.FromArgb(0, 159, 200);
- panel_Catm1Mode.BackColor = Color.FromArgb(0, 159, 200);
- panel_SensorMode.BackColor = Color.FromArgb(0, 159, 200);
- panel_GpsMode.BackColor = Color.FromArgb(0, 159, 200);
- panel_SnCheck.BackColor = Color.FromArgb(0, 159, 255);
- }
- }
- private void label_SnCheck_MouseMove(object sender, MouseEventArgs e)
- {
- panel_SnCheck.BackColor = Color.FromArgb(0, 159, 255);
- }
- private void label_Merge_MouseMove(object sender, MouseEventArgs e)
- {
- panel_Merge.BackColor = Color.FromArgb(0, 159, 255);
- }
- private void label_Catm1Test_MouseMove(object sender, MouseEventArgs e)
- {
- panel_Catm1Mode.BackColor = Color.FromArgb(0, 159, 255);
- }
- private void label_SensorTest_MouseMove(object sender, MouseEventArgs e)
- {
- panel_SensorMode.BackColor = Color.FromArgb(0, 159, 255);
- }
- private void label_GPSTest_MouseMove(object sender, MouseEventArgs e)
- {
- panel_GpsMode.BackColor = Color.FromArgb(0, 159, 255);
- }
- public struct POINT { public int X, Y; }
- [DllImport("user32.dll")] // 현재 마우스 위치를 얻기위한 API함수.
- public extern static void GetCursorPos(out POINT point);
- System.Drawing.Point FormLocation; // 현재 폼 위치
- POINT LastLocation = new POINT(); // 방금 전의 마우스 위치
- POINT CurrentLocation = new POINT(); // 현재 마우스 위치
- // 폼이 움직일 양 = CurrentLocation - LastLocation.
- bool IsMouseMoveStart = false; // 현재 마우스 움직이기 기능이 켜져있는가.
- // 만약 이게 없으면 그냥 폼위에서
- private void panel_Main_MouseDown(object sender, MouseEventArgs e)
- {
- GetCursorPos(out CurrentLocation);
- FormLocation = this.Location;
- IsMouseMoveStart = true;
- }
- private void panel_Main_MouseMove(object sender, MouseEventArgs e)
- {
- if (!IsMouseMoveStart) return;
- GetCursorPos(out LastLocation);
- FormLocation.X -= (CurrentLocation.X - LastLocation.X);
- FormLocation.Y -= (CurrentLocation.Y - LastLocation.Y);
- this.Location = FormLocation;
- CurrentLocation = LastLocation;
- }
- private void panel_Main_MouseUp(object sender, MouseEventArgs e)
- {
- IsMouseMoveStart = false;
- }
- private void pictureBox_min_red_Click(object sender, EventArgs e)
- {
- this.WindowState = FormWindowState.Minimized;
- }
- private void pictureBox_X_red_Click(object sender, EventArgs e)
- {
- //Application.Exit();
- }
- private void label_GPSTest_Click(object sender, EventArgs e)
- {
- panel_GpsTest.Visible = true;
- panel_SensorTest.Visible = false;
- panel_Catm1Test.Visible = false;
- panel_MergeMain.Visible = false;
- panel_SnCheckMain.Visible = false;
- panel_SnTest.Visible = false;
- }
- private void label_Catm1Test_Click(object sender, EventArgs e)
- {
- panel_GpsTest.Visible = false;
- panel_SensorTest.Visible = false;
- panel_Catm1Test.Visible = true;
- panel_MergeMain.Visible = false;
- panel_SnCheckMain.Visible = false;
- panel_SnTest.Visible = false;
- }
- private void label_SensorTest_Click(object sender, EventArgs e)
- {
- panel_GpsTest.Visible = false;
- panel_SensorTest.Visible = true;
- panel_Catm1Test.Visible = false;
- panel_MergeMain.Visible = false;
- panel_SnCheckMain.Visible = false;
- panel_SnTest.Visible = false;
- }
- private void Main_Load(object sender, EventArgs e)
- {
- label_Version.Text = Get_BuildDateTime(System.Reflection.Assembly.GetExecutingAssembly().GetName().Version).ToString();
- Serial_Initialize(ref comboBox_Port);
- dataGridView_Gps.RowCount = 1;
- dataGridView_Catm1.RowCount = 1;
- dataGridView_Sensor.RowCount = 1;
- dataGridView_SnInsert.RowCount = 1;
- dataGridView_Gps.Rows[0].Cells[2].Value = "100";
- dataGridView_Gps.Rows[0].Cells[3].Value = "40";
- dataGridView_Gps.Rows[0].Cells[5].Value = "50";
- dataGridView_Gps.Rows[0].Cells[6].Value = "0";
- dataGridView_Sensor.Rows[0].Cells[17].Value = "70"; //BMA X MAX
- dataGridView_Sensor.Rows[0].Cells[18].Value = "-100";//BMA X MIN
- dataGridView_Sensor.Rows[0].Cells[19].Value = "70";//BMA Y MAX
- dataGridView_Sensor.Rows[0].Cells[20].Value = "-100";//BMA X MIN
- dataGridView_Sensor.Rows[0].Cells[21].Value = null;//BMA X MAX
- dataGridView_Sensor.Rows[0].Cells[22].Value = "950";//BMA X MIN
- panel_GpsTest.Visible = true;
- panel_SensorTest.Visible = false;
- panel_Catm1Test.Visible = false;
- panel_MergeMain.Visible = false;
- panel_SnCheckMain.Visible = false;
- panel_SnTest.Visible = false;
- button_Path_Click(null, null);
- }
- public void Serial_Initialize(ref ComboBox cb_port)
- {
- this.serialPort = new System.IO.Ports.SerialPort();
- this.serialPort.DataReceived += new System.IO.Ports.SerialDataReceivedEventHandler(this.sPort_DataReceived);
- cb_port.BeginUpdate();
- foreach (string comport in SerialPort.GetPortNames())//foreach (string comport in SerialPort_TestProgram.GetPortNames())
- {
- cb_port.Items.Add(comport);
- }
- cb_port.EndUpdate();
- //SerialPort 초기 설정.
- // serialPort.Encoding = Encoding.GetEncoding("Windows-1252");
- cb_port.DataSource = SerialPort.GetPortNames();
- try
- {
- serialPort.PortName = Serial_Name = cb_port.SelectedItem.ToString();
- serialPort.BaudRate = (int)115200;
- serialPort.DataBits = (int)8;
- serialPort.Parity = System.IO.Ports.Parity.None;
- serialPort.StopBits = StopBits.One;
- }
- catch { }
- }
- private delegate void StringSend(string Text);
- private delegate void GridviewSend(ref object gridview,string Text);
- private delegate void ByteSend(byte[] Text);
- string startStr = "V";
- string endStr = "\n";
- public void Serial_DataRecvFunction(object sender, SerialDataReceivedEventArgs e)
- {
- int TmpLength = 0;
- //System.Threading.Thread.Sleep(50);
- int nLnegth = serialPort.BytesToRead;
- byte[] btdata = new byte[nLnegth];
- serialPort.Read(btdata, 0, nLnegth);
- string data = Encoding.Default.GetString(btdata);
- if (checkBox_TerminalStop.Checked == true)
- return;
- // string data = serialPort.ReadExisting();
- if (panel_SensorTest.Visible == true)
- {
- if (data.Contains(startStr))
- {
- data = data.Substring(data.IndexOf(startStr));
- if (data.Contains(endStr))
- {
- this.Invoke(new StringSend(Data_Recv_Str), data);
- }
- }
- else
- {
- if (data.Contains("No need write SN"))
- {
- MessageBox.Show("이미 시리얼 넘버가 등록되어 있습니다.");
- }
- else
- {
- this.Invoke(new StringSend(Data_Recv_Str), data);
- }
- }
- }
- else
- {
- this.Invoke(new StringSend(Data_Recv_Str), data);
- }
- /*try
- {
- this.Invoke(new ByteSend(Data_Recv_Str), btdata);
- }
- catch
- {
- }*/
- /****
- *메모리 누수 방지용 코드
- */
- System.GC.Collect(0, GCCollectionMode.Forced);
- System.GC.WaitForFullGCComplete();
- }
- int offset = 0;
- byte[] rxBuffer;
- private void sPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
- {
- if (checkBox_TerminalStop.Checked == true)
- return;
- try
- {
- if (offset == 0)
- {
- rxBuffer = new byte[4096];
- }
- string rxString = "";
- int intRecSize = serialPort.BytesToRead;
- if (intRecSize != 0)
- {
- /* if (panel_GpsTest.Visible == true)
- {
- byte[] btdata = new byte[intRecSize];
- serialPort.Read(btdata, 0, intRecSize);
- string data = Encoding.Default.GetString(rxBuffer);
- this.Invoke(new StringSend(Data_Recv_Str), data);
- }
- else*/
- {
- serialPort.Read(rxBuffer, offset, intRecSize);
- offset += intRecSize;
- for (int iTemp = 0; iTemp < offset; iTemp++)
- {
- rxString += Convert.ToChar(rxBuffer[iTemp]);
- }
- if (panel_SensorTest.Visible == true)
- {
- startStr = "V";
- endStr = "\n";
- }
- else if (panel_Catm1Test.Visible == true)
- {
- startStr = "B";
- endStr = "\n";
- }
- else if (panel_GpsTest.Visible == true)
- {
- startStr = "$";
- endStr = "\n";
- }
- if (rxString.Contains(startStr))
- {
- rxString = rxString.Substring(rxString.IndexOf(startStr));
- if (rxString.Contains(endStr))
- {
- this.Invoke(new StringSend(Data_Recv_Str), rxString);
- //program.dataReceived(rxString, "Receive");
- offset = 0;
- }
- }
- else
- {
- this.Invoke(new StringSend(Data_Recv_Str), rxString);
- offset = 0;
- }
- }
- }
- }
- catch { }
- }
- private void label_Port_MouseClick(object sender, MouseEventArgs e)
- {
- }
- int LineLimit = 500;
- [DllImport("user32.dll")]
- public static extern int SendMessage(IntPtr hWnd, Int32 wMsg, bool wParam, Int32 lParam);
- private const int WM_SETREDRAW = 11;
- public void Data_Recv_Str(string text)
- {
- System.Windows.Forms.RichTextBox tbReceived = null;
- if (panel_GpsTest.Visible == true)
- {
- tbReceived = richTextBox_Gps;
- }
- else if (panel_Catm1Test.Visible == true)
- {
- tbReceived = richTextBox_catm1;
- }
- else if (panel_SensorTest.Visible == true)
- {
- tbReceived = richTextBox_Sensor;
- }
- int nLimitLines = Convert.ToInt32(LineLimit); //제한 라인 수
- try
- {
- try
- {
- SendMessage(this.Handle, WM_SETREDRAW, false, 0);
- }
- catch (Exception e) { MessageBox.Show(e.StackTrace); }
- if (tbReceived.Lines.Length > nLimitLines)
- {
- LinkedList<string> tempLines = new LinkedList<string>(tbReceived.Lines);
- while ((tempLines.Count - nLimitLines) > 0)
- {
- tempLines.RemoveFirst();
- }
- tbReceived.Lines = tempLines.ToArray();
- }
- try
- {
- SendMessage(this.Handle, WM_SETREDRAW, true, 0);
- }
- catch { return; }
- if (checkBox_GPGSV.Checked == true && panel_GpsTest.Visible == true)
- {
- tbReceived.AppendText(GPS_TestFunc(text));
- }
- else if (panel_SensorTest.Visible == true)
- {
- Sensor_TestFunc(text);
- tbReceived.AppendText(text);
- }
- else if (panel_Catm1Test.Visible == true)
- {
- Catm1_TestFunc(text);
- tbReceived.AppendText(text);
- }
- else
- {
- tbReceived.AppendText(text);
- }
- tbReceived.SelectionStart = tbReceived.Text.Length;//맨 마지막 선택...
- tbReceived.ScrollToCaret();
- }
- catch { try { SendMessage(this.Handle, WM_SETREDRAW, true, 0); } catch { return; } }
- }
- public void Data_Recv_Str(byte[] text)
- {
- string strtext = Encoding.Default.GetString(text);
- System.Windows.Forms.RichTextBox tbReceived = null;
- if (panel_GpsTest.Visible == true)
- {
- tbReceived = richTextBox_Gps;
- }
- else if (panel_Catm1Test.Visible == true)
- {
- tbReceived = richTextBox_catm1;
- }
- else if (panel_SensorTest.Visible == true)
- {
- tbReceived = richTextBox_Sensor;
- }
- int nLimitLines = Convert.ToInt32(LineLimit); //제한 라인 수
- try
- {
- try
- {
- SendMessage(this.Handle, WM_SETREDRAW, false, 0);
- }
- catch (Exception e) { MessageBox.Show(e.StackTrace); }
- if (tbReceived.Lines.Length > nLimitLines)
- {
- LinkedList<string> tempLines = new LinkedList<string>(tbReceived.Lines);
- while ((tempLines.Count - nLimitLines) > 0)
- {
- tempLines.RemoveFirst();
- }
- tbReceived.Lines = tempLines.ToArray();
- }
- try
- {
- SendMessage(this.Handle, WM_SETREDRAW, true, 0);
- }
- catch { return; }
- if (checkBox_GPGSV.Checked == true && panel_GpsTest.Visible == true)
- {
- tbReceived.AppendText(GPS_TestFunc(Encoding.Default.GetString(text)));
- }
- else if (panel_SensorTest.Visible == true)
- {
- Sensor_TestFunc(strtext);
- tbReceived.AppendText(strtext);
- }
- else
- {
- tbReceived.AppendText(strtext);
- }
- tbReceived.SelectionStart = tbReceived.Text.Length;//맨 마지막 선택...
- tbReceived.ScrollToCaret();
- }
- catch { try { SendMessage(this.Handle, WM_SETREDRAW, true, 0); } catch { return; } }
- }
- public int WordNum(String data, String fixdata)
- {
- MatchCollection matches = Regex.Matches(data, fixdata);
- return matches.Count;
- }
- double GPS_TestSnRValue = 0;
- int Gps_CurrentCount = 0;
- int TestVal = 0;
- int GPGGA_Cnt = 0,ColdCnt = 0;
- int ArrageGpsData = 0;
- double[] Gps_Arrange = new double[11];
- int gps_arrangecnt = 0;
- private string GPS_TestFunc(string data)
- {
- int Gps_Count, Sentence, SnrIndex = 3;
- // 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";
- // string tmpstr1 = "$GPGSV,2,2,08,24,36,052,37,25,48,159,42,31,17,245,,32,46,312,45*74\r\n";
- string[] tmpstr = new String[3];
- string[] GPGGAstr = new String[3];
- string splitstr = null, str = data;
- string[] sp = str.Split(',');
- string[] GPGGA_sp = str.Split(',');
- int Losscount = 0;
- int location1, location2, LastLocation, SentenceCount;
- int GPGGA_Location,GNGGA_Location, ColdTime = 0;
- bool SaveOk = false;
- try
- {
- /*
- if(TestVal == 0)
- {
- str = tmpstr;
- TestVal++;
- }
- else
- {
- str = tmpstr1;
- TestVal = 0;
- }
- */
- GPGGA_Location = str.IndexOf("$GPGGA");
- GNGGA_Location = str.IndexOf("$GNGGA");
- // SentenceCount = WordNum(str, "GPGGA");
- //ColdTime = Convert.ToInt32(dataGridView_Sensor.Rows[0].Cells[4].Value);
- if (GPGGA_Location != -1 || GNGGA_Location != -1)
- {
- if(GNGGA_Location != -1)
- {
- GPGGA_Location = GNGGA_Location;
- }
- str = str.Substring(GPGGA_Location);
- location2 = str.IndexOf("\r\n");
- splitstr = str.Substring(location2 + 2);
- GPGGAstr[0] = str.Substring(0, location2 + 2);
- GPGGA_sp = GPGGAstr[0].Split(',');
- if (GPGGA_sp[2] != "")
- {
- GPGGA_Cnt++;
- if (GPGGA_Cnt >= 5)
- {
- if (GPGGA_Cnt >= 15)
- {
- SaveOk = true;
- }
- }
- // dataGridView_Gps.Rows[0].Cells[3].Value = GPGGA_sp[2];
-
- }
- else
- {
- ColdCnt++;
- dataGridView_Gps.Rows[0].Cells[4].Value = ColdCnt.ToString();
- gps_arrangecnt = 0;
- //ColdCnt = 0;
- // GPGGA_Cnt = 0;
- Gps_CurrentCount = 0;
- Gps_Arrange[10] = 0;
- dataGridView_Gps.Rows[0].Cells[0].Value = null;
- dataGridView_Gps.Rows[0].Cells[1].Value = null;
- // dataGridView_Gps.Rows[0].Cells[4].Value = null;
- dataGridView_Gps.Refresh();
- return "";
- }
- }
- location1 = str.IndexOf("$GPGSV");
- SentenceCount = WordNum(str, "GPGSV");
- GPS_TestSnRValue = 0;
- Gps_CurrentCount = 0;
- if (location1 != -1)
- {
- if (gps_arrangecnt < 10)
- {
- for (int ii = 0; ii < SentenceCount; ii++)
- {
- SnrIndex = 3;
- if (ii != 0)
- str = splitstr;
- location1 = str.IndexOf("$GPGSV");
- str = str.Substring(location1);
- location2 = str.IndexOf("\r\n");
- splitstr = str.Substring(location2 + 2);
- tmpstr[ii] = str = str.Substring(0, location2 + 2);
- sp = str.Split(',');
- if (sp[3].Contains("*"))
- {
- sp[3] = sp[3].Substring(0, 2);
- // dataGridView_Gps.Rows[0].Cells[1].Value = sp[3];
- Gps_Arrange[gps_arrangecnt++] = Convert.ToDouble(sp[3]);
- return str;
- }
- else
- {
- Sentence = Convert.ToInt32(sp[2]);
- Gps_Count = Convert.ToInt32(sp[3]);
- for (int i = 0; i < 4; i++)
- {
- SnrIndex += 4;
- if (sp[SnrIndex].Contains("*"))
- {
- LastLocation = sp[SnrIndex].IndexOf("*") - 2;
- sp[SnrIndex] = sp[SnrIndex].Substring(0, 2);
- GPS_TestSnRValue += Convert.ToInt32(sp[SnrIndex]);
- }
- else
- {
- if (sp[SnrIndex] == "")
- {
- sp[SnrIndex] = "0";
- Losscount++;
- }
- GPS_TestSnRValue += Convert.ToInt32(sp[SnrIndex]);
- }
- Gps_CurrentCount++;
- if (Gps_CurrentCount == Gps_Count)
- {
- GPS_TestSnRValue /= (Gps_Count - Losscount);
- GPS_TestSnRValue = Math.Round(GPS_TestSnRValue, 1);
- // dataGridView_Gps.Rows[0].Cells[1].Value = GPS_TestSnRValue.ToString();
- Gps_Arrange[gps_arrangecnt++] = Convert.ToDouble(GPS_TestSnRValue);
- break;
- }
- }
- }
- }
- }
- if(gps_arrangecnt >= 10 && dataGridView_Gps.Rows[0].Cells[1].Value == null)
- {
- for (int retcnt = 0; retcnt < 10; retcnt++)
- {
- Gps_Arrange[10] += Gps_Arrange[retcnt];
- Gps_Arrange[retcnt] = 0;
- }
- Gps_Arrange[10] = Gps_Arrange[10] / 10;
- dataGridView_Gps.Rows[0].Cells[1].Value = Gps_Arrange[10].ToString();
- Gps_Arrange[10] = 0;
- }
- str = null;
- for (int a = 0; a < SentenceCount; a++)
- str += tmpstr[a];
- if (dataGridView_Sensor.Rows[0].Cells[0].Value != null && SaveOk == true)
- {
- int SnrMinref = Convert.ToInt32(dataGridView_Gps.Rows[0].Cells[3].Value);
- int SnrValue = Convert.ToInt32(dataGridView_Gps.Rows[0].Cells[1].Value);
- if (SnrMinref > SnrValue)
- {
- MessageBox.Show("APL 부적합 Device 입니다.");
- return "";
- }
- button_GpsTestSave_Click(null, null);
- gps_arrangecnt = 0;
- ColdCnt = 0;
- SaveOk = false;
- }
- return str;
- }
- return "";
- }
- catch (Exception e) { /*MessageBox.Show(e.StackTrace); */}
- return "";
- }
- string SensorData = null;
- private void Sensor_TestFunc(string data)
- {
- string str = data;
- string[] sp = new string[11];
- try
- {
- if (data.Contains("\r\n") == false )
- {
- return;
- }
- else
- {
- SensorData += data;
- str = SensorData;
- }
-
- //if (dataGridView_Sensor.Rows[0].Cells[0].Value != null)
- {
- //location1 = str.IndexOf("\r\n");
- //str = str.Substring(0, location1);
- sp = str.Split(',');
- if (sp[0].Contains("V") == false/* || sp.Length != 11*/)
- {
- SensorData = null;
- return;
- }
- dataGridView_Sensor.Rows[0].Cells[5].Value = sp[0]; //version
- dataGridView_Sensor.Rows[0].Cells[2].Value = "8627850" + sp[2]; //,IMEI
- dataGridView_Sensor.Rows[0].Cells[3].Value = sp[3];//, Phone Number,
- dataGridView_Sensor.Rows[0].Cells[4].Value = sp[4].Substring(6);//USIM Number
- dataGridView_Sensor.Rows[0].Cells[6].Value = sp[5];//, Battery Voltage,
- dataGridView_Sensor.Rows[0].Cells[7].Value = sp[6];// System Voltage,
- dataGridView_Sensor.Rows[0].Cells[8].Value = sp[7];//Temp, BMA400 값 출력 x, y, z
- dataGridView_Sensor.Rows[0].Cells[9].Value = sp[8];//Temp, BMA400 값 출력 x, y, z
- dataGridView_Sensor.Rows[0].Cells[10].Value = sp[9];//Temp, BMA400 값 출력 x, y, z
- if (sp[10].Contains("\r"))
- {
- int loc = sp[10].IndexOf("\r");
- sp[10] = sp[10].Substring(0, loc);
- }
- dataGridView_Sensor.Rows[0].Cells[11].Value = sp[10];//Temp, BMA400 값 출력 x, y, z
- SensorData = null;
- string value = "";
- /*if (checkBox_Edit.Checked == false)
- {
- if (InputBox("번호 입력", "일련 번호:", ref value) == DialogResult.OK)
- {
- // SN
- dataGridView_Sensor.Rows[0].Cells[1].Value = Name = value;
- serialPort.Write("APLSN Write:" + value + "\r\n");
- button_SensorTestSave();
- for (int i = 0; i < 12; i++)
- dataGridView_Sensor.Rows[0].Cells[i].Value = null;
- }
- }*/
- if (dataGridView_Sensor.Rows[0].Cells[0].Value != null)
- {
- if (dataGridView_Sensor.Rows[0].Cells[1].Value != null)
- {
- //dataGridView_Sensor.Rows[0].Cells[1].Value = Name = value;
- if (dataGridView_Sensor.Rows[0].Cells[1].Value.ToString().Length == 7
- && Convert.ToInt32(dataGridView_Sensor.Rows[0].Cells[1].Value) > 0)
- {
- serialPort.Write("APLSN Write:" + dataGridView_Sensor.Rows[0].Cells[1].Value.ToString() + "\r\n");
- label_SerialWrite.Text = "APLSN Write:" + dataGridView_Sensor.Rows[0].Cells[1].Value.ToString() + "\r\n";
- }
- else
- MessageBox.Show("SKT SN이 틀립니다.");
- }
- // button_SensorTestSave();
- }
- dataGridView_Sensor.Refresh();
- }
- return;
- }
- catch (Exception ex) { /*MessageBox.Show(ex.StackTrace); */ }
- }
- string Catm1Data = null;
- private void Catm1_TestFunc(string data)
- {
- string str = data;
- string[] sp = new string[4];
- try
- {
- if (data.Contains("\r\n") == false)
- {
- return;
- }
- else
- {
- Catm1Data += data;
- str = Catm1Data;
- }
- //if (dataGridView_Catm1.Rows[0].Cells[0].Value != null)
- {
- //location1 = str.IndexOf("\r\n");
- //str = str.Substring(0, location1);
- sp = str.Split(',');
- if (sp[0].Contains("B") == false/* || sp.Length != 11*/)
- {
- Catm1Data = null;
- return;
- }
- dataGridView_Catm1.Rows[0].Cells[1].Value = sp[0]; //Modem Ver
- dataGridView_Catm1.Rows[0].Cells[2].Value = sp[1];//RSRP
- if (sp[2].Contains("\r"))
- {
- int loc = sp[2].IndexOf("\r");
- sp[2] = sp[2].Substring(0, loc);
- }
- dataGridView_Catm1.Rows[0].Cells[3].Value = sp[2];//RSRQ
- Catm1Data = null;
- dataGridView_Catm1.Refresh();
- }
- return;
- }
- catch (Exception ex) { /*MessageBox.Show(ex.StackTrace); */ }
- }
- private void label_Port_MouseLeave(object sender, EventArgs e)
- {
- panel_Port.BackColor = Color.FromArgb(0, 159, 200);
- }
- private void label_Port_MouseMove(object sender, MouseEventArgs e)
- {
- panel_Port.BackColor = Color.FromArgb(0, 159, 255);
- }
- private void label_Port_Click(object sender, EventArgs e)
- {
- // Boolean ret = false;
- try
- {
- if (serialPort.IsOpen) // 이미 포트가 열려 있을 때
- { //When the port is open
- serialPort.Close();
- label_Port.Text = "Port Open";
- //ret = true;
- }
- else//When the port is close //포트가 열려 있지 않을 때
- {
- if (comboBox_Port.Text != "")
- {
- serialPort.PortName = Serial_Name = comboBox_Port.SelectedItem.ToString();
- serialPort.BaudRate = Convert.ToInt32(comboBox_bps.Text);
- serialPort.Open();
- label_Port.Text = "Port Close";
- // Debug.Debug_Main_Form_Get(this.main_form);
- }
- else
- {
- MessageBox.Show("Port is not set");
- // ret = true;
- }
- }
- }
- catch
- {
- MessageBox.Show("Port Open Faile" + Serial_Name);
- }
- // return ret;
- }
- public static DialogResult InputBox(string title, string promptText, ref string value)
- {
- Form form = new Form();
- System.Windows.Forms.Label label = new System.Windows.Forms.Label();
- System.Windows.Forms.TextBox textBox = new System.Windows.Forms.TextBox();
- System.Windows.Forms.Button buttonOk = new System.Windows.Forms.Button();
- System.Windows.Forms.Button buttonCancel = new System.Windows.Forms.Button();
- form.Text = title;
- label.Text = promptText;
- textBox.Text = value;
- buttonOk.Text = "OK";
- buttonCancel.Text = "Cancel";
- buttonOk.DialogResult = DialogResult.OK;
- buttonCancel.DialogResult = DialogResult.Cancel;
- label.SetBounds(9, 20, 372, 13);
- textBox.SetBounds(12, 36, 372, 20);
- buttonOk.SetBounds(228, 72, 75, 23);
- buttonCancel.SetBounds(309, 72, 75, 23);
- label.AutoSize = true;
- textBox.Anchor = textBox.Anchor | AnchorStyles.Right;
- buttonOk.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
- buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
- form.ClientSize = new Size(396, 107);
- form.Controls.AddRange(new Control[] { label, textBox, buttonOk, buttonCancel });
- form.ClientSize = new Size(Math.Max(300, label.Right + 10), form.ClientSize.Height);
- form.FormBorderStyle = FormBorderStyle.FixedDialog;
- form.StartPosition = FormStartPosition.CenterScreen;
- form.MinimizeBox = false;
- form.MaximizeBox = false;
- form.AcceptButton = buttonOk;
- form.CancelButton = buttonCancel;
- DialogResult dialogResult = form.ShowDialog();
- value = textBox.Text;
- return dialogResult;
- }
- private void button_Clear_Click(object sender, EventArgs e)
- {
- System.Windows.Forms.RichTextBox tbReceived = null;
- if (panel_GpsTest.Visible == true)
- {
- tbReceived = richTextBox_Gps;
- }
- else if (panel_Catm1Test.Visible == true)
- {
- tbReceived = richTextBox_catm1;
- }
- else if (panel_SensorTest.Visible == true)
- {
- tbReceived = richTextBox_Sensor;
- }
- tbReceived.Text = "";
- }
- string FileSaveSet = null;
- void Gps_ThreadRun(string dst, object Value1, object Value2, object Value3)
- {
- //DST : 위치
- //Value1 : 생산 번호
- //Value2 : SNR
- Thread Gps_thread = new Thread(delegate ()
- {
- Gps_DataxlsWrite(dst, Value1, Value2, Value3);
- });
- Gps_thread.Start();
- }
- void Catm1_ThreadRun(object dst, object Product, object Modemver, object Rsrp, object Rsrq)
- {
- //DST : 위치
- //Value1 : 생산 번호
- //Value2 : Modem Ver
- //Value3 : RSRP
- //Value4 : RSRQ
- Thread Catm1_thread = new Thread(delegate ()
- {
- Catm1_DataxlsWrite(dst, Product, Modemver, Rsrp, Rsrq);
- });
- Catm1_thread.Start();
- }
- void Sensor_ThreadRun(object[] data)
- {
- //DST : 위치
- //Value1 : 생산 번호
- //Value2 : Modem Ver
- //Value3 : RSRP
- //Value4 : RSRQ
- Thread Sensor_thread = new Thread(delegate ()
- {
- Sensor_DataxlsWrite(data);
- });
- Sensor_thread.Start();
- }
- void Sninsert_ThreadRun(object[] data)
- {
- //DST : 위치
- //Value1 : 생산 번호
- //Value2 : SKT NUM
- //Value3 : IMEI
- Thread Sninsert_thread = new Thread(delegate ()
- {
- Sninsert_DataxlsWrite(data);
- });
- Sninsert_thread.Start();
- }
- //Thread rTh_Gps;
- string CurrentExcelFilePath = null;
- private void button_GpsTestSave_Click(object sender, EventArgs e)
- {
- //rTh_Gps = new Thread(new ParameterizedThreadStart(Gps_DataxlsWrite));
- //Thread.Sleep(1000);
- AutoClosingMessageBox.Show("저장 중.....", "알림", 1000);
- string CheckProductionNum = null;
- try
- {
- CheckProductionNum = dataGridView_Gps.Rows[0].Cells[0].Value.ToString();
- }
- catch
- {
- }
- try
- {
- if (!CheckProductionNum.Contains("BL-VITE00-V"))
- {
- MessageBox.Show("잘못된 생산 번호 입니다.");
- return;
- }
- }
- catch
- {
- MessageBox.Show("생산번호를 적어주세요.");
- }
- string Ref_Xls_File = new System.IO.DirectoryInfo(System.Windows.Forms.Application.StartupPath).ToString();
- string Dst_Xls_File = null;
- Ref_Xls_File = Ref_Xls_File + @"\APL_200307.xls";
- FileInfo SrcfileInfo = new FileInfo(Ref_Xls_File);
- FileInfo DstfileInfo;
- if (dataGridView_Gps.Rows[0].Cells[0].Value != null
- && dataGridView_Gps.Rows[0].Cells[1].Value != null)
- {
- if (SrcfileInfo.Exists)
- {
- if (FileSaveSet == null)
- {
- button_Path_Click(null, null);
- return;
- // MessageBox.Show("레퍼런스 엑셀 파일이 존재하지 않습니다. \r\n강차장님에게 문의 하세요.");
- }
- else
- {
- // File Copy 후 Data 입력
- Dst_Xls_File = FileSaveSet + @"\" + dataGridView_Gps.Rows[0].Cells[0].Value.ToString() + @".xls";
- DstfileInfo = new FileInfo(Dst_Xls_File);
- if (DstfileInfo.Exists)
- {
- if (MessageBox.Show("이미 파일이 있습니다.\r\n 덮어씌우겠습니까?", "YesOrNo", MessageBoxButtons.YesNo) == DialogResult.Yes)
- {
- try
- {
- // File.Copy(Ref_Xls_File, Dst_Xls_File, true);
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.StackTrace);
- return;
- }
- }
- else
- {
- //MessageBox.Show("아니요 클릭");
- return; // 아니오시 Return;
- }
- }
- else
- {
- File.Copy(Ref_Xls_File, Dst_Xls_File);
-
- Thread.Sleep(2000);
- }
- }
- }
- else
- {
- MessageBox.Show("레퍼런스 엑셀 파일이 존재하지 않습니다. \r\n강차장님에게 문의 하세요.");
- return;
- }
- }
- else
- {
- MessageBox.Show("생산번호/GPS SNR 값이 제대로 입력 되지 않았습니다.\r\n확인후 다시 저장하세요.");
- return;
- }
- // rTh_Gps.Start();
- //Gps_DataxlsWrite(Dst_Xls_File, dataGridView_Gps.Rows[0].Cells[0].Value, dataGridView_Gps.Rows[0].Cells[1].Value);
- Gps_ThreadRun(Dst_Xls_File, dataGridView_Gps.Rows[0].Cells[0].Value, dataGridView_Gps.Rows[0].Cells[1].Value, dataGridView_Gps.Rows[0].Cells[4].Value);
- dataGridView_Gps.Rows[0].Cells[0].Value = null;
- dataGridView_Gps.Rows[0].Cells[1].Value = null;
- dataGridView_Gps.Rows[0].Cells[4].Value = null;
- dataGridView_Gps.Refresh();
- AutoClosingMessageBox.Show("완료 되었습니다.", "알림", 1000);
- // if (!di.Exists) { di.Create(); }
- //string tmppath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
- #if false
- if (dataGridView_Gps.Rows[0].Cells[1].Value != null)
- {
- string path = @"xxxx.txt";
- FileInfo file = new FileInfo(path);
- if (file.Exists)
- { //파일이 있는지
- //복사(경로,덮어쓰기 옵션 기본값 false)
- //만약 덮어쓰기 false일 때 파일이 존재하면 에러남.
- file.CopyTo(@"xxx2.txt", true);
- }
- }
- #endif
- //this.Close();
- //MessageBox.
- }
- private void button_SensorTestSave()
- {
- string CheckProductionNum = null;
- object[] data = new object[15];// 0 :파일위치
- AutoClosingMessageBox.Show("저장 중.....", "알림", 1000);
- try
- {
- CheckProductionNum = dataGridView_Sensor.Rows[0].Cells[0].Value.ToString();
- }
- catch
- {
- }
- try
- {
- if (!CheckProductionNum.Contains("BL-VITE00-V"))
- {
- MessageBox.Show("잘못된 생산 번호 입니다.");
- return;
- }
- }
- catch
- {
- MessageBox.Show("생산번호를 적어주세요.");
- }
- string Ref_Xls_File = new System.IO.DirectoryInfo(System.Windows.Forms.Application.StartupPath).ToString();
- string Dst_Xls_File = null;
- Ref_Xls_File = Ref_Xls_File + @"\APL_200307.xls";
- FileInfo SrcfileInfo = new FileInfo(Ref_Xls_File);
- FileInfo DstfileInfo;
- if (dataGridView_Sensor.Rows[0].Cells[0].Value != null)
- {
- if (SrcfileInfo.Exists)
- {
- if (FileSaveSet == null)
- {
- button_Path_Click(null, null);
- return;
- // MessageBox.Show("레퍼런스 엑셀 파일이 존재하지 않습니다. \r\n강차장님에게 문의 하세요.");
- }
- else
- {
- // File Copy 후 Data 입력
- Dst_Xls_File = FileSaveSet + @"\" + dataGridView_Sensor.Rows[0].Cells[0].Value.ToString() + @".xls";
- DstfileInfo = new FileInfo(Dst_Xls_File);
- CurrentExcelFilePath = Dst_Xls_File;
- if (DstfileInfo.Exists)
- {
- if (MessageBox.Show("이미 파일이 있습니다.\r\n 덮어씌우겠습니까?", "YesOrNo", MessageBoxButtons.YesNo) == DialogResult.Yes)
- {
- try
- {
- // File.Copy(Ref_Xls_File, Dst_Xls_File, true);
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.StackTrace);
- return;
- }
- }
- else
- {
- //MessageBox.Show("아니요 클릭");
- return; // 아니오시 Return;
- }
- }
- else
- {
- File.Copy(Ref_Xls_File, Dst_Xls_File);
-
- Thread.Sleep(2000);
- }
- }
- }
- else
- {
- MessageBox.Show("레퍼런스 엑셀 파일이 존재하지 않습니다. \r\n강차장님에게 문의 하세요.");
- return;
- }
- }
- else
- {
- MessageBox.Show("생산번호 값이 제대로 입력 되지 않았습니다.\r\n확인후 다시 저장하세요.");
- return;
- }
- //
- data[0] = Dst_Xls_File;
- for (int i = 0; i < 13; i++)
- data[i + 1] = dataGridView_Sensor.Rows[0].Cells[i].Value;
- //Sensor_DataxlsWrite();
- Sensor_ThreadRun(data);
-
- for (int i = 0; i < 13; i++)
- dataGridView_Sensor.Rows[0].Cells[i].Value = null;
- dataGridView_Sensor.Refresh();
- // dataGridView_Sensor.Rows[0].Cells[0].Value = null;
- // dataGridView_Sensor.Rows[0].Cells[1].Value = null;
- // if (!di.Exists) { di.Create(); }
- //string tmppath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
- #if false
- if (dataGridView_Gps.Rows[0].Cells[1].Value != null)
- {
- string path = @"xxxx.txt";
- FileInfo file = new FileInfo(path);
- if (file.Exists)
- { //파일이 있는지
- //복사(경로,덮어쓰기 옵션 기본값 false)
- //만약 덮어쓰기 false일 때 파일이 존재하면 에러남.
- file.CopyTo(@"xxx2.txt", true);
- }
- }
- #endif
- }
- private void button_Catm1TestSave()
- {
- string CheckProductionNum = null;
- AutoClosingMessageBox.Show("저장 중.....", "알림", 1000);
- try
- {
- CheckProductionNum = dataGridView_Catm1.Rows[0].Cells[0].Value.ToString();
- }
- catch
- {
- }
- try
- {
- if (!CheckProductionNum.Contains("BL-VITE00-V"))
- {
- MessageBox.Show("잘못된 생산 번호 입니다.");
- return;
- }
- }
- catch
- {
- MessageBox.Show("생산번호를 적어주세요.");
- }
- string Ref_Xls_File = new System.IO.DirectoryInfo(System.Windows.Forms.Application.StartupPath).ToString();
- string Dst_Xls_File = null;
- Ref_Xls_File = Ref_Xls_File + @"\APL_200307.xls";
- FileInfo SrcfileInfo = new FileInfo(Ref_Xls_File);
- FileInfo DstfileInfo;
- if (dataGridView_Catm1.Rows[0].Cells[0].Value != null)
- {
- if (SrcfileInfo.Exists)
- {
- if (FileSaveSet == null)
- {
- button_Path_Click(null, null);
- return;
- // MessageBox.Show("레퍼런스 엑셀 파일이 존재하지 않습니다. \r\n강차장님에게 문의 하세요.");
- }
- else
- {
- // File Copy 후 Data 입력
- Dst_Xls_File = FileSaveSet + @"\" + dataGridView_Catm1.Rows[0].Cells[0].Value.ToString() + @".xls";
- DstfileInfo = new FileInfo(Dst_Xls_File);
- if (DstfileInfo.Exists)
- {
- if (MessageBox.Show("이미 파일이 있습니다.\r\n 덮어씌우겠습니까?", "YesOrNo", MessageBoxButtons.YesNo) == DialogResult.Yes)
- {
- try
- {
- // File.Copy(Ref_Xls_File, Dst_Xls_File, true);
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.StackTrace);
- return;
- }
- }
- else
- {
- //MessageBox.Show("아니요 클릭");
- return; // 아니오시 Return;
- }
- }
- else
- {
- File.Copy(Ref_Xls_File, Dst_Xls_File);
- Thread.Sleep(2000);
- }
- }
- }
- else
- {
- MessageBox.Show("레퍼런스 엑셀 파일이 존재하지 않습니다. \r\n강차장님에게 문의 하세요.");
- return;
- }
- }
- else
- {
- MessageBox.Show("생산번호 값이 제대로 입력 되지 않았습니다.\r\n확인후 다시 저장하세요.");
- return;
- }
- 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);
- for (int i = 0; i < 4; i++)
- dataGridView_Catm1.Rows[0].Cells[i].Value = null;
- dataGridView_Catm1.Refresh();
- AutoClosingMessageBox.Show("완료 되었습니다.", "알림", 1000);
- //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);
- // dataGridView_Catm1.Rows[0].Cells[0].Value = null;
- // dataGridView_Catm1.Rows[0].Cells[1].Value = null;
- // if (!di.Exists) { di.Create(); }
- //string tmppath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
- #if false
- if (dataGridView_Gps.Rows[0].Cells[1].Value != null)
- {
- string path = @"xxxx.txt";
- FileInfo file = new FileInfo(path);
- if (file.Exists)
- { //파일이 있는지
- //복사(경로,덮어쓰기 옵션 기본값 false)
- //만약 덮어쓰기 false일 때 파일이 존재하면 에러남.
- file.CopyTo(@"xxx2.txt", true);
- }
- }
- #endif
- }
- private void button_SninsertTestSave()
- {
- string CheckProductionNum = null;
- object[] data = new object[4];// 0 :파일위치
- AutoClosingMessageBox.Show("저장 중.....", "알림", 1000);
- try
- {
- CheckProductionNum = dataGridView_SnInsert.Rows[0].Cells[0].Value.ToString();
- }
- catch
- {
- }
- try
- {
- if (!CheckProductionNum.Contains("BL-VITE00-V"))
- {
- MessageBox.Show("잘못된 생산 번호 입니다.");
- return;
- }
- }
- catch
- {
- MessageBox.Show("생산번호를 적어주세요.");
- }
- string Ref_Xls_File = new System.IO.DirectoryInfo(System.Windows.Forms.Application.StartupPath).ToString();
- string Dst_Xls_File = null;
- Ref_Xls_File = Ref_Xls_File + @"\APL_200307.xls";
- FileInfo SrcfileInfo = new FileInfo(Ref_Xls_File);
- FileInfo DstfileInfo;
- if (dataGridView_SnInsert.Rows[0].Cells[0].Value != null)
- {
- if (SrcfileInfo.Exists)
- {
- if (FileSaveSet == null)
- {
- button_Path_Click(null, null);
- return;
- // MessageBox.Show("레퍼런스 엑셀 파일이 존재하지 않습니다. \r\n강차장님에게 문의 하세요.");
- }
- else
- {
- // File Copy 후 Data 입력
- Dst_Xls_File = FileSaveSet + @"\" + dataGridView_SnInsert.Rows[0].Cells[0].Value.ToString() + @".xls";
- DstfileInfo = new FileInfo(Dst_Xls_File);
- if (DstfileInfo.Exists)
- {
- if (MessageBox.Show("이미 파일이 있습니다.\r\n 덮어씌우겠습니까?", "YesOrNo", MessageBoxButtons.YesNo) == DialogResult.Yes)
- {
- try
- {
- // File.Copy(Ref_Xls_File, Dst_Xls_File, true);
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.StackTrace);
- return;
- }
- }
- else
- {
- //MessageBox.Show("아니요 클릭");
- return; // 아니오시 Return;
- }
- }
- else
- {
- File.Copy(Ref_Xls_File, Dst_Xls_File);
- Thread.Sleep(2000);
- }
- }
- }
- else
- {
- MessageBox.Show("레퍼런스 엑셀 파일이 존재하지 않습니다. \r\n강차장님에게 문의 하세요.");
- return;
- }
- }
- else
- {
- MessageBox.Show("생산번호 값이 제대로 입력 되지 않았습니다.\r\n확인후 다시 저장하세요.");
- return;
- }
- //
- data[0] = Dst_Xls_File;
- if (radioButton_Imei.Checked == true)
- {
- for (int i = 0; i < 3; i++)
- data[i + 1] = dataGridView_SnInsert.Rows[0].Cells[i].Value;
- }
- else
- {
- for (int i = 0; i < 2; i++)
- data[i + 1] = dataGridView_SnInsert.Rows[0].Cells[i].Value;
- }
- //Sensor_DataxlsWrite();
- Sninsert_ThreadRun(data);
- AutoClosingMessageBox.Show("완료 되었습니다.", "알림", 1000);
- if (radioButton_Imei.Checked == true)
- {
- for (int i = 0; i < 3; i++)
- dataGridView_SnInsert.Rows[0].Cells[i].Value = null;
- }
- else
- {
- for (int i = 0; i < 2; i++)
- dataGridView_SnInsert.Rows[0].Cells[i].Value = null;
- }
- dataGridView_SnInsert.Refresh();
- // dataGridView_Sensor.Rows[0].Cells[0].Value = null;
- // dataGridView_Sensor.Rows[0].Cells[1].Value = null;
- // if (!di.Exists) { di.Create(); }
- //string tmppath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
- #if false
- if (dataGridView_Gps.Rows[0].Cells[1].Value != null)
- {
- string path = @"xxxx.txt";
- FileInfo file = new FileInfo(path);
- if (file.Exists)
- { //파일이 있는지
- //복사(경로,덮어쓰기 옵션 기본값 false)
- //만약 덮어쓰기 false일 때 파일이 존재하면 에러남.
- file.CopyTo(@"xxx2.txt", true);
- }
- }
- #endif
- }
- private void ExcelKill()
- {
- System.Diagnostics.Process[] process = System.Diagnostics.Process.GetProcessesByName("EXCEL");
- foreach (System.Diagnostics.Process p in process)
- {
- if (!string.IsNullOrEmpty(p.ProcessName))
- {
- try
- {
- p.Kill();
- }
- catch { }
- }
- }
- }
- Excel.Application ExcelApp = null;
- Excel.Workbook wb = null;
- Excel.Worksheet ws = null;
- private void Gps_DataxlsWrite(object dst, object Value1, object Value2, object Value3)
- {
- /* #region // 프로세스 얻기
- System.Diagnostics.Process[] BeforeExcelProcess;
- BeforeExcelProcess = System.Diagnostics.Process.GetProcessesByName("EXCEL");
- ArrayList arlProcessID = new ArrayList();
- for (int i = 0; i < BeforeExcelProcess.Length; i++)
- {
- arlProcessID.Add(BeforeExcelProcess[i].Id);
- }
- #endregion
- */
- ExcelKill();
- //Write
- //파일이 존재 한다면..삭제 하고..
- /*if (File.Exists("C:\\Test.xls"))
- {
- File.Delete("C:\\Test.xls");
- }*/
- try
- {
- ExcelApp = new Excel.Application();
- Thread.Sleep(1);
- try
- {
- wb = ExcelApp.Workbooks.Open(dst.ToString(), 0, false, 5, Missing.Value, Missing.Value, false, Missing.Value,
- Missing.Value, true, false, Missing.Value, false, false, false);
- }
- catch { ExcelKill(); return; }
- Thread.Sleep(1);
- ws = wb.Worksheets["Sheet1"] as Excel.Worksheet;
- Thread.Sleep(1);
- /*ExcelApp = new Excel.Application();
- wb = ExcelApp.Workbooks.Open(dst.ToString(), 0, false, 5, Missing.Value, Missing.Value, false, Missing.Value,
- Missing.Value, true, false, Missing.Value, false, false, false);
- wb = ExcelApp.Workbooks.Open(dst.ToString());*/
- ws = wb.Worksheets["Sheet1"] as Excel.Worksheet;
- //엑셀 시트 인덱스 번호는 0,0 부터 시작 하는 것이 아니라 1,1 A1 부터 시작 함. 0,0 으로 시작하면 오류...
- //시트에 값 쓰기...
- ws.Cells[8, 9] = Value1.ToString();//dataGridView_Gps.Rows[0].Cells[0].Value;
- ws.Cells[8, 11] = Value2.ToString();//dataGridView_Gps.Rows[0].Cells[1].Value;
- ws.Cells[8, 16] = Value3.ToString(); // Cold Second
- /*ws.Cells[1, 3] = "123";
- ws.Cells[1, 4] = "1234";
- ws.Cells[2, 1] = "Test1"; //A2
- ws.Cells[3, 1] = "Test12"; //A3
- ws.Cells[4, 1] = "Test123"; //A4*/
- //다른 이름으로 저장하기...
- wb.Save(); // => 오픈한 파일 그대로 저장...
- /* wb.SaveAs("C:\\Test.xls",
- Excel.XlFileFormat.xlWorkbookNormal,
- Type.Missing,
- Type.Missing,
- Type.Missing,
- Type.Missing,
- Excel.XlSaveAsAccessMode.xlNoChange,
- Type.Missing,
- Type.Missing,
- Type.Missing,
- Type.Missing,
- Type.Missing);
- */
- //파일 닫기...
- wb.Close(false, Type.Missing, Type.Missing);
- // wb = null;
- ExcelApp.Quit();
- }
- catch (Exception ex)
- {
- //객체들 메모리 해제
- ReleaseExcelObject(ws);
- ReleaseExcelObject(wb);
- ReleaseExcelObject(ExcelApp);
- /* #region // 프로세스 죽이기
- System.Diagnostics.Process[] AfterExcelProcess;
- AfterExcelProcess = System.Diagnostics.Process.GetProcessesByName("EXCEL");
- for (int i = 0; i < AfterExcelProcess.Length; i++)
- {
- try
- {
- if (!arlProcessID.Contains(AfterExcelProcess[i].Id))
- AfterExcelProcess[i].Kill();
- }
- catch { }
- }
- #endregion*/
- GC.Collect();
- }
- finally
- {
- //객체들 메모리 해제
- ReleaseExcelObject(ws);
- ReleaseExcelObject(wb);
- ReleaseExcelObject(ExcelApp);
- /* #region // 프로세스 죽이기
- System.Diagnostics.Process[] AfterExcelProcess;
- AfterExcelProcess = System.Diagnostics.Process.GetProcessesByName("EXCEL");
- for (int i = 0; i < AfterExcelProcess.Length; i++)
- {
- try
- {
- if (!arlProcessID.Contains(AfterExcelProcess[i].Id))
- AfterExcelProcess[i].Kill();
- }
- catch { }
- }
- #endregion*/
- //ExcelApp = null;
- GC.Collect();
- }
- }
- private void Sensor_DataxlsWrite(object[] data)
- {
- ExcelKill();
- /* #region // 프로세스 얻기
- System.Diagnostics.Process[] BeforeExcelProcess;
- BeforeExcelProcess = System.Diagnostics.Process.GetProcessesByName("EXCEL");
- ArrayList arlProcessID = new ArrayList();
- for (int i = 0; i < BeforeExcelProcess.Length; i++)
- {
- arlProcessID.Add(BeforeExcelProcess[i].Id);
- }
- #endregion*/
- //Write
- //파일이 존재 한다면..삭제 하고..
- /*if (File.Exists("C:\\Test.xls"))
- {
- File.Delete("C:\\Test.xls");
- }*/
- try
- {
- ExcelApp = new Excel.Application();
- Thread.Sleep(1);
- try
- {
- wb = ExcelApp.Workbooks.Open(data[0].ToString(), 0, false, 5, Missing.Value, Missing.Value, false, Missing.Value,
- Missing.Value, true, false, Missing.Value, false, false, false);
- }
- catch { ExcelKill(); return; }
- Thread.Sleep(1);
- ws = wb.Worksheets["Sheet1"] as Excel.Worksheet;
- Thread.Sleep(1);
- //엑셀 시트 인덱스 번호는 0,0 부터 시작 하는 것이 아니라 1,1 A1 부터 시작 함. 0,0 으로 시작하면 오류...
- //시트에 값 쓰기...
- for (int i = 1; i < 13; i++){
- if(data[i] == null)
- {
- data[i] = "";
- }
- }
- // ws.Range("M6", "R6").EntireRow.Hidden = false; // ROW 숨기기
- ws.Cells[8, 9] = data[1].ToString();//dataGridView_Sensor.Rows[0].Cells[0].Value; // 제조 번호
- ws.Cells[8, 4] = data[2].ToString();//dataGridView_Sensor.Rows[0].Cells[1].Value; // 일련번호
- if (checkBox_Usim_Imei_Phone_Num.Checked == true)
- {
- ws.Cells[8, 6] = data[3].ToString();//dataGridView_Sensor.Rows[0].Cells[2].Value; //IMEI
- ws.Cells[8, 7] = data[4].ToString();//dataGridView_Sensor.Rows[0].Cells[3].Value;// PHONE
- ws.Cells[8, 8] = data[5].ToString();//dataGridView_Sensor.Rows[0].Cells[4].Value;//USIM
- }
- ws.Cells[8, 10] = data[6].ToString();//dataGridView_Sensor.Rows[0].Cells[5].Value;//FIRM VEBR
- ws.Cells[8, 17] = data[13].ToString();//BLE 나중에 추가해서 Num 다름
- ws.Cells[8, 18] = data[7].ToString();//dataGridView_Sensor.Rows[0].Cells[6].Value;//BATT
- ws.Cells[8, 19] = data[8].ToString();//dataGridView_Sensor.Rows[0].Cells[7].Value;//SYS
- ws.Cells[8, 20] = data[9].ToString();//dataGridView_Sensor.Rows[0].Cells[8].Value;//TEMP
- ws.Cells[8, 21] = data[10].ToString();//dataGridView_Sensor.Rows[0].Cells[9].Value;//BMA
- ws.Cells[8, 22] = data[11].ToString();//dataGridView_Sensor.Rows[0].Cells[10].Value;//BMA
- ws.Cells[8, 23] = data[12].ToString();//dataGridView_Sensor.Rows[0].Cells[11].Value;//BMA
- /*ws.Cells[1, 3] = "123";
- ws.Cells[1, 4] = "1234";
- ws.Cells[2, 1] = "Test1"; //A2
- ws.Cells[3, 1] = "Test12"; //A3
- ws.Cells[4, 1] = "Test123"; //A4*/
- //다른 이름으로 저장하기...
- wb.Save(); // => 오픈한 파일 그대로 저장...
- /* wb.SaveAs("C:\\Test.xls",
- Excel.XlFileFormat.xlWorkbookNormal,
- Type.Missing,
- Type.Missing,
- Type.Missing,
- Type.Missing,
- Excel.XlSaveAsAccessMode.xlNoChange,
- Type.Missing,
- Type.Missing,
- Type.Missing,
- Type.Missing,
- Type.Missing);
- */
- //파일 닫기...
- wb.Close(false, Type.Missing, Type.Missing);
- // wb = null;
- ExcelApp.Quit();
- //ExcelApp = null;
- }
- catch (Exception ex)
- {
- //객체들 메모리 해제
- ReleaseExcelObject(ws);
- ReleaseExcelObject(wb);
- ReleaseExcelObject(ExcelApp);
- /* #region // 프로세스 죽이기
- System.Diagnostics.Process[] AfterExcelProcess;
- AfterExcelProcess = System.Diagnostics.Process.GetProcessesByName("EXCEL");
- for (int i = 0; i < AfterExcelProcess.Length; i++)
- {
- try
- {
- if (!arlProcessID.Contains(AfterExcelProcess[i].Id))
- AfterExcelProcess[i].Kill();
- }
- catch { }
- }
- #endregion*/
- GC.Collect();
- // AutoClosingMessageBox.Show("완료 되었습니다.", "알림", 1000);
- }
- finally
- {
- //객체들 메모리 해제
- ReleaseExcelObject(ws);
- ReleaseExcelObject(wb);
- ReleaseExcelObject(ExcelApp);
- /* #region // 프로세스 죽이기
- System.Diagnostics.Process[] AfterExcelProcess;
- AfterExcelProcess = System.Diagnostics.Process.GetProcessesByName("EXCEL");
- for (int i = 0; i < AfterExcelProcess.Length; i++)
- {
- try
- {
- if (!arlProcessID.Contains(AfterExcelProcess[i].Id))
- AfterExcelProcess[i].Kill();
- }
- catch { }
- }
- #endregion*/
- GC.Collect();
- Thread.Sleep(1000);
- AutoClosingMessageBox.Show("완료 되었습니다.", "알림", 1000);
- ExcelKill();
-
-
-
- }
- if (checkBox_ExcelOpen.Checked == true)
- {
- Thread.Sleep(Convert.ToInt32(numericUpDown_ExcelOpenDelay.Value));
- Process.Start(CurrentExcelFilePath);
- }
- dataGridView_Sensor_CellClick(null, null);
- }
- private void Catm1_DataxlsWrite(object dst, object Product, object Modemver, object Rsrp, object Rsrq)
- {
- ExcelKill();
- /* #region // 프로세스 얻기
- System.Diagnostics.Process[] BeforeExcelProcess;
- BeforeExcelProcess = System.Diagnostics.Process.GetProcessesByName("EXCEL");
- ArrayList arlProcessID = new ArrayList();
- for (int i = 0; i < BeforeExcelProcess.Length; i++)
- {
- arlProcessID.Add(BeforeExcelProcess[i].Id);
- }
- #endregion*/
- //Write
- //파일이 존재 한다면..삭제 하고..
- /*if (File.Exists("C:\\Test.xls"))
- {
- File.Delete("C:\\Test.xls");
- }*/
- try
- {
- ExcelApp = new Excel.Application();
- Thread.Sleep(1);
- try
- {
- wb = ExcelApp.Workbooks.Open(dst.ToString(), 0, false, 5, Missing.Value, Missing.Value, false, Missing.Value,
- Missing.Value, true, false, Missing.Value, false, false, false);
- }
- catch { ExcelKill(); return; }
- Thread.Sleep(1);
- ws = wb.Worksheets["Sheet1"] as Excel.Worksheet;
- Thread.Sleep(1);
- //엑셀 시트 인덱스 번호는 0,0 부터 시작 하는 것이 아니라 1,1 A1 부터 시작 함. 0,0 으로 시작하면 오류...
- //시트에 값 쓰기...
- ws.Cells[8, 9] = Product.ToString();//dataGridView_Catm1.Rows[0].Cells[0].Value; //Bluecell 제조 번호
- ws.Cells[8, 12] = Modemver.ToString(); //dataGridView_Catm1.Rows[0].Cells[5].Value;//RSRP
- ws.Cells[8, 13] = Rsrp.ToString(); //dataGridView_Catm1.Rows[0].Cells[6].Value;//RSRQ
- ws.Cells[8, 14] = Rsrq.ToString(); //dataGridView_Catm1.Rows[0].Cells[6].Value;//RSRQ
- /*ws.Cells[1, 3] = "123";
- ws.Cells[1, 4] = "1234";
- ws.Cells[2, 1] = "Test1"; //A2
- ws.Cells[3, 1] = "Test12"; //A3
- ws.Cells[4, 1] = "Test123"; //A4*/
- //다른 이름으로 저장하기...
- wb.Save(); // => 오픈한 파일 그대로 저장...
- /* wb.SaveAs("C:\\Test.xls",
- Excel.XlFileFormat.xlWorkbookNormal,
- Type.Missing,
- Type.Missing,
- Type.Missing,
- Type.Missing,
- Excel.XlSaveAsAccessMode.xlNoChange,
- Type.Missing,
- Type.Missing,
- Type.Missing,
- Type.Missing,
- Type.Missing);
- */
- //파일 닫기...
- wb.Close(false, Type.Missing, Type.Missing);
- // wb = null;
- ExcelApp.Quit();
- //ExcelApp = null;
- }
- catch (Exception ex)
- {
- //객체들 메모리 해제
- ReleaseExcelObject(ws);
- ReleaseExcelObject(wb);
- ReleaseExcelObject(ExcelApp);
- /* #region // 프로세스 죽이기
- System.Diagnostics.Process[] AfterExcelProcess;
- AfterExcelProcess = System.Diagnostics.Process.GetProcessesByName("EXCEL");
- for (int i = 0; i < AfterExcelProcess.Length; i++)
- {
- try
- {
- if (!arlProcessID.Contains(AfterExcelProcess[i].Id))
- AfterExcelProcess[i].Kill();
- }
- catch { }
- }
- #endregion*/
- GC.Collect();
- }
- finally
- {
- //객체들 메모리 해제
- ReleaseExcelObject(ws);
- ReleaseExcelObject(wb);
- ReleaseExcelObject(ExcelApp);
- /* #region // 프로세스 죽이기
- System.Diagnostics.Process[] AfterExcelProcess;
- AfterExcelProcess = System.Diagnostics.Process.GetProcessesByName("EXCEL");
- for (int i = 0; i < AfterExcelProcess.Length; i++)
- {
- try
- {
- if (!arlProcessID.Contains(AfterExcelProcess[i].Id))
- AfterExcelProcess[i].Kill();
- }
- catch { }
- }
- #endregion*/
- GC.Collect();
- }
- }
- private void Sninsert_DataxlsWrite(object[] data)
- {
- ExcelKill();
- /* #region // 프로세스 얻기
- System.Diagnostics.Process[] BeforeExcelProcess;
- BeforeExcelProcess = System.Diagnostics.Process.GetProcessesByName("EXCEL");
- ArrayList arlProcessID = new ArrayList();
- for (int i = 0; i < BeforeExcelProcess.Length; i++)
- {
- arlProcessID.Add(BeforeExcelProcess[i].Id);
- }
- #endregion*/
- //Write
- //파일이 존재 한다면..삭제 하고..
- /*if (File.Exists("C:\\Test.xls"))
- {
- File.Delete("C:\\Test.xls");
- }*/
- try
- {
- ExcelApp = new Excel.Application();
- Thread.Sleep(1);
- try
- {
- wb = ExcelApp.Workbooks.Open(data[0].ToString(), 0, false, 5, Missing.Value, Missing.Value, false, Missing.Value,
- Missing.Value, true, false, Missing.Value, false, false, false);
- }
- catch { ExcelKill(); return; }
- Thread.Sleep(1);
- ws = wb.Worksheets["Sheet1"] as Excel.Worksheet;
- Thread.Sleep(1);
- //엑셀 시트 인덱스 번호는 0,0 부터 시작 하는 것이 아니라 1,1 A1 부터 시작 함. 0,0 으로 시작하면 오류...
- //시트에 값 쓰기...
- if (radioButton_Imei.Checked == true)
- {
- ws.Cells[8, 9] = data[1].ToString();// 제조 번호
- ws.Cells[8, 4] = data[2].ToString();// 일련번호
- ws.Cells[8, 6] = data[3].ToString();//IMEI
- ws.Cells[8, 15] = "OK";
- }
- else
- {
- ws.Cells[8, 9] = data[1].ToString();// 제조 번호
- ws.Cells[8, 8] = data[2].ToString();// 일련번호
- }
- //다른 이름으로 저장하기...
- wb.Save(); // => 오픈한 파일 그대로 저장...
- /* wb.SaveAs("C:\\Test.xls",
- Excel.XlFileFormat.xlWorkbookNormal,
- Type.Missing,
- Type.Missing,
- Type.Missing,
- Type.Missing,
- Excel.XlSaveAsAccessMode.xlNoChange,
- Type.Missing,
- Type.Missing,
- Type.Missing,
- Type.Missing,
- Type.Missing);
- */
- //파일 닫기...
- wb.Close(false, Type.Missing, Type.Missing);
- // wb = null;
- ExcelApp.Quit();
- //ExcelApp = null;
- }
- catch (Exception ex)
- {
- //객체들 메모리 해제
- ReleaseExcelObject(ws);
- ReleaseExcelObject(wb);
- ReleaseExcelObject(ExcelApp);
- /* #region // 프로세스 죽이기
- System.Diagnostics.Process[] AfterExcelProcess;
- AfterExcelProcess = System.Diagnostics.Process.GetProcessesByName("EXCEL");
- for (int i = 0; i < AfterExcelProcess.Length; i++)
- {
- try
- {
- if (!arlProcessID.Contains(AfterExcelProcess[i].Id))
- AfterExcelProcess[i].Kill();
- }
- catch { }
- }
- #endregion*/
- GC.Collect();
- }
- finally
- {
- //객체들 메모리 해제
- ReleaseExcelObject(ws);
- ReleaseExcelObject(wb);
- ReleaseExcelObject(ExcelApp);
- /* #region // 프로세스 죽이기
- System.Diagnostics.Process[] AfterExcelProcess;
- AfterExcelProcess = System.Diagnostics.Process.GetProcessesByName("EXCEL");
- for (int i = 0; i < AfterExcelProcess.Length; i++)
- {
- try
- {
- if (!arlProcessID.Contains(AfterExcelProcess[i].Id))
- AfterExcelProcess[i].Kill();
- }
- catch { }
- }
- #endregion*/
- GC.Collect();
-
- }
- }
- private void ExportExcel(bool captions)
- {
- this.openFileDialog.FileName = "TempName";
- this.openFileDialog.DefaultExt = "xls";
- this.openFileDialog.Filter = "Excel files (*.xls)|*.xls";
- this.openFileDialog.InitialDirectory = "c:\\";
- DialogResult result = openFileDialog.ShowDialog();
- if (result == DialogResult.OK)
- {
- int num = 0;
- object missingType = Type.Missing;
- Excel.Application objApp;
- Excel._Workbook objBook;
- Excel.Workbooks objBooks;
- Excel.Sheets objSheets;
- Excel._Worksheet objSheet;
- Excel.Range range;
- string[] headers = new string[dataGridView_SnInsert.ColumnCount];
- string[] columns = new string[dataGridView_SnInsert.ColumnCount];
- for (int c = 0; c < dataGridView_SnInsert.ColumnCount; c++)
- {
- headers[c] = dataGridView_SnInsert.Rows[0].Cells[c].OwningColumn.HeaderText.ToString();
- num = c + 65;
- columns[c] = Convert.ToString((char)num);
- }
- try
- {
- objApp = new Excel.Application();
- objBooks = objApp.Workbooks;
- objBook = objBooks.Add(Missing.Value);
- objSheets = objBook.Worksheets;
- objSheet = (Excel._Worksheet)objSheets.get_Item(1);
- if (captions)
- {
- for (int c = 0; c < dataGridView_SnInsert.ColumnCount; c++)
- {
- range = objSheet.get_Range(columns[c] + "1", Missing.Value);
- range.set_Value(Missing.Value, headers[c]);
- }
- }
- for (int i = 0; i < dataGridView_SnInsert.RowCount - 1; i++)
- {
- for (int j = 0; j < dataGridView_SnInsert.ColumnCount; j++)
- {
- range = objSheet.get_Range(columns[j] + Convert.ToString(i + 2),
- Missing.Value);
- range.set_Value(Missing.Value,
- dataGridView_SnInsert.Rows[i].Cells[j].Value.ToString());
- }
- }
- objApp.Visible = false;
- objApp.UserControl = false;
- objBook.SaveAs(@openFileDialog.FileName,
- Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookNormal,
- missingType, missingType, missingType, missingType,
- Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange,
- missingType, missingType, missingType, missingType, missingType);
- objBook.Close(false, missingType, missingType);
- Cursor.Current = Cursors.Default;
- MessageBox.Show("Save Success!!!");
- }
- catch (Exception theException)
- {
- String errorMessage;
- errorMessage = "Error: ";
- errorMessage = String.Concat(errorMessage, theException.Message);
- errorMessage = String.Concat(errorMessage, " Line: ");
- errorMessage = String.Concat(errorMessage, theException.Source);
- MessageBox.Show(errorMessage, "Error");
- }
- }
- }
- private void ReleaseExcelObject(object obj)
- {
- try
- {
- if (obj != null)
- {
- Marshal.ReleaseComObject(obj);
- obj = null;
- }
- }
- catch (Exception ex)
- {
- obj = null;
- throw ex;
- }
- finally
- {
- GC.Collect();
- }
- }
- // CommonOpenFileDialog 클래스 생성
- CommonOpenFileDialog dialog = new CommonOpenFileDialog();
- private void button_Path_Click(object sender, EventArgs e)
- {
- // 처음 보여줄 폴더 설정(안해도 됨)
- //dialog.InitialDirectory = "";
- dialog.IsFolderPicker = true;
- if (dialog.ShowDialog() == CommonFileDialogResult.Ok)
- {
- FileSaveSet = dialog.FileName;
- // label.Text = dialog.FileName;
- // 테스트용, 폴더 선택이 완료되면 선택된 폴더를 label에 출력
- }
- }
- private void dataGridView_Gps_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Enter)
- {
- //button_GpsTestSave_Click(null, null);
- //to do
- }
- else
- {
- return;
- }
- }
- private void button_PrevFile_Click(object sender, EventArgs e)
- {
- if (openFileDialog.ShowDialog() == DialogResult.OK)
- {
- foreach (string x in openFileDialog.FileNames)
- {
- listBox_PreviousFile.Items.Add(x);
- }
- }
- }
- private void button_AfterFile_Click(object sender, EventArgs e)
- {
- if (openFileDialog.ShowDialog() == DialogResult.OK)
- {
- foreach (string x in openFileDialog.FileNames)
- {
- listBox_AfterFile.Items.Add(x);
- }
- }
- }
- private void label_Merge_Click(object sender, EventArgs e)
- {
- panel_GpsTest.Visible = false;
- panel_SensorTest.Visible = false;
- panel_Catm1Test.Visible = false;
- panel_MergeMain.Visible = true;
- panel_SnCheckMain.Visible = false;
- panel_SnTest.Visible = false;
- }
- private void label_SnCheck_Click(object sender, EventArgs e)
- {
- panel_GpsTest.Visible = false;
- panel_SensorTest.Visible = false;
- panel_Catm1Test.Visible = false;
- panel_MergeMain.Visible = false;
- panel_SnCheckMain.Visible = true;
- panel_SnTest.Visible = false;
- }
- private string Excel03ConString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties='Excel 8.0;HDR={1}'";
- private string Excel07ConString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties='Excel 8.0;HDR={1}'";
- List<string> list1 = new List<string>();
- List<string> list2 = new List<string>();
- private void readExcel()
- {
- /*Excel.Application xlApp;
- Excel.Workbook xlWorkBook;
- Excel.Worksheet xlWorkSheet;
- Excel.Range range;
- string str;
- int rCnt = 0; // 열 갯수
- int cCnt = 0; // 행 갯수
- xlApp = new Excel.Application();
- xlWorkBook = xlApp.Workbooks.Open("d:\\test.xlsx", 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
- xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); // 첫번째 시트를 가져 옴.
- range = xlWorkSheet.UsedRange; // 가져 온 시트의 데이터 범위 값
- for (rCnt = 1; rCnt <= range.Rows.Count; rCnt++)
- {
- for (cCnt = 1; cCnt <= range.Columns.Count; cCnt++)
- {
- str = (string)(range.Cells[rCnt, cCnt] as Excel.Range).Value2; // 열과 행에 해당하는 데이터를 문자열로 반환
- MessageBox.Show(str);
- }
- }
- xlWorkBook.Close(true, null, null);
- xlApp.Quit();
- ReleaseExcelObject(xlWorkSheet);
- ReleaseExcelObject(xlWorkBook);
- ReleaseExcelObject(xlApp);
- GC.Collect();*/
- // 엑셀 문서 내용 추출
- openFileDialog1_FileOk(null, null);
- }
- private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
- {
- string filePath = openFileDialog.FileName;
- string fileExtension = Path.GetExtension(filePath);
- string header = "No";//rbHeaderYes.Checked ? "Yes" : "No";
- string connectionString = string.Empty;
- string sheetName = string.Empty;
- list1.Clear();
- list2.Clear();
- // 확장자로 구분하여 커넥션 스트링을 가져옮
- switch (fileExtension)
- {
- case ".xls": //Excel 97-03
- connectionString = string.Format(Excel03ConString, filePath, header);
- break;
- case ".xlsx": //Excel 07
- connectionString = string.Format(Excel07ConString, filePath, header);
- break;
- }
- // 첫 번째 시트의 이름을 가져옮
- using (OleDbConnection con = new OleDbConnection(connectionString))
- {
- using (OleDbCommand cmd = new OleDbCommand())
- {
- cmd.Connection = con;
- con.Open();
- DataTable dtExcelSchema = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
- sheetName = dtExcelSchema.Rows[0]["TABLE_NAME"].ToString();
- con.Close();
- }
- }
- //Console.WriteLine("sheetName = " + sheetName);
- // 첫 번째 쉬트의 데이타를 읽어서 datagridview 에 보이게 함.
- using (OleDbConnection con = new OleDbConnection(connectionString))
- {
- using (OleDbCommand cmd = new OleDbCommand())
- {
- using (OleDbDataAdapter oda = new OleDbDataAdapter())
- {
- DataTable dt = new DataTable();
- cmd.CommandText = "SELECT * From [" + sheetName + "]";
- cmd.Connection = con;
- con.Open();
- oda.SelectCommand = cmd;
- oda.Fill(dt);
- con.Close();
- //Populate DataGridView.
- dataGridView_Chk.DataSource = dt;
- }
- }
- }
- //dataGridView_Chk.Rows.Remove(1);
- /* for (int i = 0; i < 54; i++)
- {
- dataGridView_Chk.Rows.Remove(dataGridView_Chk.Rows[i]);
- }*/
- for (int i = 1; i <= 18; i++)
- {
- if (i == 3 || i == 8)
- continue;
- dataGridView_Chk.Columns.Remove("F" + i.ToString());
- }
- dataGridView_Chk.Sort(dataGridView_Chk.Columns.GetFirstColumn(DataGridViewElementStates.Visible, DataGridViewElementStates.None), ListSortDirection.Descending);
- for (int i = 0; i < dataGridView_Chk.RowCount; i++)
- {
- if (dataGridView_Chk.Rows[i].Cells[0].Value.ToString() == ""
- || dataGridView_Chk.Rows[i].Cells[1].Value.ToString() == "")
- {
- break;
- }
- list1.Add(dataGridView_Chk.Rows[i].Cells[0].Value.ToString());
- list2.Add(dataGridView_Chk.Rows[i].Cells[1].Value.ToString());
- }
- }
- private void button_FileFindLoad_Click(object sender, EventArgs e)
- {
- if (openFileDialog.ShowDialog() == DialogResult.OK)
- {
- openFileDialog1_FileOk(null, null);
- /*foreach (string x in openFileDialog.FileNames)
- {
- listBox_Previous.Items.Add(x);
- }*/
- }
- }
- private Thread rTh;
- private void button_Merge_Click(object sender, EventArgs e)
- {
- rTh = new Thread(OpenExcelFile);
- rTh.Start();
- //OpenExcelFile();
- }
- // progress bar
- private delegate void myDelegate(int theValue, int theMax);
- delegate void SetTextCallback(string text);
- // 컨트롤의 접근은 따로 함수를 만들어서 접근하도록 한다.
- private void SetText(string text)
- {
- // InvokeRequired required compares the thread ID of the
- // calling thread to the thread ID of the creating thread.
- // If these threads are different, it returns true.
- if (this.label_Cnt.InvokeRequired)
- {
- SetTextCallback d = new SetTextCallback(SetText);
- this.Invoke(d, new object[] { text });
- }
- else
- {
- this.label_Cnt.Text = "Count : " + text;
- }
- }
- private void LabelChkSetText(string text)
- {
- // InvokeRequired required compares the thread ID of the
- // calling thread to the thread ID of the creating thread.
- // If these threads are different, it returns true.
- if (this.label_Cnt.InvokeRequired)
- {
- SetTextCallback d = new SetTextCallback(SetText);
- this.Invoke(d, new object[] { text });
- }
- else
- {
- this.label_Cnt.Text = "Count : " + text;
- }
- }
- //스레드에서 아래 함수를 호출하면 된다.
- private void updateProgress(int theValue, int theMax)
- {
- if (theMax != 0)
- progressBar_Merge.Maximum = theMax;
- progressBar_Merge.Value = theValue;
- }
- #region
- /// <summary>
- /// 엑셀 정식 파일 형식이 아닌 파일 읽기
- /// </summary>
- /// <param name="FileName">파일명.확장자</param>
- /// <returns></returns>
- public void OpenExcelFile()
- {
- string[] APL_CopyArray =
- {
- "D8", "E8", "F8", "G8", "H8",//SKT 일련번호 ,VC생산번호 ,IMEI ,PHONE ,USIM
- "I8", "J8", "K8", "L8", "M8",//블루셀 제조번호,Ver ,SNR ,모뎀 버전 ,RSRP,
- "N8", "O8", "P8", "Q8", "R8",//RSRQ ,"숨기기1" ,"숨기기2" ,"숨기기3" ,BATT,
- "S8", "T8", "U8", "V8", "W8",//SySVolt ,TEMP ,BMAX ,BMAY ,BMAZ
- };
- for (int index = 0; index < listBox_PreviousFile.Items.Count; index++)
- {
- Excel.Workbook xlWorkbook_copy = null;
- Excel.Workbook xlWorkbook_paste = null;
- Excel.Worksheet xlWorksheet_copy = null;
- Excel.Worksheet xlWorksheet_paste = null;
- Excel.Application xlApp_paste = null;
- Excel.Application xlApp_copy = null;
- Excel.Range range = null;
- object data = null;
- string PrevFile = listBox_PreviousFile.Items[index].ToString();
- string AfterFile = listBox_AfterFile.Items[0].ToString();
- try
- {
- xlApp_copy = new Excel.Application();
- xlApp_paste = new Excel.Application();
- xlWorkbook_copy = xlApp_copy.Workbooks.Open(PrevFile);
- // xlWorkbook_paste = xlApp_paste.Workbooks.Open(listBox_AfterFile.Items[0].ToString());
- /* Data 붙여넣을 Excel 파일 변수 초기화 */
- xlWorkbook_paste = xlApp_paste.Workbooks.Open(AfterFile, 0, false, 5, Missing.Value, Missing.Value, false, Missing.Value,
- Missing.Value, true, false, Missing.Value, false, false, false);
- // xlWorksheet_paste = xlApp_paste.Worksheets.Item["2-1 NR 100MHz DL"]; // 특정시트 불러오기.
- /* 2-1 NR 100MHz DL Copy area*/
- xlWorksheet_paste = xlApp_paste.Worksheets.Item[1]; // 특정시트 불러오기.
- xlWorksheet_copy = xlApp_copy.Worksheets.Item[1]; // 특정시트 불러오기.
- for (int i = 0; i < APL_CopyArray.Length; i++)
- {
- range = xlWorksheet_copy.Range[APL_CopyArray[i]];
- data = range.Value;
- xlWorksheet_paste.Cells[8 + index, 4 + i] = data; // 블루셀 제조번호
- }
- xlWorkbook_paste.Save();
- xlWorkbook_paste.Close(true);
- xlApp_paste.Quit();
- xlWorkbook_copy.Close(true);
- xlApp_copy.Quit();
- xlWorkbook_copy = null;
- //xlWorkbook_copy.Save();
- //xlWorkbook_paste = null;
- //
- }
- catch (Exception ex)
- {
- //객체들 메모리 해제
- xlWorkbook_paste.Close(true);
- xlWorkbook_copy.Close(true);
- xlApp_paste.Quit();
- xlApp_copy.Quit();
- ReleaseExcelObject(xlWorksheet_paste);
- ReleaseExcelObject(xlWorkbook_paste);
- ReleaseExcelObject(xlApp_paste);
- ReleaseExcelObject(xlWorksheet_copy);
- ReleaseExcelObject(xlWorkbook_copy);
- ReleaseExcelObject(xlApp_copy);
- GC.Collect();
- rTh.Abort(); //쓰레드 강제 종료
- }
- finally
- {
- //객체들 메모리 해제
- ReleaseExcelObject(xlWorksheet_paste);
- ReleaseExcelObject(xlWorkbook_paste);
- ReleaseExcelObject(xlApp_paste);
- ReleaseExcelObject(xlWorksheet_copy);
- ReleaseExcelObject(xlWorkbook_copy);
- ReleaseExcelObject(xlApp_copy);
- GC.Collect();
- this.Invoke(new myDelegate(updateProgress), new object[] { index + 1, listBox_PreviousFile.Items.Count });
- SetText((index + 1).ToString());
- }
- }
- rTh.Abort(); //쓰레드 강제 종료
- }
- #endregion
- private void button_ChkStart_Click(object sender, EventArgs e)
- {
- string value = "";
- int Chkcnt = 0;
- bool Failed = false;
- int index1 = 0;
- int index2 = 0;
- string data1 = "", data2 = "";
- if (InputBox("번호 입력", "일련 번호:", ref value) == DialogResult.OK)
- {
- for (int i = 0; i < list1.Count; i++)
- {
- if (value == list1[i])
- {
- Chkcnt++;
- index1 = i;
- data1 = value;
- }
- }
- if (Chkcnt > 1)
- {
- listBox_SNDuplicate.Items.Add(value + " Cnt : " + Chkcnt.ToString());
- Failed = true;
- }
- Chkcnt = 0;
- if (InputBox("번호 입력", "생산 번호", ref value) == DialogResult.OK)
- {
- for (int i = 0; i < list2.Count; i++)
- {
- if (value == list2[i])
- {
- Chkcnt++;
- index2 = i;
- data2 = value;
- }
- }
- if (Chkcnt > 1)
- {
- listBox_ProductDuplicate.Items.Add(value + " Cnt : " + Chkcnt.ToString());
- Failed = true;
- }
- Chkcnt = 0;
- }
- if (Failed == true)
- {
- MessageBox.Show("중복항목을 제거 한 후 다시 시도해주세요.", "Error Check", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
- return;
- }
- if (index1 != index2)
- {
- MessageBox.Show("서로 다른 짝 입니다. 확인해주세요.\r" + "\r일련번호 : " + list1[index1] + "\r생산번호 : " + list2[index2], "Error Check", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
- return;
- }
- else
- {
- if (list1[index1] == data1)
- {
- if (list2[index2] == data2)
- {
- MessageBox.Show("서로 맞는 짝입니다.\r" + "\r일련번호 : " + list1[index1] + "\r생산번호 : " + list2[index2]);
- }
- }
- }
- // SN
- /*dataGridView_Sensor.Rows[0].Cells[1].Value = Name = value;
- serialPort.Write(value);
- button_SensorTestSave();
- for (int i = 0; i < 12; i++)
- dataGridView_Sensor.Rows[0].Cells[i].Value = null;*/
- }
- }
- private void button_SNClear_Click(object sender, EventArgs e)
- {
- listBox_SNDuplicate.Items.Clear();
- }
- private void button_DuplicateClear_Click(object sender, EventArgs e)
- {
- listBox_ProductDuplicate.Items.Clear();
- }
- private void button_DiffClear_Click(object sender, EventArgs e)
- {
- listBox_Diff.Items.Clear();
- }
- private void dataGridView_Gps_CellClick(object sender, DataGridViewCellEventArgs e)
- {
- string value = "";
- //BL-VITE00-V
- if (InputBox("번호 입력", "생산 번호:", ref value) == DialogResult.OK)
- {
- // SN
- dataGridView_Gps.Rows[0].Cells[0].Value = value;
- if (dataGridView_Gps.Rows[0].Cells[0].Value != null)
- {
- Double SnrMinref = Convert.ToDouble(dataGridView_Gps.Rows[0].Cells[3].Value);
- Double SnrValue = Convert.ToDouble(dataGridView_Gps.Rows[0].Cells[1].Value);
- Double SecValue = Convert.ToDouble(dataGridView_Gps.Rows[0].Cells[4].Value);
- Double SecMaxref = Convert.ToDouble(dataGridView_Gps.Rows[0].Cells[3].Value);
- if (SnrMinref > SnrValue || SecMaxref <= SecValue)
- {
- MessageBox.Show("APL 부적합 Device 입니다.\r\n" +"인식된 SNR 값" +SnrValue.ToString() +"\r\n"+"Cold Start Vale"+ SecValue .ToString());
- return;
- }
- gps_arrangecnt = 0;
- ColdCnt = 0;
- GPGGA_Cnt = 0;
- Gps_CurrentCount = 0;
- button_GpsTestSave_Click(null, null);
- dataGridView_Gps_CellClick(null, null);
- dataGridView_Gps.Rows[0].Cells[0].Value = Name = value;
- serialPort.Write("Reset" + "\r\n");
- // button_GpsTestSave_Click(null, null);
- }
- }
- }
- private void dataGridView_Catm1_CellClick(object sender, DataGridViewCellEventArgs e)
- {
- string value = "";
- //BL-VITE00-V
- if (InputBox("번호 입력", "생산 번호:", ref value) == DialogResult.OK)
- {
- // SN
- dataGridView_Catm1.Rows[0].Cells[0].Value = Name = value;
- button_Catm1TestSave();
- dataGridView_Catm1_CellClick(null, null);
- }
- }
- private void DataGridViewInsert_Func(string text)
- {
- dataGridView_Sensor.Rows[0].Cells[0].Value = text;
- }
- private void dataGridView_Sensor_CellClick(object sender, DataGridViewCellEventArgs e)
- {
- string[] value = new string[3];
- //BL-VITE00-V
- /*if (ButtonCheck == false)
- MessageBox.Show("버튼을 눌러 버튼을 확인 해주세요.");*/
- if (InputBox("번호 입력", "생산 번호:", ref value[0]) == DialogResult.OK)
- {
- // SN
-
- // dataGridView_Sensor.Rows[0].Cells[0].Value = Name = value[0];
- this.Invoke(new StringSend(DataGridViewInsert_Func), value[0]);
- // this.Invoke(new GridviewSend(DataGridViewInsert_Func),dataGridView_Sensor.Rows[0].Cells[0].Value, value);
- Sktnumgoback:
- if (InputBox("번호 입력", "SKT SN:", ref value[1]) == DialogResult.OK)
- {
- int BMAX = 0;
- int BMAY = 0;
- int BMAZ = 0;
- int BMAX_Max = 0;
- int BMAX_Min = 0;
- int BMAY_Max = 0;
- int BMAY_Min = 0;
- int BMAZ_Max = 0;
- int BMAZ_Min = 0;
- if (Convert.ToInt32(value[1]) <= 0)
- {
- value[1] = "";
- goto Sktnumgoback;
- }
- BMAX = Convert.ToInt32(dataGridView_Sensor.Rows[0].Cells[9].Value);
- BMAY = Convert.ToInt32(dataGridView_Sensor.Rows[0].Cells[10].Value);
- BMAZ = Convert.ToInt32(dataGridView_Sensor.Rows[0].Cells[11].Value);
- BMAX_Max = Convert.ToInt32(dataGridView_Sensor.Rows[0].Cells[17].Value);
- BMAX_Min = Convert.ToInt32(dataGridView_Sensor.Rows[0].Cells[18].Value);
- BMAY_Max = Convert.ToInt32(dataGridView_Sensor.Rows[0].Cells[19].Value);
- BMAY_Min = Convert.ToInt32(dataGridView_Sensor.Rows[0].Cells[20].Value);
- BMAZ_Max = Convert.ToInt32(dataGridView_Sensor.Rows[0].Cells[21].Value);
- BMAZ_Min = Convert.ToInt32(dataGridView_Sensor.Rows[0].Cells[22].Value);
- if (!(BMAX <= BMAX_Max && BMAX >= BMAX_Min))
- {
- MessageBox.Show("가속도 센서 X 축"+ BMAX .ToString()+ " 부적합 입니다. ");
- return;
- }
- if (!(BMAY <= BMAY_Max && BMAY >= BMAY_Min))
- {
- MessageBox.Show("가속도 센서 Y 축" + BMAY.ToString() + " 부적합 입니다. ");
- return;
- }
- if (!(BMAZ <= BMAZ_Min))
- {
- MessageBox.Show("가속도 센서 Z 축" + BMAZ.ToString() + " 부적합 입니다. ");
- return;
- }
- dataGridView_Sensor.Rows[0].Cells[1].Value = value[1];
- BleReinput:
- if (InputBox("번호 입력", "BLE RSSI Value", ref value[2]) == DialogResult.OK)
- {
- try
- {
- if (Convert.ToInt32(value[2]) > 0)
- {
- value[2] = "";
- goto BleReinput;
- }
- }
- catch
- {
- value[2] = "";
- goto BleReinput;
- }
- dataGridView_Sensor.Rows[0].Cells[12].Value = value[2];
- dataGridView_Sensor.Refresh();
- button_SensorTestSave();
- Thread.Sleep(3000);
- }
- }
- }
- }
- private void label_SnInsert_Click(object sender, EventArgs e)
- {
- panel_GpsTest.Visible = false;
- panel_SensorTest.Visible = false;
- panel_Catm1Test.Visible = false;
- panel_MergeMain.Visible = false;
- panel_SnCheckMain.Visible = false;
- panel_SnTest.Visible = true;
- }
- private void label_SnInsert_MouseMove(object sender, MouseEventArgs e)
- {
- panel_Sninsert.BackColor = Color.FromArgb(0, 159, 255);
- }
- private void label_Check_MouseLeave(object sender, EventArgs e)
- {
- if (panel_GpsTest.Visible == true)
- {
- panel_Catm1Mode.BackColor = Color.FromArgb(0, 159, 200);
- panel_SensorMode.BackColor = Color.FromArgb(0, 159, 200);
- panel_GpsMode.BackColor = Color.FromArgb(0, 159, 255);
- panel_Merge.BackColor = Color.FromArgb(0, 159, 200);
- panel_SnCheck.BackColor = Color.FromArgb(0, 159, 200);
- panel_Sninsert.BackColor = Color.FromArgb(0, 159, 200);
- }
- else if (panel_Catm1Test.Visible == true)
- {
- panel_Catm1Mode.BackColor = Color.FromArgb(0, 159, 255);
- panel_SensorMode.BackColor = Color.FromArgb(0, 159, 200);
- panel_GpsMode.BackColor = Color.FromArgb(0, 159, 200);
- panel_Merge.BackColor = Color.FromArgb(0, 159, 200);
- panel_SnCheck.BackColor = Color.FromArgb(0, 159, 200);
- panel_Sninsert.BackColor = Color.FromArgb(0, 159, 200);
- }
- else if (panel_SensorTest.Visible == true)
- {
- panel_Catm1Mode.BackColor = Color.FromArgb(0, 159, 200);
- panel_SensorMode.BackColor = Color.FromArgb(0, 159, 255);
- panel_GpsMode.BackColor = Color.FromArgb(0, 159, 200);
- panel_Merge.BackColor = Color.FromArgb(0, 159, 200);
- panel_SnCheck.BackColor = Color.FromArgb(0, 159, 200);
- panel_Sninsert.BackColor = Color.FromArgb(0, 159, 200);
- }
- else if (panel_MergeMain.Visible == true)
- {
- panel_Merge.BackColor = Color.FromArgb(0, 159, 255);
- panel_Catm1Mode.BackColor = Color.FromArgb(0, 159, 200);
- panel_SensorMode.BackColor = Color.FromArgb(0, 159, 200);
- panel_GpsMode.BackColor = Color.FromArgb(0, 159, 200);
- panel_SnCheck.BackColor = Color.FromArgb(0, 159, 200);
- panel_Sninsert.BackColor = Color.FromArgb(0, 159, 200);
- }
- else if (panel_SnCheckMain.Visible == true)
- {
- panel_Merge.BackColor = Color.FromArgb(0, 159, 200);
- panel_Catm1Mode.BackColor = Color.FromArgb(0, 159, 200);
- panel_SensorMode.BackColor = Color.FromArgb(0, 159, 200);
- panel_GpsMode.BackColor = Color.FromArgb(0, 159, 200);
- panel_SnCheck.BackColor = Color.FromArgb(0, 159, 255);
- panel_Sninsert.BackColor = Color.FromArgb(0, 159, 200);
- }
- else if (panel_SnTest.Visible == true)
- {
- panel_Merge.BackColor = Color.FromArgb(0, 159, 200);
- panel_Catm1Mode.BackColor = Color.FromArgb(0, 159, 200);
- panel_SensorMode.BackColor = Color.FromArgb(0, 159, 200);
- panel_GpsMode.BackColor = Color.FromArgb(0, 159, 200);
- panel_SnCheck.BackColor = Color.FromArgb(0, 159, 200);
- panel_Sninsert.BackColor = Color.FromArgb(0, 159, 255);
- }
- }
- private void label_Check_MouseMove(object sender, MouseEventArgs e)
- {
- }
- private void dataGridView_SnInsert_CellClick(object sender, DataGridViewCellEventArgs e)
- {
- string ProductNum = "";
- string SKTNUM = "";
- string IMEI = "";
- string USIM = "";
- string[] ImeiCheck = new string[15];
- ProductNumgoback:
- if (radioButton_Imei.Checked == true)
- {
- if (InputBox("번호 입력", "생산 번호:", ref ProductNum) == DialogResult.OK)
- {
- // SN
- if (ProductNum.Contains("BL-") == false)
- {
- ProductNum = "";
- goto ProductNumgoback;
- }
- dataGridView_SnInsert.Rows[0].Cells[0].Value = Name = ProductNum;
- if (InputBox("번호 입력", "SKT SN:", ref SKTNUM) == DialogResult.OK)
- {
- dataGridView_SnInsert.Rows[0].Cells[1].Value = SKTNUM;
- Imeigoback:
- if (InputBox("번호 입력", "IMEI:", ref IMEI) == DialogResult.OK)
- {
- if (IMEI.Contains(';') == false)
- {
- IMEI = "";
- goto Imeigoback;
- }
- ImeiCheck = IMEI.Split(';');
- dataGridView_SnInsert.Rows[0].Cells[2].Value = ImeiCheck[0];
- button_SninsertTestSave();
- dataGridView_SnInsert_CellClick(null, null);
- }
- }
- }
- }
- else
- {
- if (InputBox("번호 입력", "생산 번호:", ref ProductNum) == DialogResult.OK)
- {
- // SN
- if (ProductNum.Contains("BL-") == false)
- {
- ProductNum = "";
- goto ProductNumgoback;
- }
- dataGridView_SnInsert.Rows[0].Cells[0].Value = Name = ProductNum;
- if (InputBox("번호 입력", "USIM:", ref USIM) == DialogResult.OK)
- {
- USIM = USIM.Substring(6);
- dataGridView_SnInsert.Rows[0].Cells[1].Value = USIM;
- button_SninsertTestSave();
- dataGridView_SnInsert_CellClick(null, null);
- }
- }
- }
- }
- class AutoClosingMessageBox
- {
- [System.Runtime.InteropServices.DllImport("user32.dll", SetLastError = true)]
- static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
- [System.Runtime.InteropServices.DllImport("user32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto)]
- static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);
- System.Threading.Timer _timeoutTimer; //쓰레드 타이머
- string _caption;
- const int WM_CLOSE = 0x0010; //close 명령
- AutoClosingMessageBox(string text, string caption, int timeout)
- {
- _caption = caption;
- _timeoutTimer = new System.Threading.Timer(OnTimerElapsed,
- null, timeout, System.Threading.Timeout.Infinite);
- MessageBox.Show(text, caption);
- }
- //생성자 함수
- public static void Show(string text, string caption, int timeout)
- {
- new AutoClosingMessageBox(text, caption, timeout);
- }
- //시간이 다되면 close 메세지를 보냄
- void OnTimerElapsed(object state)
- {
- IntPtr mbWnd = FindWindow(null, _caption);
- if (mbWnd != IntPtr.Zero)
- SendMessage(mbWnd, WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
- _timeoutTimer.Dispose();
- }
- }
- private void button_GpsClear_Click(object sender, EventArgs e)
- {
- gps_arrangecnt = 0;
- ColdCnt = 0;
- GPGGA_Cnt = 0;
- Gps_CurrentCount = 0;
- dataGridView_Gps.Rows[0].Cells[0].Value = null;
- dataGridView_Gps.Rows[0].Cells[1].Value = null;
- dataGridView_Gps.Rows[0].Cells[4].Value = null;
- dataGridView_Gps.Refresh();
- }
- private void radioButton_Imei_CheckedChanged(object sender, EventArgs e)
- {
- dataGridView_SnInsert.ColumnCount = 3;
- dataGridView_SnInsert.Columns[1].HeaderText = "일련번호";
- dataGridView_SnInsert.Columns[2].HeaderText = "IMEI";
- }
- private void radioButton_Usim_CheckedChanged(object sender, EventArgs e)
- {
- dataGridView_SnInsert.Columns[1].HeaderText = "USIM";
- dataGridView_SnInsert.ColumnCount = 2;
- }
- private void button_ExcelOpen_Click(object sender, EventArgs e)
- {
- Process.Start(CurrentExcelFilePath);
- }
- private void button_SnRead_Click(object sender, EventArgs e)
- {
- serialPort.Write("APLSN Read:" + "\r\n");
- }
- private void button_Rewrite_Click(object sender, EventArgs e)
- {
- try
- {
- serialPort.Write("APLSN Rewrite:" + textBox_PrevNum.Text + "," + textBox_AfterNum.Text + "\r\n");
- label_SerialWrite.Text = "APLSN Rewrite:" + textBox_PrevNum.Text + "," + textBox_AfterNum.Text + "\r\n";
- }
- catch
- {
- MessageBox.Show("시리얼 포트가 닫혀 있습니다. Open 하세요.");
- }
- // serialPort.Write("APLSN Rewrite:0000002,0000001\r\n");
- }
- private void button_Write_Click(object sender, EventArgs e)
- {
- try
- {
- serialPort.Write("APLSN Write:" + textBox_Write +"\r\n");
- label_SerialWrite.Text = "APLSN Write:" + textBox_Write + "\r\n";
- }
- catch
- {
- MessageBox.Show("시리얼 포트가 닫혀 있습니다. Open 하세요.");
- }
- }
- private void timer1_Tick(object sender, EventArgs e)
- {
-
- }
- /// <summary>
- /// 버전 정보를 넣으면 빌드 시간을 반환.
- /// </summary>
- /// <param name="version"></param>
- /// <returns></returns>
- public System.DateTime Get_BuildDateTime(System.Version version = null)
- {
- // 주.부.빌드.수정
- // 주 버전 Major Number
- // 부 버전 Minor Number
- // 빌드 번호 Build Number
- // 수정 버전 Revision NUmber
- //매개 변수가 존재할 경우
- if (version == null)
- version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
- //세번째 값(Build Number)은 2000년 1월 1일부터
- //Build된 날짜까지의 총 일(Days) 수 이다.
- int day = version.Build;
- System.DateTime dtBuild = (new System.DateTime(2000, 1, 1)).AddDays(day);
- //네번째 값(Revision NUmber)은 자정으로부터 Build된
- //시간까지의 지나간 초(Second) 값 이다.
- int intSeconds = version.Revision;
- intSeconds = intSeconds * 2;
- dtBuild = dtBuild.AddSeconds(intSeconds);
- //시차 보정
- System.Globalization.DaylightTime daylingTime = System.TimeZone.CurrentTimeZone
- .GetDaylightChanges(dtBuild.Year);
- if (System.TimeZone.IsDaylightSavingTime(dtBuild, daylingTime))
- dtBuild = dtBuild.Add(daylingTime.Delta);
- return dtBuild;
- }
- }
- }
|