private void btnOpen_Click(object sender, EventArgs e)
        {
            OpenDirectoryDialog dlg = new OpenDirectoryDialog();

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                this.textBox1.Text = dlg.SelectedPath;
            }
        }
Пример #2
0
        private void btnOpenDirectory_Click(object sender, EventArgs e)
        {
            if (_changed)
            {
                if (MessageBox.Show("当前所做的修改还没有保存,如果继续,那么所做的修改将会丢失,确定还要继续吗?",
                                    this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                {
                    return;
                }
            }


            OpenDirectoryDialog dlg = new OpenDirectoryDialog();

            if (dlg.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            // 停止对目录的监控
            fileSystemWatcher1.EnableRaisingEvents = false;


            string selectedPath = dlg.SelectedPath;

            treeView1.BeginUpdate();
            treeView1.Nodes.Clear();

            try {
                LoadCommands(selectedPath);

                labCurrentPath.Text = selectedPath;
                RegisterHelper.SafeWrite("XmlCommandFilePath", selectedPath);
                _currentPath = selectedPath;


                _changed = false;
                _deletedFiles.Clear();
                txtSQL.Text = string.Empty;
                txtXML.Text = string.Empty;

                RefreshUI();
                treeView1.Focus();

                // 重新开始监控目录
                _fileChangedDialog.ClearFiles();
                fileSystemWatcher1.Path = selectedPath;
                fileSystemWatcher1.EnableRaisingEvents = true;
            }
            catch (Exception ex) {
                MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
            finally {
                treeView1.EndUpdate();
            }
        }