public static IncomeCategory Find(int id) { MySqlConnection conn = DB.Connection(); conn.Open(); var cmd = conn.CreateCommand() as MySqlCommand; cmd.CommandText = @"SELECT * FROM incomeCategories WHERE id = (@searchId);"; MySqlParameter searchId = new MySqlParameter(); searchId.ParameterName = "@searchId"; searchId.Value = id; cmd.Parameters.Add(searchId); var rdr = cmd.ExecuteReader() as MySqlDataReader; int incomeCategoryId = 0; string incomeCategoryName = ""; double incomeCategoryTotal = 0; int incomeAccountId = 0; while (rdr.Read()) { incomeCategoryId = rdr.GetInt32(0); incomeCategoryName = rdr.GetString(1); incomeCategoryTotal = rdr.GetDouble(2); incomeAccountId = rdr.GetInt32(3); } IncomeCategory newIncomeCategory = new IncomeCategory(incomeAccountId, incomeCategoryName, incomeCategoryTotal, incomeCategoryId); conn.Close(); if (conn != null) { conn.Dispose(); } return(newIncomeCategory); }
public static List <IncomeCategory> GetAll() { List <IncomeCategory> allCategories = new List <IncomeCategory> { }; MySqlConnection conn = DB.Connection(); conn.Open(); var cmd = conn.CreateCommand() as MySqlCommand; cmd.CommandText = @"SELECT * FROM incomeCategories;"; var rdr = cmd.ExecuteReader() as MySqlDataReader; while (rdr.Read()) { int incomeCategoryId = rdr.GetInt32(0); string incomeCategoryName = rdr.GetString(1); double incomeCategoryTotal = rdr.GetDouble(2); int incomeAccountId = rdr.GetInt32(3); IncomeCategory newIncomeCategory = new IncomeCategory(incomeAccountId, incomeCategoryName, incomeCategoryTotal, incomeCategoryId); allCategories.Add(newIncomeCategory); } conn.Close(); if (conn != null) { conn.Dispose(); } return(allCategories); }
public List <IncomeCategory> GetIncomeCategories() { List <IncomeCategory> allIncomeCategory = new List <IncomeCategory> { }; MySqlConnection conn = DB.Connection(); conn.Open(); var cmd = conn.CreateCommand() as MySqlCommand; cmd.CommandText = "SELECT * FROM incomeCategories WHERE account_id = @account_id;"; MySqlParameter accountId = new MySqlParameter(); accountId.ParameterName = "@account_id"; accountId.Value = this._id; cmd.Parameters.Add(accountId); var rdr = cmd.ExecuteReader() as MySqlDataReader; while (rdr.Read()) { int categpryId = rdr.GetInt32(0); string categoryName = rdr.GetString(1); double categoyTotal = rdr.GetDouble(2); int categoryAccountId = rdr.GetInt32(3); IncomeCategory newIncomeCategory = new IncomeCategory(categoryAccountId, categoryName, categoyTotal, categpryId); allIncomeCategory.Add(newIncomeCategory); } conn.Close(); if (conn != null) { conn.Dispose(); } return(allIncomeCategory); }
// ==========================TESTS ========================================= public override bool Equals(System.Object otherIncomeCategory) { if (!(otherIncomeCategory is IncomeCategory)) { return(false); } else { IncomeCategory newIncomeCategory = (IncomeCategory)otherIncomeCategory; bool idEquality = this.GetId().Equals(newIncomeCategory.GetId()); bool nameEquality = this.GetName().Equals(newIncomeCategory.GetName()); bool totalEquality = this.GetTotal().Equals(newIncomeCategory.GetTotal()); return(idEquality && nameEquality && totalEquality); } }