Your Name 3 rokov pred
rodič
commit
4d4ba12c23

+ 15 - 0
WpfTest1/ComAgent/AutoReleaseObject.cs

@@ -0,0 +1,15 @@
+using System;
+
+namespace WpfTest1.ComAgent
+{
+    public class AutoReleaseObject<T> where T : IDisposable
+    {
+        public T reference { get; set; }
+
+        public AutoReleaseObject(T reference) => this.reference = reference;
+        ~AutoReleaseObject() => reference.Dispose();
+
+        public static implicit operator T(AutoReleaseObject<T> obj) => obj.reference;
+        public static implicit operator AutoReleaseObject<T>(T obj) => new AutoReleaseObject<T>(obj);
+    }
+}

+ 330 - 0
WpfTest1/ComAgent/ComAgent.cs

@@ -0,0 +1,330 @@
+using System;
+using System.Collections.Generic;
+using System.IO.Ports;
+using System.Linq;
+using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
+using System.Linq;
+using System.Collections.Concurrent;
+using System.Runtime.InteropServices;
+using WpfTest1.SmallDialogs.Debug;
+
+namespace WpfTest1.ComAgent
+{
+    public interface ComAgentListener
+    {
+        void comAgentReceiveData(byte[] data);
+        void comAgentConnected();
+        void comAgentDisconnected(Exception e);
+    }
+
+    public struct TreatmentStep
+    {
+        public ushort Hz { get; set; }
+        public byte T { get; set; }
+        public byte P { get; set; }
+        public ushort S { get; set; }
+
+        public TreatmentStep(ushort hz, byte t, byte p, ushort s)
+        {
+            Hz = hz;
+            T = t;
+            P = p;
+            S = s;
+        }
+    }
+
+    public class SingleInstance<T> where T : new()
+    {
+        private static T instance;
+
+        private static object lck = new object();
+
+        public static T getInstance(Func<T> allocator = null)
+        {
+            lock (lck)
+            {
+                if (instance != null) return instance;
+                instance = allocator != null ? allocator() : new T();
+                return instance;
+            }
+        }
+    }
+
+    public class ComAgent
+    {
+        public static byte[] createAnswerCommand(bool status) => 0x00.b().pack(status ? 0x54.b() : 0x46.b());
+        public static byte[] createHandshakeCommand() => 0x4B.b().pack(0x00.b());
+        public static byte[] createShutdownCommand() => 0x47.b().pack(0x00.b());
+        public static byte[] createIdleCommand() => 0x49.b().pack(0x00.b());
+        public static byte[] createChangeStrongthCommand(byte strongth) => 0x40.b().pack(strongth);
+
+        public static byte[] createStartDefinedCommand(int mode, ushort time, byte strongth)
+        {
+            List<byte> buff = new List<byte>();
+            switch (mode)
+            {
+                case 0: buff.Add(0x10); break;
+                case 1: buff.Add(0x11); break;
+                case 2: buff.Add(0x12); break;
+                case 3: buff.Add(0x13); break;
+                case 4: buff.Add(0x14); break;
+                case 5: buff.Add(0x25); break;
+                case 6: buff.Add(0x26); break;
+                case 7: buff.Add(0x27); break;
+                case 8: buff.Add(0x28); break;
+                case 9: buff.Add(0x29); break;
+                default: throw new ComException($"Invaild mode {mode}");
+            }
+            buff.Add(0x53);
+            buff.AddRange(time.buff());
+            buff.AddRange(strongth.buff());
+            buff.Add(0x00);
+            return buff.ToArray();
+        }
+
+        public static byte[] createStartManualCommand(ushort time, byte strongth, params TreatmentStep[] steps)
+        {
+            List<byte> buff = new List<byte>();
+            buff.Add(0x53);
+            buff.AddRange(time.buff());
+            buff.AddRange(strongth.buff());
+            buff.AddRange(((byte)steps.Length).buff());
+            foreach (TreatmentStep step in steps)
+            {
+                buff.AddRange(step.Hz.buff());
+                buff.AddRange(step.T.buff());
+                buff.AddRange(step.P.buff());
+                buff.AddRange(step.S.buff());
+            }
+            return buff.ToArray();
+        }
+
+        public static byte[] createStopCommand(byte mode = 0x30) => mode.pack(0x73.b());
+
+        private AutoReleaseObject<SerialPort> serial;
+        private Thread sendThread_, recvThread_;
+        private List<ComAgentListener> listeners;
+        public string[] blockingSerialPorts { get; set; }
+
+        public void addListener(ComAgentListener listener)
+        {
+            listeners.Add(listener);
+        }
+
+#if DEBUG
+        private SerialPortLogWindow window => SingleInstance<SerialPortLogWindow>.getInstance(() =>
+        {
+            SerialPortLogWindow win = null;
+            App.Current.Dispatcher.Invoke(() =>
+            {
+                win = new SerialPortLogWindow();
+                win.Show();
+            });
+            return win;
+        });
+
+        private SerialPortSetup setupWindow = SingleInstance<SerialPortSetup>.getInstance(() =>
+        {
+            SerialPortSetup win = null;
+            bool cont = false;
+            App.Current.Dispatcher.Invoke(() =>
+            {
+                win = new SerialPortSetup();
+                win.ShowDialog();
+                cont = true;
+            });
+            while (!cont) Thread.Sleep(10);
+            return win;
+        });
+#endif
+
+        void Log(string msg)
+        {
+#if DEBUG
+            window.Log($"[{DateTime.Now}] ${msg}");
+            Console.WriteLine(msg);
+#endif
+        }
+
+        public ComAgent()
+        {
+            sendThread_ = new Thread(sendThread) { IsBackground = true };
+            sendThread_.Start();
+            recvThread_ = new Thread(recvThread) { IsBackground = true };
+            recvThread_.Start();
+            listeners = new List<ComAgentListener>();
+            sendQueue = new ConcurrentQueue<byte[]>();
+
+#if DEBUG
+            //AllocConsole();
+            blockingSerialPorts = new string[] { "COM1" };
+#endif
+        }
+
+        private byte[] readPackage(SerialPort sp)
+        {
+            byte[] buff = new byte[2];
+            List<byte> data = new List<byte>();
+            while (true)
+            {
+                sp.read(buff, 1);
+                if (buff[0] != 0x10) continue;
+                sp.read(buff, 1);
+                if (buff[0] != 0x02) continue;
+                data.AddRange(new byte[2] { 0x10, 0x02 });
+                break;
+            }
+            while (true)
+            {
+                sp.read(buff, 1);
+                data.Add(buff[0]);
+                if (buff[0] == 0x10)
+                {
+                    sp.read(buff, 1);
+                    data.Add(buff[0]);
+                    if (buff[0] == 0x03) break;
+                }
+            }
+            return data.ToArray();
+        }
+
+        private byte[] readPackageAndUnpack(SerialPort sp) => readPackage(sp).unpackData();
+
+        private bool connect()
+        {
+#if DEBUG
+            AutoReleaseObject<SerialPort> com3 = new SerialPort(setupWindow.result, 9600);
+            com3.reference.Open();
+            serial = com3;
+            return true;
+#endif
+            string[] ports = (from it in SerialPort.GetPortNames()
+                              where !blockingSerialPorts.Contains(it)
+                              select it).ToArray();
+            List<Thread> sps = new List<Thread>();
+            serial = null;
+            for (int i = 0; i < ports.Length; i++)
+            {
+                string mport = ports[i];
+                Thread mth = new Thread(() =>
+                {
+                    AutoReleaseObject<SerialPort> sp = new SerialPort(mport, 9600);
+                    sp.reference.ReadTimeout = sp.reference.WriteTimeout = 1000;
+                    try
+                    {
+                        sp.reference.Open();
+                        sp.reference.send(createHandshakeCommand().packData());
+                        byte[] resp = readPackageAndUnpack(sp);
+                        if (serial != null) return;
+                        if (resp.bEquals(new byte[1] { 0x4B }))
+                            serial = sp;
+                    }
+                    catch (Exception e)
+                    {
+                        Log(e.ToString());
+                        sp.reference.shutdown();
+                    }
+                })
+                { IsBackground = true };
+                sps.Add(mth);
+                mth.Start();
+            }
+            while (true)
+            {
+                if ((from it in sps
+                     where it.IsAlive
+                     select it).Count() == 0) break;
+                if (serial != null) break;
+            }
+            return serial != null;
+        }
+
+        private ConcurrentQueue<byte[]> sendQueue;
+        private object serial_lock_w = new object(), serial_lock_r = new object();
+
+        public void enqueueCommand(byte[] buff) => sendQueue.Enqueue(buff.packData());
+
+        private void printBuff(string from, byte[] buff)
+        {
+            StringBuilder sb = new StringBuilder();
+            for (int i = 0; i < buff.Length; i++)
+            {
+                sb.AppendFormat("{0:x2} ", buff[i]);
+            }
+            Log(from + " " + sb.ToString());
+        }
+
+        private void sendThread()
+        {
+            while (true)
+            {
+                lock (serial_lock_w)
+                {
+                    if (serial == null)
+                    {
+                        while (!connect()) Thread.Sleep(10);
+                        listeners.ForEach(listener => listener.comAgentConnected());
+                    }
+                    try
+                    {
+                        if (!serial.reference.IsOpen) throw new ComException("Shutdown by client.");
+#if !DEBUG
+                        serial.reference.send(createIdleCommand());
+#endif
+                        while (sendQueue.TryDequeue(out byte[] buff))
+                        {
+                            serial.reference.send(buff);
+                            printBuff("ME -> Client", buff);
+                        }
+                    }
+                    catch (Exception e)
+                    {
+                        Log($"SendThread {e}");
+                        if (serial != null) serial.reference.shutdown();
+                        serial = null;
+                        listeners.ForEach(listener => listener.comAgentDisconnected(e));
+                    }
+                }
+                Thread.Sleep(10);
+            }
+        }
+
+        public void shutdown()
+        {
+            enqueueCommand(createShutdownCommand());
+        }
+
+        private void recvThread()
+        {
+            while (true)
+            {
+                lock (serial_lock_r)
+                {
+                    if (serial != null)
+                    {
+                        try
+                        {
+                            if (!serial.reference.IsOpen) throw new ComException("Shutdown by client.");
+                            byte[] data = readPackage(serial);
+                            printBuff("Client -> Me", data);
+                            data = data.unpackData();
+                            listeners.ForEach(listener => listener.comAgentReceiveData(data));
+                        }
+                        catch (Exception e)
+                        {
+                            Log($"RecvThread {e}");
+#if !DEBUG
+                            if (serial != null) serial.reference.shutdown();
+                            serial = null;
+                            listeners.ForEach(listener => listener.comAgentDisconnected(e));
+#endif
+                        }
+                    }
+                }
+                Thread.Sleep(10);
+            }
+        }
+    }
+}

+ 13 - 0
WpfTest1/ComAgent/ComException.cs

@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace WpfTest1.ComAgent
+{
+    public class ComException : Exception
+    {
+        public ComException(string msg) : base(msg) { }
+    }
+}

+ 165 - 0
WpfTest1/ComAgent/Extension.cs

@@ -0,0 +1,165 @@
+using System;
+using System.Collections.Generic;
+using System.IO.Ports;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+using uint16_t = System.UInt16;
+using uint8_t = System.Byte;
+
+namespace WpfTest1.ComAgent
+{
+	public unsafe static class Extension
+	{
+		public static uint16_t cal_crc(uint8_t[] ptr)
+		{
+			uint8_t i;
+			uint16_t crc = 0;
+			uint8_t num = 0;
+			int len = ptr.Length;
+			while (len-- != 0)
+			{
+				for (i = 0x80; i != 0; i /= 2)
+				{
+					if ((crc & 0x8000) != 0)
+					{
+						crc *= 2;
+						crc ^= 0x1021;
+					}
+					else
+						crc *= 2;
+					if ((ptr[num] & i) != 0)
+						crc ^= 0x1021;
+				}
+				num++;
+			}
+			return crc;
+		}
+
+		static uint8_t[] pack0x10(uint8_t[] source)
+		{
+			List<uint8_t> list = new List<uint8_t>();
+			for (int i = 0; i < source.Length; i++)
+			{
+				if (source[i] == 0x10) list.Add(0x10);
+				list.Add(source[i]);
+			}
+			return list.ToArray();
+		}
+
+		static uint8_t[] unpack0x10(uint8_t[] dest)
+		{
+			List<uint8_t> list = new List<uint8_t>();
+			for (int i = 0; i < dest.Length; i++)
+			{
+				if (dest[i] == 0x10) i++;
+				list.Add(dest[i]);
+			}
+			return list.ToArray();
+		}
+
+		public static uint8_t[] copyz(ref uint8_t* begin, int size)
+		{
+			uint8_t[] list = new uint8_t[size];
+			for (int i = 0; i < size; i++)
+				list[i] = *begin++;
+			return list;
+		}
+
+		public static bool bEquals(this uint8_t[] lhs, uint8_t[] rhs)
+		{
+			if (lhs.Length != rhs.Length) return false;
+			for (int i = 0; i < lhs.Length; i++)
+				if (lhs[i] != rhs[i]) return false;
+			return true;
+		}
+
+		public static bool bEquals(this uint8_t[] lhs, uint8_t[] rhs, int len)
+		{
+			if (lhs.Length < len || rhs.Length < len) return false;
+			for (int i = 0; i < len; i++)
+				if (lhs[i] != rhs[i]) return false;
+			return true;
+		}
+
+		public static T[] pack<T>(this T first, params T[] other)
+        {
+			T[] t = new T[other.Length + 1];
+			t[0] = first;
+			for (int i = 0; i < other.Length; i++) t[i + 1] = other[i];
+			return t;
+        }
+
+		public static void shutdown(this SerialPort sp)
+		{
+			try
+			{
+				sp?.Close();
+				sp?.Dispose();
+			}
+			catch { }
+		}
+
+		public static void send(this SerialPort sp, byte[] data) => sp.Write(data, 0, data.Length);
+
+		public static void read(this SerialPort sp, byte[] data, int len)
+        {
+			int cursor = 0;
+			while ((cursor += sp.Read(data, cursor, len - cursor)) < data.Length) ;
+        }
+
+		public static byte b(this int i) => (byte)i;
+
+		public static void addRange<T>(this List<T> list, T[] buff, int len)
+		{
+			for (int i = 0; i < len; i++) list.Add(buff[i]);
+		}
+
+		public static byte[] buff(this int i) => BitConverter.GetBytes(i);
+		public static byte[] buff(this uint i) => BitConverter.GetBytes(i);
+		public static byte[] buff(this uint16_t i) => BitConverter.GetBytes(i);
+		public static byte[] buff(this uint8_t i) => i.pack();
+
+		public static uint8_t[] packData(this uint8_t[] inputData)
+        {
+			uint8_t[] data = pack0x10(inputData);
+			uint8_t[] data_size = ((uint8_t)(data.Length + 2)).buff();
+			List<uint8_t> buff = new List<uint8_t>();
+			buff.Add(0x10);
+			buff.Add(0x02);
+			buff.AddRange(data_size);
+			buff.AddRange(data);
+			buff.AddRange(cal_crc(data_size.add(data)).buff());
+			buff.Add(0x10);
+			buff.Add(0x03);
+			return buff.ToArray();
+        }
+
+		public static T[] add<T>(this T[] obj, T[] other)
+		{
+			T[] list = new T[obj.Length + other.Length];
+			for (int i = 0; i < obj.Length; i++)
+				list[i] = obj[i];
+			for (int i = 0; i < other.Length; i++)
+				list[i + obj.Length] = other[i];
+			return list;
+		}
+
+		public static uint8_t[] unpackData(this uint8_t[] inputData)
+        {
+			uint8_t[] buff = null;
+			fixed (uint8_t* ptr_constraint = inputData)
+			{
+				uint8_t* ptr = ptr_constraint;
+				if (!copyz(ref ptr, 2).bEquals(new uint8_t[2] { 0x10, 0x02 })) throw new ComException("Invaild package head.");
+				uint16_t length = BitConverter.ToUInt16(copyz(ref ptr, 2), 0);
+				buff = copyz(ref ptr, length - 2);
+				uint16_t ucrc = BitConverter.ToUInt16(copyz(ref ptr, 2), 0);
+				if (cal_crc(buff) != ucrc) throw new ComException("CRC check failed.");
+				if (!copyz(ref ptr, 2).bEquals(new uint8_t[2] { 0x10, 0x03 })) throw new ComException("Invaild package foot.");
+			}
+			return buff;
+        }
+	}
+}

