private void btnBrowse_Click(object sender, RoutedEventArgs e)
        {
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
            dlg.Filter = "模型(*.eftir_aid)|*.eftir_aid";
            if (dlg.ShowDialog() == true)
            {
                //分析模型文件中待检测的组分
                eftir_cls_ident_method identmethod = eftir_cls_ident_method.Deserialize(dlg.FileName);
                if (identmethod != null)
                {
                    txtMethodName.Text = dlg.FileName;

                    componentList.Clear();
                    foreach (eftir_cls_ident_method.analyte item in identmethod.analytes)                //主料API
                    {
                        ComponentInfo info = new ComponentInfo();
                        info.name  = item.name;
                        info.isAPI = true;
                        info.type  = ComponentType.IdentExist;             //临时修改20130326, 以前是定量
                        componentList.Add(new ComponentDisplayInfo(info)); //加入主成分显示列表
                    }
                    gridTargetComponent.Items.Refresh();

                    InterferentList.Clear();
                    foreach (eftir_cls_ident_method.interferent item in identmethod.interferents)       //辅料
                    {
                        //如果是系统规定的不需要处理的组分,不列出来, 包括"水_"这样的组分
                        if (SettingData.settingData.runing_para.notDeal.Find(nodealItem => item.name == nodealItem || item.name.IndexOf(nodealItem + "_") == 0) != null)
                        {
                            continue;
                        }

                        ComponentInfo info = new ComponentInfo();
                        info.name  = item.name;
                        info.type  = ComponentType.IdentExist;
                        info.isAPI = false;

                        //为辅料添加每一个targetName, 缺省设置为不检测
                        foreach (eftir_cls_ident_method.analyte apiitem in identmethod.analytes)
                        {
                            ComponentInfo.Interferent interinfo = new ComponentInfo.Interferent(apiitem.name, ComponentType.NotDeal, 0);
                            info.interferents.Add(interinfo);
                        }
                        InterferentList.Add(new InterferentDisplayInfo(info));      //加入辅料显示列表
                    }

                    UpdateInterferentGrid();
                }
                else
                {
                    CommonMethod.ErrorMsgBox("不能分析文件,错误:" + identmethod.ErrorString);
                }
            }
        }
Beispiel #2
0
        private bool CopyMethodFiles(MethodInfo method, string parentDirectory)
        {
            try
            {
                eftir_cls_ident_method cls_method = eftir_cls_ident_method.Deserialize(method.methodFile);
                if (cls_method == null)
                {
                    return(false);
                }

                //拷贝引用的光谱文件
                //会将模型中的数状结构变成平面结构,因此要保证模型中所引用的文件名不相同
                foreach (eftir_cls_ident_method.analyte item in cls_method.analytes)
                {
                    string filename = Path.Combine(parentDirectory, Path.GetFileName(item.filename));
                    File.Copy(item.filename, filename, true);
                    item.filename = filename;   //修改引用文件路径到当前路径
                }
                foreach (eftir_cls_ident_method.interferent item in cls_method.interferents)
                {
                    string filename = Path.Combine(parentDirectory, Path.GetFileName(item.filename));
                    File.Copy(item.filename, filename, true);
                    item.filename = filename;
                }

                //序列化模型文件到当前文件夹
                string clsfile = Path.Combine(parentDirectory, Path.GetFileName(method.methodFile));
                if (!cls_method.Serialize(clsfile))
                {
                    return(false);
                }

                //序列化MethodInfo到当前文件夹
                clsfile = Path.Combine(parentDirectory, "MethodInfo_Temp.methodinfo");      //MethodInfo的内容
                return(method.Serialize(clsfile));
            }
            catch (Exception ex)
            {
                CommonMethod.ErrorMsgBox(ex.Message);
                return(false);
            }
        }
Beispiel #3
0
        private MethodTreeNode CreateMethodNodeFromDirectory(string currentPath)
        {
            try
            {
                //先查找当前node的名称, 从文件methodnode.name中读取
                string namefile = Path.Combine(currentPath, "methodnode.name");
                if (!File.Exists(namefile))
                {
                    throw new Exception("文件格式不正确或者被损坏");
                }
                MethodTreeNode curnode = new MethodTreeNode();
                StreamReader   reader  = new StreamReader(namefile, Encoding.GetEncoding(SettingData.UTF8));
                curnode.Name = reader.ReadLine();
                reader.Close();
                File.Delete(namefile);      //删除临时的methodnode.name

                string tempmethodfile = Path.Combine(currentPath, "MethodInfo_Temp.methodinfo");
                if (File.Exists(tempmethodfile))      //查看是否包含MethodInfo信息
                {
                    //加载MethodInfo信息
                    curnode.Method = MethodInfo.Deserialize(tempmethodfile);
                    File.Delete(tempmethodfile);    //删除临时的MethodInfo_Temp.methodinfo

                    //更改引用拉曼方法的路径为当前路径
                    curnode.Method.methodFile = Path.Combine(currentPath, Path.GetFileName(curnode.Method.methodFile));

                    //处理拉曼方法
                    var files = Directory.EnumerateFiles(currentPath, Path.GetFileName(curnode.Method.methodFile));
                    foreach (string file in files)
                    {
                        eftir_cls_ident_method method = eftir_cls_ident_method.Deserialize(Path.Combine(currentPath, file));
                        if (method == null)
                        {
                            throw new Exception("文件格式不正确或者被损坏");
                        }

                        //更改引用光谱的路径为当前路径
                        foreach (eftir_cls_ident_method.analyte item in method.analytes)
                        {
                            item.filename = Path.Combine(currentPath, Path.GetFileName(item.filename));
                        }
                        foreach (eftir_cls_ident_method.interferent item in method.interferents)
                        {
                            item.filename = Path.Combine(currentPath, Path.GetFileName(item.filename));
                        }

                        //保存修改路径后的方法
                        method.Serialize(Path.Combine(currentPath, file));
                    }
                }

                //处理子目录, 也就是子节点
                var subdirs = Directory.GetDirectories(currentPath);
                foreach (string dir in subdirs)
                {
                    MethodTreeNode subnode = CreateMethodNodeFromDirectory(dir);
                    if (subnode == null)
                    {
                        return(null);
                    }
                    curnode.Children.Add(subnode);
                }

                return(curnode);
            }
            catch (Exception ex)
            {
                CommonMethod.ErrorMsgBox(ex.Message);
                return(null);
            }
        }