Ejemplo n.º 1
0
        public static Stylist Find(int id)
        {
            MySqlConnection conn = DB.Connection();

            conn.Open();

            var cmd = conn.CreateCommand() as MySqlCommand;

            cmd.CommandText = @"SELECT * from `stylists` WHERE id = @thisId;";

            MySqlParameter thisId = new MySqlParameter();

            thisId.ParameterName = "@thisId";
            thisId.Value         = id;
            cmd.Parameters.Add(thisId);

            var    rdr              = cmd.ExecuteReader() as MySqlDataReader;
            int    stylistId        = 0;
            string stylistFirstName = "";
            string stylistLastName  = "";

            while (rdr.Read())
            {
                stylistId        = rdr.GetInt32(2);
                stylistFirstName = rdr.GetString(0);
                stylistLastName  = rdr.GetString(1);
            }

            Stylist foundStylist = new Stylist(stylistFirstName, stylistLastName, stylistId);

            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
            return(foundStylist);
        }
Ejemplo n.º 2
0
        public List <Client> GetClients()
        {
            List <Client> allStylistClients = new List <Client> {
            };
            MySqlConnection conn            = DB.Connection();

            conn.Open();
            var cmd = conn.CreateCommand() as MySqlCommand;

            cmd.CommandText = @"SELECT * FROM `clients` WHERE `stylist_id` = @stylist_id;";

            MySqlParameter stylistId = new MySqlParameter();

            stylistId.ParameterName = "@stylist_id";
            stylistId.Value         = this._id;
            cmd.Parameters.Add(stylistId);

            var rdr = cmd.ExecuteReader() as MySqlDataReader;

            while (rdr.Read())
            {
                int    clientId        = rdr.GetInt32(1);
                string clientName      = rdr.GetString(0);
                string rawAppt         = rdr.GetString(2);
                int    clientStylistId = rdr.GetInt32(3);
                Client newClient       = new Client(clientName, rawAppt, clientId, clientStylistId);
                // newClient.SetAppt();
                allStylistClients.Add(newClient);
            }
            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }

            return(allStylistClients);
        }
Ejemplo n.º 3
0
        public List <Stylist> GetStylist()
        {
            MySqlConnection conn = DB.Connection();

            conn.Open();
            var cmd = conn.CreateCommand() as MySqlCommand;

            cmd.CommandText = @"SELECT stylists.* FROM specialties
      JOIN specialties_stylists ON (specialties.id = specialties_stylists.specialty_id)
      JOIN stylists ON (specialties_stylists.stylist_id = stylists.id)
      WHERE specialties.id = @SpecialtyId;";

            MySqlParameter specialty_idIdParameter = new MySqlParameter();

            specialty_idIdParameter.ParameterName = "@SpecialtyId";
            specialty_idIdParameter.Value         = _id;
            cmd.Parameters.Add(specialty_idIdParameter);

            MySqlDataReader rdr      = cmd.ExecuteReader() as MySqlDataReader;
            List <Stylist>  stylists = new List <Stylist> {
            };

            while (rdr.Read())
            {
                int     stylistid   = rdr.GetInt32(0);
                string  stylistName = rdr.GetString(1);
                Stylist newStylist  = new Stylist(stylistName, stylistid);
                stylists.Add(newStylist);
            }

            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
            return(stylists);
        }
Ejemplo n.º 4
0
        public static Client Find(int id)
        {
            MySqlConnection conn = DB.Connection();

            conn.Open();
            var cmd = conn.CreateCommand() as MySqlCommand;

            cmd.CommandText = @"SELECT * FROM clients WHERE id = (@searchId);";
            MySqlParameter searchId = new MySqlParameter();

            searchId.ParameterName = "@searchId";
            searchId.Value         = id;
            cmd.Parameters.Add(searchId);
            var    rdr             = cmd.ExecuteReader() as MySqlDataReader;
            int    clientId        = 0;
            string clientName      = "";
            string clientPhone     = "";
            string clientEmail     = "";
            int    clientStylistId = 0;

            while (rdr.Read())
            {
                clientId        = rdr.GetInt32(0);
                clientName      = rdr.GetString(1);
                clientPhone     = rdr.GetString(2);
                clientEmail     = rdr.GetString(3);
                clientStylistId = rdr.GetInt32(4);
            }
            Client newClient = new Client(clientName, clientPhone, clientEmail, clientStylistId, clientId);

            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
            return(newClient);
        }
Ejemplo n.º 5
0
        public void Edit(string newStylistName, string newdescription)
        {
            MySqlConnection conn = DB.Connection();

            conn.Open();
            var cmd = conn.CreateCommand() as MySqlCommand;

            cmd.CommandText = @"UPDATE stylists SET name = @newStylistName, description = @newdescription WHERE id = @searchId;";

            MySqlParameter searchId = new MySqlParameter();

            searchId.ParameterName = "@searchId";
            searchId.Value         = _id;
            cmd.Parameters.Add(searchId);

            MySqlParameter stylistName = new MySqlParameter();

            stylistName.ParameterName = "@newStylistName";
            stylistName.Value         = newStylistName;
            cmd.Parameters.Add(stylistName);

            MySqlParameter description = new MySqlParameter();

            description.ParameterName = "@newdescription";
            description.Value         = newdescription;
            cmd.Parameters.Add(description);


            cmd.ExecuteNonQuery();
            _name        = newStylistName;
            _description = newdescription;
            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
        }
Ejemplo n.º 6
0
        public void Edit(string newName, int newStylistID)
        {
            MySqlConnection conn = DB.Connection();

            conn.Open();
            var cmd = conn.CreateCommand() as MySqlCommand;

            cmd.CommandText = @"UPDATE clients SET clientName = @newClientName, stylist_id = @newStylistId WHERE id = @searchId;";

            MySqlParameter searchId = new MySqlParameter();

            searchId.ParameterName = "@searchId";
            searchId.Value         = id;
            cmd.Parameters.Add(searchId);

            MySqlParameter clientsName = new MySqlParameter();

            clientsName.ParameterName = "@newClientName";
            clientsName.Value         = newName;
            cmd.Parameters.Add(clientsName);

            MySqlParameter clientsStylistId = new MySqlParameter();

            clientsStylistId.ParameterName = "@newStylistId";
            clientsStylistId.Value         = newStylistID;
            cmd.Parameters.Add(clientsStylistId);

            cmd.ExecuteNonQuery();
            clientName = newName;
            stylist_id = newStylistID;

            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
        }
Ejemplo n.º 7
0
        public static Specialty Find(int id)
        {
            MySqlConnection conn = DB.Connection();

            conn.Open();

            var cmd = conn.CreateCommand() as MySqlCommand;

            cmd.CommandText = @"SELECT * FROM `specialties` WHERE id = @thisId;";

            MySqlParameter thisId = new MySqlParameter();

            thisId.ParameterName = "@thisId";
            thisId.Value         = id;
            cmd.Parameters.Add(thisId);

            var rdr = cmd.ExecuteReader() as MySqlDataReader;

            int    itemId        = 0;
            string itemSpecialty = "";

            while (rdr.Read())
            {
                itemId        = rdr.GetInt32(0);
                itemSpecialty = rdr.GetString(1);
            }

            Specialty foundSpecialty = new Specialty(itemSpecialty, itemId);

            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }

            return(foundSpecialty);
        }
Ejemplo n.º 8
0
        public static Stylist Find(int id)
        {
            MySqlConnection conn = DB.Connection();

            conn.Open();
            var cmd = conn.CreateCommand() as MySqlCommand;

            cmd.CommandText = @"SELECT * FROM stylists WHERE ID = @thisID;";
            MySqlParameter thisID = new MySqlParameter();

            thisID.ParameterName = "@thisID";
            thisID.Value         = id;
            cmd.Parameters.Add(thisID);
            var    rdr         = cmd.ExecuteReader() as MySqlDataReader;
            int    stylistID   = 0;
            string firstName   = "";
            string lastName    = "";
            string phoneNumber = "";
            string email       = "";

            while (rdr.Read())
            {
                stylistID   = rdr.GetInt32(0);
                firstName   = rdr.GetString(1);
                lastName    = rdr.GetString(2);
                phoneNumber = rdr.GetString(3);
                email       = rdr.GetString(4);
            }
            Stylist foundStylist = new Stylist(firstName, lastName, phoneNumber, email, stylistID);

            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
            return(foundStylist);
        }
Ejemplo n.º 9
0
        public static Client Find(int id)
        {
            MySqlConnection conn = DB.Connection();

            conn.Open();
            MySqlCommand cmd = conn.CreateCommand() as MySqlCommand;

            cmd.CommandText = @"SELECT * FROM clients WHERE id = @thisId;";

            MySqlParameter searchId = new MySqlParameter();

            searchId.ParameterName = "@thisId";
            searchId.Value         = id;
            cmd.Parameters.Add(searchId);

            var rdr = cmd.ExecuteReader() as MySqlDataReader;

            int    Id        = 0;
            string Name      = String.Empty;
            int    StylistId = 0;

            while (rdr.Read())
            {
                Id        = rdr.GetInt32(0);
                Name      = rdr.GetString(1);
                StylistId = rdr.GetInt32(2);
            }

            Client foundClient = new Client(Id, Name, StylistId);

            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
            return(foundClient);
        }
Ejemplo n.º 10
0
        public Stylist FindStylist()
        {
            MySqlConnection conn = DB.Connection();

            conn.Open();
            MySqlCommand cmd = conn.CreateCommand() as MySqlCommand;

            cmd.CommandText = @"SELECT * FROM stylists WHERE id = @thisStylistId;";

            MySqlParameter searchId = new MySqlParameter();

            searchId.ParameterName = "@thisStylistId";
            searchId.Value         = this._stylistId;
            cmd.Parameters.Add(searchId);

            var rdr = cmd.ExecuteReader() as MySqlDataReader;

            int    Id      = 0;
            string Name    = String.Empty;
            string Details = String.Empty;

            while (rdr.Read())
            {
                Id      = rdr.GetInt32(0);
                Name    = rdr.GetString(1);
                Details = rdr.GetString(2);
            }

            Stylist foundStylist = new Stylist(Id, Name, Details);

            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
            return(foundStylist);
        }
Ejemplo n.º 11
0
        public static List <Stylist> GetAll()
        {
            List <Stylist> allStylists = new List <Stylist> {
            };

            MySqlConnection conn = DB.Connection();

            conn.Open();
            MySqlCommand cmd = conn.CreateCommand() as MySqlCommand;

            cmd.CommandText = @"SELECT * FROM stylists ORDER BY last_name;";
            MySqlDataReader rdr = cmd.ExecuteReader() as MySqlDataReader;

            while (rdr.Read())
            {
                int      stylistId          = rdr.GetInt32(0);
                string   stylistFirstName   = rdr.GetString(1);
                string   stylistLastName    = rdr.GetString(2);
                string   stylistPhoneNumber = rdr.GetString(3);
                string   stylistEmail       = rdr.GetString(4);
                string   stylistStreet      = rdr.GetString(5);
                string   stylistCity        = rdr.GetString(6);
                string   stylistState       = rdr.GetString(7);
                string   stylistZip         = rdr.GetString(8);
                DateTime stylistStartDate   = rdr.GetDateTime(9);
                Stylist  newStylist         = new Stylist(stylistFirstName, stylistLastName, stylistPhoneNumber, stylistEmail, stylistStreet, stylistCity, stylistState, stylistZip, stylistStartDate, stylistId);
                allStylists.Add(newStylist);
            }

            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }

            return(allStylists);
        }
Ejemplo n.º 12
0
        public void Save()
        {
            MySqlConnection conn = DB.Connection();

            conn.Open();
            var cmd = conn.CreateCommand() as MySqlCommand;

            cmd.CommandText = @"INSERT INTO stylists (firstName, lastName, phoneNumber, email) VALUES (@firstName, @lastName, @phoneNumber, @email);";
            MySqlParameter firstName = new MySqlParameter();

            firstName.ParameterName = "@firstName";
            firstName.Value         = this.MyFirstName;
            cmd.Parameters.Add(firstName);
            MySqlParameter lastName = new MySqlParameter();

            lastName.ParameterName = "@lastName";
            lastName.Value         = this.MyLastName;
            cmd.Parameters.Add(lastName);
            MySqlParameter phoneNumber = new MySqlParameter();

            phoneNumber.ParameterName = "@phoneNumber";
            phoneNumber.Value         = this.MyPhoneNumber;
            cmd.Parameters.Add(phoneNumber);
            MySqlParameter email = new MySqlParameter();

            email.ParameterName = "@email";
            email.Value         = this.MyEmail;
            cmd.Parameters.Add(email);
            cmd.ExecuteNonQuery();
            MyID = (int)cmd.LastInsertedId;

            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
        }
