using LibraryMangementSystem.Dao;

using System;

using System.Data;

using System.Windows.Forms;

namespace LibraryMangementSystem.StatisticData
{
    public partial class StatisticCount : Form
    {
        public StatisticCount()
        {
            InitializeComponent();
            
        }
        LibraryEntities1 library = new LibraryEntities1();
        private void tabControl1_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (tabControl13.SelectedIndex == 0)//也可以判断tabControl1.SelectedTab.Text的值
            {

                //执行相应的操作
                BookByClaa(sender, e);

            }
            else if (tabControl13.SelectedIndex == 1)

            {

                //执行相应的操作  库存与类别比例
                BorrowAndStockRate(sender, e);

            } else if (tabControl13.SelectedIndex == 2) {
                PopularBooksStatistics(sender, e);


            }

        }


        private void BookByClaa(object sender, EventArgs e) {
            string sql = "select a.ClassID,a.Classname,count(*) as CountNum from bookclass a,bookInfo  b where a.ClassID=b.ClassID GROUP BY a.ClassID,a.Classname";
            DaoUtil dao = new DaoUtil();
            IDataReader result = dao.Reader(sql);
            dataGridView_byClass.Rows.Clear();
            //取消dataGridView取消最后一行空白行
            dataGridView_byClass.AllowUserToAddRows = false;
            while (result.Read()) {
                dataGridView_byClass.Rows.Add(result["ClassID"].ToString().Trim(), result["Classname"].ToString().Trim(), result["CountNum"].ToString().Trim());
                 
             }

             
            /*ResultByClass r=DataConvert.ToEntity<ResultByClass>(result);*/

            /*List<ResultByClass> BookByClassList = DataConvert.ToEntityList<ResultByClass>(result);*/
            
            /*MessageBox.Show(r.CountNum);*/
           /* foreach (ResultByClass result1 in BookByClassList)
            {
                *//*MessageBox.Show(result1.Count_num.Trim());*//*
                dataGridView_byClass.Rows.Add(result1.ClassID.Trim(), result1.Classname.Trim(), result1.Count_num);
            }*/
            dao.DaoClose();
        }


        private void BorrowAndStockRate(object sender, EventArgs e) {
            string sql = "select * from BorrowAndStockRate";
            DaoUtil dao = new DaoUtil();
            IDataReader result = dao.Reader(sql);
            dataGridView_rate.Rows.Clear();
            //取消dataGridView取消最后一行空白行
            dataGridView_rate.AllowUserToAddRows = false;
            while (result.Read())
            {
                dataGridView_rate.Rows.Add(result["borrowSum"].ToString().Trim(), result["stockSum"].ToString().Trim(), result["rate"].ToString().Trim()+"%");

            }
            dao.DaoClose();
        }
        private void PopularBooksStatistics(object sender, EventArgs e)
        {
            string sql = "select * from PopularBooksStatistics ORDER BY borrowOnce desc";
            DaoUtil dao = new DaoUtil();
            IDataReader result = dao.Reader(sql);
            dataGridView_hot.Rows.Clear();
            //取消dataGridView取消最后一行空白行
            dataGridView_hot.AllowUserToAddRows = false;
            while (result.Read())
            {
                dataGridView_hot.Rows.Add(result["bookid"].ToString().Trim(), result["Title"].ToString().Trim(), result["borrowOnce"].ToString().Trim());

            }
            dao.DaoClose();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            ChartDisplay chartDisplay= new ChartDisplay();
            chartDisplay.Show();
        }
    }
}
