private void LoadClients() { _list = new Dictionary <int, Client>(); DataSet ds = DataSource.GetClients(); // Any error occurred? if (DataSource.ErrorCode() != 0) { //string msg = $"{DataSource.ErrorCode()} - {DataSource.ErrorMessage()}"; //throw new System.ApplicationException(msg); return; } if ((ds == null) || (ds.Tables[0].Rows.Count == 0)) { // There are no Clients. return; } // Retrieving the list of Employees to find the Agent assigned to each Client. EmployeeList employeeList = new EmployeeList(); foreach (DataRow row in ds.Tables[0].Rows) { Client client = new Client(); client.ClientId = (int)row["ClientId"]; client.FirstName = row["FirstName"].ToString(); client.LastName = row["LastName"].ToString(); client.BirthDate = (DateTime)row["BirthDate"]; client.Email = row["Email"].ToString(); client.Phone = row["Phone"].ToString(); client.ClientType = (ClientType)row["ClientTypeId"]; client.Agent = employeeList.FindByEmployeeId((int)row["AgentId"]); _list.Add(client.ClientId, client); } }