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.Data.OleDb;

namespace Ex04_3
{
    public partial class Form1 : Form
    {
        
        OleDbConnection Olecon;
        OleDbDataAdapter OleDat;
        DataTable dt;
        int MaxValue = 0;
        int State = 1;
        string ConStr;

        public Form1()
        {
            InitializeComponent();
        }

        private void showInfo(int first, int next)
        {
            dt = new DataTable();
            OleDat = new OleDbDataAdapter("select * from 员工信息", ConStr);
            OleDat.Fill(first, next, dt);
            this.textBox1.Text = dt.Rows[0][1].ToString();
            this.textBox2.Text = dt.Rows[0][2].ToString();
            this.textBox3.Text = dt.Rows[0][3].ToString();
            this.textBox4.Text = dt.Rows[0][4].ToString();
            this.textBox5.Text = dt.Rows[0][5].ToString();
            this.textBox6.Text = dt.Rows[0][6].ToString();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            showInfo(0, 1);          
            State = 1;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            string strPath = Application.StartupPath + "\\Mydata.accdb";
            ConStr = "Provider=Microsoft.ACE.OLEDB.12.0; Data source=" + strPath;
            Olecon = new OleDbConnection(ConStr);
            Olecon.Open();
            MaxValue = Convert.ToInt32(new OleDbCommand("select Count(*) from 员工信息", Olecon).ExecuteScalar());
            Olecon.Close();
            showInfo(0, 1);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (State <= 1)
            {
                MessageBox.Show("已经是第一条记录", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                showInfo(State - 1, State);
                State = State - 1;
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (State >= MaxValue)
            {
                MessageBox.Show("已经是最后一条记录", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                showInfo(State, State + 1);
                State = State + 1;
            }     
        }

        private void button4_Click(object sender, EventArgs e)
        {
            showInfo(MaxValue - 1, MaxValue);
            State = MaxValue;
        }

        private void button5_Click(object sender, EventArgs e)
        {
            this.Close();  
        }
    }
}
