public void writeJSONFile(string file, AddQuote addQuote) { desk = new Desk(); desk.width = addQuote.getDeskDepth(); desk.depth = addQuote.getDeskWidth(); desk.size = addQuote.getDeskDepth() * addQuote.getDeskWidth(); desk.numOfDrawers = addQuote.getDeskDrawers(); desk.material = addQuote.getMaterial(); this.clientName = addQuote.getClientName(); this.rushDays = addQuote.getRushDays(); this.calculatePrice(desk, addQuote); this.date = addQuote.getDate(); addQuote.setSize(desk.size); addQuote.setPrice(this.price); try { StreamWriter sw = new StreamWriter(file, append: true); string jsonString = JsonConvert.SerializeObject(this); sw.WriteLine(jsonString); sw.Close(); } catch (IOException e) { } }
public void calculatePrice(Desk desk, AddQuote addQuote) { int calcSA = desk.depth * desk.width; int drawersPrice = desk.numOfDrawers * 50; int rushDays = this.rushDays; int extraSurfacePrice = 0; int rushDaysPrice = 0; int materialPrice = 0; int [,] extraCharges = new int[3, 3]; extraCharges = getRushOrder("rushOrderPrices.txt"); if (calcSA > 1000) { extraSurfacePrice = calcSA - 1000; } switch (addQuote.getMaterial()) { case "Oak": materialPrice = (int)Desk.DesktopMaterial.Oak; price += 200; break; case "Laminate": materialPrice = (int)Desk.DesktopMaterial.Laminate; price += 100; break; case "Pine": materialPrice = (int)Desk.DesktopMaterial.Pine; price += 50; break; case "Rosewood": materialPrice = (int)Desk.DesktopMaterial.Rosewood; price += 300; break; case "Veneer": materialPrice = (int)Desk.DesktopMaterial.Veneer; price += 125; break; default: materialPrice = 0; break; } if (calcSA > 0 && calcSA < 1000) { switch (rushDays) { case 3: rushDaysPrice = extraCharges[0, 0]; break; case 5: rushDaysPrice = extraCharges[0, 1]; break; case 7: rushDaysPrice = extraCharges[0, 2]; break; default: rushDaysPrice = 0; break; } } else if (calcSA >= 1000 && calcSA <= 2000) { switch (rushDays) { case 3: rushDaysPrice = extraCharges[1, 0]; break; case 5: rushDaysPrice = extraCharges[1, 1]; break; case 7: rushDaysPrice = extraCharges[1, 2]; break; default: rushDaysPrice = 0; break; } } else { switch (rushDays) { case 3: rushDaysPrice = extraCharges[2, 0]; break; case 5: rushDaysPrice = extraCharges[2, 1]; break; case 7: rushDaysPrice = extraCharges[2, 2]; break; default: rushDaysPrice = 0; break; } } this.price = 200 + extraSurfacePrice + drawersPrice + rushDaysPrice + materialPrice; }