protected void bt_Disable_Click(object sender, EventArgs e)
    {
        EWF_ApproveAgencyBLL bll = new EWF_ApproveAgencyBLL((int)ViewState["ID"]);
        bll.Model.EnableFlag = "N";
        bll.Model.UpdateStaff = (int)Session["UserID"];
        bll.Update();

        MessageBox.ShowAndRedirect(this, "失效成功", "ApproveAgencyList.aspx");
    }
    protected void bt_Disable_Click(object sender, EventArgs e)
    {
        EWF_ApproveAgencyBLL bll = new EWF_ApproveAgencyBLL((int)ViewState["ID"]);

        bll.Model.EnableFlag  = "N";
        bll.Model.UpdateStaff = (int)Session["UserID"];
        bll.Update();

        MessageBox.ShowAndRedirect(this, "失效成功", "ApproveAgencyList.aspx");
    }
    protected void bt_Disable_Click(object sender, EventArgs e)
    {
        foreach (GridViewRow row in gv_List.Rows)
        {
            CheckBox cbx_Check = (CheckBox)row.FindControl("cbx_Check");

            if (cbx_Check != null && cbx_Check.Visible && cbx_Check.Checked)
            {
                int id = (int)gv_List.DataKeys[row.RowIndex][0];
                EWF_ApproveAgencyBLL agencybll = new EWF_ApproveAgencyBLL(id);

                agencybll.Model.EnableFlag = "N";
                agencybll.Model.UpdateStaff = (int)Session["UserID"];
                agencybll.Update();
            }
        }

        BindGrid();
    }
    protected void bt_Disable_Click(object sender, EventArgs e)
    {
        foreach (GridViewRow row in gv_List.Rows)
        {
            CheckBox cbx_Check = (CheckBox)row.FindControl("cbx_Check");

            if (cbx_Check != null && cbx_Check.Visible && cbx_Check.Checked)
            {
                int id = (int)gv_List.DataKeys[row.RowIndex][0];
                EWF_ApproveAgencyBLL agencybll = new EWF_ApproveAgencyBLL(id);

                agencybll.Model.EnableFlag  = "N";
                agencybll.Model.UpdateStaff = (int)Session["UserID"];
                agencybll.Update();
            }
        }

        BindGrid();
    }
    protected void bt_Save_Click(object sender, EventArgs e)
    {
        if ((int)ViewState["ID"] == 0)
        {
            EWF_ApproveAgencyBLL bll = new EWF_ApproveAgencyBLL();
            pl_detail.GetData(bll.Model);

            if (bll.Model.AgentStaff == 0)
            {
                MessageBox.Show(this, "请选择代理人!");
                return;
            }

            if (bll.Model.BeginDate < DateTime.Today)
            {
                MessageBox.Show(this, "起始日期不能小于今天!");
                return;
            }

            if (bll.Model.EndDate.Year != 1900 && bll.Model.BeginDate > bll.Model.EndDate)
            {
                MessageBox.Show(this, "截止日期不能小于起始日期!");
                return;
            }

            if (cbx_AppList.SelectedIndex == -1)
            {
                MessageBox.Show(this, "请选择待授权的工作流!");
                return;
            }

            bll.Model.EnableFlag  = "Y";
            bll.Model.ApproveFlag = 2;
            bll.Model.InsertStaff = (int)Session["UserID"];
            foreach (ListItem item in cbx_AppList.Items)
            {
                if (item.Selected)
                {
                    bll.Model.App = new Guid(item.Value);
                    bll.Add();
                }
            }
        }
        else
        {
            EWF_ApproveAgencyBLL bll = new EWF_ApproveAgencyBLL((int)ViewState["ID"]);

            DateTime orgBeginDate = bll.Model.BeginDate;
            DateTime orgEndDate   = bll.Model.EndDate;

            pl_detail.GetData(bll.Model);

            if (bll.Model.BeginDate < DateTime.Today && bll.Model.BeginDate != orgBeginDate)
            {
                MessageBox.Show(this, "起始日期不能小于今天!");
                return;
            }
            if (bll.Model.EndDate < DateTime.Today && bll.Model.EndDate != orgEndDate)
            {
                MessageBox.Show(this, "截止日期不能小于今天!");
                return;
            }

            if (bll.Model.AgentStaff == 0)
            {
                MessageBox.Show(this, "请选择代理人!");
                return;
            }

            bll.Model.UpdateStaff = (int)Session["UserID"];
            bll.Update();
        }

        Response.Redirect("ApproveAgencyList.aspx");
    }
    protected void bt_Save_Click(object sender, EventArgs e)
    {
        if ((int)ViewState["ID"] == 0)
        {
            EWF_ApproveAgencyBLL bll = new EWF_ApproveAgencyBLL();
            pl_detail.GetData(bll.Model);

            if (bll.Model.AgentStaff == 0)
            {
                MessageBox.Show(this, "请选择代理人!");
                return;
            }

            if (bll.Model.BeginDate < DateTime.Today)
            {
                MessageBox.Show(this, "起始日期不能小于今天!");
                return;
            }

            if (bll.Model.EndDate.Year != 1900 && bll.Model.BeginDate > bll.Model.EndDate)
            {
                MessageBox.Show(this, "截止日期不能小于起始日期!");
                return;
            }

            if (cbx_AppList.SelectedIndex == -1)
            {
                MessageBox.Show(this, "请选择待授权的工作流!");
                return;
            }

            bll.Model.EnableFlag = "Y";
            bll.Model.ApproveFlag = 2;
            bll.Model.InsertStaff = (int)Session["UserID"];
            foreach (ListItem item in cbx_AppList.Items)
            {
                if (item.Selected)
                {
                    bll.Model.App = new Guid(item.Value);
                    bll.Add();
                }
            }
        }
        else
        {
            EWF_ApproveAgencyBLL bll = new EWF_ApproveAgencyBLL((int)ViewState["ID"]);

            DateTime orgBeginDate = bll.Model.BeginDate;
            DateTime orgEndDate = bll.Model.EndDate;

            pl_detail.GetData(bll.Model);

            if (bll.Model.BeginDate < DateTime.Today && bll.Model.BeginDate != orgBeginDate)
            {
                MessageBox.Show(this, "起始日期不能小于今天!");
                return;
            }
            if (bll.Model.EndDate < DateTime.Today && bll.Model.EndDate != orgEndDate)
            {
                MessageBox.Show(this, "截止日期不能小于今天!");
                return;
            }

            if (bll.Model.AgentStaff == 0)
            {
                MessageBox.Show(this, "请选择代理人!");
                return;
            }

            bll.Model.UpdateStaff = (int)Session["UserID"];
            bll.Update();
        }

        Response.Redirect("ApproveAgencyList.aspx");
    }