Bonjour,
Je sollicite votre aide parce que j'ai un problème de lenteur dans mon programme. En fait je veux afficher un planning des projets que j'affiche dans un tableau avec une double boucle for (une pour les lignes et une pour les colonnes). Pour chaque cellule j'utilise une fonction pour savoir quelle doit être sa couleur et une autre pour connaitre son taux d'avancement.
Voici le programme principal:
Voici la fonction qui crée le planning:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10 Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load Try If Not IsPostBack Then LabelAnneeGeneral.Text = Date.Now.Year End If creationPlanning(Val(LabelAnneeGeneral.Text)) Catch ex As Exception GestionErreur.LogErreur(ex.ToString()) End Try End Sub
Voici la fonction qui détermine la couleur de la cellule:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14 Protected Sub creationPlanning(annee As Integer) Dim mstrPg As Site = Page.Master Dim noChef As Integer = mstrPg.noChef LabelPlanGeneral.Text = "<table cellspacing='0px' cellpadding='10px' border='1px solid'>" LabelPlanGeneral.Text += "<tr><td><b>TOUS LES PROJETS</b></td><td><b>Janv.</b></td><td><b>Févr.</b></td><td><b>Mars</b></td><td><b>Avril</b></td><td><b>Mai</b></td><td><b>Juin</b></td><td><b>Juil.</b></td><td><b>Août</b></td><td><b>Sept.</b></td><td><b>Oct.</b></td><td><b>Nov.</b></td><td><b>Déc.</b></td></tr>" For j As Integer = 0 To dataStatusP.ListeDroitsTotal(noChef).Rows.Count - 1 LabelPlanGeneral.Text += "<tr><td style='text-align:right'><b>" & dataStatusP.ListeDroitsTotal(noChef).Rows(j).Item("PRJ_LIB") & "</b></td>" For k As Integer = 1 To 12 LabelPlanGeneral.Text += "<td style='width:20px;color:white;background-color:" & CaseCouleur(dataStatusP.FichePRJ_PRJ(dataStatusP.ListeDroitsTotal(noChef).Rows(j).Item("PRJ_COD")), New DateTime(annee, k, 1)) & "'>" & CaseAvancement(dataStatusP.FichePRJ_PRJ(dataStatusP.ListeDroitsTotal(noChef).Rows(j).Item("PRJ_COD")), New DateTime(annee, k, 1)) & "</td>" Next LabelPlanGeneral.Text += "</tr>" Next LabelPlanGeneral.Text += "</table>" End Sub
Et enfin voici la fonction qui détermine le taux d'avancement de la celulle:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 Protected Function CaseCouleur(Prj As BLL_PRJ_PRJ, DatCase As DateTime) As String Dim retour As String = Nothing Try Dim DatDebut As DateTime = Prj.PRJ_DAT_DEB Dim DatFin As DateTime = Prj.PRJ_DAT_FIN retour = "#4b6c9e" If (DatDebut <= DatCase Or DateDiff(DateInterval.Month, DatDebut, DatCase) = 0) And (DatFin >= DatCase Or DateDiff(DateInterval.Month, DatFin, DatCase) = 0) Then retour = "#3a4f63" End If If Prj.STA_COD = 2 And DatFin < DatCase And (DatCase <= Date.Now Or DateDiff(DateInterval.Month, DatCase, Date.Now) = 0) Then retour = "#cf1111" End If Catch ex As Exception retour = Nothing GestionErreur.LogErreur(ex.ToString()) End Try Return retour End Function
Sachant que j'ai fait un test avec 10 projets, ce qui fait 10 lignes de 12 colonnes (les mois de l'année). Le tableau fait donc 120 cellules et à chaque chargement de ce planning il met environ 30 secondes à s'afficher ce qui est évidement énorme, donc je voudrais savoir si vous n'aviez pas une idée pour améliorer les performances de mon programme.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 Protected Function CaseAvancement(Prj As BLL_PRJ_PRJ, DatCase As DateTime) As String Dim retour As String = Nothing Try For i As Integer = 0 To dataStatusA.ListeByProjet(Prj.PRJ_COD).Rows.Count - 1 Dim DatTx As DateTime = dataStatusA.ListeByProjet(Prj.PRJ_COD).Rows(i).Item("AV_DAT") If DatTx.Month = DatCase.Month And DatTx.Year = DatCase.Year Then Return dataStatusA.ListeByProjet(Prj.PRJ_COD).Rows(i).Item("AV_TX") End If Next Catch ex As Exception retour = Nothing GestionErreur.LogErreur(ex.ToString()) End Try Return retour End Function
Merci d'avance
Partager