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.drawers = 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 { Task newt = new Task(async() => { StorageFolder storageFolder = ApplicationData.Current.LocalFolder; StorageFile sampleFile = await storageFolder.CreateFileAsync("Quotes.json", CreationCollisionOption.OpenIfExists); //StorageFolder storageFolder = ApplicationData.Current.LocalFolder; StorageFile quotesFile = await storageFolder.GetFileAsync(name: "Quotes.json"); string jsonString = Environment.NewLine + JsonConvert.SerializeObject(this); await FileIO.AppendTextAsync(quotesFile, jsonString); }); newt.Start(); } catch (IOException e) { } }
public void calculatePrice(Desk desk, AddQuote addQuote) { int basePrice = 200; int deskSurface = desk.depth * desk.width; int drawersPrice = desk.drawers * 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 (deskSurface > 1000) { extraSurfacePrice = deskSurface - 1000; } switch (addQuote.getMaterial()) { case "Oak": materialPrice = (int)Desk.desktopMaterials.Oak; break; case "Laminate": materialPrice = (int)Desk.desktopMaterials.Laminate; break; case "Pine": materialPrice = (int)Desk.desktopMaterials.Pine; break; case "Rossewood": materialPrice = (int)Desk.desktopMaterials.Rossewood; break; case "Veneer": materialPrice = (int)Desk.desktopMaterials.Veneer; break; default: materialPrice = 0; break; } if (deskSurface > 0 && deskSurface < 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 (deskSurface >= 1000 && deskSurface <= 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 = basePrice + extraSurfacePrice + drawersPrice + rushDaysPrice + materialPrice; }