| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 
 |         private delegate Hashtable GetListeDelg(Form frm, string ficXls, string xlsFeuille, string xlsColId, string xlsColLib, string xlsLigne1, string texte, string regexId = "");
        private static Hashtable GetListe(frmMain frm, string ficXls, string xlsFeuille, string xlsColId, string xlsColLib, string xlsLigne1, string texte, string regexId="") {
            /*if (InvokeRequired) { // Gérer les accès concurentiels.
                return (Hashtable)Invoke(new GetListeDelg(GetListe), frm, ficXls, xlsFeuille, xlsColId, xlsColLib, xlsLigne1, texte, regexId);
            } // */
            Hashtable ret = new Hashtable();
            int tmp = 0;
            if (!string.IsNullOrEmpty(ficXls.Trim()) && (File.Exists(ficXls)) && (int.TryParse(xlsLigne1, out tmp))) {
                //try {
                    UtilsExcel ue = new UtilsExcel();
                    /*if (frm.tssLabel.GetCurrentParent().InvokeRequired) { // Gérer les accès concurentiels.
                        frm.tssLabel.GetCurrentParent().Invoke(new UtilsControls.setControlStr(UtilsControls.ctrlAddText), frm.tssLabel, texte);
                    } else
                        frm.tssLabel.Text += texte; // */
                    using (var pb = new ProgressBar()) {
                        pb.Name = "pb" + Guid.NewGuid().ToString().Substring(0, 8).Replace("-", "");
                        if (frm.txtInfos.InvokeRequired) { // Gérer les accès concurentiels.
                            frm.txtInfos.Invoke(new UtilsControls.AddControl(UtilsControls.CtlAddControl), frm.txtInfos, pb);
                        } else
                            pb.Parent = frm.txtInfos;
                        Application.DoEvents();
                        if (pb.InvokeRequired) { // Gérer les accès concurentiels.
                            pb.Invoke(new UtilsControls.setControlDock(UtilsControls.ctrlDock), pb, DockStyle.Top);
                        } else
                            pb.Dock = DockStyle.Top;
                        ret = ue.GetListe(ficXls, xlsFeuille, xlsColId, xlsColLib, tmp, pb, regexId); //tssPbMain
                    }
                    string msg = (string.IsNullOrEmpty(ue.msgErr)) ? 
                        "OK. " + frm.tssLabel.Text + ". " + ret.Count + " éléments intégrés." + Environment.NewLine + ue.msgInfo:
                        "KO. " + frm.tssLabel.Text + ". " + ue.msgErr + Environment.NewLine;
                        if (frm.txtInfos.InvokeRequired) { // Gérer les accès concurentiels.
                            frm.txtInfos.Invoke(new UtilsControls.setControlStr(UtilsControls.ctrlAddText), frm.txtInfos, msg);
                        } else
                            frm.txtInfos.Text += msg;
                /*} catch (Exception ex) {
                    Log.LogWriter.Instance.WriteException(ex);
                    Log.LogWriter.Instance.FlushLog();
                } // */
            } // */
            return ret;
        }
 
        static Hashtable htUd = null;
        static Hashtable htCpm = null;
        static Hashtable htItem = null;
        static Hashtable htSpm = null;
        static Hashtable htSol = null;
        static Hashtable htEIPC = null;
        static Hashtable htSbA = null;
        static Hashtable htSbB = null;
        private void btnVal_Click(object sender, EventArgs e) {
            canChangePc = true;
            txtInfos.Text = "";
            tcMain.SelectedIndex = tcMain.SelectedIndex + 1;
            int nbCoeurs = 2;
            int.TryParse(Environment.GetEnvironmentVariable("NUMBER_OF_PROCESSORS"), out nbCoeurs);
            Parallel.Invoke(new ParallelOptions { MaxDegreeOfParallelism = nbCoeurs },  // Task.Factory.StartNew(() => 
                () => { htUd = GetListe(this, txtFicXlsUd.Text, txtXlsFllUd.Text, txtXlsRefUD.Text, txtXlsLibUD.Text, txtXlsLn1UD.Text, "Lecture de la liste 0"); }, 
                () => { htCpm = GetListe(this, txtFicXlsCPM.Text, txtXlsFllCPM.Text, txtXlsRefCPM.Text, txtXlsLibCPM.Text, txtXlsLn1CPM.Text, "Lecture de la liste 1"); },
                () => { htItem = GetListe(this, txtFicXlsITEM.Text, txtXlsFllITEM.Text, txtXlsRefITEM.Text, txtXlsLibITEM.Text, txtXlsLn1ITEM.Text, "Lecture de la liste 2"); },
                () => { htSpm = GetListe(this, txtFicXlsSPM.Text, txtXlsFllSPM.Text, txtXlsRefSPM.Text, txtXlsLibSPM.Text, txtXlsLn1SPM.Text, "Lecture de la liste 3"); },
                () => { htSol = GetListe(this, txtFicXlsSOL.Text, txtXlsFllSOL.Text, txtXlsRefSOL.Text, txtXlsLibSOL.Text, txtXlsLn1SOL.Text, "Lecture de la liste 4"); },
                () => { htEIPC = GetListe(this, txtFicXlsEIPCA.Text, txtXlsFllEIPCA.Text, txtXlsRefEIPCA.Text, txtXlsLibEIPCA.Text, txtXlsLn1EIPCA.Text, "Lecture de la liste 5"); },
                () => { htSbA = GetListe(this, txtFicXlsSBA.Text, txtXlsFllSBA.Text, txtXlsRefSBA.Text, txtXlsLibSBA.Text, txtXlsLn1SBA.Text, "Lecture de la liste des 6"); },
                () => { htSbB = GetListe(this, txtFicXlsSBB.Text, txtXlsFllSBB.Text, txtXlsRefSBB.Text, txtXlsLibSBB.Text, txtXlsLn1SBB.Text, "Lecture de la liste des 7"); }
            ); // */
            tssLabel.Text = "Traitement des XML";
            Traite(txtChemRepUd.Text, txtFicXsd.Text, htUd, htCpm, htItem, htSpm, htSol, htEIPC, htSbA, htSbB, txtInfos, tssPbMain.ProgressBar);
            tssLabel.Text = "Traitement terminé";
        }
    class UtilsControls {
 
        public delegate void AddControl(Control ctlParent, Control ctlEnfant); // Modèle de fonction (prototype) pour l'instanciation.
        public static void CtlAddControl(Control ctlParent, Control ctlEnfant) {
            try {
                ctlEnfant.Parent = ctlParent;
            } catch (Exception ex) {
                Log.LogWriter.Instance.WriteException(ex);
                Log.LogWriter.Instance.FlushLog();
            }
        }
 
        public delegate void setControlDock(Control ctl, DockStyle ds); // Modèle de fonction (prototype) pour l'instanciation.
        public static void ctrlDock(Control ctl, DockStyle ds) {
            ctl.Dock = ds;
        }
 
        public delegate void setControlStr(Control ctl, string str); // Modèle de fonction (prototype) pour l'instanciation.
        public static void ctrlAddText(Control ctl, string str) {
            Application.DoEvents();
            ctl.Text += str;
        }
 
        public delegate void setPbInc(ProgressBar ctl, int cmp, int total);
        public static void ProgBarInc(ProgressBar pb, int cmp, int total) { // ToolStripProgressBar
            pb.Value = Math.Min(((int)(((double)cmp / total) * 100)), 100);
        }
 
    } | 
Partager