using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
//www.51aspx.com
public partial class goods_goodssqrk :PageBase
{
    SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["constring"].ConnectionString);
    string struer;

    protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {
            struer = Session["uid"].ToString();
            string strtime2 = DateTime.Now.ToString("yyyy-MM-dd");
            string strtime1 = DateTime.Now.ToString("yyyy-MM");
            strtime1 = strtime1 + "-01";
            TextBox1.Text = strtime1;
            TextBox2.Text = strtime2;
            DataBindRePeat();
        }

    }
    private void DataBindRePeat()
    {
        int temp1 = Convert.ToInt32(lblCurrentPage.Text);

        List<department> Stus = GetTestData();
        Stus = Stus.Skip((temp1 - 1) * 15).Take(15).ToList();
        this.Repeater1.DataSource = Stus;
        this.Repeater1.DataBind();

        int count;

        List<department> Stu = GetTestData();
        count = ConvertHelper.GetInteger(Stu.Count());

        int j = count / 15;
        int i = count % 15;
        if (j >= 1)
        {
            if (i > 0)
            {
                j = j + 1;
            }

        }
        else
        {
            j = 1;

        }

        lblPageCount.Text = j.ToString();
    }
    private List<department> GetTestData()
    {
        struer = Session["uid"].ToString();
        string str1, str2;
        DateTime adt1, adt2;

        str1 = TextBox1.Text + " 00:00:00";

        str2 = TextBox2.Text + " 23:59:59";

        adt1 = Convert.ToDateTime(str1);
        adt2 = Convert.ToDateTime(str2);
        List<department> stus = new List<department>();

        try
        {
            string sql = "SELECT * FROM [v_sq01] where date >='" + adt1 + "' and date <= '" + adt2 + "' and ckygid = '" + struer + "' order by ckdh asc ";
            conn.Open();
            SqlCommand cmd = new SqlCommand(sql, conn);
            using (SqlDataReader dr = cmd.ExecuteReader())
            {
                while (dr.Read())
                {
                    department s = new department();
                    s.ckdh = ConvertHelper.GetInteger(dr["ckdh"]);
                    s.PersonnelName = ConvertHelper.GetString(dr["PersonnelName"]);

                    s.ckbz = ConvertHelper.GetInteger(dr["ckbz"]);
                    s.Date = ConvertHelper.GetDateTime(dr["date"]);
                    stus.Add(s);
                }
            }
        }
        catch (Exception)
        {

            throw;
        }
        finally
        {
            conn.Close();
        }
        return stus;
    }
    public class department
    {
        public int ckdh { get; set; }
        public string Storagename { get; set; }
        public string PersonnelName { get; set; }
        public int ckbz { get; set; }
        public int state { get; set; }
        public DateTime Date { get; set; }

    }


    protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
    {

        int str = Convert.ToInt32(e.CommandArgument.ToString());
        string strid = (e.Item.FindControl("HiddenField1") as HiddenField).Value;

        string url;
        url = "";
        if (e.CommandName == "Delete")
        {
            if (str == 0)
            {

                url = "checksqcl.aspx?ckdh=" + strid;

                Response.Redirect(url);
            }

            else
            {

                Response.Write("<script>alert('已审核通过！')</script>");
            }

        }
        if (e.CommandName == "detaileduser")
        {

            url = "goodssqmx.aspx?ckdh=" + strid;

            Response.Redirect(url);
        }

    }
    protected void Button2_Click(object sender, EventArgs e)
    {

        Response.Redirect("newrksq.aspx");
    }
    protected void Button6_Click(object sender, EventArgs e)
    {

        int temp = Convert.ToInt32(this.lblCurrentPage.Text);

        if (temp > 1)
        {
            List<department> Stus = GetTestData();

            this.lblCurrentPage.Text = (--temp).ToString();

            Stus = Stus.Skip((temp - 1) * 15).Take(15).ToList();

            this.Repeater1.DataSource = Stus;
            this.Repeater1.DataBind();
        }
    }
    protected void Button7_Click(object sender, EventArgs e)
    {
        int temp = Convert.ToInt32(this.lblCurrentPage.Text);

        if (temp < Convert.ToInt32(lblPageCount.Text))
        {
            List<department> Stus = GetTestData();
            this.lblCurrentPage.Text = (++temp).ToString();

            Stus = Stus.Skip((temp - 1) * 15).Take(15).ToList();

            this.Repeater1.DataSource = Stus;
            this.Repeater1.DataBind();
        }
    }
    protected void Button8_Click(object sender, EventArgs e)
    {
        int intendpage = Convert.ToInt32(lblPageCount.Text);

        List<department> Stus = GetTestData();

        Stus = Stus.Skip((intendpage - 1) * 15).Take(15).ToList();

        this.Repeater1.DataSource = Stus;
        this.Repeater1.DataBind();
        lblCurrentPage.Text = lblPageCount.Text;
    }
    protected void Button4_Click(object sender, EventArgs e)
    {

        List<department> Stus = GetTestData();

        Stus = Stus.Skip(0).Take(15).ToList();

        this.Repeater1.DataSource = Stus;
        this.Repeater1.DataBind();
        lblCurrentPage.Text = "1";
    }
    protected void Btncx_Click(object sender, EventArgs e)
    {
        DataBindRePeat();
    }
}
