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;

public partial class WTOSYSadmin_vipmag_orderdo : System.Web.UI.Page
{
    private Label l1 = new Label();
    private Label l2 = new Label();
    private Label l3 = new Label();
    private Label l4 = new Label();
    private Label l5 = new Label();
    private Label l6 = new Label();
    private Label l7 = new Label();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["WtoRightName"] == null)
        {
            Response.Redirect("~/SYSADMIN/main/error.aspx?err=非法登陆!或系统超时，请刷新后重新登录");
        }
        this.HyperLink1.NavigateUrl = "orderprin.aspx?id=" + Request.QueryString["id"].ToString();
        this.HyperLink1.Target = "_blank";
        if (!IsPostBack)
        {
            SqlConnection conn = CDatabase.wtoconn();
            conn.Open();
            SqlCommand smd = new SqlCommand("select * from Orderw where id=" + Request.QueryString["id"], conn);
            SqlDataReader sdr = smd.ExecuteReader();
            sdr.Read();
            if (sdr.GetString(17) == "y")
            {
                this.Image1.Visible = true;
                this.Label1.Visible = true;
            }
            this.Orderno.Text = sdr.GetString(1);
            this.Ordername.Text = sdr.GetString(3);
            this.OrderEmail.Text = sdr.GetString(4);
            this.OrderTel.Text = sdr.GetString(5);
            this.OrderMobi.Text = sdr.GetString(6);
            string  laear = sdr.GetString(9);
            this.OrderAdd.Text = sdr.GetString(7);
            this.OrderPost.Text = sdr.GetString(8);
            this.OrderPostTime.Text = sdr.GetString(10);
            this.OrderPayM.Text = sdr.GetString(12);
            this.OrderSonF.Text = sdr.GetString(13);
            Label2.Text = sdr["b3"].ToString();
            this.Label4.Text = sdr["xszk"].ToString();
            this.TextBox1.Text = sdr["text1"].ToString();
            this.OrderAddDate.Text =Convert.ToString(sdr.GetDateTime(15));
            if (sdr.GetString(11) != "")
            {
                this.OrderMone.Text = sdr.GetString(11);
            }
            else
            {
                this.OrderMone.Text = "无";
            }
            this.OrderTatal.Text ="￥ "+Convert.ToString(sdr.GetDecimal(14));
            int orderid = sdr.GetInt32(0);
            int sta=sdr.GetInt32(16);

            switch(sta)
            {
                case 0:
                    this.sta.Text = "等待确定";
                    break;
                case 1:
                    this.sta.Text = "未付款";
                    break;
                case 2:
                    this.sta.Text = "等待处理";
                    break;
                case 3:
                    this.sta.Text = "已收款";
                    break;
                case 4:
                    this.sta.Text = "未发货";
                    break;
                case 5:
                    this.sta.Text = "发货中";
                    break;
                case 6:
                    this.sta.Text = "等待确认收货";
                    break;
                case 7:
                    this.sta.Text = "已确认收货";
                    break;
                case 8:
                    this.sta.Text = "√完成";
                    break;
                case 20:
                    this.sta.Text = "×作废";
                    break;
                case 21:
                    this.sta.Text = "×作废[VIP清除]";
                    break;
                case 22:
                    this.sta.Text = "√积分订单未处理";
                    break;
                case 23:
                    this.sta.Text = "√积分订单完成";
                    break;

            }
            sdr.Close();
            SqlCommand smdordert = new SqlCommand("select AreaName from ServiceArea where id=" + laear.ToString(), conn);
            this.Orderaear.Text = Convert.ToString(smdordert.ExecuteScalar());

            //----------------------------------------------------------------------------
            # region 表格TB创建[动态]


            l1.Text = "图片";
            l2.Text = "商品名称";
            l3.Text = "优惠价格";
            l4.Text = "属性配件";
            l5.Text = "数量";
            l6.Text = "小计";
            TableRow tr;
            TableCell tc;
            tr = new TableRow();
            tr.HorizontalAlign = HorizontalAlign.Center;
            tc = new TableCell();
            tc.Controls.Add(l1);
            tr.Controls.Add(tc);
            tc = new TableCell();
            tc.Controls.Add(l2);
            tr.Controls.Add(tc);
            tc = new TableCell();
            tc.Controls.Add(l3);
            tr.Controls.Add(tc);
            tc = new TableCell();
            tc.Controls.Add(l4);
            tr.Controls.Add(tc);
            tc = new TableCell();
            tc.Controls.Add(l5);
            tr.Controls.Add(tc);
            tc = new TableCell();
            tc.Controls.Add(l6);
            tr.Controls.Add(tc);
            tc = new TableCell();
            tc.Controls.Add(l7);
            tr.Controls.Add(tc);
            TB.Controls.Add(tr);
            TB.HorizontalAlign = HorizontalAlign.Center;
            tr.CssClass = "carttr";

            ImageButton img1;

            SqlCommand smd2 = new SqlCommand("select * from OrderInfo  where OrderID=" + orderid, conn);
            SqlDataReader sdr2 = smd2.ExecuteReader();

            Label lbl1 = new Label();
            TableCell tc2;
            TextBox txtBox;
            decimal counttotal = 0;
            while (sdr2.Read())
            {
                img1 = new ImageButton();
                img1.Width = 60;
                img1.Height = 60;
                img1.ImageUrl = "~/upfile/" + sdr2.GetString(7);
                tr = new TableRow();
                tr.CssClass = "carttrM";
                tc = new TableCell();
                tc.Controls.Add(img1);
                tr.Controls.Add(tc);

                l1 = new Label();
                l1.Text = sdr2.GetString(3);
                tc = new TableCell();
                tc.Controls.Add(l1);
                tr.Controls.Add(tc);

                l1 = new Label();
                l1.Text = "￥：" + Convert.ToString(sdr2.GetDecimal(4));
                tc = new TableCell();
                tc.Controls.Add(l1);
                tr.Controls.Add(tc);


                l1 = new Label();
                l1.Text = sdr2.GetString(6);
                tc = new TableCell();
                tc.Controls.Add(l1);
                tr.Controls.Add(tc);
                l1 = new Label();

                l1 = new Label();
                l1.Text = Convert.ToString(sdr2.GetInt32(5));
                tc = new TableCell();
                tc.Controls.Add(l1);
                tr.Controls.Add(tc);


                l1 = new Label();
                l1.Text = "￥：" + Convert.ToString(sdr2.GetInt32(5) * sdr2.GetDecimal(4));
                counttotal += sdr2.GetInt32(5) * sdr2.GetDecimal(4);
                tc = new TableCell();
                tc.Controls.Add(l1);
                tr.Controls.Add(tc);

                TB.Controls.Add(tr);
            }
            sdr2.Close();
            # endregion
            conn.Close();
        }
    }

    protected void ImageButton3_Click(object sender, ImageClickEventArgs e)
    {
        Doadmin.Exec("update Orderw set OrderState=20  where  id=" + Request.QueryString["id"]);
        Response.Redirect("orderlist.aspx");
    }
    protected void LinkButton2_Click(object sender, EventArgs e)
    {
        if (Doadmin.Exec("update Orderw set text1='" + this.TextBox1.Text + "'  where  id=" + Request.QueryString["id"]))
        {
            Response.Write("<script>alert('操作成功');window.location.href='orderlist.aspx';</script>");
        }
        else
        {
            Response.Write("<script>alert('操作失败');window.location.href='orderlist.aspx';</script>");
        }
    }
}
