/// <summary> /// Edition de la fiche pour un plan /// </summary> public string Editer_Fiche_Plan() { //Création de l'application Excel app = new Microsoft.Office.Interop.Excel.Application(); app.DisplayAlerts = false; Plan plan = (Plan)Acces.Trouver_Element(Acces.type_PLAN.id, id_element); var modele = Chemin + "\\Modeles\\Fiche_PLAN.xltx"; var fichier = Chemin + "\\Fichiers\\" + "FP-" + plan.Code + "-" + string.Format("{0:yyMMddHHmmss}", DateTime.Now); app.Workbooks.Open(modele); Workbooks wk = app.Workbooks; Workbook wb = app.ActiveWorkbook; Worksheet ws = wb.Sheets[1]; Range r; r = ws.Cells[2, 4]; r.Value = plan.Libelle; r = ws.Cells[3, 4]; if (plan.Pilote != null) { r.Value = plan.Pilote.Nom + " " + plan.Pilote.Prenom; } r = ws.Cells[4, 4]; r.Value = Acces.Donner_Chaine_Liste_Utilisateur(plan.Equipe);; //Groupe interne r = ws.Cells[5, 4]; r.Value = plan.GroupeExterne; //Groupe externe r = ws.Cells[6, 4]; r.Value = string.Format("{0:dd/MM/yyyy}", DateTime.Now); //Groupe interne r = ws.Cells[6, 14]; r.Value = plan.Code; //Affichage des éléments int n_ligne = 10; //Efface la zone ws.Range["A11:Z10000"].Clear(); List <Lien> listeLien = Acces.Remplir_ListeLien(Acces.type_PLAN, plan.ID.ToString()); listeLien.Sort(); //Passe 1 : les objectifs foreach (Lien l in listeLien) { if (l.element2_type != Acces.type_OBJECTIF.id) { goto Suite1; } Objectif obj = (Objectif)Acces.Trouver_Element(Acces.type_OBJECTIF.id, l.element2_id); n_ligne++; r = ws.Cells[n_ligne, 1]; r.Value = obj._op; r = ws.Cells[n_ligne, 2]; r.Value = obj.Libelle; r = ws.Cells[n_ligne, 22]; r.Value = obj.Code.Replace("OBJ-", ""); Suite1 :; } //Passe 2 : les actions foreach (Lien l in listeLien) { if (l.element2_type != Acces.type_ACTION.id) { goto Suite2; } PATIO.Classes.Action action = (PATIO.Classes.Action)Acces.Trouver_Element(Acces.type_ACTION.id, l.element2_id); if (action.TypeAction != TypeAction.ACTION) { goto Suite2; } n_ligne++; r = ws.Cells[n_ligne, 3]; r.Value = action.Libelle; r = ws.Cells[n_ligne, 4]; string pilote = ""; pilote = Acces.Donner_Chaine_Liste(action.DirectionPilote, "DIRECTION_METIER", "", true); pilote += (action.Pilote != null) ? "\n" + action.Pilote.Nom + " " + action.Pilote.Prenom : plan.Pilote.Nom + " " + plan.Pilote.Prenom; r.Value = pilote; r = ws.Cells[n_ligne, 7]; r.Value = (action.ActionPhare ? "X" : ""); if (action.OrdreActionPhare > 0) { r.Value = Acces.Trouver_TableValeur(action.OrdreActionPhare).Valeur; } r = ws.Cells[n_ligne, 8]; //Année 2018 r.Interior.Color = Acces.Exister_Valeur(action.AnneeMiseOeuvre, "ANNEE_MO", "2018") ? XlRgbColor.rgbLightBlue : XlRgbColor.rgbWhite; r.Value = action.Mt_2018; r = ws.Cells[n_ligne, 9]; //Année 2019 r.Interior.Color = Acces.Exister_Valeur(action.AnneeMiseOeuvre, "ANNEE_MO", "2019") ? XlRgbColor.rgbLightBlue : XlRgbColor.rgbWhite; r.Value = action.Mt_2019; r = ws.Cells[n_ligne, 10]; //Année 2020 r.Interior.Color = Acces.Exister_Valeur(action.AnneeMiseOeuvre, "ANNEE_MO", "2020") ? XlRgbColor.rgbLightBlue : XlRgbColor.rgbWhite; r.Value = action.Mt_2020; r = ws.Cells[n_ligne, 11]; //Année 2021 r.Interior.Color = Acces.Exister_Valeur(action.AnneeMiseOeuvre, "ANNEE_MO", "2021") ? XlRgbColor.rgbLightBlue : XlRgbColor.rgbWhite; r.Value = action.Mt_2021; r = ws.Cells[n_ligne, 12]; //Année 2022 r.Interior.Color = Acces.Exister_Valeur(action.AnneeMiseOeuvre, "ANNEE_MO", "2022") ? XlRgbColor.rgbLightBlue : XlRgbColor.rgbWhite; r.Value = action.Mt_2022; r = ws.Cells[n_ligne, 13]; //Année 2023 r.Interior.Color = Acces.Exister_Valeur(action.AnneeMiseOeuvre, "ANNEE_MO", "2023") ? XlRgbColor.rgbLightBlue : XlRgbColor.rgbWhite; r.Value = action.Mt_2023; r = ws.Cells[n_ligne, 14]; //Financement r.Value = action.CoutFinancier; if (action.Mt_Total != null) { if (action.Mt_Total.Length > 0) { r.Value += "\n TOTAL : " + action.Mt_Total + " k€"; } } r = ws.Cells[n_ligne, 15]; //TDS MF r.Value = Acces.Exister_Valeur(action.TSante, "TSANTE", "TS591") ? "X" : ""; r.Interior.Color = Acces.Exister_Valeur(action.Priorite_CTS, "PRIO_CTS_591", "", true) ? XlRgbColor.rgbLightBlue : XlRgbColor.rgbWhite; r = ws.Cells[n_ligne, 16]; //TDS Hainaut r.Value = Acces.Exister_Valeur(action.TSante, "TSANTE", "TS592") ? "X" : ""; r.Interior.Color = Acces.Exister_Valeur(action.Priorite_CTS, "PRIO_CTS_592", "", true) ? XlRgbColor.rgbLightBlue : XlRgbColor.rgbWhite; r = ws.Cells[n_ligne, 17]; //TDS 62 r.Value = Acces.Exister_Valeur(action.TSante, "TSANTE", "TS62") ? "X" : ""; r.Interior.Color = Acces.Exister_Valeur(action.Priorite_CTS, "PRIO_CTS_62", "", true) ? XlRgbColor.rgbLightBlue : XlRgbColor.rgbWhite; r = ws.Cells[n_ligne, 18]; //TDS 80 r.Value = Acces.Exister_Valeur(action.TSante, "TSANTE", "TS80") ? "X" : ""; r.Interior.Color = Acces.Exister_Valeur(action.Priorite_CTS, "PRIO_CTS_80", "", true) ? XlRgbColor.rgbLightBlue : XlRgbColor.rgbWhite; r = ws.Cells[n_ligne, 19]; //TDS 60 r.Value = Acces.Exister_Valeur(action.TSante, "TSANTE", "TS60") ? "X" : ""; r.Interior.Color = Acces.Exister_Valeur(action.Priorite_CTS, "PRIO_CTS_60", "", true) ? XlRgbColor.rgbLightBlue : XlRgbColor.rgbWhite; r = ws.Cells[n_ligne, 20]; //TDS 02 r.Value = Acces.Exister_Valeur(action.TSante, "TSANTE", "TS02") ? "X" : ""; r.Interior.Color = Acces.Exister_Valeur(action.Priorite_CTS, "PRIO_CTS_02", "", true) ? XlRgbColor.rgbLightBlue : XlRgbColor.rgbWhite; r = ws.Cells[n_ligne, 21]; //REGION r.Value = Acces.Exister_Valeur(action.TSante, "TSANTE", "REGION") ? "X" : ""; r = ws.Cells[n_ligne, 22]; r.Value = action.Code.Replace("ACT-", ""); Suite2 :; } //Passe 3 : les opérations foreach (Lien l in listeLien) { if (l.element2_type != Acces.type_ACTION.id) { goto Suite3; } PATIO.Classes.Action action = (PATIO.Classes.Action)Acces.Trouver_Element(Acces.type_ACTION.id, l.element2_id); if (action.TypeAction != TypeAction.OPERATION) { goto Suite3; } n_ligne++; r = ws.Cells[n_ligne, 5]; r.Value = action.Libelle; r = ws.Cells[n_ligne, 6]; string pilote = ""; pilote = Acces.Donner_Chaine_Liste(action.DirectionPilote, "DIRECTION_METIER", "", true); pilote += (action.Pilote != null)? "\n" + action.Pilote.Nom + " " + action.Pilote.Prenom : plan.Pilote.Nom + " " + plan.Pilote.Prenom; r.Value = pilote; r = ws.Cells[n_ligne, 7]; r.Value = (action.ActionPhare ? "X" : ""); if (action.OrdreActionPhare > 0) { r.Value = Acces.Trouver_TableValeur(action.OrdreActionPhare).Valeur; } r = ws.Cells[n_ligne, 8]; //Année 2018 r.Interior.Color = Acces.Exister_Valeur(action.AnneeMiseOeuvre, "ANNEE_MO", "2018") ? XlRgbColor.rgbLightBlue : XlRgbColor.rgbWhite; r.Value = action.Mt_2018; r = ws.Cells[n_ligne, 9]; //Année 2019 r.Interior.Color = Acces.Exister_Valeur(action.AnneeMiseOeuvre, "ANNEE_MO", "2019") ? XlRgbColor.rgbLightBlue : XlRgbColor.rgbWhite; r.Value = action.Mt_2019; r = ws.Cells[n_ligne, 10]; //Année 2020 r.Interior.Color = Acces.Exister_Valeur(action.AnneeMiseOeuvre, "ANNEE_MO", "2020") ? XlRgbColor.rgbLightBlue : XlRgbColor.rgbWhite; r.Value = action.Mt_2020; r = ws.Cells[n_ligne, 11]; //Année 2021 r.Interior.Color = Acces.Exister_Valeur(action.AnneeMiseOeuvre, "ANNEE_MO", "2021") ? XlRgbColor.rgbLightBlue : XlRgbColor.rgbWhite; r.Value = action.Mt_2021; r = ws.Cells[n_ligne, 12]; //Année 2022 r.Interior.Color = Acces.Exister_Valeur(action.AnneeMiseOeuvre, "ANNEE_MO", "2022") ? XlRgbColor.rgbLightBlue : XlRgbColor.rgbWhite; r.Value = action.Mt_2022; r = ws.Cells[n_ligne, 13]; //Année 2023 r.Interior.Color = Acces.Exister_Valeur(action.AnneeMiseOeuvre, "ANNEE_MO", "2023") ? XlRgbColor.rgbLightBlue : XlRgbColor.rgbWhite; r.Value = action.Mt_2023; r = ws.Cells[n_ligne, 14]; //Financement r.Value = action.CoutFinancier; if (action.Mt_Total != null) { if (action.Mt_Total.Length > 0) { r.Value += "\n TOTAL : " + action.Mt_Total + " k€"; } } r = ws.Cells[n_ligne, 15]; //TDS MF r.Value = Acces.Exister_Valeur(action.TSante, "TSANTE", "TS591") ? "X" : ""; r.Interior.Color = Acces.Exister_Valeur(action.Priorite_CTS, "PRIO_CTS_591", "", true) ? XlRgbColor.rgbLightBlue : XlRgbColor.rgbWhite; r = ws.Cells[n_ligne, 16]; //TDS Hainaut r.Value = Acces.Exister_Valeur(action.TSante, "TSANTE", "TS592") ? "X" : ""; r.Interior.Color = Acces.Exister_Valeur(action.Priorite_CTS, "PRIO_CTS_592", "", true) ? XlRgbColor.rgbLightBlue : XlRgbColor.rgbWhite; r = ws.Cells[n_ligne, 17]; //TDS 62 r.Value = Acces.Exister_Valeur(action.TSante, "TSANTE", "TS62") ? "X" : ""; r.Interior.Color = Acces.Exister_Valeur(action.Priorite_CTS, "PRIO_CTS_62", "", true) ? XlRgbColor.rgbLightBlue : XlRgbColor.rgbWhite; r = ws.Cells[n_ligne, 18]; //TDS 80 r.Value = Acces.Exister_Valeur(action.TSante, "TSANTE", "TS80") ? "X" : ""; r.Interior.Color = Acces.Exister_Valeur(action.Priorite_CTS, "PRIO_CTS_80", "", true) ? XlRgbColor.rgbLightBlue : XlRgbColor.rgbWhite; r = ws.Cells[n_ligne, 19]; //TDS 60 r.Value = Acces.Exister_Valeur(action.TSante, "TSANTE", "TS60") ? "X" : ""; r.Interior.Color = Acces.Exister_Valeur(action.Priorite_CTS, "PRIO_CTS_60", "", true) ? XlRgbColor.rgbLightBlue : XlRgbColor.rgbWhite; r = ws.Cells[n_ligne, 20]; //TDS 02 r.Value = Acces.Exister_Valeur(action.TSante, "TSANTE", "TS02") ? "X" : ""; r.Interior.Color = Acces.Exister_Valeur(action.Priorite_CTS, "PRIO_CTS_02", "", true) ? XlRgbColor.rgbLightBlue : XlRgbColor.rgbWhite; r = ws.Cells[n_ligne, 21]; //REGION r.Value = Acces.Exister_Valeur(action.TSante, "TSANTE", "REGION") ? "X" : ""; //Définition de l'ordre : différent d'action car la structure diffère avec les directions métier r = ws.Cells[n_ligne, 22]; PATIO.Classes.Action parent = (PATIO.Classes.Action)Acces.Trouver_Element(Acces.type_ACTION.id, l.element1_id); string ordre = parent.Code.Replace("ACT-", "") + "-" + string.Format("{0:x3}", l.ordre); r.Value = ordre; //r.Value = action.Code.Replace("OPE-", ""); Suite3 :; } //Tri des lignes Range r_data = ws.Range["A11:W" + n_ligne]; r_data.Sort(r_data.Columns[22, Type.Missing], Microsoft.Office.Interop.Excel.XlSortOrder.xlAscending); r_data.Cells.VerticalAlignment = XlVAlign.xlVAlignCenter; //Mise en forme { r_data.WrapText = true; //Renvoie à la ligne //Bordures Borders border = r_data.Borders; border.LineStyle = XlLineStyle.xlContinuous; border.Weight = 2d; border[XlBordersIndex.xlEdgeLeft].LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous; border[XlBordersIndex.xlEdgeTop].LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous; border[XlBordersIndex.xlEdgeBottom].LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous; border[XlBordersIndex.xlEdgeRight].LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous; //Alignement ws.Columns[1].HorizontalAlignment = XlHAlign.xlHAlignCenter; ws.Columns[4].HorizontalAlignment = XlHAlign.xlHAlignCenter; ws.Columns[6].HorizontalAlignment = XlHAlign.xlHAlignCenter; ws.Columns[7].HorizontalAlignment = XlHAlign.xlHAlignCenter; ws.Columns[8].HorizontalAlignment = XlHAlign.xlHAlignCenter; ws.Columns[9].HorizontalAlignment = XlHAlign.xlHAlignCenter; ws.Columns[10].HorizontalAlignment = XlHAlign.xlHAlignCenter; ws.Columns[11].HorizontalAlignment = XlHAlign.xlHAlignCenter; ws.Columns[12].HorizontalAlignment = XlHAlign.xlHAlignCenter; ws.Columns[13].HorizontalAlignment = XlHAlign.xlHAlignCenter; ws.Columns[15].HorizontalAlignment = XlHAlign.xlHAlignCenter; ws.Columns[16].HorizontalAlignment = XlHAlign.xlHAlignCenter; ws.Columns[17].HorizontalAlignment = XlHAlign.xlHAlignCenter; ws.Columns[18].HorizontalAlignment = XlHAlign.xlHAlignCenter; ws.Columns[19].HorizontalAlignment = XlHAlign.xlHAlignCenter; ws.Columns[20].HorizontalAlignment = XlHAlign.xlHAlignCenter; ws.Columns[21].HorizontalAlignment = XlHAlign.xlHAlignCenter; //Colonnes masquées ws.Columns["A"].Hidden = true; ws.Columns["V"].Hidden = true; } //Sauvegarde du fichier wb.SaveAs(fichier + ".xlsx"); wb.ExportAsFixedFormat(Microsoft.Office.Interop.Excel.XlFixedFormatType.xlTypePDF, fichier + ".pdf"); wb.Close(false); wk.Close(); //Fermeture de l'application Excel app.Quit(); app = null; if (OuvertureAuto) { OuvertureFichier(fichier + ".pdf"); } return(fichier); }
/// <summary> /// Repositionne les éléments selon la hiérarchie définie /// </summary> void CreeStructure() { int nbObjectif = 0; int nbAction = 0; int nbOpération = 0; int nbIndicateur = 0; //Affichage de la structure actuelle du plan d'actions tree.Nodes.Clear(); TreeNode NodG = new TreeNode() { Text = "Plan d'actions de " + plan.NiveauPlan, Name = Acces.type_PLAN.code + "-" + plan.ID, ImageIndex = 1, Tag = Acces.type_PLAN.id, }; NodG.Expand(); n = 1; //Placement des objectifs/sous-objectifs List <Lien> listeLien = Acces.Remplir_ListeLien(Acces.type_PLAN, plan.ID.ToString()); listeLien.Sort(); //On balaye la liste des éléments //On crée l'élément sous le parent foreach (var p in listeLien) { //Recherche du parent string Parent = Acces.Trouver_TableValeur(p.element1_type).Code + "-" + p.element1_id.ToString(); TreeNode NodParent = NodG; if (!(Parent == NodG.Name)) { TreeNode[] NodP = NodG.Nodes.Find(Parent, true); if (NodP.Length > 0) { NodParent = NodP[0]; } } string Enfant = Acces.Trouver_TableValeur(p.element2_type).Code + "-" + p.element2_id.ToString(); if (!(Enfant is null)) { Boolean Ajoute = true; //Création de l'élément enfant TreeNode NodEnfant = new TreeNode() { Name = Enfant, Tag = p, }; if (p.element2_type == Acces.type_OBJECTIF.id) //if (p.element2_type == Acces.Trouver_TableValeur_ID("TYPE_ELEMENT", p.element1_type.ToString())) { Objectif q = (Objectif)Acces.Trouver_Element(Acces.type_OBJECTIF.id, p.element2_id); if (!(q is null)) { NodEnfant.Text = q.Libelle; NodEnfant.Name = Acces.type_OBJECTIF.code + "-" + q.ID; //NodEnfant.ImageIndex = Donner_ImageIndex(Acces.type_OBJECTIF.id, p.element2_id); NodEnfant.ToolTipText = q.Code; nbObjectif++; } else { Console.Ajouter("[Objectif non trouvé] ID:" + p.element2_id + " Code :" + p.element2_code); } } if (p.element2_type == Acces.type_ACTION.id) { PATIO.Classes.Action q = (PATIO.Classes.Action)Acces.Trouver_Element(Acces.type_ACTION.id, p.element2_id); if (!optOpération.Checked) { Ajoute = (q.TypeAction == TypeAction.ACTION); } if (!(q is null)) { NodEnfant.Text = q.Libelle; NodEnfant.Name = Acces.type_ACTION.code + "-" + q.ID; //NodEnfant.ImageIndex = Donner_ImageIndex(Acces.type_ACTION.id, p.element2_id); //if (q.ActionPhare) { NodEnfant.ImageIndex = imgs[PosImageActionPhare].Id; } NodEnfant.ToolTipText = q.Code + " [" + p.ordre + "]"; if (q.TypeAction == TypeAction.ACTION) { nbAction++; } if (q.TypeAction == TypeAction.OPERATION) { nbOpération++; } } else { Console.Ajouter("[Action non trouvée] ID:" + p.element2_id + " CODE:" + p.element2_code); } } if (p.element2_type == Acces.type_INDICATEUR.id) { Ajoute = optIndicateur.Checked; Indicateur q = (Indicateur)Acces.Trouver_Element(Acces.type_INDICATEUR.id, p.element2_id); if (!(q is null)) { NodEnfant.Text = q.Libelle; NodEnfant.Name = Acces.type_INDICATEUR.code + "-" + q.ID; //NodEnfant.ImageIndex = Donner_ImageIndex(Acces.type_INDICATEUR.id, p.element2_id); NodEnfant.ToolTipText = q.Code; nbIndicateur++; } else { Console.Ajouter("[Indicateur non trouvée] ID:" + p.element2_id + " CODE:" + p.element2_code); } }