private void Importer(object sender, EventArgs e)
 {
     try
     {
         // TODO: verifier ligne
         _controller.Ajouter(_lignesAnnexe);
         DialogResult = DialogResult.OK;
         Close();
     }
     catch (Exception ex)
     {
         XtraMessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
        private void SaveLigne(object sender, EventArgs e)
        {
            if (_currentLigne == null)
            {
                return;
            }

            var ligneZoneValue = gcLigneZoneValue.DataSource as List <LigneAnnexeZoneValue>;

            if (ligneZoneValue == null)
            {
                return;
            }
            var counter     = -1;
            var erreurValue = false;
            var colValue    = gvLigneZoneValue.Columns["Value"];

            foreach (var ligneZone in ligneZoneValue.OrderBy(x => x.Code))
            {
                // incrementer nb ligne
                counter++;
                gvLigneZoneValue.FocusedRowHandle = counter;
                switch (ligneZone.Type)
                {
                case ZoneType.D:
                    // ver valeur date
                    var valueD = Convert.ToDateTime(ligneZone.Value);
                    if (valueD >= new DateTime(2000, 01, 01))
                    {
                        break;
                    }
                    gvLigneZoneValue.SetColumnError(colValue, "Date invalide!");
                    erreurValue = true;
                    break;

                case ZoneType.E:
                    // ver valeur enum
                    var valueE = Convert.ToInt32(ligneZone.Value);
                    if (valueE >= 0)
                    {
                        break;
                    }
                    gvLigneZoneValue.SetColumnError(colValue, "Valeur invalide!");
                    erreurValue = true;
                    break;

                case ZoneType.I:
                    // ver valeur int
                    var valueI = Convert.ToInt32(ligneZone.Value);
                    if (valueI >= 0)
                    {
                        break;
                    }
                    gvLigneZoneValue.SetColumnError(colValue, "Valeur invalide!");
                    erreurValue = true;
                    break;

                case ZoneType.N:
                    // ver valeur numerique(decimal)
                    var valueN = Convert.ToInt32(ligneZone.Value);
                    if (valueN >= 0)
                    {
                        break;
                    }
                    gvLigneZoneValue.SetColumnError(colValue, "Montant invalide!");
                    erreurValue = true;
                    break;

                case ZoneType.X:
                    var valueX = Convert.ToString(ligneZone.Value);
                    if (!string.IsNullOrEmpty(valueX))
                    {
                        break;
                    }
                    gvLigneZoneValue.SetColumnError(colValue, "Chaine invalide!");
                    erreurValue = true;
                    break;

                default:
                    throw new NotImplementedException("Zone type non implimenté!");
                }

                if (erreurValue)
                {
                    return;
                }
                if (_currentLigne.Id == 0)
                {
                    continue;
                }
                // get ligne annexe propertie
                var propertie = typeof(TL).GetProperty(ligneZone.PropertieFieldName);
                // set ligne annexe propertie
                propertie.SetValue(_currentLigne, ligneZone.Value);
            }
            var i = -1;


            try
            {
                // mode ajout
                if (_currentLigne.Id == 0)
                {
                    _currentLigne = _controller.InitializeLigneAnnexe(ligneZoneValue);
                    if (_currentLigne == null)
                    {
                        return;
                    }
                    var listErr = _controller.Verifier(_currentLigne);
                    foreach (var ligneZone in ligneZoneValue.OrderBy(x => x.Code))
                    {
                        // incrementer nb ligne
                        i++;
                        gvLigneZoneValue.FocusedRowHandle = i;
                        var err = listErr.Where(x => x.PropertyName == ligneZone.PropertieFieldName).ToList();
                        if (err.Any())
                        {
                            gvLigneZoneValue.SetColumnError(colValue, err.First().ErrorMessage);
                            return;
                        }
                    }
                    _controller.Ajouter(_currentLigne);
                    RefreshDataSource();
                    AjouterLigne(null, null);
                    return;
                }

                var listErrUpadte = _controller.Verifier(_currentLigne);
                foreach (var ligneZone in ligneZoneValue.OrderBy(x => x.Code))
                {
                    // incrementer nb ligne
                    i++;
                    gvLigneZoneValue.FocusedRowHandle = i;
                    var err = listErrUpadte.Where(x => x.PropertyName == ligneZone.PropertieFieldName).ToList();
                    if (err.Any())
                    {
                        gvLigneZoneValue.SetColumnError(colValue, err.First().ErrorMessage);
                        return;
                    }
                }
                // mode update
                _controller.Update(_currentLigne);
                // get focused row
                var focusedRow = gvLignesAnnexes.GetFocusedRow() as ILigneAnnexe;
                if (focusedRow == null)
                {
                    return;
                }
                // refresh
                var index = _lignesCollection.IndexOf((TL)focusedRow);
                if (index <= 0)
                {
                    return;
                }
                // get updated row
                var updatedRow = _controller.GetLigne(_currentLigne.Id);
                if (updatedRow == null)
                {
                    return;
                }
                _lignesCollection[index] = updatedRow;

                gvLignesAnnexes.RefreshData();
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.Message, "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }