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
|
public void ficheClientOutlook(string num)
{
try
{
Outlook.Application app = new Outlook.ApplicationClass();//On crée un objet Outlook
Outlook.NameSpace NS = app.GetNamespace("MAPI");
Outlook.MAPIFolder objFolder = NS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);
Outlook.Items contactItems = objFolder.Items;//On récupère les contacts dans le outlook ouvert
string nmodif=num;
if ((nmodif.Length == 10) &&
nmodif.StartsWith("0") &&
(nmodif.Substring(1,1) != "0") &&
(nmodif.Substring(1,1)!= "7") &&
(nmodif.Substring(1,1) != "9"))
{
nmodif = nmodif.Insert(0,"(");
nmodif = nmodif.Insert(3,")");
nmodif = nmodif.Insert(4," ");
nmodif = nmodif.Insert(7," ");
nmodif = nmodif.Insert(10," ");
nmodif = nmodif.Insert(13," ");
}
num = nmodif;//on met le numéro dans le même format que Outlook
Outlook.Items contact_filtre = contactItems.Restrict(String.Format("[AssistantTelephoneNumber]='{0}' or [Business2TelephoneNumber]='{0}' or [BusinessTelephoneNumber]='{0}' or [HomeTelephoneNumber]='{0}' or [CompanyMainTelephoneNumber]='{0}' or [Home2TelephoneNumber]='{0}' or [HomeTelephoneNumber]='{0}' or [MobileTelephoneNumber]='{0}' or [OtherTelephoneNumber]='{0}' or [PrimaryTelephoneNumber]='{0}' or [RadioTelephoneNumber]='{0}' or [TTYTDDTelephoneNumber]='{0}'",num));
//On filtre les contacts Outlook et en fontion du nombre de reponse on les affiche différement
switch (contact_filtre.Count)
{
case 0:
break;
case 1:
Outlook.ContactItem contact = (Outlook.ContactItem)contact_filtre.GetLast();
contact.Display(false);
break;
default :
ComboBox cb = new ComboBox();
foreach (Outlook.ContactItem contact_multi in contact_filtre)
{
cb.Items.Add(contact_multi.FullName);
}
Form frm = new frmContacts(cb, contactItems);//on crée un nouveau formulaire permettant de choisir le contact à afficher
frm.Show();
break;
}
}
catch (Exception exc)
{
MessageBox.Show(this,"Action impossible : Outlook indisponible : "+exc.Message,"ClickTel");
return;
}
} |
Partager