Ejemplo n.º 1
0
 public bool runPDFCreatorTest()
 {
     bool success = false;
     PDFCreator pdfCreator = new PDFCreator(new Investor2(
             _firstName: "Sally",
             _lastName: "Johnson",
             _investorID: "1",
             _address: "123 Main Street",
             _city: "Kansas City",
             _state: "MO",
             _zip: "64410",
             _email: "*****@*****.**",
             _phone: "913-999-9999",
             _deceased: "false",
             _joinDate: default(DateTime).ToShortDateString(),
             _labelName: "Johnson, Sally",
             _notes: "",
             _lastInvestYear: "2014"
         ));
     pdfCreator.createPDF(new Investment2(1,1,DateTime.Now.ToShortDateString(), 500, "A 123-623", "general fund", -1, "cash", "", "true"
         ), "print");
     return success;
 }
Ejemplo n.º 2
0
        private void saveAndCloseToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //First check for invalid cells on the datagrid
            foreach (DataGridViewRow row in InvDataGridView.SelectedRows)
            {
                if(checkForInvalidValues(row))
                {
                    return;
                }
            }

            //check to make sure that the required fields have been entered
            if (!RequiredFieldsAreFilledOut())
            {
                MessageBox.Show("Please fill out all required fields.");
                return;
            }

            //check to make sure the user does not already exist in the DB
            int checkIfUserExistsResult = DBCommunication.checkIfInvestorExists(InvestorFNTextBox.Text, InvestorLNTextBox.Text);
            if (checkIfUserExistsResult == -1)
            {
                return;
            }
            if (checkIfUserExistsResult > 0)
            {
                MessageBox.Show(string.Format("A user with the first name {0} and last name {1} already exists in the database.", InvestorFNTextBox.Text, InvestorLNTextBox.Text));
                return;
            }


            //After all the user data has been verified, make sure the user is ready to save changes.
            var dialogResult = MessageBox.Show("Changes will be saved now.  Continue?", "Alert!", MessageBoxButtons.YesNo);
            if (dialogResult == System.Windows.Forms.DialogResult.No)
            {
                return;
            }

            if(!DBCommunication.SaveNewInvestor(InvestorFNTextBox.Text, InvestorLNTextBox.Text, InvestorAddressTextBox.Text,
                InvestorCityTextBox.Text, InvestorStateTextBox.Text, InvestorZipTextBox.Text, InvestorEmailTextBox.Text, InvestorPhoneMaskedTextBox.Text,
                InvestorDeceasedCheckBox.Checked, InvestorJoinDateDateTimePicker.Value, InvestorNotesRichTextBox.Text))
            {
                return; //error message supplied to user in the SaveNewInvestor() method
            }


            //Update the global list of investors to reflect the addition of the new investor
            Globals.GlobalInvestors = DBCommunication.GetInvestors();

            if (!InvDataGridView.Rows[0].IsNewRow)
            {
                List<Investment2> newInvestments = new List<Investment2>();
                int investorID = Globals.GlobalInvestors.Where(i => i.LabelName == InvestorFNTextBox.Text + " " + InvestorLNTextBox.Text).Single().InvestorID;
                FetchNewInvestments(newInvestments, investorID);

                int numSuccessfullySaved = DBCommunication.SaveNewInvestments(newInvestments);
                if(numSuccessfullySaved != newInvestments.Count)
                {
                    return;
                }

                PDFCreator pdfCreator = new PDFCreator(Globals.GlobalInvestors.Where(i => i.InvestorID == investorID).Single());
                bool savePDFSuccess = false;
                foreach (Investment2 i in newInvestments)
                {
                   savePDFSuccess = pdfCreator.createPDF(i, "saveOnly");
                    if(!savePDFSuccess)
                    {
                        return;
                    }
                }
            }
            MessageBox.Show(string.Format("Save operation successfully completed."));
            Globals.rebindOnMainForm = true;
            this.Close();
        }
