Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. using Newtonsoft.Json;
  2. using Newtonsoft.Json.Linq;
  3. using System;
  4. using System.IO;
  5. using System.Windows.Forms;
  6.  
  7. namespace IGEA
  8. {
  9. public partial class Form1 : Form
  10. {
  11. public Form1()
  12. {
  13. InitializeComponent();
  14. }
  15.  
  16. private void Form1_Load(object sender, EventArgs e)
  17. {
  18.  
  19. //Procitaj .json shemu
  20. string shema = File.ReadAllText("IGEA.schema.json");
  21.  
  22. //Procitaj json
  23. JObject result = JObject.Parse(shema);
  24.  
  25. //Za svaki input
  26. int id_polja = 0;
  27. foreach (var input in result["properties"])
  28. {
  29. //Za svaki element inputa (type, description)
  30. string tip, opis="";
  31. foreach (var a in input)
  32. {
  33. if (a["type"].ToString().Equals("array")) continue; //Onaj zadnji input preskacemo
  34.  
  35. tip = a["type"].ToString();
  36. opis = a["description"].ToString();
  37. }
  38.  
  39. TextBox tb = new TextBox();
  40. tb.Location = new System.Drawing.Point(180, (id_polja * 20) + 10);
  41. tb.Name = opis;
  42. tb.Width = 200;
  43. this.Controls.Add(tb);
  44.  
  45. Label lb = new Label();
  46. lb.Text = opis;
  47. lb.Width = 200;
  48. lb.Location = new System.Drawing.Point(10, (id_polja * 20) + 10);
  49. this.Controls.Add(lb);
  50.  
  51. id_polja++;
  52. }
  53.  
  54. Button bt = new Button();
  55. bt.Text = "Spremi";
  56. bt.Location = new System.Drawing.Point(10, (id_polja * 20) + 10);
  57. bt.Click += new System.EventHandler(this.onClickEvent);
  58. this.Controls.Add(bt);
  59. }
  60.  
  61. private void onClickEvent(object sender, EventArgs e)
  62. {
  63. dynamic jsonObject = new JObject();
  64.  
  65. foreach (Control c in Controls)
  66. {
  67. if (c is TextBox) jsonObject[c.Name] = c.Text;
  68. }
  69.  
  70. File.WriteAllText("studenti.json", JsonConvert.SerializeObject(jsonObject));
  71. MessageBox.Show("Spremljeno");
  72. }
  73.  
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement