public void TestMethodInsertIntoUserData() { Boolean expectedInsert = true; Boolean expectedDelete = true; string expectedUserName = "******"; string expectedPassword = "******"; string expectedFullName = "John Sampleson"; string expectedType = "SA"; List <object> bookstore = new List <object>( new object[] { expectedUserName, expectedPassword, expectedType, 0, expectedFullName } ); Boolean actualInsert = dbQ.INSERT_INTO_TABLE("UserData", bookstore); //Insert method for database Assert.AreEqual(expectedInsert, actualInsert); ds = dbQ.SELECT_FROM_TABLE("SELECT * FROM UserData WHERE UserName = '******'"); string actualUserName = ds.Tables[0].Rows[0]["UserName"].ToString(); string actualPassword = ds.Tables[0].Rows[0]["Password"].ToString(); string actualFullName = ds.Tables[0].Rows[0]["FullName"].ToString(); string actualType = ds.Tables[0].Rows[0]["Type"].ToString(); Assert.AreEqual(expectedUserName, actualUserName); Assert.AreEqual(expectedPassword, actualPassword); Assert.AreEqual(expectedFullName, actualFullName); Assert.AreEqual(expectedType, actualType); Boolean actualDelete = dbQ.DELETE_FROM_TABLE("DELETE FROM UserData WHERE UserName = '******'"); Assert.AreEqual(expectedDelete, actualDelete); }
public void TestMethodDeleteFromSupplier() { var c = new SqlConnection(Properties.Settings.Default.dbConnectionString); Boolean expectedInsert = true; Boolean expectedDelete = true; string expectedName = "Google"; int expectedSupplierID = dbG.GetID("Supplier", c); List <object> bookstore = new List <object>( new object[] { expectedName } ); Boolean actualInsert = dbQ.INSERT_INTO_TABLE("Supplier", bookstore); Assert.AreEqual(expectedInsert, actualInsert); ds = dbQ.SELECT_FROM_TABLE("SELECT * FROM Supplier WHERE Name = '" + expectedName + "'"); int actualSupplierID = Int32.Parse(ds.Tables[0].Rows[0]["SupplierId"].ToString()); string actualName = ds.Tables[0].Rows[0]["Name"].ToString(); Assert.AreEqual(expectedSupplierID, actualSupplierID); Assert.AreEqual(expectedName, actualName); //Delete from Database Boolean actualDelete = dbQ.DELETE_FROM_TABLE("DELETE FROM Supplier WHERE Name = '" + expectedName + "'"); Assert.AreEqual(expectedDelete, actualDelete); Boolean expectedFinalDeleteReturn = true; Boolean finalDeleteReturn = false; ds = dbQ.SELECT_FROM_TABLE("SELECT * FROM Supplier WHERE Name = '" + expectedName + "'"); if (ds.Tables[0].Rows.Count == 0) { finalDeleteReturn = true; } Assert.AreEqual(expectedFinalDeleteReturn, finalDeleteReturn); c.Close(); }
public bool EnterQuestion(string userID, string question) { //string newType = "CU"; DBQueries db = new DBQueries(); List <object> bookstore = new List <object>( new object[] { userID, question } ); return(db.INSERT_INTO_TABLE("UserData", bookstore)); }
public int PlaceOrderFinal(int userID) { DBQueries dbQ = new DBQueries(); bool res = false; var conn = new SqlConnection(Properties.Settings.Default.dbConnectionString); int orderId = 0; try { SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandText = "INSERT INTO Orders (UserID, Status) VALUES " + " (@UserID, @Status)"; cmd.Parameters.AddWithValue("@UserID", userID); cmd.Parameters.AddWithValue("@Status", "P"); conn.Open(); cmd.ExecuteScalar(); } catch (Exception ex) { Debug.WriteLine(ex.ToString()); } finally { if (conn.State == ConnectionState.Open) { conn.Close(); } } DBGetID dbG = new DBGetID(); orderId = (dbG.GetID("Orders", conn)) - 1; foreach (var item in orderItemList) { List <object> bookstore1 = new List <object>( new object[] { orderId, item.BookID, item.Quantity } ); dbQ.INSERT_INTO_TABLE("OrderItem", bookstore1); } return(orderId); }
public bool Register(string username, string password1, string password2, string fullName) { if (!UserRegister.VerifyRegistration(username, password1, password2, fullName)) { ErrorMessage = "Please fill in all fields."; return(false); } if (DALUserInfo.HasInvalidPassword(password1)) { ErrorMessage = "Password requires at least six alphanumeric characters."; return(false); } string newType = "CU"; DBQueries db = new DBQueries(); List <object> bookstore = new List <object>( new object[] { username, password1, newType, 0, fullName } ); return(db.INSERT_INTO_TABLE("UserData", bookstore)); }