Пример #1
0
        private void submitQuote_Click(object sender, EventArgs e)
        {
            string ship = shippingBox.Text;

            switch (ship)
            {
            case "3 Days":
                shippingBox.Tag = 3;
                break;

            case "5 Days":
                shippingBox.Tag = 5;
                break;

            case "7 Days":
                shippingBox.Tag = 7;
                break;

            case "14 Days":
                shippingBox.Tag = 14;
                break;

            default:
                shippingBox.Tag = 14;
                break;
            }

            int          shipDays  = (int)shippingBox.Tag;
            DisplayQuote viewQuote = new DisplayQuote(nameBox.Text, depthBox.Text,
                                                      widthBox.Text, drawerSelection.Text, materialSelection.Text, shipDays);
            // Jose Concha
            int deskWidth        = 0;
            int deskWidthValue   = 0;
            int deskDepth        = 0;
            int deskDepthValue   = 0;
            int deskDrawers      = 0;
            int deskDrawersValue = 0;

            if (int.TryParse(widthBox.Text, out deskWidthValue))
            {
                deskWidth = deskWidthValue;
            }
            else
            {
                return;
            }
            if (int.TryParse(depthBox.Text, out deskDepthValue))
            {
                deskDepth = deskDepthValue;
            }
            else
            {
                return;
            }
            if (int.TryParse(drawerSelection.Text, out deskDrawersValue))
            {
                deskDrawers = deskDrawersValue;
            }
            else
            {
                return;
            }

            //Desk desk = new Desk(deskDepth, deskWidth, deskDrawers, materialSelection.Text);
            DeskQuote deskQuote = new DeskQuote(nameBox.Text, deskDepth, deskWidth,
                                                deskDrawers, materialSelection.Text, shipDays);
            string jsonWrite = JsonConvert.SerializeObject(deskQuote);
            string jsonFile  = @"quotes.json";

            try
            {
                if (!File.Exists(jsonFile))
                {
                    using (StreamWriter sw = File.CreateText(jsonFile)) { }
                }
                using (StreamWriter swa = File.AppendText(jsonFile)) { swa.WriteLine(jsonWrite); }
            }
            catch (IOException err)
            {
                // Extract some information from this exception, and then
                // throw it to the parent method.
                if (err.Source != null)
                {
                    Console.WriteLine("IOException source: {0}", err.Source);
                }
                throw;
            }
            viewQuote.Tag = this.Tag;
            viewQuote.Show(this);
            this.Hide();
        }