public string B() { string group = "HeatingByMotor"; string tagName = "SA"; string dryBulbTag = "FIX.SA_DBT.F_CV"; string absoluteHumidityTag= "FIX.SA_AH.F_CV"; double dryBulbValue = 0; double absoluteHumidityValue = 0; bool showTagName= false; string process = "HeatingByMotor"; RootObject root = new RootObject(); Tag t = new Tag(); t.group = group; t.tagName = tagName; t.dryBulbTag = dryBulbTag; t.dryBulbValue = dryBulbValue; t.absoluteHumidityTag = absoluteHumidityTag; t.absoluteHumidityValue = absoluteHumidityValue; t.showTagName = showTagName; List<Tag> tl = new List<Tag>(); tl.Add(t); Process p = new Process(); p.name = process; List<Process> pl = new List<Process>(); pl.Add(p); root.tags = tl; root.process = pl; string strJson = JsonConvert.SerializeObject(root, Formatting.Indented); System.IO.File.WriteAllText(@"C:\WriteText.json", strJson); return strJson; }
private void OnGeneratorButtonClick(object sender, EventArgs e) { try { SaveFileDialog saveFileDialog1 = new SaveFileDialog(); saveFileDialog1.Filter = "json files (*.json)|*.json"; saveFileDialog1.FileName = "FrontEndConfig"; if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK && saveFileDialog1.FileName.Length > 0) { string path = saveFileDialog1.FileName; RichTextBoxStreamType b = RichTextBoxStreamType.PlainText; //richTextBox1.SaveFile(saveFileDialog1.FileName, // RichTextBoxStreamType.PlainText); // System.IO.File.WriteAllText(path, strJson); RootObject root = new RootObject(); root.tags = this.tagList; root.process = this.processList; string strJson = JsonConvert.SerializeObject(root, Newtonsoft.Json.Formatting.Indented); System.IO.File.WriteAllText(path, strJson); MessageBox.Show("Success", "", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }