public productprintlist_t[] readrecordBy(string materialScancode) { string commandText; string[] recordArray; productprintlist_t[] st_productprint, result; recordArray = mySQLClass.databaseCommonReadingUnsplitted(c_productprintlistTableName, commandText); if (recordArray == null) { return(null); } st_productprint = new productprintlist_t[recordArray.GetLength(0)]; for (int i = 0; i < recordArray.GetLength(0); i++) { result = parseinput(recordArray[i]); if (result != null) { st_productprint[i] = result.Value; } } return(st_productprint); }
public static string format(productprintlist_t st) { string str = null; str += st.machineID + ";" + st.materialBarCode + ";" + st.materialScanTime + ";" + st.productBarCode + ";"; str += st.productScanTime + ";" + st.dispatchCode + ";" + st.batchNum + ";" + st.largeIndex + ";"; str += st.weight; return(str); }
//return 0 written to table successfully // -1 exception occurred public int writerecord(productprintlist_t st_productprint) { int num; int index; string[] itemName; string insertString; string connectionString; connectionString = "data source = " + gVariable.hostString + "; user id = root; PWD = ; Charset=utf8"; mySQLClass.getDatabaseInsertStringFromExcel(ref insertString, c_productprintlistFileName); try { index = 0; itemName = insertString.Split(',', ')'); MySqlConnection myConnection = new MySqlConnection("database = " + c_dbName + "; " + connectionString); myConnection.Open(); MySqlCommand myCommand = myConnection.CreateCommand(); myCommand.CommandText = "insert into `" + c_productprintlistTableName + "`" + insertString; myCommand.Parameters.AddWithValue("@id", 0); myCommand.Parameters.AddWithValue(itemName[index++], st_productprint.machineID); myCommand.Parameters.AddWithValue(itemName[index++], st_productprint.materialBarCode); myCommand.Parameters.AddWithValue(itemName[index++], st_productprint.materialScanTime); myCommand.Parameters.AddWithValue(itemName[index++], st_productprint.productBarCode); myCommand.Parameters.AddWithValue(itemName[index++], st_productprint.productScanTime); myCommand.Parameters.AddWithValue(itemName[index++], st_productprint.dispatchCode); myCommand.Parameters.AddWithValue(itemName[index++], st_productprint.salesOrderCode); myCommand.Parameters.AddWithValue(itemName[index++], st_productprint.batchNum); myCommand.Parameters.AddWithValue(itemName[index++], st_productprint.largeIndex); myCommand.Parameters.AddWithValue(itemName[index++], st_productprint.workerID); myCommand.ExecuteNonQuery(); myConnection.Close(); return(0); } catch (Exception ex) { Console.WriteLine(c_dbName + ":" + c_productprintlistTableName + ": write record failed! " + ex); } return(-1); }
public int updateProductScancode(productprintlist_t st_productprint) { string insertString; string[] insertStringSplitted; string connectionString; connectionString = "data source = " + gVariable.hostString + "; user id = root; PWD = ; Charset=utf8"; mySQLClass.getDatabaseInsertStringFromExcel(ref insertString, c_productprintlistFileName); insertStringSplitted = insertString.Split(',@'); try { MySqlConnection myConnection = new MySqlConnection("database = " + c_dbName + "; " + connectionString); myConnection.Open(); MySqlCommand myCommand = myConnection.CreateCommand(); myCommand.CommandText = "update "; myCommand.CommandText += "`" + c_productprintlistTableName + "` "; myCommand.CommandText += "set "; myCommand.CommandText += "`" + insertStringSplitted[PRODUCT_BARCODE_INDEX] + "`=" + st_productprint.productBarCode + ","; myCommand.CommandText += "`" + insertStringSplitted[PRODUCT_SCAN_TIME_INDEX] + "`=" + st_productprint.productScanTime; myCommand.CommandText += "where "; myCommand.CommandText += "`" + insertStringSplitted[MATERIAL_BARCODE_INDEX] + "`=" + st_productprint.materialBarCode; myCommand.ExecuteNonQuery(); myConnection.Close(); return(0); } catch (Exception ex) { Console.WriteLine(c_dbName + ":" + c_productprintlistTableName + ": update product barcode failed! " + ex); } return(-1); }