using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Product;
using Base;

public partial class member_Trade_PurchaseManage : nspBase.MemberBasePge
{
    string verify="";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (CheckCookies())
        {
            if (!IsPostBack)
            {
                Bind();
            }
        }
        else
            Response.Redirect("../login/login.aspx");

    }

    private void Bind()
    {
        try
        {
            int Userid = int.Parse(GetCookie("UserID"));
            if (Userid > 0)
            {
                int PageIndex = 0;
                if (HttpContext.Current.Request.QueryString["page"] != null)
                    PageIndex = Convert.ToInt32(Request.QueryString["Page"].ToString());
                if (PageIndex <= 0) PageIndex = 1;
                string strWhere = " UserID=" + Userid;
                if (verify == "")
                {
                    verify = "1";
                }
                if (Request.QueryString["Verify"] != null && Request.QueryString["Verify"] != "")
                {

                    if (Request.QueryString["Verify"] == "4")//过期信息
                    {
                        strWhere += " and (datediff(hh,EndDate,getdate())>0)";
                    }
                    else if (Request.QueryString["Verify"] == "2")//审核未通过
                    {
                        strWhere += " and Verify =";
                        strWhere += Request.QueryString["Verify"];
                    }
                    else if (Request.QueryString["Verify"] == "3")//审核中信息
                    {
                        strWhere += " and Verify =";
                        strWhere += Request.QueryString["Verify"];
                    }
                    else //已发布上网
                    {
                        strWhere += " and (datediff(hh,EndDate,getdate())<0) and Verify =";
                        strWhere += Request.QueryString["Verify"];
                    }
                    verify = Request.QueryString["Verify"];
                }
                else //默认进入已发布上网
                {
                    strWhere += " and Verify =1 and (datediff(hh,EndDate,getdate())<0)";

                }
                DataTable Lists = PageList.GetDataTable(strWhere, "C_Purchase", 1, "AddDate", "*", 10, PageIndex, 0);
                dlstPurchase.DataSource = Lists.DefaultView;
                dlstPurchase.DataBind();
                this.Pagin.Text = PageList.GoToPager(PageIndex, 10, "PurchaseManage.aspx?Verify=" + verify + "&page", strWhere, "C_Purchase");
                btnDelete.Attributes.Add("onclick", "javascript:return confirm('你确认要删除吗?')");
                SetColor();
            }
            else
                Response.Redirect("../login/login.aspx");
        }
        catch (Exception ex)
        {
            ShowMessage(ex.Message);
        }
    }


    /// <summary>
    /// 设置颜色
    /// </summary>
    private void SetColor()
    {
        if (Request.QueryString["Verify"] != null)
        {
            if (Request.QueryString["Verify"] == "3")
                this.menu2.Attributes.Add("class", Request.QueryString["class"]);
            else if (Request.QueryString["Verify"] == "2")
                this.menu3.Attributes.Add("class", Request.QueryString["class"]);
            else if (Request.QueryString["Verify"] == "4")
                this.menu4.Attributes.Add("class", Request.QueryString["class"]);
            else
                this.menu1.Attributes.Add("class", Request.QueryString["class"]);
        }
        else
            this.menu1.Attributes.Add("class", "MenuLiCheck");
    }

    /// <summary>
    /// 取得短日期
    /// </summary>
    /// <param name="dateStr"></param>
    /// <returns></returns>
    public string GetShortDate(string dateStr)
    {
        if (dateStr != string.Empty)
            return Convert.ToDateTime(dateStr).ToShortDateString();
        else
            return string.Empty;
    }

    protected void btnDelete_Click(object sender, EventArgs e)
    {
        try
        {
            for (int i = 0; i <= dlstPurchase.Items.Count - 1; i++)
            {

                CheckBox cbox = (CheckBox)dlstPurchase.Items[i].FindControl("CheckBox1");
                if (cbox.Checked == true)
                {

                    int UserID = Convert.ToInt32(dlstPurchase.DataKeys[i]);
                    IPurchase RM = new RPurchase();
                    int m = RM.Delete(UserID);
                }
            }
            Bind();
        }
        catch (Exception ex)
        {
            ShowMessage(ex.Message);
        }
    }

    public string GetImageUrl(string Url)
    {
        if (Url != "")
        {
            return Url;
        }
        else
        {
            return "../../Images/System/wutu.gif";
        }
        return "../../Images/System/wutu.gif";
    }
}