Ejemplo n.º 3
0
        private void saveAndEmailCertificatesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (InvestmentsDataGridView.SelectedRows.Count == 0)
            {
                var result = MessageBox.Show("You have not selected any investments to email.");
                return;
            }

            if(EmailTextBox.Text == "")
            {
                MessageBox.Show("Please provide an email address.");
                return;
            }

            if (!RequiredFieldsAreFilledOut())
            {
                MessageBox.Show("Please fill out all required fields.");
                return;
            }
            if (LabelNameTextBox.Text != FirstNameTextBox.Text + " " + LastNameTextBox.Text)
            {
                var result = MessageBox.Show("The label name does not match the first and last name.  Continue?", "Name Mis-match Alert!", MessageBoxButtons.YesNo);
                if (result == System.Windows.Forms.DialogResult.No)
                {
                    return;
                }
            }

            //First check for invalid cells on the datagrid
            foreach (DataGridViewRow row in InvestmentsDataGridView.SelectedRows)
            {
                if (checkForInvalidValues(row))
                {
                    return;
                }
            }
            var dialogResult = MessageBox.Show("Changes will be saved now.  Continue?", "Alert!", MessageBoxButtons.YesNo);
            if(dialogResult == System.Windows.Forms.DialogResult.No)
            {
                return;
            }
            string lastInvestYear = LastInvYearTextBox.Text;
            List<Investment2> newInvestments = new List<Investment2>();
            List<Investment2> updatedInvestments = new List<Investment2>();

            FetchNewAndUpdatedInvestments(newInvestments, updatedInvestments, lastInvestYear);

            #region old code that correctly populates the list of new and updated investments from the selected rows
            //foreach (DataGridViewRow row in InvestmentsDataGridView.SelectedRows)
            //{
            //    int outAmount, outYouthID;
            //    string outReinvest;
            //    string checkNumber = "";
            //    if (Int32.TryParse(row.Cells[1].Value.ToString(), out outAmount))
            //    {

            //    }
            //    if (row.Cells[3].Value != null)
            //    {
            //        checkNumber = row.Cells[3].Value.ToString();
            //    }
            //    if (row.Cells[4].Value.ToString() != "youth")
            //    {
            //        outYouthID = -1;
            //    }
            //    else
            //    {
            //        outYouthID = Globals.GlobalYouth.Where(y => y.FullName == row.Cells[5].Value.ToString()).Select(y => y.YouthID).Single();
            //    }
            //    if (row.Cells[6].Value.GetType() == typeof(string))
            //    {
            //        if (row.Cells[6].Value.ToString() == "false")
            //        {
            //            outReinvest = "0";
            //        }
            //        else
            //        {
            //            outReinvest = "1";
            //        }

            //    }
            //    else
            //    {
            //        if ((bool)row.Cells[6].Value == true)
            //        {
            //            outReinvest = "1";
            //        }
            //        else
            //        {
            //            outReinvest = "0";
            //        }
            //    }
            //    if (row.Cells[9].Value.ToString() == "true") //If true it's a bran new investment
            //    {
            //        lastInvestYear = DateTime.Now.Year.ToString(); //Update the investor's LastInvestYear since we're adding a new investment this year
            //        newInvestments.Add(new Investment2(
            //                _investorID: selectedInvestor.InvestorID,
            //                _date: row.Cells[0].Value.ToString(),
            //                _amount: outAmount,
            //                _creditTo: row.Cells[4].Value.ToString(),
            //                _youthID: outYouthID,
            //                _paymentType: row.Cells[2].Value.ToString(),
            //                _checkNumber: checkNumber,
            //                _reinvest: outReinvest
            //            ));
            //    }
            //    else //This is a previously created investment we're now updating
            //    {
            //        int outInvestmentID;
            //        if (Int32.TryParse(row.Cells[8].Value.ToString(), out outInvestmentID)) { }
            //        updatedInvestments.Add(new Investment2(
            //            _investmentID: outInvestmentID,
            //            _investorID: selectedInvestor.InvestorID,
            //            _date: row.Cells[0].Value.ToString(),
            //            _amount: outAmount,
            //            _certificateNumber: row.Cells[7].Value.ToString(),
            //            _creditTo: row.Cells[4].Value.ToString(),
            //            _youthID: outYouthID,
            //            _paymentType: row.Cells[2].Value.ToString(),
            //            _checkNumber: checkNumber,
            //            _reinvest: outReinvest
            //        ));
            //    }
            //}
            #endregion
            //Now update the investor's information in the DB
            if (!DBCommunication.UpdateInvestor(selectedInvestor.InvestorID, FirstNameTextBox.Text, LastNameTextBox.Text, AddressTextBox.Text,
                CityTextBox.Text, StateTextBox.Text, ZipTextBox.Text, EmailTextBox.Text, PhoneMaskedTextBox.Text, InvestorDeceasedCheckBox.Checked,
                JoinDateTimePicker.Value, NotesRichTextBox.Text, LabelNameTextBox.Text, lastInvestYear))
            {
                return;
            }

            //Save the new investments
            int numNewInvestmentsSaved = 0;
            if (newInvestments.Count > 0)
            {
                numNewInvestmentsSaved = DBCommunication.SaveNewInvestments(newInvestments);
                if (numNewInvestmentsSaved == 0)
                {
                    MessageBox.Show("Any updates made to the investor were saved to the database.  New or updated investments were not saved. 0 investments were emailed.");
                    return;
                }
            }

            //Save updates to existing investments
            int numInvestmentsUpdated = 0;
            if (updatedInvestments.Count > 0)
            {
                numInvestmentsUpdated = DBCommunication.UpdateInvestments(updatedInvestments);
                if (numInvestmentsUpdated == 0)
                {
                    MessageBox.Show("Any updates made to the investor were saved to the database.  Any new investments may have been saved to the database but updated investments were not saved. 0 investments were emailed.");
                    return;
                }
            }

            int numEmailedNewInvestments = 0;
            int numEmailedUpdatedInvestements = 0;
            PDFCreator pdfCreator = new PDFCreator(Globals.GlobalInvestors.Where(i=>i.InvestorID == selectedInvestor.InvestorID).Single());
            bool emailSuccess = false;
            bool finalEmailSuccess = true;
            foreach (Investment2 i in updatedInvestments)
            {
                emailSuccess = pdfCreator.createPDF(i, "email");
                if(!emailSuccess)
                {
                    finalEmailSuccess = false;
                }
                numEmailedUpdatedInvestements++;
            }
            foreach (Investment2 i in newInvestments)
            {
                emailSuccess = pdfCreator.createPDF(i, "email");
                if (!emailSuccess)
                {
                    finalEmailSuccess = false ;
                }
                numEmailedNewInvestments++;
            }

            if (finalEmailSuccess)
            {
                if (newInvestments.Count > 0 && updatedInvestments.Count > 0)
                {
                    MessageBox.Show(string.Format("The program has attempted to email {0} new investment(s) and {1} updated investment(s).  Please check your email account to verify.", numEmailedNewInvestments, numEmailedUpdatedInvestements));
                }
                else if (newInvestments.Count > 0)
                {
                    MessageBox.Show(string.Format("The program has attempted to email {0} new investment(s).  Please check your email account to verify.", numEmailedNewInvestments));
                }
                else if (updatedInvestments.Count > 0)
                {
                    MessageBox.Show(string.Format("The program has attempted to email {0} updated investment(s).  Please check your email account to verify", numEmailedUpdatedInvestements));
                }
            }
            Globals.rebindOnMainForm = true;
            this.Close();
        }
Ejemplo n.º 4
0
        private void saveAndEmailToolStripMenuItem_Click(object sender, EventArgs e)
        {

            //check to make sure that the required fields have been entered
            if (!RequiredFieldsAreFilledOut())
            {
                MessageBox.Show("Please fill out all required fields.");
                return;
            }

            //check to make sure the user does not already exist in the DB
            int checkIfUserExistsResult = DBCommunication.checkIfInvestorExists(InvestorFNTextBox.Text, InvestorLNTextBox.Text);
            if (checkIfUserExistsResult == -1)
            {
                return;
            }
            if (checkIfUserExistsResult > 0)
            {
                MessageBox.Show(string.Format("A user with the first name {0} and last name {1} already exists in the database.", InvestorFNTextBox.Text, InvestorLNTextBox.Text));
                return;
            }


            if(InvDataGridView.Rows[0].IsNewRow)
            {
                MessageBox.Show("You have not entered any investments to email");
                return;
            }

            //check for invalid cells on the datagrid
            foreach (DataGridViewRow row in InvDataGridView.SelectedRows)
            {
                if (checkForInvalidValues(row))
                {
                    return;
                }
            }

            //After all the user data has been verified, make sure the user is ready to save changes.
            var dialogResult = MessageBox.Show("Changes will be saved now.  Continue?", "Alert!", MessageBoxButtons.YesNo);
            if (dialogResult == System.Windows.Forms.DialogResult.No)
            {
                return;
            }

            if (!DBCommunication.SaveNewInvestor(InvestorFNTextBox.Text, InvestorLNTextBox.Text, InvestorAddressTextBox.Text,
                InvestorCityTextBox.Text, InvestorStateTextBox.Text, InvestorZipTextBox.Text, InvestorEmailTextBox.Text, InvestorPhoneMaskedTextBox.Text,
                InvestorDeceasedCheckBox.Checked, InvestorJoinDateDateTimePicker.Value, InvestorNotesRichTextBox.Text))
            {
                return; //error message supplied to user in the SaveNewInvestor() method
            }


            //Update the global list of investors to reflect the addition of the new investor
            Globals.GlobalInvestors = DBCommunication.GetInvestors();

            /*To create a new investment I need the investor's ID.  The investor's ID is not created until entered into
             *the DB for the first time.  That's why I have to fetch it from the DB now.
             */
            Investor2 newInvestor = Globals.GlobalInvestors.Where(i => i.LabelName == InvestorFNTextBox.Text + " " + InvestorLNTextBox.Text).Single();

            //The following variables track the number of successully emailed investments
            int numEmailAttempts = 0;

            List<Investment2> newInvestments = new List<Investment2>();
            if (!InvDataGridView.Rows[0].IsNewRow)
            {
                int investorID = Globals.GlobalInvestors.Where(i => i.LabelName == InvestorFNTextBox.Text + " " + InvestorLNTextBox.Text).Single().InvestorID;
                FetchNewInvestments(newInvestments, investorID);
                int numSuccessfullySaved = DBCommunication.SaveNewInvestments(newInvestments);
                if(numSuccessfullySaved != newInvestments.Count)
                {
                    return;
                }
            }
            Globals.rebindOnMainForm = true;

            //Now email the investments.  I'm emailing after saving all the investments.  It is important to save first,
            //because if emailing fails, the user has not lost the investment information and can attempt to re-email in the view/edit investor form.

            PDFCreator pdfCreator = new PDFCreator(newInvestor);
            foreach (Investment2 i in newInvestments)
            {
                pdfCreator.createPDF(i, "email");
                numEmailAttempts++;
            }

            MessageBox.Show(string.Format("Save operation was successful. The program has attempted to email {0} new investment certificate(s).  Please check your email account to verify they have been emailed.", numEmailAttempts));

            this.Close();
        }
