private void getHeaderData(String[] unitMeasure, String[] testDescription) { // GET PCB DATA for (int i = 1; i < PCBSIZE; i++) { /* * type_PCB pcbData = createDummyType_PCB(i); * printPCBHeader(pcbData); * int headerID = insertHeaderData(pcbData); * getDetailData(i, headerID); */ Tag udfTag = new Tag("LastPartHeader" + i); // 1-7 if (ControlLogix.ReadTag(udfTag) != Logix.ResultCode.E_SUCCESS) { addToLog("ERROR: Unable to download PLC Header Data: " + ControlLogix.ErrorString + "--" + udfTag.ErrorCode, true); return; } if (ResultCode.QUAL_GOOD == udfTag.QualityCode) { type_PCB pcbData = (type_PCB)udtEnc.ToType(udfTag, typeof(type_PCB)); printPCBHeader(pcbData); int passed = pcbData.Passed; int failed = pcbData.Failed; if (!(passed == 0 && failed == 0)) { int headerID = insertHeaderData(pcbData); //int headerID = i; getDetailData(i, headerID, unitMeasure, testDescription); } } } }
private void printPCBHeader(type_PCB pcbData) { if (showDebug) { addToLog("ID: " + pcbData.ID, showDebug); addToLog("passed: " + pcbData.Passed, showDebug); addToLog("failed: " + pcbData.Failed, showDebug); addToLog("year: " + pcbData.Year, showDebug); addToLog("month: " + pcbData.Month, showDebug); addToLog("day: " + pcbData.Day, showDebug); addToLog("hour: " + pcbData.Hour, showDebug); addToLog("min: " + pcbData.Minute, showDebug); addToLog("sec: " + pcbData.Second, showDebug); Char[] barCodeArray = pcbData.BarCodeString; String barcode = new String(barCodeArray); addToLog("barcode: " + barcode.Trim(), showDebug); addToLog("-----------------", showDebug); } }
private int insertHeaderData(type_PCB pcb) { int ID = 0; try { using (SqlConnection con = new SqlConnection(cnstr)) { string sql = "INSERT INTO plc_header (position, passed, failed, year, month, day, hour, minute, second, barcode) VALUES " + "(@position, @passed, @failed, @year, @month, @day, @hour, @minute, @second, @barcode)"; string sql2 = "SELECT @@Identity"; using (SqlCommand command = new SqlCommand(sql, con)) { command.Parameters.Add("position", SqlDbType.Int).Value = pcb.ID; command.Parameters.Add("passed", SqlDbType.Bit).Value = pcb.Passed; command.Parameters.Add("failed", SqlDbType.Bit).Value = pcb.Failed; command.Parameters.Add("year", SqlDbType.Int).Value = pcb.Year; command.Parameters.Add("month", SqlDbType.Int).Value = pcb.Month; command.Parameters.Add("day", SqlDbType.Int).Value = pcb.Day; command.Parameters.Add("hour", SqlDbType.Int).Value = pcb.Hour; command.Parameters.Add("minute", SqlDbType.Int).Value = pcb.Minute; command.Parameters.Add("second", SqlDbType.Int).Value = pcb.Second; command.Parameters.Add("barcode", SqlDbType.VarChar, 50).Value = new String(pcb.BarCodeString); //command.Parameters.Add("date_saved", SqlDbType.DateTime).Value = DateTime.Now; con.Open(); command.ExecuteNonQuery(); command.CommandText = sql2; ID = System.Convert.ToInt32(command.ExecuteScalar()); con.Close(); } } } catch (System.Data.SqlClient.SqlException e) { // SEND EMAIL addToLog("PLC DB ERROR (insertHeaderData): " + e.StackTrace, true); } return(ID); }
private type_PCB createDummyType_PCB(int id) { string strBarcode = "13000000" + id; char[] barcode = strBarcode.ToCharArray(); type_PCB pcb = new type_PCB(); pcb.ID = (short)id; pcb.Passed = 1; pcb.Failed = 0; pcb.Year = 2013; pcb.Month = 11; pcb.Day = 6; pcb.Hour = 10; pcb.Minute = 56; pcb.Second = 0; pcb.BarCodeInt = 8; pcb.BarCodeString = barcode; return(pcb); }