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_Rkfs :PageBase
{
    SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["constring"].ConnectionString);
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

            GridViewBin();

        }

    }
    public void GridViewBin()
    {

        int temp1 = Convert.ToInt32(lblCurrentPage.Text);

        List<Goos> Stus = GetTestData();

        Stus = Stus.Skip((temp1 - 1) * 15).Take(15).ToList();
        this.Repeater1.DataSource = Stus;
        this.Repeater1.DataBind();

        string strsql = "select count(*) from tabG_Storage  ";
        SqlCommand cmd = new SqlCommand(strsql, conn);
        int count;
        conn.Open();

        count = Convert.ToInt32(cmd.ExecuteScalar());

        conn.Close();
        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<Goos> GetTestData()
    {
        List<Goos> stus = new List<Goos>();

        try
        {
            string sql = "SELECT * FROM [tabG_Storage] ";
            conn.Open();
            SqlCommand cmd = new SqlCommand(sql, conn);
            using (SqlDataReader dr = cmd.ExecuteReader())
            {
                while (dr.Read())
                {
                    Goos s = new Goos();
                    s.Storageid = ConvertHelper.GetInteger(dr["Storageid"]);
                    s.Storagename = ConvertHelper.GetString(dr["Storagename"]);
                    s.Date = ConvertHelper.GetDateTime(dr["Date"]);
                    s.State = ConvertHelper.GetInteger(dr["State"]);

                    stus.Add(s);
                }
            }
        }
        catch (Exception)
        {

            throw;
        }
        finally
        {
            conn.Close();
        }
        return stus;
    }
    public class Goos
    {
        public int Storageid { get; set; }
        public string Storagename { get; set; }
        public DateTime Date { get; set; }
        public int State { get; set; }
    }
    protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        string strsql;

        string str = e.CommandArgument.ToString();

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


        if (e.CommandName == "Delete")
        {

            if (strid == 0)
            {
                strsql = "update tabG_Storage set State=1 where Storageid='" + Convert.ToInt32(str) + "'";
            }
            else
            {
                strsql = "update tabG_Storage set State=0 where Storageid='" + Convert.ToInt32(str) + "'";
            }

            conn.Open();
            SqlCommand mycmd = new SqlCommand(strsql, conn);
            mycmd.ExecuteNonQuery();
            mycmd.Dispose();
            conn.Close();
            Response.Write("<script>alert('执行成功！')</script>");

            GridViewBin();
        }

        if (e.CommandName == "updateUser")
        {
            string url;
            url = "updaterkfs.aspx?name=" + str;
            Response.Redirect(url);

        }

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

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

        if (temp > 1)
        {
            List<Goos> 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 Button2_Click(object sender, EventArgs e)
    {
        int temp = Convert.ToInt32(this.lblCurrentPage.Text);

        if (temp < Convert.ToInt32(lblPageCount.Text))
        {
            List<Goos> 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 Button1_Click1(object sender, EventArgs e)
    {
        Response.Redirect("newrkfs.aspx");
    }
}