+ 80 - 51
WpfTest1/MainWindow.xaml

@@ -13,7 +13,7 @@
         ShowIconOnTitleBar="True"
         ShowIconOnTitleBar="True"
         PreviewKeyDown="processGrid_KeyDown"
         PreviewKeyDown="processGrid_KeyDown"
         WindowStartupLocation="CenterScreen"
         WindowStartupLocation="CenterScreen"
-        WindowState = "Normal" FontFamily="SimHei"
+        WindowState = "Normal" FontFamily="SimHei" Activated="MetroWindow_Activated" Closing="MetroWindow_Closing"
         >
         >
     <Controls:MetroWindow.Resources>
     <Controls:MetroWindow.Resources>
         <Style BasedOn="{StaticResource MetroTabItem}" TargetType="{x:Type TabItem}" x:Key="smallHeader" >
         <Style BasedOn="{StaticResource MetroTabItem}" TargetType="{x:Type TabItem}" x:Key="smallHeader" >
@@ -64,7 +64,7 @@
                 <ColumnDefinition Width="959*"/>
                 <ColumnDefinition Width="959*"/>
             </Grid.ColumnDefinitions>
             </Grid.ColumnDefinitions>
             <TabControl x:Name="tabControlGeneral"  HorizontalAlignment="Left" Height="694" VerticalAlignment="Top" Width="1358" SelectionChanged="tabControlGeneral_SelectionChanged" Grid.ColumnSpan="2" Controls:TabControlHelper.Underlined="TabPanel">
             <TabControl x:Name="tabControlGeneral"  HorizontalAlignment="Left" Height="694" VerticalAlignment="Top" Width="1358" SelectionChanged="tabControlGeneral_SelectionChanged" Grid.ColumnSpan="2" Controls:TabControlHelper.Underlined="TabPanel">
-                <TabItem Header="首页" Style="{StaticResource smallHeader}" x:Uid="1000">
+                <TabItem Header="首页" Style="{StaticResource smallHeader}" x:Uid="1000" Height="31" VerticalAlignment="Top">
                     <Grid  Margin="-1,-1,-1,-1">
                     <Grid  Margin="-1,-1,-1,-1">
                         <Grid.Background>
                         <Grid.Background>
                             <ImageBrush ImageSource="/WpfTest1;component/Resources/homepage.jpg" />
                             <ImageBrush ImageSource="/WpfTest1;component/Resources/homepage.jpg" />
@@ -97,21 +97,21 @@
                                 </DataTemplate>
                                 </DataTemplate>
                             </Button.ContentTemplate>
                             </Button.ContentTemplate>
                         </Button>
                         </Button>
-                        <!--<Button x:Name="buttonHomePageFilterFunction" Content="Button" HorizontalAlignment="Left" Margin="699,178,0,0" VerticalAlignment="Top" Width="160" Height="150" Background="#008b7b" Click="buttonHomePageFilterFunction_Click">
-                        <Button.ContentTemplate>
-                            <DataTemplate>
-                                <StackPanel>
-                                    <Rectangle Fill="#ffffff" Width="80" Height="80">
-                                        <Rectangle.OpacityMask>
-                                            <VisualBrush Visual="{StaticResource appbar_clipboard_paper_check}" Stretch="Fill" />
-                                        </Rectangle.OpacityMask>
-                                    </Rectangle>
-                                    <TextBlock Text="快速筛查"  Margin="5 10 4 4" VerticalAlignment="Center" FontSize="20" Foreground="White" />
-                                </StackPanel>
-                            </DataTemplate>
-                        </Button.ContentTemplate>
-                    </Button>-->
-                        <Button x:Name="buttonHomePageEvaluationFunction" Content="Button" HorizontalAlignment="Left" Margin="699,178,0,0" VerticalAlignment="Top" Width="160" Height="150" Background="#daa520" Click="buttonHomePageEvaluationFunction_Click">
+                        <Button x:Name="buttonHomePageFilterFunction" Content="Button" HorizontalAlignment="Left" Margin="699,178,0,0" VerticalAlignment="Top" Width="160" Height="150" Background="#008b7b" Click="buttonHomePageFilterFunction_Click">
+                            <Button.ContentTemplate>
+                                <DataTemplate>
+                                    <StackPanel>
+                                        <Rectangle Fill="#ffffff" Width="80" Height="80">
+                                            <Rectangle.OpacityMask>
+                                                <VisualBrush Visual="{StaticResource appbar_clipboard_paper_check}" Stretch="Fill" />
+                                            </Rectangle.OpacityMask>
+                                        </Rectangle>
+                                        <TextBlock Text="   治疗"  Margin="5 10 4 4" VerticalAlignment="Center" FontSize="20" Foreground="White" />
+                                    </StackPanel>
+                                </DataTemplate>
+                            </Button.ContentTemplate>
+                        </Button>
+                        <Button x:Name="buttonHomePageEvaluationFunction" Content="Button" HorizontalAlignment="Left" Margin="886,178,0,0" VerticalAlignment="Top" Width="160" Height="150" Background="#daa520" Click="buttonHomePageEvaluationFunction_Click">
                             <Button.ContentTemplate>
                             <Button.ContentTemplate>
                                 <DataTemplate>
                                 <DataTemplate>
                                     <StackPanel>
                                     <StackPanel>
@@ -167,7 +167,7 @@
                                 </DataTemplate>
                                 </DataTemplate>
                             </Button.ContentTemplate>
                             </Button.ContentTemplate>
                         </Button>
                         </Button>
-                        <Button x:Name="buttonHomePageHelp" Content="Button" HorizontalAlignment="Left" Margin="886,178,0,0" VerticalAlignment="Top" Width="160" Height="150" Background="#008080" Click="buttonHomePageHelp_Click">
+                        <Button x:Name="buttonHomePageHelp" Content="Button" HorizontalAlignment="Left" Margin="886,359,0,0" VerticalAlignment="Top" Width="160" Height="150" Background="#008080" Click="buttonHomePageHelp_Click">
                             <Button.ContentTemplate>
                             <Button.ContentTemplate>
                                 <DataTemplate>
                                 <DataTemplate>
                                     <StackPanel>
                                     <StackPanel>
@@ -198,44 +198,73 @@
                         </TabItem>
                         </TabItem>
                     </TabControl>
                     </TabControl>
                 </TabItem>
                 </TabItem>
-                <!--快筛-->
-                <TabItem Header="快速筛查" Style="{StaticResource smallHeader}" Visibility="Hidden" Width="5" >
+                <!--治疗(原快筛-->
+                <TabItem Header="治疗" Style="{StaticResource smallHeader}" Visibility="Visible" Width="Auto" Margin="0" >
                     <TabControl x:Name="tabFilter" HorizontalAlignment="Left" Height="645" Width="1338" Margin="10,-5,0,0" VerticalAlignment="Top" >
                     <TabControl x:Name="tabFilter" HorizontalAlignment="Left" Height="645" Width="1338" Margin="10,-5,0,0" VerticalAlignment="Top" >
                         <TabItem  Header="选择用户" Style="{StaticResource smallerHeader}"  IsEnabled="False" >
                         <TabItem  Header="选择用户" Style="{StaticResource smallerHeader}"  IsEnabled="False" >
                             <Grid Background="White" Margin="0,0,0,0">
                             <Grid Background="White" Margin="0,0,0,0">
                                 <my:selectUser x:Name="selectUserfilter" Margin="0,0,0,0"></my:selectUser>
                                 <my:selectUser x:Name="selectUserfilter" Margin="0,0,0,0"></my:selectUser>
-                                <Button x:Name="buttonFilterSelectPatient" IsEnabled="True" Content="开始测试" HorizontalAlignment="Left" Margin="41,531,0,0" VerticalAlignment="Top" Width="240" Height="36" FontSize="15" Click="buttonFilterSelectPatient_Click"/>
+                                <Button x:Name="buttonFilterSelectTreatment" IsEnabled="True" Content="开始治疗" HorizontalAlignment="Left" Margin="41,531,0,0" VerticalAlignment="Top" Width="240" Height="36" FontSize="15" Click="buttonFilterSelectTreatment_Click"/>
                             </Grid>
                             </Grid>
                         </TabItem>
                         </TabItem>
-                        <TabItem  Header="筛查流程" Style="{StaticResource smallerHeader}"  IsEnabled="False">
+                        <TabItem  Header="治疗" Style="{StaticResource smallerHeader}"  IsEnabled="False">
                             <Grid x:Name="filterProcessGrid" Background="White" Margin="0,0,0,0">
                             <Grid x:Name="filterProcessGrid" Background="White" Margin="0,0,0,0">
-                                <Label x:Name="labelGong" Content="共" HorizontalAlignment="Left" Margin="90,10,0,0" VerticalAlignment="Top" FontSize="18"/>
-                                <Label x:Name="labelFilterNumberofTotalQuestions" Content="XXX" HorizontalAlignment="Left" Margin="110,10,0,0" VerticalAlignment="Top" FontSize="18"/>
-                                <Label x:Name="labelTi" Content="题,当前第" HorizontalAlignment="Left" Margin="150,10,0,0" VerticalAlignment="Top" FontSize="18"/>
-                                <Label x:Name="labelFilterNameLabel" Content="当前病例:" HorizontalAlignment="Left" Margin="800,10,0,0" VerticalAlignment="Top" FontSize="18"/>
-                                <Label x:Name="labelFilterName" Content="[被试姓名]" HorizontalAlignment="Left" Margin="890,10,0,0" VerticalAlignment="Top" FontSize="18"/>
-                                <Label x:Name="labelFilterRecordidLabel" Content="病案号:" HorizontalAlignment="Left" Margin="1000,10,0,0" VerticalAlignment="Top" FontSize="18"/>
-                                <Label x:Name="labelFilterRecordid" Content="[病案编号233333333]" HorizontalAlignment="Left" Margin="1070,10,0,0" VerticalAlignment="Top" FontSize="18"/>
-                                <Label x:Name="labelFilterNumberofCurrentQuestion" Content="XXX" HorizontalAlignment="Left" Margin="240,10,0,0" VerticalAlignment="Top" FontSize="18"/>
-                                <Label x:Name="labelTi2" Content="题" HorizontalAlignment="Left" Margin="280,10,0,0" VerticalAlignment="Top" FontSize="18"/>
-                                <Label x:Name="labelFilterQuestionTitle" Content="[问题的标题,大约需要30个汉字,所以空间需要够]" HorizontalAlignment="Left" Margin="90,36,0,0" VerticalAlignment="Top" FontSize="30"/>
-                                <TextBlock x:Name="textBlockFilterQuetionContent" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="94,90,0,0" TextWrapping="Wrap" Text="Here is the question content." Height="240" Width="745" FontSize="18"/>
-                                <Image x:Name="imageFilterQuestion_start" HorizontalAlignment="Left" Width="460" Height="245" Margin="850,50,0,0" VerticalAlignment="Top" />
-                                <Image x:Name="imageFilterQuestion_active" HorizontalAlignment="Left" Width="460" Height="245" Margin="850,295,0,0" VerticalAlignment="Top" />
-                                <Grid x:Name="gridFilterSelection" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="94,340,0,0" Width="745" Height="200" ></Grid>
-                                <Label x:Name="labelFilterStartPosition" Content="起始位" HorizontalAlignment="Left" Margin="1210,50,0,0" VerticalAlignment="Top" FontSize="30"/>
-                                <Label x:Name="labelFilterActivePosition" Content="动作位" HorizontalAlignment="Left" Margin="1210,295,0,0" VerticalAlignment="Top" FontSize="30"/>
-                                <Button x:Name="buttonFilterPrevious" Content="上一题" HorizontalAlignment="Left" Margin="424,550,0,0" VerticalAlignment="Top" Width="130" Height="50" FontSize="18" IsEnabled="False" Click="buttonFilterPrevious_Click" />
-                                <Button x:Name="buttonFilterNext" Content="下一题" HorizontalAlignment="Left" Margin="784,550,0,0" VerticalAlignment="Top" Width="130" Height="50" FontSize="18" IsEnabled="False" Click="buttonFilterNext_Click" />
-                                <Button x:Name="buttonSubmitFilter" Content="提交" HorizontalAlignment="Left" Margin="604,550,0,0" VerticalAlignment="Top" Width="130" Height="50" FontSize="18" Background="#FF317602" Foreground="White" IsEnabled="False" Click="buttonSubmitFilter_Click"/>
-                                <Button x:Name="buttonAbortFilter" Content="中止筛查" HorizontalAlignment="Left" Margin="110,545,0,0" VerticalAlignment="Top" Width="132" Height="50" FontSize="18" Background="#FFB92424" Foreground="White" Click="buttonAbortFilter_Click"/>
-                            </Grid>
-                        </TabItem>
-                        <TabItem  Header="筛查报告" Style="{StaticResource smallerHeader}"  IsEnabled="False" >
-                            <Grid Background="White" Margin="0,0,0,0">
-                                <Label x:Name="labelPDF" Content="该报告已在第三方软件中打开" HorizontalAlignment="Left" Margin="543,133,0,0" VerticalAlignment="Top" FontSize="18"/>
-                                <Button x:Name="buttonFilterBackToSelectUser" Content="开始新的筛查" HorizontalAlignment="Left" Margin="500,550,0,0" VerticalAlignment="Top" Width="130" Height="50" FontSize="18" Click="buttonFilterBackToSelectUser_Click" />
-                                <Button x:Name="buttonFilterBackToHome" Content="回到首页" HorizontalAlignment="Left" Margin="700,550,0,0" VerticalAlignment="Top" Width="130" Height="50" FontSize="18" Click="buttonFilterBackToHome_Click" />
+                                <Grid x:Name="userInfoGrid" HorizontalAlignment="Left" Height="592" Margin="10,10,0,0" VerticalAlignment="Top" Width="285">
+                                    <Label Content="病例编号:" HorizontalAlignment="Left" Margin="10,60,0,0" VerticalAlignment="Top" RenderTransformOrigin="0.498,1.882" FontSize="18"/>
+                                    <Label Content="姓名:" HorizontalAlignment="Left" Margin="46,90,0,0" VerticalAlignment="Top" FontSize="18"/>
+                                    <Label Content="身高:" HorizontalAlignment="Left" Margin="46,121,0,0" VerticalAlignment="Top" RenderTransformOrigin="0.597,0.495" FontSize="18"/>
+                                    <Label Content="体重:" HorizontalAlignment="Left" Margin="46,152,0,0" VerticalAlignment="Top" FontSize="18"/>
+                                    <Label Content="性别:" HorizontalAlignment="Left" Margin="46,182,0,0" VerticalAlignment="Top" FontSize="18"/>
+                                    <Label Content="孕次:" HorizontalAlignment="Left" Margin="46,212,0,0" VerticalAlignment="Top" FontSize="18"/>
+                                    <Label Content="出生日期:" HorizontalAlignment="Left" Margin="10,242,0,0" VerticalAlignment="Top" FontSize="18"/>
+                                    <Label Content="联系方式:" HorizontalAlignment="Left" Margin="10,272,0,0" VerticalAlignment="Top" FontSize="18"/>
+                                    <Label Content="通讯地址:" HorizontalAlignment="Left" Margin="10,303,0,0" VerticalAlignment="Top" FontSize="18"/>
+                                    <Label Content="病史:" HorizontalAlignment="Left" Margin="46,334,0,0" VerticalAlignment="Top" FontSize="18"/>
+                                    <Label Content="诊断:" HorizontalAlignment="Left" Margin="46,419,0,0" VerticalAlignment="Top" FontSize="18"/>
+                                    <Label Content="患者信息" HorizontalAlignment="Left" Margin="71,10,0,0" VerticalAlignment="Top" Height="45" Width="132" FontSize="30"/>
+                                    <Button x:Name="buttonFilterBackToSelectUser" FontSize="18" Content="重选患者" HorizontalAlignment="Left" Margin="25,544,0,0" VerticalAlignment="Top" Width="236" Height="38" Click="buttonFilterBackToSelectUser_Click"/>
+                                    <TextBox x:Name="textBoxCaseId" HorizontalAlignment="Left" Height="30" Margin="98,58,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="177" FontSize="18" IsReadOnly="True" IsUndoEnabled="False"/>
+                                    <TextBox x:Name="textBoxName" HorizontalAlignment="Left" Height="30" Margin="98,88,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="177" FontSize="18" IsReadOnly="True" IsUndoEnabled="False"/>
+                                    <TextBox x:Name="textBoxHeight" HorizontalAlignment="Left" Height="30" Margin="98,119,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="177" FontSize="18" IsReadOnly="True" IsUndoEnabled="False"/>
+                                    <TextBox x:Name="textBoxWeight" HorizontalAlignment="Left" Height="30" Margin="98,150,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="177" FontSize="18" IsReadOnly="True" IsUndoEnabled="False"/>
+                                    <TextBox x:Name="textBoxGender" HorizontalAlignment="Left" Height="30" Margin="98,180,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="177" FontSize="18" IsReadOnly="True" IsUndoEnabled="False"/>
+                                    <TextBox x:Name="textBoxPregnancyTimes" HorizontalAlignment="Left" Height="30" Margin="98,210,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="177" FontSize="18" IsReadOnly="True" IsUndoEnabled="False"/>
+                                    <TextBox x:Name="textBoxBirthDate" HorizontalAlignment="Left" Height="30" Margin="98,240,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="177" FontSize="18" IsReadOnly="True" IsUndoEnabled="False"/>
+                                    <TextBox x:Name="textBoxMobile" HorizontalAlignment="Left" Height="30" Margin="98,270,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="177" FontSize="18" IsReadOnly="True" IsUndoEnabled="False"/>
+                                    <TextBox x:Name="textBoxAddress" HorizontalAlignment="Left" Height="30" Margin="98,301,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="177" FontSize="18" IsReadOnly="True" IsUndoEnabled="False"/>
+                                    <TextBox x:Name="textBoxHistory" HorizontalAlignment="Left" Height="87" Margin="98,332,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="177" FontSize="18" IsReadOnly="True" AcceptsReturn="True" IsUndoEnabled="False" VerticalScrollBarVisibility="Auto"/>
+                                    <TextBox x:Name="textBoxDiagnosis" HorizontalAlignment="Left" Height="87" Margin="98,417,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="177" FontSize="18" IsReadOnly="True" AcceptsReturn="True" IsUndoEnabled="False" VerticalScrollBarVisibility="Auto"/>
+                                </Grid>
+                                <Grid HorizontalAlignment="Left" Height="592" Margin="300,10,0,0" VerticalAlignment="Top" Width="1024" RenderTransformOrigin="-0.004,-0.019">
+                                    <Grid.RowDefinitions>
+                                        <RowDefinition Height="545*"/>
+                                        <RowDefinition Height="47*"/>
+                                    </Grid.RowDefinitions>
+                                    <Button x:Name="buttonStart" Content="开始" HorizontalAlignment="Left" Margin="134,499,0,0" VerticalAlignment="Top" Width="130" Height="50" FontSize="18" Background="#FF317602" Foreground="White" Grid.RowSpan="2" Click="buttonStartTreat_Click"/>
+                                    <Button x:Name="buttonStop" Content="停止" HorizontalAlignment="Left" Margin="344,499,0,0" VerticalAlignment="Top" Width="132" Height="50" FontSize="18" Background="#FFB92424" Foreground="White" IsEnabled="False" Grid.RowSpan="2" Click="buttonStop_Click"/>
+                                    <Button x:Name="buttonSelectTreatment" Content="治疗方案" HorizontalAlignment="Left"  Margin="134,10,0,0" VerticalAlignment="Top" Width="197" Height="62" FontSize="30" Click="buttonChooseTreatmentPlan_Click" RenderTransformOrigin="-1.554,0.551"/>
+                                    <Label x:Name="labelTreatmentName" Content="请选择治疗方案" HorizontalAlignment="Left" Margin="25,77,0,0" VerticalAlignment="Top" Height="96" Width="408" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" FontSize="40" />
+                                    <Slider x:Name="sliderStrength" HorizontalAlignment="Left" Margin="153,267,0,0" VerticalAlignment="Top" Height="9" Width="219" ValueChanged="sliderStrength_ValueChanged"/>
+                                    <Label Content="强度调节" HorizontalAlignment="Left" Margin="47,260,0,0" VerticalAlignment="Top" FontSize="18"/>
+                                    <Label x:Name="labelStrength" Content="" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" HorizontalAlignment="Center" Margin="153,278,652,0" VerticalAlignment="Top" FontSize="12" Width="219" Height="30"/>
+                                    <Label Content="时间调节" HorizontalAlignment="Left" Margin="47,320,0,0" VerticalAlignment="Top" FontSize="18"/>
+                                    <Label x:Name="labelTreatmentTime" Content="30:00" HorizontalAlignment="Left" Margin="230,320,0,0" VerticalAlignment="Top" FontSize="18"/>
+                                    <Button Content="+" HorizontalAlignment="Left" Margin="319,315,0,0" VerticalAlignment="Top" Width="35" Height="43" FontSize="18" VerticalContentAlignment="Top" Click="increaseTreatmentTime"/>
+                                    <Button Content="-" HorizontalAlignment="Left" Margin="167,315,0,0" VerticalAlignment="Top" Width="35" Height="43" FontSize="18" VerticalContentAlignment="Top" Click="decreaseTreatmentTime"/>
+                                    <Label Content="温度" HorizontalAlignment="Left" Margin="47,384,0,0" VerticalAlignment="Top" FontSize="18"/>
+                                    <Label Content="温度值" HorizontalAlignment="Left" Margin="230,384,0,0" VerticalAlignment="Top" FontSize="18"/>
+                                    <CheckBox x:Name="checkBoxCustomMode" Content="自定义模式" HorizontalAlignment="Left" Margin="534,10,0,0" VerticalAlignment="Top" Height="62" Width="184" FontSize="30" RenderTransformOrigin="0.486,0.085" Unchecked="checkBoxCustomMode_CheckedChanged" Checked="checkBoxCustomMode_CheckedChanged"/>
+                                    <DataGrid x:Name="dataGridCustomMode" HorizontalAlignment="Left" Height="372" Margin="534,77,0,0" VerticalAlignment="Top" Width="480" SelectionChanged="dataGridCustomMode_SelectionChanged" RowEditEnding="dataGridCustomMode_RowEditEnding" IsEnabled="False" AutoGenerateColumns="False" CanUserReorderColumns="False" CanUserSortColumns="False" SelectionMode="Single" CanUserResizeRows="False" CanUserAddRows="False" CanUserDeleteRows="False">
+                                        <DataGrid.Columns>
+                                            <DataGridTextColumn Header="序号" Binding="{Binding Path=tcID}" Width="45" IsReadOnly="True"/>
+                                            <DataGridTextColumn Header="刺激频率" Binding="{Binding Path=tcRate}" Width="100"/>
+                                            <DataGridTextColumn Header="刺激时间" Binding="{Binding Path=tcActiveTime}" Width="120"/>
+                                            <DataGridTextColumn Header="间歇时间" Binding="{Binding Path=tcInactiveTime}" Width="120"/>
+                                        </DataGrid.Columns>
+                                    </DataGrid>
+                                    <Button x:Name="buttonAddCustomModeItem" Content="增行" HorizontalAlignment="Left" Margin="929,38,0,0" VerticalAlignment="Top" FontSize="15" Width="40" IsEnabled="False" Click="buttonAddCustomModeItem_Click" />
+                                    <Button x:Name="buttonDelCustomModeItem" Content="减行" HorizontalAlignment="Left" Margin="974,38,0,0" VerticalAlignment="Top" FontSize="15" Width="40" IsEnabled="False" Click="buttonDelCustomModeItem_Click" />
+                                </Grid>
                             </Grid>
                             </Grid>
                         </TabItem>
                         </TabItem>
                     </TabControl>
                     </TabControl>
@@ -276,12 +305,12 @@
                                         <Label HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,0,0,0" Content="动作不标准" FontSize="20" Foreground="#FF27405A"/>
                                         <Label HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,0,0,0" Content="动作不标准" FontSize="20" Foreground="#FF27405A"/>
                                     </Grid>
                                     </Grid>
                                 </Grid>
                                 </Grid>
-                                
+
                                 <Button x:Name="buttonEvaluationPrevious" Visibility="Hidden" Content="上一题" HorizontalAlignment="Left" Margin="424,550,0,0" VerticalAlignment="Top" Width="130" Height="50" FontSize="18" IsEnabled="False" Click="buttonEvaluationPrevious_Click" />
                                 <Button x:Name="buttonEvaluationPrevious" Visibility="Hidden" Content="上一题" HorizontalAlignment="Left" Margin="424,550,0,0" VerticalAlignment="Top" Width="130" Height="50" FontSize="18" IsEnabled="False" Click="buttonEvaluationPrevious_Click" />
                                 <Button x:Name="buttonEvaluationNext" Content="下一题" HorizontalAlignment="Center" Margin="450,550,0,0" VerticalAlignment="Top" Width="130" Height="50" FontSize="18" IsEnabled="False" Click="buttonEvaluationNext_Click" />
                                 <Button x:Name="buttonEvaluationNext" Content="下一题" HorizontalAlignment="Center" Margin="450,550,0,0" VerticalAlignment="Top" Width="130" Height="50" FontSize="18" IsEnabled="False" Click="buttonEvaluationNext_Click" />
                                 <Button x:Name="buttonSubmitEvaluation" Content="提交" HorizontalAlignment="Center" Margin="0,550,0,0" VerticalAlignment="Top" Width="130" Height="50" FontSize="18" Background="#FF317602" Foreground="White" IsEnabled="False" Click="buttonSubmitEvaluation_Click"/>
                                 <Button x:Name="buttonSubmitEvaluation" Content="提交" HorizontalAlignment="Center" Margin="0,550,0,0" VerticalAlignment="Top" Width="130" Height="50" FontSize="18" Background="#FF317602" Foreground="White" IsEnabled="False" Click="buttonSubmitEvaluation_Click"/>
                                 <Button x:Name="buttonAbortEvaluation" Content="中止评估" HorizontalAlignment="Center" Margin="-450,550,0,0" VerticalAlignment="Top" Width="132" Height="50" FontSize="18" Background="#FFB92424" Foreground="White" Click="buttonAbortEvaluation_Click"/>
                                 <Button x:Name="buttonAbortEvaluation" Content="中止评估" HorizontalAlignment="Center" Margin="-450,550,0,0" VerticalAlignment="Top" Width="132" Height="50" FontSize="18" Background="#FFB92424" Foreground="White" Click="buttonAbortEvaluation_Click"/>
-                                </Grid>
+                            </Grid>
                         </TabItem>
                         </TabItem>
                         <TabItem  Header="评估报告" Style="{StaticResource smallerHeader}"  IsEnabled="False" >
                         <TabItem  Header="评估报告" Style="{StaticResource smallerHeader}"  IsEnabled="False" >
                             <Grid Background="White" Margin="0,0,0,0">
                             <Grid Background="White" Margin="0,0,0,0">

+ 221 - 61
WpfTest1/MainWindow.xaml.cs

@@ -14,6 +14,9 @@ using System.ComponentModel;
 using System.Windows.Media.Imaging;
 using System.Windows.Media.Imaging;
 using System.Windows.Documents;
 using System.Windows.Documents;
 using System.Windows.Media;
 using System.Windows.Media;
+using WpfTest1.ComAgent;
+
+using Com = WpfTest1.ComAgent.ComAgent;
 
 
 namespace WpfTest1
 namespace WpfTest1
 {
 {
@@ -50,6 +53,9 @@ namespace WpfTest1
         BindingList<Record> bindingRecords;
         BindingList<Record> bindingRecords;
         Dictionary<string, int> mapKeyToDigit = new Dictionary<string, int>();
         Dictionary<string, int> mapKeyToDigit = new Dictionary<string, int>();
 
 
+        Treatment targetTreatment = null;
+        List <TreatmentCustomItem> treatmentCustomModeList;
+        //DataTable treatmentCustomDataTable;
         #endregion
         #endregion
 
 
         public MainWindow()
         public MainWindow()
@@ -89,7 +95,7 @@ namespace WpfTest1
             }
             }
             loadUSBDogStatus();
             loadUSBDogStatus();
 
 
-            string datestr = "2021-12-31 00:00:00";
+            string datestr = "2050-12-31 00:00:00";
             DateTime dtStandard = DateTime.Parse(datestr);
             DateTime dtStandard = DateTime.Parse(datestr);
             DateTime now = DateTime.Now;
             DateTime now = DateTime.Now;
             if(DateTime.Compare(dtStandard, now) < 0)
             if(DateTime.Compare(dtStandard, now) < 0)
@@ -144,7 +150,7 @@ namespace WpfTest1
             //System.Console.WriteLine(String.Format("KeyDown detected. {0} is detected.", e.Key.ToString()));
             //System.Console.WriteLine(String.Format("KeyDown detected. {0} is detected.", e.Key.ToString()));
             if (tabControlGeneral.SelectedIndex == 2 && tabFilter.SelectedIndex == 1)
             if (tabControlGeneral.SelectedIndex == 2 && tabFilter.SelectedIndex == 1)
             {
             {
-                //筛查流程中
+                /*//筛查流程中
                 if (e.Key == Key.N && buttonFilterNext.IsEnabled)
                 if (e.Key == Key.N && buttonFilterNext.IsEnabled)
                 {
                 {
                     buttonFilterNext_Click(sender, (RoutedEventArgs)e);
                     buttonFilterNext_Click(sender, (RoutedEventArgs)e);
@@ -180,7 +186,7 @@ namespace WpfTest1
                     }
                     }
                     
                     
                     return;
                     return;
-                }
+                }*/
             }
             }
             else if(tabControlGeneral.SelectedIndex == 3 && tabEvaluation.SelectedIndex == 1)
             else if(tabControlGeneral.SelectedIndex == 3 && tabEvaluation.SelectedIndex == 1)
             {
             {
@@ -360,18 +366,23 @@ namespace WpfTest1
         #endregion
         #endregion
         #endregion
         #endregion
 
 
-        #region 筛查功能
+        #region 治疗功能 原筛查功能
 
 
         /// <summary>
         /// <summary>
-        /// 点击开始筛查后触发的事件
+        /// 点击治疗后触发的事件
         /// </summary>
         /// </summary>
         /// <param name="sender">默认</param>
         /// <param name="sender">默认</param>
         /// <param name="e">默认</param>
         /// <param name="e">默认</param>
-        public void buttonFilterSelectPatient_Click(object sender, RoutedEventArgs e)
+        public void buttonFilterSelectTreatment_Click(object sender, RoutedEventArgs e)
         {
         {
             try
             try
             {
             {
                 var target = (DataRowView)this.selectUserfilter.dataGrid.SelectedItem;
                 var target = (DataRowView)this.selectUserfilter.dataGrid.SelectedItem;
+                if (target == null)
+                {
+                    MessageBox.Show("请先选择病人!");
+                    return;
+                }
                 filterPatient = SQLite.SQLiteModel.getPatientById(target["p_id"].ToString());
                 filterPatient = SQLite.SQLiteModel.getPatientById(target["p_id"].ToString());
             }
             }
             catch (Exception err)
             catch (Exception err)
@@ -395,39 +406,127 @@ namespace WpfTest1
             }
             }
             catch (Exception err)
             catch (Exception err)
             {
             {
-                MessageBox.Show("筛查题目加载失败\r\n调试信息:" + err.Message + "\r\n" + err.StackTrace, "错误");
-                return;
-            }
-            if(filterQuestionaire.Count == 0)
-            {
-                MessageBox.Show("筛查题目加载失败\r\n数据库中无有效问卷", "错误");
+                MessageBox.Show("治疗数据加载失败\r\n调试信息:" + err.Message + "\r\n" + err.StackTrace, "错误");
                 return;
                 return;
             }
             }
-            labelFilterName.Content = filterPatient.p_name;
-            labelFilterRecordid.Content = filterPatient.p_record_id;
             currentFilterCount = 1;
             currentFilterCount = 1;
-            loadQuestionViewFilter(currentFilterCount);
             tabFilter.SelectedIndex += 1;
             tabFilter.SelectedIndex += 1;
+
+            textBoxCaseId.Text = filterPatient.p_record_id;
+            textBoxGender.Text = filterPatient.p_gender;
+            textBoxName.Text = filterPatient.p_name;
+            textBoxHeight.Text = filterPatient.p_height.ToString();
+            textBoxWeight.Text = filterPatient.p_weight.ToString();
+            textBoxPregnancyTimes.Text = filterPatient.p_pregnancy_time.ToString();
+            textBoxBirthDate.Text = filterPatient.p_birthdate.ToString("yyyy/M/d");
+            textBoxMobile.Text = filterPatient.p_phone;
+            textBoxAddress.Text = filterPatient.p_address;
+            textBoxHistory.Text = filterPatient.p_history;
+            textBoxDiagnosis.Text = filterPatient.p_diagnosis;
+
+            //*/
+            treatmentCustomModeList = new List<TreatmentCustomItem>();
+            dataGridCustomMode.ItemsSource = treatmentCustomModeList;/*/
+            treatmentCustomDataTable = new DataTable();
+            treatmentCustomDataTable.Columns.Add("tcID", typeof(int));
+            treatmentCustomDataTable.Columns.Add("tcRate", typeof(double));
+            treatmentCustomDataTable.Columns.Add("tcActiveTime", typeof(double));
+            treatmentCustomDataTable.Columns.Add("tcInactiveTime", typeof(double));
+            dataGridCustomMode.ItemsSource = treatmentCustomDataTable.DefaultView;//*/
         }
         }
 
 
+        /// <summary>
+        /// 重选用户
+        /// </summary>
+        /// <param name="sender">默认</param>
+        /// <param name="e">默认</param>
+        private void buttonFilterBackToSelectUser_Click(object sender, RoutedEventArgs e)
+        {
+            tabFilter.SelectedIndex = 0;
+        }
 
 
         /// <summary>
         /// <summary>
-        /// 点击中止筛查后触发的事件
+        /// 治疗方案
         /// </summary>
         /// </summary>
         /// <param name="sender">默认</param>
         /// <param name="sender">默认</param>
         /// <param name="e">默认</param>
         /// <param name="e">默认</param>
-        private void buttonAbortFilter_Click(object sender, RoutedEventArgs e)
+        private void buttonChooseTreatmentPlan_Click(object sender, RoutedEventArgs e)
         {
         {
-            filterUserSelection.Clear();
-            filterPatient = null;
-            resultsFilter = "";
+            TreatmentPlan a_new_one = new TreatmentPlan(this);
+            a_new_one.Show();
+        }
 
 
-            currentFilterCount = 0;
-            buttonFilterPrevious.IsEnabled = false;
-            buttonFilterNext.IsEnabled = false;
-            buttonSubmitFilter.IsEnabled = false;
+        public void setTreatment(Treatment target)
+        {
+            targetTreatment = target;
+            labelTreatmentName.Content = targetTreatment.disease;
+            sliderStrength.Value = 100;
+        }
 
 
-            tabFilter.SelectedIndex = 0;
+        private void sliderStrength_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
+        {
+            labelStrength.Content = sliderStrength.Value.ToString("0.");
+            comAgent.enqueueCommand(Com.createChangeStrongthCommand((byte)(sliderStrength.Value * 100)));
+        }
+
+        /// <summary>
+        /// 自定义模式
+        /// </summary>
+        /// <param name="sender">默认</param>
+        /// <param name="e">默认</param>
+        private void checkBoxCustomMode_CheckedChanged(object sender, RoutedEventArgs e)
+        {
+            if (checkBoxCustomMode.IsChecked == true) {
+                labelTreatmentName.Content = "自定义模式";
+                buttonSelectTreatment.IsEnabled = false;
+                dataGridCustomMode.IsEnabled = true;
+                //dataGridCustomMode.CanUserAddRows = true;
+                //dataGridCustomMode.CanUserDeleteRows = true;
+                buttonAddCustomModeItem.IsEnabled = true;
+                buttonDelCustomModeItem.IsEnabled = true;
+            } else {
+                if (targetTreatment == null) {
+                    labelTreatmentName.Content = "请选择治疗方案";
+                } else {
+                    labelTreatmentName.Content = targetTreatment.disease;
+                }
+                buttonSelectTreatment.IsEnabled = true;
+                dataGridCustomMode.IsEnabled = false;
+                buttonAddCustomModeItem.IsEnabled = false;
+                buttonDelCustomModeItem.IsEnabled = false;
+            }
+        }
+
+        private void buttonAddCustomModeItem_Click(object sender, RoutedEventArgs e)
+        {
+            TreatmentCustomItem item = new TreatmentCustomItem();
+            item.tcID = treatmentCustomModeList.Count + 1;
+            treatmentCustomModeList.Add(item);
+            dataGridCustomMode.ItemsSource = null;
+            dataGridCustomMode.ItemsSource = treatmentCustomModeList;
+        }
+
+        private void buttonDelCustomModeItem_Click(object sender, RoutedEventArgs e)
+        {
+            int index = dataGridCustomMode.SelectedIndex;
+            if (index == -1) { return; }
+            treatmentCustomModeList.RemoveAt(index);
+            for (int i = 0; i < treatmentCustomModeList.Count; i++)
+            {
+                treatmentCustomModeList[i].tcID = i + 1;
+            }
+            dataGridCustomMode.ItemsSource = null;
+            dataGridCustomMode.ItemsSource = treatmentCustomModeList;
+        }
+
+        private void dataGridCustomMode_SelectionChanged(object sender, SelectionChangedEventArgs e)
+        {
+            //System.Console.WriteLine("asdasdasd");
+        }
+
+        private void dataGridCustomMode_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
+        {
+            //System.Console.WriteLine("asdasdasd");
         }
         }
 
 
         /// <summary>
         /// <summary>
@@ -435,29 +534,27 @@ namespace WpfTest1
         /// </summary>
         /// </summary>
         /// <param name="sender">默认</param>
         /// <param name="sender">默认</param>
         /// <param name="e">默认</param>
         /// <param name="e">默认</param>
-        private void buttonFilterPrevious_Click(object sender, RoutedEventArgs e)
+        /*private void buttonFilterPrevious_Click(object sender, RoutedEventArgs e)
         {
         {
             currentFilterCount -= 1;
             currentFilterCount -= 1;
             loadQuestionViewFilter(currentFilterCount);
             loadQuestionViewFilter(currentFilterCount);
             checkFilterButtonStatues();
             checkFilterButtonStatues();
-        }
+        }*/
 
 
         /// <summary>
         /// <summary>
         /// 点击筛查下一步后触发的事件
         /// 点击筛查下一步后触发的事件
         /// </summary>
         /// </summary>
         /// <param name="sender">默认</param>
         /// <param name="sender">默认</param>
         /// <param name="e">默认</param>
         /// <param name="e">默认</param>
-        private void buttonFilterNext_Click(object sender, RoutedEventArgs e)
+        /*private void buttonFilterNext_Click(object sender, RoutedEventArgs e)
         {
         {
-            currentFilterCount += 1;
-            loadQuestionViewFilter(currentFilterCount);
             checkFilterButtonStatues();
             checkFilterButtonStatues();
-        }
+        }*/
 
 
         /// <summary>
         /// <summary>
         /// 确认筛查阶段各个按钮应当处于的状态
         /// 确认筛查阶段各个按钮应当处于的状态
         /// </summary>
         /// </summary>
-        private void checkFilterButtonStatues()
+        /*private void checkFilterButtonStatues()
         {
         {
             bool radioCheckFlag = false;
             bool radioCheckFlag = false;
             foreach(RadioButton rb in gridFilterSelection.Children){
             foreach(RadioButton rb in gridFilterSelection.Children){
@@ -484,12 +581,12 @@ namespace WpfTest1
                 buttonSubmitFilter.IsEnabled = true;
                 buttonSubmitFilter.IsEnabled = true;
             else
             else
                 buttonSubmitFilter.IsEnabled = false;
                 buttonSubmitFilter.IsEnabled = false;
-        }
+        }*/
 
 
         /// <summary>
         /// <summary>
         /// 加载题目和选项界面
         /// 加载题目和选项界面
         /// </summary>
         /// </summary>
-        private void loadQuestionViewFilter(int currentIndex)
+        /*private void loadQuestionViewFilter(int currentIndex)
         {
         {
             labelFilterNumberofTotalQuestions.Content = filterQuestionaire.Count.ToString();
             labelFilterNumberofTotalQuestions.Content = filterQuestionaire.Count.ToString();
             labelFilterNumberofCurrentQuestion.Content = currentIndex.ToString();
             labelFilterNumberofCurrentQuestion.Content = currentIndex.ToString();
@@ -558,9 +655,9 @@ namespace WpfTest1
                 oneOption.Name = "rbf" + filterQuestionaire[currentIndex - 1].answers[i].a_id.ToString();
                 oneOption.Name = "rbf" + filterQuestionaire[currentIndex - 1].answers[i].a_id.ToString();
                 gridFilterSelection.Children.Add(oneOption);
                 gridFilterSelection.Children.Add(oneOption);
             }
             }
-        }
+        }*/
 
 
-        private void radioButtonFilter_Checked(object sender, RoutedEventArgs e)
+        /*private void radioButtonFilter_Checked(object sender, RoutedEventArgs e)
         {
         {
             //首先,记录该选择
             //首先,记录该选择
             RadioButton oneSelection = (RadioButton)sender;
             RadioButton oneSelection = (RadioButton)sender;
@@ -568,14 +665,14 @@ namespace WpfTest1
             //MessageBox.Show(filterUserSelection[currentFilterCount - 1].a_id.ToString());
             //MessageBox.Show(filterUserSelection[currentFilterCount - 1].a_id.ToString());
             //然后,确认各个按钮状态
             //然后,确认各个按钮状态
             checkFilterButtonStatues();
             checkFilterButtonStatues();
-        }
+        }*/
 
 
         /// <summary>
         /// <summary>
         /// 点击筛查提交后触发的事件
         /// 点击筛查提交后触发的事件
         /// </summary>
         /// </summary>
         /// <param name="sender">默认</param>
         /// <param name="sender">默认</param>
         /// <param name="e">默认</param>
         /// <param name="e">默认</param>
-        private void buttonSubmitFilter_Click(object sender, RoutedEventArgs e)
+        /*private void buttonSubmitFilter_Click(object sender, RoutedEventArgs e)
         {
         {
             int[] timesLimit =  dop.getTimesCount();
             int[] timesLimit =  dop.getTimesCount();
             if (Constants.productionEnvironment && (timesLimit[1] >= timesLimit[0]))
             if (Constants.productionEnvironment && (timesLimit[1] >= timesLimit[0]))
@@ -620,28 +717,7 @@ namespace WpfTest1
                 buttonAbortFilter_Click(sender, e);
                 buttonAbortFilter_Click(sender, e);
             }
             }
             return;
             return;
-        }
-
-        /// <summary>
-        /// 返回至选择用户页
-        /// </summary>
-        /// <param name="sender">默认</param>
-        /// <param name="e">默认</param>
-        private void buttonFilterBackToSelectUser_Click(object sender, RoutedEventArgs e)
-        {
-            buttonAbortFilter_Click(sender, e);
-        }
-
-        /// <summary>
-        /// 返回至选择首页
-        /// </summary>
-        /// <param name="sender">默认</param>
-        /// <param name="e">默认</param>
-        private void buttonFilterBackToHome_Click(object sender, RoutedEventArgs e)
-        {
-            buttonAbortFilter_Click(sender, e);
-            tabControlGeneral.SelectedIndex = 0;
-        }
+        }*/
 
 
         #endregion
         #endregion
 
 
@@ -1544,8 +1620,92 @@ namespace WpfTest1
                 MessageBox.Show("操作成功");
                 MessageBox.Show("操作成功");
             }
             }
         }
         }
