예제 #1
0
        //添加足底病历
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            PatientInfo.PatientName = TextBox1.Text;
            PatientInfo.PatientId   = TextBox2.Text;
            PatientInfo.PatientBed  = TextBox3.Text;
            PatientInfo.PatientSex  = TextBox4.Text;
            PatientInfo.PatientAge  = TextBox5.Text;
            if (PatientInfo.PatientId.Length != 8)
            {
                CMessageBox.Show("病历号需为八位!", CMessageBoxButton.OK);
            }
            else if (PatientInfo.PatientBed.Length == 0)
            {
                CMessageBox.Show("床号不能为零!", CMessageBoxButton.OK);
            }
            else
            {
                PatientInfo.newornot           = true;
                PatientInfo.IsAdd              = true;
                PatientInfo.IsAddAndSavefailed = true;
                PatientInfo.PatientIdToSave    = TextBox2.Text;
                PatientInfo.NameToSave         = TextBox2.Text + "1";
                PatientInfo.IsSave             = false;
                contentControl1.Content        = new MeasureMain();
            }

            //添加病人信息
            //id,床号,性别,病历号,姓名,年龄,最大次数,住院日期,次数,备注,发布日期,修改日期
            int a = 1;

            PatientInfo.Add[0]  = TextBox3.Text; //床号
            PatientInfo.Add[1]  = TextBox4.Text; //性别
            PatientInfo.Add[2]  = TextBox2.Text; //病历号
            PatientInfo.Add[3]  = TextBox1.Text; //姓名
            PatientInfo.Add[4]  = TextBox5.Text; //年龄
            PatientInfo.Add[5]  = a.ToString();  //最大次数
            PatientInfo.Add[6]  = DateTime.Now.ToString();
            PatientInfo.Add[7]  = a.ToString();
            PatientInfo.Add[8]  = "无";
            PatientInfo.Add[9]  = DateTime.Now.ToString();
            PatientInfo.Add[10] = PatientInfo.Add[2] + PatientInfo.Add[7];
        }
예제 #2
0
        }//初始化函数

        private void Loadnewornot()//判断是否需要添加新的项
        {
            if (PatientInfo.loadornot == true)
            {
                string[] Add = new string[12];
                Add[0]  = null;
                Add[1]  = null;
                Add[2]  = PatientInfo.PatientId;   //获得病历号
                Add[3]  = PatientInfo.PatientName; //获得姓名
                Add[4]  = null;
                Add[5]  = null;
                Add[6]  = null;
                Add[7]  = null;
                Add[8]  = null;
                Add[9]  = null;
                Add[10] = null;
                fflushSearch(dpt.Search(Add, Date, SearchOpiton));
                SearchboardOpen          = true;
                DataGridView1.DataSource = Searchboard;
                for (int i = 0; i < 12; i++)
                {
                    DataGridView1.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
                }
                if (DataGridView1.RowCount == 0)
                {
                    CMessageBox.Show("未搜索到相关记录!", CMessageBoxButton.OK);
                }

                //在表格1与表格2中分别显示记录
                ObservableCollection <Member> memberData = new ObservableCollection <Member>();
                memberData.Add(new Member()
                {//Name病历号 Age姓名
                    Name = Add[2],
                    Age  = Add[3]
                });
                dataGrid.DataContext = memberData;
                LoadGrid2();
//                PatientInfo.PatientId = null;
//                PatientInfo.PatientName = null;
//                PatientInfo.loadornot = false;
            }
        }
예제 #3
0
        private void Window_Loaded(object sender, RoutedEventArgs e)//主窗口初始化
        {
            #region 可用串口下拉控件↓↓↓↓↓↓↓↓↓
            ports = SerialPort.GetPortNames(); //获取可用串口
            if (ports.Length > 0)              //ports.Length > 0说明有串口可用
            {
                for (int i = 0; i < ports.Length; i++)
                {
                    comList.Add(new customer()
                    {
                        com = ports[i]
                    });                                          //下拉控件里添加可用串口
                }
                AvailableComCbobox.ItemsSource       = comList;  //资源路径
                AvailableComCbobox.DisplayMemberPath = "com";    //显示路径
                AvailableComCbobox.SelectedValuePath = "com";    //值路径
                AvailableComCbobox.SelectedValue     = ports[0]; //默认选第1个串口
            }
            else//未检测到串口
            {
                CMessageBox.Show("未连接到设备!", CMessageBoxButton.OK);
            }
            #endregion 可用串口下拉控件↑↑↑↑↑↑↑↑↑
            #region 默认设置↓↓↓↓↓↓↓↓↓
            ComPort.ReadTimeout     = 8000; //串口读超时8秒
            ComPort.WriteTimeout    = 8000; //串口写超时8秒,在1ms自动发送数据时拔掉串口,写超时5秒后,会自动停止发送,如果无超时设定,这时程序假死
            ComPort.ReadBufferSize  = 1024; //数据读缓存
            ComPort.WriteBufferSize = 1024; //数据写缓存
            #endregion

            #region 画图属性
            graph[0] = plotter.AddLineGraph(dataSource[0], colorSelect[0], 2, Convert.ToString(0));

            plotter.LegendVisible = false;
            plotter.Viewport.FitToView();
            #endregion
            ComPort.DataReceived += new SerialDataReceivedEventHandler(ComReceive);//串口接收中断
        }
예제 #4
0
 private void Button_Click_3(object sender, RoutedEventArgs e)//联系我们
 {
     CMessageBox.Show("医疗压力测量系统v1.0,请联系18810913505", CMessageBoxButton.OK);
 }
