lu
2025-11-08 ab6b5aaa9c12693003410e1b836d466340793c21
DevApp/Gs.DevApp/XtraForm1.cs
@@ -1,7 +1,9 @@
using DevExpress.XtraEditors;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NModbus;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
@@ -262,5 +264,124 @@
        {
            MessageBox.Show("d");
        }
        private void button1_Click(object sender, EventArgs e)
        {
            string json = @"{
            ""100℃"": {
                ""temp"": ""94"",
                ""150ml"": ""143"",
                ""250ml"": ""241"",
                ""500ml"": ""482"",
                ""750ml"": ""732""
            },
            ""85℃"": {
                ""temp"": ""86"",
                ""150ml"": ""146"",
                ""250ml"": ""238"",
                ""500ml"": ""495"",
                ""750ml"": ""739""
            },
            ""60℃"": {
                ""temp"": ""62"",
                ""150ml"": ""152"",
                ""250ml"": ""244"",
                ""500ml"": ""499"",
                ""750ml"": ""745""
            },
            ""45℃"": {
                ""temp"": ""48"",
                ""150ml"": ""158"",
                ""250ml"": ""246"",
                ""500ml"": ""506"",
                ""750ml"": ""778""
            },
            ""常温水"": {
                ""temp"": ""29"",
                ""150ml"": ""161"",
                ""250ml"": ""249"",
                ""500ml"": ""504"",
                ""750ml"": ""781""
            }
        }";
            System.Text.StringBuilder sbLine = new StringBuilder();
            var data = JsonConvert.DeserializeObject<Dictionary<string, Dictionary<string, string>>>(json);
            List<string> resultLines = new List<string>();
            foreach (var entry in data)
            {
                string key = entry.Key;
                var values = entry.Value;
                string temp = values["temp"];
                sbLine.Append(key + "/" + temp + ":");
                System.Text.StringBuilder dbdb = new StringBuilder();
                foreach (var dddddd in values)
                {
                    if (dddddd.Key == "temp")
                        continue;
                    dbdb.Append(dddddd.Key+"-"+ dddddd.Value + "、");
                }
                sbLine.Append(dbdb.ToString()+"\n");
            }
            richTextBox1.Text = sbLine.ToString();
        }
        private void simpleButton3_Click(object sender, EventArgs e)
        {
            string ddd = "1";
            try
            {
                if (IsValidDate(ddd, "日期"))
                    MessageBox.Show("正常");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        /// <summary>
        /// 判断是否为日期
        /// </summary>
        /// <param name="dateString"></param>
        /// <returns></returns>
        public  bool IsValidDate(string dateString, string ziDuan = "")
        {
            bool bl = DateTime.TryParse(dateString, out _);
            if (bl == true)
                return bl;
            if (string.IsNullOrEmpty(ziDuan))
                return bl;
            throw new Exception(ziDuan + "不是合法的日期类型!");
        }
        private void simpleButton4_Click(object sender, EventArgs e)
        {
            Toast vm = new Toast(0, simpleButton4.Text);
            vm.Show();
            return;
        }
        private void simpleButton5_Click(object sender, EventArgs e)
        {
            Toast vm = new Toast(0, simpleButton5.Text);
            vm.Show();
            return;
        }
        private void simpleButton6_Click(object sender, EventArgs e)
        {
            Toast vm = new Toast(0, simpleButton6.Text);
            vm.Show();
            return;
        }
        private void simpleButton7_Click(object sender, EventArgs e)
        {
            Toast vm = new Toast(0, simpleButton7.Text);
            vm.Show();
            return;
        }
    }
}