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;

public partial class goods_goodsckcxmx : PageBase
{
    string strgid, adt1, adt2;
    SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["constring"].ConnectionString);

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string strname;
            strgid = Request.QueryString["gid"];
            strname = Request.QueryString["strname"];
            adt1 = Request.QueryString["adt1"];
            adt2 = Request.QueryString["adt2"];
            Label1.Text = strname + adt1 + "至" + adt2 + "出库明细";
            DataBindRePeat();
        }
    }
    private void DataBindRePeat()
    {

        int temp1 = Convert.ToInt32(lblCurrentPage.Text);
        List<goods> Stus = GetTestData();
        Stus = Stus.Skip((temp1 - 1) * 15).Take(15).ToList();
        this.Repeater1.DataSource = Stus;
        this.Repeater1.DataBind();
        int count;
        List<goods> 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<goods> GetTestData()
    {
        string str1, str2;
        int Storageid;
        DateTime adt_1, adt_2;

        str1 = adt1 + " 00:00:00";
        str2 = adt2 + " 23:59:59";
        adt_1 = Convert.ToDateTime(str1);
        adt_2 = Convert.ToDateTime(str2);
        List<goods> stus = new List<goods>();
        try
        {
            string sql = " select * FROM [v_ckcxmx] where date >='" + adt_1 + "' and date <= '" + adt_2 + "'and gid = '" + strgid + "' order by  Date asc ";
            conn.Open();
            SqlCommand cmd = new SqlCommand(sql, conn);
            using (SqlDataReader dr = cmd.ExecuteReader())
            {
                while (dr.Read())
                {
                    goods s = new goods();

                    s.ckdh = ConvertHelper.GetInteger(dr["ckdh"]);
                    s.cksl = ConvertHelper.GetInteger(dr["cksl"]);
                    s.price = ConvertHelper.GetDecimal(dr["Goodprice"]);
                    s.Date = ConvertHelper.GetDateTime(dr["Date"]);
                       s.GoodsName = ConvertHelper.GetString(dr["GoodsName"]);
                    s.PersonnelName = ConvertHelper.GetString(dr["PersonnelName"]);
                    Storageid = ConvertHelper.GetInteger(dr["Storageid"]);
                    s.ckygname = "123";
                    if (Storageid == 1)
                    {
                        s.Storagename = "内部员工";
                    }
                    else

                        if (Storageid == 2)
                        {
                            s.Storagename = "外借";
                        }
                        else

                            if (Storageid == 2)
                            {
                                s.Storagename = "破损";
                            }
                    stus.Add(s);
                }
            }
        }
        catch (Exception)
        {

            throw;
        }
        finally
        {
            conn.Close();
        }
        return stus;
    }

    public class goods
    {
        public int ckdh { get; set; }
        public int cksl { get; set; }
        public string GoodsName { get; set; }
        public string PersonnelName { get; set; }
        public decimal price { get; set; }
        public DateTime Date { get; set; }
        public string Storagename { get; set; }
        public string ckygname { get; set; }
    }
    protected void Button4_Click(object sender, EventArgs e)
    {
        List<goods> Stus = GetTestData();

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

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

        if (temp > 1)
        {
            List<goods> 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<goods> 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<goods> Stus = GetTestData();

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

        this.Repeater1.DataSource = Stus;
        this.Repeater1.DataBind();
        lblCurrentPage.Text = lblPageCount.Text;
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("goodsckcx.aspx");
    }
}