예제 #5
0
 private void SetComLose()//成功关闭串口或串口丢失后的设置
 {
     CMessageBox.Show("设备丢失");
     GetPort();       //刷新可用串口
     SetAfterClose(); //成功关闭串口或串口丢失后的设置
 }
예제 #6
0
        private void ComReceive(object sender, SerialDataReceivedEventArgs e) //接收数据 中断只标志有数据需要读取,读取操作在中断外进行
        {
            Thread.Sleep(20);                                                 //发送和接收均为文本时,接收中为加入判断是否为文字的算法,发送你(C4E3),接收可能识别为C4,E3,可用在这里加延时解决
            if (ComPortIsOpen)                                                //如果已经开启接收
            {
                byte[] recBufferd;                                            //接收缓冲区
                try
                {
                    if (ComPort.BytesToRead >= 12)                      //缓存数据包中的内容
                    {
                        recBufferd = new byte[ComPort.BytesToRead];     //接收数据缓存大小
                        ComPort.Read(recBufferd, 0, recBufferd.Length); //读取数据
                        int start = 0;
                        for (; start < recBufferd.Length; start++)
                        {
                            if ((int)recBufferd[start] == 83)  //判断是否为S
                            {
                                break;
                            }
                        }
                        byte[] recBuffer = new byte[12];
                        for (int i = 0; i < 12; i++)
                        {
                            recBuffer[i] = recBufferd[start++];
                        }
                        #region 判断是否合格的数据,并进行显示
                        try
                        {
                            string recData;                                                      //接收数据转码后缓存
                            recData = System.Text.Encoding.Default.GetString(recBuffer);         //转码
                            #region 数据包判断并显示
                            if (recData[0] == 'S' && recData.Length == 12 && recData[11] == 'E') //根据协议处理,数据包头为00
                            {
                                shujvbao = "";
                                shujvbao = recData.Substring(3, 8);


                                // Console.WriteLine(shujvbao);
                                #region 文字\数据显示

                                UIAction(() =>
                                {
                                    checkBox1.Content = "当前压力值:" + biaoding(shujvbao.Substring(bigORsmall * 4, 4), bigORsmall
                                                                            ) + "mmHg";

                                    recCount.Text = (Convert.ToInt32(recCount.Text) + recBufferd.Length).ToString();//接收数据字节数
                                });
                                #endregion
                                #region 显示部分
                                Task tasknew = Task.Run
                                               //UIAction
                                                   (() => timerTick(shujvbao));
                                tasknew.Wait();

                                #region 控件更改
                                UIAction(() =>
                                {
                                    int temp           = string2int(shujvbao.Substring(bigORsmall * 4, 4), bigORsmall);
                                    ellipse[0].Fill    = new SolidColorBrush(Color.FromRgb(setiao[temp * 3], setiao[temp * 3 + 1], setiao[temp * 3 + 2]));
                                    ellipse[0].ToolTip = biaoding(shujvbao.Substring(bigORsmall * 4, 4), bigORsmall);
                                });


                                #region ReadyOrStart==2 显示测量
                                if (ReadyOrStart == 2) //如果为测量模式
                                {
                                    UIAction(() =>
                                    {
                                        timeSlider.Maximum = timelimit;                         //进度条
                                        timeSlider.Value   = currentSecond;                     //进度条
                                        sum += biaoding(shujvbao.Substring(bigORsmall * 4, 4), bigORsmall);
                                        if ((currentSecond > timelimit) && (ReadyOrStart == 2)) //ComPortIsOpen == true,当前串口为打开状态,按钮事件为关闭串口
                                        {
                                            try                                                 //尝试关闭串口
                                            {
                                                ComPort.DiscardInBuffer();                      //清接收缓存
                                                SetAfterClose();                                //成功关闭串口或串口丢失后的设置
                                                ComPort.Close();                                //关闭串口
                                                ReadyOrStart = 0;                               //设置指示
                                                CMessageBoxResult confirmToDel = CMessageBox.Show("测量完成", CMessageBoxButton.OK);


                                                //测量完成加入数据
                                                string NumTemp = epoint2.Margin.ToString();
                                                int NumLen     = 0;
                                                for (int commNum = 0; commNum < 2; NumLen++)
                                                {
                                                    if (NumTemp[NumLen] == ',')
                                                    {
                                                        commNum += 1;
                                                    }
                                                }
                                                Num = NumTemp.Substring(0, NumLen - 1);
                                                sum = sum / (timelimit + 1);   //平均值

                                                int _b = (int)(sum * 100);

                                                Value = (double)_b / 100;

                                                sum = 0;

                                                #region 标记ellipse
                                                //标记新的ellipse
                                                Ellipse justMeasure = new Ellipse();
                                                HaveMeasure.Add(justMeasure);
                                                justMeasure.VerticalAlignment   = VerticalAlignment.Top;
                                                justMeasure.HorizontalAlignment = HorizontalAlignment.Left;
                                                justMeasure.Width  = 10;
                                                justMeasure.Height = 10;
                                                justMeasure.Margin = epoint2.Margin;
                                                LayoutRoot.Children.Add(justMeasure);
                                                justMeasure.Fill    = new SolidColorBrush(Colors.Pink);
                                                justMeasure.ToolTip = Value.ToString();
                                                #endregion

                                                #region 在grid中添加数据
                                                //添加新的数据项

                                                memberData3.Add(new Member3()
                                                {       //Name病历号 Age姓名
                                                    Number  = Num.ToString(),
                                                    Value   = Value.ToString(),
                                                    EMargin = epoint2.Margin.ToString(),
                                                });
                                                dataGrid1.DataContext = memberData3;
                                                #endregion

                                                BigRange.IsEnabled     = true;
                                                SmallRange.IsEnabled   = true;
                                                PatientInfo.finishtime = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                                                openBtn.Content        = "再次测量";
                                            }
                                            catch                            //如果在未关闭串口前,串口就已丢失,这时关闭串口会出现异常
                                            {
                                                if (ComPort.IsOpen == false) //判断当前串口状态,如果ComPort.IsOpen==false,说明串口已丢失
                                                {
                                                    SetComLose();
                                                }
                                                else//未知原因,无法关闭串口
                                                {
                                                    CMessageBox.Show("无法关闭设备,原因未知!");
                                                    return;//无法关闭串口,提示后直接返回
                                                }
                                            }
                                        }
                                    });
                                }
                                #endregion
                                if (ReadyOrStart == 2)                   //测量模式保存数据
                                {
                                    PatientInfo.PatientData += shujvbao; //记录当前保存的数据
                                }
                                //Thread.Sleep(10);
                                #endregion
                                #endregion
                            }
                            else
                            {
                                if (recData[0] != 0)
                                {
                                    Console.WriteLine("Drop data because of incorrect header");
                                }
                                else
                                {
                                    Console.WriteLine("Drop data because of incrrocet length");
                                }
                            }
                            #endregion
                        }
                        catch (Exception ed)
                        {
                            Console.WriteLine("error" + ed.Message);
                        }
                        #endregion
                    }
                }
                catch (Exception ed)
                {
                    CMessageBox.Show(ed.Message);
                    UIAction(() =>
                    {
                        if (ComPort.IsOpen == false) //如果ComPort.IsOpen == false,说明串口已丢失
                        {
                            SetComLose();            //串口丢失后相关设置
                        }
                        else
                        {
                            CMessageBox.Show("无法接收数据,原因未知!");
                        }
                    });
                }
            }
        }