Ejemplo n.º 13
0
        public void Edit(string newName, string newPhone)
        {
            MySqlConnection conn = DB.Connection();

            conn.Open();
            var cmd = conn.CreateCommand() as MySqlCommand;

            cmd.CommandText = @"UPDATE clients SET name, phone = @newName, @newPhone WHERE id = @searchId;";
            MySqlParameter searchId = new MySqlParameter();

            searchId.ParameterName = "@searchId";
            searchId.Value         = _id;
            cmd.Parameters.Add(searchId);

            MySqlParameter name = new MySqlParameter();

            name.ParameterName = "@newName";
            name.Value         = newName;
            cmd.Parameters.Add(name);

            MySqlParameter phone = new MySqlParameter();

            phone.ParameterName = "@newPhone";
            phone.Value         = newPhone;
            cmd.Parameters.Add(phone);

            cmd.ExecuteNonQuery();
            _name  = newName;
            _phone = newPhone;

            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
        }
Ejemplo n.º 14
0
        public void Save()
        {
            MySqlConnection conn = DB.Connection();

            conn.Open();
            var cmd = conn.CreateCommand() as MySqlCommand;

            cmd.CommandText = @"INSERT INTO clients (name, phone, stylist_id) VALUES (@clientName, @clientPhone, @stylist_id);";
            cmd.Parameters.AddWithValue("@clientName", _name);
            cmd.Parameters.AddWithValue("@clientPhone", _phone);
            cmd.Parameters.AddWithValue("@stylist_id", _stylist_id);
            // MySqlParameter name = new MySqlParameter();
            // name.ParameterName = "@clientName";
            // name.Value = this._name;
            // cmd.Parameters.Add(name);
            cmd.ExecuteNonQuery();
            _id = (int)cmd.LastInsertedId;

            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
        }
Ejemplo n.º 15
0
        public List <Client> GetClients()
        {
            List <Client> output = new List <Client> {
            };
            MySqlConnection conn = DB.Connection();

            conn.Open();

            var cmd = conn.CreateCommand() as MySqlCommand;

            cmd.CommandText = @"SELECT * FROM clients WHERE stylist_id = @StylistId;";

            MySqlParameter stylistIdParameter = new MySqlParameter();

            stylistIdParameter.ParameterName = "@StylistId";
            stylistIdParameter.Value         = this.Id;
            cmd.Parameters.Add(stylistIdParameter);

            var rdr = cmd.ExecuteReader() as MySqlDataReader;

            while (rdr.Read())
            {
                int    id        = rdr.GetInt32(0);
                string name      = rdr.GetString(1);
                int    stylistId = rdr.GetInt32(2);
                Client newClient = new Client(name, stylistId, id);
                output.Add(newClient);
            }

            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
            return(output);
        }
Ejemplo n.º 16
0
        public List <Stylist> GetStylists()
        {
            List <Stylist> allSpecialityStylists = new List <Stylist> {
            };
            MySqlConnection conn = DB.Connection();

            conn.Open();
            MySqlCommand cmd = conn.CreateCommand();

            cmd.CommandText = @"SELECT stylists. *
										FROM specialities
										JOIN specialities_stylists ON (specialities.id = specialities_stylists.speciality_id)
										JOIN stylists ON (stylists.id = specialities_stylists.stylist_id)
										WHERE specialities.id = @SpecialityId;"                                        ;
            MySqlParameter specialityIdParameter = new MySqlParameter("@SpecialityId", this._id);

            cmd.Parameters.Add(specialityIdParameter);
            MySqlDataReader rdr = cmd.ExecuteReader();

            while (rdr.Read())
            {
                int    stylistId   = rdr.GetInt32(0);
                string stylistName = rdr.GetString(1);


                Stylist newStylist = new Stylist(stylistName, stylistId);
                allSpecialityStylists.Add(newStylist);
            }
            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }

            return(allSpecialityStylists);
        }
