// public List<Client> GetClients() // { // MySqlConnection conn = DB.Connection(); // conn.Open(); // // MySqlCommand cmd = new MySqlCommand(@"SELECT client_id FROM clients_stylists WHERE stylist_id = @StylistId;", conn); // // cmd.Parameters.Add (new MySqlParameter ("@StylistId", _styId)); // // var rdr = cmd.ExecuteReader() as MySqlDataReader; // // List<int> clientIds = new List<int> {}; // while(rdr.Read()) // { // int clientId = rdr.GetInt32(0); // clientIds.Add(clientId); // } // rdr.Dispose(); // // List<Client> clients = new List<Client> {}; // foreach (int clientId in clientIds) // { // MySqlCommand clientQuery = new MySqlCommand(@"SELECT * FROM clients WHERE id = @ClientId;", conn); // // MySqlParameter clientIdParameter = new MySqlParameter(); // clientIdParameter.ParameterName = "@ClientId"; // clientIdParameter.Value = clientId; // clientQuery.Parameters.Add(clientIdParameter); // // var clientQueryRdr = clientQuery.ExecuteReader() as MySqlDataReader; // while(clientQueryRdr.Read()) // { // int thisClientId = clientQueryRdr.GetInt32(0); // string clientDescription = clientQueryRdr.GetString(1); // Client foundClient = new Client(clientDescription, thisClientId); // clients.Add(foundClient); // } // clientQueryRdr.Dispose(); // } // conn.Close(); // if (conn != null) // { // conn.Dispose(); // } // return clients; // } public List <Speciality> GetSpecialties() { MySqlConnection conn = DB.Connection(); conn.Open(); MySqlCommand cmd = conn.CreateCommand() as MySqlCommand; cmd.CommandText = @"SELECT specialties.* FROM stylists JOIN specialties_stylists ON (stylists.id = specialties_stylists.stylist_id) JOIN specialties ON (specialties_stylists.specialty_id = specialties.id) WHERE stylists.id = @StylistId;"; MySqlParameter SpecialityIdParameter = new MySqlParameter(); SpecialityIdParameter.ParameterName = "@StylistId"; SpecialityIdParameter.Value = _styId; cmd.Parameters.Add(SpecialityIdParameter); MySqlDataReader rdr = cmd.ExecuteReader() as MySqlDataReader; List <Speciality> specialties = new List <Speciality> { }; while (rdr.Read()) { int SpecialityId = rdr.GetInt32(0); string SpecialityTitle = rdr.GetString(1); Speciality newSpeciality = new Speciality(SpecialityTitle); specialties.Add(newSpeciality); } conn.Close(); if (conn != null) { conn.Dispose(); } return(specialties); }
public static Speciality Find(int id) { MySqlConnection conn = DB.Connection(); conn.Open(); var cmd = conn.CreateCommand() as MySqlCommand; cmd.CommandText = @"SELECT id, name FROM specialities WHERE id = (@searchId);"; MySqlParameter searchId = new MySqlParameter(); searchId.ParameterName = "@searchId"; searchId.Value = id; cmd.Parameters.Add(searchId); var rdr = cmd.ExecuteReader() as MySqlDataReader; int SpecialityId = 0; string SpecialityName = ""; while (rdr.Read()) { SpecialityId = rdr.GetInt32(0); Console.WriteLine(SpecialityId); SpecialityName = rdr.GetString(1); Console.WriteLine(SpecialityName); } Speciality newSpeciality = new Speciality(SpecialityName, SpecialityId); conn.Close(); if (conn != null) { conn.Dispose(); } return(newSpeciality); }
public void Dispose() { Stylist.ClearAll(); Client.ClearAll(); Speciality.ClearAll(); }