예제 #7
0
        private void ready_Button_Click(object sender, RoutedEventArgs e) //准备按钮
        {
            if (AvailableComCbobox.SelectedValue == null)                 //先判断是否有可用串口
            {
                CMessageBox.Show("未连接设备,无法测量");
                return;//没有串口,提示后直接返回
            }
            #region 打开串口
            if (ComPortIsOpen == false)                                             //ComPortIsOpen == false当前串口为关闭状态,按钮事件为打开串口
            {
                try                                                                 //尝试打开串口
                {
                    ComPort.PortName = AvailableComCbobox.SelectedValue.ToString(); //设置要打开的串口
                    ComPort.BaudRate = 115200;                                      //设置当前波特率
                    ComPort.Parity   = 0;                                           //设置当前校验位
                    ComPort.DataBits = 8;                                           //设置当前数据位
                    ComPort.StopBits = (StopBits)1;                                 //设置当前停止位
                    ComPort.Open();                                                 //打开串口
                    ReadyOrStart           = 1;
                    PatientInfo.readyornot = false;
                    Reset();
                }

                catch//如果串口被其他占用,则无法打开
                {
                    CMessageBox.Show("设备被占用,请检测设备是否有效");
                    GetPort(); //刷新当前可用串口
                    return;    //无法打开串口,提示后直接返回
                }
                #endregion
                #region                                //↓↓↓↓↓↓↓↓↓成功打开串口后的设置↓↓↓↓↓↓↓↓↓

                ready_Button.Content         = "取消准备"; //按钮显示改为“取消准备”
                ComPortIsOpen                = true;   //串口打开状态字改为true
                AvailableComCbobox.IsEnabled = false;  //失能可用串口控件
                BigRange.IsEnabled           = false;
                SmallRange.IsEnabled         = false;
                #endregion
            }
            #region 关闭串口
            else//ComPortIsOpen == true,当前串口为打开状态,按钮事件为关闭串口
            {
                try//尝试关闭串口
                {
                    SetAfterClose();           //成功关闭串口或串口丢失后的设置
                    ready_Button.Content = "准备";
                    ComPort.DiscardInBuffer(); //清接收缓存
                    Reset();

                    ComPort.Close();//关闭串口
                    PatientInfo.readyornot = true;
                    ReadyOrStart           = 0;
                }
                catch                            //如果在未关闭串口前,串口就已丢失,这时关闭串口会出现异常
                {
                    if (ComPort.IsOpen == false) //判断当前串口状态,如果ComPort.IsOpen==false,说明串口已丢失
                    {
                        SetComLose();
                    }
                    else//未知原因,无法关闭串口
                    {
                        CMessageBox.Show("无法关闭设备,原因未知!");
                        return;//无法关闭串口,提示后直接返回
                    }
                }
                BigRange.IsEnabled   = true;
                SmallRange.IsEnabled = true;
            }
            #endregion
        }
