public void readSalesFile(SalesCollection salesCollection)
        {
            if (File.Exists(salesLogFile))
            {
                using (StreamReader fileReader = new StreamReader(salesLogFile))
                {
                    while (!fileReader.EndOfStream)
                    {
                        string      line      = fileReader.ReadLine();
                        string[]    splitline = line.Split(',');
                        SalesPerson person    = new SalesPerson()
                        {
                            ID = splitline[0], Name = splitline[1], Amount = double.Parse(splitline[2])
                        };

                        salesCollection.AddRecord(person);
                    }
                }
            }
        }
Example #2
0
        private void btnIDFind_Click(object sender, EventArgs e)
        {
            errProvider.Clear();

            if (txtFindID.Text == string.Empty)
            {
                errProvider.SetError(txtFindID, "Input Required");
            }
            else
            {
                SalesPerson person = salesList.FindSale(txtFindID.Text);
                if (person != null)
                {
                    txtID.Text     = person.ID;
                    txtName.Text   = person.Name;
                    txtAmount.Text = $"{person.Amount}";
                }
                else
                {
                    MessageBox.Show("Record not found", "Find");
                }
            }
        }
Example #3
0
        private void btnAddSave_Click(object sender, EventArgs e)
        {
            errProvider.Clear();

            //use save state to determine what happpens with the form
            if (isSaveState)
            {
                if (ValidateData())
                {
                    SalesPerson person = new SalesPerson()
                    {
                        ID = txtID.Text, Name = txtName.Text, Amount = double.Parse(txtAmount.Text)
                    };

                    try
                    {
                        //add the record an clear necessary fields
                        salesList.AddRecord(person);
                        txtID.Items.Add(person.ID);
                        txtName.Text   = string.Empty;
                        txtAmount.Text = string.Empty;

                        isSaveState = SwitchState(isSaveState);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Error");
                    }
                }
            }
            else
            {
                //switch to save state if not in save mode
                isSaveState = SwitchState(isSaveState);
                clearFields();
            }
        }
 public void AddRecord(SalesPerson person)
 {
     salesList.Add(person.ID, person);
 }