// Calculate the surface material price based off the Desk object's surface material
    public void GetSurfaceMaterialPrice(Desk.SurfaceMaterial Material)
    {
        switch (Material)
        {
        case Desk.SurfaceMaterial.Oak:
            SurfaceMaterialPrice = 200;
            break;

        case Desk.SurfaceMaterial.Laminate:
            SurfaceMaterialPrice = 100;
            break;

        case Desk.SurfaceMaterial.Pine:
            SurfaceMaterialPrice = 50;
            break;

        case Desk.SurfaceMaterial.Rosewood:
            SurfaceMaterialPrice = 300;
            break;

        case Desk.SurfaceMaterial.Veneer:
            SurfaceMaterialPrice = 125;
            break;

        default:
            SurfaceMaterialPrice = 0;
            break;
        }
    }
Exemplo n.º 2
0
        private void materialTypeInput_SelectionChangeCommitted(object sender, EventArgs e)
        {
            Desk.SurfaceMaterial material = (Desk.SurfaceMaterial)materialTypeInput.SelectedItem;

            // Populate Grid
            DataTable table = new DataTable();

            table.Columns.Add("Date");
            table.Columns.Add("Material");
            table.Columns.Add("Width");
            table.Columns.Add("Depth");
            table.Columns.Add("Drawers");
            table.Columns.Add("Shipping");
            table.Columns.Add("Price");
            table.Columns.Add("Name");

            string text = File.ReadAllText(@"quotes.json");
            var    list = JsonConvert.DeserializeObject <List <DeskQuote> >(text);

            foreach (var item in list)
            {
                if (item.Desk.Material == material)
                {
                    table.Rows.Add(item.Date, item.Desk.Material, item.Desk.Width, item.Desk.Depth, item.Desk.Drawers, item.Shipping, item.Price, item.Customer);
                }
            }
            displayDataGrid.DataSource = table;
        }
Exemplo n.º 3
0
        private void materialTypeInput_SelectionChangeCommitted(object sender, EventArgs e)
        {
            Desk.SurfaceMaterial material = (Desk.SurfaceMaterial)materialTypeInput.SelectedItem;

            // Populate Grid
            DataTable table = new DataTable();

            table.Columns.Add("Shipping");
            table.Columns.Add("Name");
            table.Columns.Add("Date");
            table.Columns.Add("Width");
            table.Columns.Add("Depth");
            table.Columns.Add("Drawers");
            table.Columns.Add("Material");
            table.Columns.Add("Price");

            StreamReader sr = new StreamReader(@"../quotes.txt");

            while (!sr.EndOfStream)
            {
                string[] parts = sr.ReadLine().Split(',');
                if (parts[6] == material.ToString())
                {
                    table.Rows.Add(parts[0], parts[1], parts[2], parts[3], parts[4], parts[5], parts[6], parts[7]);
                }
            }

            displayDataGrid.DataSource = table;
        }
Exemplo n.º 4
0
        private void comboBoxMaterials_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBoxMaterials.SelectedIndex == -1)
            {
                txtQuotes.Text = "";
            }
            else
            {
                Desk.SurfaceMaterial material = EnumUtil.ParseEnum <Desk.SurfaceMaterial>(comboBoxMaterials.SelectedValue.ToString());
                var sb = new StringBuilder();

                foreach (DeskQuote deskQuote in deskQuotes)
                {
                    if (deskQuote.Desk.Material == material)
                    {
                        sb.AppendLine(deskQuote.ToString());
                    }
                }

                if (sb.Length != 0)
                {
                    txtQuotes.Text = DeskQuote.CSVHeader() + "\n" + sb.ToString();
                }
                else
                {
                    txtQuotes.Text = sb.ToString();
                }
            }
        }