Ejemplo n.º 17
0
        public void Save()//
        {
            MySqlConnection conn = DB.Connection();

            conn.Open();
            var cmd = conn.CreateCommand() as MySqlCommand;

            cmd.CommandText = @"INSERT INTO stylists (name) VALUES (@newName);";
            MySqlParameter name = new MySqlParameter();

            name.ParameterName = "@newName";
            name.Value         = this.GetStylist();
            cmd.Parameters.Add(name);
            // cmd.CommandText = @"INSERT INTO stylists(stylist, client_name) VALUES (@stylist, @client_name);";
            // cmd.Parameter.Add(new MySqlParameter("@stylist", this.StylistName));
            // cmd.Parameter.Add(new MySqlParameter("@client_name", this.ClientName));
            cmd.ExecuteNonQuery();
            _id = (int)cmd.LastInsertedId;
            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
        }
Ejemplo n.º 18
0
        public static Client Find(int id)
        {
            MySqlConnection conn = DB.Connection();

            conn.Open();
            var cmd = conn.CreateCommand() as MySqlCommand;

            cmd.CommandText = @"SELECT * FROM `client` WHERE id = @thisId;";
            MySqlParameter thisId = new MySqlParameter();

            thisId.ParameterName = "@thisId";
            thisId.Value         = id;
            cmd.Parameters.Add(thisId);
            var      rdr                   = cmd.ExecuteReader() as MySqlDataReader;
            string   clientName            = "";
            int      clientStylistId       = 0;
            int      clientId              = 0;
            DateTime clientNextAppointment = new DateTime(1000, 01, 01);

            while (rdr.Read())
            {
                clientId              = rdr.GetInt32(0);
                clientName            = rdr.GetString(1);
                clientNextAppointment = rdr.GetDateTime(2);
                clientStylistId       = rdr.GetInt32(3);
            }

            Client foundClient = new Client(clientName, clientStylistId, clientNextAppointment, clientId);

            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
            return(foundClient);
        }
Ejemplo n.º 19
0
        public List <Specialty> GetSpecialties()
        {
            MySqlConnection conn = DB.Connection();

            conn.Open();
            MySqlCommand cmd = conn.CreateCommand() as MySqlCommand;

            cmd.CommandText = @"SELECT specialties.* FROM stylists
      JOIN stylists_specialties ON (stylists.id = stylists_specialties.specialty_id)
      JOIN specialties ON (stylists_specialties.stylist_id = specialties.id)
      WHERE stylists.id = @StylistId;";

            MySqlParameter stylistIdParameter = new MySqlParameter();

            stylistIdParameter.ParameterName = "@StylistId";
            stylistIdParameter.Value         = _id;
            cmd.Parameters.Add(stylistIdParameter);

            MySqlDataReader  rdr            = cmd.ExecuteReader() as MySqlDataReader;
            List <Specialty> allSpecialties = new List <Specialty> {
            };

            while (rdr.Read())
            {
                int       specialtyId          = rdr.GetInt32(0);
                string    specialtyDescription = rdr.GetString(1);
                Specialty newSpecialty         = new Specialty(specialtyDescription, specialtyId);
                allSpecialties.Add(newSpecialty);
            }
            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
            return(allSpecialties);
        }
Ejemplo n.º 20
0
        public static List <Customer> FindByStylistId(int stylistId)
        {
            List <Customer> allCustomers = new List <Customer> {
            };
            MySqlConnection conn         = DB.Connection();

            conn.Open();
            var cmd = conn.CreateCommand() as MySqlCommand;

            cmd.CommandText = @"SELECT * FROM customers WHERE stylist_id = (@stylistSearchId);";

            MySqlParameter stylistIdParam = new MySqlParameter();

            stylistIdParam.ParameterName = "@stylistSearchId";
            stylistIdParam.Value         = stylistId;
            cmd.Parameters.Add(stylistIdParam);

            var rdr = cmd.ExecuteReader() as MySqlDataReader;

            while (rdr.Read())
            {
                int      customerIdRes   = rdr.GetInt32(0);
                string   customerNameRes = rdr.GetString(1);
                int      stylistIdRes    = rdr.GetInt32(2);
                Customer newCustomer     = new Customer(customerNameRes, customerIdRes, stylistIdRes);
                allCustomers.Add(newCustomer);
            }

            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }

            return(allCustomers);
        }
