Community
Showing results for 
Search instead for 
Do you mean 
Reply

Giving back to the Community - Sample Code - Folders, Files, Copy or Move

Copper Super Contributor
Posts: 478
Country: Australia

Giving back to the Community - Sample Code - Folders, Files, Copy or Move

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.

 

A recent addition to the code was a pdf file sorter, in my job i get a LOT OF STUFF in pdf format for contacts statements of accounts, policies etc, so this code sorts 4 types from 2 business into the clients individual folders. So problem to overcome where how do you check a file exists, how to move or copy a file?

 

        
        private void AnnStmtSort(string command)
        {
            try
            {
                // Set current contact record
                Act.Framework.Contacts.Contact c = oApp.ApplicationState.CurrentContact;

                if (c != null)
                {
                    DialogResult drstmt = MessageBox.Show("The statement sorter currently only sorts Superannuation and Investment statements for Wealthtrac and Netwealth.\n\nResently added but untested is the IPR Report for Wealthtrac, and Monthly Confirmation Stmt for Netwealth.", "Statement Sorter", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (drstmt == DialogResult.Yes)
                    {
                        // Data fields used in table
                        string name1 = c.FirstName;
                        string name2 = c.LastName;
                        string name3 = c.FullName;
                        DateTime now = DateTime.Now.AddYears(-1);
                        string year = now.Year.ToString();
                        string month = now.Month.ToString();
                        DateTime iprdate = DateTime.Now;
                        string ipryear = iprdate.Year.ToString();
                        string iprmonth = iprdate.Month.ToString();

                        Guid cGUID = c.ID;
                        MutableEntityFieldDescriptor oStatus = oApp.ActFramework.Opportunities.GetMutableEntityFieldDescriptor(StandardOpportunityField.StatusNum);
                        MutableEntityFieldDescriptor oName = oApp.ActFramework.Opportunities.GetMutableEntityFieldDescriptor(StandardOpportunityField.Name);
                        MutableEntityFieldDescriptor oType = oApp.ActFramework.Opportunities.GetMutableEntityFieldDescriptor(StandardOpportunityField.User7);
                        MutableEntityFieldDescriptor oAccNum = oApp.ActFramework.Opportunities.GetMutableEntityFieldDescriptor("TBL_OPPORTUNITY.CUST_PolicyNumber_051506257", true);
                        MutableEntityFieldDescriptor oAccComms = oApp.ActFramework.Opportunities.GetMutableEntityFieldDescriptor("TBL_OPPORTUNITY.CUST_Coms_125816920", true);

                        // Establish Opportunity List with "inactive opportunities filtered out
                        int[] oSt1 = { 0, 1, 2 };
                        IFilterCriteria[] oFilterCriteria = { new InFilterCriteria(oStatus, oSt1) };
                        OpportunityList cOpp = Act.UI.ActApplication.Instance.ActFramework.Opportunities.GetOpportunitiesByContact(cGUID, null, oFilterCriteria);

                        // Establish statment from download location to FDS folder and standardise naming convention
                        foreach (Opportunity opp in cOpp)
                        {
                            string oTypeVal = oType.GetValue(opp).ToString();
                            string oAccNumVal = oAccNum.GetValue(opp).ToString();

                            ContactFieldDescriptor DBPathFD = Act.UI.ActApplication.Instance.ActFramework.Contacts.GetContactFieldDescriptor("CUST_ContactTable1_090144.CUST_DropboxPath_060843623", true);
                            string DBPathVal = DBPathFD.GetValue(c).ToString();
                            string newpathfn1 = "C:\\Users\\Jason\\Dropbox\\JDFPBusiness\\" + DBPathVal + "\\FDS\\Annual Statement - Current (" + oTypeVal + ").pdf";

                            MutableEntityFieldDescriptor oComp = oApp.ActFramework.Opportunities.GetMutableEntityFieldDescriptor("TBL_OPPORTUNITY.COMPETITOR", true);
                            if (oComp.GetValue(opp) == null)
                            {
                                MessageBox.Show("Annual statements for '" + oName + "' have NOT been sorted to " + name1 + "'s folders, as the Competator field is empty.", "Annual (" + year + ") Statement Sort", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                            else
                            {
                                string oCompVal = oComp.GetValue(opp).ToString();
                                string newpathfn2 = "C:\\Users\\Jason\\Dropbox\\JDFPBusiness\\" + DBPathVal + "\\" + oCompVal + " Annual (" + year + ") Statement - Current (" + oTypeVal + " - " + oAccNumVal + ").pdf";
                                // For Investment accounts
                                if (oTypeVal == "Investment")
                                {
                                    // For Wealthtrac Investment accounts
                                    if (oCompVal == "Wealthtrac")
                                    {
                                        // For Wealthtrac Annual Statements Downloaded
                                        string oldpathfn = "D:\\Users\\Jason\\Downloads\\Wealthtrac AnnStmt\\" + oAccNumVal + ".pdf";
                                        if (System.IO.File.Exists(oldpathfn) == true)
                                        {
                                            System.IO.File.Copy(oldpathfn, newpathfn2);
                                            System.IO.File.Move(oldpathfn, newpathfn1);
                                        }
                                        else if (System.IO.File.Exists(newpathfn2) == true)
                                        {
                                            MessageBox.Show("Wealthtrac Stmt for Acc " + oAccNumVal + " has already been copied to personal folder for " + name3 + ".", "Account Stmt Sorter", MessageBoxButtons.OK);
                                        }
                                        else
                                        {
                                            MessageBox.Show("Wealthtrac Stmt for Acc " + oAccNumVal + " can not be found and has not been copied to personal folder for " + name3 + ".", "Account Stmt Sorter", MessageBoxButtons.OK);
                                        }

                                        // For Wealthtrac IPR Reports Downloaded
                                        string oldpathfnipr = "D:\\Users\\Jason\\Downloads\\Wealthtrac AnnStmt\\" + oAccNumVal + "_IPR.pdf";
                                        string newpathfnipr = "C:\\Users\\Jason\\Dropbox\\JDFPBusiness\\" + DBPathVal + "\\" + oCompVal + " IPR Report - Current (" + oTypeVal + " - " + oAccNumVal + ") - " + ipryear + iprmonth + ".pdf";
                                        if (System.IO.File.Exists(oldpathfnipr) == true)
                                        {
                                            System.IO.File.Move(oldpathfnipr, newpathfnipr);
                                        }
                                        else if (System.IO.File.Exists(newpathfnipr) == true)
                                        {
                                            MessageBox.Show("Wealthtrac IPR Report for Acc " + oAccNumVal + " has already been copied to personal folder for " + name3 + ".", "Account Stmt Sorter", MessageBoxButtons.OK);
                                        }
                                        else
                                        {
                                            MessageBox.Show("Wealthtrac IPR Report for Acc " + oAccNumVal + " can not be found and has not been copied to personal folder for " + name3 + ".", "Account Stmt Sorter", MessageBoxButtons.OK);
                                        }

                                    }
                                    // For Netwealth Investment accounts
                                    if (oCompVal == "Netwealth")
                                    {
                                        // For Netwealth My Statement Downloaded
                                        string oldpathfn = "D:\\Users\\Jason\\Downloads\\Netwealth AnnStmt\\" + name3 + "-" + oAccNumVal + "-MyStatement.pdf";
                                        if (System.IO.File.Exists(oldpathfn) == true)
                                        {
                                            System.IO.File.Copy(oldpathfn, newpathfn2);
                                            System.IO.File.Move(oldpathfn, newpathfn1);
                                        }
                                        else if (System.IO.File.Exists(newpathfn2) == true)
                                        {
                                            MessageBox.Show("Netwealth Stmt for Acc " + oAccNumVal + " has already been copied to personal folder for " + name3 + ".", "Account Stmt Sorter", MessageBoxButtons.OK);
                                        }
                                        else
                                        {
                                            MessageBox.Show("Netwealth Stmt for Acc " + oAccNumVal + " can not be found and has not been copied to personal folder for " + name3 + ".", "Account Stmt Sorter", MessageBoxButtons.OK);
                                        }
      
                                        // For Netwealth Account Snapshot Reports Downloaded
                                        string oldpathfnipr = "D:\\Users\\Jason\\Downloads\\Netwealth AnnStmt\\" + name3 + "-" + oAccNumVal + "-AccountSnapshotAndAssetAllocation.pdf";
                                        string newpathfnipr = "C:\\Users\\Jason\\Dropbox\\JDFPBusiness\\" + DBPathVal + "\\" + oCompVal + " Snapshot Report - Current (" + oTypeVal + " - " + oAccNumVal + ") - " + ipryear + iprmonth + ".pdf";
                                        if (System.IO.File.Exists(oldpathfnipr) == true)
                                        {
                                            System.IO.File.Move(oldpathfnipr, newpathfnipr);
                                        }
                                        else if (System.IO.File.Exists(newpathfnipr) == true)
                                        {
                                            MessageBox.Show("Netwealth Snapshot Report for Acc " + oAccNumVal + " has already been copied to personal folder for " + name3 + ".", "Account Stmt Sorter", MessageBoxButtons.OK);
                                        }
                                        else
                                        {
                                            MessageBox.Show("Netwealth Snapshot Report for Acc " + oAccNumVal + " can not be found and has not been copied to personal folder for " + name3 + ".", "Account Stmt Sorter", MessageBoxButtons.OK);
                                        }

                                        // For Netwealth Confirmation Statements Downloaded
                                        string oldpathfn3 = "D:\\Users\\Jason\\Downloads\\Netwealth AnnStmt\\" + oAccNumVal + "_ADV005079_DLRNETADV_" + name3 + ".pdf";
                                        string newpathfn3 = "C:\\Users\\Jason\\Dropbox\\JDFPBusiness\\" + DBPathVal + "\\" + oCompVal + " Monthly (" + year + month + ") Confirmation Statement - (" + oTypeVal + " - " + oAccNumVal + ").pdf";
                                        if (System.IO.File.Exists(oldpathfn3) == true)
                                        {
                                            System.IO.File.Move(oldpathfn3, newpathfn3);
                                        }
                                        else if (System.IO.File.Exists(newpathfn3) == true)
                                        {
                                            MessageBox.Show("Netwealth Confirmation Stmt for Acc " + oAccNumVal + " has already been copied to personal folder for " + name3 + ".", "Account Stmt Sorter", MessageBoxButtons.OK);
                                        }
                                        else
                                        {
                                            MessageBox.Show("Netwealth Confirmation Stmt for Acc " + oAccNumVal + " can not be found and has not been copied to personal folder for " + name3 + ".", "Account Stmt Sorter", MessageBoxButtons.OK);
                                        }

                                    }
                                }

                                // For Superannuation accounts
                                if (oTypeVal == "Superannuation")
                                {
                                    // For Wealthtrac Superannuation accounts
                                    if (oCompVal == "Wealthtrac")
                                    {
                                        // For Wealthtrac Annual Statements Downloaded
                                        string oldpathfn = "D:\\Users\\Jason\\Downloads\\Wealthtrac AnnStmt\\" + oAccNumVal + ".pdf";
                                        if (System.IO.File.Exists(oldpathfn) == true)
                                        {
                                            System.IO.File.Copy(oldpathfn, newpathfn2);
                                            System.IO.File.Move(oldpathfn, newpathfn1);
                                        }
                                        else if (System.IO.File.Exists(newpathfn2) == true)
                                        {
                                            MessageBox.Show("Wealthtrac Stmt for Acc " + oAccNumVal + " has already been copied to personal folder for " + name3 + ".", "Account Stmt Sorter", MessageBoxButtons.OK);
                                        }
                                        else
                                        {
                                            MessageBox.Show("Wealthtrac Stmt for Acc " + oAccNumVal + " can not be found and has not been copied to personal folder for " + name3 + ".", "Account Stmt Sorter", MessageBoxButtons.OK);
                                        }

                                        // For Wealthtrac IPR Reports Downloaded
                                        string oldpathfnipr = "D:\\Users\\Jason\\Downloads\\Wealthtrac AnnStmt\\" + oAccNumVal + "_IPR.pdf";
                                        string newpathfnipr = "C:\\Users\\Jason\\Dropbox\\JDFPBusiness\\" + DBPathVal + "\\" + oCompVal + " IPR Report - Current (" + oTypeVal + " - " + oAccNumVal + ") - " + ipryear + iprmonth + ".pdf";
                                        if (System.IO.File.Exists(oldpathfnipr) == true)
                                        {
                                            System.IO.File.Move(oldpathfnipr, newpathfnipr);
                                        }
                                        else if (System.IO.File.Exists(newpathfnipr) == true)
                                        {
                                            MessageBox.Show("Wealthtrac IPR Report for Acc " + oAccNumVal + " has already been copied to personal folder for " + name3 + ".", "Account Stmt Sorter", MessageBoxButtons.OK);
                                        }
                                        else
                                        {
                                            MessageBox.Show("Wealthtrac IPR Report for Acc " + oAccNumVal + " can not be found and has not been copied to personal folder for " + name3 + ".", "Account Stmt Sorter", MessageBoxButtons.OK);
                                        }
                                    }
                                    // For Netwealth Superannuation accounts
                                    if (oCompVal == "Netwealth")
                                    {
                                        // For Netwealth My Statement Downloaded
                                        string oldpathfn = "D:\\Users\\Jason\\Downloads\\Netwealth AnnStmt\\" + name3 + "-" + oAccNumVal + "-MyStatement.pdf";
                                        if (System.IO.File.Exists(oldpathfn) == true)
                                        {
                                            System.IO.File.Copy(oldpathfn, newpathfn2);
                                            System.IO.File.Move(oldpathfn, newpathfn1);
                                        }
                                        else if (System.IO.File.Exists(newpathfn2) == true)
                                        {
                                            MessageBox.Show("Netwealth Stmt for Acc " + oAccNumVal + " has already been copied to personal folder for " + name3 + ".", "Account Stmt Sorter", MessageBoxButtons.OK);
                                        }
                                        else
                                        {
                                            MessageBox.Show("Netwealth Stmt for Acc " + oAccNumVal + " can not be found and has not been copied to personal folder for " + name3 + ".", "Account Stmt Sorter", MessageBoxButtons.OK);
                                        }

                                        // For Netwealth Account Snapshot Reports Downloaded
                                        string oldpathfnipr = "D:\\Users\\Jason\\Downloads\\Netwealth AnnStmt\\" + name3 + "-" + oAccNumVal + "-AccountSnapshotAndAssetAllocation.pdf";
                                        string newpathfnipr = "C:\\Users\\Jason\\Dropbox\\JDFPBusiness\\" + DBPathVal + "\\" + oCompVal + " Snapshot Report - Current (" + oTypeVal + " - " + oAccNumVal + ") - " + ipryear + iprmonth + ".pdf";
                                        if (System.IO.File.Exists(oldpathfnipr) == true)
                                        {
                                            System.IO.File.Move(oldpathfnipr, newpathfnipr);
                                        }
                                        else if (System.IO.File.Exists(newpathfnipr) == true)
                                        {
                                            MessageBox.Show("Netwealth Snapshot Report for Acc " + oAccNumVal + " has already been copied to personal folder for " + name3 + ".", "Account Stmt Sorter", MessageBoxButtons.OK);
                                        }
                                        else
                                        {
                                            MessageBox.Show("Netwealth Snapshot Report for Acc " + oAccNumVal + " can not be found and has not been copied to personal folder for " + name3 + ".", "Account Stmt Sorter", MessageBoxButtons.OK);
                                        }

                                        // For Netwealth Confirmation Statements Downloaded
                                        string oldpathfn3 = "D:\\Users\\Jason\\Downloads\\Netwealth AnnStmt\\" + oAccNumVal + "_ADV005079_DLRNETADV_" + name3 + ".pdf";
                                        string newpathfn3 = "C:\\Users\\Jason\\Dropbox\\JDFPBusiness\\" + DBPathVal + "\\" + oCompVal + " Monthly (" + year + month + ") Confirmation Statement - (" + oTypeVal + " - " + oAccNumVal + ").pdf";
                                        if (System.IO.File.Exists(oldpathfn3) == true)
                                        {
                                            System.IO.File.Move(oldpathfn3, newpathfn3);
                                        }
                                        else if (System.IO.File.Exists(newpathfn3) == true)
                                        {
                                            MessageBox.Show("Netwealth Confirmation Stmt for Acc " + oAccNumVal + " has already been copied to personal folder for " + name3 + ".", "Account Stmt Sorter", MessageBoxButtons.OK);
                                        }
                                        else
                                        {
                                            MessageBox.Show("Netwealth Confirmation Stmt for Acc " + oAccNumVal + " can not be found and has not been copied to personal folder for " + name3 + ".", "Account Stmt Sorter", MessageBoxButtons.OK);
                                        }

                                    }
                                }
                            }
                        }
                        MessageBox.Show("Annual or Monthly Confirmation statements for '" + oName + "' have been sorted to the FDS folder for " + name3 + ".", "Annual Statement Sort", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message, "{0} Exception caught- Annual Statement 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