Exemplo n.º 5
0
        private void submitAddNewQuoteBtn_Click(object sender, EventArgs e)
        {
            try
            {
                if (nameInput.Text == "" || surfaceInput.SelectedItem == null || timeInput.SelectedItem == null)
                {
                    throw new ArgumentNullException();
                }
            }
            catch (ArgumentNullException f)
            {
                MessageBox.Show("Fields cannot be empty.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            widthInput.ReadOnly   = true;
            depthInput.ReadOnly   = true;
            drawersInput.ReadOnly = true;
            surfaceInput.Enabled  = false;
            timeInput.Enabled     = false;
            nameInput.ReadOnly    = true;

            decimal width   = widthInput.Value;
            decimal depth   = depthInput.Value;
            int     drawers = (int)drawersInput.Value;

            Desk.SurfaceMaterial deskMaterial = (Desk.SurfaceMaterial)surfaceInput.SelectedItem;
            DeskQuote.Delivery   shipping     = (DeskQuote.Delivery)timeInput.SelectedItem;
            string   name = nameInput.Text;
            DateTime date = DateTime.Today;

            Desk      desk  = new Desk(width, depth, drawers, deskMaterial);
            DeskQuote quote = new DeskQuote(desk, shipping, name, date);

            priceOutput.Text    = quote.Price.ToString();
            priceOutput.Visible = true;
            priceLabel.Visible  = true;

            string filepath = "quotes.json";

            if (File.Exists(filepath))
            {
                string text = File.ReadAllText(filepath);
                var    list = JsonConvert.DeserializeObject <List <DeskQuote> >(text);
                list.Add(quote);
                var convertedJson = JsonConvert.SerializeObject(list, Formatting.Indented);
                File.WriteAllText(filepath, convertedJson);
            }
            else
            {
                List <DeskQuote> list = new List <DeskQuote>();
                list.Add(quote);
                var convertedJson = JsonConvert.SerializeObject(list, Formatting.Indented);
                File.WriteAllText(filepath, convertedJson);
            }
        }
Exemplo n.º 6
0
        public Desk(int width, int depth, int drawers, Desk.SurfaceMaterial material)
        {
            Guid id = Guid.NewGuid();

            DeskId   = id;
            Width    = width;
            Depth    = depth;
            Drawers  = drawers;
            Material = material;
        }
        // Populate the surface material drop downlist
        public void populateDDLSurfaceMaterials()
        {
            // Requirement 3
            List <Desk.SurfaceMaterial> list = new List <Desk.SurfaceMaterial>();

            for (int i = 0; i < 5; i++)
            {
                Desk.SurfaceMaterial item = (Desk.SurfaceMaterial)Enum.ToObject(typeof(Desk.SurfaceMaterial), i);
                list.Add(item);
            }

            ddlSurfaceMaterials.DataSource = list;
        }
Exemplo n.º 8
0
        private void submitAddNewQuoteBtn_Click(object sender, EventArgs e)
        {
            try
            {
                if (nameInput.Text == "" || surfaceInput.SelectedItem == null || timeInput.SelectedItem == null)
                {
                    throw new ArgumentNullException();
                }
            }
            catch (ArgumentNullException f)
            {
                MessageBox.Show("Fields cannot be empty.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            widthInput.ReadOnly   = true;
            depthInput.ReadOnly   = true;
            drawersInput.ReadOnly = true;
            surfaceInput.Enabled  = false;
            timeInput.Enabled     = false;
            nameInput.ReadOnly    = true;

            decimal width   = widthInput.Value;
            decimal depth   = depthInput.Value;
            int     drawers = (int)drawersInput.Value;

            Desk.SurfaceMaterial deskMaterial = (Desk.SurfaceMaterial)surfaceInput.SelectedItem;
            DeskQuote.Delivery   shipping     = (DeskQuote.Delivery)timeInput.SelectedItem;
            string   name = nameInput.Text;
            DateTime date = new DateTime();

            Desk      desk  = new Desk(width, depth, drawers, deskMaterial);
            DeskQuote quote = new DeskQuote(desk, shipping, name, date);

            decimal price = quote.GetQuote(desk, quote);

            priceOutput.Text    = price.ToString();
            priceOutput.Visible = true;
            priceLabel.Visible  = true;

            TextWriter file = new StreamWriter(@"../quotes.txt", true);

            file.WriteLine(quote.Shipping + "," + quote.Customer + "," + quote.Date + "," + desk.Width + "," + desk.Depth + "," + desk.Drawers + "," + desk.Material + "," + price);
            file.Close();
        }
 // Get the desk object's surface material depending on what radio button is checked
 public void getSurfaceMaterial(Desk desk)
 {
     Desk.SurfaceMaterial material = (Desk.SurfaceMaterial)Enum.ToObject(typeof(Desk.SurfaceMaterial), ddlSurfaceMaterials.SelectedIndex);
     desk.Material = material;
 }