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.IO;

public partial class TaskList : System.Web.UI.UserControl
{

    # region 参数
    static string wherestring="";
    static string orderby="";
    static string linenum="22";
    static string TaskViewUrl="TaskView.aspx";
    static string TaskViewPath = "~/china/";
    static string TaskAddPlanKey = "~/images/task/TaskAddPlanKey.gif";



    public string MoneyWS(string ws) //处理金额条件
    {

        string moneywherestr = "";
        if (ws == "<1000")
        {
            moneywherestr = "money<=1000";

        }
        else
        {

            if (ws == ">1000 且 <2000")
            {
                moneywherestr = "money>1000 and money<=2000";

            }
            else
            {
                if (ws == ">2000 且 <5000")
                {
                    moneywherestr = "money>2000 and money<=5000";
                }
                else
                {
                    moneywherestr = "money>5000";
                }
            }
        }
        return moneywherestr;
    }

    public string OpenTaskViewUrl  //打开任务明细页的网页文件名
    {
        set
        {
            TaskViewUrl = value.ToString().Trim();
        }
    }
    public string OpenTaskViewPath   //打开任务明细页的路径
    {
        set
        {
            TaskViewPath = value.ToString().Trim();
        }
    }
    public string OpenTaskAddPlanKey   //参加任务的按钮
    {
        set
        {
            TaskAddPlanKey = value.ToString().Trim();
        }
    }
    public string WhereString
    {
        set
        {
            wherestring = value.ToString().Trim();
        }
    }
    public string OrderBy
    {
        set
        {
            orderby = value.ToString().Trim();
        }
    }
    public string LineNum//行数
    {
        set
        {
            linenum = value.ToString().Trim();
        }
    }
    #endregion

    protected string CategoryLink(string id)    
    {
        return Request.ServerVariables["URL"].ToString() + "?categoryid="+id;
    }

    protected string AddPlanKeyImg()
    {
        return TaskAddPlanKey;
    }

    
    protected void TaskDBList()
    {
        object RD2;
/*
        if (Session["TaskListFinish"].ToString() != "all")
        {
            wherestr1 = "finish='" + Session["TaskListFinish"].ToString() + "'";
        }
         * */

        if (wherestring!="")
        {
            wherestring="where "+wherestring;
        }
        if (orderby!="")
        {
            orderby="order by "+orderby;
        }

        if (linenum == "0")
        {
            RD2 = CDatabase.DBFillSelect("select * from TaksInfo " + wherestring + " " + orderby);
        }else{
            RD2 = CDatabase.DBFillSelect("select top " + linenum + " * from TaksInfo " + wherestring + " " + orderby);
        }
        TaskGridView2.DataSource = RD2;
        TaskGridView2.DataBind();
        CDatabase.CloseConn();
        //TaskListTextBox1.Text = Session["TaskListKeyword"].ToString();
        //Message.Text = "select * from TaksInfo where " + wherestr + " " + Session["TaskListOrderBy"].ToString() + "  " + Session["TaskCategoryID"].ToString();
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
        {
        }
        else
        {
            //*******获取选择参数
            /*
            if (Request["finish"] != null) //finish=false
            {
                Session["TaskListFinish"] = Request["finish"].ToString();
                if (Request["finish"].ToString() == "false")
                {
                    TaskKey02.CssClass = "TaskSelectNow";
                }
                else
                {

                    TaskKey03.CssClass = "TaskSelectNow";
                }
            }
            else
            {
                if (Session["TaskListFinish"] == null)
                {
                    Session["TaskListFinish"] = "all";

                }

                TaskKey01.CssClass = "TaskSelectNow";

            }
             */

            //分类显示
            if (Request["CategoryID"] != null)
            {
                Session["TaskCategoryID"] = Request["CategoryID"].ToString();
            }
            else
            {
                if (Session["TaskCategoryID"] == null)
                {
                    Session["TaskCategoryID"] = "0";
                }
            }

            //排序方式
            if (Session["TaskListOrderBy"] == null)
            {
                Session["TaskListOrderBy"] = " order by sdt desc";
            }
            if (Session["TaskListKeyword"] == null)
            {
                Session["TaskListKeyword"] = "";
            }




            //金额条件限制
            if (Request["Money"] != null)
            {
                wherestring = MoneyWS(Request["Money"].ToString());
              
            }
            else
            {
                wherestring = "money>0";
            }

            //是否显示完成的或未完成的
            if (Request["finish"] != null)
            {
                wherestring += " and finish='" + Request["finish"].ToString()+"'";

            }

            //关键字条件
            if (Request["kw"] != null)
            {
                wherestring += " and subject like '%" + Request["kw"].ToString()+"%'";

            }


            //==============总数
            /*
            if(Session["TaskListFinish"].ToString()=="all")
            {
                   TotalLabel.Text=CDatabase.DBReadData("select Count(*) as cc from TaksInfo"); 
            }else{

                TotalLabel.Text = CDatabase.DBReadData("select Count(*) as cc from TaksInfo where finish='" + Session["TaskListFinish"].ToString() + "'"); 

                }
            */
            /*
            object RD = CDatabase.DBSelect("select * from TaksCategory where pid=0 order by sort");
            TaskListDataList1.DataSource = RD;
            TaskListDataList1.DataBind();
            CDatabase.CloseConn();
            //TaskListPanel1.Visible = true;
            //ADDTaksPanel1.Visible = false; 
            */
            TaskDBList();

            if (Request["categoryID"] == null)
            {


            }
            else
            {
            }
        }
    }


