/// <summary>
        /// Initialize self streaming system
        /// </summary>
        /// <param name="path">path to file</param>
        public static void begin(string path)
        {
            p = path;
            end();
            if (File.Exists(path))
            {
                // load and save statistic file
                if (!File.Exists(path + ".xml"))
                {
                    formStatistic sttc = new formStatistic();
                    if (sttc.ShowDialog() == DialogResult.OK)
                    {
                        EcgStatistic ecg = new EcgStatistic();
                        ecg.id   = sttc.mId.Text;
                        ecg.name = sttc.mName.Text;
                        ecg.age  = sttc.mAge.Text;

                        string[] tm = sttc.mTime.Text.Split(':');
                        int      hh = int.Parse(tm[0]);
                        int      mm = int.Parse(tm[1]);
                        int      ss = int.Parse(tm[2]);
                        ecg.starttimeSec = ss + mm * 60 + hh * 60 * 60;

                        id = ecg;
                    }
                    else
                    {
                        id = new EcgStatistic();
                    }
                    XmlClass <EcgStatistic> .Save(id, path + ".xml", SerializedFormat.Document);
                }
                else
                {
                    id = XmlClass <EcgStatistic> .Load(path + ".xml", SerializedFormat.Document);
                }



                // load file to stream
                io = new BinaryReader(new FileStream(path, FileMode.Open));
            }
        }
예제 #2
0
        public formMain()
        {
            InitializeComponent();
            ribon1.add("Open", box.folder, true, () =>
            {
                // open ecg file
                OpenFileDialog op = new OpenFileDialog();
                op.Filter         = "ECG Files (*.bin)|*.bin";
                if (op.ShowDialog() == DialogResult.OK)
                {
                    // store path to config
                    Settings set = Settings.instance();
                    set.path     = op.FileName;
                    set.commit();
                    // load file
                    FileHandler.begin(set.path);
                    this.OnLoad(null);
                }
            });
            ribon1.add("Print", box.mail, true, () =>
            {
                // skip if file not loaded
                if (!FileHandler.available())
                {
                    return;
                }
                // open print form
                formPrint frm = new formPrint(this);
                frm.ShowDialog();
            });
            ribon1.add("Edit", box.edit, true, () =>
            {
                // skip if file not loaded
                if (!FileHandler.available())
                {
                    return;
                }
                Settings set = Settings.instance();

                // edit file information
                formStatistic sttc = new formStatistic();

                sttc.mId.Text   = FileHandler.id.id;
                sttc.mName.Text = FileHandler.id.name;
                sttc.mAge.Text  = FileHandler.id.age;

                TimeSpan ts = TimeSpan.FromSeconds(FileHandler.id.starttimeSec);



                sttc.mTime.Text = zero(ts.Hours) + ":" + zero(ts.Minutes) + ":" + zero(ts.Seconds);

                if (sttc.ShowDialog() == DialogResult.OK)
                {
                    // load ecg information data
                    EcgStatistic ecg = new EcgStatistic();
                    ecg.id           = sttc.mId.Text;
                    ecg.name         = sttc.mName.Text;
                    ecg.age          = sttc.mAge.Text;
                    ecg.critical     = FileHandler.id.critical;
                    string[] tm      = sttc.mTime.Text.Split(':');
                    int hh           = int.Parse(tm[0]);
                    int mm           = int.Parse(tm[1]);
                    int ss           = int.Parse(tm[2]);
                    ecg.starttimeSec = ss + mm * 60 + hh * 60 * 60;

                    FileHandler.id = ecg;

                    // save file information
                    XmlClass <EcgStatistic> .Save(ecg, set.path + ".xml", SerializedFormat.Document);

                    // refresh graph data
                    graph1.ecgid = ecg;
                    slider1.s2   = graph1.ecgid.starttimeSec;
                    graph1.s2    = graph1.ecgid.starttimeSec + slider1.seek * 56.0f / sampleRate;
                    graph1.Refresh();
                    slider1.Refresh();
                }
            });
            ribon1.add("Save", box.save, true, () =>
            {
                // skip if file not loaded
                if (!FileHandler.available())
                {
                    return;
                }

                // save  data
                SaveFileDialog op = new SaveFileDialog();
                op.Filter         = "ECG Files (*.bin)|*.bin";
                if (op.ShowDialog() == DialogResult.OK)
                {
                    FileHandler.save(op.FileName, slider1.seek, slider1.blocks);
                }
            });
            ribon1.add("Analyses", box.heart, true, () =>
            {
                if (!FileHandler.available())
                {
                    return;
                }

                // open analyse form
                formAnalyse frm = new formAnalyse();
                frm.ShowDialog();
            });


            ribon1.add("Goto", box.ff, true, () =>
            {
                // skip if file not loaded
                if (!FileHandler.available())
                {
                    return;
                }

                // goto time
                formTime tme = new formTime();

                TimeSpan ts     = TimeSpan.FromSeconds(FileHandler.id.starttimeSec + slider1.seek * 56.0f / slider1.sampleRate);
                tme.mDays.Value = ts.Days;
                tme.mTime.Text  = zero(ts.Hours) + ":" + zero(ts.Minutes) + ":" + zero(ts.Seconds);


                if (tme.ShowDialog() == DialogResult.OK)
                {
                    int days    = (int)(tme.mDays.Value);
                    string[] tm = tme.mTime.Text.Split(':');
                    int hh      = int.Parse(tm[0]);
                    int mm      = int.Parse(tm[1]);
                    int ss      = int.Parse(tm[2]);

                    // calculate seek seconds
                    long sc = days * 24 * 60 * 60 + hh * 60 * 60 + mm * 60 + ss;

                    // conver seconds to block number
                    slider1.seek = (long)((float)(sc - FileHandler.id.starttimeSec) * (float)slider1.sampleRate / 56.0f) + 1;

                    if (slider1.seek < 0)
                    {
                        slider1.seek = 0;
                    }

                    slider1.page = (long)((float)slider1.seek / (float)slider1.perPage);

                    // refresh
                    slider1.reload();
                }
            });
            ribon1.add("Process Button Presses", box.analyse, true, () =>
            {
                // skip if file not loaded
                if (!FileHandler.available())
                {
                    return;
                }

                // open signal for analysing button presses
                formProcess frm = new formProcess(this);
                if (frm.ShowDialog() == DialogResult.OK)
                {
                    if (frm.listBox1.SelectedIndex >= 0)
                    {
                        var aa = (formProcess.time)(frm.listBox1.Items[frm.listBox1.SelectedIndex]);

                        slider1.seek = aa.block;
                        slider1.reload();
                    }
                }
            });
            ribon1.add("Settings", box.settings, false, () =>
            {
                formSettings frm = new formSettings(this);
                frm.ShowDialog();
            });

            ribon1.add("About", box.i, false, () => { });
        }