protected void gvMain_RowCommand(object sender, GridViewCommandEventArgs e)
 {
     if (e.CommandName.Equals("Detail"))
     {
         GridViewRow clickedRow          = ((LinkButton)e.CommandSource).NamingContainer as GridViewRow;
         Dictionary <string, string> dic = new Dictionary <string, string>();
         PunchUpdate.GridViewToDictionary(gvMain, out dic, clickedRow.RowIndex, strDataKeyNames);
         Session["Punch_Confirm_Remedy_Bean"] = dic;
         Response.Redirect("PunchUpdateModify.aspx");
     }
 }
    protected void gvMain_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        GridViewRow clickedRow = ((ImageButton)e.CommandSource).NamingContainer as GridViewRow;

        switch (e.CommandName)
        {
        case "Detail":
            string flowCode = "", flowSN = "", msg = "", btnName = "";
            Dictionary <string, string> dic = new Dictionary <string, string>();
            Dictionary <string, string> toUserData;
            PunchUpdate.GridViewToDictionary(gvMain, out dic, clickedRow.RowIndex, strDataKeyNames);
            FlowExpress oFlow = new FlowExpress(FlowCustDB, dic["FlowCaseID"], false);
            Punch_Confirm_Remedy_Bean model = new Punch_Confirm_Remedy_Bean()
            {
                //跟共用條件
                CompID      = dic["CompID"],
                EmpID       = dic["EmpID"],
                EmpName     = dic["EmpName"],
                LastChgComp = UserInfo.getUserInfo().CompID.Trim(),
                LastChgID   = UserInfo.getUserInfo().UserID.Trim(),
                LastChgDate = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"),

                //預存所需資料
                PunchTime        = dic["PunchTime"],
                ConfirmPunchFlag = dic["ConfirmPunchFlag"],
                DutyTime         = dic["DutyTime"],
                RestBeginTime    = dic["RestBeginTime"],
                RestEndTime      = dic["RestEndTime"],
                //Remedy所需資料
                PunchDate      = dic["PunchDate"],
                PunchRemedySeq = dic["PunchRemedySeq"],
                FlowCaseID     = dic["FlowCaseID"],
                ValidDateTime  = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"),
                ValidCompID    = UserInfo.getUserInfo().CompID.Trim(),
                ValidID        = UserInfo.getUserInfo().UserID.Trim(),
                ValidName      = UserInfo.getUserInfo().UserName.Trim(),

                //Confirm所需資料
                DutyDate                = dic["DutyDate"],
                PunchConfirmSeq         = dic["PunchConfirmSeq"],
                RemedyReasonID          = dic["RemedyReasonID"],
                RemedyReasonCN          = dic["RemedyReasonCN"],
                RemedyPunchTime         = dic["RemedyPunchTime"],
                Remedy_MAFT10_FLAG      = dic["Remedy_MAFT10_FLAG"],
                Remedy_AbnormalFlag     = dic["Remedy_AbnormalFlag"],
                Remedy_AbnormalReasonID = dic["Remedy_AbnormalReasonID"],
                Remedy_AbnormalReasonCN = dic["Remedy_AbnormalReasonCN"],
                Remedy_AbnormalDesc     = dic["Remedy_AbnormalDesc"]
            };
            //按鈕清單
            ClearBtn(model.FlowCaseID);

            //下一關邏輯判斷,產生審核按鈕資訊,給出Ken流程相關資訊
            if (!nextFlowBtn(model, out flowCode, out flowSN, ref btnName, out toUserData, out msg))       //判斷審核按鈕
            {
                Util.MsgBox(msg);
                return;
            }
            CustVerify.setFlowSignID_CompID(toUserData["SignID"].ToString() + "," + toUserData["SignIDComp"].ToString());
            //傳給審核畫面-單筆審核使用
            Session["PunchAppdOperation_toUserData"] = toUserData;
            Session["PunchAppdOperation_GridView"]   = dic;
            //產生審核按鈕
            FlowExpress.getFlowTodoList(FlowExpress.TodoListAssignKind.All, model.ValidID.Trim(), FlowCustDB.Split(','), "".Split(','), false, "", "");
            //跳轉畫面
            Response.Redirect(string.Format(FlowExpress._FlowPageVerifyURL + "?FlowID={0}&FlowLogID={1}&ProxyType={2}&IsShowBtnComplete={3}&IsShowCheckBoxList={4}&ChkMaxKeyLen={5}", oFlow.FlowID, oFlow.FlowCurrLastLogID, "Self", "N", "N", ""));
            break;
        }
    }
    private void SaveData()
    {
        string ErrorIndex = "";

        for (int index = 0; index < gvMain.Rows.Count; index++)
        {
            CheckBox objchk = (CheckBox)gvMain.Rows[index].FindControl("chkChoiced");
            if (objchk.Checked == true)
            {
                bool   result = false;
                long   seccessCount = 0;
                string msg = "", flowCode = "", flowSN = "";
                string btnName = "";

                RadioButton rdoApp    = (RadioButton)gvMain.Rows[index].FindControl("rbnApproved");
                RadioButton rdoRej    = (RadioButton)gvMain.Rows[index].FindControl("rbnReject");
                TextBox     txtReason = (TextBox)gvMain.Rows[index].FindControl("txtReason");

                Dictionary <string, string> dic        = new Dictionary <string, string>();
                Dictionary <string, string> toUserData = new Dictionary <string, string>();
                PunchUpdate.GridViewToDictionary(gvMain, out dic, index, strDataKeyNames);
                Punch_Confirm_Remedy_Bean model = new Punch_Confirm_Remedy_Bean()
                {
                    //跟共用條件
                    CompID      = dic["CompID"],
                    EmpID       = dic["EmpID"],
                    EmpName     = dic["EmpName"],
                    LastChgComp = UserInfo.getUserInfo().CompID.Trim(),
                    LastChgID   = UserInfo.getUserInfo().UserID.Trim(),
                    LastChgDate = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"),

                    //預存所需資料
                    PunchTime        = dic["PunchTime"],
                    ConfirmPunchFlag = dic["ConfirmPunchFlag"],
                    DutyTime         = dic["DutyTime"],
                    RestBeginTime    = dic["RestBeginTime"],
                    RestEndTime      = dic["RestEndTime"],
                    //Remedy所需資料
                    PunchDate      = dic["PunchDate"],
                    PunchRemedySeq = dic["PunchRemedySeq"],
                    FlowCaseID     = dic["FlowCaseID"],
                    ValidDateTime  = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"),
                    ValidCompID    = UserInfo.getUserInfo().CompID.Trim(),
                    ValidID        = UserInfo.getUserInfo().UserID.Trim(),
                    ValidName      = UserInfo.getUserInfo().UserName.Trim(),

                    //Confirm所需資料
                    DutyDate                = dic["DutyDate"],
                    PunchConfirmSeq         = dic["PunchConfirmSeq"],
                    RemedyReasonID          = dic["RemedyReasonID"],
                    RemedyReasonCN          = dic["RemedyReasonCN"],
                    RemedyPunchTime         = dic["RemedyPunchTime"],
                    Remedy_MAFT10_FLAG      = dic["Remedy_MAFT10_FLAG"],
                    Remedy_AbnormalFlag     = dic["Remedy_AbnormalFlag"],
                    Remedy_AbnormalReasonID = dic["Remedy_AbnormalReasonID"],
                    Remedy_AbnormalReasonCN = dic["Remedy_AbnormalReasonCN"],
                    Remedy_AbnormalDesc     = dic["Remedy_AbnormalDesc"]
                };

                if (rdoApp.Checked == true)                                                                  //核准
                {
                    if (!nextFlowBtn(model, out flowCode, out flowSN, ref btnName, out toUserData, out msg)) //判斷審核按鈕
                    {
                        Util.MsgBox(msg);
                        return;
                    }
                    switch (btnName)
                    {
                    //PORemedyStatus。0:未處理,1:未送簽,2:送簽中,3:核准,4:駁回
                    //ConfirmStatus。0:正常,1:異常,2:送簽中,3:異常不控管
                    case "btnClose":
                        model.PORemedyStatus = "3";
                        string strConfirmStatus = "", strAbnormalType = "";
                        if (!PunchUpdate.PunchAppdOperation_EXEC_PunchCheckData(model, out strConfirmStatus, out strAbnormalType))
                        {
                            Util.MsgBox("打卡異常檢核失敗!!");
                            return;
                        }
                        model.ConfirmStatus = strConfirmStatus;     //0 or 1記得用John的TSQL
                        model.AbnormalType  = strAbnormalType;
                        break;

                    case "btnApprove":
                    case "btnReApprove":
                        model.PORemedyStatus = "2";
                        model.ConfirmStatus  = "2";
                        break;
                    }
                }
                else if (rdoRej.Checked == true)//駁回
                {
                    btnName = "btnReject";
                    model.PORemedyStatus = "4";
                    model.ConfirmStatus  = "1";
                }

                DataTable LastHROtherFlowLog        = PunchUpdate.HROtherFlowLog(model.FlowCaseID, true);
                Dictionary <string, string> oAssDic = CustVerify.getEmpID_Name_Dictionary(toUserData["SignID"], toUserData["SignIDComp"]);

                if (!string.IsNullOrEmpty(btnName))
                {
                    //審核動作
                    result = PunchUpdate.PunchAppdOperation_SaveData(model, oAssDic, btnName, txtReason.Text, out seccessCount, out msg, flowCode, flowSN, LastHROtherFlowLog.Rows[0]["FlowSeq"].ToString(), LastHROtherFlowLog.Rows[0]["FlowLogBatNo"].ToString(), LastHROtherFlowLog.Rows[0]["FlowLogID"].ToString(), toUserData);
                }
                else
                {
                    result = false;
                }

                if (!result)
                {
                    //Util.MsgBox(msg);
                    ErrorIndex += (index + 1).ToString() + ",";
                    continue;
                }
                if (seccessCount == 0)
                {
                    ErrorIndex += (index + 1).ToString() + ",";
                    continue;
                }
            }
        }
        if (ErrorIndex.Length > 0)
        {
            ErrorIndex = ErrorIndex.Substring(0, ErrorIndex.Length - 1);
            Util.MsgBox("第" + ErrorIndex + "筆審核失敗");
        }
        else
        {
            Util.MsgBox("審核成功");
        }
    }