+
         #endregion
         #endregion
 
 
-        
+        private float treatmentTime_ = 30, treatmentTimeMin = 1, treatmentTimeMax = 100;
+
+        public float treatmentTime
+        {
+            get => treatmentTime_;
+            set
+            {
+                treatmentTime_ = value > treatmentTimeMax ? treatmentTimeMax : value < treatmentTimeMin ? treatmentTimeMin : value;
+                labelTreatmentTime.Content = $"{(int)treatmentTime_}:{(treatmentTime_ - (int)treatmentTime_) * 60}";
+            }
+        }
+
+        private void increaseTreatmentTime(object sender, RoutedEventArgs e)
+        {
+            treatmentTime += 0.5f;
+        }
+
+        private void decreaseTreatmentTime(object sender, RoutedEventArgs e)
+        {
+            treatmentTime -= 0.5f;
+        }
+
+        private Com comAgent => SingleInstance<Com>.getInstance();
+        private bool isRunning;
+
+        private void updateUIIsRunning()
+        {
+            buttonStart.IsEnabled = !isRunning;
+            buttonStop.IsEnabled = isRunning;
+        }
+
+        private void MetroWindow_Activated(object sender, EventArgs e)
+        {
+
+        }
+
+        private void MetroWindow_Closing(object sender, CancelEventArgs e)
+        {
+            comAgent.shutdown();
+        }
+
+        private void buttonStartTreat_Click(object sender, RoutedEventArgs e)
+        {
+            if (targetTreatment == null && !checkBoxCustomMode.IsChecked.Value)
+            {
+                MessageBox.Show("请选择或添加一个治疗方案", "", MessageBoxButton.OK, MessageBoxImage.Error);
+                return;
+            }
+
+            if (checkBoxCustomMode.IsChecked.Value)
+            {
+                TreatmentStep[] steps = new TreatmentStep[treatmentCustomModeList.Count];
+                for (int i = 0; i < steps.Length; i++)
+                {
+                    steps[i] = new TreatmentStep((ushort)treatmentCustomModeList[i].tcRate,
+                        (byte)treatmentCustomModeList[i].tcActiveTime,
+                        (byte)treatmentCustomModeList[i].tcInactiveTime,
+                        (ushort)(treatmentCustomModeList[i].tcActiveTime + treatmentCustomModeList[i].tcInactiveTime));
+                }
+                comAgent.enqueueCommand(Com.createStartManualCommand((ushort)treatmentTime, (byte)(sliderStrength.Value * 100), steps));
+            }
+            else
+            {
+                comAgent.enqueueCommand(Com.createStartDefinedCommand(targetTreatment.id, (ushort)treatmentTime, (byte)(sliderStrength.Value * 100)));
+            }
+
+            isRunning = true;
+            updateUIIsRunning();
+        }
+
+        private void buttonStop_Click(object sender, RoutedEventArgs e)
+        {
+            if (checkBoxCustomMode.IsChecked.Value)
+            {
+                comAgent.enqueueCommand(Com.createStopCommand());
+            }
+            else
+            {
+                comAgent.enqueueCommand(Com.createStopCommand(targetTreatment.id.b()));
+            }
+
+            isRunning = false;
+            updateUIIsRunning();
+        }
     }
     }
 }
 }

