Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to Exclude Outlook Categories on ALT-Down for Outlook #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions source/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -827,11 +827,13 @@ private void btn_read_Outlook_Click(object sender, EventArgs e)
// check whether the user had the shift key pressed while calling this function and store this in a variable for further use
bool shiftpressed_for_custom_folder = false;
bool ctrlpressed_for_category_filter = false;
bool altpressed_for_category_exclusion_filter = false;

if ((Control.ModifierKeys & Keys.Shift) == Keys.Shift) { shiftpressed_for_custom_folder = true; }
if ((Control.ModifierKeys & Keys.Control) == Keys.Control) { ctrlpressed_for_category_filter = true; }
if ((Control.ModifierKeys & Keys.Alt) == Keys.Alt) { altpressed_for_category_exclusion_filter = true; }

ReadDataReturn myReadDataReturn = read_data_Outlook(shiftpressed_for_custom_folder, ctrlpressed_for_category_filter);
ReadDataReturn myReadDataReturn = read_data_Outlook(shiftpressed_for_custom_folder, ctrlpressed_for_category_filter, altpressed_for_category_exclusion_filter);

if (myReadDataReturn.duplicates != "") MessageBox.Show(myReadDataReturn.duplicates, "The following duplicate entries could not be imported");
update_datagrid();
Expand Down Expand Up @@ -1005,7 +1007,8 @@ private bool CheckOutlookVersion(string OL_version)

}

private ReadDataReturn read_data_Outlook(bool customfolder, bool categoryfilter)
private ReadDataReturn read_data_Outlook(bool customfolder, bool categoryfilter,
bool categoryExclusionFilter)
{
// read all information from Outlook and save all contacts that have at least one phone or fax number

Expand Down Expand Up @@ -1047,10 +1050,21 @@ private ReadDataReturn read_data_Outlook(bool customfolder, bool categoryfilter)
string my_category_filter = "";
if (categoryfilter == true)
{
SimpleInputDialog MySimpleInputDialog = new SimpleInputDialog("Please enter the string that must be present in the category field:", "Category Filter", false, false);
MySimpleInputDialog.ShowDialog();
my_category_filter = MySimpleInputDialog.resultstring;
MySimpleInputDialog.Dispose();
using (SimpleInputDialog mySimpleInputDialog = new SimpleInputDialog("Please enter the string that must be present in the category field:", "Category Filter", false, false))
{
mySimpleInputDialog.ShowDialog();
my_category_filter = mySimpleInputDialog.resultstring;
}
}

string my_category_exclusion_filter = "";
if (categoryExclusionFilter == true)
{
using (SimpleInputDialog mySimpleInputDialog = new SimpleInputDialog("Please enter the string that must *not* be present in the category field:", "Category Filter", false, false))
{
mySimpleInputDialog.ShowDialog();
my_category_exclusion_filter = mySimpleInputDialog.resultstring;
}
}

Microsoft.Office.Interop.Outlook.Items oContactItems = outlookFolder.Items;
Expand Down Expand Up @@ -1088,6 +1102,12 @@ private ReadDataReturn read_data_Outlook(bool customfolder, bool categoryfilter)
continue; // abort this foreach loop and switch to the next contact
}

// if a category exclusion filter has been selected, we now check this first in order to save time (we can skip the contact data transfer if the excluded category is present)
if (my_category_exclusion_filter != "" && categories.Contains(my_category_exclusion_filter))
{
continue;
}

GroupDataContact myContact = new GroupDataContact();
myContact.lastname = (myContactItem.LastName == null) ? string.Empty : myContactItem.LastName;
myContact.firstname = (myContactItem.FirstName == null) ? string.Empty : myContactItem.FirstName;
Expand Down