public static void LoadClients(SqlDataReader reader) { while (reader.Read()) { Client client = new Client(); client.ClientID = (int)reader["ClientID"]; client.FirstName = reader["FirstName"].ToString(); client.LastName = reader["LastName"].ToString(); client.Email = reader["email"].ToString(); client.IsChanged = false; clients.Add(client); } }
public static void UpdateClients() { string query1 = string.Empty; string query2 = string.Empty; Client tmpClient = new Client(); SqlCommand command; SqlDataReader reader; List<int> changedData; query1 = "select * from Clients"; command = new SqlCommand(query1, DataBase.Sql); reader = command.ExecuteReader(); changedData = new List<int>(); foreach (Client client in ClientsManager.Clients) { if (client.IsChanged) changedData.Add(client.ClientID); } while (reader.Read()) { if (changedData.Contains((int)reader["ClientID"])) { foreach (Client client in ClientsManager.Clients) { if (client.ClientID == ((int)reader["ClientID"])) { tmpClient = client; break; } } query2 = string.Format("update Clients set FirstName = '{0}' where ClientID = {1}", tmpClient.FirstName, tmpClient.ClientID); (new SqlCommand(query2, DataBase.Sql)).ExecuteNonQuery(); query2 = string.Format("update Clients set LastName = '{0}' where ClientID = {1}", tmpClient.LastName, tmpClient.ClientID); (new SqlCommand(query2, DataBase.Sql)).ExecuteNonQuery(); query2 = string.Format("update Clients set email = '{0}' where ClientID = {1}", tmpClient.Email, tmpClient.ClientID); (new SqlCommand(query2, DataBase.Sql)).ExecuteNonQuery(); tmpClient.IsChanged = false; } } reader.Close(); }
public ClientForCB(Client cl) { clientFromList = cl; name = string.Format("{0} {1} {2}", cl.ClientID, cl.FirstName, cl.LastName); }