Exemplo n.º 1
0
        private void buttonSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                CustomerName = boxName.Text;
                DeskWidth    = int.Parse(boxWidth.Text);
                DeskDepth    = int.Parse(boxDepth.Text);
                Drawers      = int.Parse(comboBoxDrawers.SelectedItem.ToString());
                Material     = (Desk.Material)comboBoxMaterial.SelectedValue;

                // Get rush order days base on radio box selections
                if (radioRushNone.Checked)
                {
                    RushDays = 0;
                }
                if (radioRush3.Checked)
                {
                    RushDays = 3;
                }
                if (radioRush5.Checked)
                {
                    RushDays = 5;
                }
                if (radioRush7.Checked)
                {
                    RushDays = 7;
                }

                // create new deskOrder and calcQuote
                DeskQuote NewQuote = new DeskQuote(CustomerName, DateTime.Now, DeskWidth, DeskDepth, Drawers, Material, RushDays);
                QuoteTotal = NewQuote.CalcQuote();

                //build string to quote save to file
                //var DeskFileWrite = CustomerName + "," + DateTime.Now + "," + DeskWidth + "," + DeskDepth + "," + Drawers + "," + Material + "," + RushDays + "," + QuoteTotal;
                //var DeskFileWrite = NewQuote;

                // ask how to do this without making all of the properties public because I know they are in and can be used
                // I just have no idea how to get the Serializer to get them when they are "private".
                string jsonWrite = JsonConvert.SerializeObject(NewQuote);
                string jsonFile  = @"quotes.json";

                if (!File.Exists(jsonFile))
                {
                    using (StreamWriter sw = File.CreateText(jsonFile)) { }
                }
                using (StreamWriter swa = File.AppendText(jsonFile)) { swa.WriteLine(jsonWrite); }

                //MessageBox.Show("Quote Submitted");
                DisplayQuote display  = new DisplayQuote();
                MainMenu     mainMenu = new MainMenu();
                display.Tag                = mainMenu;
                display.nameLabel.Text     = boxName.Text;
                display.dateLabel.Text     = DateTime.Now.ToShortDateString();
                display.widthLabel.Text    = boxWidth.Text + " inches";
                display.depthLabel.Text    = boxDepth.Text + " inches";
                display.drawerLabel.Text   = comboBoxDrawers.SelectedItem.ToString();
                display.materialLabel.Text = comboBoxMaterial.SelectedItem.ToString();
                display.Show(this);
                Hide();

                confirmQuotePanel.Visible = false;
            }
            catch (Exception)
            {
                throw;
            }
        }