public bool WriteMarkDataInfo(MarkDataInfo dataInfo) { MarkDataInfo markDataTemp = new MarkDataInfo(dataInfo); if (ReadMarkDataType(ref markDataTemp)) { return(UpdateMarkDataInfo(dataInfo)); } else { return(InsertMarkDataInfo(dataInfo)); } }
private bool UpdateMarkDataInfo(MarkDataInfo dataInfo) { string sqlCmd = "update "; sqlCmd += _tableName; sqlCmd += " set MarkInfo='" + dataInfo.MarksToString() + "', Time=datetime('now','localtime') where "; sqlCmd += "Product='" + dataInfo.ProductName + "' "; sqlCmd += "and Batch='" + dataInfo.BatchName + "' "; sqlCmd += "and Board='" + dataInfo.BoardName + "' "; sqlCmd += "and Side='" + dataInfo.SideName + "' "; sqlCmd += "and Shot='" + dataInfo.ShotName + "' "; sqlCmd += "and Defect='" + dataInfo.DefectName + "';"; return(SqliteCMD(sqlCmd)); }
private bool InsertMarkDataInfo(MarkDataInfo dataInfo) { string sqlCmd = "insert into "; sqlCmd += _tableName; sqlCmd += " (Product, Batch, Board, Side, Shot, Defect, MarkInfo)"; sqlCmd += " values("; sqlCmd += "'" + dataInfo.ProductName + "', "; sqlCmd += "'" + dataInfo.BatchName + "', "; sqlCmd += "'" + dataInfo.BoardName + "', "; sqlCmd += "'" + dataInfo.SideName + "', "; sqlCmd += "'" + dataInfo.ShotName + "', "; sqlCmd += "'" + dataInfo.DefectName + "', "; sqlCmd += "'" + dataInfo.MarksToString() + "'"; sqlCmd += ");"; return(SqliteCMD(sqlCmd)); }
public bool ReadMarkDataType(ref MarkDataInfo dataInfo) { string sqlCmd = "select * from " + _tableName + " where "; sqlCmd += "Product='" + dataInfo.ProductName + "' "; sqlCmd += "and Batch='" + dataInfo.BatchName + "' "; sqlCmd += "and Board='" + dataInfo.BoardName + "' "; sqlCmd += "and Side='" + dataInfo.SideName + "' "; sqlCmd += "and Shot='" + dataInfo.ShotName + "' "; sqlCmd += "and Defect='" + dataInfo.DefectName + "';"; string dbPath = "Data Source = " + _dataBaseDir + "\\" + _dataBaseName + ".db"; SQLiteConnection connect = new SQLiteConnection(dbPath); connect.Open(); SQLiteCommand cmdCreateTable = new SQLiteCommand(sqlCmd, connect); SQLiteDataReader reader = cmdCreateTable.ExecuteReader(); bool isOK; if (reader.Read()) { string marksString = (string)reader["MarkInfo"]; dataInfo.SetMarksByString(marksString); isOK = true; // multi line is the same data, return false while (reader.Read()) { // if not read out the data, database may be locked. } } else { dataInfo.SetMarksByString(""); isOK = false; } connect.Close(); return(isOK); }