示例#1
0
        /// <summary>
        /// 打开时封装数据并传递到Main窗口
        /// </summary>
        /// <param name="sender">对象</param>
        /// <param name="e">参数</param>
        private void btnOpenFiles_Click(object sender, EventArgs e)
        {
            List <WavefromData> waveDataList = new List <WavefromData>();

            for (int i = 0; i < listViewFiles.CheckedItems.Count; i++)
            {
                WavefromData waveData      = new WavefromData();
                string       citFullPath   = "";
                string       indexFilePath = string.Empty;
                try
                {
                    int          directoryIndex = listViewFiles.Columns.Count - 2;
                    int          fileNameIndex  = listViewFiles.Columns.Count - 4;
                    ListViewItem item           = listViewFiles.CheckedItems[i];

                    if (ckbLoadIndex.Checked)
                    {
                        waveData.IsLoadIndex = true;
                    }
                    if (item.SubItems[directoryIndex].Text.EndsWith("\\"))
                    {
                        citFullPath          = item.SubItems[directoryIndex].Text + item.SubItems[fileNameIndex].Text;
                        waveData.CitFilePath = citFullPath;
                        indexFilePath        = item.SubItems[directoryIndex].Text + Path.GetFileNameWithoutExtension(item.SubItems[fileNameIndex].Text) + ".idf";
                    }
                    else
                    {
                        citFullPath          = item.SubItems[directoryIndex].Text + "\\" + item.SubItems[fileNameIndex].Text;
                        waveData.CitFilePath = citFullPath;
                        indexFilePath        = item.SubItems[directoryIndex].Text + "\\" + Path.GetFileNameWithoutExtension(item.SubItems[fileNameIndex].Text) + ".idf";
                    }
                    if (ConfigData.RecentFiles.Files.Contains(citFullPath))
                    {
                        ConfigData.RecentFiles.Files.Remove(citFullPath);
                    }
                    ConfigData.RecentFiles.Files.Insert(0, citFullPath);
                }
                catch (Exception ex)
                {
                    MyLogger.logger.Error("初始化cit文件时失败:" + ex.Message + ",堆栈:" + ex.StackTrace);
                    if (listViewFiles.CheckedItems.Count > 1)
                    {
                        MessageBox.Show("无法解析" + citFullPath + "文件,系统将自动跳过!");
                        continue;
                    }
                    else
                    {
                        MessageBox.Show("无法解析" + citFullPath + ",文件可能已损坏!");
                        return;
                    }
                }
                try
                {
                    waveData.WaveIndexFilePath = indexFilePath;
                }
                catch (Exception ex)
                {
                    MyLogger.logger.Error("初始化索引文件时失败:" + ex.Message + ",堆栈:" + ex.StackTrace);
                    MessageBox.Show(ex.Message);
                }

                if (ConfigData.WaveConfigs.WaveConfigList.Count > 0)
                {
                    WaveConfigDesc waveConfig = ConfigData.WaveConfigs.WaveConfigList.Find(w => w.WaveConfigIndex == (i + 1));
                    if (waveConfig != null)
                    {
                        if (!string.IsNullOrEmpty(waveConfig.WaveConfigFile) && File.Exists(waveConfig.WaveConfigFile))
                        {
                            try
                            {
                                waveData.WaveConfigFilePath = waveConfig.WaveConfigFile;
                            }
                            catch (Exception ex)
                            {
                                MyLogger.LogError("加载波形配置路径错误", ex);
                                MessageBox.Show(ex.Message);
                                waveData.WaveConfigFilePath = string.Empty;
                                waveConfig.WaveConfigFile   = string.Empty;
                            }
                            finally
                            {
                            }
                        }
                    }
                }
                waveDataList.Add(waveData);
            }
            if (waveDataList.Count > 0)
            {
                try
                {
                    ConfigManger.SaveConfigData(ConfigData);
                }
                catch (Exception ex)
                {
                    MyLogger.LogError("保存错误", ex);
                }
                this.Visible = false;
                this.ckbLoadIndex.Checked = false;
                this.listViewFiles.Items.Clear();
                MainForm.sMainform.LoadLayerInfo(waveDataList);
                MainForm.sMainform.Activate();
            }
            else
            {
                MessageBox.Show("请先选择一个Cit文件!");
            }
        }