Click here to Skip to main content
15,886,518 members
Articles / All Topics

What if Aristotle Were a Software Engineer?

Rate me:
Please Sign up or sign in to vote.
4.82/5 (11 votes)
6 Jan 2011CPOL20 min read 25.5K   77   23  
An introduction to philosophy-based patterns.
using System;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Furniture_Items;
using HistoryParam;

namespace ObjectHistoryWinSample
{
    public partial class TableEditor : Form
    {
        private Table m_Table;

        public TableEditor()
        {
            InitializeComponent();
        }

        public void Init(Table table)
        {
            // Keep the object for later use
            m_Table = table;

            // Model
            this.textBoxModel.Text = m_Table.Model;

            // Catalog ID
            this.textBoxCatalogID.Text = m_Table.CatalogID.ToString();

            // Width
            this.textBoxWidth.Text = m_Table.Width.ToString();

            // Heigt
            this.textBoxHeight.Text = m_Table.Height.ToString();

            // Length
            this.textBoxLength.Text = m_Table.Length.ToString();

            // Number of drawers / seats
            if (m_Table.GetType().Name.ToLower().IndexOf("writing") >= 0)
            {
                this.labelNumberOf.Text = "Drawers";
                this.textBoxNumberOf.Text = ((WritingTable)m_Table).NumberOfDrawers.ToString();
            }
            else // Dining table
            {
                this.labelNumberOf.Text = "Seats";
                this.textBoxNumberOf.Text = ((DiningRoomTable)m_Table).NumberOfSeats.ToString();
            }

            // Price
            HandlePrices();
        }

        private void HandlePrices()
        {
            listViewPrices.Items.Clear();

            ArrayList prices = m_Table.Price.History;
            for (int index = 0; index < prices.Count; ++index)
            {
                TimePeriodValuePair timePeriodValuePair = (TimePeriodValuePair)prices[index];
                ListViewItem lvi = new ListViewItem(timePeriodValuePair.From.ToShortDateString());
                lvi.SubItems.Add(timePeriodValuePair.Value.ToString());
                lvi.Tag = timePeriodValuePair;
                this.listViewPrices.Items.Add(lvi);
            }
        }

        private void buttonAdd_Click(object sender, EventArgs e)
        {
            EditPrice editPrice = new EditPrice();
            if (editPrice.ShowDialog() == DialogResult.OK)
            {
                m_Table.Price.AddValueByPeriod(editPrice.GetPrice(), editPrice.GetDate());
                HandlePrices();
            }
        }

        private void buttonEdit_Click(object sender, EventArgs e)
        {
            MessageBox.Show("To be developed", "TBD", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
        }

        private void buttonDelete_Click(object sender, EventArgs e)
        {
            MessageBox.Show("To be developed", "TBD", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Israel Israel
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions