Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using Newtonsoft.Json;
- using System.Net;
- using GMap.NET.MapProviders;
- namespace Form_JSON_test
- {
- public partial class Form1 : Form
- {
- int numberOfCars = 0;
- dynamic dobj;
- private void loadDataToTable()
- {
- listView1.Items.Clear();
- for (int i = 0; i <= numberOfCars; i++)
- {
- ListViewItem id = new ListViewItem(dobj[i]["Id"].ToString());
- id.SubItems.Add(dobj[i]["Name"].ToString());
- id.SubItems.Add(dobj[i]["Type"].ToString());
- id.SubItems.Add(dobj[i]["SerialNumber"].ToString());
- id.SubItems.Add(dobj[i]["Strength"].ToString());
- id.SubItems.Add(dobj[i]["BatteryLevel"].ToString());
- id.SubItems.Add(dobj[i]["WorkingMode"].ToString());
- listView1.Items.Add(id);
- }
- }
- private void getData(int jid = 0)
- {
- try
- {
- WebClient client = new WebClient();
- string jsonToDecode = client.DownloadString("http://localhost:8080/radios");
- dobj = JsonConvert.DeserializeObject<dynamic>(jsonToDecode);
- numberOfCars = JsonConvert.DeserializeObject<List<Car>>(jsonToDecode).Count()-1;
- numericUpDown1.Maximum = numberOfCars;
- textBox1.Text = jsonToDecode.ToString();
- loadDataToTable();
- }
- catch (Exception ee)
- {
- listView1.Items.Clear();
- if(MessageBox.Show(ee.Message + " Would you like to retry?", "ERROR", MessageBoxButtons.YesNo, MessageBoxIcon.Error)
- == DialogResult.Yes)
- {
- getData();
- }
- textBox1.Text = ee.Message;
- }
- }
- private void setupTable()
- {
- listView1.View = View.Details;
- listView1.FullRowSelect = true;
- listView1.Columns.Add("ID", 30);
- listView1.Columns.Add("Name", 80);
- listView1.Columns.Add("Type", 100);
- listView1.Columns.Add("Serial Number", 150);
- listView1.Columns.Add("Signal Strength", 120);
- listView1.Columns.Add("Battery Level", 120);
- listView1.Columns.Add("Working mode", 150);
- }
- private void setupGmap(double lat, double longt)
- {
- map.DragButton = MouseButtons.Left;
- map.MapProvider = GMapProviders.GoogleMap;
- map.Position = new GMap.NET.PointLatLng(lat, longt);
- map.MinZoom = 1;
- map.MaxZoom = 100;
- map.Zoom = 10;
- }
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- setupTable();
- getData();
- setupGmap(12.2, 12.4);
- }
- private void numericUpDown1_ValueChanged(object sender, EventArgs e)
- {
- getData((int)numericUpDown1.Value);
- }
- }
- }
RAW Paste Data