예제 #8
0
        private void Button_Open(object sender, RoutedEventArgs e) //打开/关闭串口事件
        {
            if (AvailableComCbobox.SelectedValue == null)          //先判断是否有可用串口
            {
                CMessageBox.Show("设备未连接!", CMessageBoxButton.OK);
                return;//没有串口,提示后直接返回
            }
            #region 打开串口
            if (ReadyOrStart == 1)
            {
                Console.Write("1");
                SetAfterClose();           //成功关闭串口或串口丢失后的设置
                ComPort.DiscardInBuffer(); //清接收缓存
                ready_Button.Content = "准备";
                Reset();

                ComPort.Close();        //关闭串口
            }
            if (ComPortIsOpen == false) //ComPortIsOpen == false当前串口为关闭状态,按钮事件为打开串口
            {
                timelimit             = Convert.ToInt16(timeSelect.Text) - 1;
                PatientInfo.timelimit = timelimit;
                try                                                                 //尝试打开串口
                {
                    ComPort.PortName = AvailableComCbobox.SelectedValue.ToString(); //设置要打开的串口
                    ComPort.BaudRate = 115200;                                      //设置当前波特率
                    ComPort.Parity   = 0;                                           //设置当前校验位
                    ComPort.DataBits = 8;                                           //设置当前数据位
                    ComPort.StopBits = (StopBits)1;                                 //设置当前停止位
                    ComPort.Open();                                                 //打开串口
                    PatientInfo.readyornot = false;
                    ReadyOrStart           = 2;                                     //设置指示
                    Reset();                                                        //重置
                }
                catch                                                               //如果串口被其他占用,则无法打开
                {
                    CMessageBox.Show("无法打开串口,请检测此串口是否有效或被其他占用!");
                    GetPort(); //刷新当前可用串口
                    return;    //无法打开串口,提示后直接返回
                }
                #endregion
                #region                               //↓↓↓↓↓↓↓↓↓成功打开串口后的设置↓↓↓↓↓↓↓↓↓
                openBtn.Content = "停止测量";             //按钮显示改为“关闭按钮”
                ComPortIsOpen   = true;               //串口打开状态字改为true
                AvailableComCbobox.IsEnabled = false; //失能可用串口控件

                BigRange.IsEnabled   = false;
                SmallRange.IsEnabled = false;
                #endregion
            }
            #region 关闭串口
            else
            {
                try                             //尝试关闭串口
                {
                    ComPort.DiscardOutBuffer(); //清发送缓存
                    ComPort.DiscardInBuffer();  //清接收缓存
                    ComPort.Close();            //关闭串口
                    PatientInfo.readyornot = true;
                    ReadyOrStart           = 0; //设置指示
                    openBtn.Content        = "开始测量";
                    SetAfterClose();            //成功关闭串口或串口丢失后的设置
                    Reset();
                }
                catch                            //如果在未关闭串口前,串口就已丢失,这时关闭串口会出现异常
                {
                    if (ComPort.IsOpen == false) //判断当前串口状态,如果ComPort.IsOpen==false,说明串口已丢失
                    {
                        SetComLose();
                    }
                    else//未知原因,无法关闭串口
                    {
                        CMessageBox.Show("无法关闭设备,原因未知!");
                        return;//无法关闭串口,提示后直接返回
                    }
                }
                BigRange.IsEnabled   = true;
                SmallRange.IsEnabled = true;
            }
            #endregion
        }
예제 #9
0
        private void UserControl_Loaded_2(object sender, RoutedEventArgs e)
        {
            if (PatientInfo.IsSave == true)
            {
                HMSDATA.Clear();
                if (IsForfoot == true)
                {
                    HMSDATA.SetPlace("TestData.accdb");
                    FileName = "TestData.accdb";
                }
                else
                {
                    HMSDATA.SetPlace("TestData2.accdb");
                    FileName = "TestData2.accdb";
                }
                Saved = true;
                LoadFile();
                homeCtrlHToolStripMenuItem_Click();
                if (HMSDATA.IfCon == false)
                {
                    CMessageBox.Show("连接失败!", CMessageBoxButton.OK);
                }
                HMSDATA.NewRow(PatientInfo.Add);
                HMSDATA.CloseCon();//操作完成后关闭连接
                //重新载入表格2
                HMSDATA.Clear();
                if (IsForfoot == true)
                {
                    HMSDATA.SetPlace("TestData.accdb");
                    FileName = "TestData.accdb";
                }
                else
                {
                    HMSDATA.SetPlace("TestData2.accdb");
                    FileName = "TestData2.accdb";
                }
                Saved = true;
                LoadFile();
                if (HMSDATA.IfCon == false)
                {
                    CMessageBox.Show("连接失败!", CMessageBoxButton.OK);
                }
                DataGridView1.DataSource = HMSDATA.GetData().Tables[0];
                for (int i = 0; i < 12; i++)
                {
                    DataGridView1.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable; DataGridView1.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
                }

                DataGridRow row = (DataGridRow)dataGrid.ItemContainerGenerator.ContainerFromIndex(PatientInfo.SelectRowNum);
                if (row != null)
                {
                    dataGrid.UpdateLayout();
                    dataGrid.ScrollIntoView(dataGrid.Items[PatientInfo.SelectRowNum]);
                    row            = (DataGridRow)dataGrid.ItemContainerGenerator.ContainerFromIndex(PatientInfo.SelectRowNum);
                    row.IsSelected = true;
                }
                PatientInfo.IsSave          = false;
                PatientInfo.PatientIdToSave = null;
                PatientInfo.NameToSave      = null;
                PatientInfo.SelectRowNum    = 0;
            }
            Loadnewornot();
            LoadGrid1();
            HMSDATA.CloseCon();
            try
            {
                this.dataGrid.SelectedIndex = 0;
            }
            catch
            {
                //Do nothing
            }
        }
