Community
Showing results for 
Search instead for 
Do you mean 
Reply

Giving back to the Community - Sample Code - Folders, DropBox, and Contact Types

Copper Super Contributor
Posts: 478
Country: Australia

Giving back to the Community - Sample Code - Folders, DropBox, and Contact Types

Hi all

 

Over the last year i have been writing some code to customise my Act and received a lot of help from the Act Community particularly wellmet, jimdurkin, sam_raikes, vivek, knif and several others. So to help other newbies i will post my code here.

 

Before i do you must understand i am not a coder to claim such would be insulting to those listed above, i only dabble, so my code is not sexy or clean, it is what it is.

 

Another more recent project was to sort client documents out that i have stored on DropBox, so problem here was how to create a new windows folder for a contact within their own folder system, and with many types of contacts that got a little confusing and tricky, the code below is the folder create button along with the Dropbox sort and create code that is launched from many locations

 

 

    [Act.Shared.ComponentModel.CustomControl(true)]

    // Folder Creator Button
    class FolderCButton : System.Windows.Forms.Button
    {
        protected override void OnClick(System.EventArgs e)
        {
            try
            {

                // This function runs when a Client Contact record is changed
                //
                // 1) Checks Dropbox directories and if any standard options are missing it will create new directory
                // 2) Runs time card function if last edit date is more than 7 days old
                //


                //Get current contact
                Contact c = Act.UI.ActApplication.Instance.ApplicationState.CurrentContact;


                // Folder Checking Method
                // Checks and creates missing folders based on the client type group

                //Get current contact group
                string ContactRecordType = c.Fields["TBL_CONTACT.INSTANTMSGID", true].ToString();

                string clast = c.LastName;
                string cfirst = c.FirstName;
                DateTime now = DateTime.Now;

                //Get name of the new folder
                ContactFieldDescriptor NewFoldNameFD = null;
                NewFoldNameFD = Act.UI.ActApplication.Instance.ActFramework.Contacts.GetContactFieldDescriptor("CUST_ContactTable1_090144.CUST_NewFolderName_121242291", true);
                string NewFoldName = NewFoldNameFD.GetValue(c).ToString();

                //List out the note types
                Act.Framework.Notes.NoteType[] noteTypes = Act.UI.ActApplication.Instance.ActFramework.Notes.GetNoteTypes();

                NewFoldNameFD.SetValue(c, " ");

                if (NewFoldName != null)
                {

                    // Folder Checking Method
                    // Checks and creates missing folders based on the client type group

                    //Get current contact group
                    string newpath1 = clast + ", " + cfirst + "/" + NewFoldName;
                    var instance = new DropBoxFolderCheker();
                    instance.cSort(ContactRecordType, newpath1);

                }
                else
                {
                    MessageBox.Show("The New Folder Name has not been entered or saved.", "Error - Missing Data", MessageBoxButtons.OK, MessageBoxIcon.Information);

                }
                c.Update();

            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message, "{0} Exception caught - Folder Creator Button");
            }

        }
    }

    class DropBoxFolderCheker : System.Windows.Forms.Button
    {

        public void dbFolders(string dbase, string ContactRecordType)
        {
            try
            {

                //Get current contact
                Contact c = Act.UI.ActApplication.Instance.ApplicationState.CurrentContact;

                //List out the note types
                Act.Framework.Notes.NoteType[] noteTypes = Act.UI.ActApplication.Instance.ActFramework.Notes.GetNoteTypes();

                DateTime now = DateTime.Now;

                // Standard list of directories for each client type
                string clast = c.LastName;
                string cfirst = c.FirstName;
                string fullpath2 = dbase + clast + ", " + cfirst;
                string fullpath3 = dbase + clast + ", " + cfirst + "/SOA";
                string fullpath4 = dbase + clast + ", " + cfirst + "/ID Docs";
                string fullpath5 = dbase + clast + ", " + cfirst + "/Archive";
                string fullpath6 = dbase + clast + ", " + cfirst + "/Research";
                string fullpath12 = dbase + clast + ", " + cfirst + "/ROA";
                string fullpath13 = dbase + clast + ", " + cfirst + "/FDS";

                string fullpath7 = dbase + clast + ", " + cfirst + "/Bank Account - Macquarie";
                string fullpath8 = dbase + clast + ", " + cfirst + "/";
                string fullpath9 = dbase + clast + ", " + cfirst + "/SMSF Docs - Original";
                string fullpath10 = dbase + clast + ", " + cfirst + "/Strategy Reports";
                string fullpath11 = dbase + clast + ", " + cfirst + "/SMSF Docs - Misc";
                string fullpath14 = dbase + clast + ", " + cfirst + "/SMSF Docs - ASIC";

                if (Directory.Exists(fullpath2))
                {

                    if (Directory.Exists(fullpath3))
                    {

                    }
                    else
                    {
                        Directory.CreateDirectory(fullpath3);
                        //Set a new Note
                        Act.UI.ActApplication.Instance.ActFramework.Notes.CreateNote(noteTypes[0], "New storage folder created under the " + c.FirstName + " " + c.LastName + "'s file \n(called " + fullpath3 + ") ", now, false, c);
                    }

                    if (Directory.Exists(fullpath4))
                    {

                    }
                    else
                    {
                        Directory.CreateDirectory(fullpath4);
                        //Set a new Note
                        Act.UI.ActApplication.Instance.ActFramework.Notes.CreateNote(noteTypes[0], "New storage folder created under the " + c.FirstName + " " + c.LastName + "'s file \n(called " + fullpath4 + ") ", now, false, c);
                    }

                    if (Directory.Exists(fullpath5))
                    {

                    }
                    else
                    {
                        Directory.CreateDirectory(fullpath5);
                        //Set a new Note
                        Act.UI.ActApplication.Instance.ActFramework.Notes.CreateNote(noteTypes[0], "New storage folder created under the " + c.FirstName + " " + c.LastName + "'s file \n(called " + fullpath5 + ") ", now, false, c);
                    }

                    if (Directory.Exists(fullpath6))
                    {

                    }
                    else
                    {
                        Directory.CreateDirectory(fullpath6);
                        //Set a new Note
                        Act.UI.ActApplication.Instance.ActFramework.Notes.CreateNote(noteTypes[0], "New storage folder created under the " + c.FirstName + " " + c.LastName + "'s file \n(called " + fullpath6 + ") ", now, false, c);
                    }

                    if (Directory.Exists(fullpath12))
                    {

                    }
                    else
                    {
                        Directory.CreateDirectory(fullpath12);
                        //Set a new Note
                        Act.UI.ActApplication.Instance.ActFramework.Notes.CreateNote(noteTypes[0], "New storage folder created under the " + c.FirstName + " " + c.LastName + "'s file \n(called " + fullpath12 + ") ", now, false, c);
                    }

                    if (Directory.Exists(fullpath13))
                    {

                    }
                    else
                    {
                        Directory.CreateDirectory(fullpath13);
                        //Set a new Note
                        Act.UI.ActApplication.Instance.ActFramework.Notes.CreateNote(noteTypes[0], "New storage folder created under the " + c.FirstName + " " + c.LastName + "'s file \n(called " + fullpath13 + ") ", now, false, c);
                    }

                }
                else
                {
                    // Create client directory first before all others
                    Directory.CreateDirectory(fullpath2);

                    Directory.CreateDirectory(fullpath3);
                    Directory.CreateDirectory(fullpath4);
                    Directory.CreateDirectory(fullpath5);
                    Directory.CreateDirectory(fullpath6);
                    Directory.CreateDirectory(fullpath12);
                    Directory.CreateDirectory(fullpath13);
                    //Set a new Note
                    Act.UI.ActApplication.Instance.ActFramework.Notes.CreateNote(noteTypes[0], "New storage folder created under the " + c.FirstName + " " + c.LastName + "'s file \n(called " + fullpath2 + "\n" + fullpath3 + "\n" + fullpath4 + "\n" + fullpath5 + "\n" + fullpath6 + "\n" + fullpath12 + "\n" + fullpath13 + ") ", now, false, c);

                }

                if (ContactRecordType == "SMSF" || ContactRecordType == "Trust")
                {
                    if (Directory.Exists(fullpath7))
                    {

                    }
                    else
                    {
                        Directory.CreateDirectory(fullpath7);
                        //Set a new Note
                        Act.UI.ActApplication.Instance.ActFramework.Notes.CreateNote(noteTypes[0], "New storage folder created under the " + c.FirstName + " " + c.LastName + "'s file \n(called " + fullpath7 + ") ", now, false, c);
                    }

                    if (Directory.Exists(fullpath8))
                    {

                    }
                    else
                    {
                        Directory.CreateDirectory(fullpath8);
                        //Set a new Note
                        Act.UI.ActApplication.Instance.ActFramework.Notes.CreateNote(noteTypes[0], "New storage folder created under the " + c.FirstName + " " + c.LastName + "'s file \n(called " + fullpath8 + ") ", now, false, c);
                    }
                    if (Directory.Exists(fullpath9))
                    {

                    }
                    else
                    {
                        Directory.CreateDirectory(fullpath9);
                        //Set a new Note
                        Act.UI.ActApplication.Instance.ActFramework.Notes.CreateNote(noteTypes[0], "New storage folder created under the " + c.FirstName + " " + c.LastName + "'s file \n(called " + fullpath9 + ") ", now, false, c);
                    }
                    if (Directory.Exists(fullpath10))
                    {

                    }
                    else
                    {
                        Directory.CreateDirectory(fullpath10);
                        //Set a new Note
                        Act.UI.ActApplication.Instance.ActFramework.Notes.CreateNote(noteTypes[0], "New storage folder created under the " + c.FirstName + " " + c.LastName + "'s file \n(called " + fullpath10 + ") ", now, false, c);
                    }
                    if (Directory.Exists(fullpath11))
                    {

                    }
                    else
                    {
                        Directory.CreateDirectory(fullpath11);
                        //Set a new Note
                        Act.UI.ActApplication.Instance.ActFramework.Notes.CreateNote(noteTypes[0], "New storage folder created under the " + c.FirstName + " " + c.LastName + "'s file \n(called " + fullpath11 + ") ", now, false, c);
                    }
                    if (Directory.Exists(fullpath14))
                    {

                    }
                    else
                    {
                        Directory.CreateDirectory(fullpath14);
                        //Set a new Note
                        Act.UI.ActApplication.Instance.ActFramework.Notes.CreateNote(noteTypes[0], "New storage folder created under the " + c.FirstName + " " + c.LastName + "'s file \n(called " + fullpath14 + ") ", now, false, c);
                    }

                }

            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message, "{0} Exception caught - Buttons - Dropbox Folder Creator");
            }
        }

        public void cSort(string ContactRecordType, string newpath1)
        {
            try
            {

                //Get current contact
                Contact c = Act.UI.ActApplication.Instance.ApplicationState.CurrentContact;
                DateTime now = DateTime.Now;

                //List out the note types
                Act.Framework.Notes.NoteType[] noteTypes = Act.UI.ActApplication.Instance.ActFramework.Notes.GetNoteTypes();

                if (ContactRecordType == "Client")
                {
                    string dbase = "C:/Users/Jason/Dropbox/JDFPBusiness/Client Files - Client/";
                    c.Fields["CUST_ContactTable1_090144.CUST_DropboxPath_060843623", true] = dbase;

                    if (newpath1 != null)
                    {
                        string newpath2 = dbase + newpath1;
                        Directory.CreateDirectory(newpath2);
                        Act.UI.ActApplication.Instance.ActFramework.Notes.CreateNote(noteTypes[0], "New storage folder created under the " + c.FirstName + " " + c.LastName + "'s file \n(called " + newpath2 + ") ", now, false, c);
                    }

                    dbFolders(dbase, ContactRecordType);
                }
                if (ContactRecordType == "Refer")
                {
                    string dbase = "C:/Users/Jason/Dropbox/JDFPBusiness/Client Files - Refer/";
                    c.Fields["CUST_ContactTable1_090144.CUST_DropboxPath_060843623", true] = dbase;

                    if (newpath1 != null)
                    {
                        string newpath2 = dbase + newpath1;
                        Directory.CreateDirectory(newpath2);
                        Act.UI.ActApplication.Instance.ActFramework.Notes.CreateNote(noteTypes[0], "New storage folder created under the " + c.FirstName + " " + c.LastName + "'s file \n(called " + newpath2 + ") ", now, false, c);
                    }

                    dbFolders(dbase, ContactRecordType);
                }
                if (ContactRecordType == "Orphaned")
                {
                    string dbase = "C:/Users/Jason/Dropbox/JDFPBusiness/Client Files - Orphaned/";
                    c.Fields["CUST_ContactTable1_090144.CUST_DropboxPath_060843623", true] = dbase;

                    if (newpath1 != null)
                    {
                        string newpath2 = dbase + newpath1;
                        Directory.CreateDirectory(newpath2);
                        Act.UI.ActApplication.Instance.ActFramework.Notes.CreateNote(noteTypes[0], "New storage folder created under the " + c.FirstName + " " + c.LastName + "'s file \n(called " + newpath2 + ") ", now, false, c);
                    }

                    dbFolders(dbase, ContactRecordType);
                }
                if (ContactRecordType == "Family")
                {
                    string dbase = "C:/Users/Jason/Dropbox/JDFPBusiness/Client Files - Family/";
                    c.Fields["CUST_ContactTable1_090144.CUST_DropboxPath_060843623", true] = dbase;

                    if (newpath1 != null)
                    {
                        string newpath2 = dbase + newpath1;
                        Directory.CreateDirectory(newpath2);
                        Act.UI.ActApplication.Instance.ActFramework.Notes.CreateNote(noteTypes[0], "New storage folder created under the " + c.FirstName + " " + c.LastName + "'s file \n(called " + newpath2 + ") ", now, false, c);
                    }

                    dbFolders(dbase, ContactRecordType);
                }
                if (ContactRecordType == "Provider")
                {
                    string dbase = "C:/Users/Jason/Dropbox/JDFPBusiness/Client Files - Provider/";
                    c.Fields["CUST_ContactTable1_090144.CUST_DropboxPath_060843623", true] = dbase;

                    if (newpath1 != null)
                    {
                        string newpath2 = dbase + newpath1;
                        Directory.CreateDirectory(newpath2);
                        Act.UI.ActApplication.Instance.ActFramework.Notes.CreateNote(noteTypes[0], "New storage folder created under the " + c.FirstName + " " + c.LastName + "'s file \n(called " + newpath2 + ") ", now, false, c);
                    }

                    dbFolders(dbase, ContactRecordType);
                }
                if (ContactRecordType == "Beacon")
                {
                    string dbase = "C:/Users/Jason/Dropbox/JDFPBusiness/Client Files - Beacon/";
                    c.Fields["CUST_ContactTable1_090144.CUST_DropboxPath_060843623", true] = dbase;

                    if (newpath1 != null)
                    {
                        string newpath2 = dbase + newpath1;
                        Directory.CreateDirectory(newpath2);
                        Act.UI.ActApplication.Instance.ActFramework.Notes.CreateNote(noteTypes[0], "New storage folder created under the " + c.FirstName + " " + c.LastName + "'s file \n(called " + newpath2 + ") ", now, false, c);
                    }

                    dbFolders(dbase, ContactRecordType);
                }
                if (ContactRecordType == "BDM")
                {
                    string dbase = "C:/Users/Jason/Dropbox/JDFPBusiness/Client Files - BDM/";
                    c.Fields["CUST_ContactTable1_090144.CUST_DropboxPath_060843623", true] = dbase;

                    if (newpath1 != null)
                    {
                        string newpath2 = dbase + newpath1;
                        Directory.CreateDirectory(newpath2);
                        Act.UI.ActApplication.Instance.ActFramework.Notes.CreateNote(noteTypes[0], "New storage folder created under the " + c.FirstName + " " + c.LastName + "'s file \n(called " + newpath2 + ") ", now, false, c);
                    }

                    dbFolders(dbase, ContactRecordType);
                }
                if (ContactRecordType == "Business")
                {
                    string dbase = "C:/Users/Jason/Dropbox/JDFPBusiness/Client Files - Business/";
                    c.Fields["CUST_ContactTable1_090144.CUST_DropboxPath_060843623", true] = dbase;

                    if (newpath1 != null)
                    {
                        string newpath2 = dbase + newpath1;
                        Directory.CreateDirectory(newpath2);
                        Act.UI.ActApplication.Instance.ActFramework.Notes.CreateNote(noteTypes[0], "New storage folder created under the " + c.FirstName + " " + c.LastName + "'s file \n(called " + newpath2 + ") ", now, false, c);
                    }

                    dbFolders(dbase, ContactRecordType);
                }
                if (ContactRecordType == "JDFP")
                {
                    string dbase = "C:/Users/Jason/Dropbox/JDFPBusiness/Client Files - Business/";
                    c.Fields["CUST_ContactTable1_090144.CUST_DropboxPath_060843623", true] = dbase;

                    if (newpath1 != null)
                    {
                        string newpath2 = dbase + newpath1;
                        Directory.CreateDirectory(newpath2);
                        Act.UI.ActApplication.Instance.ActFramework.Notes.CreateNote(noteTypes[0], "New storage folder created under the " + c.FirstName + " " + c.LastName + "'s file \n(called " + newpath2 + ") ", now, false, c);
                    }

                    dbFolders(dbase, ContactRecordType);
                }
                if (ContactRecordType == "SMSF")
                {
                    string dbase = "C:/Users/Jason/Dropbox/JDFPBusiness/Client Files - SMSF/";
                    c.Fields["CUST_ContactTable1_090144.CUST_DropboxPath_060843623", true] = dbase;

                    if (newpath1 != null)
                    {
                        string newpath2 = dbase + newpath1;
                        Directory.CreateDirectory(newpath2);
                        Act.UI.ActApplication.Instance.ActFramework.Notes.CreateNote(noteTypes[0], "New storage folder created under the " + c.FirstName + " " + c.LastName + "'s file \n(called " + newpath2 + ") ", now, false, c);
                    }

                    dbFolders(dbase, ContactRecordType);
                }
                if (ContactRecordType == "Trust")
                {
                    string dbase = "C:/Users/Jason/Dropbox/JDFPBusiness/Client Files - Trust/";
                    c.Fields["CUST_ContactTable1_090144.CUST_DropboxPath_060843623", true] = dbase;

                    if (newpath1 != null)
                    {
                        string newpath2 = dbase + newpath1;
                        Directory.CreateDirectory(newpath2);
                        Act.UI.ActApplication.Instance.ActFramework.Notes.CreateNote(noteTypes[0], "New storage folder created under the " + c.FirstName + " " + c.LastName + "'s file \n(called " + newpath2 + ") ", now, false, c);
                    }

                    dbFolders(dbase, ContactRecordType);
                }

            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message, "{0} Exception caught - Buttons - Client Sorter");
            }

        }

    }

Jason Dawson Financial Planning
Brisbane | Australia - JDFP Home Page

Act Ver - Act! Premium Version 17.1.169.0, Hot Fix 3
OS - Windows 7 (stand alone machine)
MS Office - Enterprise 2007
Phone - Samsung Galaxy s6