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;

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

    public int id = BLL.BLLemployee.getMobile(System.Web.HttpContext.Current.Session["user"].ToString()).EmployeeID;
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
        {
            bind();
        }
    }
    public void bind()
    {
        AccessDataSource1.SelectParameters[0].DefaultValue = id.ToString();
        AccessDataSource1.Select(DataSourceSelectArguments.Empty);
    
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        { 
          e.Row.Attributes.Add("onmouseover","c=this.style.backgroundColor;this.style.backgroundColor='#ffff66'");
          e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
        }
    }
    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        string task=Convert.ToString(this.GridView1.DataKeys[e.RowIndex]["taskID"]);
        string getValue = ((DropDownList)(this.GridView1.Rows[e.RowIndex].Cells[2].FindControl("DropDownList1"))).SelectedValue;
        AccessDataSource1.UpdateParameters[0].DefaultValue = getValue;
        AccessDataSource1.UpdateParameters[1].DefaultValue = task;
        AccessDataSource1.Update();
        bind();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (this.CustomValidator1.IsValid == false)
        {
            msgBox.putMsg("名称有重复");
            return;
        }
        string taskName = this.TextBox1.Text;
        string taskInfo = this.TextArea1.Value;
        DateTime time = DateTime.Now;
        AccessDataSource1.InsertParameters[0].DefaultValue = taskName;
        AccessDataSource1.InsertParameters[1].DefaultValue = taskInfo;
        AccessDataSource1.InsertParameters[2].DefaultValue = time.ToString();
        AccessDataSource1.InsertParameters[3].DefaultValue = id.ToString();
        AccessDataSource1.Insert();
        bind();
        this.TextBox1.Text = "";
        this.TextArea1.Value = "";
        
    }

    protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
    {
        if (BLL.BLLtask.checkTask(args.Value) == false)
        {
            args.IsValid = false;
        }
        else
        {
            args.IsValid = true;
        }
    }
}