예제 #10
0
        private void Button_Click_2(object sender, RoutedEventArgs e)//删除记录按钮按下
        {
            string  NameToDelete     = null;
            string  NameToDelete1    = null;
            bool    DetelteAll       = false;
            int     max_delete       = 0;
            bool    delete           = false;
            Member  SelectedElement  = (Member)dataGrid.SelectedItem;
            Member2 SelectedElement1 = (Member2)dataGrid1.SelectedItem;

            if (SelectedElement == null)
            {
                CMessageBox.Show("请首先选择一个病人信息!", CMessageBoxButton.OK);
            }
            else
            {
                if (SelectedElement1 == null)
                {
                    CMessageBoxResult confirmToDel = CMessageBox.Show("确定要删除该病人的所有记录吗?", CMessageBoxButton.OKCancel);
                    if (confirmToDel == CMessageBoxResult.OK)
                    {
                        CMessageBoxResult confirmToDel2 = CMessageBox.Show("您确定吗?", CMessageBoxButton.OKCancel);
                        if (confirmToDel2 == CMessageBoxResult.OK)
                        {
                            if (SelectedElement != null)
                            {
                                string result1 = SelectedElement.Name.ToString();//获得当前病历号
                                NameToDelete  = result1;
                                NameToDelete1 = result1;
                                HMSDATA.Connect();
                                HMSDATA.SheetCon();
                                HMSDATA.DeleteRows(result1);
                                HMSDATA.CloseCon();
                                DetelteAll = true;
                                max_delete = dataGrid1.Items.Count;
                                delete     = true;
                            }
                        }
                    }
                }
                else
                {
                    CMessageBoxResult confirmToDel = CMessageBox.Show("确定要删除该条记录吗?", CMessageBoxButton.OKCancel);
                    if (confirmToDel == CMessageBoxResult.OK)
                    {
                        SelectRowNum_Change = dataGrid.SelectedIndex;
                        if (SelectedElement != null && SelectedElement1 != null)
                        {
                            string result1 = SelectedElement.Name.ToString();//获得当前病历号
                            //string result = SelectedElement1.Num.ToString();//获得该病历号的次数
                            int    a      = Convert.ToInt32(SelectedElement1.Num) - 1;
                            string result = Numtoshow.ElementAt(a);//获得该病历号的次数
                            NameToDelete  = result1 + result + ".fot";
                            NameToDelete1 = result1;
                            DetelteAll    = false;
                            HMSDATA.Connect();
                            HMSDATA.SheetCon();
                            HMSDATA.DeleteRow(result1 + result);
                            HMSDATA.CloseCon();
                            delete = true;
                        }
                    }
                }
                if (delete)
                {
                    //重新载入表格2
                    HMSDATA.Clear();
                    if (IsForfoot)
                    {
                        HMSDATA.SetPlace("TestData.accdb");
                        FileName = "TestData.accdb";
                    }
                    else
                    {
                        HMSDATA.SetPlace("TestData2.accdb");
                        FileName = "TestData2.accdb";
                    }
                    Saved = true;
                    LoadFile();
                    if (HMSDATA.IfCon == false)
                    {
                        CMessageBox.Show("连接失败!", CMessageBoxButton.OK);
                    }
                    DataGridView1.DataSource = HMSDATA.GetData().Tables[0];
                    for (int i = 0; i < 12; i++)
                    {
                        DataGridView1.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable; DataGridView1.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
                    }
                    if (dataGrid_SelectedElement != null)
                    {
                        string result = dataGrid_SelectedElement.Name.ToString();
                        choosed = Convert.ToInt32(result);

                        Searchboard.Clear();
                        final[0]  = null;                                     //床号
                        final[1]  = null;                                     //性别
                        final[2]  = dataGrid_SelectedElement.Name.ToString(); //病历号
                        final[3]  = dataGrid_SelectedElement.Age.ToString();  //姓名
                        final[4]  = null;                                     //年龄
                        final[5]  = null;                                     //最大次数
                        final[6]  = null;                                     //住院日期
                        final[7]  = null;                                     //次数
                        final[8]  = null;                                     //备注
                        final[9]  = null;                                     //发布日期
                        final[10] = null;                                     //修改日期
                        LoadGrid1();
                        fflushSearch(dpt.Search(final, Date, SearchOpiton));
                        SearchboardOpen          = true;
                        DataGridView1.DataSource = Searchboard;
                        for (int i = 0; i < 12; i++)
                        {
                            DataGridView1.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
                        }
                        LoadGrid2();

                        try
                        {
                            DataGridRow row = (DataGridRow)dataGrid.ItemContainerGenerator.ContainerFromIndex(SelectRowNum_Change);
                            if (row == null)
                            {
                                dataGrid.UpdateLayout();
                                dataGrid.ScrollIntoView(dataGrid.Items[SelectRowNum_Change]);
                                row            = (DataGridRow)dataGrid.ItemContainerGenerator.ContainerFromIndex(SelectRowNum_Change);
                                row.IsSelected = true;
                            }
                        }
                        catch
                        {
                        }
                        if (DetelteAll == false)
                        {
                            if (IsForfoot)
                            {
                                if (System.IO.File.Exists("footshow/" + NameToDelete))
                                {
                                    System.IO.File.Delete("footshow/" + NameToDelete);
                                }
                            }
                            else
                            {
                                if (System.IO.File.Exists("singleshow/" + NameToDelete))
                                {
                                    System.IO.File.Delete("singleshow/" + NameToDelete);
                                }
                            }
                        }
                        else
                        {
                            if (IsForfoot)
                            {
                                for (int i = 1; i < max_delete + 1; i++)
                                {
                                    if (System.IO.File.Exists("footshow/" + NameToDelete1 + i.ToString() + ".fot"))
                                    {
                                        System.IO.File.Delete("footshow/" + NameToDelete1 + i.ToString() + ".fot");
                                    }
                                }
                            }
                            else
                            {
                                for (int i = 1; i < max_delete + 1; i++)
                                {
                                    if (System.IO.File.Exists("singleshow/" + NameToDelete1 + i.ToString() + ".fot"))
                                    {
                                        System.IO.File.Delete("singleshow/" + NameToDelete1 + i.ToString() + ".fot");
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
예제 #11
0
        }//创建一个新的数据库

        private void Button_Click_1(object sender, RoutedEventArgs e)//直接测量按钮按下
        {
            Member SelectedElement = (Member)dataGrid.SelectedItem;

            if (SelectedElement == null)
            {
                CMessageBox.Show("请首先选择一个病人信息!", CMessageBoxButton.OK);
            }
            else
            {
                PatientInfo.SelectRowNum = dataGrid.SelectedIndex;
                HMSDATA.Connect();
                HMSDATA.SheetCon();
                //在数据库中添加记录
                //string[] Add = new string[11];
                PatientInfo.Add[0]  = DataGridView1.Rows[DataGridView1.Rows[DataGridView1.Rows.Count - 1].Index].Cells[1].Value.ToString();
                PatientInfo.Add[1]  = DataGridView1.Rows[DataGridView1.Rows[DataGridView1.Rows.Count - 1].Index].Cells[2].Value.ToString();
                PatientInfo.Add[2]  = SelectedElement.Name.ToString();
                PatientInfo.Add[3]  = SelectedElement.Age.ToString();
                PatientInfo.Add[4]  = DataGridView1.Rows[DataGridView1.Rows[DataGridView1.Rows.Count - 1].Index].Cells[5].Value.ToString();
                PatientInfo.Add[5]  = DataGridView1.Rows[DataGridView1.Rows[DataGridView1.Rows.Count - 1].Index].Cells[6].Value.ToString();
                PatientInfo.Add[6]  = DataGridView1.Rows[DataGridView1.Rows[DataGridView1.Rows.Count - 1].Index].Cells[7].Value.ToString();
                PatientInfo.Add[7]  = (Convert.ToInt32(DataGridView1.Rows[DataGridView1.Rows[DataGridView1.Rows.Count - 1].Index].Cells[8].Value.ToString()) + 1).ToString();
                PatientInfo.Add[8]  = DataGridView1.Rows[DataGridView1.Rows[DataGridView1.Rows.Count - 1].Index].Cells[9].Value.ToString();
                PatientInfo.Add[9]  = DateTime.Now.ToString();
                PatientInfo.Add[10] = PatientInfo.Add[2] + PatientInfo.Add[7];


                CMessageBoxResult confirmToDel = CMessageBox.Show("确定要添加测量吗?", CMessageBoxButton.OKCancel);
                if (confirmToDel == CMessageBoxResult.OK)
                {
                    //Do Nothing
                    if (dataGrid_SelectedElement != null)
                    {
                        string result = dataGrid_SelectedElement.Name.ToString();
                        choosed = Convert.ToInt32(result);

                        Searchboard.Clear();
                        final[0]  = null;                                     //床号
                        final[1]  = null;                                     //性别
                        final[2]  = dataGrid_SelectedElement.Name.ToString(); //病历号
                        final[3]  = dataGrid_SelectedElement.Age.ToString();  //姓名
                        final[4]  = null;                                     //年龄
                        final[5]  = null;                                     //最大次数
                        final[6]  = null;                                     //住院日期
                        final[7]  = null;                                     //次数
                        final[8]  = null;                                     //备注
                        final[9]  = null;                                     //发布日期
                        final[10] = null;                                     //修改日期
                        fflushSearch(dpt.Search(final, Date, SearchOpiton));
                        SearchboardOpen          = true;
                        DataGridView1.DataSource = Searchboard;
                        for (int i = 0; i < 12; i++)
                        {
                            DataGridView1.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
                        }
                        if (DataGridView1.RowCount == 0)
                        {
                            CMessageBox.Show("未搜索到相关记录!", CMessageBoxButton.OK);
                        }
                        LoadGrid2();

                        PatientInfo.IsAdd           = true;
                        PatientInfo.PatientIdToSave = PatientInfo.Add[2];
                        PatientInfo.NameToSave      = PatientInfo.Add[10];
                        PatientInfo.PatientId       = PatientInfo.Add[2];
                        PatientInfo.PatientBed      = PatientInfo.Add[0];
                        PatientInfo.PatientSex      = PatientInfo.Add[1];
                        if (IsForfoot)
                        {
                            this.Content = mm;
                        }
                        else
                        {
                            this.Content = ss;
                        }
                    }
                }
                else
                {
                    //Do Nothing
                }
            }
        }
예제 #12
0
        private void saveBtn_Click(object sender, RoutedEventArgs e)//保存数据
        {
            try
            {
                Console.WriteLine(PatientInfo.PatientData);
                if (PatientInfo.IsAdd == true)
                {
                    if (System.IO.File.Exists("footshow/" + PatientInfo.NameToSave + ".fot"))
                    {
                        System.IO.File.Delete("footshow/" + PatientInfo.NameToSave + ".fot");
                    }
                    FileStream   fs = new FileStream("footshow/" + PatientInfo.NameToSave + ".fot", FileMode.OpenOrCreate, FileAccess.ReadWrite);
                    StreamWriter sw = new StreamWriter(fs); // 创建写入流
                    sw.WriteLine(PatientInfo.PatientData);  // 写入Hello World

                    sw.WriteLine("测量时间:" + PatientInfo.finishtime);
                    sw.WriteLine("病人ID:" + PatientInfo.PatientId);
                    sw.WriteLine("病人床号:" + PatientInfo.PatientBed);
                    sw.WriteLine("病人性别:" + PatientInfo.PatientSex);

                    double[] average = new double[8];
                    for (int i = 0; i < 8; i++)
                    {
                        int timelimit = PatientInfo.PatientData.Length / 32;
                        for (int j = 0; j < timelimit; j++)
                        {
                            average[i] += biaoding(PatientInfo.PatientData.Substring(32 * j + i * 4, 4), i);
                            if (j == timelimit - 1)
                            {
                                average[i] = Math.Round(average[i] / timelimit, 2);
                                #region oh f**k
                                if (i == 0)
                                {
                                    sw.WriteLine();
                                    sw.WriteLine("左脚第一跖骨" + "点压力的平均值:" + average[i] + "mmHg");
                                }
                                if (i == 1)
                                {
                                    sw.WriteLine("左脚第三跖骨" + "点压力的平均值:" + average[i] + "mmHg");
                                }
                                if (i == 2)
                                {
                                    sw.WriteLine("左脚第五跖骨" + "点压力的平均值:" + average[i] + "mmHg");
                                }
                                if (i == 3)
                                {
                                    sw.WriteLine("左脚根骨" + "点压力的平均值:" + average[i] + "mmHg");
                                    sw.WriteLine();
                                }

                                if (i == 4)
                                {
                                    sw.WriteLine("右脚第一跖骨" + "点压力的平均值:" + average[i] + "mmHg");
                                }
                                if (i == 5)
                                {
                                    sw.WriteLine("右脚第三跖骨" + "点压力的平均值:" + average[i] + "mmHg");
                                }
                                if (i == 6)
                                {
                                    sw.WriteLine("右脚第五跖骨" + "点压力的平均值:" + average[i] + "mmHg");
                                }
                                if (i == 7)
                                {
                                    sw.WriteLine("右脚跟骨" + "点压力的平均值:" + average[i] + "mmHg");
                                }

                                #endregion
                            }
                        }
                    }

                    sw.Close(); //关闭文件
                    PatientInfo.IsSave             = true;
                    PatientInfo.IsAddAndSavefailed = false;
                    PatientInfo.IsAdd       = false;
                    PatientInfo.PatientData = null;
                    PatientInfo.readyornot  = true;
                    this.Content            = new AccessMain(true);
                }
                else
                {
                    CMessageBoxResult confirmToDel = CMessageBox.Show("请选择病人进行添加测量!", CMessageBoxButton.OKCancel);
                }
            }
            catch
            {
                CMessageBox.Show("无信息保存!", CMessageBoxButton.OK);
            }
        }
예제 #13
0
        private void ComReceive(object sender, SerialDataReceivedEventArgs e) //接收数据 中断只标志有数据需要读取,读取操作在中断外进行
        {
            Thread.Sleep(20);                                                 //发送和接收均为文本时,接收中为加入判断是否为文字的算法,发送你(C4E3),接收可能识别为C4,E3,可用在这里加延时解决
            if (ComPortIsOpen)                                                //如果已经开启接收
            {
                byte[] recBufferd;                                            //接收缓冲区
                try
                {
                    if (ComPort.BytesToRead >= 20)                      //缓存数据包中的内容
                    {
                        recBufferd = new byte[ComPort.BytesToRead];     //接收数据缓存大小
                        ComPort.Read(recBufferd, 0, recBufferd.Length); //读取数据
                        int start = 0;
                        for (; start < recBufferd.Length; start++)
                        {
                            if ((int)recBufferd[start] == 83)  //判断是否为S
                            {
                                break;
                            }
                        }
                        byte[] recBuffer = new byte[20];
                        for (int i = 0; i < 20; i++)
                        {
                            recBuffer[i] = recBufferd[start++];
                        }
                        #region 判断是否合格的数据,并进行显示
                        try
                        {
                            string recData;                                                      //接收数据转码后缓存
                            int    LorR = 0;                                                     //判断左右脚
                            recData = System.Text.Encoding.Default.GetString(recBuffer);         //转码
                            #region 数据包判断并显示
                            if (recData[0] == 'S' && recData.Length == 20 && recData[19] == 'E') //根据协议处理,数据包头为00
                            {
                                shujvbao = "";
                                if (recData[1] == '0' && recData[2] == '0' && leftRight == 0)
                                {
                                    LorR      = 1;//左脚
                                    finalLR   = 1;
                                    leftRight = 1;
                                    shujvbao  = recData.Substring(3, 16);
                                }
                                else if (recData[1] == '3' && recData[2] == '4' && leftRight == 1)
                                {
                                    LorR      = -1;//右脚
                                    finalLR   = -1;
                                    leftRight = 2;
                                    shujvbao  = recData.Substring(3, 16);
                                }
                                else if (recData[1] == '0' && recData[2] == '0' && leftRight == 2)
                                {
                                    LorR      = 1;
                                    finalLR   = 1;
                                    leftRight = 1;
                                    shujvbao  = recData.Substring(3, 16);
                                }
                                else
                                {
                                    LorR = 0;
                                }


                                // Console.WriteLine(shujvbao);
                                #region 显示部分

                                #region 文字\数据显示
                                Task tasknew = Task.Run
                                               //UIAction
                                                   (() => timerTick(shujvbao, LorR, leftRight));
                                tasknew.Wait();
                                UIAction(() =>
                                {
                                    if (LorR == 1 && finalLR == 1)
                                    {
                                        checkBox1.Content = "第一跖骨" + "(" + biaoding(shujvbao.Substring(0 * 4, 4), 0) + ")";
                                        checkBox2.Content = "第三跖骨" + "(" + biaoding(shujvbao.Substring(1 * 4, 4), 1) + ")";
                                        checkBox3.Content = "第五跖骨" + "(" + biaoding(shujvbao.Substring(2 * 4, 4), 2) + ")";
                                        checkBox4.Content = "跟骨" + "(" + biaoding(shujvbao.Substring(3 * 4, 4), 3) + ")";
                                    }
                                    if (LorR == -1 && finalLR == -1)
                                    {
                                        checkBox11.Content = "第一趾骨" + "(" + biaoding(shujvbao.Substring(0 * 4, 4), 4) + ")";
                                        checkBox22.Content = "第三跖骨" + "(" + biaoding(shujvbao.Substring(1 * 4, 4), 5) + ")";
                                        checkBox33.Content = "第五跖骨" + "(" + biaoding(shujvbao.Substring(2 * 4, 4), 6) + ")";
                                        checkBox44.Content = "跟骨" + "(" + biaoding(shujvbao.Substring(3 * 4, 4), 7) + ")";
                                    }
                                    recCount.Text = (Convert.ToInt32(recCount.Text) + recBufferd.Length).ToString();            //接收数据字节数
                                });
                                #endregion


                                #region 控件更改
                                UIAction(() =>
                                {
                                    int LRbase = 0;
                                    int flag   = 0;
                                    if (LorR == 1 && finalLR == 1)
                                    {
                                        LRbase = 0;
                                        flag   = 1;
                                    }
                                    if (LorR == -1 && finalLR == -1)
                                    {
                                        LRbase = 4;
                                        flag   = 1;
                                    }
                                    if (flag == 1)
                                    {
                                        for (int ii = 0; ii < 4; ii++)
                                        {
                                            int temp = string2int(shujvbao.Substring(ii * 4, 4), ii);
                                            ellipse[LRbase + ii].Fill    = new SolidColorBrush(Color.FromRgb(setiao[temp * 3], setiao[temp * 3 + 1], setiao[temp * 3 + 2]));
                                            ellipse[LRbase + ii].ToolTip = biaoding(shujvbao.Substring(ii * 4, 4), ii);
                                        }
                                        #region checkBox
                                        for (int jj = 0; jj < 8; jj++)
                                        {
                                            if (checkbox[jj].IsChecked == true)
                                            {
                                                graph[jj].Visibility = Visibility.Visible;
                                                ellipse[jj].Stroke   = new SolidColorBrush(Colors.Red);
                                            }
                                            else
                                            {
                                                graph[jj].Visibility = Visibility.Hidden;
                                                ellipse[jj].Stroke   = new SolidColorBrush(Colors.White);
                                            }
                                        }
                                    }
                                    else
                                    {
                                    }
                                    #endregion
                                });

                                #region ReadyOrStart==2 显示测量
                                if (ReadyOrStart == 2)  //如果为测量模式
                                {
                                    UIAction(() =>
                                    {
                                        timeSlider.Maximum = timelimit;                         //进度条
                                        timeSlider.Value   = currentSecond;                     //进度条
                                        if ((currentSecond > timelimit) && (ReadyOrStart == 2)) //ComPortIsOpen == true,当前串口为打开状态,按钮事件为关闭串口
                                        {
                                            try                                                 //尝试关闭串口
                                            {
                                                ComPort.DiscardInBuffer();                      //清接收缓存
                                                SetAfterClose();                                //成功关闭串口或串口丢失后的设置
                                                ComPort.Close();                                //关闭串口
                                                ReadyOrStart = 0;                               //设置指示
                                                CMessageBoxResult confirmToDel = CMessageBox.Show("测量完成", CMessageBoxButton.OK);
                                                PatientInfo.finishtime         = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                                                openBtn.Content = "再次测量";
                                            }
                                            catch                            //如果在未关闭串口前,串口就已丢失,这时关闭串口会出现异常
                                            {
                                                if (ComPort.IsOpen == false) //判断当前串口状态,如果ComPort.IsOpen==false,说明串口已丢失
                                                {
                                                    SetComLose();
                                                }
                                                else//未知原因,无法关闭串口
                                                {
                                                    CMessageBox.Show("无法关闭设备,原因未知!");
                                                    return;//无法关闭串口,提示后直接返回
                                                }
                                            }
                                        }
                                    });
                                }
                                #endregion
                                if (ReadyOrStart == 2) //测量模式保存数据
                                {
                                    if (save == 0 && finalLR == 1)
                                    {
                                        PatientInfo.PatientData += shujvbao;     //记录当前保存的数据
                                        save = 1;
                                    }
                                    else if (save == 1 && finalLR == -1)
                                    {
                                        PatientInfo.PatientData += shujvbao;     //记录当前保存的数据
                                        save = 2;
                                    }
                                    else if (save == 2 && finalLR == 1)
                                    {
                                        PatientInfo.PatientData += shujvbao;     //记录当前保存的数据
                                        save = 1;
                                    }
                                }
                                //Thread.Sleep(10);
                                #endregion
                                #endregion
                            }
                            else
                            {
                                if (recData[0] != 0)
                                {
                                    Console.WriteLine("Drop data because of incorrect header");
                                }
                                else
                                {
                                    Console.WriteLine("Drop data because of incrrocet length");
                                }
                            }
                            #endregion
                        }
                        catch (Exception ed)
                        {
                            Console.WriteLine("error" + ed.Message);
                        }
                        #endregion
                    }
                }
                catch (Exception ed)
                {
                    CMessageBox.Show(ed.Message);
                    UIAction(() =>
                    {
                        if (ComPort.IsOpen == false) //如果ComPort.IsOpen == false,说明串口已丢失
                        {
                            SetComLose();            //串口丢失后相关设置
                        }
                        else
                        {
                            CMessageBox.Show("无法接收数据,原因未知!");
                        }
                    });
                }
            }
        }