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)
    {
        if (Session["WtoRightName"] == null)
        {
            Response.Redirect("~/SYSADMIN/main/error.aspx?err=非法登陆!或系统超时，请刷新后重新登录");
        }
        SqlConnection conn = CDatabase.wtoconn();
        conn.Open();
        DataTable dt = new DataTable();
        dt.Columns.Add("ph", typeof(int));
        dt.Columns.Add("pn", typeof(string));
        dt.Columns.Add("pa", typeof(string));
        dt.Columns.Add("xj", typeof(string));
        DataRow dr;
        SqlCommand smdt=new SqlCommand();
        SqlDataReader sdr;
        string  d1="";
        string  d2="";

        switch (DateTime.Now.DayOfWeek.ToString())
        {
            case "Monday":
                d1 = DateTime.Now.ToString();
                d2 = DateTime.Now.AddDays(6).ToString();
                break;
            case "Tuesday":
                d1 = DateTime.Now.AddDays(-1).ToString();
                d2 = DateTime.Now.AddDays(5).ToString();
                break;
            case "Wednesday":
                d1 = DateTime.Now.AddDays(-2).ToString();
                d2 = DateTime.Now.AddDays(4).ToString();
                break;
            case "Thursday":
                d1 = DateTime.Now.AddDays(-3).ToString();
                d2 = DateTime.Now.AddDays(3).ToString();
                break;
            case "Friday":
                d1 = DateTime.Now.AddDays(-4).ToString();
                d2 = DateTime.Now.AddDays(2).ToString();
                break;
            case "Saturday":
                d1 = DateTime.Now.AddDays(-5).ToString();
                d2 = DateTime.Now.AddDays(1).ToString();
                break;
            case "Sunday":
                d1 = DateTime.Now.AddDays(-6).ToString();
                d2 = DateTime.Now.ToString();
                break;
        }
        smdt = new SqlCommand("select ProductName,sum(Amount) as am,sum(Amount*price) as am2 from OrderInfo where addtime>'"+d1+"' and addtime<'"+d2+"' and OrderState=8 group by ProductName", conn);
        sdr = smdt.ExecuteReader();
        int ph = 0;
                while (sdr.Read())
                {
                    ph++;
                    dr = dt.NewRow();
                    dr["ph"] = ph;
                    dr["pn"] = sdr["ProductName"].ToString();
                    dr["pa"] = sdr["am"].ToString();
                    dr["xj"] = sdr["am2"].ToString();
                    dt.Rows.Add(dr);
                }
                sdr.Close();
            DataSet ds = new DataSet();
            ds.Tables.Add(dt);
            this.GridView1.DataSource = ds;
            this.GridView1.DataBind();

            smdt = new SqlCommand("select sum(Amount*price) as am3 from OrderInfo where  addtime>'" + d1 + "' and addtime<'" + d2 + "' and OrderState=8", conn);
            this.tt.Text = Convert.ToString(smdt.ExecuteScalar().ToString());
            this.dtme.Text = DateTime.Now.Date.ToString("d");
            this.ps.Text = dt.Rows.Count.ToString();
            
            if (dt.Rows.Count == 0)
            {
                this.Label5.Visible = true;
            }
            else
            {
                this.Label5.Visible = false;
            }
        
        conn.Close();
    }
}
