private void button1_Click(object sender, EventArgs e) { string consumerFullname = consumerFullNameTextbox.Text; int deskWidth = 0; int deskWidthValue = 0; if (int.TryParse(deskWidthTextbox.Text, out deskWidthValue)) { deskWidth = deskWidthValue; } else { return; } int deskDepth = 0; int deskDepthValue = 0; if (int.TryParse(deskDepthTextbox.Text, out deskDepthValue)) { deskDepth = deskDepthValue; } else { return; } int nDrawers = int.Parse(nDrawersCombobox.Text); string desktopSurface = surfaceCombobox.Text; int rushTime = int.Parse(buildTimeCombobox.Text); // ===== DEBUG ===== /* string message = String.Format("Consumer Name: {0}\ndeskWidth: {1}\ndeskDepth: {2}\n" + * "Drawers: {3}\nsurface: {4}\nrush: {5}", consumerFullname, deskWidth, deskDepth, * nDrawers, desktopSurface, rushTime); * MessageBox.Show(message, "Debug"); */ // Creamos objectos segun los parametros entregados Desk desk = new Desk(deskWidth, deskDepth, nDrawers, desktopSurface); DeskQuote deskQuote = new DeskQuote(desk, rushTime, consumerFullname); // Obtenemos el directorio donde se esta ejecutando el exe //Console.WriteLine(System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)); // Leer archivo // Verificar si tiene datos // Si tiene datos añadir este objeto al final // guardar y cerrar archivo // TODO. how to get the Serializer to get them when they are "private". // Se añade el json resultante del objecto 1 por linea 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; } // Display Quote Data DisplayQuote displayQuoteScreen = new DisplayQuote(deskQuote); // Show testDialog as a modal dialog and determine if DialogResult = OK. if (displayQuoteScreen.ShowDialog(this) == DialogResult.OK) { // Presionene Okay o X en la ventana genera un // DialogResult.OK // Cerramos esta ventana y vamos al Menu Principal this.Close(); this.refBack.Show(); } }