public Contact NouveauContact() { if (this.contact == null) { this.contact = new Contact(); } List <Donnee> donnees; contact.setIduser(template.getIduser()); contact.setDtcreation(DateTime.Now); contact.setFavoris(false); contact.setActif(true); donnees = new List <Donnee>(); foreach (Control ctrl in this.panel1.Controls) { if (ctrl.Tag != null && ctrl.Tag.GetType() == typeof(Champ)) { Champ c = (Champ)ctrl.Tag; Donnee d = new Donnee(); d.setIdchamp(c.getIdchamp()); if (ctrl.GetType() == typeof(DateTimePicker)) { if ((((DateTimePicker)ctrl).Value.ToShortDateString() != DateTime.Now.ToShortDateString())) { d.setValeur(((DateTimePicker)ctrl).Value.ToString("yyyy-MM-dd")); } else { d.setValeur(null); } } else { d.setValeur(ctrl.Text); } donnees.Add(d); } } contact.setDonnees(donnees); return(contact); }
private void BtnAjouter_Click(object sender, EventArgs e) { if (FormIsValid()) { contact = NouveauContact(); contact.setIduser(iduser); ContactWrapper cw = new ContactWrapper(); cw.setContact(contact); cw.setIdtemplate(template.getIdtemplate()); ApiContact.SetContact(cw); ChargerListeContact.DynamicInvoke(); if (this.panel1.Controls["BtnAjouter"] != null && this.panel1.Controls["BtnAjouter"].Text == "Ajouter") { contact = null; this.panel1.Controls.Clear(); this.InitialiseChamp(); } } }