1 2 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 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320
   |  
 
 public partial class SendMail : ServiceBase
    {
        public SendMail()
        {    
                List<C_Q_NCONF> oListeQNConfRelByFournST = new List<C_Q_NCONF>();// Liste des non conformités à relancer par fournisseur
                Decimal cdqnconf = new Decimal();//Identifiant de la FNC en cours
                String fncPage = "";//Lien vers la fnc 
                int trouve = 0;
                List<String> ListAddrMail = new List<string>();
                bool mailSend = false;
                AppSettingsReader appSettingsReader = new AppSettingsReader();
                ResourceManager rm = new ResourceManager("WindowsService1.ResourceEnvMail", Assembly.GetExecutingAssembly());
                CultureInfo fr = new CultureInfo("fr");
                CultureInfo ci = new CultureInfo("en");
 
     while (Thread.CurrentThread.IsAlive)
               {
                    //Boucle de temporisation, attente de l'heure de premier lancement du thread
           while (DateTime.Now.TimeOfDay.CompareTo(new TimeSpan(9,42, 0)) < 0)
                 { }
                // Liste des fnc qui n'ont pas été diffusées
                List<C_Q_NCONF> olistCQNConf = C_Q_NCONF.ListQNConfDateCreatEgDateJour();
 
                // Liste des fnc qui ont une date de relance égale à celle du jour
                List<C_Q_NCONF> oListQNConfDateRelEgDateJour = C_Q_NCONF.ListQNConfDateRelEgDateJour();
 
                // Liste des fnc ayant été modifié par le sous-traitant ce jour.
                List<C_Q_NCONF> oListQNConfModif = C_Q_NCONF.ListQNCONFModif();
 
                {
                    //Envoi des mails concernant les nouvelles FNC
                    foreach (C_Q_NCONF oQnconf in olistCQNConf)
                    {
                        //Déterminons la langue des email
                        if (oQnconf.Ref_FOURN_ST_For_CD_FOURN_ST.PAYS.Value == "FRANCE")
                        {
                            ci = new CultureInfo("fr");
                        }
                        else
                        {
                            ci = new CultureInfo("en");
                        }
 
                        //  if (oQnconf.Ref_FOURN_ST_For_CD_FOURN_ST.NOM.Value == "ESKULANAK")
                        {
                            // Adrresse e-mail du contact sous-traitant de la FNC
                            List<String> listTempMail = oQnconf.getEmailAdrressFstContact_BY_CD_Q_NCONF();
 
                            foreach (String addrMail in listTempMail)
                            {
                                foreach (String addr in ListAddrMail)
                                {
                                    if (addr == addrMail)
                                    {
                                        trouve = 1;
                                    }
                                }
                                if (trouve == 0)
                                    ListAddrMail.Add(addrMail);
                                else trouve = 0;
                            }
                            // Adresse e-mail du contrôleur responsable de la FNC
                            String AddrMailControleur = oQnconf.getEmailAdrressControleurResp_BY_CD_Q_NCONF();
 
                            //Identité contrôleur
                            String identiteControl = oQnconf.getIdentiteControleurResp_BY_CD_Q_NCONF();
 
                            //Création du lien vers la FNC concernée
                            cdqnconf = oQnconf.CD_Q_NCONF.Value;
 
                            //fncPage = "<a href=http://localhost:1767/AtlasWebSite1/conformite/FNC.aspx?id=" + cdqnconf + ">" + cdqnconf + "</a>";
                            fncPage = String.Format("<a href={0}{1}>{1}</a>", appSettingsReader.GetValue("URL_FNC", typeof(string)), cdqnconf);
 
                            //Création du Mail de signification d'une nouvelle FNC
                            MailManagement mail;
                            mail = new MailManagement();
 
                            //Adresse e-mail de l'expéditeur
                            mail.From = String.Format("{0}", appSettingsReader.GetValue("FROM", typeof(string)));
 
                            //Adresse e-mail du destinataire  
                            //S'il n'y a pas de contact dans helios
                            if (ListAddrMail.Count == 0)
                            {
                                mail.To = AddrMailControleur;
 
                                //Sujet du mail
                                mail.Subject = String.Format("{0}", rm.GetString("SubjectNoCtact", fr));
 
                                mail.Body = String.Format("{0}{1}", rm.GetString("BodyNoCtact", fr), rm.GetString("SubjectBodyNoCtact", ci));
 
                            }
                            else
                            {
                                foreach (String AddrMail in ListAddrMail)
                                {
                                    mail.To = mail.To + AddrMail + ";";
                                }
 
                                //Sujet du mail
                                mail.Subject = rm.GetString("Subject", ci);
 
                                mail.Body = "";
                            }
 
                            mail.To = "xlasbats@potez.com";
 
                            //Corps du mail
 
                            mail.Body = String.Format("{0}{1}{2}{3}{4}{5}", mail.Body, rm.GetString("BodyDiff1", ci), fncPage, rm.GetString("BodyDiff2", ci), AddrMailControleur, rm.GetString("BodyDiff3", ci));
 
                            //Définition du server mail
                            mail.SmtpServer = String.Format("{0}", appSettingsReader.GetValue("SMTP_SERVER", typeof(string)));
 
                            //Envoi du mail
                            mailSend = mail.IsMailSent();
 
                            if (mailSend == true)
                            {
                                //Passage de la FNC en statut diffusée
                                //     oQnconf.STATUT.Value = "D";
                            }
                        }
                    }
 
                    //Envoi du mail de relance
                    //Chaque fin de semaine un mail est envoyé avec la lsite des liens vers toutes les FNC à relancer
                    if (DateTime.Now.DayOfWeek == (DayOfWeek)(4))
                    {
                        //Identifiant du sous_traitant concerné
                        Decimal cdFournSt = oListQNConfDateRelEgDateJour[0].CD_FOURN_ST.Value;
 
                        //Parcours de la liste des FNC à relancer
                        foreach (C_Q_NCONF oQnconfRel in oListQNConfDateRelEgDateJour)
                        {
                            if (oQnconfRel.Ref_FOURN_ST_For_CD_FOURN_ST.PAYS.Value == "FRANCE")
                            {
                                ci = new CultureInfo("fr");
                            }
                            else
                            {
                                ci = new CultureInfo("en");
                            }
                            //Adresse mail contact fournisseur
                            List<String> listTempMail = oQnconfRel.getEmailAdrressFstContact_BY_CD_Q_NCONF();
 
                            foreach (String addrMail in listTempMail)
                            {
                                foreach (String addr in ListAddrMail)
                                {
                                    if (addr == addrMail)
                                    {
                                        trouve = 1;
                                    }
                                }
                                if (trouve == 0)
                                    ListAddrMail.Add(addrMail);
                                else
                                    trouve = 0;
                            }
 
                            //Adresse mail contrôleur responsable
                            String AddrMailControleur = oQnconfRel.getEmailAdrressControleurResp_BY_CD_Q_NCONF();
 
                            //Identité contrôleur
                            String identiteControl = oQnconfRel.getIdentiteControleurResp_BY_CD_Q_NCONF();
 
                            //Si le fournisseur reste le même on rajoute la FNC à la liste
                            if (oQnconfRel.CD_FOURN_ST.Value == cdFournSt)
                            {
                                oListeQNConfRelByFournST.Add(oQnconfRel);
                            }
                            //sinon on envoi le mail et l'identifiant fournisseur est mis à jour
                            else
                            {
                                //Mise à jour Identifiant fournisseur
                                cdFournSt = oQnconfRel.CD_FOURN_ST.Value;
 
                                //  if (oListeQNConfRelByFournST[0].Ref_FOURN_ST_For_CD_FOURN_ST.NOM.Value == "ESKULANAK")
                                {
                                    String liens = "";
 
                                    List<String> listfncpage = new List<String>();//liens vers les différentes FNC
 
                                    //Création de la liste de lien
                                    foreach (C_Q_NCONF oQnconfRelByFournSt in oListeQNConfRelByFournST)
                                    {
                                        listfncpage.Add(String.Format("<a href={0}{1}>{1}</a>", appSettingsReader.GetValue("URL_FNC", typeof(string)), oQnconfRelByFournSt.CD_Q_NCONF.Value));
                                    }
 
                                    foreach (String nfnc in listfncpage)
                                    {
                                        liens += nfnc.ToString() + ", ";
                                    }
 
 
                                    //Création du mail
                                    MailManagement mail;
                                    mail = new MailManagement();
 
                                    //Adresse mail expéditeur
                                    mail.From = String.Format("{0}", appSettingsReader.GetValue("FROM", typeof(string)));
 
                                    if (ListAddrMail.Count == 0)
                                    {
                                        mail.To = AddrMailControleur;
 
                                        //Sujet du mail
                                        mail.Subject = String.Format("{0}", rm.GetString("SubjectNoCtact", fr));
 
                                        mail.Body = String.Format("{0}{1}", rm.GetString("BodyNoCtact", fr), rm.GetString("SubjectBodyNoCtactRel", ci));
                                    }
                                    else
                                    {
                                        //Adresse mail destinataire
                                        foreach (String AddrMail in ListAddrMail)
                                        {
                                            mail.To = mail.To + AddrMail + ";";
                                        }
 
                                        //Sujet du mail
                                        mail.Subject = String.Format("{0}", rm.GetString("SubjectRel", ci));
                                        mail.Body = "";
                                    }
 
                                    mail.To = "xlasbats@potez.com; ";
 
                                    //Corps mail
                                    mail.Body = String.Format("{0}{1}{2}{3}", mail.Body, rm.GetString("BodyRel1", ci), liens, rm.GetString("BodyRel2", ci));
 
                                    //Définition du server
                                    mail.SmtpServer = String.Format("{0}", appSettingsReader.GetValue("SMTP_SERVER", typeof(string)));
 
                                    //Envoi Mail
                                    mail.IsMailSent();
 
                                    ListAddrMail.Clear();
 
                                }
                                oListeQNConfRelByFournST.Clear();
                                oListeQNConfRelByFournST.Add(oQnconfRel);
                            }
                        }
                    }
 
                    //Envoie mmail au contrôleur responsable, lorsque la fnc est modifiée.
                    if (oListQNConfModif.Count > 0)
                    {
                        foreach (C_Q_NCONF oQnconfModif in oListQNConfModif)
                        {
                            //Déterminons la langue des email
 
                            if (oQnconfModif.Ref_FOURN_ST_For_CD_FOURN_ST.PAYS.Value == "FRANCE")
                            {
                                ci = new CultureInfo("fr");
                            }
                            else
                            {
                                ci = new CultureInfo("en");
                            }
                            //   if (oQnconfModif.Ref_FOURN_ST_For_CD_FOURN_ST.NOM.Value == "ESKULANAK")
                            {
                                //Adresse mail contrôleur reponsable 
                                String AddrMailControleur = oQnconfModif.getEmailAdrressControleurResp_BY_CD_Q_NCONF();
 
                                //Identifiant FNC en cours
                                cdqnconf = oQnconfModif.CD_Q_NCONF.Value;
 
                                //Nom du sous traitant
                                String nomFourn = oQnconfModif.Ref_FOURN_ST_For_CD_FOURN_ST.NOM.Value;
 
                                //Programme auquel appartient la FNC
                                String Programme = oQnconfModif.Ref_OFS_PHASE_For_CD_OFS_CONCERNE_CD_GAMME_N_LIEN_CD_PHASE.Ref_OFS_CDC_For_CD_CDC.Ref_OFS_For_CD_OFS.Ref_OFS_ARTICLE_For_CD_OFS_ARTICLE.ARTI_FAMILLE.Value;
 
                                //Lien vers la FNC correspondante
                                fncPage = String.Format("<a href={0}{1}>{1}</a>", appSettingsReader.GetValue("URL_FNC", typeof(string)), cdqnconf);
 
                                //Création du mail
                                MailManagement mail;
                                mail = new MailManagement();
 
                                //Adresse expediteur
                                mail.From = String.Format("{0}", appSettingsReader.GetValue("FROM", typeof(string)));
 
                                //Adresse destinataire
                                if (Programme == "E2C")
                                {
                                    mail.To = "dducamin@potez.com";
                                }
                                else
                                {
                                    mail.To = AddrMailControleur;
                                }
                                mail.To = "xlasbats@potez.com";
 
                                //Sujet mail
                                mail.Subject = String.Format("{0}", rm.GetString("SubjectModif", fr));
 
 
                                mail.Body = String.Format("{0}{1}{2}{3}{4}", rm.GetString("BodyModif1"), nomFourn, rm.GetString("BodyModif2"), fncPage, rm.GetString("BodyModif3"));
 
                                //définition server mail
                                mail.SmtpServer = String.Format("{0}", appSettingsReader.GetValue("SMTP_SERVER", typeof(string)));
 
                                //Envoi mail
                                mailSend = mail.IsMailSent();
                                if (mailSend == false)
                                {
                                    oQnconfModif.DATE_MODIF.Value.AddDays(1);
                                }
                            }
                        }
                    }
                }
                //Mise en attente du thread pendant 24h
            // Thread.Sleep((23 * 60 * 60 * 1000) + (59 * 60 * 1000));
           }
        } | 
Partager