Пример #1
0
 public void update(FieldDTO entity)
 {
     SqlSingleton.getInstance().ExecQuery("update  field set " +
                                          " value='" + entity.value + "'" +
                                          " where idContact=" + entity.idContact + "" +
                                          " and name='" + entity.name + "';");
 }
Пример #2
0
 public void Add(FieldDTO entity)
 {
     SqlSingleton.getInstance().ExecQuery("insert into field (name,value,idContact) values (" +
                                          "'" + entity.name + "'," +
                                          "'" + entity.value + "'," +
                                          "'" + entity.idContact + "');");
 }
Пример #3
0
        public IEnumerable <ContactDTO> GetAll()
        {
            var             retour = new List <ContactDTO>();
            List <FieldDTO> fieldOfCurrentReturn = new List <FieldDTO>();

            DataTable dt = SqlSingleton.getInstance().ExecQuery("select * from contact  order by firstname,lastname;").Tables[0];

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                retour.Add(new ContactDTO
                {
                    id        = int.Parse(dt.Rows[i]["id"].ToString()),
                    firstName = dt.Rows[i]["firstname"].ToString(),
                    lastName  = dt.Rows[i]["lastname"].ToString()
                });
            }
            foreach (var item in retour)
            {
                dt = SqlSingleton.getInstance().ExecQuery("select * from field  where idContact=" + item.id + ";").Tables[0];
                foreach (DataRow row in dt.Rows)
                {
                    item.fields.Add(new FieldDTO
                    {
                        idContact = item.id,
                        name      = row["name"].ToString(),
                        value     = row["value"].ToString(),
                    });
                }
            }
            return(retour);
        }
Пример #4
0
 public void update(ContactDTO entity)
 {
     SqlSingleton.getInstance().ExecQuery("update  contact set firstname='" + entity.firstName + "'" +
                                          ",lastname='" + entity.lastName + "'" +
                                          " where id=" + entity.id + ";");
     foreach (var item in entity.fields)
     {
         new FieldSQL().update(item);
     }
 }
Пример #5
0
        public FieldDTO Get(int id)
        {
            DataTable dt = SqlSingleton.getInstance().ExecQuery("select * from field where id=" + id + ";").Tables[0];
            DataRow   dr = dt.Rows[0];

            return(new FieldDTO
            {
                value = dr["value"].ToString(),
                name = dr["name"].ToString(),
                idContact = int.Parse(dr["idContact"].ToString())
            });
        }
Пример #6
0
        public IEnumerable <FieldDTO> GetAll()
        {
            var       retour = new List <FieldDTO>();
            DataTable dt     = SqlSingleton.getInstance().ExecQuery("select * from contact  ;").Tables[0];

            foreach (DataRow row in dt.Rows)
            {
                retour.Add(new FieldDTO
                {
                    idContact = int.Parse(row["idContact"].ToString()),
                    name      = row["name"].ToString(),
                    value     = row["value"].ToString()
                });
            }
            return(retour);
        }
Пример #7
0
        public void Add(ContactDTO entity)
        {
            SqlSingleton.getInstance().ExecQuery("insert into contact (firstname,lastname) values (" +
                                                 "'" + entity.firstName + "'," +
                                                 "'" + entity.lastName + "');");
            DataTable dt = SqlSingleton.getInstance().ExecQuery(" select id from contact order by id desc limit 1 ;").Tables[0];
            int       id = int.Parse(dt.Rows[0]["id"].ToString());

            foreach (var item in entity.fields)
            {
                new FieldSQL().Add(new FieldDTO
                {
                    idContact = id,
                    name      = item.name,
                    value     = item.value
                });
            }
        }
Пример #8
0
        public ContactDTO Get(int id)
        {
            DataTable  dt     = SqlSingleton.getInstance().ExecQuery("select * from contact  where id=" + id + ";").Tables[0];
            DataRow    dr     = dt.Rows[0];
            ContactDTO retour = new ContactDTO
            {
                id        = int.Parse(dr["id"].ToString()),
                firstName = dr["firstname"].ToString(),
                lastName  = dr["lastname"].ToString()
            };

            dt = SqlSingleton.getInstance().ExecQuery("select * from field  where idContact=" + id + ";").Tables[0];
            foreach (DataRow row in dt.Rows)
            {
                retour.fields.Add(new FieldDTO
                {
                    idContact = int.Parse(row["idContact"].ToString()),
                    name      = row["name"].ToString(),
                    value     = row["value"].ToString(),
                });
            }
            return(retour);
        }
Пример #9
0
 public void remove(FieldDTO field)
 {
     SqlSingleton.getInstance().ExecQuery("delete from field where idcontact =" + field.idContact + " and name='" + field.name + "';");
 }
Пример #10
0
        public void remove(ContactDTO entity)
        {
            SqlSingleton.getInstance().ExecQuery("delete from field where idContact=" + entity.id + ";");

            SqlSingleton.getInstance().ExecQuery("delete from contact where id=" + entity.id + ";");
        }