Пример #1
0
        private void printDocument1_BeginPrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            int i = 0;

            char[] param = { '\n' };

            ListBox ml = new ListBox();

            GlobeVal.putlistboxitem(ml);

            lines = new string[ml.Items.Count];

            for (i = 0; i < ml.Items.Count; i++)
            {
                lines[i] = Convert.ToString(ml.Items[i]);
            }
        }
        private void btnelook_Click(object sender, EventArgs e)
        {
            if (tabControl1.SelectedIndex == 2)
            {
                CustomControls.MethodOpenFileDialog controlex = new CustomControls.MethodOpenFileDialog();
                controlex.StartLocation               = AddonWindowLocation.Right;
                controlex.DefaultViewMode             = FolderViewMode.Details;
                controlex.OpenDialog.InitialDirectory = lblpath.Text;
                controlex.OpenDialog.AddExtension     = true;
                controlex.OpenDialog.Filter           = "样品文件(*.spe)|*.spe";
                controlex.ShowDialog(this);

                if (controlex.OpenDialog.FileName == null)
                {
                    return;
                }
                else
                {
                    string fileName = controlex.OpenDialog.FileName;
                    gfilename = fileName;
                    if (fileName == "")
                    {
                        return;
                    }
                    else
                    {
                        this.txtsample.Text     = Path.GetFileNameWithoutExtension(fileName);
                        this.txtsamplepath.Text = Path.GetDirectoryName(fileName);

                        if (CComLibrary.GlobeVal.filesave == null)
                        {
                            CComLibrary.GlobeVal.filesave = new CComLibrary.FileStruct();
                        }
                        CComLibrary.GlobeVal.filesave = CComLibrary.GlobeVal.filesave.DeSerializeNow(fileName);

                        CComLibrary.GlobeVal.currentfilesavename = fileName;


                        GlobeVal.putlistboxitem(listBox2);


                        ListViewItem lv = new ListViewItem();
                        lv.Text = this.txtsample.Text;


                        lv.SubItems.Add(ClsStaticStation.m_Global.mycls.TestkindList[CComLibrary.GlobeVal.filesave.methodkind]);
                        lv.SubItems.Add(System.IO.File.GetLastWriteTime(fileName).ToLongDateString() + " " + System.IO.File.GetLastWriteTime(fileName).ToLongTimeString());
                        lv.SubItems.Add(Path.GetDirectoryName(fileName));

                        if (listView2.Items.Count > 0)
                        {
                            if (this.txtsample.Text == listView2.Items[0].Text)
                            {
                                listView2.Items.RemoveAt(0);
                            }

                            if (listView2.Items.Count >= 20)
                            {
                                listView2.Items.RemoveAt(19);
                            }
                        }
                        listView2.Items.Insert(0, lv);



                        for (int i = 0; i < listView2.Items.Count; i++)
                        {
                            GlobeVal.myglobefile.RecentSampleFilename[i]     = listView2.Items[i].Text;
                            GlobeVal.myglobefile.RecentSampleFilenameKind[i] = listView2.Items[i].SubItems[1].Text;
                            GlobeVal.myglobefile.RecentSampleFilePath[i]     = listView2.Items[i].SubItems[3].Text;
                        }

                        for (int i = listView2.Items.Count; i < 20; i++)
                        {
                            GlobeVal.myglobefile.RecentSampleFilename[i]     = "";
                            GlobeVal.myglobefile.RecentSampleFilenameKind[i] = "";
                            GlobeVal.myglobefile.RecentSampleFilePath[i]     = "";
                        }

                        ClsStaticStation.m_Global.mycls.initchannel();
                        ((FormMainLab)Application.OpenForms["FormMainLab"]).InitKey();
                        ((FormMainLab)Application.OpenForms["FormMainLab"]).InitMeter();

                        //lblmethodkind.Text = ClsStaticStation.m_Global.mycls.TestkindList[CComLibrary.GlobeVal.filesave.methodkind];
                        //lblmethod.Text = this.txtmethod.Text;
                    }
                }

                controlex.Dispose();
            }
            if (tabControl1.SelectedIndex == 1)
            {
                this.folderBrowserDialog1.SelectedPath = lblpath.Text;
                this.folderBrowserDialog1.ShowDialog();

                lblpath.Text = this.folderBrowserDialog1.SelectedPath;

                GlobeVal.myglobefile.SamplePath = lblpath.Text;
            }
            if (tabControl1.SelectedIndex == 0)
            {
                CustomControls.MethodOpenFileDialog controlex = new CustomControls.MethodOpenFileDialog();
                controlex.StartLocation               = AddonWindowLocation.Right;
                controlex.DefaultViewMode             = FolderViewMode.Details;
                controlex.OpenDialog.InitialDirectory = System.Windows.Forms.Application.StartupPath + "\\AppleLabJ" + "\\Method";
                controlex.OpenDialog.AddExtension     = true;
                controlex.OpenDialog.Filter           = "试验方法文件(*.dat)|*.dat";
                controlex.ShowDialog(this);



                if (controlex.OpenDialog.FileName == null)
                {
                    return;
                }
                else
                {
                    string fileName = controlex.OpenDialog.FileName;
                    gfilename = fileName;

                    if (fileName == "")
                    {
                        return;
                    }
                    else
                    {
                        this.txtmethod.Text = Path.GetFileNameWithoutExtension(fileName);
                        this.txtpath.Text   = Path.GetDirectoryName(fileName);

                        if (CComLibrary.GlobeVal.filesave == null)
                        {
                            CComLibrary.GlobeVal.filesave = new CComLibrary.FileStruct();
                        }
                        CComLibrary.GlobeVal.filesave = CComLibrary.GlobeVal.filesave.DeSerializeNow(fileName);

                        CComLibrary.GlobeVal.currentfilesavename = fileName;

                        GlobeVal.putlistboxitem(listBox1);


                        ListViewItem lv = new ListViewItem();
                        lv.Text = this.txtmethod.Text;


                        lv.SubItems.Add(ClsStaticStation.m_Global.mycls.TestkindList[CComLibrary.GlobeVal.filesave.methodkind]);
                        lv.SubItems.Add(System.IO.File.GetLastWriteTime(fileName).ToLongDateString() + " " + System.IO.File.GetLastWriteTime(fileName).ToLongTimeString());


                        if (listView1.Items.Count > 0)
                        {
                            if (this.txtmethod.Text == listView1.Items[0].Text)
                            {
                                listView1.Items.RemoveAt(0);
                            }
                        }

                        if (listView1.Items.Count >= 20)
                        {
                            listView1.Items.RemoveAt(19);
                        }
                        listView1.Items.Insert(0, lv);



                        for (int i = 0; i < listView1.Items.Count; i++)
                        {
                            GlobeVal.myglobefile.RecentFilename[i]     = listView1.Items[i].Text;
                            GlobeVal.myglobefile.RecentFilenameKind[i] = listView1.Items[i].SubItems[1].Text;
                        }

                        for (int i = listView1.Items.Count; i < 20; i++)
                        {
                            GlobeVal.myglobefile.RecentFilename[i]     = "";
                            GlobeVal.myglobefile.RecentFilenameKind[i] = "";
                        }

                        ClsStaticStation.m_Global.mycls.initchannel();
                        ((FormMainLab)Application.OpenForms["FormMainLab"]).InitKey();
                        ((FormMainLab)Application.OpenForms["FormMainLab"]).InitMeter();

                        lblmethodkind.Text = ClsStaticStation.m_Global.mycls.TestkindList[CComLibrary.GlobeVal.filesave.methodkind];
                        lblmethod.Text     = this.txtmethod.Text;
                    }
                }

                controlex.Dispose();
            }
        }
        private void btneopen_Click(object sender, EventArgs e)
        {
            if (tabControl1.SelectedIndex == 0)
            {
                if (listView1.SelectedIndices.Count > 0)
                {
                    string fileName = System.Windows.Forms.Application.StartupPath + "\\AppleLabJ" + "\\Method\\" + listView1.Items[listView1.SelectedIndices[0]].SubItems[1].Text + "\\"
                                      + listView1.Items[listView1.SelectedIndices[0]].Text + ".dat";
                    gfilename = fileName;

                    if (System.IO.File.Exists(fileName) == true)
                    {
                    }
                    else
                    {
                        MessageBox.Show("方法不存在");
                        return;
                    }

                    if (fileName == "")
                    {
                        return;
                    }
                    else
                    {
                        this.txtmethod.Text = Path.GetFileNameWithoutExtension(fileName);
                        this.txtpath.Text   = Path.GetDirectoryName(fileName);

                        if (CComLibrary.GlobeVal.filesave == null)
                        {
                            CComLibrary.GlobeVal.filesave = new CComLibrary.FileStruct();
                        }
                        CComLibrary.GlobeVal.filesave = CComLibrary.GlobeVal.filesave.DeSerializeNow(fileName);

                        CComLibrary.GlobeVal.currentfilesavename = fileName;

                        GlobeVal.putlistboxitem(listBox1);



                        ListViewItem lv = new ListViewItem();
                        lv.Text = this.txtmethod.Text;


                        lv.SubItems.Add(ClsStaticStation.m_Global.mycls.TestkindList[CComLibrary.GlobeVal.filesave.methodkind]);
                        lv.SubItems.Add(System.IO.File.GetLastWriteTime(fileName).ToLongDateString() + " " + System.IO.File.GetLastWriteTime(fileName).ToLongTimeString());



                        if (this.txtmethod.Text == listView1.Items[0].Text)
                        {
                            listView1.Items.RemoveAt(0);
                        }

                        if (listView1.Items.Count >= 20)
                        {
                            listView1.Items.RemoveAt(19);
                        }
                        listView1.Items.Insert(0, lv);

                        for (int i = 0; i < listView1.Items.Count; i++)
                        {
                            GlobeVal.myglobefile.RecentFilename[i]     = listView1.Items[i].Text;
                            GlobeVal.myglobefile.RecentFilenameKind[i] = listView1.Items[i].SubItems[1].Text;
                        }

                        for (int i = listView1.Items.Count; i < 20; i++)
                        {
                            GlobeVal.myglobefile.RecentFilename[i]     = "";
                            GlobeVal.myglobefile.RecentFilenameKind[i] = "";
                        }

                        ClsStaticStation.m_Global.mycls.initchannel();
                        ((FormMainLab)Application.OpenForms["FormMainLab"]).InitKey();
                        ((FormMainLab)Application.OpenForms["FormMainLab"]).InitMeter();

                        lblmethodkind.Text = ClsStaticStation.m_Global.mycls.TestkindList[CComLibrary.GlobeVal.filesave.methodkind];
                        lblmethod.Text     = this.txtmethod.Text;
                    }
                }

                else
                {
                    MessageBox.Show("请选择最近使用的试验方法");
                }
            }

            if (tabControl1.SelectedIndex == 2)
            {
                if (listView2.SelectedIndices.Count > 0)
                {
                    string fileName = listView2.Items[listView2.SelectedIndices[0]].SubItems[3].Text + "\\"
                                      + listView2.Items[listView2.SelectedIndices[0]].Text + ".spe";
                    gfilename = fileName;

                    if (System.IO.File.Exists(fileName) == true)
                    {
                    }
                    else
                    {
                        MessageBox.Show("样品文件不存在");
                        return;
                    }

                    if (fileName == "")
                    {
                        return;
                    }
                    else
                    {
                        this.txtsample.Text     = Path.GetFileNameWithoutExtension(fileName);
                        this.txtsamplepath.Text = Path.GetDirectoryName(fileName);

                        if (CComLibrary.GlobeVal.filesave == null)
                        {
                            CComLibrary.GlobeVal.filesave = new CComLibrary.FileStruct();
                        }
                        CComLibrary.GlobeVal.filesave = CComLibrary.GlobeVal.filesave.DeSerializeNow(fileName);

                        CComLibrary.GlobeVal.currentfilesavename = fileName;

                        GlobeVal.putlistboxitem(listBox2);


                        ListViewItem lv = new ListViewItem();
                        lv.Text = this.txtsample.Text;


                        lv.SubItems.Add(ClsStaticStation.m_Global.mycls.TestkindList[CComLibrary.GlobeVal.filesave.methodkind]);
                        lv.SubItems.Add(System.IO.File.GetLastWriteTime(fileName).ToLongDateString() + " " + System.IO.File.GetLastWriteTime(fileName).ToLongTimeString());
                        lv.SubItems.Add(Path.GetDirectoryName(fileName));

                        if (this.txtsample.Text == listView2.Items[0].Text)
                        {
                            listView2.Items.RemoveAt(0);
                        }


                        if (listView2.Items.Count >= 20)
                        {
                            listView2.Items.RemoveAt(19);
                        }
                        listView2.Items.Insert(0, lv);



                        for (int i = 0; i < listView2.Items.Count; i++)
                        {
                            GlobeVal.myglobefile.RecentSampleFilename[i]     = listView2.Items[i].Text;
                            GlobeVal.myglobefile.RecentSampleFilenameKind[i] = listView2.Items[i].SubItems[1].Text;
                            GlobeVal.myglobefile.RecentSampleFilePath[i]     = listView2.Items[i].SubItems[3].Text;
                        }

                        for (int i = listView2.Items.Count; i < 20; i++)
                        {
                            GlobeVal.myglobefile.RecentSampleFilename[i]     = "";
                            GlobeVal.myglobefile.RecentSampleFilenameKind[i] = "";
                            GlobeVal.myglobefile.RecentSampleFilePath[i]     = "";
                        }

                        ClsStaticStation.m_Global.mycls.initchannel();
                        ((FormMainLab)Application.OpenForms["FormMainLab"]).InitKey();
                        ((FormMainLab)Application.OpenForms["FormMainLab"]).InitMeter();

                        //lblmethodkind.Text = ClsStaticStation.m_Global.mycls.TestkindList[CComLibrary.GlobeVal.filesave.methodkind];
                        //lblmethod.Text = this.txtmethod.Text;
                    }
                }
                else
                {
                    MessageBox.Show("请选择最近使用的样本");
                }
            }
        }