Newer
Older
GHFX_REFACTOR / FrmMetadataOutput.cs
wxn on 2 Nov 2016 3 KB 提交
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using DevComponents.DotNetBar;
using System.Xml.Linq;

namespace Cyberpipe
{
    public partial class FrmMetadataOutput : Office2007Form
    {
        XDocument l_doc;
        string filename;
        public FrmMetadataOutput(XDocument doc,string titlename)
        {
            InitializeComponent();

            l_doc = doc;
            filename = titlename;
        } 
        string dir_Ok = "";
        private void FrmMetadataOutput_Load(object sender, EventArgs e)
        {
            Drive_Name(CMB_MDout);
        }

        public void Drive_Name(ComboBox Cbm)
        {
            Cbm.Items.Clear();
            DriveInfo[] myAllDrives = DriveInfo.GetDrives();
            foreach (DriveInfo myDrive in myAllDrives)//循环写入每个磁盘的参数
            {
                if (myDrive.IsReady)
                {
                    Cbm.Items.Add(myDrive.Name);
                }
            }
        }

        private void OK_Click(object sender, EventArgs e)
        {
            if (dir_Ok == "")
                dir_Ok = CMB_MDout.Text;
             
            l_doc.Save(dir_Ok + "//"+filename+"元数据.xml");
            DialogResult = DialogResult.OK;//将当前窗体的对话框返回值设为OK
        }

        private void CMB_MDout_TextChanged(object sender, EventArgs e)
        {
            SubForders(((ComboBox)sender).Text, TV_MDout, new TreeNode(""));
        }

        public void SubForders(string dir, TreeView TV, TreeNode node)
        {
            int n = 0;
            try
            {
                DirectoryInfo directoryInfo = new DirectoryInfo(dir);
                TreeNode SelectNode = new TreeNode();
                if (dir.Length <= 3)
                {
                    TV.Nodes.Clear();
                    foreach (DirectoryInfo childDirectoryInfo in directoryInfo.GetDirectories())
                    {
                        TreeNode SubNode = new TreeNode(childDirectoryInfo.Name.ToString());
                        SubNode.ImageIndex = 0;
                        TV.Nodes.Add(SubNode);
                        SubNode.Nodes.Add(new TreeNode(""));
                    }
                }
                else
                {
                    SelectNode = TV.SelectedNode;
                    if (TV.SelectedNode == null)
                        SelectNode = node;
                    SelectNode.Nodes.Clear();
                    foreach (DirectoryInfo childDirectoryInfo in directoryInfo.GetDirectories())
                    {
                        TreeNode SubNode = new TreeNode(childDirectoryInfo.Name.ToString());
                        SubNode.ImageIndex = 0;
                        SelectNode.Nodes.Add(SubNode);
                        SubNode.Nodes.Add(new TreeNode(""));
                        n = 1;
                    }
                }
                if (n == 0)
                    SelectNode.ImageIndex = 0;
            }
            catch (Exception ex) { }


        }
         
        private void TV_MDout_AfterExpand(object sender, TreeViewEventArgs e)
        {
            e.Node.ImageIndex = 1;
            SubForders(CMB_MDout.Text + e.Node.FullPath, TV_MDout, e.Node);
        }

        private void TV_MDout_AfterCollapse(object sender, TreeViewEventArgs e)
        {
            e.Node.ImageIndex = 0;
        } 

        private void TV_MDout_NodeMouseClick_1(object sender, TreeNodeMouseClickEventArgs e)
        {
            dir_Ok = CMB_MDout.Text + e.Node.FullPath;
            //dir = comboBox_Disk.Text + e.Node.FullPath; 
            e.Node.SelectedImageIndex = e.Node.ImageIndex;
        }
    }
}