Example #1
0
        public FormAddItem(Form parent, GroceryItem item)
        {
            InitializeComponent();
            txtName.Select();
            myParent = parent;

            txtName.Text = item.Name;
            numQuant.Value = item.Quantity;
            txtCost.Text = item.Cost.ToString();

            //select and deselect the txtCost to cause validation to occur
            txtCost.Select();
            txtName.Select();
            boxTax.Checked = item.Taxed;

            int payers = item.Payers;
            string payersString = ((Payer)payers).ToString();
            if (payersString.Contains("Ed"))
                boxEd.Checked = true;
            if (payersString.Contains("Matt"))
                boxMatt.Checked = true;
            if (payersString.Contains("Mel"))
                boxMel.Checked = true;
            if (payersString.Contains("Mike"))
                boxMike.Checked = true;
        }
Example #2
0
        private void btnEditItem_Click(object sender, EventArgs e)
        {
            if (listItems.SelectedItems.Count == 0)
            {
                statusLabel.Text = "Must select an item to edit.";
                return;
            }

            //Get the item to be edited and send it back to the AddItem form
            ListViewItem selectedItem = listItems.SelectedItems[0];
            int selectedItemIndex = selectedItem.Index;
            GroceryItem selectedGroceryItem = new GroceryItem (selectedItem);
            FormAddItem addItemForm = new FormAddItem(this, selectedGroceryItem);

            DialogResult result = addItemForm.ShowDialog();

            if (result == System.Windows.Forms.DialogResult.OK)
                listItems.Items.Remove(selectedItem);

            //since our new item is in the last position of the list,
            //move it back to where it was
            ListViewItem editedItem = addItemForm.getLastItemAdded();

            listItems.Items.Remove(editedItem);
            listItems.Items.Insert(selectedItemIndex, editedItem);

            SavedSinceModified = false;
        }
Example #3
0
        private void btnEditItem_Click(object sender, EventArgs e)
        {
            if (listItems.SelectedItems.Count == 0)
            {
                statusLabel.Text = "Must select an item to edit.";
                return;
            }

            //Get the item to be edited and send it back to the AddItem form
            ListViewItem selectedItem        = listItems.SelectedItems[0];
            int          selectedItemIndex   = selectedItem.Index;
            GroceryItem  selectedGroceryItem = new GroceryItem(selectedItem);
            FormAddItem  addItemForm         = new FormAddItem(this, selectedGroceryItem);

            DialogResult result = addItemForm.ShowDialog();

            if (result == System.Windows.Forms.DialogResult.OK)
            {
                listItems.Items.Remove(selectedItem);
            }

            //since our new item is in the last position of the list,
            //move it back to where it was
            ListViewItem editedItem = addItemForm.getLastItemAdded();

            listItems.Items.Remove(editedItem);
            listItems.Items.Insert(selectedItemIndex, editedItem);

            SavedSinceModified = false;
        }
Example #4
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (txtName.Text == "")
            {
                toolStripStatusLabel1.Text = "Enter an item name!";
                System.Media.SystemSounds.Exclamation.Play();
                return;
            }

            int quantity = (int)numQuant.Value;

            if (txtCost.Text == "")
            {
                toolStripStatusLabel1.Text = "Enter an item cost!";
                System.Media.SystemSounds.Exclamation.Play();
                return;
            }

            //make sure at least one checkbox is checked
            if (!boxEd.Checked && !boxMatt.Checked && !boxMel.Checked && !boxMike.Checked)
            {
                toolStripStatusLabel1.Text = "Check at least one person!";
                System.Media.SystemSounds.Exclamation.Play();
                return;
            }

            decimal cost;

            decimal.TryParse(txtCost.Text.Substring(1), out cost);
            int payers = 0;

            if (boxEd.Checked)
            {
                payers += (int)Payer.Ed;
            }
            if (boxMatt.Checked)
            {
                payers += (int)Payer.Matt;
            }
            if (boxMel.Checked)
            {
                payers += (int)Payer.Mel;
            }
            if (boxMike.Checked)
            {
                payers += (int)Payer.Mike;
            }



            GroceryItem newItem = new GroceryItem(txtName.Text, cost, boxTax.Checked, payers, quantity);

            m_LastAddedItem = newItem.GetListItem();
            ((Form1)myParent).AddItem(m_LastAddedItem);
        }