Ejemplo n.º 21
0
    public static List<Client> GetAll()
    {
      List<Client> allClients = new List<Client> {};
      MySqlConnection conn = DB.Connection();
      conn.Open();
      MySqlCommand cmd = conn.CreateCommand() as MySqlCommand;
      cmd.CommandText = @"SELECT * FROM clients;";
      MySqlDataReader rdr = cmd.ExecuteReader() as MySqlDataReader;
      while(rdr.Read())
      {
        int clientId = rdr.GetInt32(0);
        string clientName = rdr.GetString(1);
        string clientEmail = rdr.GetString(2);

        Client newClient = new Client(clientName, clientEmail, clientId);
        allClients.Add(newClient);
      }
      conn.Close();
      if (conn != null)
      {
        conn.Dispose();
      }
      return allClients;
    }
Ejemplo n.º 22
0
        public static Stylist Find(int id)
        {
            MySqlConnection conn = DB.Connection();

            conn.Open();

            var cmd = conn.CreateCommand() as MySqlCommand;

            cmd.CommandText = @"SELECT * FROM stylists WHERE id = (@stylistId);";

            MySqlParameter stylistId = new MySqlParameter();

            stylistId.ParameterName = "@stylistId";
            stylistId.Value         = id;
            cmd.Parameters.Add(stylistId);

            var    rdr         = cmd.ExecuteReader() as MySqlDataReader;
            int    StylistId   = 0;
            string StylistName = "";
            string HireDate    = "";

            while (rdr.Read())
            {
                StylistId   = rdr.GetInt32(0);
                StylistName = rdr.GetString(1);
                HireDate    = rdr.GetString(2);
            }
            Stylist newStylist = new Stylist(StylistName, HireDate, StylistId);

            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
            return(newStylist);
        }
Ejemplo n.º 23
0
    public void AddStylist(Stylist newStylist)
    {
      MySqlConnection conn = DB.Connection();
      conn.Open();
      var cmd = conn.CreateCommand() as MySqlCommand;
      cmd.CommandText = @"INSERT INTO stylists_clients (stylist_id, client_id) VALUES (@StylistId, @ClientId);";

      MySqlParameter stylist_id = new MySqlParameter();
      stylist_id.ParameterName = "@StylistId";
      stylist_id.Value = newStylist.GetId();
      cmd.Parameters.Add(stylist_id);

      MySqlParameter client_id = new MySqlParameter();
      client_id.ParameterName = "@ClientId";
      client_id.Value = _id;
      cmd.Parameters.Add(client_id);

      cmd.ExecuteNonQuery();
      conn.Close();
      if(conn != null)
      {
        conn.Dispose();
      }
    }
Ejemplo n.º 24
0
        public void Update(string name, int stylistId)
        {
            MySqlConnection conn = DB.Connection();

            conn.Open();
            var cmd = conn.CreateCommand() as MySqlCommand;

            cmd.CommandText = @"UPDATE clients SET name = @name, stylistId = @stylistId WHERE id = @clientId;";

            MySqlParameter tempName      = new MySqlParameter("@name", name);
            MySqlParameter tempStylistId = new MySqlParameter("@stylistId", stylistId);
            MySqlParameter tempClientId  = new MySqlParameter("@clientId", this.GetId());

            cmd.Parameters.Add(tempName);
            cmd.Parameters.Add(tempStylistId);
            cmd.Parameters.Add(tempClientId);

            cmd.ExecuteNonQuery();
            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
        }
Ejemplo n.º 25
0
        public static Client Find(int id)
        {
            MySqlConnection conn = DB.Connection();

            conn.Open();

            var cmd = conn.CreateCommand() as MySqlCommand;

            cmd.CommandText = @"SELECT * FROM clients where id = @thisId;";

            MySqlParameter thisId = new MySqlParameter();

            thisId.ParameterName = "@thisId";
            thisId.Value         = id;
            cmd.Parameters.Add(thisId);

            MySqlDataReader rdr = cmd.ExecuteReader() as MySqlDataReader;

            int    clientId   = 0;
            string clientName = "";

            while (rdr.Read())
            {
                clientId   = rdr.GetInt32(0);
                clientName = rdr.GetString(1);
            }

            Client foundClient = new Client(clientName, clientId);

            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
            return(foundClient);
        }
Ejemplo n.º 26
0
        public static Client Find(int id)
        {
            MySqlConnection conn = DB.Connection();

            conn.Open();
            var cmd = conn.CreateCommand() as MySqlCommand;

            cmd.CommandText = @"SELECT * FROM clients WHERE id = (@searchId);";

            MySqlParameter searchId = new MySqlParameter();

            searchId.ParameterName = "@searchId";
            searchId.Value         = id;
            cmd.Parameters.Add(searchId);

            var    rdr        = cmd.ExecuteReader() as MySqlDataReader;
            int    ClientId   = 0;
            string ClientName = "";
            int    Stylist_Id = 0;

            while (rdr.Read())
            {
                ClientId   = rdr.GetInt32(0);
                ClientName = rdr.GetString(1);
                Stylist_Id = rdr.GetInt32(2);
            }
            Client newClient = new Client(ClientName, Stylist_Id, ClientId);

            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
            // return new Client("", 0, 0); //Test will fail
            return(newClient); //Test will pass
        }
Ejemplo n.º 27
0
        public void Delete()
        {
            MySqlConnection conn = DB.Connection();

            conn.Open();

            var cmd = conn.CreateCommand() as MySqlCommand;

            cmd.CommandText = @"DELETE FROM specialties WHERE id = @thisid;";

            MySqlParameter thisId = new MySqlParameter();

            thisId.ParameterName = "@thisId";
            thisId.Value         = this._id;
            cmd.Parameters.Add(thisId);

            cmd.ExecuteNonQuery();

            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
        }
Ejemplo n.º 28
0
        //DELETE CLIENT
        public void DeleteClient()
        {
            MySqlConnection conn = DB.Connection();

            conn.Open();

            var cmd = conn.CreateCommand() as MySqlCommand;

            cmd.CommandText = @"DELETE FROM clients WHERE id = @id;";

            MySqlParameter thisId = new MySqlParameter();

            thisId.ParameterName = "@id";
            thisId.Value         = this._id;
            cmd.Parameters.Add(thisId);
            var rdr = cmd.ExecuteReader() as MySqlDataReader;


            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
        }
Ejemplo n.º 29
0
        public void Save()
        {
            MySqlConnection conn = DB.Connection();

            conn.Open();

            var cmd = conn.CreateCommand() as MySqlCommand;

            cmd.CommandText = @"INSERT INTO stylists (name) VALUES (@name);";

            MySqlParameter name = new MySqlParameter();

            name.ParameterName = "@name";
            name.Value         = this._name;
            cmd.Parameters.Add(name);

            cmd.ExecuteNonQuery();
            _id = (int)cmd.LastInsertedId;
            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
        }
Ejemplo n.º 30
0
        //RETURNS LIST OF CLIENTS BY STYLIST ID
        public static List <Client> GetClientsByStylistId(int id)
        {
            List <Client> clientsByStylist = new List <Client> {
            };
            MySqlConnection conn           = DB.Connection();

            conn.Open();
            var cmd = conn.CreateCommand() as MySqlCommand;

            cmd.CommandText = @"SELECT * FROM clients WHERE stylist_id = @searchId;";

            MySqlParameter searchId = new MySqlParameter();

            searchId.ParameterName = "@searchId";
            searchId.Value         = id;
            cmd.Parameters.Add(searchId);
            var rdr = cmd.ExecuteReader() as MySqlDataReader;

            while (rdr.Read())
            {
                int    clientId        = rdr.GetInt32(0);
                string clientFirstName = rdr.GetString(1);
                string clientLastName  = rdr.GetString(2);
                long   clientNumber    = rdr.GetInt64(3);
                string clientEmail     = rdr.GetString(4);
                int    clientStylistId = rdr.GetInt32(5);
                Client newClient       = new Client(clientFirstName, clientLastName, clientNumber, clientEmail, clientStylistId, clientId);
                clientsByStylist.Add(newClient);
            }
            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
            return(clientsByStylist);
        }