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 System.Data.SqlClient;
using System.Web.Mail;
public partial class WTOSYSadmin_orderlist_Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Doadmin.Execsql("update Orderw set ckstatus='y'");
        Response.Write(Session["xls"]);
        if (Session["WtoRightName"] == null)
        {
            Response.Redirect("~/SYSADMIN/main/error.aspx?err=非法登陆!或系统超时，请刷新后重新登录");
        }
        if (Request.QueryString["do"] != null)
        {
            string sql2 = "delete from Orderw where id=" + Request.QueryString["id"];
            Doadmin.Execsql(sql2);
            #region GRIDVIEW绑定 快捷查询
            switch (this.DropDownList1.SelectedValue.ToString())
            {
                case "0":
                    databind("0", "n");
                    break;
                case "1":
                    databind("1", "n");
                    break;
                case "2":
                    databind("2", "n");
                    break;
                case "3":
                    databind("3", "n");
                    break;
                case "5":
                    databind("5", "n");
                    break;
                case "7":
                    databind("7", "n");
                    break;
                case "8":
                    databind("8", "n");
                    break;
                case "20":
                    databind("20", "n");
                    break;
                case "22":
                    databind("22", "n");
                    break;
                case "23":
                    databind("23", "n");
                    break;
                case "100":
                    databind("100", "n");
                    break;
                case "101":
                    databind("101", "n");
                    break;
                case "all":
                    databind("all", "n");
                    break;
            }
            #endregion
        }
        if (Request.QueryString["zt"] != null)
        {
            int doing = Convert.ToInt32(Request.QueryString["zt"]);
            string sql1 = "";
            string sql2 = "";
            switch (doing)
            {
                case 0:
                    sql1 = "update Orderw set OrderState=1 where id=" + Request.QueryString["id"];
                    break;
                case 1:
                    sql1 = "update Orderw set OrderState=2 where id=" + Request.QueryString["id"];
                    break;
                case 2:
                    sql1 = "update Orderw set OrderState=3 where id=" + Request.QueryString["id"];
                    break;
                case 3:
                    sql1 = "update Orderw set OrderState=4 where id=" + Request.QueryString["id"];
                    break;
                case 4:
                    sql1 = "update Orderw set OrderState=5 where id=" + Request.QueryString["id"];

                    //邮件发送

                    SqlConnection Mconn = CDatabase.wtoconn();
                    Mconn.Open();
                    SqlCommand Msmd = new SqlCommand("select * from SystemBasicInformation", Mconn);
                    SqlDataReader Msdr = Msmd.ExecuteReader();
                    Msdr.Read();
                    string Mform, Muid, Mpwd, Mstmp, Misopen, Mcont, MCompanyName, MWEBName, MTel, MFax, MEmail, MQQ, MAddress, MMSN, TBWW, MLOGOpic, Memailto;
                    Mform = Msdr.GetString(7);
                    Muid = Mform;
                    Mpwd = Msdr.GetString(26);
                    Mstmp = Msdr.GetString(25);
                    Misopen = Msdr.GetString(1).ToString().Trim();
                    MCompanyName = Msdr.GetString(2);
                    MWEBName = Msdr.GetString(3);
                    MTel = Msdr.GetString(5);
                    MFax = Msdr.GetString(6);
                    MEmail = Msdr.GetString(7);
                    MQQ = Msdr.GetString(8);
                    MAddress = Msdr.GetString(10);
                    MMSN = Msdr.GetString(13);
                    TBWW = Msdr.GetString(14);
                    Memailto = Msdr.GetString(23).Trim();
                    MLOGOpic = "<a href=http://" + Request.ServerVariables["SERVER_NAME"].ToString() + "><img src=http://" + Request.ServerVariables["SERVER_NAME"].ToString() + "/images/" + Msdr.GetString(15) + " border=0></a>";
                    Msdr.Close();
                    SqlCommand smdem = new SqlCommand("select OrderEmail from Orderw where id=" + Request.QueryString["id"], Mconn);
                    if (Convert.ToString(smdem.ExecuteScalar()) != "")
                    {
                        if (Memailto == "y")
                        {
                            string OrderUserId, Orderno, Ordername, OrderEmail, OrderAddDate, OrderTatal;
                            SqlCommand Msmd2 = new SqlCommand("select content from email where lx='5'", Mconn);
                            Mcont = Server.HtmlDecode(Convert.ToString(Msmd2.ExecuteScalar()));
                            SqlCommand Msmd3 = new SqlCommand("select title from email where lx='5'", Mconn);
                            string Mti = Convert.ToString(Msmd3.ExecuteScalar());
                            SqlCommand Vsmd = new SqlCommand("select OrderUserId,Orderno,Ordername,OrderEmail,OrderAddDate,OrderTatal,isvip from Orderw where id=" + Request.QueryString["id"], Mconn);
                            SqlDataReader Vsdr = Vsmd.ExecuteReader();
                            Vsdr.Read();
                            OrderUserId = Convert.ToString(Vsdr.GetInt32(0));
                            Orderno = Vsdr.GetString(1);
                            Ordername = Vsdr.GetString(2);
                            OrderEmail = Vsdr.GetString(3);
                            OrderAddDate = Convert.ToString(Vsdr.GetDateTime(4));
                            OrderTatal = Convert.ToString(Vsdr.GetDecimal(5));
                            Vsdr.Close();

                            //SqlCommand Osmd = new SqlCommand("select vipusername,vipuserpwd from MemberVIP where id=" + OrderUserId, Mconn);
                            //SqlDataReader Osdr = Osmd.ExecuteReader();
                            //Osdr.Read();
                            //string username = Osdr.GetString(0);
                            //string userpwd = Osdr.GetString(1);
                            //Osdr.Close();
                            MailMessage msg = new MailMessage();
                            msg.From = Mform;  //发送方地址(如test@163.com)
                            msg.To = OrderEmail; //接收方地址(如test@163.com) 
                            msg.BodyFormat = MailFormat.Html;   //正文内容类型 
                            msg.BodyEncoding = System.Text.Encoding.Default;    //正文内容编码 
                            //msg.Attachments.Add(new MailAttachment("d:\\d.txt"));
                            //主题 
                            msg.Subject = Mti;
                            //内容 
                            //编码定义
                            Mcont = Mcont.Replace("$CMY$", MCompanyName);
                            Mcont = Mcont.Replace("$WEBN$", MWEBName);
                            Mcont = Mcont.Replace("$TEL$", MTel);
                            Mcont = Mcont.Replace("$FAX$", MFax);
                            Mcont = Mcont.Replace("$EMA$", MEmail);
                            Mcont = Mcont.Replace("$QQ$", MQQ);
                            Mcont = Mcont.Replace("$ADD$", MAddress);
                            Mcont = Mcont.Replace("$MSN$", MMSN);
                            Mcont = Mcont.Replace("$TBW$", TBWW);
                            Mcont = Mcont.Replace("$LOGO$", MLOGOpic);
                            Mcont = Mcont.Replace("$ORD$", Orderno);
                            Mcont = Mcont.Replace("$ODT$", OrderAddDate);
                            Mcont = Mcont.Replace("$OTA$", OrderTatal);
                            msg.Body = Mcont;
                            msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //设置为需要用户验证 
                            msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", Muid); //设置验证用户名 
                            msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", Mpwd); //设置验证密码 
                            SmtpMail.SmtpServer = Mstmp;  //邮件服务器地址(如smtp.163.com) 
                            SmtpMail.Send(msg);  //发送 

                        }
                    }

                    SqlCommand smdfip = new SqlCommand("select isvip from Orderw where id=" + Request.QueryString["id"], Mconn);
                    if (Convert.ToString(smdfip.ExecuteScalar()) == "y")
                    {
                        //int where1, result1, where2, result2, where3, result3, result4;
                        SqlCommand smdjf;
                        SqlDataReader sdrjf;
                        //smdjf = new SqlCommand("select * from Integral", Mconn);
                        //sdrjf = smdjf.ExecuteReader();
                        //sdrjf.Read();
                        //where1 = Convert.ToInt32(sdrjf["where1"].ToString());
                        //result1 = Convert.ToInt32(sdrjf["result1"].ToString());
                        //where2 = Convert.ToInt32(sdrjf["where2"].ToString());
                        //result2 = Convert.ToInt32(sdrjf["result2"].ToString());
                        //where3 = Convert.ToInt32(sdrjf["where3"].ToString());
                        //result3 = Convert.ToInt32(sdrjf["result3"].ToString());
                        //result4 = Convert.ToInt32(sdrjf["result4"].ToString());
                        //sdrjf.Close();
                        smdjf = new SqlCommand("select  OrderTatal,OrderUserId,b3 from Orderw where id=" + Request.QueryString["id"], Mconn);
                        sdrjf = smdjf.ExecuteReader();
                        sdrjf.Read();
                        int tal = Convert.ToInt32(sdrjf["b3"].ToString());
                        string OrderUserId2 = Convert.ToString(sdrjf["OrderUserId"].ToString());
                        sdrjf.Close();
                        Doadmin.Execsql("update MemberVIP set Integral=Integral+" + tal + ",intin='" + DateTime.Now.ToString() + "' where id=" + OrderUserId2);
                        //if (Convert.ToInt32(tal) < where1)
                        //{
                        //    Doadmin.Execsql("update MemberVIP set Integral=Integral+" + result1 + ",intin='" + DateTime.Now.ToString() + "' where id=" + OrderUserId2);
                        //}

                        //if (Convert.ToInt32(tal) >= where1 && Convert.ToInt32(tal) < where2)
                        //{
                        //    Doadmin.Execsql("update MemberVIP set Integral=Integral+" + result1 + ",intin='" + DateTime.Now.ToString() + "' where id=" + OrderUserId2);
                        //}

                        //if (Convert.ToInt32(tal) >= where2 && Convert.ToInt32(tal) < where3)
                        //{
                        //    Doadmin.Execsql("update MemberVIP set Integral=Integral+" + result2 + ",intin='" + DateTime.Now.ToString() + "' where id=" + OrderUserId2);
                        //}

                        //if (Convert.ToInt32(tal) == where3)
                        //{
                        //    Doadmin.Execsql("update MemberVIP set Integral=Integral+" + result1 + ",intin='" + DateTime.Now.ToString() + "' where id=" + OrderUserId2);
                        //}

                        //if (Convert.ToInt32(tal) > where3)
                        //{
                        //    Doadmin.Execsql("update MemberVIP set Integral=Integral+" + result4 + ",intin='" + DateTime.Now.ToString() + "' where id=" + OrderUserId2);
                        //}

                    }
                    Mconn.Close();
                    break;
                case 5:
                    sql1 = "update Orderw set OrderState=6 where id=" + Request.QueryString["id"];
                    break;
                case 6:
                    sql1 = "update Orderw set OrderState=7 where id=" + Request.QueryString["id"];
                    break;
                case 7:
                    sql1 = "update Orderw set OrderState=8 where id=" + Request.QueryString["id"];
                    sql2 = "update OrderInfo set OrderState=8 where OrderID=" + Request.QueryString["id"];   
                    Doadmin.Execsql(sql2);
                    break;
                case 22:
                    sql1 = "update Orderw set OrderState=23 where id=" + Request.QueryString["id"];
                    break;
            }
            Doadmin.Execsql(sql1);


            #region GRIDVIEW绑定 快捷查询
            switch (this.DropDownList1.SelectedValue.ToString())
            {
                case "0":
                    databind("0", "n");
                    break;
                case "1":
                    databind("1", "n");
                    break;
                case "2":
                    databind("2", "n");
                    break;
                case "3":
                    databind("3", "n");
                    break;
                case "5":
                    databind("5", "n");
                    break;
                case "7":
                    databind("7", "n");
                    break;
                case "8":
                    databind("8", "n");
                    break;
                case "20":
                    databind("20", "n");
                    break;
                case "22":
                    databind("22", "n");
                    break;
                case "23":
                    databind("23", "n");
                    break;
                case "100":
                    databind("100", "n");
                    break;
                case "101":
                    databind("101", "n");
                    break;
                case "all":
                    databind("all", "n");
                    break;
            }
            #endregion


        }
        if (!IsPostBack)
        {
            #region GRIDVIEW绑定 快捷查询
            switch (this.DropDownList1.SelectedValue.ToString())
            {
                case "0":
                    databind("0", "n");
                    break;
                case "1":
                    databind("1", "n");
                    break;
                case "2":
                    databind("2", "n");
                    break;
                case "3":
                    databind("3", "n");
                    break;
                case "5":
                    databind("5", "n");
                    break;
                case "7":
                    databind("7", "n");
                    break;
                case "8":
                    databind("8", "n");
                    break;
                case "20":
                    databind("20", "n");
                    break;
                case "22":
                    databind("22", "n");
                    break;
                case "23":
                    databind("23", "n");
                    break;
                case "100":
                    databind("100", "n");
                    break;
                case "101":
                    databind("101", "n");
                    break;
                case "all":
                    databind("all", "n");
                    break;
            }
            #endregion
        }
    }
    private void databind(string whe,string vl)
    {
        SqlConnection conn = CDatabase.wtoconn();
        conn.Open();
        SqlDataAdapter sad;
        switch (whe)
        {
            case "100":
                sad = new SqlDataAdapter("select * from Orderw order by OrderAddDate desc", conn);
                break;
            case "101":
                sad = new SqlDataAdapter("select * from Orderw where year(OrderAddDate)='" + DateTime.Now.Year + "' and month(OrderAddDate)='" + DateTime.Now.Month + "' and day(OrderAddDate)='" + DateTime.Now.Day + "' order by OrderAddDate desc", conn);
                break;
            case "0":
                sad = new SqlDataAdapter("select * from Orderw where OrderState=0 order by OrderAddDate desc", conn);
                break;
            case "1":
                sad = new SqlDataAdapter("select * from Orderw where OrderState=1 order by OrderAddDate desc", conn);
                break;
            case "2":
                sad = new SqlDataAdapter("select * from Orderw where OrderState=2 order by OrderAddDate desc", conn);
                break;
            case "3":
                sad = new SqlDataAdapter("select * from Orderw where OrderState=3 order by OrderAddDate desc", conn);
                break;
            case "5":
                sad = new SqlDataAdapter("select * from Orderw where OrderState=5 order by OrderAddDate desc", conn);
                break;
            case "7":
                sad = new SqlDataAdapter("select * from Orderw where OrderState=7 order by OrderAddDate desc", conn);
                break;
            case "8":
                sad = new SqlDataAdapter("select * from Orderw where OrderState=8 order by OrderAddDate desc", conn);
                break;
            case "20":
                sad = new SqlDataAdapter("select * from Orderw where OrderState=20 or OrderState=21 order by OrderAddDate desc", conn);
                break;
            case "22":
                sad = new SqlDataAdapter("select * from Orderw where OrderState=22 order by OrderAddDate desc", conn);
                break;
            case "23":
                sad = new SqlDataAdapter("select * from Orderw where OrderState=23 order by OrderAddDate desc", conn);
                break;
            case "all":
                sad = new SqlDataAdapter("select * from Orderw where OrderAddDate>='" + this.TextBox2.Text.ToString() + "' and OrderAddDate<='" + this.TextBox3.Text.ToString() + "' order by OrderAddDate desc", conn);
                break;
            default:
                sad = new SqlDataAdapter("select * from Orderw  order by OrderAddDate desc", conn);
                break;
        }
        DataSet ds = new DataSet();
        sad.Fill(ds, "cu");
        this.GridView1.DataSource = ds;
        this.GridView1.DataKeyNames = new string[] { "id" };
        this.GridView1.DataBind();

        if (vl == "n")
        {
            this.GridView1.Columns[5].Visible = false;
            this.GridView1.Columns[6].Visible = false;
            this.GridView1.Columns[7].Visible = false;
            this.GridView1.Columns[8].Visible = false;
            this.GridView1.Columns[9].Visible = false;
        }
        else
        {
            this.GridView1.Columns[5].Visible = true;
            this.GridView1.Columns[6].Visible = true;
            this.GridView1.Columns[7].Visible = true;
            this.GridView1.Columns[8].Visible = true;
            this.GridView1.Columns[9].Visible = true;
            this.GridView1.Columns[0].Visible = false;
        }
        GridView1.DataBind();
        if (GridView1.Rows.Count == 0)
        {
            this.nors.Visible = true;
            this.t1.Visible = false;
        }
        this.Label1.Text = "当前订单数为<font color='red'><b>" + ds.Tables["cu"].DefaultView.Count + "</b></font>.分为<font color='red'><b>" + this.GridView1.PageCount + "</b></font>页显示.";
        LinkButton lb;
        SqlCommand sad2;


        for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
        {
            DataRowView mydrv = ds.Tables["cu"].DefaultView[i];
            sad2 = new SqlCommand("select OrderState from Orderw where id=" + GridView1.DataKeys[i].Value, conn);
            int isok = Convert.ToInt32(sad2.ExecuteScalar());
            sad2 = new SqlCommand("select OrderPayM from Orderw where id=" + GridView1.DataKeys[i].Value, conn);
            if (Convert.ToString(sad2.ExecuteScalar()).Trim() != "货到付款")
            {
                switch (isok)
                {
                    case 0:
                        lb = (LinkButton)this.GridView1.Rows[i].FindControl("doing");
                        lb.Text = "等待确认";
                        lb.PostBackUrl = "orderlist.aspx?id=" + GridView1.DataKeys[i].Value + "&zt=0";
                        lb.ForeColor = System.Drawing.Color.Red;
                        break;
                    case 1:
                        lb = (LinkButton)this.GridView1.Rows[i].FindControl("doing");
                        lb.Text = "未付款";
                        lb.PostBackUrl = "orderlist.aspx?id=" + GridView1.DataKeys[i].Value + "&zt=2";
                        lb.ForeColor = System.Drawing.Color.Blue;
                        break;
                    case 2:
                        lb = (LinkButton)this.GridView1.Rows[i].FindControl("doing");
                        lb.Text = "等待处理";
                        lb.ForeColor = System.Drawing.Color.Green;
                        lb.PostBackUrl = "orderlist.aspx?id=" + GridView1.DataKeys[i].Value + "&zt=4";
                        
                        break;
                    case 3:
                        lb = (LinkButton)this.GridView1.Rows[i].FindControl("doing");
                        lb.Text = "已收款";
                        lb.ForeColor = System.Drawing.Color.FromArgb(128, 0, 128);
                        lb.PostBackUrl = "orderlist.aspx?id=" + GridView1.DataKeys[i].Value + "&zt=1";
                        break;
                    case 4:
                        lb = (LinkButton)this.GridView1.Rows[i].FindControl("doing");
                        lb.Text = "未发货";
                        lb.PostBackUrl = "orderlist.aspx?id=" + GridView1.DataKeys[i].Value + "&zt=4";
                        break;
                    case 5:
                        lb = (LinkButton)this.GridView1.Rows[i].FindControl("doing");
                        lb.Text = "发货中";
                        lb.ForeColor = System.Drawing.Color.FromArgb(255, 0, 255);
                        lb.PostBackUrl = "orderlist.aspx?id=" + GridView1.DataKeys[i].Value + "&zt=6";
                        break;
                    case 6:
                        lb = (LinkButton)this.GridView1.Rows[i].FindControl("doing");
                        lb.Text = "等待确认收货";
                        lb.PostBackUrl = "orderlist.aspx?id=" + GridView1.DataKeys[i].Value + "&zt=6";
                        break;
                    case 7:
                        lb = (LinkButton)this.GridView1.Rows[i].FindControl("doing");
                        lb.Text = "已确认收货";
                        lb.ForeColor = System.Drawing.Color.FromArgb(128, 0, 0);
                        lb.PostBackUrl = "orderlist.aspx?id=" + GridView1.DataKeys[i].Value + "&zt=7";
                        break;
                    case 8:
                        lb = (LinkButton)this.GridView1.Rows[i].FindControl("doing");
                        lb.Text = "√完成";
                        lb.ForeColor = System.Drawing.Color.FromArgb(255, 153, 0);
                        lb.Enabled = false;
                        break;
                    case 20:
                        lb = (LinkButton)this.GridView1.Rows[i].FindControl("doing");
                        lb.Text = "×作废";
                        lb.Enabled = false;
                        break;
                    case 21:
                        lb = (LinkButton)this.GridView1.Rows[i].FindControl("doing");
                        lb.Text = "×完成[VIP清除]";
                        lb.Enabled = false;
                        break;
                    case 22:
                        lb = (LinkButton)this.GridView1.Rows[i].FindControl("doing");
                        lb.Text = "√积分订单未处理";
                        lb.PostBackUrl = "orderlist.aspx?id=" + GridView1.DataKeys[i].Value + "&zt=22";
                        lb.ForeColor = System.Drawing.Color.Blue;
                        break;
                    case 23:
                        lb = (LinkButton)this.GridView1.Rows[i].FindControl("doing");
                        lb.Text = "√积分订单完成";
                        lb.Enabled = false;
                        break;
                }
            }
            else
            {
                switch (isok)
                {
                    case 0:
                        lb = (LinkButton)this.GridView1.Rows[i].FindControl("doing");
                        lb.Text = "等待确认";
                        lb.ForeColor = System.Drawing.Color.Red;
                        lb.PostBackUrl = "orderlist.aspx?id=" + GridView1.DataKeys[i].Value + "&zt=1";
                        break;
                    case 1:
                        lb = (LinkButton)this.GridView1.Rows[i].FindControl("doing");
                        lb.Text = "未付款";
                        lb.ForeColor = System.Drawing.Color.Blue;
                        lb.PostBackUrl = "orderlist.aspx?id=" + GridView1.DataKeys[i].Value + "&zt=2";
                        break;
                    case 2:
                        lb = (LinkButton)this.GridView1.Rows[i].FindControl("doing");
                        lb.Text = "等待处理";
                        lb.PostBackUrl = "orderlist.aspx?id=" + GridView1.DataKeys[i].Value + "&zt=4";
                        lb.ForeColor = System.Drawing.Color.Green;
                        break;
                    case 3:
                        lb = (LinkButton)this.GridView1.Rows[i].FindControl("doing");
                        lb.Text = "已收款";
                        lb.ForeColor = System.Drawing.Color.FromArgb(128, 0, 128);
                        lb.PostBackUrl = "orderlist.aspx?id=" + GridView1.DataKeys[i].Value + "&zt=7";
                        break;
                    case 4:
                        lb = (LinkButton)this.GridView1.Rows[i].FindControl("doing");
                        lb.Text = "未发货";
                        lb.PostBackUrl = "orderlist.aspx?id=" + GridView1.DataKeys[i].Value + "&zt=4";
                        break;
                    case 5:
                        lb = (LinkButton)this.GridView1.Rows[i].FindControl("doing");
                        lb.Text = "发货中";
                        lb.ForeColor = System.Drawing.Color.FromArgb(255, 0, 255);
                        lb.PostBackUrl = "orderlist.aspx?id=" + GridView1.DataKeys[i].Value + "&zt=6";
                        break;
                    case 6:
                        lb = (LinkButton)this.GridView1.Rows[i].FindControl("doing");
                        lb.Text = "等待确认收货";
                        lb.PostBackUrl = "orderlist.aspx?id=" + GridView1.DataKeys[i].Value + "&zt=6";
                        break;
                    case 7:
                        lb = (LinkButton)this.GridView1.Rows[i].FindControl("doing");
                        lb.Text = "已确认收货";
                        lb.ForeColor = System.Drawing.Color.FromArgb(128, 0, 0);
                        lb.PostBackUrl = "orderlist.aspx?id=" + GridView1.DataKeys[i].Value + "&zt=0";
                        break;
                    case 8:
                        lb = (LinkButton)this.GridView1.Rows[i].FindControl("doing");
                        lb.Text = "√完成";
                        lb.ForeColor = System.Drawing.Color.FromArgb(255, 153, 0);
                        lb.Enabled = false;
                        break;
                    case 20:
                        lb = (LinkButton)this.GridView1.Rows[i].FindControl("doing");
                        lb.Text = "×作废";
                        lb.Enabled = false;
                        break;
                    case 21:
                        lb = (LinkButton)this.GridView1.Rows[i].FindControl("doing");
                        lb.Text = "×完成[VIP清除]";
                        lb.Enabled = false;
                        break;
                    case 22:
                        lb = (LinkButton)this.GridView1.Rows[i].FindControl("doing");
                        lb.Text = "√积分订单未处理";
                        lb.PostBackUrl = "orderlist.aspx?id=" + GridView1.DataKeys[i].Value + "&zt=22";
                        lb.ForeColor = System.Drawing.Color.Blue;
                        break;
                    case 23:
                        lb = (LinkButton)this.GridView1.Rows[i].FindControl("doing");
                        lb.Text = "√积分订单完成";
                        lb.Enabled = false;
                        break;
                }
            }
        }
        sad.Dispose();
        conn.Close();
    }

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        
        # region 行变色
        int i;
        int g = 0;
        //执行循环，保证每条数据都可以更新
        for (i =0; i < GridView1.Rows.Count; i++)
        {
            //首先判断是否是数据行
            if (e.Row.RowType == DataControlRowType.DataRow)
            {

                //当鼠标停留时更改背景色
                e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#00A9FF'");
                //当鼠标移开时还原背景色
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
            }
            g++;
        }
        //如果是绑定数据行 
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            //鼠标经过时，行背景色变 
            e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#E6F5FA'");
            //鼠标移出时，行背景色变 
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF'");
        }
        # endregion
        //如果是绑定数据行 
        if (e.Row.RowType == DataControlRowType.DataRow)
        {

            if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
            {
                ((HyperLink)e.Row.Cells[11].Controls[0]).Attributes.Add("onclick", "javascript:return confirm('你确认要删除\"" + ((HyperLink)e.Row.Cells[1].Controls[0]).Text + "\"吗?')");
            }
        }
       
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        #region GRIDVIEW绑定 快捷查询
        switch (this.DropDownList1.SelectedValue.ToString())
        {
            case "0":
                databind("0", "n");
                break;
            case "1":
                databind("1", "n");
                break;
            case "2":
                databind("2", "n");
                break;
            case "3":
                databind("3", "n");
                break;
            case "5":
                databind("5", "n");
                break;
            case "7":
                databind("7", "n");
                break;
            case "8":
                databind("8", "n");
                break;
            case "20":
                databind("20", "n");
                break;
            case "22":
                databind("22", "n");
                break;
            case "23":
                databind("23", "n");
                break;
            case "100":
                databind("100", "n");
                break;
            case "101":
                databind("101", "n");
                break;
            case "all":
                databind("all", "n");
                break;
        }
        #endregion
    }
    protected void CheckBox2_CheckedChanged(object sender, EventArgs e)
    {
        for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
        {
            CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1");
            if (CheckBox2.Checked == true)
            {
                cbox.Checked = true;
            }
            else
            {
                cbox.Checked = false;
            }
        }

    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        CheckBox2.Checked = false;
        for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
        {
            CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1");
            cbox.Checked = false;
        }

    }
    protected void LinkButton2_Click(object sender, EventArgs e)
    {
        for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
        {
            CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1");

            if (cbox.Checked == true)
            {
                string sqlstr = "delete from Orderw where id=" + GridView1.DataKeys[i].Value;
                Doadmin.Execsql(sqlstr);
            }
        }
        #region GRIDVIEW绑定 快捷查询
        switch (this.DropDownList1.SelectedValue.ToString())
        {
            case "0":
                databind("0", "n");
                break;
            case "1":
                databind("1", "n");
                break;
            case "2":
                databind("2", "n");
                break;
            case "3":
                databind("3", "n");
                break;
            case "5":
                databind("5", "n");
                break;
            case "7":
                databind("7", "n");
                break;
            case "8":
                databind("8", "n");
                break;
            case "20":
                databind("20", "n");
                break;
            case "22":
                databind("22", "n");
                break;
            case "23":
                databind("23", "n");
                break;
            case "100":
                databind("100", "n");
                break;
            case "101":
                databind("101", "n");
                break;
            case "all":
                databind("all", "n");
                break;
        }
        #endregion
    }

    protected void LinkButton3_Click(object sender, EventArgs e)
    {
        for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
        {
            CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1");

            if (cbox.Checked == true)
            {
                string sqlstr = "update Orderw set OrderState=20 where id=" + GridView1.DataKeys[i].Value;
                Doadmin.Execsql(sqlstr);
            }
        }
        #region GRIDVIEW绑定 快捷查询
        switch (this.DropDownList1.SelectedValue.ToString())
        {
            case "0":
                databind("0", "n");
                break;
            case "1":
                databind("1", "n");
                break;
            case "2":
                databind("2", "n");
                break;
            case "3":
                databind("3", "n");
                break;
            case "5":
                databind("5", "n");
                break;
            case "7":
                databind("7", "n");
                break;
            case "8":
                databind("8", "n");
                break;
            case "20":
                databind("20", "n");
                break;
            case "22":
                databind("22", "n");
                break;
            case "23":
                databind("23", "n");
                break;
            case "100":
                databind("100", "n");
                break;
            case "101":
                databind("101", "n");
                break;
            case "all":
                databind("all", "n");
                break;
        }
        #endregion
    }
    protected void LinkButton4_Click(object sender, EventArgs e)
    {
        this.DropDownList1.SelectedValue = "all";
        #region GRIDVIEW绑定 快捷查询
        switch (this.DropDownList1.SelectedValue.ToString())
        {
            case "0":
                databind("0", "n");
                break;
            case "1":
                databind("1", "n");
                break;
            case "2":
                databind("2", "n");
                break;
            case "3":
                databind("3", "n");
                break;
            case "5":
                databind("5", "n");
                break;
            case "7":
                databind("7", "n");
                break;
            case "8":
                databind("8", "n");
                break;
            case "20":
                databind("20", "n");
                break;
            case "22":
                databind("22", "n");
                break;
            case "23":
                databind("23", "n");
                break;
            case "100":
                databind("100", "n");
                break;
            case "101":
                databind("101", "n");
                break;
            case "all":
                databind("all", "n");
                break;
        }
        #endregion
    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        #region GRIDVIEW绑定 快捷查询
        switch (this.DropDownList1.SelectedValue.ToString())
        {
            case "0":
                databind("0", "n");
                break;
            case "1":
                databind("1", "n");
                break;
            case "2":
                databind("2", "n");
                break;
            case "3":
                databind("3", "n");
                break;
            case "5":
                databind("5", "n");
                break;
            case "7":
                databind("7", "n");
                break;
            case "8":
                databind("8", "n");
                break;
            case "20":
                databind("20", "n");
                break;
            case "22":
                databind("22", "n");
                break;
            case "23":
                databind("23", "n");
                break;
            case "100":
                databind("100", "n");
                break;
            case "101":
                databind("101", "n");
                break;
            case "all":
                databind("all", "n");
                break;
        }
        #endregion
    }
    protected void LinkButton5_Click(object sender, EventArgs e)
    {
        this.GridView1.DataBind();
        GridViewToExcel(GridView1,"ORDER"+DateTime.Now.Month.ToString()+"-"+DateTime.Now.Day.ToString()+".xls");
    }
    public override void VerifyRenderingInServerForm(Control control)
    {
    } 
    /*
               ExcelGridView ：需要导出的GridView
               FileName ：保存出来的Excel文件名，需要加文件名后缀
    */
    public void GridViewToExcel(GridView ExcelGridView, string FileName)
   {
        Response.Clear();
        Response.AddHeader("content-disposition", "attachment;filename="+FileName);
        Response.Charset = "GB2312";
        Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");//设置输出流为简体中文
        Response.ContentType = "application/vnd.xls";
        System.IO.StringWriter stringWrite = new System.IO.StringWriter();
        System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);

        ExcelGridView.AllowPaging = false;
        #region GRIDVIEW绑定 快捷查询
        switch (this.DropDownList1.SelectedValue.ToString())
        {
            case "0":
                databind("0", "n");
                break;
            case "1":
                databind("1", "n");
                break;
            case "2":
                databind("2", "n");
                break;
            case "3":
                databind("3", "n");
                break;
            case "5":
                databind("5", "n");
                break;
            case "7":
                databind("7", "n");
                break;
            case "8":
                databind("8", "n");
                break;
            case "20":
                databind("20", "n");
                break;
            case "22":
                databind("22", "n");
                break;
            case "23":
                databind("23", "n");
                break;
            case "100":
                databind("100", "n");
                break;
            case "101":
                databind("101", "n");
                break;
            case "all":
                databind("all", "n");
                break;
        }
        #endregion

        ExcelGridView.RenderControl(htmlWrite);

        Response.Write(stringWrite.ToString());
        Response.End();
        ExcelGridView.AllowPaging = true;
        #region GRIDVIEW绑定 快捷查询
        switch (this.DropDownList1.SelectedValue.ToString())
        {
            case "0":
                databind("0", "n");
                break;
            case "1":
                databind("1", "n");
                break;
            case "2":
                databind("2", "n");
                break;
            case "3":
                databind("3", "n");
                break;
            case "5":
                databind("5", "n");
                break;
            case "7":
                databind("7", "n");
                break;
            case "8":
                databind("8", "n");
                break;
            case "20":
                databind("20", "n");
                break;
            case "22":
                databind("22", "n");
                break;
            case "23":
                databind("23", "n");
                break;
            case "100":
                databind("100", "n");
                break;
            case "101":
                databind("101", "n");
                break;
            case "all":
                databind("all", "n");
                break;
        }
        #endregion


    }
}
