List <CsDetailMoratoire> CreateListeFromDetailMoratoire(List <CsDetailMoratoire> lesfactureMoratoire) { try { string refem = MoisComptable; if (lesfactureMoratoire.Count == 1) { refem = lesfactureMoratoire.First().REFEM; } List <CsDetailMoratoire> moratoires = new List <CsDetailMoratoire>(); selectedoccurMoratoire = int.Parse(NumericUpDown.Value.ToString()); for (int i = 0; i < selectedoccurMoratoire + 1; i++) { int inc = i + 1; TextBox amounts = null; TextBox dates = null; if (i != 0) { amounts = AllInOne.FindControl <TextBox>((UIElement)LayoutRoot, typeof(TextBox), "txtAmount" + i); dates = AllInOne.FindControl <TextBox>((UIElement)LayoutRoot, typeof(TextBox), "txtDate" + i); } if (i == 0) { continue; } CsDetailMoratoire echeanceMoratoire = new CsDetailMoratoire() { COPER = SessionObject.Enumere.CoperMOR, REFEM = MoisComptable, CENTRE = lesfactureMoratoire.First().CENTRE, CLIENT = lesfactureMoratoire.First().CLIENT, ORDRE = lesfactureMoratoire.First().ORDRE, CRET = SessionObject.Cret()[i - 1], DATEVALEUR = null, DC = SessionObject.Enumere.Debit, MONTANT = Convert.ToDecimal(amounts.Text), EXIGIBILITE = DateTime.Parse(dates.Text), TOP1 = SessionObject.Enumere.TopMoratoire, MATRICULE = UserConnecte.matricule, DATECREATION = DateTime.Now.Date, USERCREATION = UserConnecte.matricule, FK_IDCLIENT = lesfactureMoratoire.First().FK_IDCLIENT, FK_IDCENTRE = lesfactureMoratoire.First().FK_IDCENTRE, FK_IDADMUTILISATEUR = UserConnecte.PK_ID, FK_IDCOPER = SessionObject.LstDesCopers.FirstOrDefault(t => t.CODE == SessionObject.Enumere.CoperMOR).PK_ID, FK_IDLIBELLETOP = SessionObject.LstDesLibelleTop.FirstOrDefault(t => t.CODE == SessionObject.Enumere.TopMoratoire).PK_ID, IDMORATOIRE = lesfactureMoratoire.First().IDMORATOIRE, FK_IDMORATOIRE = lesfactureMoratoire.First().IDMORATOIRE }; CsDetailMoratoire leAncMor = lesfactureMoratoire.FirstOrDefault(t => t.CRET == echeanceMoratoire.CRET); if (leAncMor != null) { echeanceMoratoire.REFEM = leAncMor.REFEM; echeanceMoratoire.NDOC = leAncMor.NDOC; } moratoires.Add(echeanceMoratoire); } return(moratoires); } catch (Exception ex) { throw ex; } }