    protected string SUBJECT(string id,string subject,string sdt,string edt)
    {

        return "第" + id + "号任务" + ":" + subject + " |  " + (Convert.ToDateTime(sdt)).ToShortDateString() + " ～ " + (Convert.ToDateTime(edt)).ToShortDateString();
    }

    protected string PLANNUM(string id)
    {
        return CDatabase.DBReadData("select count(*) as c from TaksPlan where tid=" + id);
    }

    protected string STATE(string f)
    {
        if (f == "true")
        {
            return "完成";
        }
        else
        {

            return "进行中";
        }
    }


    protected string CategoryMoneyText(string CID, string money)
    {
        return CDatabase.DBReadData("select category from takscategory where id=" + CID) + "<br>" + "￥" + money; ;

    }

    protected string CategoryMoneyBK(string money)
    {
        string css;
        if (Convert.ToUInt16(money) < 2000)
        {
            css = "Money-2000";
        }
        else
        {
            if (Convert.ToUInt16(money) < 5000)
            {
                css = "Money2000";
            }
            else
            {
                css = "Money5000";
            }

        }
        return css;


    }

    protected string CATEGORY(string CID)
    {
        return CDatabase.DBReadData("select category from takscategory where id="+CID);
    }
    protected string MONEY(string money)
    {
        return "￥" + money;
    }
    protected string SURPLUS(string sdt, string edt)
    {
        Task.FUNC su = new Task.FUNC();
        return su.SurplusDateTime(sdt, edt);
    }
    protected string ViewTimeOut(string sdt,string edt)
    {
      Task.FUNC su = new Task.FUNC();
      string re=su.SurplusDateTime(sdt, edt);
        if (re=="-")
        {
            return "投稿截止";
        }else{
            return "剩余时间<br>"+re;
        }

    }



    protected string Link(string c, string i)
    {
        return Request.ServerVariables["URL"].ToString()+"?category=" + c + "&categoryid=" + i;

    }
    public static AjaxControlToolkit.CascadingDropDownNameValue[] GetDropDownContents(string knownCategoryValues, string category)
    {
        return default(AjaxControlToolkit.CascadingDropDownNameValue[]);
    }

   
    protected void TaskListLinkButton2_Click(object sender, EventArgs e)
    {
        //Session["TaskListKeyword"] = TaskListTextBox1.Text;
        TaskDBList();
    }

    protected string TASKVIEWURL(string id)
    {
        return TaskViewPath+TaskViewUrl + "?taskid=" + id;

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

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



    }
    protected void TaskGridView2_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        this.TaskGridView2.PageIndex = e.NewPageIndex;
        this.TaskGridView2.DataBind();
    }
}
