/// <summary>
    /// 原本不允許送審重複主管,現在又改成可以,所以把這方法註解,改成不檢核直接查詢
    /// </summary>
    /// <param name="SignID">下一關主管ID</param>
    /// <param name="SignIDComp">下一關主管公司</param>
    /// <param name="oAssDic">回傳Dictionary格式給永豐流程使用</param>
//    private void oAssDicCheck(string SignID, string SignIDComp, ref  Dictionary<string, string> oAssDic)
//{
//    if (SignID.Trim().Equals(UserInfo.getUserInfo().UserID.Trim()))
//        {
//            oAssDic.Clear();
//        }
//        else
//        {
//            oAssDic = CustVerify.getEmpID_Name_Dictionary(SignID, SignIDComp);
//        }
//}

    protected void Page_Load(object sender, EventArgs e)
    {
        //代辦畫面傳來的多筆審核資料
        DataTable dtOverTimeAdvance     = (DataTable)Session["dtOverTimeAdvance"];
        DataTable dtOverTimeDeclaration = (DataTable)Session["dtOverTimeDeclaration"];

        //永豐流程相關資料
        FlowExpress oFlow = new FlowExpress(Aattendant._AattendantFlowID, Request["FlowLogID"], true);

        //錯誤訊息儲存
        string     ErrMsg = "";
        CustVerify CV     = new CustVerify();
        Dictionary <string, string> toUserData = (Dictionary <string, string>)Session["toUserData"];

        //EmpInfo.QueryOrganData || EmpInfo.QueryFlowOrganData 使用
        //string SignOrganID = "", SignID = "", SignIDComp = "";

        if (!IsPostBack)
        {
            if (Session["FlowVerifyInfo"] != null)
            {
                #region "變數"
                //TrtCatchIsFlowVerify()使用
                DbHelper      db = new DbHelper(Aattendant._AattendantDBName);
                CommandHelper sb = db.CreateCommandHelper();
                DbConnection  cn = db.OpenConnection();
                DbTransaction tx = cn.BeginTransaction();

                //撈取該筆加班單相關資料
                DataTable dtOverTime;

                //預設下關待辦人(會變,沒變代表沒找到相關資料)
                Dictionary <string, string> oVerifyInfo = (Dictionary <string, string>)Session["FlowVerifyInfo"];
                Util.setJSContent(oVerifyInfo["FlowVerifyJS"]);
                Session["FlowVerifyInfo"] = null;
                Dictionary <string, string> oAssDic = Util.getDictionary(oVerifyInfo["FlowStepAssignToList"]);

                //共用檔
                Aattendant _Aattendant = new Aattendant();

                //Para撈取參數設定
                DataTable dtOverTimePara_All = db.ExecuteDataSet(CommandType.Text, string.Format("SELECT DISTINCT CompID,Para FROM OverTimePara ")).Tables[0];

                string AD = "";
                #endregion "變數"
                switch (oVerifyInfo["FlowStepBtnID"].ToString())
                {
                case "btnClose":
                case "btnReApprove":
                case "FlowReassign":
                case "btnApprove":      //審核
                    //單筆審核(使用oFlow.FlowCaseID判斷)
                    if (dtOverTimeAdvance == null && dtOverTimeDeclaration == null)
                    {
                        #region "單筆審核"
                        //給IsFlowVerify的下一關簽核主管
                        //oAssDicCheck(toUserData["SignID"], toUserData["SignIDComp"], ref oAssDic); //原本要檢核主管是否重複,後來說不要了
                        oAssDic = CustVerify.getEmpID_Name_Dictionary(toUserData["SignID"], toUserData["SignIDComp"]);
                        switch (oFlow.FlowCurrStepID)
                        {
                        //事先
                        case "A10":
                        case "A20":
                            AD = "A";
                            break;

                        //事後
                        case "A30":
                        case "A40":
                            AD = "D";
                            break;
                        }
                        dtOverTime = CustVerify.OverTime_find_by_FlowCaseID(oFlow.FlowCaseID, AD);
                        if (oVerifyInfo["FlowStepBtnID"].ToString() == "btnClose")     //結案
                        {
                            sb.Reset();
                            CustVerify.UpdateOverTime(AD, "3", oFlow.FlowCaseID, ref sb);
                            CustVerify.UpdateHROrverTimeLog(oFlow.FlowCaseID, "2", ref sb);
                            CustVerify.CloseHROverTimeLog(oFlow.FlowCaseID, AD, ref sb);
                            if (AD == "A")
                            {
                                CustVerify.insertFromAdvanceToData(oFlow.FlowCaseID, ref sb);
                            }
                            if (TryCatchIsFlowVerify(Request["FlowLogID"], oVerifyInfo["FlowStepBtnID"], oAssDic, oVerifyInfo["FlowStepOpinion"].ToString().Replace("'", "''"), sb, out ErrMsg, dtOverTime.Rows[0], true))
                            {
                                CV.MailLogContent(oFlow.FlowCaseID, "3", AD, "", "", true);
                                labMsg.Text = Util.getHtmlMessage(Util.HtmlMessageKind.Succeed, "審核成功!");
                            }
                            else
                            {
                                labMsg.Text = Util.getHtmlMessage(Util.HtmlMessageKind.Error, "審核失敗");
                            }
                        }
                        else     //沒結案
                        {
                            sb.Reset();
                            DataTable dtHROverTimeLog = CustVerify.HROverTimeLog(oFlow.FlowCaseID, false);
                            CustVerify.UpdateOverTime(AD, "2", oFlow.FlowCaseID, ref sb);
                            CustVerify.UpdateHROrverTimeLog(oFlow.FlowCaseID, "2", ref sb);
                            FlowUtility.InsertHROverTimeLogCommand(
                                oFlow.FlowCaseID,
                                CustVerify.addone(dtHROverTimeLog.Rows[0]["FlowLogBatNo"].ToString()),
                                CustVerify.FlowLogIDadd(dtHROverTimeLog.Rows[0]["FlowLogID"].ToString()),
                                AD,
                                dtHROverTimeLog.Rows[0]["OTEmpID"].ToString(),
                                dtHROverTimeLog.Rows[0]["EmpOrganID"].ToString(),
                                dtHROverTimeLog.Rows[0]["EmpFlowOrganID"].ToString(),
                                UserInfo.getUserInfo().UserID,
                                dtHROverTimeLog.Rows[0]["FlowCode"].ToString(),
                                dtHROverTimeLog.Rows[0]["FlowSN"].ToString(),
                                CustVerify.addone(dtHROverTimeLog.Rows[0]["FlowSeq"].ToString()),
                                toUserData["SignLine"],
                                toUserData["SignIDComp"],
                                toUserData["SignID"],
                                toUserData["SignOrganID"],
                                toUserData["SignFlowOrganID"],
                                "1", false, ref sb, int.Parse(dtHROverTimeLog.Rows[0]["Seq"].ToString()) + 1
                                );

                            if (TryCatchIsFlowVerify(Request["FlowLogID"], oVerifyInfo["FlowStepBtnID"], oAssDic, oVerifyInfo["FlowStepOpinion"].ToString().Replace("'", "''"), sb, out ErrMsg, dtOverTime.Rows[0], true))
                            {
                                CV.MailLogContent(oFlow.FlowCaseID, "2", AD, "", "", false);
                                labMsg.Text = Util.getHtmlMessage(Util.HtmlMessageKind.Succeed, "審核成功!");
                            }
                            else
                            {
                                labMsg.Text = Util.getHtmlMessage(Util.HtmlMessageKind.Error, "審核失敗");
                            }
                        }
                        #endregion "單筆審核"
                    }
                    /*================================================*/
                    //多筆審核有四個迴圈,事先兩個是後兩個
                    //UpdateAD、HROverTimeLog、MailLog在第一迴圈
                    //其他在第二迴圈
                    //多筆審核按鈕(非印章)
                    else
                    {
                        #region "事先多筆"
                        if (dtOverTimeAdvance.Rows.Count > 0)
                        {
                            AD = "A";
                            for (int i = 0; i < dtOverTimeAdvance.Rows.Count; i++)
                            {
                                if (dtOverTimeAdvance.Rows[i]["OTSeqNo"].ToString() == "1")
                                {
                                    oFlow = new FlowExpress(Aattendant._AattendantFlowID, CustVerify.getFlowLogID(dtOverTimeAdvance.Rows[i]["FlowCaseID"].ToString(), "A"), true);
                                    string btnName = dtOverTimeAdvance.Rows[i]["btnName"].ToString();
                                    //oAssDicCheck(dtOverTimeAdvance.Rows[i]["SignID"].ToString(), dtOverTimeAdvance.Rows[i]["SignIDComp"].ToString(), ref oAssDic);
                                    oAssDic = CustVerify.getEmpID_Name_Dictionary(dtOverTimeAdvance.Rows[i]["SignID"].ToString(), dtOverTimeAdvance.Rows[i]["SignIDComp"].ToString());
                                    if (btnName == "btnClose")     //結案
                                    {
                                        sb.Reset();
                                        CustVerify.UpdateOverTime(AD, "3", dtOverTimeAdvance.Rows[i]["FlowCaseID"].ToString(), ref sb);
                                        CustVerify.UpdateHROrverTimeLog(dtOverTimeAdvance.Rows[i]["FlowCaseID"].ToString(), "2", ref sb);
                                        CustVerify.CloseHROverTimeLog(dtOverTimeAdvance.Rows[i]["FlowCaseID"].ToString(), AD, ref sb);
                                        CustVerify.insertFromAdvanceToData(dtOverTimeAdvance.Rows[i]["FlowCaseID"].ToString(), ref sb);
                                        if (TryCatchIsFlowVerify(oFlow.FlowCurrLastLogID, btnName, oAssDic, oVerifyInfo["FlowStepOpinion"].ToString().Replace("'", "''"), sb, out ErrMsg, dtOverTimeAdvance.Rows[i], false))
                                        {
                                            CV.MailLogContent(dtOverTimeAdvance.Rows[i]["FlowCaseID"].ToString(), "3", AD, "", "", true);
                                            labMsg.Text = Util.getHtmlMessage(Util.HtmlMessageKind.Succeed, "審核成功!");
                                        }
                                        else
                                        {
                                            labMsg.Text = Util.getHtmlMessage(Util.HtmlMessageKind.Error, "審核失敗");
                                        }
                                    }
                                    else     //沒結案
                                    {
                                        sb.Reset();
                                        DataTable dtHROverTimeLog = CustVerify.HROverTimeLog(dtOverTimeAdvance.Rows[i]["FlowCaseID"].ToString(), false);
                                        CustVerify.UpdateOverTime(AD, "2", dtOverTimeAdvance.Rows[i]["FlowCaseID"].ToString(), ref sb);
                                        CustVerify.UpdateHROrverTimeLog(dtOverTimeAdvance.Rows[i]["FlowCaseID"].ToString(), "2", ref sb);
                                        FlowUtility.InsertHROverTimeLogCommand(
                                            dtOverTimeAdvance.Rows[i]["FlowCaseID"].ToString(),
                                            CustVerify.addone(dtHROverTimeLog.Rows[0]["FlowLogBatNo"].ToString()),
                                            CustVerify.FlowLogIDadd(dtHROverTimeLog.Rows[0]["FlowLogID"].ToString()),
                                            AD,
                                            dtHROverTimeLog.Rows[0]["OTEmpID"].ToString(),
                                            dtHROverTimeLog.Rows[0]["EmpOrganID"].ToString(),
                                            dtHROverTimeLog.Rows[0]["EmpFlowOrganID"].ToString(),
                                            UserInfo.getUserInfo().UserID,
                                            dtHROverTimeLog.Rows[0]["FlowCode"].ToString(),
                                            dtHROverTimeLog.Rows[0]["FlowSN"].ToString(),
                                            CustVerify.addone(dtHROverTimeLog.Rows[0]["FlowSeq"].ToString()),
                                            //toUserData start
                                            dtOverTimeAdvance.Rows[i]["SignLine"].ToString(),
                                            dtOverTimeAdvance.Rows[i]["SignIDComp"].ToString(),
                                            dtOverTimeAdvance.Rows[i]["SignID"].ToString(),
                                            dtOverTimeAdvance.Rows[i]["SignOrganID"].ToString(),
                                            dtOverTimeAdvance.Rows[i]["SignFlowOrganID"].ToString(),
                                            //toUserData end
                                            "1", false, ref sb, int.Parse(dtHROverTimeLog.Rows[0]["Seq"].ToString()) + 1
                                            );

                                        if (TryCatchIsFlowVerify(oFlow.FlowCurrLastLogID, btnName, oAssDic, oVerifyInfo["FlowStepOpinion"].ToString().Replace("'", "''"), sb, out ErrMsg, dtOverTimeAdvance.Rows[i], false))
                                        {
                                            CV.MailLogContent(dtOverTimeAdvance.Rows[i]["FlowCaseID"].ToString(), "2", AD, "", "", false);
                                            labMsg.Text = Util.getHtmlMessage(Util.HtmlMessageKind.Succeed, "審核成功!");
                                        }
                                        else
                                        {
                                            labMsg.Text = Util.getHtmlMessage(Util.HtmlMessageKind.Error, "審核失敗");
                                        }
                                    }
                                }
                            }
                        }
                        #endregion "事先多筆"
                        /*------------------*/
                        #region "事後多筆"
                        if (dtOverTimeDeclaration.Rows.Count > 0)
                        {
                            AD = "D";
                            for (int i = 0; i < dtOverTimeDeclaration.Rows.Count; i++)
                            {
                                if (dtOverTimeDeclaration.Rows[i]["OTSeqNo"].ToString() == "1")
                                {
                                    oFlow = new FlowExpress(Aattendant._AattendantFlowID, CustVerify.getFlowLogID(dtOverTimeDeclaration.Rows[i]["FlowCaseID"].ToString(), "D"), true);
                                    string btnName = dtOverTimeDeclaration.Rows[i]["btnName"].ToString();
                                    //oAssDicCheck(dtOverTimeDeclaration.Rows[i]["SignID"].ToString(), dtOverTimeDeclaration.Rows[i]["SignIDComp"].ToString(), ref oAssDic);
                                    oAssDic = CustVerify.getEmpID_Name_Dictionary(dtOverTimeDeclaration.Rows[i]["SignID"].ToString(), dtOverTimeDeclaration.Rows[i]["SignIDComp"].ToString());
                                    if (btnName == "btnClose")     //結案
                                    {
                                        sb.Reset();
                                        CustVerify.UpdateOverTime(AD, "3", dtOverTimeDeclaration.Rows[i]["FlowCaseID"].ToString(), ref sb);
                                        CustVerify.UpdateHROrverTimeLog(dtOverTimeDeclaration.Rows[i]["FlowCaseID"].ToString(), "2", ref sb);
                                        CustVerify.CloseHROverTimeLog(dtOverTimeDeclaration.Rows[i]["FlowCaseID"].ToString(), AD, ref sb);

                                        if (TryCatchIsFlowVerify(oFlow.FlowCurrLastLogID, btnName, oAssDic, oVerifyInfo["FlowStepOpinion"].ToString().Replace("'", "''"), sb, out ErrMsg, dtOverTimeDeclaration.Rows[i], false))
                                        {
                                            CV.MailLogContent(dtOverTimeDeclaration.Rows[i]["FlowCaseID"].ToString(), "3", AD, "", "", true);
                                            labMsg.Text = Util.getHtmlMessage(Util.HtmlMessageKind.Succeed, "審核成功!");
                                        }
                                        else
                                        {
                                            labMsg.Text = Util.getHtmlMessage(Util.HtmlMessageKind.Error, "審核失敗");
                                        }
                                    }
                                    else     //沒結案
                                    {
                                        sb.Reset();
                                        DataTable dtHROverTimeLog = CustVerify.HROverTimeLog(dtOverTimeDeclaration.Rows[i]["FlowCaseID"].ToString(), false);
                                        CustVerify.UpdateOverTime(AD, "2", dtOverTimeDeclaration.Rows[i]["FlowCaseID"].ToString(), ref sb);
                                        CustVerify.UpdateHROrverTimeLog(dtOverTimeDeclaration.Rows[i]["FlowCaseID"].ToString(), "2", ref sb);
                                        FlowUtility.InsertHROverTimeLogCommand(
                                            dtOverTimeDeclaration.Rows[i]["FlowCaseID"].ToString(),
                                            CustVerify.addone(dtHROverTimeLog.Rows[0]["FlowLogBatNo"].ToString()),
                                            CustVerify.FlowLogIDadd(dtHROverTimeLog.Rows[0]["FlowLogID"].ToString()),
                                            AD,
                                            dtHROverTimeLog.Rows[0]["OTEmpID"].ToString(),
                                            dtHROverTimeLog.Rows[0]["EmpOrganID"].ToString(),
                                            dtHROverTimeLog.Rows[0]["EmpFlowOrganID"].ToString(),
                                            UserInfo.getUserInfo().UserID,
                                            dtHROverTimeLog.Rows[0]["FlowCode"].ToString(),
                                            dtHROverTimeLog.Rows[0]["FlowSN"].ToString(),
                                            CustVerify.addone(dtHROverTimeLog.Rows[0]["FlowSeq"].ToString()),
                                            //toUserData start
                                            dtOverTimeDeclaration.Rows[i]["SignLine"].ToString(),
                                            dtOverTimeDeclaration.Rows[i]["SignIDComp"].ToString(),
                                            dtOverTimeDeclaration.Rows[i]["SignID"].ToString(),
                                            dtOverTimeDeclaration.Rows[i]["SignOrganID"].ToString(),
                                            dtOverTimeDeclaration.Rows[i]["SignFlowOrganID"].ToString(),
                                            //toUserData end
                                            "1", false, ref sb, int.Parse(dtHROverTimeLog.Rows[0]["Seq"].ToString()) + 1
                                            );

                                        if (TryCatchIsFlowVerify(oFlow.FlowCurrLastLogID, btnName, oAssDic, oVerifyInfo["FlowStepOpinion"].ToString().Replace("'", "''"), sb, out ErrMsg, dtOverTimeDeclaration.Rows[i], false))
                                        {
                                            CV.MailLogContent(dtOverTimeDeclaration.Rows[i]["FlowCaseID"].ToString(), "2", AD, "", "", false);
                                            labMsg.Text = Util.getHtmlMessage(Util.HtmlMessageKind.Succeed, "審核成功!");
                                        }
                                        else
                                        {
                                            labMsg.Text = Util.getHtmlMessage(Util.HtmlMessageKind.Error, "審核失敗");
                                        }
                                    }
                                }
                            }
                        }
                        #endregion "事後多筆"
                    }
                    break;

                /*=================================================*/
                case "btnReject":                                                   //駁回
                    if (dtOverTimeAdvance == null && dtOverTimeDeclaration == null) //true 印章 false 多筆審核按鈕
                    {
                        #region "單筆駁回"
                        switch (oFlow.FlowCurrStepID)
                        {
                        //事先
                        case "A10":
                        case "A20":
                            AD = "A";
                            break;

                        //事後
                        case "A30":
                        case "A40":
                            AD = "D";
                            break;
                        }
                        dtOverTime = CustVerify.OverTime_find_by_FlowCaseID(oFlow.FlowCaseID, AD);
                        sb.Reset();
                        CustVerify.UpdateOverTime(AD, "4", oFlow.FlowCaseID, ref sb);
                        CustVerify.UpdateHROrverTimeLog(oFlow.FlowCaseID, "3", ref sb);
                        CustVerify.CloseHROverTimeLog(oFlow.FlowCaseID, AD, ref sb);
                        if (AD == "D")
                        {
                            CustVerify.AfterReject_CheckAndInsert(oFlow.FlowCaseID, ref sb);
                        }
                        //ClearBtn(oFlow.FlowCurrLogAssignTo);
                        if (TryCatchIsFlowVerify(Request["FlowLogID"], "btnReject", oAssDic, oVerifyInfo["FlowStepOpinion"].ToString().Replace("'", "''"), sb, out ErrMsg, dtOverTime.Rows[0], true))
                        {
                            CV.MailLogContent(oFlow.FlowCaseID, "4", AD, "", "", true);
                            labMsg.Text = Util.getHtmlMessage(Util.HtmlMessageKind.Succeed, "審核成功!");
                        }
                        else
                        {
                            labMsg.Text = Util.getHtmlMessage(Util.HtmlMessageKind.Error, "審核失敗");
                        }
                        #endregion "單筆駁回"
                    }

                    else     //多筆審核按鈕
                    {
                        #region "多筆駁回"
                        if (dtOverTimeAdvance.Rows.Count > 0)
                        {
                            AD = "A";
                            for (int i = 0; i < dtOverTimeAdvance.Rows.Count; i++)
                            {
                                if (dtOverTimeAdvance.Rows[i]["OTSeqNo"].ToString() == "1")
                                {
                                    oFlow = new FlowExpress(Aattendant._AattendantFlowID, CustVerify.getFlowLogID(dtOverTimeAdvance.Rows[i]["FlowCaseID"].ToString(), "A"), true);
                                    sb.Reset();
                                    CustVerify.UpdateOverTime(AD, "4", dtOverTimeAdvance.Rows[i]["FlowCaseID"].ToString(), ref sb);
                                    CustVerify.UpdateHROrverTimeLog(dtOverTimeAdvance.Rows[i]["FlowCaseID"].ToString(), "3", ref sb);
                                    CustVerify.CloseHROverTimeLog(dtOverTimeAdvance.Rows[i]["FlowCaseID"].ToString(), AD, ref sb);
                                    //ClearBtn(oFlow.FlowCurrLogAssignTo);
                                    if (TryCatchIsFlowVerify(oFlow.FlowCurrLastLogID, "btnReject", oAssDic, oVerifyInfo["FlowStepOpinion"].ToString().Replace("'", "''"), sb, out ErrMsg, dtOverTimeAdvance.Rows[i], false))
                                    {
                                        CV.MailLogContent(dtOverTimeAdvance.Rows[i]["FlowCaseID"].ToString(), "4", AD, "", "", true);
                                        labMsg.Text = Util.getHtmlMessage(Util.HtmlMessageKind.Succeed, "審核成功!");
                                    }
                                    else
                                    {
                                        labMsg.Text = Util.getHtmlMessage(Util.HtmlMessageKind.Error, "審核失敗");
                                    }
                                }
                            }
                        }
                        if (dtOverTimeDeclaration.Rows.Count > 0)
                        {
                            AD = "D";
                            for (int i = 0; i < dtOverTimeDeclaration.Rows.Count; i++)
                            {
                                if (dtOverTimeDeclaration.Rows[i]["OTSeqNo"].ToString() == "1")
                                {
                                    oFlow = new FlowExpress(Aattendant._AattendantFlowID, CustVerify.getFlowLogID(dtOverTimeDeclaration.Rows[i]["FlowCaseID"].ToString(), "D"), true);
                                    sb.Reset();
                                    CustVerify.UpdateOverTime(AD, "4", oFlow.FlowCaseID, ref sb);
                                    CustVerify.UpdateHROrverTimeLog(oFlow.FlowCaseID, "3", ref sb);
                                    CustVerify.CloseHROverTimeLog(oFlow.FlowCaseID, AD, ref sb);
                                    CustVerify.AfterReject_CheckAndInsert(oFlow.FlowCaseID, ref sb);
                                    //ClearBtn(oFlow.FlowCurrLogAssignTo);
                                    if (TryCatchIsFlowVerify(oFlow.FlowCurrLastLogID, "btnReject", oAssDic, oVerifyInfo["FlowStepOpinion"].ToString().Replace("'", "''"), sb, out ErrMsg, dtOverTimeDeclaration.Rows[i], false))
                                    {
                                        CV.MailLogContent(oFlow.FlowCaseID, "4", AD, "", "", true);
                                        labMsg.Text = Util.getHtmlMessage(Util.HtmlMessageKind.Succeed, "審核成功!");
                                    }
                                    else
                                    {
                                        labMsg.Text = Util.getHtmlMessage(Util.HtmlMessageKind.Error, "審核失敗");
                                    }
                                }
                            }
                        }
                        #endregion "多筆駁回"
                    }
                    break;
                    /*==============================*/
                }
                if (txtErrMsg.Text != "")
                {
                    txtErrMsg.Text    = "審核失敗清單:" + txtErrMsg.Text;
                    txtErrMsg.Visible = true;
                }
            }
            else
            {
                //參數錯誤
                labMsg.Text = Util.getHtmlMessage(Util.HtmlMessageKind.ParaError);
            }
        }
    }
Beispiel #2
0
    public static bool PunchAppdOperation_SaveData(Punch_Confirm_Remedy_Bean model, Dictionary <string, string> oAssDic, string btnName, string FlowStepOpinion, out long seccessCount, out string msg, string flowCode = "", string flowSN = "", string flowSeq = "", string FlowLogBatNo = "", string FlowLogID = "", Dictionary <string, string> toUserData = null)
    {
        seccessCount = 0;
        msg          = "";
        Punch_Confirm_Remedy_Bean datas = new Punch_Confirm_Remedy_Bean();

        try
        {
            FlowExpress flow         = new FlowExpress(Util.getAppSetting("app://AattendantDB_PunchUpdate/"), model.FlowCaseID, false);
            string      strFlowLogID = flow.FlowCurrLastLogID;
            //string strFlowLogID=PunchUpdate.getFlowLogID(Util.getAppSetting("app://AattendantDB_PunchUpdate/"), model.FlowCaseID);
            //FlowExpress flow = new FlowExpress(Util.getAppSetting("app://AattendantDB_PunchUpdate/"), model.FlowCaseID);
            //FlowExpress flow = new FlowExpress(Util.getAppSetting("app://AattendantDB_PunchUpdate/"), strFlowLogID);
            DbHelper      db = new DbHelper(Aattendant._AattendantDBName);
            CommandHelper sb = db.CreateCommandHelper();
            DbConnection  cn = db.OpenConnection();
            DbTransaction tx = cn.BeginTransaction();

            Punch_Confirm_Remedy_Bean dataBean = new Punch_Confirm_Remedy_Bean()
            {
                FlowCaseID       = model.FlowCaseID,
                CompID           = model.CompID,
                EmpID            = model.EmpID,
                EmpName          = model.EmpName,
                DutyDate         = model.DutyDate,
                DutyTime         = model.DutyTime,
                PunchDate        = model.PunchDate,
                PunchTime        = model.PunchTime,
                PunchConfirmSeq  = model.PunchConfirmSeq,
                DeptID           = model.DeptID,
                DeptName         = model.DeptName,
                OrganID          = model.OrganID,
                OrganName        = model.OrganName,
                FlowOrganID      = model.FlowOrganID,
                FlowOrganName    = model.FlowOrganName,
                ConfirmStatus    = model.ConfirmStatus,
                PunchRemedySeq   = model.PunchRemedySeq,
                RemedyReasonID   = model.RemedyReasonID,
                RemedyReasonCN   = model.RemedyReasonCN,
                RemedyPunchTime  = model.RemedyPunchTime,
                AbnormalFlag     = model.AbnormalFlag,
                AbnormalReasonID = model.AbnormalReasonID,
                AbnormalReasonCN = model.AbnormalReasonCN,
                AbnormalDesc     = model.AbnormalDesc,

                Remedy_MAFT10_FLAG      = model.Remedy_MAFT10_FLAG,
                Remedy_AbnormalFlag     = model.Remedy_AbnormalFlag,
                Remedy_AbnormalReasonID = model.Remedy_AbnormalReasonID,
                Remedy_AbnormalReasonCN = model.Remedy_AbnormalReasonCN,
                Remedy_AbnormalDesc     = model.Remedy_AbnormalDesc,
                LastChgComp             = model.LastChgComp,
                LastChgID   = model.LastChgID,
                LastChgDate = model.LastChgDate,
                //Remedy
                RemedyPunchFlag = model.RemedyPunchFlag,
                BatchFlag       = model.BatchFlag,
                PORemedyStatus  = model.PORemedyStatus,
                RejectReason    = model.RejectReason,
                RejectReasonCN  = model.RejectReasonCN,
                ValidDateTime   = model.ValidDateTime,
                ValidCompID     = model.ValidCompID,
                ValidID         = model.ValidID,
                ValidName       = model.ValidName
            };
            try
            {
                SqlCommand.PunchAppdOperation_UpdatePunchRemedyLog(dataBean, ref sb);
                SqlCommand.PunchAppdOperation_UpdatePunchConfirm(dataBean, ref sb); //內部判定結案or駁回
                SqlCommand.PunchAppdOperation_UpdateHROtherFlowLog(dataBean.FlowCaseID, dataBean.ConfirmStatus == "4" ? "3" : "2", ref sb);

                if (dataBean.PORemedyStatus == "2")//沒結案(送簽中)
                {
                    OBFlowUtility.InsertHROtherFlowLogCommand(dataBean.FlowCaseID, CustVerify.addone(FlowLogBatNo), CustVerify.FlowLogIDadd(FlowLogID), "P", dataBean.EmpID, dataBean.OrganID, dataBean.FlowOrganID, UserInfo.getUserInfo().UserID, flowCode, flowSN, CustVerify.addone(flowSeq), toUserData["SignLine"], toUserData["SignIDComp"], toUserData["SignID"], toUserData["SignOrganID"], toUserData["SignFlowOrganID"], "1", false, ref sb);
                }
                else if (dataBean.PORemedyStatus == "3" || dataBean.PORemedyStatus == "4")//結案
                {
                    FlowUtility.ChangeFlowFlag(dataBean.FlowCaseID, flowCode, flowSN, UserInfo.getUserInfo().CompID, UserInfo.getUserInfo().UserID, "0", ref sb);
                }
                //======(test錯誤的存在)=======
                //sb.Append("test錯誤的存在");
                msg = "注定失敗";
                return(false);

                //======(test錯誤的存在)=======
                seccessCount = db.ExecuteNonQuery(sb.BuildCommand(), tx); //執行新增,成功筆數回傳,並做Transaction機制
                if (seccessCount > 0)
                {
                    if (FlowExpress.IsFlowVerify(flow.FlowID, flow.FlowCurrLastLogID, btnName, oAssDic, FlowStepOpinion))
                    {
                        tx.Commit(); //成功Transaction直接Commit
                    }
                    else
                    {
                        tx.Rollback(); //失敗Transaction Rollback
                        msg = "永豐流程寫入失敗";
                    }
                }
                else
                {
                    tx.Rollback(); //失敗Transaction Rollback
                    msg = "審核失敗,更新0筆資料";
                }
            }
            catch (Exception ex)
            {
                tx.Rollback(); //失敗Transaction Rollback
                msg = ex.Message;
                throw ex;
            }
        }
        catch (Exception ex)
        {
            //tx.Rollback(); //失敗Transaction Rollback
            msg = ex.Message;
            return(false);
        }
        return(true);
    }