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 Ex03_5
{
    public partial class Form1 : Form
    {

        string strPath= System.Environment.CurrentDirectory+"\\Image";
        string strInfo = "";
        string[] strName = null;
        int Num = 0;
        int Count = 0;

        public Form1()
        {
            InitializeComponent();
        }

        public void GetAllFiles(DirectoryInfo dir)
        {

            FileSystemInfo[] fileinfo = dir.GetFileSystemInfos();    //定义FileSystemInfo数组
            foreach (FileSystemInfo i in fileinfo)                   //利用Foreach语句提取数组中的数据信息
            {
                if (i is DirectoryInfo)
                {
                    GetAllFiles((DirectoryInfo)i);
                }
                else
                {
                    string str = i.FullName;
                    int b = str.LastIndexOf("\\");
                    string strType = str.Substring(b + 1);
                    if (strType.Substring(strType.Length - 3) == "jpg" || strType.Substring(strType.Length - 3) == "bmp")
                    {
                        strInfo += strType + "#";
                    }
                }
            }
        }

        private void showPic(int X)
        {
            this.pictureBox1.ImageLocation = strPath + "\\" + strName[X];
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            DirectoryInfo dir = new DirectoryInfo(strPath);         //定义DirectoryInfo对象实例
            GetAllFiles(dir);                                       //调用GetAllFiles方法
            if (strInfo != "")
            {
                strName = strInfo.Split('#');
                Num = 0;
                showPic(Num);                                    //调用showPic方法显示第一张图像
                Count = strName.Length - 1;

            }
            else
            {
                MessageBox.Show("影集里没有照片");                //提示信息
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Num -= 1;
            if (Num >= 0)
            {
                showPic(Num);
            }
            else
            {
                Num = Count - 1;
                showPic(Num);
            }   
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Num += 1;
            if (Count > Num)
            {
                showPic(Num);
            }
            else
            {
                Num = 0;
                showPic(Num);
            }
        }


    }
}
