Example #1
0
        private void button_Import_Click(object sender, RoutedEventArgs e)
        {
            string sTmp     = "";
            bool   bIsExist = false;

            if (ListBox_SelectFile.Items.Count <= 0)                     // 没有选择文件
            {
                MessageBox.Show("没有选择导入文件。", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }
            ButtonEnable(false);

            int iStep = 100 / ListBox_SelectFile.Items.Count;

            for (int i = 0; i < ListBox_SelectFile.Items.Count; i++)
            {
                sTmp = ListBox_SelectFile.Items[i].ToString();
                if (!File.Exists(sTmp))
                {
                    MessageBox.Show("文件 " + sTmp + " 不存在,请检查。" + System.Environment.NewLine + "按任意键继续......", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Information);
                    continue;
                }

                mod_ReadGen2.Gen2_Struct Gen2_Struct1;
                mod_GG gg1         = null;
                string sErrString  = "";
                string sExtendName = System.IO.Path.GetExtension(sTmp);

                try
                {
                    if (sExtendName == ".gen2")
                    {
                        Gen2_Struct1 = new mod_ReadGen2.Gen2_Struct();
                        if (mod_ReadGen2.ReadGen2FromFile(sTmp, ref Gen2_Struct1, ref sErrString) != MyData.iErr_Succ)
                        {
                            MessageBox.Show("读取文件 " + sTmp + " 时出错:" + sErrString + ",请检查!" + System.Environment.NewLine + "按任意键继续......", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Information);
                            goto ggEend;
                        }
                    }
                    else  // gg File
                    {
                        gg1          = new mod_GG();
                        Gen2_Struct1 = new mod_ReadGen2.Gen2_Struct();
                        if (gg1.ReadggHeader(sTmp, ref sErrString) != MyData.iErr_Succ)
                        {
                            MessageBox.Show("读取文件 " + sTmp + " 时出错:" + sErrString + ",请检查!" + System.Environment.NewLine + "按任意键继续......", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Information);
                            goto ggEend;
                        }

                        if (!gg1.ggFileMoveToFrame("Top", 0, ref sErrString))
                        {
                            MessageBox.Show("读取文件 " + sTmp + " 时出错:" + sErrString + ",请检查!" + System.Environment.NewLine + "按任意键继续......", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Information);
                            goto ggEend;
                        }

                        if (!gg1.ReadRawFrameDataFromFile(ref gg1.ggData.m_ggframe_info, ref gg1.ggData.m_lprawdata, ref gg1.ggData.m_lpimagedata, ref sErrString))
                        {
                            MessageBox.Show("读取文件 " + sTmp + " 时出错:" + sErrString + ",请检查!" + System.Environment.NewLine + "按任意键继续......", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Information);
                            goto ggEend;
                        }

                        if (mod_ReadGen2.ReadGen2FromGGClass(gg1, ref Gen2_Struct1, ref sErrString) != MyData.iErr_Succ)
                        {
                            MessageBox.Show("读取文件 " + sTmp + " 时出错:" + sErrString + ",请检查!" + System.Environment.NewLine + "按任意键继续......", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Information);
                            goto ggEend;
                        }
                    }

                    if (Ask_Patient == "Ask")
                    {
                        if (MyData.MySqlite.FindPatient(Gen2_Struct1.m_patientid, ref bIsExist, ref sErrString))
                        {
                            if (bIsExist)
                            {
                                IsAnswer    = false;
                                sAnswerMode = "";

                                TextBlock_Question.Text = "数据库已存在档案号 = " + Gen2_Struct1.m_patientid + "的资料,请选择:";
                                RepeatDisp(Visibility.Visible);
                                button_Continue.Focus();

                                while (!IsAnswer)
                                {
                                    MyTools.DoEvents();
                                    Thread.Sleep(100);
                                }

                                RepeatDisp(Visibility.Hidden);
                                if (sAnswerMode == "Stop")
                                {
                                    MyTools.ShowMsg("你已中断了导入功能!", "");
                                    ButtonEnable(true);
                                    if (sExtendName == ".gg")
                                    {
                                        gg1.ggClose();
                                    }
                                    return;
                                }
                                else
                                {
                                    if ((bool)RadioButton_Cover.IsChecked)
                                    {
                                        iCoverMode_Patient = MyData.iDataCoverMode_Cover;
                                    }
                                    else if ((bool)RadioButton_NotCover.IsChecked)
                                    {
                                        iCoverMode_Patient = MyData.iDataCoverMode_NotCover;
                                    }
                                    else
                                    {
                                        iCoverMode_Patient = MyData.iDataCoverMode_New;
                                    }

                                    if ((bool)RadioButton_Same.IsChecked)
                                    {
                                        Ask_Patient = "Same";
                                    }
                                    else
                                    {
                                        Ask_Patient = "Ask";
                                    }
                                }
                            }
                        }
                        else
                        {
                            MessageBox.Show("检查数据库时出现错误:" + sErrString + ",请检查!" + System.Environment.NewLine + "按任意键继续......", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Information);
                            goto ggEend;
                        }
                    }

                    if (Ask_Record == "Ask")
                    {
                        if (MyData.MySqlite.FindRecord(Gen2_Struct1.m_patientid, Gen2_Struct1.m_image_datatime, ref bIsExist, ref sErrString))
                        {
                            if (bIsExist)
                            {
                                IsAnswer    = false;
                                sAnswerMode = "";

                                TextBlock_Question.Text = Gen2_Struct1.m_patientid + " 的档案已存在检查时间 = " + Gen2_Struct1.m_image_datatime + " 的记录,请选择:";
                                RepeatDisp(Visibility.Visible);
                                button_Continue.Focus();

                                while (!IsAnswer)
                                {
                                    MyTools.DoEvents();
                                    Thread.Sleep(100);
                                }

                                RepeatDisp(Visibility.Hidden);
                                if (sAnswerMode == "Stop")
                                {
                                    MyTools.ShowMsg("你已中断了导入功能!", "");
                                    ButtonEnable(true);
                                    if (sExtendName == ".gg")
                                    {
                                        gg1.ggClose();
                                    }
                                    return;
                                }
                                else
                                {
                                    if ((bool)RadioButton_Cover.IsChecked)
                                    {
                                        iCoverMode_Record = MyData.iDataCoverMode_Cover;
                                    }
                                    else if ((bool)RadioButton_NotCover.IsChecked)
                                    {
                                        iCoverMode_Record = MyData.iDataCoverMode_NotCover;
                                    }
                                    else
                                    {
                                        iCoverMode_Record = MyData.iDataCoverMode_New;
                                    }

                                    if ((bool)RadioButton_Same.IsChecked)
                                    {
                                        Ask_Record = "Same";
                                    }
                                    else
                                    {
                                        Ask_Record = "Ask";
                                    }
                                }
                            }
                        }
                        else
                        {
                            MessageBox.Show("检查数据库时出现错误:" + sErrString + ",请检查!" + System.Environment.NewLine + "按任意键继续......", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Information);
                            goto ggEend;
                        }
                    }

                    // Insert into DB
                    if (mod_ReadGen2.Gen2DataToDB(sTmp, Gen2_Struct1,
                                                  true,                              // Check PatientID
                                                  false,                             // Check Name
                                                  iCoverMode_Patient,
                                                  true,
                                                  iCoverMode_Record,
                                                  ref sErrString) == MyData.iErr_Succ)
                    {
                        //MyTools.ShowMsg("导入成功!", "");
                    }
                    else
                    {
                        MessageBox.Show("导入文件 " + sTmp + " 时出错:" + sErrString + ",请检查!" + System.Environment.NewLine + "按任意键继续......", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Information);
                    }

ggEend:
                    if (sExtendName == ".gg")
                    {
                        gg1.ggClose();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("导入文件 " + sTmp + " 时出现意外错误:" + ex.Message + ",请检查!" + System.Environment.NewLine + "按任意键继续......", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Information);
                }

                progressBar_Read.Value += iStep;
                MyTools.DoEvents();
            }
            progressBar_Read.Value = 100;
            MyTools.ShowMsg("已完成所选文件的导入!", "");
            ButtonEnable(true);
        }
Example #2
0
        public static int ReadGen2FromGGClass(mod_GG GG, ref Gen2_Struct ThisGen2, ref string sErrString)
        {
            int iResult = iErr_UnknowErr;

            // 用GG当前帧的数据构建 Gen2
            ThisGen2 = new Gen2_Struct();

            try
            {
                ThisGen2.m_FileName       = GG.ggData.m_szFileName;
                ThisGen2.m_cbsize         = 0;
                ThisGen2.m_lastname       = GG.ggData.m_ggheader.szLastname;
                ThisGen2.m_firstname      = GG.ggData.m_ggheader.szFirstname;
                ThisGen2.m_patientid      = GG.ggData.m_ggheader.szPatientid;
                ThisGen2.m_sex            = GG.ggData.m_ggheader.szSex;
                ThisGen2.m_dateofbirth    = GG.ggData.m_ggheader.szDateofBirth;
                ThisGen2.m_physican1      = GG.ggData.m_ggheader.szPhysican1;
                ThisGen2.m_physican2      = GG.ggData.m_ggheader.szPhysican2;
                ThisGen2.m_image_datatime = DateTime.Parse(GG.ggData.m_ggheader.szDate).ToString("yyyy-MM-dd ") +
                                            DateTime.Parse(GG.ggData.m_ggheader.szTime).ToString("HH:mm:ss");

                // 补充
                ThisGen2.m_FileID     = 0;
                ThisGen2.m_Address    = "";
                ThisGen2.m_Tele       = "";
                ThisGen2.m_IdentifyID = "";
                // 补充 End

                //ThisGen2.m_Procedures;
                ThisGen2.m_Note = GG.ggData.m_ggheader.szNote;

                ThisGen2.m_NScanSave       = GG.ggData.m_ggheader.numberofline;
                ThisGen2.m_Angle2          = (int)GG.ggData.m_ggheader.Angle2;
                ThisGen2.m_Number_line_360 = GG.ggData.m_ggheader.NumberOfline_360;
                ThisGen2.m_SN = GG.ggData.m_ggheader.SN;
                ThisGen2.m_DD = GG.ggData.m_ggheader.DD;
                ThisGen2.m_G  = GG.ggData.m_ggheader.G;

                ThisGen2.m_NData    = GG.ggData.m_ggheader.numberofpointofline;
                ThisGen2.m_maxValue = GG.ggData.m_ggframe_info.raw_maxvalue;       // 记录这组Data中的最大值与最小值
                ThisGen2.m_minValue = GG.ggData.m_ggframe_info.raw_minvalue;

                ThisGen2.ampplot_sI = new Int32[ThisGen2.m_NScanSave, ThisGen2.m_NData];
                ThisGen2.ampplot_s  = new double[ThisGen2.m_NScanSave, ThisGen2.m_NData];

                sbyte  d1 = 0;
                sbyte  d2 = 0;
                int    i = 0, j = 0;
                int    iTmp = 0;
                ushort uSi  = 0;

                double Max = 0, Min = 0;

                // For Print ========================================
                //FileStream FileForPrint = File.Open(Directory.GetCurrentDirectory() + "\\gg_Ampplot_sI.txt", FileMode.Create);
                //StreamWriter w = new StreamWriter(FileForPrint);
                // ==================================================

                for (j = 0; j < ThisGen2.m_NScanSave; j++)
                {
                    for (i = 0; i < ThisGen2.m_NData; i++)
                    {
                        ////d1 = (sbyte)br.ReadByte();
                        ////d2 = (sbyte)br.ReadByte();

                        //d1 = (sbyte)GG.ggData.m_lprawdata[j * ThisGen2.m_NData + 2 * i];
                        //d2 = (sbyte)GG.ggData.m_lprawdata[j * ThisGen2.m_NData + 2 * i + 1];
                        //iTmp = d1;
                        //if (iTmp < 0)
                        //    iTmp += 256;
                        //ThisGen2.ampplot_sI[j, i] = iTmp * 256;

                        //iTmp = d2;
                        //if (iTmp < 0)
                        //    iTmp += 256;
                        //ThisGen2.ampplot_sI[j, i] += iTmp;

                        uSi = BitConverter.ToUInt16(GG.ggData.m_lprawdata, j * 2 * ThisGen2.m_NData + 2 * i);
                        ThisGen2.ampplot_sI[j, i] = uSi;

                        // For Print ========================
                        //w.Write("ThisGen2.ampplot_sI[" + j.ToString() + "," + i.ToString() + "] = " + ThisGen2.ampplot_sI[j, i].ToString() + Environment.NewLine);
                        // ==================================

                        //if (j < 10)
                        ThisGen2.ampplot_s[j, i] = (ThisGen2.ampplot_sI[j, i] / 65535.0) * (ThisGen2.m_maxValue - ThisGen2.m_minValue) + ThisGen2.m_minValue;
                        //else
                        //    ThisGen2.ampplot_s[j, i] = 0;

                        if (ThisGen2.ampplot_s[j, i] < Min)
                        {
                            Min = ThisGen2.ampplot_s[j, i];
                        }

                        if (ThisGen2.ampplot_s[j, i] > Max)
                        {
                            Max = ThisGen2.ampplot_s[j, i];
                        }
                    }
                }

                // For Print ========================
                //w.Close();
                //FileForPrint.Close();
                // ==================================

                iResult    = iErr_Succ;
                sErrString = "";
            }
            catch (Exception ex)
            {
                iResult    = iErr_Exception;
                sErrString = "GG转换成Gen2时意外错误(" + ex.Message + ")";
            }

            return(iResult);
        }