Ejemplo n.º 1
0
 private void button2_Click(object sender, EventArgs e)//AddInvestorButton
 {
     if (Globals.GlobalYouth.Count == 0)
     {
         MessageBox.Show("Please enter at least one youth in the database before adding investors.");
         return;
     }
     AddInvestorForm _addInvestorForm = new AddInvestorForm();
     _addInvestorForm.ShowDialog();
 }
Ejemplo n.º 2
0
        /*
         * The following is the click event for the "Save & New Investor" tool strip menu item
         * When clicked, the investor information will be saved to the database and any
         * investments will also be saved to the DB.  After the save operation is completed, 
         * a new add investor form will automatically open.
         */
        private void toolStripMenuItem1_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;
            }

            //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;
            }

            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 (!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();
            AddInvestorForm AIF = new AddInvestorForm();
            AIF.Show();
        }