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;

namespace Ex06_8
{
    public partial class Form2 : Form
    {
        public string mystr;
        public Form2()
        {
            InitializeComponent();
        }

        private void btOK_Click(object sender, EventArgs e)
        {
            FileInfo info = new FileInfo(mystr);
            if (info.Exists)
            {
                FileAttributes Attributes = FileAttributes.Normal;
                if (this.chkReadOnly.Checked)
                {
                    Attributes = Attributes | FileAttributes.ReadOnly;

                }
                if (this.chkHidden.Checked)
                {
                    Attributes = Attributes | FileAttributes.Hidden;
                }
                if (this.chkArchive.Checked)
                {
                    Attributes = Attributes | FileAttributes.Archive;
                }
                info.Attributes = Attributes;//最后设置文件的属性
                this.Hide();
            }
        }

        private void Form2_Load(object sender, EventArgs e)
        {
            mystr = this.Text;
            FileInfo info = new FileInfo(mystr);
            this.Text = info.Name + "属性";
            this.txtName.Text = info.Name;
            this.lblLocation.Text = info.Directory.Name;
            this.lblSize.Text = string.Format("{0}字节({1}字节)", info.Length, info.Length);
            this.lblCreatTime.Text = info.CreationTime.ToString("yyyy年MM月dd日, HH:mm:ss");//格式化日期
            this.lblLastWriteTime.Text = info.LastWriteTime.ToString("yyyy年MM月dd日, HH:mm:ss");
            this.lblLastAccessTime.Text = info.LastAccessTime.ToString("yyyy年MM月dd日, HH:mm:ss");
            if ((info.Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
            {
                this.chkReadOnly.Checked = true;
            }
            else
            {
                this.chkReadOnly.Checked = false;
            }
            if ((info.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden)
            {
                this.chkHidden.Checked = true;
            }
            else
            {
                this.chkHidden.Checked = false;
            }
            if ((info.Attributes & FileAttributes.Archive) == FileAttributes.Archive)
            {
                this.chkArchive.Checked = true;
            }
            else
            {
                this.chkArchive.Checked = false;
            }
        }

        private void btCancel_Click(object sender, EventArgs e)
        {
            this.Hide();
        }
    }
}
