Example #1
0
        public ViewAllQuotes()
        {
            InitializeComponent();

            string cFile = @"quotes.json";

            using (StreamReader sr = new StreamReader(cFile))
            {
                string line;
                while ((line = sr.ReadLine()) != null)
                {
                    MegaDeskQuotes jsonList = JsonConvert.DeserializeObject <MegaDeskQuotes>(line);

                    string[] row = new string[]
                    {
                        jsonList.mdLastName,
                        jsonList.mdFirstName,
                        jsonList.mdOrderDate.ToString("dd MMM yyyy"),
                        jsonList.mdDeskType,
                        jsonList.mdWidth.ToString(),
                        jsonList.mdDepth.ToString(),
                        jsonList.mdNumOfDrawers.ToString(),
                        jsonList.mdTotalCost
                    };
                    gridQuotes.Rows.Add(row);
                }
            }
        }
Example #2
0
        public static void DeskCost(ref Desk testDesk, ref DeskQuote testQuote, ref DisplayQuotes viewDisplayQuotes)
        {
            // Variables
            float    squareInch, feeRush = 0, matFee = 0, exDays = 0, drawFee, topfee = 0, deskCost, width, depth, drawers, baseDeskPrice = (float)MegaConst.BaseDeskPrice;
            string   fName, lName, addrss, cty, rush, materials, stte, phone;
            DateTime orderDate, expDate = default;

            int[,] rushFee = new int[3, 3];

            //Assignment
            fName     = testQuote.firstName;
            lName     = testQuote.lastName;
            addrss    = testQuote.address;
            cty       = testQuote.city;
            stte      = testQuote.state;
            phone     = testQuote.phone;
            orderDate = testQuote.orderDate;
            depth     = testDesk.Depth;
            width     = testDesk.Width;
            drawers   = testDesk.NumOfDrawers;
            materials = testDesk.DeskType;
            rush      = testDesk.RushDays;


            // Area
            squareInch = depth * width;
            // Drawer fee math
            drawFee = (float)MegaConst.DrawerPrice * drawers;

            // Load rush costs into array
            rushFee = GetRushOrder();

            // Logic
            // Check for Rush
            if (rush != RushDays.Fourteen.ToString())
            {
                (feeRush, exDays) = RushFee(squareInch, rush, rushFee);
            }
            else
            {
                feeRush = 0;
                exDays  = 14;
            }

            // Check material fee
            switch (materials)
            {
            case "Oak":
                matFee = (float)MegaConst.OakPrice;
                break;

            case "Laminate":
                matFee = (float)MegaConst.LaminatePrice;
                break;

            case "Pine":
                matFee = (float)MegaConst.PinePrice;
                break;

            case "Rosewood":
                matFee = (float)MegaConst.RosewoodPrice;
                break;

            case "Veneer":
                matFee = (float)MegaConst.VeneerPrice;
                break;
            }

            // Check square foot fee
            if (squareInch > (float)MegaConst.BaseDeskSize)
            {
                topfee = (squareInch - (float)MegaConst.BaseDeskSize);
            }

            // Expected date math
            switch (rush)
            {
            case "Fourteen":
                expDate = orderDate.AddDays(14);
                break;

            case "Seven":
                expDate = orderDate.AddDays(7);
                break;

            case "Five":
                expDate = orderDate.AddDays(5);
                break;

            case "Three":
                expDate = orderDate.AddDays(3);
                break;
            }

            // Add it all up
            deskCost = feeRush + matFee + drawFee + topfee + baseDeskPrice;

            // Output for DisplayQuotes
            #region Output Display
            viewDisplayQuotes.FirstNameLabel.Text     = fName;
            viewDisplayQuotes.LastNameLabel.Text      = lName;
            viewDisplayQuotes.AddressLabel.Text       = addrss;
            viewDisplayQuotes.CityLabel.Text          = cty + ",";
            viewDisplayQuotes.StateLabel.Text         = stte;
            viewDisplayQuotes.PhoneLabel.Text         = phone;
            viewDisplayQuotes.MaterialLabel.Text      = materials;
            viewDisplayQuotes.WidthLabel.Text         = width.ToString();
            viewDisplayQuotes.DepthLabel.Text         = depth.ToString();
            viewDisplayQuotes.DrawersLabel.Text       = drawers.ToString();
            viewDisplayQuotes.DaysLabel.Text          = exDays.ToString();
            viewDisplayQuotes.BaseDeskPriceLabel.Text = "$" + baseDeskPrice.ToString();
            viewDisplayQuotes.MaterialFeeLabel.Text   = "$" + matFee.ToString();
            viewDisplayQuotes.DrawerFeeLabel.Text     = "$" + drawFee.ToString();
            viewDisplayQuotes.OversizeFeeLabel.Text   = "$" + topfee.ToString();
            viewDisplayQuotes.RushFeeLabel.Text       = "$" + feeRush.ToString();
            viewDisplayQuotes.OrderDate.Text          = orderDate.ToString("MMMM dd yyyy");
            viewDisplayQuotes.ExpectedDateLabel.Text  = expDate.ToString("MMMM dd yyyy");
            viewDisplayQuotes.TotalCostLabel.Text     = "$" + deskCost;
            #endregion

            MegaDeskQuotes megaDeskQuotes = new MegaDeskQuotes();

            megaDeskQuotes.mdFirstName    = fName;
            megaDeskQuotes.mdLastName     = lName;
            megaDeskQuotes.mdAddress      = addrss;
            megaDeskQuotes.mdCity         = cty;
            megaDeskQuotes.mdState        = stte;
            megaDeskQuotes.mdPhone        = phone;
            megaDeskQuotes.mdOrderDate    = orderDate;
            megaDeskQuotes.mdWidth        = width;
            megaDeskQuotes.mdDepth        = depth;
            megaDeskQuotes.mdNumOfDrawers = drawers;
            megaDeskQuotes.mdDeskType     = materials;
            megaDeskQuotes.mdRushDays     = rush;
            megaDeskQuotes.mdTotalCost    = "$" + deskCost.ToString();


            string result = JsonConvert.SerializeObject(megaDeskQuotes);
            string cFile  = @"quotes.json";
            if (!File.Exists(cFile))
            {
                using (StreamWriter sw = File.CreateText(cFile))
                {
                }
            }
            using (StreamWriter sw = File.AppendText(cFile))
            {
                sw.WriteLine(result);
            }
        }
Example #3
0
        private void SubButton_Click(object sender, EventArgs e)
        {
            // Get Selected desktype
            string selectMaterial = searchComboBox.Text;

            // Clear text from prior search
            searchGridView.Rows.Clear();
            searchResult.Text = "";

            // Catch exception for file reader
            try
            {
                // Create method to search JSON file with saved Quotes
                StreamReader readFile = new StreamReader(@"quotes.json");


                while (readFile.EndOfStream == false)
                {
                    // loop through file looking for selected material type
                    string         line          = readFile.ReadLine();
                    MegaDeskQuotes outDeskQuotes = JsonConvert.DeserializeObject <MegaDeskQuotes>(line);

                    // Catch exception for material type not found
                    try
                    {
                        if (outDeskQuotes.mdDeskType != selectMaterial)
                        {
                            // If type not found continue
                            continue;
                        }
                        else
                        {
                            // If type found write line
                            string[] row = new string[]
                            {
                                outDeskQuotes.mdFirstName,
                                outDeskQuotes.mdLastName,
                                outDeskQuotes.mdOrderDate.ToString(),
                                outDeskQuotes.mdWidth.ToString(),
                                outDeskQuotes.mdDepth.ToString(),
                                outDeskQuotes.mdDeskType,
                                outDeskQuotes.mdNumOfDrawers.ToString(),
                                outDeskQuotes.mdRushDays,
                                outDeskQuotes.mdTotalCost
                            };
                            searchGridView.Rows.Add(row);
                        }
                    }
                    catch (Exception exception)
                    {
                        Console.WriteLine(exception);
                    }
                }

                // Close reader
                readFile.Close();

                // Check for rows added, if none added, msg
                int rowCount = searchGridView.Rows.Count;
                searchResult.Text = rowCount > 1 ? "" :  selectMaterial + " orders do not exist.";
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }