protected void Page_Load(object sender, EventArgs e)
        {
            _trainDetaiRepo = RepositoryFactory.CreateTrainDetailRepo();
            if (!Authentication.HasResource(User.Identity.Name, "ProcessWorkflowList"))
            {
                Response.Redirect(@"/account/logon.aspx?ReturnUrl=%2f");
            }

            if (!IsPostBack)
            {
                _processwfRepo = RepositoryFactory.CreateProcessWorkflowRepo();
                _rootRepo      = RepositoryFactory.CreateRootRepo();

                //從QueryString取得 簽核文件代碼
                if (String.IsNullOrWhiteSpace(Request["SignDocID"]))
                {
                    Response.Write("需要簽核文件代碼!".ToAlertFormat());
                    return;
                }

                ProcessWorkflowViewModel model = _processwfRepo.GetWorkflowDataAndCheck(Request["SignDocID"], User.Identity.Name);
                if (model == null)
                {
                    Response.Write("查無簽核流程資料!".ToAlertFormat());
                    return;
                }

                //將 viewModel 的值綁定到 頁面上
                WebUtils.PageDataBind(model, this.Page);
                SignDocID_FK.Value = model.SignDocID;

                FormContent1.Attributes.Add("Src", ConstructAspxPage(model.SignDocID, model.FormID_FK));
            }
            PageInit();
        }
        //取得簽核主表資料
        public ProcessWorkflowViewModel GetWorkflowData(string signDocID)
        {
            ProcessWorkflowViewModel model = null;
            string strSQL       = @"Select * from SignForm_Main where SignDocID = @SignDocID";
            var    strCondition = new Conditions()
            {
                { "@SignDocID", signDocID }
            };

            var result = _dc.QueryForDataRow(strSQL, strCondition);

            if (result == null)
            {
                return(null);
            }

            model = new ProcessWorkflowViewModel()
            {
                SignDocID                 = result["SignDocID"].ToString(),
                FormID_FK                 = Int32.Parse(result["FormID_FK"].ToString()),
                EmployeeID_FK             = result["EmployeeID_FK"].ToString(),
                SendDate                  = !result["SendDate"].IsDBNullOrWhiteSpace() ? DateTime.Parse(result["SendDate"].ToString()) : (DateTime?)null,
                CurrentSignLevelDeptID_FK = result["CurrentSignLevelDeptID_FK"].ToString(),
                FinalStatus               = Int32.Parse(result["FinalStatus"].ToString()),
                Creator            = result["Creator"].ToString(),
                CreateDate         = DateTime.Parse(result["CreateDate"].ToString()),
                Modifier           = result["Modifier"].ToString(),
                ModifyDate         = !result["ModifyDate"].IsDBNullOrWhiteSpace() ? DateTime.Parse(result["ModifyDate"].ToString()) : (DateTime?)null,
                WorkflowDetailList = GetWorkflowDataDetail(result["SignDocID"].ToString())
            };

            return(model);
        }
        //明細是否存在主管簽核(針對跨部門相同主管)
        public ProcessWorkflowViewModel GetChiefID(string SignDocID_FK, string ChiefID_FK)
        {
            var conditions = new Conditions()
            {
                { "@SignDocID_FK", SignDocID_FK },
                { "@ChiefID_FK", ChiefID_FK }
            };
            var sql  = @"Select * from SignForm_Detail where SignDocID_FK = @SignDocID_FK and ChiefID_FK=@ChiefID_FK";
            var rows = _dc.QueryForRowsCount(sql, conditions);
            ProcessWorkflowViewModel model = new ProcessWorkflowViewModel()
            {
            };

            return(model);
        }
Ejemplo n.º 4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Authentication.HasResource(User.Identity.Name, "OvertimeList"))
            {
                Response.Redirect(@"/account/logon.aspx?ReturnUrl=%2f");
            }

            if (!IsPostBack)
            {
                _overitmeRepo = RepositoryFactory.CreateOvertimeRepo();
                _rootRepo     = RepositoryFactory.CreateRootRepo();
                _smartRepo    = RepositoryFactory.CreateSmartManRepo();

                // 取得 QueryString
                var paggerParms   = WebUtils.ParseQueryString <PaggerParms>(Page.Request);
                var signListParms = WebUtils.ParseQueryString <SignListParms>(Page.Request);
                signListParms.GridView      = OvertimeGridView;
                signListParms.PaginationBar = paginationBar;

                //根據查詢的 簽核代碼 搜尋加班單
                var pagination = _overitmeRepo.GetOvertimeListPagination(signListParms, paggerParms);

                if (pagination == null)
                {
                    return;
                }

                //設定 gridView Source
                ViewUtils.SetGridView(OvertimeGridView, pagination.Data);

                //Pagination Bar Generator
                string paginationHtml = WebUtils.GetPagerNumericString(pagination, Request);
                paginationBar.InnerHtml = paginationHtml;


                model = _overitmeRepo.GetWorkflowData(signListParms.SignDocID);
                WebUtils.PageDataBind(model, this.Page);
                Signed.NavigateUrl = "~/Area/Sign/WorkflowDetail.aspx?signDocID=" + signListParms.SignDocID;
                if (model == null)
                {
                    return;
                }
                var employeeData = _rootRepo.QueryForEmployeeByEmpID(model.EmployeeID_FK);
                ApplyName.Text = employeeData != null ? employeeData["EmployeeName"].ToString() : String.Empty;
            }
        }
        public ProcessWorkflowViewModel GetWorkflowData(string signDocID, string status = "2")
        {
            string strSQL =
                @"select m.*, t.SignID_FK as SignID_FK from signform_main m
             left outer join signtype t on m.formid_FK = t.formid
             where m.SignDocID = @SignDocID ";
            var strCondition = new Conditions()
            {
                { "@SignDocID", signDocID }
            };

            if (!String.IsNullOrEmpty(status))
            {
                strSQL = String.Concat(strSQL, " and m.FinalStatus = @FinalStatus");
                strCondition.Add("@FinalStatus", status);
            }

            var result = _dc.QueryForDataRow(strSQL, strCondition);

            if (result == null)
            {
                return(null);
            }

            ProcessWorkflowViewModel model = new ProcessWorkflowViewModel()
            {
                SignDocID                 = result["SignDocID"].ToString(),
                FormID_FK                 = Int32.Parse(result["FormID_FK"].ToString()),
                EmployeeID_FK             = result["EmployeeID_FK"].ToString(),
                SendDate                  = !result["SendDate"].IsDBNullOrWhiteSpace() ? DateTime.Parse(result["SendDate"].ToString()) : (DateTime?)null,
                CurrentSignLevelDeptID_FK = result["CurrentSignLevelDeptID_FK"].ToString(),
                FinalStatus               = Int32.Parse(result["FinalStatus"].ToString()),
                Remainder                 = Int32.Parse(result["Remainder"].ToString()),
                RuleID_FK                 = result["SignID_FK"].ToString(),
                Creator            = result["Creator"].ToString(),
                CreateDate         = DateTime.Parse(result["CreateDate"].ToString()),
                Modifier           = result["Modifier"].ToString(),
                ModifyDate         = !result["ModifyDate"].IsDBNullOrWhiteSpace() ? DateTime.Parse(result["ModifyDate"].ToString()) : (DateTime?)null,
                WorkflowDetailList = GetWorkflowDataDetail((string)result["SignDocID"])
            };

            return(model);
        }
        public ProcessWorkflowViewModel GetWorkflowDataAndCheck(string signDocID, string adAccount)
        {
            ProcessWorkflowViewModel model = null;
            string strSQL =
                @"SELECT *
FROM   signform_main
WHERE  signdocid = @SignDocID AND finalstatus = 2 AND
	EXISTS (SELECT *
			FROM   signform_detail
			WHERE  signdocid_fk = @SignDocID AND chiefid_fk = @ChiefID_FK AND status = 2) "            ;

            var chiefData    = _rootRepo.QueryForEmployeeByADAccount(adAccount);
            var strCondition = new Conditions()
            {
                { "@SignDocID", signDocID },
                { "@ChiefID_FK", chiefData != null ? chiefData["EmployeeID"].ToString() : (string)null }
            };

            var result = _dc.QueryForDataRow(strSQL, strCondition);

            if (result == null)
            {
                return(null);
            }

            model = new ProcessWorkflowViewModel()
            {
                SignDocID                 = result["SignDocID"].ToString(),
                FormID_FK                 = Int32.Parse(result["FormID_FK"].ToString()),
                EmployeeID_FK             = result["EmployeeID_FK"].ToString(),
                SendDate                  = !result["SendDate"].IsDBNullOrWhiteSpace() ? DateTime.Parse(result["SendDate"].ToString()) : (DateTime?)null,
                CurrentSignLevelDeptID_FK = result["CurrentSignLevelDeptID_FK"].ToString(),
                FinalStatus               = Int32.Parse(result["FinalStatus"].ToString()),
                Creator            = result["Creator"].ToString(),
                CreateDate         = DateTime.Parse(result["CreateDate"].ToString()),
                Modifier           = result["Modifier"].ToString(),
                ModifyDate         = !result["ModifyDate"].IsDBNullOrWhiteSpace() ? DateTime.Parse(result["ModifyDate"].ToString()) : (DateTime?)null,
                WorkflowDetailList = GetWorkflowDataDetail(result["SignDocID"].ToString())
            };

            return(model);
        }
Ejemplo n.º 7
0
        /*
         *  Main 狀態:
         * 1 草稿
         * 2 待簽核
         * 3 核准
         * 4 駁回
         * 5 取消
         * 6 結案
         * 7 歸檔
         *  Detial 狀態:
         * 1
         * 2 待簽核
         * 3 核准
         * 4 駁回
         * 5 取消
         * 6
         * 7
         */

        /// <summary>
        /// 簽核處理函式
        /// </summary>
        /// <param name="workflowModel"></param>
        /// <param name="sqlDML"></param>
        /// <param name="orgSupervisorID"></param>
        public void ProcessIdentify(ProcessWorkflowViewModel workflowModel, List <MultiConditions> sqlDML, string orgSupervisorID)
        {
            var sqlList = new List <MultiConditions>();

            //var detail = workflowModel.WorkflowDetailList.Single(row => orgSupervisorID.Equals(row.ChiefID_FK));

            #region 0020 會有多筆資料 不該用Single

            var detail = workflowModel.WorkflowDetailList.FirstOrDefault(row => orgSupervisorID.Equals(row.ChiefID_FK));

            #endregion 0020 會有多筆資料 不該用Single

            if (detail.Status == 4)
            {
                //駁回
                workflowModel.FinalStatus = detail.Status;
                var rejectDML = ProcesswfRepo.GetRejectSQLDML(workflowModel, orgSupervisorID);

                //加入DML
                sqlList.AddRange(sqlDML);
                sqlList.AddRange(rejectDML);
            }
            else if (workflowModel.WorkflowDetailList.All(row => row.Status == 3))
            {
                //會簽只差本次主管同意,同意後寫入DB並上呈簽核
                var nextDML = ProcesswfRepo.GetNextSQLDML(workflowModel, orgSupervisorID);

                //加入DML
                sqlList.Add(sqlDML.Last());
                sqlList.AddRange(nextDML);
            }
            else
            {
                //不符合以上情形,簽核結果直接寫入DB
                sqlList.AddRange(sqlDML);
            }

            ProcesswfRepo.ExecuteSQL(sqlList);
        }
        /// <summary>
        /// 上呈簽核SQL(判斷是否還有上層需要簽核)
        /// </summary>
        /// <param name="mainModel"></param>
        /// <param name="currentSignerID"></param>
        /// <returns></returns>
        public List <MultiConditions> GetNextSQLDML(ProcessWorkflowViewModel mainModel, string currentSignerID)
        {
            var result = new List <MultiConditions>();

            //取出指定明細
            //var detailModel = mainModel.WorkflowDetailList.Single(row => currentSignerID.Equals(row.ChiefID_FK));

            #region 0020 會有多筆資料 不該用Single

            var detailModel = mainModel.WorkflowDetailList.FirstOrDefault(row => currentSignerID.Equals(row.ChiefID_FK));

            #endregion 0020 會有多筆資料 不該用Single

            //更新時間
            mainModel.ModifyDate   = DateTime.Now;
            detailModel.ModifyDate = mainModel.ModifyDate;
            mainModel.Creator      = null;
            mainModel.CreateDate   = new DateTime();

            //更新修改人員
            mainModel.Modifier = detailModel.Modifier;

            //找尋上層簽核部門資料
            var upperDeptData = FindUpperDeptData(mainModel.CurrentSignLevelDeptID_FK, currentSignerID);
            var isFollowRule  = IsFollowFlowRule(mainModel.RuleID_FK, upperDeptData.Values.Single(), mainModel.Remainder);

            var        sql        = String.Empty;
            Conditions conditions = null;
            //確認當前部門是否符合上呈簽核規則
            if (isFollowRule)
            {
                //符合上呈簽核規則 卻沒有上層簽核 => 發生Exception
                if (upperDeptData == null || upperDeptData.Count == 0)
                {
                    throw new MissingMemberException(String.Format("簽核發生符合規則卻找不到上層簽核部門的例外!"));
                }

                //符合上呈簽核規則 且 有上層簽核

                //確認是否有額外的會簽人員
                var otherChiefCount = GetWorkflowDataDetail(mainModel.SignDocID).Count;
                if (otherChiefCount > 1)
                {
                    //刪除不是當前簽核主管的會簽人員
                    sql =
                        @"Delete SignForm_Detail Where SignDocID_FK = @SignDocID_FK and ChiefID_FK <> @OrgSupervisorID ";
                    conditions = new Conditions();
                    conditions.Add("@SignDocID_FK", detailModel.SignDocID_FK);
                    conditions.Add("@OrgSupervisorID", currentSignerID);
                    result.Add(new MultiConditions()
                    {
                        { sql, conditions }
                    });
                }

                //更改主表簽核部門
                mainModel.CurrentSignLevelDeptID_FK = upperDeptData.Values.Single();
                sql =
                    @"UPDATE signform_main
                SET currentsignleveldeptid_fk = @CurrentSignLevelDeptID_FK, remainder = @Remainder, modifier = @Modifier, modifydate = @ModifyDate WHERE  signdocid = @SignDocID ";
                conditions = new Conditions();
                conditions.Add("@CurrentSignLevelDeptID_FK", mainModel.CurrentSignLevelDeptID_FK);
                conditions.Add("@Remainder", --mainModel.Remainder);
                conditions.Add("@Modifier", mainModel.Modifier);
                conditions.Add("@ModifyDate", mainModel.ModifyDate);
                conditions.Add("@SignDocID", mainModel.SignDocID);
                result.Add(new MultiConditions()
                {
                    { sql, conditions }
                });

                //更改子表簽核人員
                detailModel.ChiefID_FK = upperDeptData.Keys.Single();
                detailModel.Status     = 2;
                detailModel.Remark     = String.Empty;
                sql =
                    @"UPDATE signform_detail
                SET chiefid_fk = @ChiefID_FK, status = @Status, remark = @Remark,modifier = @Modifier, modifydate = @ModifyDate WHERE  signdocid_fk = @SignDocID AND chiefid_fk = @OrgSupervisorID ";
                conditions = new Conditions();
                conditions.Add("@ChiefID_FK", detailModel.ChiefID_FK);
                conditions.Add("@Status", detailModel.Status);
                conditions.Add("@Remark", detailModel.Remark);
                conditions.Add("@SignDocID", detailModel.SignDocID_FK);
                conditions.Add("@OrgSupervisorID", currentSignerID);
                conditions.Add("@Modifier", detailModel.Modifier);
                conditions.Add("@ModifyDate", detailModel.ModifyDate);
                result.Add(new MultiConditions()
                {
                    { sql, conditions }
                });
            }
            else
            {
                //不符合規則,表示已經到終點

                //指派當前簽核人員
                detailModel.ChiefID_FK = currentSignerID;

                //更改主表狀態 為結案
                sql =
                    @"Update SignForm_Main Set FinalStatus = '6', remainder = @Remainder, modifier = @Modifier, modifydate = @ModifyDate Where SignDocID = @SignDocID ";
                mainModel.FinalStatus = 6;
                conditions            = new Conditions();
                conditions.Add("@Remainder", --mainModel.Remainder);
                conditions.Add("@SignDocID", mainModel.SignDocID);
                conditions.Add("@Modifier", mainModel.Modifier);
                conditions.Add("@ModifyDate", mainModel.ModifyDate);
                result.Add(new MultiConditions()
                {
                    { sql, conditions }
                });

                //更改子表狀態
                sql =
                    @"Update SignForm_Detail Set Status = @Status, modifier = @Modifier, modifydate = @ModifyDate Where SignDocID_FK = @SignDocID_FK ";
                conditions         = new Conditions();
                detailModel.Status = 6;
                detailModel.Remark = String.Empty;
                conditions.Add("@Status", detailModel.Status);
                conditions.Add("@SignDocID_FK", detailModel.SignDocID_FK);
                conditions.Add("@Modifier", detailModel.Modifier);
                conditions.Add("@ModifyDate", detailModel.ModifyDate);
                result.Add(new MultiConditions()
                {
                    { sql, conditions }
                });

                //轉交 AutoInsertHandler

                #region 決定將寫入志元與否

                AutoInsertHandler autoInsert = RepositoryFactory.CreateAutoInsert(mainModel.SignDocID);

                #endregion 決定將寫入志元與否

                var autoInsertDML = autoInsert.GetDML();
                if (autoInsertDML != null)
                {
                    //windows server2003 DTC 設定 交易管理通訊雙方必須設定為 不需驗證
                    result.Add(autoInsert.GetXACTABORTON());
                    result.AddRange(autoInsertDML);
                }
            }

            //log
            conditions = new Conditions()
            {
                { "@SignDocID_FK", mainModel != null ? mainModel.SignDocID : (string)null },
                { "@FormID_FK", mainModel != null?mainModel.FormID_FK.ToString() : (string)null },
                { "@EmployeeID_FK", mainModel != null ? mainModel.EmployeeID_FK : (string)null },
                { "@SendDate", mainModel != null?mainModel.SendDate.Value.FormatDatetime() : (string)null },
                { "@CurrentSignLevelDeptID_FK", mainModel != null ? mainModel.CurrentSignLevelDeptID_FK : (string)null },
                { "@FinalStatus", mainModel != null?mainModel.FinalStatus.ToString() : (string)null },
                { "@Remainder", mainModel != null?mainModel.Remainder.ToString() : (string)null },
                { "@Creator_Main", mainModel != null ? mainModel.Creator : (string)null },
                { "@CreateDate_Main", mainModel != null && mainModel.CreateDate != DateTime.MinValue ? mainModel.CreateDate.FormatDatetime() : (string)null },
                { "@Modifier_Main", mainModel != null ? mainModel.Modifier : (string)null },
                { "@ModifyDate_Main", mainModel != null && mainModel.ModifyDate != DateTime.MinValue ? mainModel.ModifyDate.Value.FormatDatetime() :(string)null },
                { "@DetailSignDocID_FK", detailModel != null ? detailModel.SignDocID_FK : (string)null },
                { "@ChiefID_FK", detailModel != null ? detailModel.ChiefID_FK : (string)null },
                { "@Remark", detailModel != null ? detailModel.Remark : (string)null },
                { "@Status", detailModel != null?detailModel.Status.ToString() : (string)null },
                { "@Creator_Detail", detailModel != null ? detailModel.Creator : (string)null },
                { "@CreateDate_Detail", detailModel != null && detailModel.CreateDate != DateTime.MinValue ? detailModel.CreateDate.FormatDatetime() : (string)null },
                { "@Modifier_Detail", detailModel != null ? detailModel.Modifier : (string)null },
                { "@ModifyDate_Detail", detailModel != null && detailModel.ModifyDate != DateTime.MinValue ? detailModel.ModifyDate.Value.FormatDatetime(): (string)null },
                { "@LogDatetime", DateTime.Now },
            };

            var log = _dc.ConstructInsertDML("SignForm_Log", conditions);
            result.Add(new MultiConditions()
            {
                { log, conditions }
            });

            return(result);
        }
        //駁回SQL
        public List <MultiConditions> GetRejectSQLDML(ProcessWorkflowViewModel mainModel, string orgSupervisorID)
        {
            var result = new List <MultiConditions>();

            //取得原始簽核規則
            var procedureData = _rootRepo.QueryForSignProcedureBySignDocID(mainModel.SignDocID);

            mainModel.Remainder  = Int32.Parse(procedureData["SignLevel"].ToString());
            mainModel.ModifyDate = DateTime.Now;
            mainModel.Modifier   = _rootRepo.QueryForEmployeeByEmpID(orgSupervisorID)["ADAccount"].ToString();

            //駁回後即送回原部門 改Main 為最初設定 狀態為駁回
            var sql =
                @"UPDATE signform_main
                    SET    finalstatus = @FinalStatus,
                    currentsignleveldeptid_fk = @CurrentSignLevelDeptID_FK,
                    remainder = @remainder,
                    modifier = @Modifier,
                    modifydate = @ModifyDate
                    WHERE  signdocid = @SignDocID ";
            var conditions = new Conditions();

            conditions.Add("@FinalStatus", mainModel.FinalStatus);
            conditions.Add("@CurrentSignLevelDeptID_FK", mainModel.CurrentSignLevelDeptID_FK);
            conditions.Add("@Remainder", mainModel.Remainder);
            conditions.Add("@Modifier", mainModel.Modifier);
            conditions.Add("@ModifyDate", mainModel.ModifyDate);
            conditions.Add("@SignDocID", mainModel.SignDocID);
            result.Add(new MultiConditions()
            {
                { sql, conditions }
            });

            //刪除Detail資料
            sql =
                @"Delete SignForm_Detail Where SignDocID_FK = @SignDocID ";
            conditions = new Conditions();
            conditions.Add("@SignDocID", mainModel.SignDocID);
            result.Add(new MultiConditions()
            {
                { sql, conditions }
            });

            mainModel.Creator    = (string)null;
            mainModel.CreateDate = new DateTime();

            //log
            conditions = new Conditions()
            {
                { "@SignDocID_FK", mainModel != null ? mainModel.SignDocID : (string)null },
                { "@FormID_FK", mainModel != null?mainModel.FormID_FK.ToString() : (string)null },
                { "@EmployeeID_FK", mainModel != null ? mainModel.EmployeeID_FK : (string)null },
                { "@SendDate", mainModel != null?mainModel.SendDate.Value.FormatDatetime() : (string)null },
                { "@CurrentSignLevelDeptID_FK", mainModel != null ? mainModel.CurrentSignLevelDeptID_FK : (string)null },
                { "@FinalStatus", mainModel != null?mainModel.FinalStatus.ToString() : (string)null },
                { "@Remainder", mainModel != null?mainModel.Remainder.ToString() : (string)null },
                { "@Creator_Main", mainModel != null ? mainModel.Creator : (string)null },
                { "@CreateDate_Main", mainModel != null && mainModel.CreateDate != DateTime.MinValue ? mainModel.CreateDate.FormatDatetime() : (string)null },
                { "@Modifier_Main", mainModel != null ? mainModel.Modifier : (string)null },
                { "@ModifyDate_Main", mainModel != null && mainModel.ModifyDate != DateTime.MinValue ? mainModel.ModifyDate.Value.FormatDatetime() :(string)null },
                { "@LogDatetime", DateTime.Now },
            };

            var log = _dc.ConstructInsertDML("SignForm_Log", conditions);

            result.Add(new MultiConditions()
            {
                { log, conditions }
            });

            return(result);
        }
        protected void SaveBtn_Click(object sender, EventArgs e)
        {
            _processwfRepo = RepositoryFactory.CreateProcessWorkflowRepo();
            _rootRepo      = RepositoryFactory.CreateRootRepo();

            //取得頁面資料

            //簽核擔當
            ProcessWorkflowDetailViewModel model   = PageDataBind();
            ProcessWorkflowViewModel       model_M = _processwfRepo.GetWorkflowDataAndCheck(Request["SignDocID"], User.Identity.Name);

            //btn處理
            ViewUtils.ButtonOff(SaveBtn, CoverBtn);

            var sectionChief = new SectionChief(null);

            #region #0012 忘刷單的時間如果不符合邏輯,在確認簽核的時候主管要看到明顯提示 (目前針對桃園所做設定)

            //判斷是否為忘刷單
            if (model_M.FormID_FK == 1)
            {
                //判斷登入者是否為桃園所的員工
                EmployeeRepository employeeRepository = RepositoryFactory.CreateEmployeeRepo();
                EmployeeViewModel  empInfo            = employeeRepository.GetEmployeeDataByADAccount(Context.User.Identity.Name);
                if (empInfo.DepartmentID_FK == "3910")
                {
                    bool isInRule = _processwfRepo.CheckFogotPunchTimeHasInRule(Request["SignDocID"]);
                    if (!isInRule)
                    {
                        ClientScriptManager cs = Page.ClientScript;
                        cs.RegisterClientScriptBlock(this.GetType(), "PopupScript", "var fpTimeIsSuccess = false;", true);
                        return;
                    }
                }
            }

            #endregion #0012 忘刷單的時間如果不符合邏輯,在確認簽核的時候主管要看到明顯提示 (目前針對桃園所做設定)

            try
            {
                if (model_M.FormID_FK == 3 && model.Status == 3)
                {
                    //txterror.Text = "123";
                    //Response.Write("未填寫單位主管意見".ToAlertFormat());
                    _trainDetaiRepo = RepositoryFactory.CreateTrainDetailRepo();
                    //取得頁面資料

                    model = PageDataBind();
                    var    QuestionDataList = _trainDetaiRepo.QueryQuestionDataByChief("02");
                    String chkString        = "";
                    String ansString        = "";
                    QuestionDataList.All(row =>
                    {
                        if (row["ANSTYPE"].ToString() == "C")//填文字
                        {
                            TextBox tmpbox = PlaceHolder1.FindControl("textbox" + row["serial_no"].ToString()) as TextBox;
                            ansString      = tmpbox.Text;
                            if (ansString == "")
                            {
                                chkString += row["CODENAME"].ToString() + " 不可空白!";
                            }
                        }
                        else if (row["ANSTYPE"].ToString() == "N")
                        {
                            //RadioButtonList tmprbl = PlaceHolder1.FindControl("rbl" + row["serial_no"].ToString()) as RadioButtonList;
                            RadioButtonList tmprbl = (RadioButtonList)PlaceHolder1.FindControl("rbl" + row["serial_no"].ToString());
                            ansString = tmprbl.SelectedValue;
                            if (ansString == "")
                            {
                                chkString += row["CODENAME"].ToString() + " 不可空白!";
                            }
                        }
                        return(true);
                    });
                    if (chkString != "")
                    {
                        Response.Write(chkString.ToAlertFormat());
                        return;
                    }
                    else
                    {
                        //儲存主管意見
                        var    successRdUrl = String.Empty;
                        string strCLID      = _trainDetaiRepo.Find_CLID(Request["SignDocID"]);
                        string strSID       = _trainDetaiRepo.Find_SID(Request["SignDocID"]);
                        //刪除記錄調查表的主管意見
                        _trainDetaiRepo.DelChiefAnswer("CHARACTER_ANSWER", strCLID, strSID, "02");
                        _trainDetaiRepo.DelChiefAnswer("NUMERIC_ANSWER", strCLID, strSID, "02");
                        QuestionDataList.All(row =>
                        {
                            if (row["ANSTYPE"].ToString() == "C")//填文字
                            {
                                //新增
                                TextBox tmpbox = PlaceHolder1.FindControl("textbox" + row["serial_no"].ToString()) as TextBox;
                                //ansString = tmpbox.Text;
                                _trainDetaiRepo.AddAnswer_C(strCLID, strSID, row["TABLE_ID"].ToString(), row["QNO"].ToString(), row["serial_no"].ToString(), tmpbox.Text, "Portal");
                            }
                            else if (row["ANSTYPE"].ToString() == "N")
                            {
                                //新增
                                RadioButtonList tmprbl = (RadioButtonList)PlaceHolder1.FindControl("rbl" + row["serial_no"].ToString());
                                //ansString = tmprbl.SelectedValue;
                                _trainDetaiRepo.AddAnswer_N(strCLID, strSID, row["TABLE_ID"].ToString(), row["QNO"].ToString(), row["serial_no"].ToString(), tmprbl.SelectedValue, "Portal");
                            }
                            return(true);
                        });
                    }
                }

                //主管簽核
                sectionChief.SignOff(model);

                MailInfo info = new MailInfo()
                {
                    AddresseeTemp = System.Web.Configuration.WebConfigurationManager.AppSettings["MailTemplate"],
                    DomainPattern = ConfigUtils.ParsePageSetting("Pattern")["DomainPattern"],
                };

                var     mainData = _processwfRepo.GetWorkflowData(model.SignDocID_FK, null);
                DataRow deptData = null;
                //送簽人AD帳號
                var signSender = (string)_rootRepo.QueryForEmployeeByEmpID(mainData.EmployeeID_FK)["ADAccount"];

                switch (mainData.FinalStatus)
                {
                //待簽核
                default:
                case 2:
                    //尋找目前待簽主管AD帳號
                    deptData = _rootRepo.QueryForDepartmentByDeptID(mainData.CurrentSignLevelDeptID_FK);
                    info.To  = (string)_rootRepo.QueryForEmployeeByEmpID((string)deptData["chiefID_FK"])["ADAccount"];

                    info.Subject = String.Format("系統提醒!簽核單號 : {0} 已經送達,請儘速處理!", model.SignDocID_FK);
                    info.Body.AppendFormat("{0}{1}", info.Subject, "此件為系統發送,請勿回覆!");
                    break;

                //駁回
                case 4:
                    info.To = signSender;

                    info.Subject = String.Format("系統提醒!簽核單號 : {0} 已被駁回,請儘速修改!", model.SignDocID_FK);
                    info.Body.AppendFormat("{0}{1}", info.Subject, "此件為系統發送,請勿回覆!");
                    break;

                //結案
                case 6:

                    #region #0013 加班時間小於結薪日,通知email給總務手動要寫入志元 直接判斷Table=>OvertimeForm的AutoInsert

                    //加班單的時候傳的參數為2,方能判斷是否送來簽核的是加班單
                    if (model_M.FormID_FK == 2)
                    {
                        string sid = Request["SignDocID"].ToString();
                        //取得結薪日
                        DateTime salaryLimit = Convert.ToDateTime(_rootRepo.GetSalaryLimit()["LimitDate"]);
                        Overtime overSev     = new Overtime();
                        List <OvertimeViewModel> overDataList   = new List <OvertimeViewModel>();
                        List <OvertimeViewModel> resultDataList = new List <OvertimeViewModel>();

                        //取得加班資料明細
                        OvertimeRepository _overtimeRepo = RepositoryFactory.CreateOvertimeRepo();
                        DataTable          tableData     = _overtimeRepo.QueryOvertimeFormData(sid);
                        var rows = tableData.Select();


                        overDataList = _overtimeRepo.dataMapping(tableData);
                        foreach (var over in overDataList)
                        {
                            if (!over.AutoInsert)
                            {
                                resultDataList.Add(over);
                            }
                            //DateTime startDate = (DateTime)over.StartDateTime;
                            //int mathDate = new TimeSpan(startDate.Ticks - salaryLimit.Ticks).Days;
                            //if (mathDate <= 0)
                            //resultDataList.Add(over);
                        }

                        //info.To = "wenhua.yu";
                        info.To = "juncheng.liu";
                        info.CC = new List <string>()
                        {
                            "juncheng.liu"
                        };
                        foreach (var ov in resultDataList)
                        {
                            info.Subject = String.Format("系統提醒!加班單號 : {0} [{1}-{2}]手動轉志元通知!", sid, ov.EmployeeID_FK, ov.EmployeeName);
                            DateTime      ovStartTime = (DateTime)ov.StartDateTime;
                            StringBuilder mailBody    = new StringBuilder();
                            mailBody.AppendLine(@"<p>[通知] 加班單 手動轉志元通知。</p>");
                            mailBody.AppendLine(@"<p>&nbsp;</p>");
                            mailBody.AppendLine(@"<p>Dear&nbsp;遇玟樺:</p>");
                            mailBody.AppendLine(@"<p>需手動轉入志元的加班單如下:</p>");
                            mailBody.AppendLine(@"<p>加班單號:<span style=""color:#0000ff;"">OT201707290010</span></p>");
                            mailBody.AppendLine(@"<p>加班日:" + ovStartTime.ToFullTaiwanDate() + "</p>");
                            //mailBody.AppendLine(@"<p>結薪日:<span style=""color:#ff0000;"">" + salaryLimit.ToFullTaiwanDate() + "</span></p>");
                            mailBody.AppendLine(@"<p>員工ID:" + ov.EmployeeID_FK + "</p>");
                            mailBody.AppendLine(@"<p>員工姓名:" + ov.EmployeeName + "</p>");
                            mailBody.AppendLine(@"<p><a href=""http://portal.rinnai.com.tw/Area/Manage/OvertimeReport.aspx"">Portal</a></p>");
                            info.Body = mailBody;
                            _mailer   = new Mailer(info);
                            //if (PublicRepository.CurrentWorkflowMode == Enums.WorkflowTypeEnum.RELEASE)
                            _mailer.SendMail();
                        }
                    }

                    #endregion #0013 加班時間小於結薪日,通知email給總務手動要寫入志元 直接判斷Table=>OvertimeForm的AutoInsert

                    //尋找歸檔人員
                    var fillingDept = (string)_rootRepo.QueryForDepartmentByFormID(mainData.FormID_FK)["DepartmentID"];
                    deptData = _rootRepo.QueryForDepartmentByDeptID(fillingDept);
                    //20170327 修改不寄給歸檔人員
                    //info.To = (string)_rootRepo.QueryForEmployeeByEmpID((string)deptData["FilingEmployeeID_FK"])["ADAccount"];
                    info.To = signSender;
                    //info.CC.Add(signSender);

                    info.Subject = String.Format("系統提醒!簽核單號 : {0} 已通過審核並結案,請儘速確認!", model.SignDocID_FK);
                    info.Body.AppendFormat("{0}{1}", info.Subject, "此件為系統發送,請勿回覆!");
                    break;
                }
                GlobalDiagnosticsContext.Set("User", User.Identity.Name);
                //mail
                _mailer = new Mailer(info);
                if (PublicRepository.CurrentWorkflowMode == Enums.WorkflowTypeEnum.RELEASE)
                {
                    _mailer.SendMail();
                }
                //log
                var cc = String.Join(",", info.CC);
                _log.Trace(String.Format("MailTo : {0}\r\ncc : {1}\r\nTitle : {2}\r\nContent : {3}\r\n", info.To, cc, info.Subject, info.Body));

                Response.Write("已送出簽核".ToAlertAndRedirect("/Area/Sign/ProcessWorkflowList.aspx?orderField=ModifyDate&descending=True"));
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message.ToAlertFormat());
            }
            finally
            {
                //btn處理
                SaveBtn.ButtonOn(CoverBtn);
            }
        }
        //送出簽核
        public void SubmitData(ProcessWorkflowViewModel mainModel)
        {
            var procedureData = _rootRepo.QueryForSignProcedureBySignDocID(mainModel.SignDocID);
            var remainder     = procedureData != null?Int32.Parse(procedureData["SignLevel"].ToString()) : -1;

            var chiefDeptData = _pwfRepo.FindUpperDeptData(mainModel.CurrentSignLevelDeptID_FK);
            var chiefDeptID   = chiefDeptData.Values.SingleOrDefault();

            if (chiefDeptID == null)
            {
                throw new Exception("查尋上層部門發生異常!");
            }

            //判斷 FlowRule
            if (!_pwfRepo.IsFollowFlowRule(mainModel.RuleID_FK, chiefDeptID))
            {
                throw new Exception("不符合簽核規則,無法送出簽核!");
            }
            mainModel.SendDate    = currentDateTime;
            mainModel.FinalStatus = 2;
            mainModel.Remainder   = remainder;
            mainModel.ModifyDate  = currentDateTime;

            //根據支援部門更新簽核資料
            var manipulationConditions = new List <MultiConditions>();
            var strSQL = string.Empty;

            strSQL =
                @"UPDATE signform_main 
SET    senddate = @SendDate, 
	   finalstatus = @FinalStatus, 
	   remainder = @remainder,
	   modifier = @Modifier, 
	   modifydate = @ModifyDate 
WHERE  signdocid = @SignDocID ";
            var dic = new Conditions()
            {
                { "@SignDocID", mainModel.SignDocID },
                { "@SendDate", mainModel.SendDate },
                { "@FinalStatus", mainModel.FinalStatus },
                { "@remainder", mainModel.Remainder },
                { "@Modifier", mainModel.Modifier },
                { "@ModifyDate", mainModel.ModifyDate },
            };

            manipulationConditions.Add(new MultiConditions()
            {
                { strSQL, dic }
            });

            dic = new Conditions()
            {
                { "@SignDocID_FK", mainModel.SignDocID },
                { "@FormID_FK", mainModel.FormID_FK },
                { "@EmployeeID_FK", mainModel.EmployeeID_FK },
                { "@SendDate", mainModel.SendDate },
                { "@CurrentSignLevelDeptID_FK", chiefDeptID },
                { "@FinalStatus", mainModel.FinalStatus },
                { "@Remainder", mainModel.Remainder },
                { "@Modifier_Main", mainModel.Modifier },
                { "@ModifyDate_Main", mainModel.ModifyDate },
                { "@LogDatetime", DateTime.Now },
            };
            //加入 log
            strSQL = _dc.ConstructInsertDML("signform_log", dic);
            manipulationConditions.Add(new MultiConditions()
            {
                { strSQL, dic }
            });

            int seq = 0;

            //根據所屬單位產生會簽資料
            mainModel.RinnaiForms.Cast <OvertimeViewModel>().All(x =>
            {
                var employeeData  = _rootRepo.QueryForEmployeeByEmpID(x.EmployeeID_FK);
                x.DepartmentID_FK = employeeData != null ? employeeData["DepartmentID_FK"].ToString() : String.Empty;
                return(true);
            });

            //20170119 修正會簽主管短少問題Start
            var orgOvertimeTable = QueryOvertimeData(mainModel.SignDocID);

            foreach (DataRow row in orgOvertimeTable.Rows)
            {
                //orgOvertimeList.Add(Int32.Parse(row["SN"].ToString()));
                seq++;
                //var deptData = _rootRepo.QueryForDepartmentByDeptID(row["DepartmentID_FK"].ToString());
                var chiefID = row["ChiefID_FK"].ToString();
                dic = new Conditions()
                {
                    { String.Format("@SignDocID_FK{0}", seq), mainModel.SignDocID },
                    { "@ChiefID_FK", chiefID },
                    { "@Status", mainModel.FinalStatus },
                    { "@Creator", mainModel.Modifier },
                    { "@CreateDate", currentDateTime },
                };

                //新增 SignForm_Detail 資料
                strSQL = _dc.ConstructInsertDML("signform_detail", dic);
                manipulationConditions.Add(new MultiConditions()
                {
                    { String.Format(strSQL, seq), dic }
                });

                dic = new Conditions()
                {
                    { String.Format("@DetailSignDocID_FK{0}", seq), mainModel.SignDocID },
                    { "@ChiefID_FK", chiefID },
                    { "@Status", mainModel.FinalStatus },
                    { "@Creator_Detail", mainModel.Modifier },
                    { "@CreateDate_Detail", currentDateTime },
                    { "@LogDatetime", DateTime.Now },
                };
                //加入 log
                strSQL = _dc.ConstructInsertDML("signform_log", dic);
                manipulationConditions.Add(new MultiConditions()
                {
                    { String.Format(strSQL, seq), dic }
                });
            }
            //20170119 修正會簽主管短少問題End

            //foreach (var data in mainModel.ChiefIDs.Distinct())
            //{
            //    seq++;
            //    var deptData = _rootRepo.QueryForDepartmentByDeptID(data);
            //    var chiefID = deptData != null ? deptData["ChiefID_FK"].ToString() : String.Empty;
            //    //if (!IsExistChiefID(mainModel.SignDocID, chiefID))//兼任主管不寫入重複signform_detail
            //    //{
            //        dic = new Conditions()
            //        {
            //            {String.Format("@SignDocID_FK{0}", seq), mainModel.SignDocID},
            //            {"@ChiefID_FK", data},
            //            {"@Status", mainModel.FinalStatus},
            //            {"@Creator", mainModel.Modifier},
            //            {"@CreateDate", currentDateTime},
            //        };

            //        //新增 SignForm_Detail 資料
            //        strSQL = _dc.ConstructInsertDML("signform_detail", dic);
            //        manipulationConditions.Add(new MultiConditions() { { String.Format(strSQL, seq), dic } });

            //        dic = new Conditions()
            //        {
            //            {String.Format("@DetailSignDocID_FK{0}", seq), mainModel.SignDocID},
            //            {"@ChiefID_FK", data},
            //            {"@Status", mainModel.FinalStatus},
            //            {"@Creator_Detail", mainModel.Modifier},
            //            {"@CreateDate_Detail", currentDateTime},
            //            {"@LogDatetime", DateTime.Now},
            //        };
            //        //加入 log
            //        strSQL = _dc.ConstructInsertDML("signform_log", dic);
            //        manipulationConditions.Add(new MultiConditions() { { String.Format(strSQL, seq), dic } });
            //    //}
            //};

            //判斷結薪日,當加班日小於結薪日手動入志元,大於結薪日自動入志元
            var limitData = _rootRepo.GetSalaryLimit();
            var limitDate = limitData.Count != 0 ? limitData["LimitDate"].ToString().ToDateTimeNullable() : (DateTime?)null;

            if (limitDate.HasValue)
            {
                var date = mainModel.RinnaiForms.Cast <OvertimeViewModel>().First().StartDateTime;
                if (date.HasValue)
                {
                    //加班時間大於等於結薪日,自動入志元
                    if (DateTime.Compare(limitDate.Value.Date, date.Value.Date) <= 0)
                    {
                        mainModel.RinnaiForms.ForEach(form => form.AutoInsert = true);
                    }
                }
            }

            var overtimeModel = mainModel.RinnaiForms.Cast <OvertimeViewModel>().First();

            //更新送出日期
            strSQL =
                @"UPDATE overtimeform 
            SET    applydatetime = @ApplyDateTime, 
	               autoinsert = @AutoInsert, 
	               isholiday = @IsHoliday
            WHERE  signdocid_fk = @SignDocID_FK ";

            dic = new Conditions()
            {
                { "@SignDocID_FK", mainModel.SignDocID },
                { "@ApplyDateTime", mainModel.SendDate },
                { "@AutoInsert", overtimeModel.AutoInsert },
                { "@IsHoliday", overtimeModel.IsHoliday },
                //{"@TotalHours", overtimeModel.TotalHours },
            };
            manipulationConditions.Add(new MultiConditions()
            {
                { String.Format(strSQL, seq), dic }
            });

            //            var overtimeList = mainModel.RinnaiForms.Cast<OvertimeViewModel>().ToList();
            //            //更新 OvertimeForm 資料
            //            seq = 0;
            //            string signDocID = String.Empty;
            //            strSQL =
            //                @"UPDATE overtimeform
            //            SET    applydatetime = @ApplyDateTime,
            //	               autoinsert = @AutoInsert,
            //	               isholiday = @IsHoliday,
            //	               totalhours = @TotalHours
            //            WHERE  sn=@SN{0}
            //            AND    signdocid_fk=@SignDocID_FK";

            //            foreach (var overtime in overtimeList)
            //            {
            //                if (overtime.SN == 0) { continue; }
            //                seq++;
            //                var sn = String.Format("@SN{0}", seq);
            //                dic = new Conditions()
            //                {
            //                    {sn, overtime.SN},
            //                    {"@SignDocID_FK", mainModel.SignDocID},
            //                    {"@ApplyDateTime", mainModel.SendDate},
            //                    {"@AutoInsert", overtime.AutoInsert},
            //                    {"@IsHoliday", overtime.IsHoliday },
            //                    {"@TotalHours", overtime.TotalHours },
            //                };
            //                manipulationConditions.Add(new MultiConditions() { { String.Format(strSQL, seq), dic } });
            //            }

            //seq = 0;
            //var overtimeModelList = mainModel.RinnaiForms.Cast<OvertimeViewModel>();
            //            overtimeModelList.All(overtime =>
            //            {
            //                seq++;
            //                //更新送出日期
            //                strSQL =
            //                @"UPDATE overtimeform
            //            SET    applydatetime = @ApplyDateTime,
            //	               autoinsert = @AutoInsert,
            //	               isholiday = @IsHoliday,
            //	               totalhours = @TotalHours
            //            WHERE  signdocid_fk = @SignDocID_FK ";

            //                dic = new Conditions()
            //                {
            //                    {"@SignDocID_FK", mainModel.SignDocID},
            //                    {"@ApplyDateTime", mainModel.SendDate},
            //                    {"@AutoInsert", overtime.AutoInsert},
            //                    {"@IsHoliday", overtime.IsHoliday },
            //                    {"@TotalHours", overtime.TotalHours },
            //                };
            //                manipulationConditions.Add(new MultiConditions() { { String.Format(strSQL, seq), dic } });
            //                return true;
            //            });



            //var overtimeModel = mainModel.RinnaiForms.Cast<OvertimeViewModel>().First();


            try
            {
                if (!_dc.ExecuteMultAndCheck(manipulationConditions))
                {
                    throw new Exception("送出加班單失敗!");
                }
            }
            catch (Exception ex)
            {
                throw new Exception("送出加班單失敗!" + ex.Message);
            }
        }