+ 1 - 1
WpfTest1/SQLite/SQLiteLogic.cs

@@ -45,8 +45,8 @@ namespace WpfTest1.SQLite
                 SQLiteModel.CreateDoctorTable();
                 SQLiteModel.CreateDoctorTable();
                 SQLiteModel.CreateExpressionTable();
                 SQLiteModel.CreateExpressionTable();
                 SQLiteModel.CreateCommonWordsTable();
                 SQLiteModel.CreateCommonWordsTable();
+                SQLiteModel.CreateTreatmentTable();
             }
             }
- 
         }
         }
     }
     }
 }
 }

+ 236 - 2
WpfTest1/SQLite/SQLiteModel.cs

@@ -138,6 +138,45 @@ namespace WpfTest1.SQLite
             db.ExecuteNonQuery(sql, null);
             db.ExecuteNonQuery(sql, null);
         }
         }
 
 
+        //创建治疗方案表
+        public static void CreateTreatmentTable()
+        {
+            //如果不存在改数据库文件,则创建该数据库文件 
+            if (!System.IO.File.Exists(dbPath))
+            {
+                SQLiteHelper.CreateDB(dbPath);
+            }
+            SQLiteHelper db = new SQLiteHelper(dbPath);
+            string sql = @"CREATE TABLE Treatment (
+                                        t_id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
+                                        t_disease TEXT NOT NULL,
+                                        t_body_parts TEXT NOT NULL,
+                                        t_rate1 real,
+                                        t_rate2 real,
+                                        t_rate3 real,
+                                        t_rate4 real,
+                                        t_rate5 real,
+                                        t_rate6 real,
+                                        t_rate7 real,
+                                        t_rate8 real,
+                                        t_rate9 real,
+                                        t_rate10 real,
+                                        t_num1 integer,
+                                        t_num2 integer,
+                                        t_num3 integer,
+                                        t_num4 integer,
+                                        t_num5 integer,
+                                        t_num6 integer,
+                                        t_num7 integer,
+                                        t_num8 integer,
+                                        t_num9 integer,
+                                        t_num10 integer,
+                                        t_interval_time real,
+                                        t_repeat_times integer
+                                        )";
+            db.ExecuteNonQuery(sql, null);
+        }
+
         #endregion
         #endregion
 
 
         #region 数据库整体操作
         #region 数据库整体操作
@@ -631,7 +670,6 @@ namespace WpfTest1.SQLite
 
 
         #endregion
         #endregion
 
 
-
         #region doctor表相关的操作
         #region doctor表相关的操作
         //医生登录操作
         //医生登录操作
         public static doctor doctorLogin(string name,string passwordHash)
         public static doctor doctorLogin(string name,string passwordHash)
@@ -845,10 +883,206 @@ namespace WpfTest1.SQLite
                                                                };
                                                                };
             db.ExecuteNonQuery(sql, parameters);
             db.ExecuteNonQuery(sql, parameters);
         }
         }
-       
+
 
 
         #endregion
         #endregion
 
 
