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.SqlClient;

namespace Ex04_9
{
    public partial class Form1 : Form
    {

        public static int INum = 0;
        public static int AllCount = 0;
        int Sizes = 3;

        private void show(int i, int j)
        {
            SqlConnection con = new SqlConnection("server=(local);user id=myzf;pwd=123456;database=MysqlData");
            SqlDataAdapter daone = new SqlDataAdapter("select * from 应付账", con);
            DataSet dsone = new DataSet();
            daone.Fill(dsone, i, j, "one");
            this.dataGridView1.DataSource = dsone.Tables["one"].DefaultView;
            dsone = null;
        }

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            using (SqlConnection con = new SqlConnection("server=(local);user id=myzf;pwd=123456;database=MysqlData"))
            {
                SqlDataAdapter da = new SqlDataAdapter("select * from 应付账", con);
                DataTable dt = new DataTable();
                da.Fill(dt);
                int i = dt.Rows.Count;
                AllCount = i;
                int m = i % Sizes;
                if (m == 0)
                {
                    m = i / Sizes;
                }
                else
                {
                    m = i / Sizes + 1;
                }
                this.label2.Text = m.ToString();
                this.label5.Text = "1";
                show(0, 3);
            }
        }

        private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            this.dataGridView1.DataSource = null;
            int m = Convert.ToInt16(this.label5.Text) - 1;
            if (m < 1)
            {
                this.label5.Text = "1";
            }
            else
            {
                this.label5.Text = m.ToString();
            }
            int a = Convert.ToInt16(this.label5.Text) * 3 - 3;
            show(a, 3); 
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            this.dataGridView1.DataSource = null;
            this.label5.Text = "1";
            show(0, Convert.ToInt16(this.label5.Text) * 3);
        }

        private void linkLabel3_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            this.dataGridView1.DataSource = null;
            int m = Convert.ToInt16(this.label5.Text) + 1;
            if (m > Convert.ToInt16(this.label2.Text))
            {
                this.label5.Text = this.label2.Text;
            }
            else
            {
                this.label5.Text = m.ToString();
            }
            int a = Convert.ToInt16(this.label5.Text) * 3 - 3;
            show(a, 3); 
        }

        private void linkLabel4_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            this.label5.Text = this.label2.Text;
            this.dataGridView1.DataSource = null;
            show(Convert.ToInt16(this.label5.Text) * 3 - 3, AllCount - 1);
        }
    }
}
