//修改 即添加小任务 分派到员工

        #region
        protected void SaveSuperviseAssign_Click(object sender, EventArgs e)
        {
            S_UserInFo user = null;
            int        num  = 0;

            try
            {
                user = (S_UserInFo)Session["User"];
                user.ToString();
            }
            catch (Exception s)
            {
                Response.Redirect("Login.aspx");
            }
            SuperviseMxBLL     superviseMxBLL     = new SuperviseMxBLL();
            SuperviseAssignBLL superviseAssignBLL = new SuperviseAssignBLL();
            R_SuperviseMx      superviseMx        = new R_SuperviseMx();
            int RID = int.Parse(Request.Params["ModifyRID"]);

            superviseMx.RID   = RID;
            superviseMx.Title = Request.Params["ModifyTitle"];
            string FinishDate = Request.Params["ModifyFinishDate"].ToString();

            superviseMx.Mender   = user.UserID;
            superviseMx.MendDate = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd"));

            //判断是否分派
            string            str              = Request.Params["ModifySetStaff"];
            int               assignID         = int.Parse(ModifyAssignID.Text);
            R_SuperviseAssign superviseAssign2 = superviseAssignBLL.FindSuperviseAssign(assignID);
            int               mxID             = 0;

            if (str == null || str == "")
            {//如果新建任务未分派 则 处理人依然是分派的部门
                if (FinishDate == null || FinishDate == "" || superviseMx.Title == "" || superviseMx.Title == null)
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "", "SetStyle()", true);
                    return;
                }
                else
                {
                    superviseMx.FinishDate = DateTime.Parse(FinishDate);
                    num  = superviseMxBLL.AddSuperviseMx(superviseMx);                      //新增小任务成功
                    mxID = superviseMxBLL.FindSuperviseMxID(Request.Params["ModifyTitle"]); //新增成功返回MxID   用来分派
                }
                R_SuperviseAssign superviseAssign = new R_SuperviseAssign();
                superviseAssign.RID       = int.Parse(Request.Params["ModifyRID"]);
                superviseAssign.MxID      = mxID;
                superviseAssign.AssignNo  = user.UserID;
                superviseAssign.ReplyMemo = "";
                superviseAssign.bSate     = 0;
                superviseAssign.Memo      = "";
                superviseAssign.Mender    = user.UserID;
                superviseAssign.MendDate  = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd"));
                num = superviseAssignBLL.AddsuperviseAssign(superviseAssign);

                superviseAssignBLL.DeleteSuperviseAssignByMxID(0, superviseAssign2.AssignNo);
            }
            else if (str != "" || str != null)
            {
                //如果分派 跟进人是分派的员工
                string   srt2   = str.Trim(',');
                string[] sArray = srt2.Split(',');
                if (FinishDate == null || FinishDate == "" || superviseMx.Title == "" || superviseMx.Title == null)
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "", "SetStyle()", true);
                    return;
                }
                else
                {
                    superviseMx.FinishDate = DateTime.Parse(FinishDate);
                    num  = superviseMxBLL.AddSuperviseMx(superviseMx);                      //新增小任务成功
                    mxID = superviseMxBLL.FindSuperviseMxID(Request.Params["ModifyTitle"]); //新增成功返回MxID   用来分派
                }
                R_SuperviseAssign superviseAssign = superviseAssignBLL.FindSuperviseAssign(assignID);
                superviseAssign.RID       = int.Parse(Request.Params["ModifyRID"]);
                superviseAssign.MxID      = mxID;
                superviseAssign.ReplyMemo = "";
                superviseAssign.bSate     = 0;
                superviseAssign.Memo      = "";
                superviseAssign.Mender    = user.UserID;
                superviseAssign.MendDate  = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd"));
                foreach (string i in sArray)
                {
                    superviseAssign.AssignNo = i.ToString();
                    num = superviseAssignBLL.AddsuperviseAssign(superviseAssign);
                    superviseAssignBLL.DeleteSuperviseAssignByMxID(0, superviseAssign2.AssignNo);
                }
            }
            if (num != 0)
            {
                Response.Write("<script language='javascript'>alert('新增任务成功!')</script>");
                Page_Load(sender, e);
            }
            else
            {
                Response.Write("<script language='javascript'>alert('新增任务失败!')</script>");
            }
        }
        //保存步骤修改
        #region
        protected void SaveSmallTtile_Click(object sender, EventArgs e)
        {
            SuperviseMxBLL superviseMxBLL = new SuperviseMxBLL();
            R_SuperviseMx  superviseMx    = superviseMxBLL.FindSuperviseMx(int.Parse(ModifyMxID.Text));
            S_UserInFo     user           = null;
            int            num            = 0;

            try
            {
                user = (S_UserInFo)Session["User"];
                user.ToString();
            }
            catch (Exception s)
            {
                Response.Redirect("Login.aspx");
            }
            superviseMx.Title = Request.Params["ModifySmallTitle"];
            string FinishDate = Request.Params["ModifyFinishDate2"].ToString();

            superviseMx.Mender   = user.UserID;
            superviseMx.MendDate = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd"));
            if (superviseMx.Title == null || superviseMx.Title == "" || FinishDate == null || FinishDate == "")
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "", "SetStyle()", true);
                return;
            }
            else
            {
                superviseMx.FinishDate = DateTime.Parse(FinishDate);
                superviseMxBLL.UpdateSuperviseMx(superviseMx);
                string   OldAssignStr2 = Session["OldStaff"].ToString().Trim(',');    //分割旧的部门主管
                string[] OldsArray     = OldAssignStr2.Split(',');
                string   NewAssignStr2 = Request.Params["ModifySetStaff2"].Trim(','); //分割新的部门主管
                string[] NewsArray     = NewAssignStr2.Split(',');
                foreach (string item in NewsArray)                                    //遍历intA中的元素
                {
                    if (!OldsArray.Contains(item))                                    //假如intA中的元素tem不包含在intB中
                    {
                        R_SuperviseAssign superviseAssign = new R_SuperviseAssign();
                        superviseAssign.RID       = int.Parse(ModifyRID3.Text);
                        superviseAssign.MxID      = int.Parse(ModifyMxID.Text);
                        superviseAssign.ReplyMemo = "";
                        superviseAssign.bSate     = 0;
                        superviseAssign.Memo      = "";
                        superviseAssign.Mender    = user.UserID;
                        superviseAssign.MendDate  = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd"));
                        superviseAssign.AssignNo  = item;
                        SuperviseAssignBLL superviseAssignBLL = new SuperviseAssignBLL();
                        superviseAssignBLL.DeleteSuperviseAssignByRIDandAssignNozero(int.Parse(ModifyRID3.Text));
                        num = superviseAssignBLL.AddsuperviseAssign(superviseAssign);
                    }
                }
            }
            if (num != 0)
            {
                Response.Write("<script language='javascript'>alert('步骤更新成功!')</script>");
                Page_Load(sender, e);
            }
            else
            {
                Response.Write("<script language='javascript'>alert('步骤更新失败!')</script>");
            }
        }
        //添加议题
        #region
        protected void AddSupervise_Click(object sender, EventArgs e)
        {
            SuperviseMxBLL     superviseMxBLL     = new SuperviseMxBLL();
            SuperviseAssignBLL superviseAssignBLL = new SuperviseAssignBLL();
            SuperviseBLL       superviseBLL       = new SuperviseBLL();
            S_UserInFo         user = null;
            int num = 0;

            try
            {
                user = (S_UserInFo)Session["User"];
                user.ToString();
            }
            catch (Exception s)
            {
                Response.Redirect("Login.aspx");
            }
            string str = Request.Params["SetDeptCharge"];//获取部门信息

            //如果不添加小任务
            if (Request.Params["AddSmallTitle"] == "" || Request.Params["AddSmallTitle"] == null)
            {
                R_Supervise supervise = new R_Supervise();
                supervise.SuperviseType = int.Parse(AddTypeList.SelectedValue);
                supervise.Title         = Request.Params["AddBigTitle"];
                supervise.Urgency       = int.Parse(AddUrgencyList.SelectedValue);
                if (supervise.Title == null || supervise.Title == "")
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "", "SetStyle()", true);
                    return;
                }
                else
                {
                    try
                    {
                        supervise.Mender = user.UserID;
                    }
                    catch (Exception ex)
                    {
                        Response.Redirect("Login.aspx");
                    }
                    supervise.MendDate = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd"));

                    num = superviseBLL.AddSupervise(supervise);                                  //新建议题后
                    R_Supervise supervise2 = superviseBLL.FindSuperviseByTitle(supervise.Title); //新增议题后 按议题内容查找刚刚添加的议题,进行任务添加



                    R_SuperviseAssign superviseAssign = new R_SuperviseAssign();
                    superviseAssign.RID       = supervise2.RID;
                    superviseAssign.MxID      = 0;
                    superviseAssign.ReplyMemo = "";
                    superviseAssign.bSate     = 0;
                    superviseAssign.Memo      = "";
                    superviseAssign.Mender    = user.UserID;
                    superviseAssign.MendDate  = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd"));
                    if (str == "" || str == null)
                    {
                        superviseAssign.AssignNo = "";
                        num = superviseAssignBLL.AddsuperviseAssign(superviseAssign);
                    }
                    else
                    {
                        string   srt2   = str.Trim(',');
                        string[] sArray = srt2.Split(',');
                        foreach (string i in sArray)
                        {
                            superviseAssign.AssignNo = i.ToString();
                            num = superviseAssignBLL.AddsuperviseAssign(superviseAssign);
                        }
                    }
                }
            }
            else if (Request.Params["AddSmallTitle"] != "" || Request.Params["AddSmallTitle"] != null)//如果要添加小任务
            {
                R_Supervise supervise = new R_Supervise();
                supervise.SuperviseType = int.Parse(AddTypeList.SelectedValue);
                supervise.Title         = Request.Params["AddBigTitle"];
                supervise.Urgency       = int.Parse(AddUrgencyList.SelectedValue);
                try
                {
                    supervise.Mender = user.UserID;
                }
                catch (Exception ex)
                {
                    Response.Redirect("Login.aspx");
                }
                supervise.MendDate = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd"));

                superviseBLL.AddSupervise(supervise);//新建议题后
                string        AddBigTitle = Request.Params["AddBigTitle"];
                R_Supervise   supervise2  = superviseBLL.FindSuperviseByTitle(AddBigTitle);
                R_SuperviseMx superviseMx = new R_SuperviseMx();
                superviseMx.Title = Request.Params["AddSmallTitle"];
                string FinishDate = Request.Params["AddFinishDate"].ToString();
                superviseMx.Mender   = user.UserID;
                superviseMx.MendDate = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd"));
                if (FinishDate == null || FinishDate == "")
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "", "SetStyle()", true);
                    return;
                }
                else
                {
                    superviseMx.FinishDate = DateTime.Parse(FinishDate);
                    num = superviseMxBLL.AddSuperviseMx(superviseMx);                         //添加小任务成功
                }
                int MxID = superviseMxBLL.FindSuperviseMxID(Request.Params["AddSmallTitle"]); //添加小任务成功后返回任务ID
                R_SuperviseAssign superviseAssign = new R_SuperviseAssign();
                superviseAssign.RID       = supervise2.RID;
                superviseAssign.MxID      = MxID;
                superviseAssign.ReplyMemo = "";
                superviseAssign.bSate     = 0;
                superviseAssign.Memo      = "";
                superviseAssign.Mender    = user.UserID;
                superviseAssign.MendDate  = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd"));
                if (str == "" || str == null)
                {
                    superviseAssign.AssignNo = "";
                    num = superviseAssignBLL.AddsuperviseAssign(superviseAssign);
                }
                else
                {
                    string   srt2   = str.Trim(',');
                    string[] sArray = srt2.Split(',');
                    foreach (string i in sArray)
                    {
                        superviseAssign.AssignNo = i.ToString();
                        num = superviseAssignBLL.AddsuperviseAssign(superviseAssign);
                    }
                }
            }
            if (num != 0)
            {
                Response.Write("<script language='javascript'>alert('新增议题成功!')</script>");
                LoadData();
                Page_Load(sender, e);
            }
            else
            {
                Response.Write("<script language='javascript'>alert('新增议题失败!')</script>");
            }
        }