/// <summary> /// 保存通道配置信息 /// </summary> /// <param name="sFileName">配置文件路径</param> /// <param name="channelList">通道配置信息集合</param> public static void SaveChannelsConfig(string sFileName, List <ChannelsClass> channelList) { try { XmlDocument xd = new XmlDocument(); xd.Load(sFileName); XmlNodeList xnl = xd.DocumentElement["channels"].ChildNodes; for (int i = 0; i < xnl.Count; i++) { //保存配置文件 string name = xnl[i].Attributes["name"].InnerText.ToLower(); for (int j = 0; j < channelList.Count; j++) { if (channelList[j].NonChineseName.ToLower().Equals(name)) { xnl[i].Attributes["non-chinese_name"].Value = channelList[j].NonChineseName; xnl[i].Attributes["chinese_name"].Value = channelList[j].ChineseName; xnl[i].Attributes["color"].Value = channelList[j].Color.ToString("x"); xnl[i].Attributes["visible"].Value = channelList[j].IsVisible.ToString(); xnl[i].Attributes["zoomin"].Value = channelList[j].ZoomIn.ToString(); xnl[i].Attributes["mea-offset"].Value = channelList[j].IsMeaOffset.ToString(); xnl[i].Attributes["line_width"].Value = channelList[j].LineWidth.ToString(); xnl[i].Attributes["location"].Value = channelList[j].Location.ToString(); break; } } } xd.Save(sFileName); } catch (Exception ex) { MyLogger.LogError("保存通道配置时出错", ex); throw new Exception(ex.Message); } }
/// <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文件!"); } }