public Form1() { InitializeComponent(); _tubeData = new TubeData { Name = "No Name", TubeWall = 1, TubeOD = 1 }; tubeDataBindingSource.DataSource = _tubeData; }
private void BtnImportFromText_Click(object sender, EventArgs e) { const string title = "Import Tube Data from Text File"; string fileName = GetFileNameFromOpenDialog(textFilePattern, title); if (!string.IsNullOrWhiteSpace(fileName)) { string text = File.ReadAllText(fileName); _tubeData = JsonConvert.DeserializeObject <TubeData>(text); tubeDataBindingSource.DataSource = _tubeData; } }
private void BtnImportFromXml_Click(object sender, EventArgs e) { const string title = "Import Tube Data from Xml File"; string fileName = GetFileNameFromOpenDialog(xmlFilePattern, title); if (!string.IsNullOrWhiteSpace(fileName)) { string fileContent = File.ReadAllText(fileName); XmlDocument doc = new XmlDocument(); doc.LoadXml(fileContent); fileContent = JsonConvert.SerializeXmlNode(doc); JObject json = JObject.Parse(fileContent); _tubeData = JsonConvert.DeserializeObject <TubeData>(json.First.First.ToString()); tubeDataBindingSource.DataSource = _tubeData; } }