Beispiel #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);
        }
Beispiel #2
0
        public bool ReadAllFramDataFromFile(ref byte[] AllFrameInfo, ref byte[] AllRaw, ref double[,] BeltData, double Angle0, UserControl_ReadFileBar RBar, ref string sErrString)
        {
            bool bResult = false;

            sErrString = "";
            double dBarStep = RBar.iBarValue;

            if (ggData.m_szFileName == "")   // 还没关联gg文件
            {
                sErrString = "尚未打开相关文件。";
                return(bResult);
            }

            if (ggData.numberof_frames <= 0)
            {
                AllRaw   = null;       // 没有数据
                BeltData = null;
                return(bResult);
            }

            dBarStep      += 5.0;
            RBar.iBarValue = (int)(dBarStep);
            MyTools.DoEvents();

            double Angle = 2 * PI_360 * Angle0 / 360;

            BeltData = null;
            IntPtr buffer = Marshal.AllocHGlobal(1);

            try
            {
                int iFrameInfoSize = Marshal.SizeOf(typeof(ggFrame_struct));

                AllFrameInfo = new byte[ggData.numberof_frames * iFrameInfoSize];
                mod_ReadGen2.Gen2_Struct Gen2Current = new mod_ReadGen2.Gen2_Struct();
                //Gen2Array = new mod_ReadGen2.Gen2_Struct[ggData.numberof_frames];
                mod_ShowPict PB = new mod_ShowPict();

                byte[] FirstLine  = new byte[ggData.numberof_frames * ggData.numberofpointofline * 2];
                byte[] SecondLine = new byte[ggData.numberof_frames * ggData.numberofpointofline * 2];

                int iFirstLine = 0, iSeconLine = 0;   // 取出第几线
                iFirstLine = (int)((ggData.numberofline / (PI_360 * 2)) * (Angle + ggData.Angle2));
                if (iFirstLine > ggData.numberofline)
                {
                    iFirstLine -= ggData.numberofline;
                }

                iSeconLine = iFirstLine + ggData.numberofline / 2;
                if (iSeconLine > ggData.numberofline)
                {
                    iSeconLine -= ggData.numberofline;
                }

                for (int i = 0; i < ggData.numberof_frames; i++)
                {
                    if (ggFileMoveToFrame("Goto", i, ref sErrString))
                    {
                        // 计算从第几帧取数据

                        if (ReadRawFrameDataFromFile(ref ggData.m_ggframe_info, ref ggData.m_lprawdata, ref ggData.m_lpimagedata, ref sErrString))
                        {
                            if (i == 0)
                            {
                                ggData.m_sizeofrawdata = ggData.m_ggframe_info.rawdatasize;
                                AllRaw = new byte[ggData.numberof_frames * ggData.m_sizeofrawdata];
                            }

                            Marshal.FreeHGlobal(buffer);                          // 释放以前分配的空间
                            buffer = Marshal.AllocHGlobal(iFrameInfoSize);        // 重新分配
                            Marshal.StructureToPtr((ggFrame_struct)ggData.m_ggframe_info, buffer, false);
                            Marshal.Copy(buffer, AllFrameInfo, i * iFrameInfoSize, iFrameInfoSize);

                            Array.Copy(ggData.m_lprawdata, 0, AllRaw, i * ggData.m_sizeofrawdata, ggData.m_sizeofrawdata);
                            //Gen2Current = new mod_ReadGen2.Gen2_Struct();
                            //if (mod_ReadGen2.ReadGen2FromGGClass(this, ref Gen2Current, ref sErrString) != MyData.iErr_Succ)
                            //{
                            //    MyTools.ShowMsg("读取数据失败!", "从gg类读数据失败 = " + sErrString);
                            //    goto Eend;
                            //}
                            //PB.pGen2 = Gen2Current;
                            //PB.Gen2ToData();                        // 转变成 PictData
                            //Gen2Array[i] = PB.pGen2;

                            Array.Copy(ggData.m_lprawdata, iFirstLine * ggData.numberofpointofline * 2, FirstLine, i * ggData.numberofpointofline * 2, ggData.numberofpointofline * 2);       // To First Line
                            Array.Copy(ggData.m_lprawdata, iSeconLine * ggData.numberofpointofline * 2, SecondLine, i * ggData.numberofpointofline * 2, ggData.numberofpointofline * 2);      // To First Line

                            dBarStep      += (double)(85.0 / ggData.numberof_frames);
                            RBar.iBarValue = (int)(dBarStep);
                            MyTools.DoEvents();
                        }
                        else
                        {
                            sErrString = "移动到第" + i.ToString() + "帧时出错";
                            goto Eend;
                        }
                    }
                    else
                    {
                        sErrString = "移动到第" + i.ToString() + "帧时出错";
                        goto Eend;
                    }
                }

                BeltData = new double[ggData.numberof_frames * 2, ggData.numberofpointofline];
                ushort uSi = 0;
                ushort uMax = 0, uMin = 0;

                for (int i = 0; i < ggData.numberof_frames; i++)
                {
                    for (int j = 0; j < ggData.numberofpointofline; j++)
                    {
                        uSi            = BitConverter.ToUInt16(FirstLine, i * ggData.numberofpointofline * 2 + j * 2);
                        BeltData[i, j] = (double)uSi;
                        if (uMin > uSi)
                        {
                            uMin = uSi;
                        }

                        if (uMax < uSi)
                        {
                            uMax = uSi;
                        }

                        uSi = BitConverter.ToUInt16(SecondLine, i * ggData.numberofpointofline * 2 + j * 2);
                        BeltData[ggData.numberof_frames + i, j] = (double)uSi;
                        if (uMin > uSi)
                        {
                            uMin = uSi;
                        }

                        if (uMax < uSi)
                        {
                            uMax = uSi;
                        }
                    }
                }

                for (int i = 0; i < ggData.numberof_frames; i++)
                {
                    for (int j = 0; j < ggData.numberofpointofline; j++)
                    {
                        //BeltData[i, j] = (BeltData[i, j] / 65535.0) * (uMax - uMin) + uMin;
                        //BeltData[ggData.numberof_frames + i, j] = (BeltData[ggData.numberof_frames + i, j] / 65535.0) * (uMax - uMin) + uMin;

                        BeltData[i, j] = BeltData[i, j] * 255 / 65535.0;
                        BeltData[ggData.numberof_frames + i, j] = BeltData[ggData.numberof_frames + i, j] * 255 / 65535.0;
                    }
                }

                bResult    = true;
                sErrString = "";
            }
            catch (OutOfMemoryException)
            {
                sErrString = "内存不足";
            }
            catch (Exception ex)
            {
                sErrString = ex.Message;
            }
            finally
            {
                Marshal.FreeHGlobal(buffer);
            }

Eend:
            return(bResult);
        }