Ejemplo n.º 5
0
        //For this save option, the user wishes to save any changes made to the investor, including
        //changes made to the selected investments (may be new investments).
        private void saveAndCloseToolStripMenuItem_Click(object sender, EventArgs e)
        {
            /*Multiple saves are potentially going on.  An investor's info is being saved,
             new investments may be saved, and updates to old investments may be saved.  The following
             variables track which save operations were successfully completed so as to give the user
             a helpful error message should something go wrong.*/


            //check to make sure that the required fields have been entered
            if (!RequiredFieldsAreFilledOut())
            {
                MessageBox.Show("Please fill out all required fields.");
                return;
            }

            if (LabelNameTextBox.Text != FirstNameTextBox.Text + " " + LastNameTextBox.Text)
            {
                var result = MessageBox.Show("The label name does not match the first and last name.  Save changes anyway?", "Name Mis-match Alert!", MessageBoxButtons.YesNo);
                if(result == System.Windows.Forms.DialogResult.No)
                {
                    return;
                }
            }
            if(InvestmentsDataGridView.SelectedRows.Count == 0)
            {
                var result = MessageBox.Show("You have not selected any investments to update/add.  Save anyway?", "Alert!", MessageBoxButtons.YesNo);
                if(result == System.Windows.Forms.DialogResult.No)
                {
                    return;
                }
            }

            //First check for invalid cells on the datagrid
            foreach (DataGridViewRow row in InvestmentsDataGridView.SelectedRows)
            {
                if(checkForInvalidValues(row))
                {
                    return;
                }
            }

            string lastInvestYear = LastInvYearTextBox.Text;
            List<Investment2> newInvestments = new List<Investment2>();
            List<Investment2> updatedInvestments = new List<Investment2>();

            FetchNewAndUpdatedInvestments(newInvestments, updatedInvestments, lastInvestYear);


            //Update the investor's information in the DB
            if (!DBCommunication.UpdateInvestor(selectedInvestor.InvestorID, FirstNameTextBox.Text, LastNameTextBox.Text, AddressTextBox.Text,
                CityTextBox.Text, StateTextBox.Text, ZipTextBox.Text, EmailTextBox.Text, PhoneMaskedTextBox.Text, InvestorDeceasedCheckBox.Checked,
                JoinDateTimePicker.Value, NotesRichTextBox.Text, LabelNameTextBox.Text, lastInvestYear))
            {
                return;
            }

            int numNewInvestementsSaved = 0;
            if (newInvestments.Count > 0)
            {
                numNewInvestementsSaved = DBCommunication.SaveNewInvestments(newInvestments);
                if (numNewInvestementsSaved == 0)
                {
                    MessageBox.Show("Any updates made to the investor were saved to the database.  Selected investments were not saved to the database.");
                    return;
                }
            }

            int numUpdatedInvestmentsSaved = 0;
            if (updatedInvestments.Count > 0)
            {
                numUpdatedInvestmentsSaved = DBCommunication.UpdateInvestments(updatedInvestments);
                if (numUpdatedInvestmentsSaved == 0)
                {
                    MessageBox.Show("Any updates made to the investor were saved to the database.  Any new investments may have been saved to the database but updated investments were not saved.");
                    return;
                }
            }

            PDFCreator creator = new PDFCreator(selectedInvestor);
            bool savePDFSuccess = false;
            foreach (Investment2 i2 in newInvestments)
            {
                savePDFSuccess = creator.createPDF(i2, "saveOnly");
                if(!savePDFSuccess)
                {
                    return;
                }
            }

            foreach (Investment2 i2 in updatedInvestments)
            {
                savePDFSuccess = creator.createPDF(i2, "saveOnly");
                if (!savePDFSuccess)
                {
                    return;
                }
            }

            MessageBox.Show(string.Format("Save operation successfully completed."));
            Globals.rebindOnMainForm = true;
            this.Close();
        }