Exemple #1
0
        public bool FillClients(repositories.Client clientRepository)
        {
            SQLiteCommand command = new SQLiteCommand("SELECT * FROM client", db.connection);

            SQLiteDataReader reader = command.ExecuteReader();

            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    string phone;

                    if (!reader.IsDBNull(2))
                    {
                        phone = reader.GetString(2);
                    }
                    else
                    {
                        phone = "";
                    }

                    entities.Client client = new entities.Client(reader.GetInt32(0), reader.GetString(1), phone);
                    clientRepository.Add(client);
                }
            }

            reader.Close();

            return(true);
        }
        public Tuple <int> LoadClients(repositories.Client clients)
        {
            List <string[]> lines = ParseCsv(GetCsvString("clients"));

            int added = 0;

            foreach (string[] line in lines)
            {
                int    id    = Convert.ToInt32(line[0]);
                string name  = line[1];
                string phone = line[2];

                entities.Client client = clients.FindOne(id);
                if (client == null)
                {
                    entities.Client addClient = new entities.Client(id, name, phone);

                    clients.SaveWithSql(addClient);
                }
                else
                {
                    client.SetId(id);
                    client.SetName(name);
                    client.SetPhone(phone);

                    clients.SaveWithSql(client);

                    added++;
                }
            }

            return(new Tuple <int>(added));
        }