+        #region Treatment治疗方案表
+        // 增加
+        public static void insertTreatment(string disease, string bodyParts, double rate1, double rate2, double rate3, double rate4, double rate5, double rate6, double rate7, double rate8, double rate9, double rate10, int num1, int num2, int num3, int num4, int num5, int num6, int num7, int num8, int num9, int num10, double intervalTime, int repeatTimes)
+        {
+            string sql = "INSERT INTO Treatment(t_disease, t_body_parts, t_rate1, t_rate2, t_rate3, t_rate4, t_rate5, t_rate6, t_rate7, t_rate8, t_rate9, t_rate10, t_num1, t_num2, t_num3, t_num4, t_num5, t_num6, t_num7, t_num8, t_num9, t_num10, t_interval_time, t_repeat_times)" +
+                                        "values(@disease, @bodyParts, @rate1, @rate2, @rate3, @rate4, @rate5, @rate6, @rate7, @rate8, @rate9, @rate10, @num1, @num2, @num3, @num4, @num5, @num6, @num7, @num8, @num9, @num10, @intervalTime, @repeatTimes)";
+            SQLiteHelper db = new SQLiteHelper(dbPath);
+            SQLiteParameter[] parameters = new SQLiteParameter[]{
+                                                               new SQLiteParameter("@disease", disease),
+                                                               new SQLiteParameter("@bodyParts", bodyParts),
+                                                               new SQLiteParameter("@rate1", rate1),
+                                                               new SQLiteParameter("@rate2", rate2),
+                                                               new SQLiteParameter("@rate3", rate3),
+                                                               new SQLiteParameter("@rate4", rate4),
+                                                               new SQLiteParameter("@rate5", rate5),
+                                                               new SQLiteParameter("@rate6", rate6),
+                                                               new SQLiteParameter("@rate7", rate7),
+                                                               new SQLiteParameter("@rate8", rate8),
+                                                               new SQLiteParameter("@rate9", rate9),
+                                                               new SQLiteParameter("@rate10", rate10),
+                                                               new SQLiteParameter("@num1", num1),
+                                                               new SQLiteParameter("@num2", num2),
+                                                               new SQLiteParameter("@num3", num3),
+                                                               new SQLiteParameter("@num4", num4),
+                                                               new SQLiteParameter("@num5", num5),
+                                                               new SQLiteParameter("@num6", num6),
+                                                               new SQLiteParameter("@num7", num7),
+                                                               new SQLiteParameter("@num8", num8),
+                                                               new SQLiteParameter("@num9", num9),
+                                                               new SQLiteParameter("@num10", num10),
+                                                               new SQLiteParameter("@intervalTime", intervalTime),
+                                                               new SQLiteParameter("@repeatTimes", repeatTimes),
+                                                               };
+            db.ExecuteNonQuery(sql, parameters);
+        }
+
+        // 删除
+        public static int deleteTreatment(int id)
+        {
+            string sql = "DELETE from Treatment WHERE t_id = @id";
+            SQLiteHelper db = new SQLiteHelper(dbPath);
+            SQLiteParameter[] parameters = new SQLiteParameter[] {
+                                                               new SQLiteParameter("@id", id),
+                                                               };
+            return db.ExecuteNonQuery(sql, parameters);
+        }
+
+        // 修改
+        public static void updateTreatment(int id, string disease, string bodyParts, double rate1, double rate2, double rate3, double rate4, double rate5, double rate6, double rate7, double rate8, double rate9, double rate10, int num1, int num2, int num3, int num4, int num5, int num6, int num7, int num8, int num9, int num10, double intervalTime, int repeatTimes)
+        {
+            string sql = "UPDATE Treatment SET " +
+                         "t_disease = @disease, " +
+                         "t_body_parts = @bodyParts, " +
+                         "t_rate1 = @rate1, " +
+                         "t_rate2 = @rate2, " +
+                         "t_rate3 = @rate3, " +
+                         "t_rate4 = @rate4, " +
+                         "t_rate5 = @rate5, " +
+                         "t_rate6 = @rate6, " +
+                         "t_rate7 = @rate7, " +
+                         "t_rate8 = @rate8, " +
+                         "t_rate9 = @rate9, " +
+                         "t_rate10 = @rate10, " +
+                         "t_num1 = @num1, " +
+                         "t_num2 = @num2, " +
+                         "t_num3 = @num3, " +
+                         "t_num4 = @num4, " +
+                         "t_num5 = @num5, " +
+                         "t_num6 = @num6, " +
+                         "t_num7 = @num7, " +
+                         "t_num8 = @num8, " +
+                         "t_num9 = @num9, " +
+                         "t_num10 = @num10, " +
+                         "t_interval_time = @intervalTime, " +
+                         "t_repeat_times = @repeatTimes " +
+                         "WHERE t_id = @id ";
+            SQLiteHelper db = new SQLiteHelper(dbPath);
+            SQLiteParameter[] parameters = new SQLiteParameter[]{
+                                                               new SQLiteParameter("@id", id),
+                                                               new SQLiteParameter("@disease", disease),
+                                                               new SQLiteParameter("@bodyParts", bodyParts),
+                                                               new SQLiteParameter("@rate1", rate1),
+                                                               new SQLiteParameter("@rate2", rate2),
+                                                               new SQLiteParameter("@rate3", rate3),
+                                                               new SQLiteParameter("@rate4", rate4),
+                                                               new SQLiteParameter("@rate5", rate5),
+                                                               new SQLiteParameter("@rate6", rate6),
+                                                               new SQLiteParameter("@rate7", rate7),
+                                                               new SQLiteParameter("@rate8", rate8),
+                                                               new SQLiteParameter("@rate9", rate9),
+                                                               new SQLiteParameter("@rate10", rate10),
+                                                               new SQLiteParameter("@num1", num1),
+                                                               new SQLiteParameter("@num2", num2),
+                                                               new SQLiteParameter("@num3", num3),
+                                                               new SQLiteParameter("@num4", num4),
+                                                               new SQLiteParameter("@num5", num5),
+                                                               new SQLiteParameter("@num6", num6),
+                                                               new SQLiteParameter("@num7", num7),
+                                                               new SQLiteParameter("@num8", num8),
+                                                               new SQLiteParameter("@num9", num9),
+                                                               new SQLiteParameter("@num10", num10),
+                                                               new SQLiteParameter("@intervalTime", intervalTime),
+                                                               new SQLiteParameter("@repeatTimes", repeatTimes),
+                                                               new SQLiteParameter("@id", id),
+                                                               };
+            //System.Console.WriteLine(sql);
+            db.ExecuteNonQuery(sql, parameters);
+        }
+
+        // 查询
+        public static Treatment getTreatmentById(int id)
+        {
+            string sql = "SELECT * FROM Treatment WHERE t_id = @id";
+            SQLiteHelper db = new SQLiteHelper(dbPath);
+            SQLiteParameter[] parameters = new SQLiteParameter[]{
+                                                               new SQLiteParameter("@id",id),
+                                                               };
+            using (SQLiteDataReader reader = db.ExecuteReader(sql, parameters))
+            {
+                while (reader.Read())
+                {
+                    Treatment temp = new Treatment();
+                    temp.id           = reader.IsDBNull( 0) ? 0  : reader.GetInt32(  0);
+                    temp.disease      = reader.IsDBNull( 1) ? "" : reader.GetString( 1);
+                    temp.bodyParts    = reader.IsDBNull( 2) ? "" : reader.GetString( 2);
+                    temp.rate1        = reader.IsDBNull( 3) ? 0  : reader.GetDouble( 3);
+                    temp.rate2        = reader.IsDBNull( 4) ? 0  : reader.GetDouble( 4);
+                    temp.rate3        = reader.IsDBNull( 5) ? 0  : reader.GetDouble( 5);
+                    temp.rate4        = reader.IsDBNull( 6) ? 0  : reader.GetDouble( 6);
+                    temp.rate5        = reader.IsDBNull( 7) ? 0  : reader.GetDouble( 7);
+                    temp.rate6        = reader.IsDBNull( 8) ? 0  : reader.GetDouble( 8);
+                    temp.rate7        = reader.IsDBNull( 9) ? 0  : reader.GetDouble( 9);
+                    temp.rate8        = reader.IsDBNull(10) ? 0  : reader.GetDouble(10);
+                    temp.rate9        = reader.IsDBNull(11) ? 0  : reader.GetDouble(11);
+                    temp.rate10       = reader.IsDBNull(12) ? 0  : reader.GetDouble(12);
+                    temp.num1         = reader.IsDBNull(13) ? 0  : reader.GetInt32( 13);
+                    temp.num2         = reader.IsDBNull(14) ? 0  : reader.GetInt32( 14);
+                    temp.num3         = reader.IsDBNull(15) ? 0  : reader.GetInt32( 15);
+                    temp.num4         = reader.IsDBNull(16) ? 0  : reader.GetInt32( 16);
+                    temp.num5         = reader.IsDBNull(17) ? 0  : reader.GetInt32( 17);
+                    temp.num6         = reader.IsDBNull(18) ? 0  : reader.GetInt32( 18);
+                    temp.num7         = reader.IsDBNull(19) ? 0  : reader.GetInt32( 19);
+                    temp.num8         = reader.IsDBNull(20) ? 0  : reader.GetInt32( 20);
+                    temp.num9         = reader.IsDBNull(21) ? 0  : reader.GetInt32( 21);
+                    temp.num10        = reader.IsDBNull(22) ? 0  : reader.GetInt32( 22);
+                    temp.intervalTime = reader.IsDBNull(23) ? 0  : reader.GetDouble(23);
+                    temp.repeatTimes  = reader.IsDBNull(24) ? 0  : reader.GetInt32( 24);
+                    return temp;
+                }
+            }
+            return null;
+        }
+
+        public static List<Treatment> getALLTreatment()
+        {
+            string sql = "SELECT * FROM Treatment";
+            SQLiteHelper db = new SQLiteHelper(dbPath);
+            SQLiteParameter[] parameters = new SQLiteParameter[] { };
+            List<Treatment> result = new List<Treatment>();
+            using (SQLiteDataReader reader = db.ExecuteReader(sql, parameters))
+            {
+                while (reader.Read())
+                {
+                    Treatment temp = new Treatment();
+                    temp.id           = reader.IsDBNull( 0) ? 0  : reader.GetInt32(  0);
+                    temp.disease      = reader.IsDBNull( 1) ? "" : reader.GetString( 1);
+                    temp.bodyParts    = reader.IsDBNull( 2) ? "" : reader.GetString( 2);
+                    temp.rate1        = reader.IsDBNull( 3) ? 0  : reader.GetDouble( 3);
+                    temp.rate2        = reader.IsDBNull( 4) ? 0  : reader.GetDouble( 4);
+                    temp.rate3        = reader.IsDBNull( 5) ? 0  : reader.GetDouble( 5);
+                    temp.rate4        = reader.IsDBNull( 6) ? 0  : reader.GetDouble( 6);
+                    temp.rate5        = reader.IsDBNull( 7) ? 0  : reader.GetDouble( 7);
+                    temp.rate6        = reader.IsDBNull( 8) ? 0  : reader.GetDouble( 8);
+                    temp.rate7        = reader.IsDBNull( 9) ? 0  : reader.GetDouble( 9);
+                    temp.rate8        = reader.IsDBNull(10) ? 0  : reader.GetDouble(10);
+                    temp.rate9        = reader.IsDBNull(11) ? 0  : reader.GetDouble(11);
+                    temp.rate10       = reader.IsDBNull(12) ? 0  : reader.GetDouble(12);
+                    temp.num1         = reader.IsDBNull(13) ? 0  : reader.GetInt32( 13);
+                    temp.num2         = reader.IsDBNull(14) ? 0  : reader.GetInt32( 14);
+                    temp.num3         = reader.IsDBNull(15) ? 0  : reader.GetInt32( 15);
+                    temp.num4         = reader.IsDBNull(16) ? 0  : reader.GetInt32( 16);
+                    temp.num5         = reader.IsDBNull(17) ? 0  : reader.GetInt32( 17);
+                    temp.num6         = reader.IsDBNull(18) ? 0  : reader.GetInt32( 18);
+                    temp.num7         = reader.IsDBNull(19) ? 0  : reader.GetInt32( 19);
+                    temp.num8         = reader.IsDBNull(20) ? 0  : reader.GetInt32( 20);
+                    temp.num9         = reader.IsDBNull(21) ? 0  : reader.GetInt32( 21);
+                    temp.num10        = reader.IsDBNull(22) ? 0  : reader.GetInt32( 22);
+                    temp.intervalTime = reader.IsDBNull(23) ? 0  : reader.GetDouble(23);
+                    temp.repeatTimes  = reader.IsDBNull(24) ? 0  : reader.GetInt32( 24);
+                    result.Add(temp);
+                }
+            }
+            return result;
+        }
+
+        #endregion
         #region 以下是测试功能,请在生产环境之前删除这些功能
         #region 以下是测试功能,请在生产环境之前删除这些功能
         public static byte[] getRecordData()
         public static byte[] getRecordData()
         {
         {

+ 57 - 0
WpfTest1/SQLite/Treatment.cs

@@ -0,0 +1,57 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace WpfTest1.SQLite
+{
+    public class Treatment
+    {
+        public int id { get; set; }
+        public string disease { get; set; }
+        public string bodyParts { get; set; }
+        public double rate1 { get; set; }
+        public double rate2 { get; set; }
+        public double rate3 { get; set; }
+        public double rate4 { get; set; }
+        public double rate5 { get; set; }
+        public double rate6 { get; set; }
+        public double rate7 { get; set; }
+        public double rate8 { get; set; }
+        public double rate9 { get; set; }
+        public double rate10 { get; set; }
+        public int num1 { get; set; }
+        public int num2 { get; set; }
+        public int num3 { get; set; }
+        public int num4 { get; set; }
+        public int num5 { get; set; }
+        public int num6 { get; set; }
+        public int num7 { get; set; }
+        public int num8 { get; set; }
+        public int num9 { get; set; }
+        public int num10 { get; set; }
+        public double intervalTime { get; set; }
+        public int repeatTimes { get; set; }
+        public double totalTime => Math.Round((num1 / rate1 + 
+                                               num2 / rate2 +
+                                               num3 / rate3 +
+                                               num4 / rate4 +
+                                               num5 / rate5 +
+                                               num6 / rate6 +
+                                               num7 / rate7 +
+                                               num8 / rate8 +
+                                               num9 / rate9 +
+                                               num10 / rate10 + intervalTime) * repeatTimes, 2);
+        public int totalNum => (num1 + num2 + num3 + num4 + num5 + num6 + num7 + num8 + num9 + num10) * repeatTimes;
+    }
+
+    //*/
+    public class TreatmentCustomItem
+    {
+        public int tcID { get; set; }
+        public double tcRate { get; set; }
+        public double tcActiveTime { get; set; }
+        public double tcInactiveTime { get; set; }
+    }//*/
+}

+ 2 - 2
WpfTest1/SmallDialogs/ModifyUser.xaml

@@ -33,8 +33,8 @@
         </DatePicker>
         </DatePicker>
         <TextBox x:Name="textBoxMobile" HorizontalAlignment="Left" Height="33" Margin="555,37,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="191" FontSize="15"/>
         <TextBox x:Name="textBoxMobile" HorizontalAlignment="Left" Height="33" Margin="555,37,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="191" FontSize="15"/>
         <TextBox x:Name="textBoxAddress" HorizontalAlignment="Left" Height="33" Margin="555,83,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="191" FontSize="15"/>
         <TextBox x:Name="textBoxAddress" HorizontalAlignment="Left" Height="33" Margin="555,83,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="191" FontSize="15"/>
-        <TextBox x:Name="textBoxHistory" HorizontalAlignment="Left" Height="113" Margin="555,123,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="191" FontSize="15"/>
-        <TextBox x:Name="textBoxDiagnosis" HorizontalAlignment="Left" Height="113" Margin="555,243,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="191" FontSize="15"/>
+        <TextBox x:Name="textBoxHistory" HorizontalAlignment="Left" Height="113" Margin="555,123,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="191" FontSize="15" VerticalScrollBarVisibility="Auto"/>
+        <TextBox x:Name="textBoxDiagnosis" HorizontalAlignment="Left" Height="113" Margin="555,243,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="191" FontSize="15" VerticalScrollBarVisibility="Auto"/>
         <Label x:Name="label_Copy15" Content="*" HorizontalAlignment="Left" FontWeight="Bold" Foreground="Blue" Margin="93,37,0,0" VerticalAlignment="Top" FontSize="18"/>
         <Label x:Name="label_Copy15" Content="*" HorizontalAlignment="Left" FontWeight="Bold" Foreground="Blue" Margin="93,37,0,0" VerticalAlignment="Top" FontSize="18"/>
         <Label x:Name="label_Copy17" Content="*" HorizontalAlignment="Left" FontWeight="Bold" Foreground="Blue" Margin="129,83,0,0" VerticalAlignment="Top" FontSize="18"/>
         <Label x:Name="label_Copy17" Content="*" HorizontalAlignment="Left" FontWeight="Bold" Foreground="Blue" Margin="129,83,0,0" VerticalAlignment="Top" FontSize="18"/>
         <Label x:Name="label_Copy18" Content="*" HorizontalAlignment="Left" FontWeight="Bold" Foreground="Blue" Margin="39,123,0,0" VerticalAlignment="Top" FontSize="18"/>
         <Label x:Name="label_Copy18" Content="*" HorizontalAlignment="Left" FontWeight="Bold" Foreground="Blue" Margin="39,123,0,0" VerticalAlignment="Top" FontSize="18"/>

+ 51 - 0
WpfTest1/SmallDialogs/TreatmentPlan.xaml

@@ -0,0 +1,51 @@
+<Window x:Class="WpfTest1.TreatmentPlan"
+        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+        xmlns:local="clr-namespace:WpfTest1.SmallDialogs"
+        mc:Ignorable="d"
+        Title="治疗方案" Height="513.745" Width="864.286">
+    <Grid>
+        <Button x:Name="buttonAdd" Content="新增" HorizontalAlignment="Left" Margin="385,431,0,0" VerticalAlignment="Top" Width="75" FontSize="18" Click="buttonAdd_Click" />
+        <Button x:Name="buttonDelete" Content="删除" HorizontalAlignment="Left" Margin="507,431,0,0" VerticalAlignment="Top" Width="75" FontSize="18" Click="buttonDelete_Click" />
+        <Button x:Name="buttonChange" Content="修改" HorizontalAlignment="Left" Margin="630,431,0,0" VerticalAlignment="Top" Width="75" FontSize="18" Click="buttonChange_Click" />
+        <Button x:Name="buttonSelect" Content="选择" HorizontalAlignment="Left" Margin="752,431,0,0" VerticalAlignment="Top" Width="75" FontSize="18" Background="#FF11CE66" Click="buttonSelect_Click" />
+        <DataGrid x:Name="dataGrid" HorizontalAlignment="Left" Height="466" Margin="10,10,0,0" VerticalAlignment="Top" Width="330" IsReadOnly="True" SelectionMode="Single" SelectionChanged="dataGrid_SelectionChanged" AutoGenerateColumns="False" CanUserReorderColumns="False">
+            <DataGrid.Columns>
+                <DataGridTextColumn Header="ID" Binding="{Binding Path=id}" Width="35"/>
+                <DataGridTextColumn Header="方案名" Binding="{Binding Path=disease}" Width="215"/>
+                <DataGridTextColumn Header="刺激部位" Binding="{Binding Path=bodyParts}" Width="80"/>
+            </DataGrid.Columns>
+        </DataGrid>
+        <Label x:Name="label" Content="          病症:&#xA;&#xA;  频率1(Hz)&#xA;&#xA;  频率2(Hz)&#xA;&#xA;  频率3(Hz)&#xA;&#xA;  频率4(Hz)&#xA;&#xA;  频率5(Hz)&#xA;&#xA;  频率6(Hz)&#xA;&#xA;  频率7(Hz)&#xA;&#xA;  频率8(Hz)&#xA;&#xA;  频率9(Hz)&#xA;&#xA;频率10(Hz)&#xA;&#xA; 间歇时间:&#xA;&#xA; " HorizontalAlignment="Left" Margin="373,10,0,0" VerticalAlignment="Top" Height="402" Width="87" HorizontalContentAlignment="Right"/>
+        <Label x:Name="label_Copy" Content=" 刺激部位:&#xA;&#xA;  刺激个数1&#xA;&#xA;  刺激个数2&#xA;&#xA;  刺激个数3&#xA;&#xA;  刺激个数4&#xA;&#xA;  刺激个数5&#xA;&#xA;  刺激个数6&#xA;&#xA;  刺激个数7&#xA;&#xA;  刺激个数8&#xA;&#xA;  刺激个数9&#xA;&#xA;刺激个数10&#xA;&#xA;&#xA; " HorizontalAlignment="Left" Margin="598,10,0,0" VerticalAlignment="Top" Height="402" Width="87" HorizontalContentAlignment="Right"/>
+        <TextBox x:Name="textBoxDisease" HorizontalAlignment="Left" Height="25" Margin="465,11,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="120" TextChanged="textBoxRateAll_TextChanged"/>
+        <TextBox x:Name="textBoxRate1" HorizontalAlignment="Left" Height="23" Margin="465,41,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="120" TextChanged="textBoxRateAll_TextChanged"/>
+        <TextBox x:Name="textBoxRate2" HorizontalAlignment="Left" Height="23" Margin="465,72,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="120" TextChanged="textBoxRateAll_TextChanged"/>
+        <TextBox x:Name="textBoxRate3" HorizontalAlignment="Left" Height="23" Margin="465,102,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="120" TextChanged="textBoxRateAll_TextChanged"/>
+        <TextBox x:Name="textBoxRate4" HorizontalAlignment="Left" Height="22" Margin="465,133,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="120" TextChanged="textBoxRateAll_TextChanged"/>
+        <TextBox x:Name="textBoxRate5" HorizontalAlignment="Left" Height="23" Margin="465,163,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="120" TextChanged="textBoxRateAll_TextChanged"/>
+        <TextBox x:Name="textBoxRate6" HorizontalAlignment="Left" Height="24" Margin="465,193,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="120" TextChanged="textBoxRateAll_TextChanged"/>
+        <TextBox x:Name="textBoxRate7" HorizontalAlignment="Left" Height="23" Margin="465,224,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="120" TextChanged="textBoxRateAll_TextChanged"/>
+        <TextBox x:Name="textBoxRate8" HorizontalAlignment="Left" Height="23" Margin="465,254,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="120" TextChanged="textBoxRateAll_TextChanged"/>
+        <TextBox x:Name="textBoxRate9" HorizontalAlignment="Left" Height="24" Margin="465,285,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="120" TextChanged="textBoxRateAll_TextChanged"/>
+        <TextBox x:Name="textBoxRate10" HorizontalAlignment="Left" Height="23" Margin="465,315,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="120" TextChanged="textBoxRateAll_TextChanged"/>
+        <TextBox x:Name="textBoxIntervalTime" HorizontalAlignment="Left" Height="23" Margin="465,346,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="120" TextChanged="textBoxIntervalTime_TextChanged"/>
+        <TextBox x:Name="textBoxTotalTime" HorizontalAlignment="Left" Height="23" Margin="465,376,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="120" IsReadOnly="True" Visibility="Hidden"/>
+        <TextBox x:Name="textBoxBodyParts" HorizontalAlignment="Left" Height="25" Margin="690,11,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="120" TextChanged="textBoxRateAll_TextChanged"/>
+        <TextBox x:Name="textBoxNum1" HorizontalAlignment="Left" Height="23" Margin="690,41,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="120" TextChanged="textBoxRateAll_TextChanged"/>
+        <TextBox x:Name="textBoxNum2" HorizontalAlignment="Left" Height="23" Margin="690,72,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="120" TextChanged="textBoxRateAll_TextChanged"/>
+        <TextBox x:Name="textBoxNum3" HorizontalAlignment="Left" Height="23" Margin="690,102,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="120" TextChanged="textBoxRateAll_TextChanged"/>
+        <TextBox x:Name="textBoxNum4" HorizontalAlignment="Left" Height="22" Margin="690,133,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="120" TextChanged="textBoxRateAll_TextChanged"/>
+        <TextBox x:Name="textBoxNum5" HorizontalAlignment="Left" Height="23" Margin="690,163,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="120" TextChanged="textBoxRateAll_TextChanged"/>
+        <TextBox x:Name="textBoxNum6" HorizontalAlignment="Left" Height="24" Margin="690,193,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="120" TextChanged="textBoxRateAll_TextChanged"/>
+        <TextBox x:Name="textBoxNum7" HorizontalAlignment="Left" Height="23" Margin="690,224,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="120" TextChanged="textBoxRateAll_TextChanged"/>
+        <TextBox x:Name="textBoxNum8" HorizontalAlignment="Left" Height="23" Margin="690,254,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="120" TextChanged="textBoxRateAll_TextChanged"/>
+        <TextBox x:Name="textBoxNum9" HorizontalAlignment="Left" Height="24" Margin="690,285,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="120" TextChanged="textBoxRateAll_TextChanged"/>
+        <TextBox x:Name="textBoxNum10" HorizontalAlignment="Left" Height="23" Margin="690,315,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="120" TextChanged="textBoxRateAll_TextChanged"/>
+        <TextBox x:Name="textBoxRepeatTimes" HorizontalAlignment="Left" Height="23" Margin="690,346,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="120" TextChanged="textBoxRepeatTimes_TextChanged" Visibility="Hidden"/>
+        <TextBox x:Name="textBoxTotalNum" HorizontalAlignment="Left" Height="23" Margin="690,376,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="120" IsReadOnly="True" Visibility="Hidden"/>
+
+    </Grid>
+</Window>

+ 387 - 0
WpfTest1/SmallDialogs/TreatmentPlan.xaml.cs

@@ -0,0 +1,387 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Shapes;
+using WpfTest1.SQLite;
+
+namespace WpfTest1
+{
+    /// <summary>
+    /// TreatmentPlan.xaml 的交互逻辑
+    /// </summary>
+    public partial class TreatmentPlan : Window
+    {
+        MainWindow father;
+        public List<Treatment> treatmentList;
+        private Treatment target = null;
+
+        public TreatmentPlan(MainWindow father)
+        {
+            this.father = father;
+            InitializeComponent();
+
+            loadDataGrid();
+        }
+
+        public void loadDataGrid()
+        {
+            treatmentList = SQLiteModel.getALLTreatment();
+            dataGrid.ItemsSource = treatmentList;
+            target = null;
+        }
+
+        private void dataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
+        {
+            target = (Treatment)dataGrid.CurrentItem;
+            if (target != null)
+            {
+                textBoxDisease.Text = target.disease;
+                textBoxBodyParts.Text = target.bodyParts;
+                textBoxRate1.Text = target.rate1.ToString();
+                textBoxRate2.Text = target.rate2.ToString();
+                textBoxRate3.Text = target.rate3.ToString();
+                textBoxRate4.Text = target.rate4.ToString();
+                textBoxRate5.Text = target.rate5.ToString();
+                textBoxRate6.Text = target.rate6.ToString();
+                textBoxRate7.Text = target.rate7.ToString();
+                textBoxRate8.Text = target.rate8.ToString();
+                textBoxRate9.Text = target.rate9.ToString();
+                textBoxRate10.Text = target.rate10.ToString();
+                textBoxNum1.Text = target.num1.ToString();
+                textBoxNum2.Text = target.num2.ToString();
+                textBoxNum3.Text = target.num3.ToString();
+                textBoxNum4.Text = target.num4.ToString();
+                textBoxNum5.Text = target.num5.ToString();
+                textBoxNum6.Text = target.num6.ToString();
+                textBoxNum7.Text = target.num7.ToString();
+                textBoxNum8.Text = target.num8.ToString();
+                textBoxNum9.Text = target.num9.ToString();
+                textBoxNum10.Text = target.num10.ToString();
+                textBoxIntervalTime.Text = target.intervalTime.ToString();
+                textBoxRepeatTimes.Text = target.repeatTimes.ToString();
+                textBoxTotalTime.Text = target.totalTime.ToString();
+                textBoxTotalNum.Text = target.totalNum.ToString();
+            } else {
+                textBoxDisease.Text = "";
+                textBoxBodyParts.Text = "";
+                textBoxRate1.Text = "";
+                textBoxRate2.Text = "";
+                textBoxRate3.Text = "";
+                textBoxRate4.Text = "";
+                textBoxRate5.Text = "";
+                textBoxRate6.Text = "";
+                textBoxRate7.Text = "";
+                textBoxRate8.Text = "";
+                textBoxRate9.Text = "";
+                textBoxRate10.Text = "";
+                textBoxNum1.Text = "";
+                textBoxNum2.Text = "";
+                textBoxNum3.Text = "";
+                textBoxNum4.Text = "";
+                textBoxNum5.Text = "";
+                textBoxNum6.Text = "";
+                textBoxNum7.Text = "";
+                textBoxNum8.Text = "";
+                textBoxNum9.Text = "";
+                textBoxNum10.Text = "";
+                textBoxIntervalTime.Text = "";
+                textBoxRepeatTimes.Text = "";
+                textBoxTotalTime.Text = "";
+                textBoxTotalNum.Text = "";
+            }
+        }
+
+        private void textBoxDisease_TextChanged(object sender, TextChangedEventArgs e)
+        {
+            checkChange();
+        }
+
+        private void textBoxBodyParts_TextChanged(object sender, TextChangedEventArgs e)
+        {
+            checkChange();
+        }
+
+        private void textBoxRateAll_TextChanged(object sender, TextChangedEventArgs e)
+        {
+            checkChange();
+        }
+
+        private void textBoxIntervalTime_TextChanged(object sender, TextChangedEventArgs e)
+        {
+            checkChange();
+        }
+
+        private void textBoxRepeatTimes_TextChanged(object sender, TextChangedEventArgs e)
+        {
+            checkChange();
+        }
+
+        private void checkChange()
+        {
+            if (target != null)
+            {
+                textBoxDisease.Background = textBoxDisease.Text == target.disease ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
+                textBoxBodyParts.Background = textBoxBodyParts.Text == target.bodyParts ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
+                textBoxRate1.Background = textBoxRate1.Text == target.rate1.ToString() ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
+                textBoxRate2.Background = textBoxRate2.Text == target.rate2.ToString() ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
+                textBoxRate3.Background = textBoxRate3.Text == target.rate3.ToString() ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
+                textBoxRate4.Background = textBoxRate4.Text == target.rate4.ToString() ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
+                textBoxRate5.Background = textBoxRate5.Text == target.rate5.ToString() ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
+                textBoxRate6.Background = textBoxRate6.Text == target.rate6.ToString() ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
+                textBoxRate7.Background = textBoxRate7.Text == target.rate7.ToString() ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
+                textBoxRate8.Background = textBoxRate8.Text == target.rate8.ToString() ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
+                textBoxRate9.Background = textBoxRate9.Text == target.rate9.ToString() ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
+                textBoxRate10.Background = textBoxRate10.Text == target.rate10.ToString() ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
+                textBoxNum1.Background = textBoxNum1.Text == target.num1.ToString() ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
+                textBoxNum2.Background = textBoxNum2.Text == target.num2.ToString() ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
+                textBoxNum3.Background = textBoxNum3.Text == target.num3.ToString() ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
+                textBoxNum4.Background = textBoxNum4.Text == target.num4.ToString() ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
+                textBoxNum5.Background = textBoxNum5.Text == target.num5.ToString() ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
+                textBoxNum6.Background = textBoxNum6.Text == target.num6.ToString() ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
+                textBoxNum7.Background = textBoxNum7.Text == target.num7.ToString() ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
+                textBoxNum8.Background = textBoxNum8.Text == target.num8.ToString() ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
+                textBoxNum9.Background = textBoxNum9.Text == target.num9.ToString() ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
+                textBoxNum10.Background = textBoxNum10.Text == target.num10.ToString() ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
+                textBoxIntervalTime.Background = textBoxIntervalTime.Text == target.intervalTime.ToString() ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
+                textBoxRepeatTimes.Background = textBoxRepeatTimes.Text == target.repeatTimes.ToString() ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
+                checkError();
+            } else {
+                textBoxDisease.Background = Brushes.White;
+                textBoxBodyParts.Background = Brushes.White;
+                textBoxRate1.Background = Brushes.White;
+                textBoxRate2.Background = Brushes.White;
+                textBoxRate3.Background = Brushes.White;
+                textBoxRate4.Background = Brushes.White;
+                textBoxRate5.Background = Brushes.White;
+                textBoxRate6.Background = Brushes.White;
+                textBoxRate7.Background = Brushes.White;
+                textBoxRate8.Background = Brushes.White;
+                textBoxRate9.Background = Brushes.White;
+                textBoxRate10.Background = Brushes.White;
+                textBoxNum1.Background = Brushes.White;
+                textBoxNum2.Background = Brushes.White;
+                textBoxNum3.Background = Brushes.White;
+                textBoxNum4.Background = Brushes.White;
+                textBoxNum5.Background = Brushes.White;
+                textBoxNum6.Background = Brushes.White;
+                textBoxNum7.Background = Brushes.White;
+                textBoxNum8.Background = Brushes.White;
+                textBoxNum9.Background = Brushes.White;
+                textBoxNum10.Background = Brushes.White;
+                textBoxIntervalTime.Background = Brushes.White;
+                textBoxRepeatTimes.Background = Brushes.White;
+            }
+        }
+
+        private bool checkError()
+        {
+            bool error = false;
+            TextBox[] textBoxRateList = { textBoxRate1, textBoxRate2, textBoxRate3, textBoxRate4, textBoxRate5, textBoxRate6, textBoxRate7, textBoxRate8, textBoxRate9, textBoxRate10 };
+            for (int i = 0; i < 10; i++)
+            {
+                double t = 0;
+                if (double.TryParse(textBoxRateList[i].Text, out t))
+                {
+                    if (t >= 0 & t < 1)
+                    {
+                        if ((t * 10 % 1).Equals(0))
+                        {
+                            continue;
+                        }
+                    }
+                    else if (t >= 1 & t <= 100)
+                    {
+                        if (t % 1 == 0)
+                        {
+                            continue;
+                        }
+                    }
+                }
+                textBoxRateList[i].Background = (Brush)new BrushConverter().ConvertFrom("#FFFFB5B5");
+                error = true;
+            }
+            TextBox[] textBoxNumList = { textBoxNum1, textBoxNum2, textBoxNum3, textBoxNum4, textBoxNum5, textBoxNum6, textBoxNum7, textBoxNum8, textBoxNum9, textBoxNum10, textBoxIntervalTime, textBoxRepeatTimes };
+            for (int i = 0; i < 12; i++)
+            {
+                int t = 0;
+                if (int.TryParse(textBoxNumList[i].Text, out t))
+                {
+                    if (t >= 0 & t <= 100)
+                    {
+                        if (t % 1 == 0)
+                        {
+                            continue;
+                        }
+                    }
+                }
+                textBoxNumList[i].Background = (Brush)new BrushConverter().ConvertFrom("#FFFFB5B5");
+                error = true;
+            }
+            return error;
+        }
+
+        private bool isEqualsTarget()
+        {
+            if (target == null) return true;
+            int changenum = 0;
+            changenum = textBoxDisease.Text == target.disease ? changenum : changenum + 1;
+            changenum = textBoxBodyParts.Text == target.bodyParts ? changenum : changenum + 1;
+            changenum = textBoxRate1.Text == target.rate1.ToString() ? changenum : changenum + 1;
+            changenum = textBoxRate2.Text == target.rate2.ToString() ? changenum : changenum + 1;
+            changenum = textBoxRate3.Text == target.rate3.ToString() ? changenum : changenum + 1;
+            changenum = textBoxRate4.Text == target.rate4.ToString() ? changenum : changenum + 1;
+            changenum = textBoxRate5.Text == target.rate5.ToString() ? changenum : changenum + 1;
+            changenum = textBoxRate6.Text == target.rate6.ToString() ? changenum : changenum + 1;
+            changenum = textBoxRate7.Text == target.rate7.ToString() ? changenum : changenum + 1;
+            changenum = textBoxRate8.Text == target.rate8.ToString() ? changenum : changenum + 1;
+            changenum = textBoxRate9.Text == target.rate9.ToString() ? changenum : changenum + 1;
+            changenum = textBoxRate10.Text == target.rate10.ToString() ? changenum : changenum + 1;
+            changenum = textBoxNum1.Text == target.num1.ToString() ? changenum : changenum + 1;
+            changenum = textBoxNum2.Text == target.num2.ToString() ? changenum : changenum + 1;
+            changenum = textBoxNum3.Text == target.num3.ToString() ? changenum : changenum + 1;
+            changenum = textBoxNum4.Text == target.num4.ToString() ? changenum : changenum + 1;
+            changenum = textBoxNum5.Text == target.num5.ToString() ? changenum : changenum + 1;
+            changenum = textBoxNum6.Text == target.num6.ToString() ? changenum : changenum + 1;
+            changenum = textBoxNum7.Text == target.num7.ToString() ? changenum : changenum + 1;
+            changenum = textBoxNum8.Text == target.num8.ToString() ? changenum : changenum + 1;
+            changenum = textBoxNum9.Text == target.num9.ToString() ? changenum : changenum + 1;
+            changenum = textBoxNum10.Text == target.num10.ToString() ? changenum : changenum + 1;
+            changenum = textBoxIntervalTime.Text == target.intervalTime.ToString() ? changenum : changenum + 1;
+            changenum = textBoxRepeatTimes.Text == target.repeatTimes.ToString() ? changenum : changenum + 1;
+            return changenum == 0 ? true : false;
+        }
+
+        private void buttonChange_Click(object sender, RoutedEventArgs e)
+        {
+            if (target == null)
+            {
+                MessageBox.Show("请选择要修改的治疗方案!");
+                return;
+            }
+
+            int id = target.id;
+            string disease = textBoxDisease.Text;
+            string bodyParts = textBoxBodyParts.Text;
+
+            double.TryParse(textBoxRate1.Text, out double rate1);
+            double.TryParse(textBoxRate2.Text, out double rate2);
+            double.TryParse(textBoxRate3.Text, out double rate3);
+            double.TryParse(textBoxRate4.Text, out double rate4);
+            double.TryParse(textBoxRate5.Text, out double rate5);
+            double.TryParse(textBoxRate6.Text, out double rate6);
+            double.TryParse(textBoxRate7.Text, out double rate7);
+            double.TryParse(textBoxRate8.Text, out double rate8);
+            double.TryParse(textBoxRate9.Text, out double rate9);
+            double.TryParse(textBoxRate10.Text, out double rate10);
+            int.TryParse(textBoxNum1.Text, out int num1);
+            int.TryParse(textBoxNum2.Text, out int num2);
+            int.TryParse(textBoxNum3.Text, out int num3);
+            int.TryParse(textBoxNum4.Text, out int num4);
+            int.TryParse(textBoxNum5.Text, out int num5);
+            int.TryParse(textBoxNum6.Text, out int num6);
+            int.TryParse(textBoxNum7.Text, out int num7);
+            int.TryParse(textBoxNum8.Text, out int num8);
+            int.TryParse(textBoxNum9.Text, out int num9);
+            int.TryParse(textBoxNum10.Text, out int num10);
+            double.TryParse(textBoxIntervalTime.Text, out double intervalTime);
+            int.TryParse(textBoxRepeatTimes.Text, out int repeatTimes);
+
+            if (checkError())
+            {
+                MessageBox.Show("存在无效数据,请检查后再点击修改按钮!");
+                return;
+            }
+            if (isEqualsTarget())
+            {
+                MessageBox.Show("未进行任何修改!");
+                return;
+            }
+
+            SQLiteModel.updateTreatment(id, disease, bodyParts, rate1, rate2, rate3, rate4, rate5, rate6, rate7, rate8, rate9, rate10, num1, num2, num3, num4, num5, num6, num7, num8, num9, num10, intervalTime, repeatTimes);
+            loadDataGrid();
+        }
+
+        private void buttonAdd_Click(object sender, RoutedEventArgs e)
+        {
+            if (target == null)
+            {
+                MessageBox.Show("请先随意选择一个方案,修改完成后再点击新增按钮。");
+                return;
+            }
+
+            string disease = textBoxDisease.Text;
+            string bodyParts = textBoxBodyParts.Text;
+
+            double.TryParse(textBoxRate1.Text, out double rate1);
+            double.TryParse(textBoxRate2.Text, out double rate2);
+            double.TryParse(textBoxRate3.Text, out double rate3);
+            double.TryParse(textBoxRate4.Text, out double rate4);
+            double.TryParse(textBoxRate5.Text, out double rate5);
+            double.TryParse(textBoxRate6.Text, out double rate6);
+            double.TryParse(textBoxRate7.Text, out double rate7);
+            double.TryParse(textBoxRate8.Text, out double rate8);
+            double.TryParse(textBoxRate9.Text, out double rate9);
+            double.TryParse(textBoxRate10.Text, out double rate10);
+            int.TryParse(textBoxNum1.Text, out int num1);
+            int.TryParse(textBoxNum2.Text, out int num2);
+            int.TryParse(textBoxNum3.Text, out int num3);
+            int.TryParse(textBoxNum4.Text, out int num4);
+            int.TryParse(textBoxNum5.Text, out int num5);
+            int.TryParse(textBoxNum6.Text, out int num6);
+            int.TryParse(textBoxNum7.Text, out int num7);
+            int.TryParse(textBoxNum8.Text, out int num8);
+            int.TryParse(textBoxNum9.Text, out int num9);
+            int.TryParse(textBoxNum10.Text, out int num10);
+            double.TryParse(textBoxIntervalTime.Text, out double intervalTime);
+            int.TryParse(textBoxRepeatTimes.Text, out int repeatTimes);
+
+            if (checkError())
+            {
+                MessageBox.Show("存在无效数据,请检查后再点击修改按钮!");
+                return;
+            }
+
+            if (isEqualsTarget())
+            {
+                MessageBox.Show("新方案与旧方案重复!");
+                return;
+            }
+
+            SQLiteModel.insertTreatment(disease, bodyParts, rate1, rate2, rate3, rate4, rate5, rate6, rate7, rate8, rate9, rate10, num1, num2, num3, num4, num5, num6, num7, num8, num9, num10, intervalTime, repeatTimes);
+            loadDataGrid();
+        }
+
+        private void buttonDelete_Click(object sender, RoutedEventArgs e)
+        {
+            if (target == null)
+            {
+                MessageBox.Show("请选择要删除的治疗方案!");
+                return;
+            }
+
+            int id = target.id;
+            SQLiteModel.deleteTreatment(id);
+            loadDataGrid();
+        }
+
+        private void buttonSelect_Click(object sender, RoutedEventArgs e)
+        {
+            if (target == null)
+            {
+                MessageBox.Show("请选择治疗方案!");
+                return;
+            }
+            father.setTreatment(target);
+            Close();
+        }
+    }
+}

+ 1 - 1
WpfTest1/Toolkits/Constants.cs

@@ -20,7 +20,7 @@ namespace WpfTest1.Toolkits
         //加密狗验证所使用的uid
         //加密狗验证所使用的uid
         public static string registerUid = "587E770BB077E785";
         public static string registerUid = "587E770BB077E785";
         //是否是生产环境
         //是否是生产环境
-        public static bool productionEnvironment = true;
+        public static bool productionEnvironment = false;
         //数据库物理地址
         //数据库物理地址
         public static string dbPath = System.Environment.CurrentDirectory + "\\Junde.db3";
         public static string dbPath = System.Environment.CurrentDirectory + "\\Junde.db3";
         //数据库连接直接实用的连接字符串
         //数据库连接直接实用的连接字符串

+ 27 - 0
WpfTest1/WpTest.csproj

@@ -24,6 +24,7 @@
     <DefineConstants>DEBUG;TRACE</DefineConstants>
     <DefineConstants>DEBUG;TRACE</DefineConstants>
     <ErrorReport>prompt</ErrorReport>
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
     <WarningLevel>4</WarningLevel>
+    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
   </PropertyGroup>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
     <PlatformTarget>AnyCPU</PlatformTarget>
     <PlatformTarget>AnyCPU</PlatformTarget>
@@ -188,15 +189,29 @@
       <Generator>MSBuild:Compile</Generator>
       <Generator>MSBuild:Compile</Generator>
       <SubType>Designer</SubType>
       <SubType>Designer</SubType>
     </ApplicationDefinition>
     </ApplicationDefinition>
+    <Compile Include="ComAgent\AutoReleaseObject.cs" />
+    <Compile Include="ComAgent\ComAgent.cs" />
+    <Compile Include="ComAgent\ComException.cs" />
+    <Compile Include="ComAgent\Extension.cs" />
     <Compile Include="Exceptions\SplitException.cs" />
     <Compile Include="Exceptions\SplitException.cs" />
     <Compile Include="SmallDialogs\AboutBox.xaml.cs">
     <Compile Include="SmallDialogs\AboutBox.xaml.cs">
       <DependentUpon>AboutBox.xaml</DependentUpon>
       <DependentUpon>AboutBox.xaml</DependentUpon>
     </Compile>
     </Compile>
+    <Compile Include="SmallDialogs\Debug\SerialPortLogWindow.xaml.cs">
+      <DependentUpon>SerialPortLogWindow.xaml</DependentUpon>
+    </Compile>
+    <Compile Include="SmallDialogs\Debug\SerialPortSetup.xaml.cs">
+      <DependentUpon>SerialPortSetup.xaml</DependentUpon>
+    </Compile>
     <Compile Include="SmallDialogs\LoginWindow.xaml.cs">
     <Compile Include="SmallDialogs\LoginWindow.xaml.cs">
       <DependentUpon>LoginWindow.xaml</DependentUpon>
       <DependentUpon>LoginWindow.xaml</DependentUpon>
     </Compile>
     </Compile>
+    <Compile Include="SmallDialogs\TreatmentPlan.xaml.cs">
+      <DependentUpon>TreatmentPlan.xaml</DependentUpon>
+    </Compile>
     <Compile Include="SQLite\Bar1.cs" />
     <Compile Include="SQLite\Bar1.cs" />
     <Compile Include="SQLite\Answer.cs" />
     <Compile Include="SQLite\Answer.cs" />
+    <Compile Include="SQLite\Treatment.cs" />
     <Compile Include="SQLite\UserSelection.cs" />
     <Compile Include="SQLite\UserSelection.cs" />
     <Compile Include="SQLite\QuestionAnswerPair.cs" />
     <Compile Include="SQLite\QuestionAnswerPair.cs" />
     <Compile Include="SQLite\Question.cs" />
     <Compile Include="SQLite\Question.cs" />
@@ -241,6 +256,14 @@
       <SubType>Designer</SubType>
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
       <Generator>MSBuild:Compile</Generator>
     </Page>
     </Page>
+    <Page Include="SmallDialogs\Debug\SerialPortLogWindow.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
+    <Page Include="SmallDialogs\Debug\SerialPortSetup.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
     <Page Include="SmallDialogs\LoginWindow.xaml">
     <Page Include="SmallDialogs\LoginWindow.xaml">
       <SubType>Designer</SubType>
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
       <Generator>MSBuild:Compile</Generator>
@@ -289,6 +312,10 @@
       <SubType>Designer</SubType>
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
       <Generator>MSBuild:Compile</Generator>
     </Page>
     </Page>
+    <Page Include="SmallDialogs\TreatmentPlan.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
   </ItemGroup>
   </ItemGroup>
   <ItemGroup>
   <ItemGroup>
     <Compile Include="Properties\AssemblyInfo.cs">
     <Compile Include="Properties\AssemblyInfo.cs">

+ 1 - 1
WpfTest1/selectUser.xaml.cs

@@ -251,7 +251,7 @@ namespace WpfTest1
             {
             {
                 if (this.Name == "selectUserfilter")
                 if (this.Name == "selectUserfilter")
                 {
                 {
-                    father.buttonFilterSelectPatient_Click(this.father, e);
+                    father.buttonFilterSelectTreatment_Click(this.father, e);
                 }
                 }
                 if (this.Name == "selectUserPatientManagent")
                 if (this.Name == "selectUserPatientManagent")
                 {
                 {