Example #5
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (txtName.Text == "")
            {
                toolStripStatusLabel1.Text = "Enter an item name!";
                System.Media.SystemSounds.Exclamation.Play();
                return;
            }

            int quantity = (int)numQuant.Value;

            if (txtCost.Text == "")
            {
                toolStripStatusLabel1.Text = "Enter an item cost!";
                System.Media.SystemSounds.Exclamation.Play();
                return;
            }

            //make sure at least one checkbox is checked
            if (!boxEd.Checked && !boxMatt.Checked && !boxMel.Checked && !boxMike.Checked)
            {
                toolStripStatusLabel1.Text = "Check at least one person!";
                System.Media.SystemSounds.Exclamation.Play();
                return;
            }

            decimal cost;
            decimal.TryParse(txtCost.Text.Substring(1), out cost);
            int payers = 0;
            if (boxEd.Checked) payers += (int)Payer.Ed;
            if (boxMatt.Checked) payers += (int)Payer.Matt;
            if (boxMel.Checked) payers += (int)Payer.Mel;
            if (boxMike.Checked) payers += (int)Payer.Mike;

            GroceryItem newItem = new GroceryItem(txtName.Text, cost, boxTax.Checked, payers, quantity);
            m_LastAddedItem = newItem.GetListItem();
            ((Form1)myParent).AddItem(m_LastAddedItem);
        }
Example #6
0
        private void loadFile(string filepath)
        {
            //open the file stream
            System.IO.StreamReader file = new System.IO.StreamReader(filepath);
            string line;
            string[] entries = new string[5];

            //clear our current list
            listItems.Items.Clear();

            //loop through all the items
            while (!file.EndOfStream)
            {
                line = file.ReadLine();
                entries = line.Split('\t');

                string name = entries[0];

                int quantity;
                int.TryParse(entries[1], out quantity);

                decimal cost;
                decimal.TryParse( entries[2].TrimStart('$'), out cost );

                bool taxed;
                if (entries[3] == "Y") taxed = true;
                else taxed = false;

                string payersString = entries[4];
                int payersInt = 0;

                if (payersString.Contains("Ed"))
                {
                    payersInt += (int)Payer.Ed;
                }
                if (payersString.Contains("Matt"))
                {
                    payersInt += (int)Payer.Matt;
                }
                if (payersString.Contains("Mel"))
                {
                    payersInt += (int)Payer.Mel;
                }
                if (payersString.Contains("Mike"))
                {
                    payersInt += (int)Payer.Mike;
                }

                GroceryItem item = new GroceryItem(name, cost, taxed, payersInt, quantity);
                AddItem(item.GetListItem());
            }

            file.Close();
        }
Example #7
0
        private void button1_Click(object sender, EventArgs e)
        {
            decimal totalCost = 0;
            decimal EdTotal = 0, MattTotal = 0, MelTotal = 0, MikeTotal = 0;

            foreach (ListViewItem item in listItems.Items)
            {
                decimal itemCost = decimal.Parse(item.SubItems[2].Text.Replace("$",""));
                bool taxable = (item.SubItems[3].Text == "Y");
                int quantity = int.Parse(item.SubItems[1].Text);
                if (taxable) itemCost *= 1 + TaxRate;
                itemCost *= quantity;
                totalCost += itemCost;
            }

            labelCost2.Text = "$" + totalCost.ToString("F");

            //loop through all the items
            for (int i = 0; i < listItems.Items.Count; i++)
            {
                ListViewItem item = listItems.Items[i];
                GroceryItem gItem = new GroceryItem(item);

                //calculate the cost of the item after tax

                decimal itemCost = gItem.Cost;

                if (gItem.Taxed)
                    itemCost *= 1 + TaxRate;

                //divide the cost of the item among all the people paying for it
                bool EdPay = false, MattPay = false, MelPay = false, MikePay = false;
                string payersString = ((Payer)gItem.Payers).ToString();
                int payerCount = 0;

                if (payersString.Contains("Ed"))
                {
                    payerCount++;
                    EdPay = true;
                }
                if (payersString.Contains("Matt"))
                {
                    payerCount++;
                    MattPay = true;
                }
                if (payersString.Contains("Mike"))
                {
                    payerCount++;
                    MikePay = true;
                }
                if (payersString.Contains("Mel"))
                {
                    payerCount++;
                    MelPay = true;
                }

                decimal splitCost = (itemCost * gItem.Quantity) / payerCount;

                if (EdPay) EdTotal += splitCost;
                if (MattPay) MattTotal += splitCost;
                if (MelPay) MelTotal += splitCost;
                if (MikePay) MikeTotal += splitCost;

            }

            decimal sumOfIndividualCosts = EdTotal + MattTotal + MelTotal + MikeTotal;
            if (sumOfIndividualCosts > totalCost + 1
                || sumOfIndividualCosts < totalCost - 1)
            {
                MessageBox.Show("Math went wrong somewhere. The sum of each person's share is "
                    + sumOfIndividualCosts.ToString() + " but it should equal the total cost, ie "
                    + totalCost.ToString() + ". We're off by $"
                    + (Math.Abs(sumOfIndividualCosts - totalCost).ToString() )  );
            }

            lblEdCost.Text = "$"   + Math.Round(EdTotal,2).ToString();
            lblMattCost.Text = "$" + Math.Round(MattTotal,2).ToString();
            lblMelCost.Text = "$"  + Math.Round(MelTotal, 2).ToString();
            lblMikeCost.Text = "$" + Math.Round(MikeTotal, 2).ToString();
        }
