Exemplo n.º 1
0
 private void ResetData()
 {
     Taxpayer.ResetCounts();
     MarriedList.Clear();
     UnmarriedList.Clear();
     savedBool = true;
     taxpayerBindingSource.Clear();
     outputTextBox.Clear();
     GetReady();
 }
Exemplo n.º 2
0
 private void summaryButton_Click(object sender, EventArgs e)
 {
     if (taxpayerDataGridView.Rows.Count == 0)
     {
         MessageBox.Show("No data available.");
     }
     else
     {
         outputTextBox.AppendText(Taxpayer.Summary() + "\r\n");
     }
     //end if statement
 }
Exemplo n.º 3
0
        private void submitButton_Click(object sender, EventArgs e)
        {
            //declarations
            String nameString;
            double salaryDouble;
            double investmentDouble;
            int    exemptionInt;
            bool   marriedBool;

            //class
            Taxpayer newTaxpayer;

            //inputs
            nameString       = nameTextBox.Text;
            salaryDouble     = double.Parse(salaryTextBox.Text);
            investmentDouble = double.Parse(investmentTextBox.Text);
            exemptionInt     = int.Parse(exemptionTextBox.Text);
            marriedBool      = marriedCheckBox.Checked;

            if (exemptionInt >= 0 && exemptionInt <= 2) //exemption int must be 0, 1, or 2
            {
                //add to class
                newTaxpayer = new Taxpayer(nameString, salaryDouble, investmentDouble, exemptionInt, marriedBool);
                taxpayerBindingSource.Add(newTaxpayer);

                //add to appropriate list
                if (marriedBool == true)
                {
                    MarriedList.Add(newTaxpayer);
                }
                else
                {
                    UnmarriedList.Add(newTaxpayer);
                }
                //end if statement

                //display output
                outputTextBox.AppendText(newTaxpayer.Info() + "\r\n");

                DisableControls();

                //set saved data to false
                savedBool = false;
            }
            else
            {
                MessageBox.Show("Error: exemptions claimed must be 0, 1, or 2");
                exemptionTextBox.SelectAll();
                exemptionTextBox.Focus();
            }
            //end if statement
        }
Exemplo n.º 4
0
        private void loadButton_Click(object sender, EventArgs e)
        {
            //read data from a text file
            String taxpayerFile;

            OpenFileDialog taxpayerFileChooser = new OpenFileDialog();

            taxpayerFileChooser.Filter = "All text files|*.txt";
            taxpayerFileChooser.ShowDialog();
            taxpayerFile = taxpayerFileChooser.FileName;
            taxpayerFileChooser.Dispose();

            if (taxpayerFile == "") //protect from crashing if user clicks cancel with if statement
            {
                //do nothing related to load
            }
            else
            {
                using (StreamReader fileReader = new StreamReader(taxpayerFile))
                {
                    while (fileReader.EndOfStream == false)
                    {
                        String[] properties; //an 'array': list is an array on steroids
                        String   line;

                        //update these declarations to match your object
                        String taxpayername; //input to constructor
                        double salary;       //input to constructor
                        double investment;
                        int    exemption;
                        bool   married;

                        line       = fileReader.ReadLine();
                        properties = line.Split(',');

                        //update these lines to match your object
                        taxpayername = properties[0];
                        salary       = int.Parse(properties[1]);
                        investment   = double.Parse(properties[2]);
                        exemption    = int.Parse(properties[3]);
                        married      = bool.Parse(properties[4]);
                        Taxpayer newTaxpayer;
                        newTaxpayer = new Taxpayer(taxpayername, salary, investment, exemption, married);
                        taxpayerBindingSource.Add(newTaxpayer);

                        if (married == true)
                        {
                            MarriedList.Add(newTaxpayer);
                        }
                        else
                        {
                            UnmarriedList.Add(newTaxpayer);
                        }
                        //end if statement
                    }
                    //end while
                }
                //end stream reader

                //set saved bool to false upon loading data
                savedBool = false;
            }
        }