using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Collections.Generic;

public partial class goods_goodrkcl : PageBase
{
    SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["constring"].ConnectionString);

    protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {


            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()
    {
        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 [Rkdh], [Storagename], [PersonnelName],  [Rkbz], [state],[date] FROM [v_goodsrk01] where date >='" + adt1 + "' and date <= '" + adt2 + "'order by Rkdh asc ";
            conn.Open();
            SqlCommand cmd = new SqlCommand(sql, conn);
            using (SqlDataReader dr = cmd.ExecuteReader())
            {
                while (dr.Read())
                {
                    department s = new department();

                    s.Rkdh = ConvertHelper.GetInteger(dr["Rkdh"]);
                    s.Storagename = ConvertHelper.GetString(dr["Storagename"]);
                    s.PersonnelName = ConvertHelper.GetString(dr["PersonnelName"]);
                    s.Rkbz = ConvertHelper.GetInteger(dr["Rkbz"]);
                    s.state = ConvertHelper.GetInteger(dr["state"]);
                    s.Date = ConvertHelper.GetDateTime(dr["date"]);
                    stus.Add(s);
                }
            }
        }
        catch (Exception)
        {

            throw;
        }
        finally
        {
            conn.Close();
        }
        return stus;
    }
    public class department
    {
        public int Rkdh { get; set; }
        public string Storagename { get; set; }
        public string PersonnelName { get; set; }
        public int Rkbz { 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 = "checkrkcl.aspx?rkdh=" + strid;

                Response.Redirect(url);
            }

            else
            {

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

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

            url = "detailedrkcl.aspx?rkdh=" + strid;

            Response.Redirect(url);
        }

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

        Response.Redirect("newrkcl.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();
    }
}