Example #8
0
        private void button1_Click(object sender, EventArgs e)
        {
            decimal totalCost = 0;
            decimal EdTotal = 0, MattTotal = 0, MelTotal = 0, MikeTotal = 0;

            foreach (ListViewItem item in listItems.Items)
            {
                decimal itemCost = decimal.Parse(item.SubItems[2].Text.Replace("$", ""));
                bool    taxable  = (item.SubItems[3].Text == "Y");
                int     quantity = int.Parse(item.SubItems[1].Text);
                if (taxable)
                {
                    itemCost *= 1 + TaxRate;
                }
                itemCost  *= quantity;
                totalCost += itemCost;
            }

            labelCost2.Text = "$" + totalCost.ToString("F");

            //loop through all the items
            for (int i = 0; i < listItems.Items.Count; i++)
            {
                ListViewItem item  = listItems.Items[i];
                GroceryItem  gItem = new GroceryItem(item);

                //calculate the cost of the item after tax

                decimal itemCost = gItem.Cost;

                if (gItem.Taxed)
                {
                    itemCost *= 1 + TaxRate;
                }

                //divide the cost of the item among all the people paying for it
                bool   EdPay = false, MattPay = false, MelPay = false, MikePay = false;
                string payersString = ((Payer)gItem.Payers).ToString();
                int    payerCount   = 0;

                if (payersString.Contains("Ed"))
                {
                    payerCount++;
                    EdPay = true;
                }
                if (payersString.Contains("Matt"))
                {
                    payerCount++;
                    MattPay = true;
                }
                if (payersString.Contains("Mike"))
                {
                    payerCount++;
                    MikePay = true;
                }
                if (payersString.Contains("Mel"))
                {
                    payerCount++;
                    MelPay = true;
                }


                decimal splitCost = (itemCost * gItem.Quantity) / payerCount;

                if (EdPay)
                {
                    EdTotal += splitCost;
                }
                if (MattPay)
                {
                    MattTotal += splitCost;
                }
                if (MelPay)
                {
                    MelTotal += splitCost;
                }
                if (MikePay)
                {
                    MikeTotal += splitCost;
                }
            }

            decimal sumOfIndividualCosts = EdTotal + MattTotal + MelTotal + MikeTotal;

            if (sumOfIndividualCosts > totalCost + 1 ||
                sumOfIndividualCosts < totalCost - 1)
            {
                MessageBox.Show("Math went wrong somewhere. The sum of each person's share is "
                                + sumOfIndividualCosts.ToString() + " but it should equal the total cost, ie "
                                + totalCost.ToString() + ". We're off by $"
                                + (Math.Abs(sumOfIndividualCosts - totalCost).ToString()));
            }



            lblEdCost.Text   = "$" + Math.Round(EdTotal, 2).ToString();
            lblMattCost.Text = "$" + Math.Round(MattTotal, 2).ToString();
            lblMelCost.Text  = "$" + Math.Round(MelTotal, 2).ToString();
            lblMikeCost.Text = "$" + Math.Round(MikeTotal, 2).ToString();
        }
Example #9
0
        private void loadFile(string filepath)
        {
            //open the file stream
            System.IO.StreamReader file = new System.IO.StreamReader(filepath);
            string line;

            string[] entries = new string[5];

            //clear our current list
            listItems.Items.Clear();

            //loop through all the items
            while (!file.EndOfStream)
            {
                line    = file.ReadLine();
                entries = line.Split('\t');

                string name = entries[0];

                int quantity;
                int.TryParse(entries[1], out quantity);

                decimal cost;
                decimal.TryParse(entries[2].TrimStart('$'), out cost);

                bool taxed;
                if (entries[3] == "Y")
                {
                    taxed = true;
                }
                else
                {
                    taxed = false;
                }

                string payersString = entries[4];
                int    payersInt    = 0;

                if (payersString.Contains("Ed"))
                {
                    payersInt += (int)Payer.Ed;
                }
                if (payersString.Contains("Matt"))
                {
                    payersInt += (int)Payer.Matt;
                }
                if (payersString.Contains("Mel"))
                {
                    payersInt += (int)Payer.Mel;
                }
                if (payersString.Contains("Mike"))
                {
                    payersInt += (int)Payer.Mike;
                }


                GroceryItem item = new GroceryItem(name, cost, taxed, payersInt, quantity);
                AddItem(item.GetListItem());
            }


            file.Close();
        }