public static void itemPurchased(string vendingMachineID, int ProductID, double cost, int quantity, DateTime date) { try { connection.Open(); //string time = date.ToShortDateString() + " " + date.ToLongTimeString(); string time = date.ToString("yyyy-MM-dd HH:mm:ss"); string q1 = string.Format("INSERT INTO `vendingmachine`.`tblpurchase` (`ID`, `VendingMachineID`, `ProductID`, `Cost`, `Quantity`, `PurchaseDateTime`) VALUES(NULL, '{0}', '{1}', '{2}', '{3}', '{4}');", vendingMachineID, ProductID, cost, quantity, time); if (connection.State.ToString() == "Open") { using (MySqlCommand cmd = new MySqlCommand(q1, connection)) { cmd.ExecuteNonQuery(); connection.Close(); MySqlConnection.ClearAllPools(); } } } catch (Exception) { connection.Close(); MySqlConnection.ClearAllPools(); throw; } }
public static int getProductIDbyName(string productName) { try { if (connection.State.ToString() != "Open") { connection.Open(); } string query = "SELECT * FROM `tblproduct` WHERE `ProductName` = '" + productName + "'"; if (connection.State.ToString() == "Open") { int result = 0; using (MySqlCommand cmd = new MySqlCommand(query, connection)) { using (var dataReader = cmd.ExecuteReader()) { while (dataReader.Read()) { result = Convert.ToInt16(dataReader["ID"].ToString()); } dataReader.Close(); } } connection.Close(); MySqlConnection.ClearAllPools(); return(result); } } catch (Exception) { throw; } return(0); }
public InsertController() { MySqlConnection.ClearAllPools(); }
public static void killConnections() { MySqlConnection.ClearAllPools(); }
public SelectController() { MySqlConnection.ClearAllPools(); }