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 txt = "";
        switch(DateTime.Now.Month)
        {
           case 1:
               smdt = new SqlCommand("select ProductName,sum(Amount) as am,sum(Amount*price) as am2 from OrderInfo where  DATEPART(year,addtime)='"+DateTime.Now.Year.ToString()+"' and DATEPART(month,addtime)='1' or DATEPART(month,addtime)='2' or DATEPART(month,addtime)='3' and OrderState=8 group by ProductName", conn);
               txt = "第一季度统计";
               break;
           case 2:
               smdt = new SqlCommand("select ProductName,sum(Amount) as am,sum(Amount*price) as am2 from OrderInfo where   DATEPART(year,addtime)='" + DateTime.Now.Year.ToString() + "' and  DATEPART(month,addtime)='1' or DATEPART(month,addtime)='2' or DATEPART(month,addtime)='3' and OrderState=8 group by ProductName", conn);
               txt = "第一季度统计";
               break;
           case 3:
               smdt = new SqlCommand("select ProductName,sum(Amount) as am,sum(Amount*price) as am2 from OrderInfo where  DATEPART(year,addtime)='" + DateTime.Now.Year.ToString() + "' and  DATEPART(month,addtime)='1' or DATEPART(month,addtime)='2' or DATEPART(month,addtime)='3' and OrderState=8 group by ProductName", conn);
               txt = "第一季度统计";
               break;
           case 4:
               smdt = new SqlCommand("select ProductName,sum(Amount) as am,sum(Amount*price) as am2 from OrderInfo where  DATEPART(year,addtime)='" + DateTime.Now.Year.ToString() + "' and  DATEPART(month,addtime)='4' or DATEPART(month,addtime)='5' or DATEPART(month,addtime)='6' and OrderState=8 group by ProductName", conn);
               txt = "第二季度统计";
               break;
           case 5:
               smdt = new SqlCommand("select ProductName,sum(Amount) as am,sum(Amount*price) as am2 from OrderInfo where  DATEPART(year,addtime)='" + DateTime.Now.Year.ToString() + "' and  DATEPART(month,addtime)='4' or DATEPART(month,addtime)='5' or DATEPART(month,addtime)='6' and OrderState=8 group by ProductName", conn);
               txt = "第二季度统计";
               break;
           case 6:
               smdt = new SqlCommand("select ProductName,sum(Amount) as am,sum(Amount*price) as am2 from OrderInfo where  DATEPART(year,addtime)='" + DateTime.Now.Year.ToString() + "' and  DATEPART(month,addtime)='4' or DATEPART(month,addtime)='5' or DATEPART(month,addtime)='6' and OrderState=8 group by ProductName", conn);
               txt = "第二季度统计";
               break;
           case 7:
               smdt = new SqlCommand("select ProductName,sum(Amount) as am,sum(Amount*price) as am2 from OrderInfo where  DATEPART(year,addtime)='" + DateTime.Now.Year.ToString() + "' and  DATEPART(month,addtime)='7' or DATEPART(month,addtime)='8' or DATEPART(month,addtime)='9' and OrderState=8 group by ProductName", conn);
               txt = "第三季度统计";
               break;
           case 8:
               smdt = new SqlCommand("select ProductName,sum(Amount) as am,sum(Amount*price) as am2 from OrderInfo where  DATEPART(year,addtime)='" + DateTime.Now.Year.ToString() + "' and  DATEPART(month,addtime)='7' or DATEPART(month,addtime)='8' or DATEPART(month,addtime)='9' and OrderState=8 group by ProductName", conn);
               txt = "第三季度统计";
               break;
           case 9:
               smdt = new SqlCommand("select ProductName,sum(Amount) as am,sum(Amount*price) as am2 from OrderInfo where  DATEPART(year,addtime)='" + DateTime.Now.Year.ToString() + "' and  DATEPART(month,addtime)='7' or DATEPART(month,addtime)='8' or DATEPART(month,addtime)='9' and OrderState=8 group by ProductName", conn);
               txt = "第三季度统计";
               break;
           case 10:
               smdt = new SqlCommand("select ProductName,sum(Amount) as am,sum(Amount*price) as am2 from OrderInfo where  DATEPART(year,addtime)='" + DateTime.Now.Year.ToString() + "' and  DATEPART(month,addtime)='10' or DATEPART(month,addtime)='11' or DATEPART(month,addtime)='12' and OrderState=8 group by ProductName", conn);
               txt = "第四季度统计";
               break;
           case 11:
               smdt = new SqlCommand("select ProductName,sum(Amount) as am,sum(Amount*price) as am2 from OrderInfo where  DATEPART(year,addtime)='" + DateTime.Now.Year.ToString() + "' and  DATEPART(month,addtime)='10' or DATEPART(month,addtime)='11' or DATEPART(month,addtime)='12' and OrderState=8 group by ProductName", conn);
               txt = "第四季度统计";
               break;
            case 12:
                smdt = new SqlCommand("select ProductName,sum(Amount) as am,sum(Amount*price) as am2 from OrderInfo where  DATEPART(year,addtime)='" + DateTime.Now.Year.ToString() + "' and  DATEPART(month,addtime)='10' or DATEPART(month,addtime)='11' or DATEPART(month,addtime)='12' and OrderState=8 group by ProductName", conn);
                txt = "第四季度统计";
                break;
        }
                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();
            this.Label1.Text = txt;
            this.Label2.Text = txt;
            switch(Convert.ToInt32(DateTime.Now.Month.ToString()))
            {
                case 1:
                    smdt = new SqlCommand("select sum(Amount*price) as am3 from OrderInfo where  DATEPART(year,addtime)='" + DateTime.Now.Year.ToString() + "' and  DATEPART(month,addtime)='1' or DATEPART(month,addtime)='2' or DATEPART(month,addtime)='3'  and OrderState=8", conn);
                    break;
                case 2:
                    smdt = new SqlCommand("select sum(Amount*price) as am3 from OrderInfo where  DATEPART(year,addtime)='" + DateTime.Now.Year.ToString() + "' and  DATEPART(month,addtime)='1' or DATEPART(month,addtime)='2' or DATEPART(month,addtime)='3'  and OrderState=8", conn);
                    break;
                case 3:
                    smdt = new SqlCommand("select sum(Amount*price) as am3 from OrderInfo where  DATEPART(year,addtime)='" + DateTime.Now.Year.ToString() + "' and  DATEPART(month,addtime)='1' or DATEPART(month,addtime)='2' or DATEPART(month,addtime)='3'  and OrderState=8", conn);
                    break;
                case 4:
                    smdt = new SqlCommand("select sum(Amount*price) as am3 from OrderInfo where  DATEPART(year,addtime)='" + DateTime.Now.Year.ToString() + "' and  DATEPART(month,addtime)='4' or DATEPART(month,addtime)='5' or DATEPART(month,addtime)='6'  and OrderState=8", conn);
                    break;
                case 5:
                    smdt = new SqlCommand("select sum(Amount*price) as am3 from OrderInfo where  DATEPART(year,addtime)='" + DateTime.Now.Year.ToString() + "' and  DATEPART(month,addtime)='4' or DATEPART(month,addtime)='5' or DATEPART(month,addtime)='6'  and OrderState=8", conn);
                    break;
                case 6:
                    smdt = new SqlCommand("select sum(Amount*price) as am3 from OrderInfo where  DATEPART(year,addtime)='" + DateTime.Now.Year.ToString() + "' and  DATEPART(month,addtime)='4' or DATEPART(month,addtime)='5' or DATEPART(month,addtime)='6'  and OrderState=8", conn);
                    break;
                case 7:
                    smdt = new SqlCommand("select sum(Amount*price) as am3 from OrderInfo where  DATEPART(year,addtime)='" + DateTime.Now.Year.ToString() + "' and  DATEPART(month,addtime)='7' or DATEPART(month,addtime)='8' or DATEPART(month,addtime)='9'  and OrderState=8", conn);
                    break;
                case 8:
                    smdt = new SqlCommand("select sum(Amount*price) as am3 from OrderInfo where  DATEPART(year,addtime)='" + DateTime.Now.Year.ToString() + "' and  DATEPART(month,addtime)='7' or DATEPART(month,addtime)='8' or DATEPART(month,addtime)='9'  and OrderState=8", conn);
                    break;
                case 9:
                    smdt = new SqlCommand("select sum(Amount*price) as am3 from OrderInfo where   DATEPART(year,addtime)='" + DateTime.Now.Year.ToString() + "' and DATEPART(month,addtime)='7' or DATEPART(month,addtime)='8' or DATEPART(month,addtime)='9'  and OrderState=8", conn);
                    break;
                case 10:
                    smdt = new SqlCommand("select sum(Amount*price) as am3 from OrderInfo where  DATEPART(year,addtime)='" + DateTime.Now.Year.ToString() + "' and  DATEPART(month,addtime)='10' or DATEPART(month,addtime)='11' or DATEPART(month,addtime)='12'  and OrderState=8", conn);
                    break;
                case 11:
                    smdt = new SqlCommand("select sum(Amount*price) as am3 from OrderInfo where  DATEPART(year,addtime)='" + DateTime.Now.Year.ToString() + "' and  DATEPART(month,addtime)='10' or DATEPART(month,addtime)='11' or DATEPART(month,addtime)='12'  and OrderState=8", conn);
                    break;
                case 12:
                    smdt = new SqlCommand("select sum(Amount*price) as am3 from OrderInfo where  DATEPART(year,addtime)='" + DateTime.Now.Year.ToString() + "' and  DATEPART(month,addtime)='10' or DATEPART(month,addtime)='11' or DATEPART(month,addtime)='12'  and OrderState=8", conn);
                    break;

            }
            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();
    }
}
