Ejemplo n.º 1
0
 /// <summary>
 /// 按delete键时删除访问列表中的项
 /// </summary>
 /// <param name="sender">触发对象</param>
 /// <param name="e">事件参数</param>
 private void treePathAndMedia_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
 {
     try
     {
         if (e.KeyCode == Keys.Delete)
         {
             if (treePathAndMedia.SelectedNode.Index > 1 &&
                 treePathAndMedia.SelectedNode.Index < treePathAndMedia.Nodes.Count - 1)
             {
                 Node node = treePathAndMedia.Nodes[treePathAndMedia.SelectedNode.Index];
                 if (node != null)
                 {
                     string nodePath = node.Tag.ToString();
                     treePathAndMedia.Nodes.Remove(node);
                     ConfigData.DirPaths.PathList.Remove(nodePath);
                     ConfigManger.SaveConfigData(ConfigData);
                 }
             }
             else
             {
                 MessageBox.Show("无法删除目录或媒体库");
             }
         }
     }
     catch (Exception ex)
     {
         MyLogger.logger.Error("删除节点出错:" + ex.Message + ",堆栈:" + ex.StackTrace);
         MessageBox.Show("删除节点出错:" + ex.Message);
     }
 }
 private void tsmiOpenPathOrMedia_Click(object sender, EventArgs e)
 {
     if (folderDialog.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
     {
         _configData.DirPaths.PathList.Add(folderDialog.SelectedPath);
         ConfigManger.SaveConfigData(_configData);
         OpenFileForm form = new OpenFileForm(_configData);
         form.ShowDialog();
     }
 }
        /// <summary>
        /// 台帐选择显示方式
        /// </summary>
        /// <param name="sender">点击按钮(包括:曲线,坡度,道岔,速度区段)</param>
        /// <param name="e"></param>
        private void tsmiAccountDisplayMode_Click(object sender, EventArgs e)
        {
            ToolStripMenuItem item = sender as ToolStripMenuItem;

            item.Checked = !item.Checked;
            for (int i = 0; i < _configData.Accouts.AcountList.Count; i++)
            {
                if (_configData.Accouts.AcountList[i].Name.Contains(item.Text))
                {
                    _configData.Accouts.AcountList[i].IsCheck = item.Checked;
                    break;
                }
            }
            ConfigManger.SaveConfigData(_configData);
        }
 private void tsmiOpenFile_Click(object sender, EventArgs e)
 {
     if (fileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
     {
         foreach (var file in fileDialog.FileNames)
         {
             _configData.RecentFiles.Files.Insert(0, file);
         }
         ConfigManger.SaveConfigData(_configData);
         OpenFileForm form = new OpenFileForm(_configData);
         if (form.ShowDialog() == System.Windows.Forms.DialogResult.OK)
         {
             _fileInfoList = form.Tag as List <FileInformation>;
         }
     }
 }
 private void MainForm_Load(object sender, EventArgs e)
 {
     progressBar.Visible        = false;
     ConfigManger.ConfigPath    = Application.StartupPath + @"\config.xml";
     _configData                = ConfigManger.GetConfigData();
     DBOperator.DBConnectString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Application.StartupPath + "\\InnerDB.idf;Persist Security Info=True;Mode=Share Exclusive;Jet OLEDB:Database Password=iicdc;";
     //_configData.WaveConfigs.WaveConfigCount = 10;
     _configData.RecentFiles.FilesCount = 10;
     if (!string.IsNullOrEmpty(_configData.MediaPath) ||
         (_configData.RecentFiles.Files != null &&
          _configData.RecentFiles.Files.Count > 0) ||
         _configData.DirPaths.PathList.Count > 0)
     {
         OpenFileForm form = new OpenFileForm(_configData);
         if (form.ShowDialog() == System.Windows.Forms.DialogResult.OK)
         {
             progressBar.Visible = true;
             _fileInfoList       = form.Tag as List <FileInformation>;
         }
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// 点击确定按钮,保存数据
        /// </summary>
        /// <param name="sender">确定按钮</param>
        /// <param name="e">触发参数</param>
        private void btnOk_Click(object sender, EventArgs e)
        {
            try
            {
                _configData.ServerConfig       = _networkControl.ServerConfig;
                _configData.MeterageRadius     = _commonControl.MeterageRadius;
                _configData.MediaPath          = _commonControl.MediaPath;
                _configData.SignRadius         = _commonControl.SignRadius;
                _configData.AutoScrollVelocity = _commonControl.AutoScrollVelocity;
                _configData.WaveConfigs        = _waveDisplayControl.WaveConfigs;
                if (_standard.StandardChangedList != null && _standard.StandardChangedList.Count > 0)
                {
                    foreach (var item in _standard.StandardChangedList)
                    {
                        string cmd = String.Format("update 大值国家标准表 set VALUEDIY={0} where speed = {1} and class = {2} and type = '{3}' and STANDARDTYPE = {4}",
                                                   item.StdValue, item.Speed, item.StdClass, item.StdParam, item.stdType);
                        InnerFileOperator.ExcuteSql(cmd);
                    }
                }
                //for (int i = 0; i < _standardControl.dtStandardValue.Rows.Count; i++)
                //{
                //    string cmd = String.Format("update 大值国家标准表 set VALUEDIY={0},VALUESTANDARD={1} where ID = {2}",
                //        _standardControl.dtStandardValue.Rows[i][5].ToString(),
                //        _standardControl.dtStandardValue.Rows[i][4].ToString(),
                //        _standardControl.dtStandardValue.Rows[i][0].ToString());

                //    InnerFileOperator.ExcuteSql(cmd);
                //}
                ConfigManger.SaveConfigData(_configData);
            }
            catch (Exception ex)
            {
                MyLogger.logger.Error("保存配置失败:" + ex.Message + ",堆栈:" + ex.StackTrace);
                MessageBox.Show("错误:" + ex.Message);
            }
            finally
            {
                this.Close();
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 加载树结构数据
        /// </summary>
        public void LoadTreeData()
        {
            try
            {
                treePathAndMedia.Nodes.Clear();
                List <string> nodes = new List <string>()
                {
                    "添加更多...", "波形库", "最近打开的文件"
                };
                dockContainerItem1.Text = "波形库";

                treePathAndMedia.BeginUpdate();
                //初始化根节点
                foreach (var s in nodes)
                {
                    Node node = new Node(s);
                    treePathAndMedia.Nodes.Add(node);
                }

                if (ConfigData != null)
                {
                    //初始化媒体库
                    if (!string.IsNullOrEmpty(ConfigData.MediaPath))
                    {
                        if (Directory.Exists(ConfigData.MediaPath))
                        {
                            //Node mediaFilesNode = new Node();
                            treePathAndMedia.Nodes[1].Nodes.AddRange(GetFiles(ConfigData.MediaPath, _fileFilter));
                            //treePathAndMedia.Nodes[1].Nodes.Add(mediaFilesNode);
                        }
                    }
                    //初始化目录节点
                    if (ConfigData.DirPaths.PathList.Count > 0)
                    {
                        List <string> noExistDir = new List <string>();
                        foreach (string dir in ConfigData.DirPaths.PathList)
                        {
                            if (Directory.Exists(dir))
                            {
                                Node          dirFilesNode = new Node();
                                DirectoryInfo folder       = new DirectoryInfo(dir);
                                dirFilesNode.Text = folder.Name;
                                dirFilesNode.Tag  = folder.FullName;
                                string[] files = Directory.GetFiles(dir, _fileFilter, SearchOption.TopDirectoryOnly);
                                foreach (string file in files)
                                {
                                    Node     chldNode    = new Node();
                                    string[] splitString = file.Split('\\');
                                    chldNode.Text = splitString[splitString.Length - 1];
                                    chldNode.Tag  = file;
                                    dirFilesNode.Nodes.Add(chldNode);
                                }
                                Node loadingNode = new Node();
                                loadingNode.Text = "加载子目录....";
                                //loadingNode.ImageExpanded= Image.FromFile("blue-loading.gif");
                                //loadingNode.Image = Image.FromFile("blue-loading.gif");
                                //loadingNode.Tag = "loading";
                                dirFilesNode.Nodes.Add(loadingNode);
                                treePathAndMedia.Nodes.Insert(2, dirFilesNode);
                            }
                            else
                            {
                                noExistDir.Add(dir);
                            }
                        }
                        if (noExistDir.Count > 0)
                        {
                            MyLogger.logger.Info("有:" + noExistDir.Count + "条目录不存在,准备删除");
                            foreach (var item in noExistDir)
                            {
                                MyLogger.logger.Info("删除目录:" + item);
                                ConfigData.DirPaths.PathList.Remove(item);
                            }
                            ConfigManger.SaveConfigData(ConfigData);
                        }
                    }
                    //初始化最近访问列表
                    if (ConfigData.RecentFiles.Files.Count > 0)
                    {
                        Node dirFilesNode = treePathAndMedia.Nodes[treePathAndMedia.Nodes.Count - 1];
                        //最近访问的文件个数小于配置中的个数
                        if (ConfigData.RecentFiles.Files.Count > ConfigData.RecentFiles.FilesCount)
                        {
                            for (int i = 0; i < ConfigData.RecentFiles.FilesCount; i++)
                            {
                                string[] split    = ConfigData.RecentFiles.Files[i].Split('\\');
                                Node     fileNode = new Node(split[split.Length - 1])
                                {
                                    Tag = ConfigData.RecentFiles.Files[i]
                                };
                                dirFilesNode.Nodes.Add(fileNode);
                            }
                        }
                        else
                        {
                            foreach (var file in ConfigData.RecentFiles.Files)
                            {
                                string[] split    = file.Split('\\');
                                Node     fileNode = new Node(split[split.Length - 1])
                                {
                                    Tag = file
                                };
                                dirFilesNode.Nodes.Add(fileNode);
                            }
                        }
                        //if (IsDirectLoad)
                        //{
                        //    CheckNodeAndLoad(dirFilesNode.Nodes[0]);
                        //}
                    }
                }
                treePathAndMedia.Nodes[treePathAndMedia.Nodes.Count - 1].Expand();
                Node addMoreNode = treePathAndMedia.Nodes[0];
                addMoreNode.Nodes.Add(new Node("添加文件"));
                addMoreNode.Nodes.Add(new Node("添加文件夹"));
                addMoreNode.Expanded = false;
                treePathAndMedia.EndUpdate();
            }
            catch (Exception ex)
            {
                MyLogger.logger.Error("初始化目录失败:" + ex.Message + ",堆栈:" + ex.StackTrace);
                MessageBox.Show("加载目录失败:" + ex.Message);
            }
        }
Ejemplo n.º 8
0
 /// <summary>
 /// 检查节点的文件并加载
 /// </summary>
 /// <param name="node">选择的文件节点</param>
 private void CheckNodeAndLoad(Node node)
 {
     if (node.Level < 1)
     {
         return;
     }
     if (node.Tag == null)
     {
         if (node.Text == "添加文件")
         {
             MainForm.sMainform.tsmiOpenFile_Click(null, null);
         }
         else if (node.Text == "添加文件夹")
         {
             MainForm.sMainform.tsmiOpenPathOrMedia_Click(null, null);
         }
         else
         {
             node.Text          = "";
             node.HostedControl = labLoading;
             labLoading.Visible = true;
             Task <Node[]> t = Task.Factory.StartNew <Node[]>(new Func <Node[]>(() => { return(GetSubFiles(node.Parent.Tag.ToString(), _fileFilter)); }));
             t.ContinueWith(new Action <Task <Node[]> >((task) =>
             {
                 this.Invoke(new Action(() =>
                 {
                     labLoading.Visible = false;
                     Node parentNode    = node.Parent;
                     parentNode.Nodes.Remove(node);
                     parentNode.Nodes.AddRange(t.Result);
                 }));
             }));
         }
     }
     else if (File.Exists(node.Tag.ToString()))
     {
         for (int i = 0; i < listViewFiles.Items.Count; i++)
         {
             int    directoryIndex = listViewFiles.Columns.Count - 2;
             int    fileNameIndex  = listViewFiles.Columns.Count - 4;
             string existFilePath  = string.Empty;
             if (listViewFiles.Items[i].SubItems[directoryIndex].Text.EndsWith("\\"))
             {
                 existFilePath = listViewFiles.Items[i].SubItems[directoryIndex].Text + listViewFiles.Items[i].SubItems[fileNameIndex].Text;
             }
             else
             {
                 existFilePath = listViewFiles.Items[i].SubItems[directoryIndex].Text + "\\" + listViewFiles.Items[i].SubItems[fileNameIndex].Text;
             }
             if (node.Tag.ToString() == existFilePath)
             {
                 node.Tooltip = "文件已经添加完毕";
                 return;
             }
         }
         DisplayInListview(node.Tag.ToString());
     }
     else if (node.Parent.Index > 1)
     {
         if (MessageBox.Show("文件不存在,是否从列表中移除?", "提示", MessageBoxButtons.OKCancel) == DialogResult.OK)
         {
             bool isSave = false;
             if (node.Parent.Index != 0)
             {
                 //最近访问列表移除该项
                 if (node.Parent.Index == treePathAndMedia.Nodes.Count - 1)
                 {
                     int index = node.Parent.Nodes.IndexOf(node);
                     node.Parent.Nodes.Remove(node);
                     ConfigData.RecentFiles.Files.Remove(node.TagString);
                     isSave = true;
                 }
                 else
                 {
                     //检查目录个数,如果就一个文件,移除该目录,需要保存配置
                     if (node.Parent.Nodes.Count > 1)
                     {
                         node.Parent.Nodes.Remove(node);
                     }
                     else
                     {
                         treePathAndMedia.Nodes.Remove(node.Parent);
                         isSave = true;
                     }
                 }
             }
             else
             {
                 //媒体库只是移除该项
                 node.Parent.Nodes.Remove(node);
             }
             if (isSave)
             {
                 try
                 {
                     ConfigManger.SaveConfigData(ConfigData);
                 }
                 catch (Exception ex)
                 {
                     MyLogger.logger.Error("保存配置数据时失败:" + ex.Message + ",堆栈:" + ex.StackTrace);
                 }
             }
         }
     }
 }
Ejemplo n.º 9
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文件!");
            }
        }