示例#1
0
 public Boolean isReductible(DocLog anotherDocLog)
 {
     if (anotherDocLog.idDocument == this.idDocument)
     {
         return true;
     }
     else
     {
         return false;
     }
 }
 private static List<DocLog> OptimiseDocLogList(List<DocLog> listDocLogs)
 {
     if(listDocLogs.Count < 2)
     {
         return listDocLogs;
     }
     List<DocLog> returnList = new List<DocLog>();
     //for (int i = 0; i < listDocLogs.Count - 1; i++)
     //{
     foreach (DocLog docLogRef in listDocLogs)
     {
         //DocLog docLogRef = listDocLogs[i];
         for (int j = listDocLogs.Count - 1; j > listDocLogs.IndexOf(docLogRef); j--)
         {
             DocLog docLogToCompare = listDocLogs[j];
             if (docLogRef.isReductible(docLogToCompare)) //même id
             {
                 if (docLogRef.typeModification == "ADD")//Si le premier élément est un ajout
                 {
                     if(docLogToCompare.typeModification != "DEL")
                     {
                         DocLog newDocLog = new DocLog(docLogRef.idDocLogs, docLogRef.idDocument, "ADD");
                         returnList.Add(newDocLog);
                     }
                     //sinon OSEF
                 }
                 else
                 {
                     if (docLogToCompare.typeModification != "DEL")
                     {
                         DocLog newDocLog = new DocLog(docLogRef.idDocLogs, docLogRef.idDocument, "EDIT");
                         returnList.Add(newDocLog);
                     }
                     else
                     {
                         DocLog newDocLog = new DocLog(docLogRef.idDocLogs, docLogRef.idDocument, "DEL");
                         returnList.Add(newDocLog);
                     }
                 }
                 //On efface les docLog référents à cet idDocument
                 foreach (DocLog aDocLog in listDocLogs)
                 {
                     if (aDocLog.isReductible(docLogRef))
                     {
                         listDocLogs.Remove(aDocLog);
                     }
                 }
                 //On sort de la boucle
                 break;
             }
         }
     }
     // Fusionner les lists listDocLogs et returnList
     returnList = listDocLogs.Concat(returnList).ToList();
     return returnList;
 }