public Client getClient(int clientId) { Client client = new Client(); mysql.open(); string query = "SELECT * FROM klijent WHERE idKlijenta = @id"; mysql.setCmd(query); mysql.cmd.Parameters.AddWithValue("@id", clientId); mysql.reader = mysql.cmd.ExecuteReader(); while (mysql.reader.Read()) { client.old_id = int.Parse(mysql.reader["idKlijenta"].ToString()); client.fname = mysql.reader["ime"].ToString(); client.lname = mysql.reader["prezime"].ToString(); client.phone1 = mysql.reader["telefon"].ToString(); client.phone2 = mysql.reader["telefon2"].ToString(); client.email = mysql.reader["email"].ToString(); client.fblink = mysql.reader["fblink"].ToString(); client.notes = mysql.reader["napomene"].ToString(); client.address = mysql.reader["adresa"].ToString(); if (mysql.reader["rating"] != null && mysql.reader["rating"].ToString() != "") client.rating = float.Parse(mysql.reader["rating"].ToString(), System.Globalization.CultureInfo.InvariantCulture); client.status = (int)mysql.reader["status"]; } mysql.close(); return client; }
public void getClients(ref Model model) { mysql.open(); string query = "SELECT * FROM klijent"; mysql.setCmd(query); mysql.reader = mysql.cmd.ExecuteReader(); while (mysql.reader.Read()) { Client client = new Client(); client.old_id = int.Parse(mysql.reader["idKlijenta"].ToString()); client.fname = mysql.reader["ime"].ToString(); client.lname = mysql.reader["prezime"].ToString(); client.phone1 = mysql.reader["telefon"].ToString(); client.phone2 = mysql.reader["telefon2"].ToString(); client.email = mysql.reader["email"].ToString(); client.fblink = mysql.reader["fblink"].ToString(); client.notes = mysql.reader["napomene"].ToString(); client.address = mysql.reader["adresa"].ToString(); if (mysql.reader["rating"] != null && mysql.reader["rating"].ToString() != "") client.rating = float.Parse(mysql.reader["rating"].ToString(), System.Globalization.CultureInfo.InvariantCulture); client.status = (int)mysql.reader["status"]; model.clients.Add(client); } mysql.close(); }
public int insertClient(Client client) { sql.open(); string query = "INSERT INTO clients (fname, lname, phone, phone2, email, fblink, notes, address, rating, status) OUTPUT INSERTED.ID VALUES (@fname, @lname, @phone, @phone2, @email, @fblink, @notes, @address, @rating, @status)"; sql.setCmd(query); if (sql.hasParams == false) { sql.addParam(System.Data.SqlDbType.NVarChar, "@fname", client.fname); sql.addParam(System.Data.SqlDbType.NVarChar, "@lname", client.lname); sql.addParam(System.Data.SqlDbType.NVarChar, "@phone", client.phone1); sql.addParam(System.Data.SqlDbType.NVarChar, "@phone2", client.phone2); sql.addParam(System.Data.SqlDbType.NVarChar, "@email", client.email); sql.addParam(System.Data.SqlDbType.NVarChar, "@fblink", client.fblink); sql.addParam(System.Data.SqlDbType.NVarChar, "@notes", client.notes); sql.addParam(System.Data.SqlDbType.NVarChar, "@address", client.address); sql.addParam(System.Data.SqlDbType.Float, "@rating", client.rating); sql.addParam(System.Data.SqlDbType.Int, "@status", client.status); sql.cmd.Prepare(); } else { sql.setValue("@fname", client.fname); sql.setValue("@lname", client.lname); sql.setValue("@phone", client.phone1); sql.setValue("@phone2", client.phone2); sql.setValue("@email", client.email); sql.setValue("@fblink", client.fblink); sql.setValue("@notes", client.notes); sql.setValue("@address", client.address); sql.setValue("@rating", client.rating); sql.setValue("@status", client.status); } int a = (int)sql.cmd.ExecuteScalar(); sql.close(); return a; }