예제 #1
0
        /// <summary>
        /// 新增稽核軌跡
        /// </summary>
        /// <param name="codeUserDao"></param>
        /// <param name="codeUser"></param>
        /// <param name="conn"></param>
        /// <param name="transaction"></param>
        public void procTrackLog(string type, CodeUserDao codeUserDao, CODE_USER codeUser, SqlConnection conn, SqlTransaction transaction)
        {
            PIA_LOG_MAIN piaLog = new PIA_LOG_MAIN();

            piaLog.TRACKING_TYPE     = "A";
            piaLog.ACCESS_ACCOUNT    = Session["UserID"].ToString();
            piaLog.ACCOUNT_NAME      = Session["UserName"].ToString();
            piaLog.PROGFUN_NAME      = "UserReview";
            piaLog.ACCESSOBJ_NAME    = "CodeUser";
            piaLog.EXECUTION_TYPE    = type;
            piaLog.EXECUTION_CONTENT = codeUserDao.userLogContent(codeUser);
            piaLog.AFFECT_ROWS       = 1;
            piaLog.PIA_OWNER1        = codeUser.USER_ID;
            piaLog.PIA_OWNER2        = "";
            piaLog.PIA_TYPE          = "0100000000";


            PiaLogMainDao piaLogMainDao = new PiaLogMainDao();

            piaLogMainDao.Insert(piaLog, conn, transaction);
        }
예제 #2
0
        public JsonResult execReviewU(string aplyNo, string userId, string apprStatus)
        {
            string strConn = DbUtil.GetDBTreasuryConnStr();

            using (SqlConnection conn = new SqlConnection(strConn))
            {
                conn.Open();
                SqlTransaction transaction = conn.BeginTransaction("Transaction");

                try
                {
                    AuthApprDao AuthApprDao = new AuthApprDao();
                    AUTH_APPR   authAppr    = AuthApprDao.qryByKey(aplyNo);

                    if (StringUtil.toString(authAppr.CREATE_UID).Equals(Session["UserID"].ToString()))
                    {
                        return(Json(new { success = false, errors = "覆核人員與申請人員相同,不可執行覆核作業!!" }, JsonRequestBehavior.AllowGet));
                    }


                    //異動使用者資料檔
                    string         cExecType      = "";
                    CodeUserHisDao codeUserHisDao = new CodeUserHisDao();
                    CodeUserDao    codeUserDao    = new CodeUserDao();
                    CODE_USER      cODEUSERO      = new CODE_USER();

                    CODE_USER_HIS codeUserHis = codeUserHisDao.qryByAplyNo(aplyNo);
                    string        execAction  = "";
                    if (codeUserHis != null)
                    {
                        execAction = StringUtil.toString(codeUserHis.EXEC_ACTION);
                    }

                    if ("A".Equals(execAction))  //新增使用者
                    {
                    }
                    else
                    {  //異動角色
                        cODEUSERO = codeUserDao.qryUserByKey(userId);
                    }



                    if ("A".Equals(execAction))
                    {
                        if ("2".Equals(apprStatus))
                        {
                            cODEUSERO.USER_ID         = StringUtil.toString(codeUserHis.USER_ID);
                            cODEUSERO.IS_DISABLED     = codeUserHis.IS_DISABLED;
                            cODEUSERO.IS_MAIL         = codeUserHis.IS_MAIL;
                            cODEUSERO.MEMO            = codeUserHis.MEMO;
                            cODEUSERO.DATA_STATUS     = "1";
                            cODEUSERO.CREATE_UID      = authAppr.CREATE_UID;
                            cODEUSERO.CREATE_DT       = authAppr.CREATE_DT;
                            cODEUSERO.LAST_UPDATE_UID = StringUtil.toString(authAppr.CREATE_UID);
                            cODEUSERO.LAST_UPDATE_DT  = authAppr.CREATE_DT;
                            cODEUSERO.APPR_UID        = Session["UserID"].ToString();
                            cODEUSERO.APPR_DT         = DateTime.Now;

                            int cnt = codeUserDao.Create(cODEUSERO, conn, transaction);

                            //新增LOG
                            Log log = new Log();
                            log.CFUNCTION = "使用者管理-新增";
                            log.CACTION   = "A";
                            log.CCONTENT  = codeUserDao.userLogContent(cODEUSERO);
                            LogDao.Insert(log, Session["UserID"].ToString());

                            //新增稽核軌跡
                            procTrackLog("A", codeUserDao, cODEUSERO, conn, transaction);
                        }
                    }
                    else
                    {
                        //新增LOG
                        Log log = new Log();
                        log.CFUNCTION = "使用者管理-修改";
                        log.CACTION   = "U";
                        log.CCONTENT  = codeUserDao.userLogContent(cODEUSERO);
                        LogDao.Insert(log, Session["UserID"].ToString());

                        cODEUSERO.DATA_STATUS     = "1";
                        cODEUSERO.LAST_UPDATE_UID = StringUtil.toString(authAppr.CREATE_UID);
                        cODEUSERO.LAST_UPDATE_DT  = authAppr.CREATE_DT;
                        cODEUSERO.APPR_UID        = Session["UserID"].ToString();
                        cODEUSERO.APPR_DT         = DateTime.Now;
                        cODEUSERO.FREEZE_DT       = null;
                        cODEUSERO.FREEZE_UID      = "";

                        if ("U".Equals(execAction) && "2".Equals(apprStatus))
                        {
                            cODEUSERO.IS_DISABLED = codeUserHis.IS_DISABLED;
                            cODEUSERO.IS_MAIL     = StringUtil.toString(codeUserHis.IS_MAIL);
                            cODEUSERO.MEMO        = StringUtil.toString(codeUserHis.MEMO);
                        }


                        int cnt = codeUserDao.Update(cODEUSERO, conn, transaction);

                        //20190418 201904160117-00 Bianco 修改稽核軌跡
                        procTrackLog("E", codeUserDao, cODEUSERO, conn, transaction);
                    }


                    //覆核狀態=核可時
                    if ("2".Equals(apprStatus))
                    {
                        procUserRoleHis(cODEUSERO, aplyNo, conn, transaction); //異動使用者角色
                    }
                    //異動覆核資料檔
                    procAuthAppr(aplyNo, apprStatus, conn, transaction);

                    transaction.Commit();
                    return(Json(new { success = true }));
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                    logger.Error("[execReviewR]其它錯誤:" + e.ToString());

                    return(Json(new { success = false, errors = "其它錯誤,請洽系統管理員!!" }, JsonRequestBehavior.AllowGet));
                }
            }
        }
예제 #3
0
        /// <summary>
        /// 異動使用者資訊
        /// </summary>
        /// <param name="userMgrModel"></param>
        /// <returns></returns>
        public JsonResult updateUser(UserMgrModel userMgrModel, List <CodeUserRoleModel> roleData, string execAction)
        {
            bool bUserChg = false;
            bool bRoleChg = false;



            CodeUserDao codeUserDao = new CodeUserDao();
            CODE_USER   userO       = codeUserDao.qryUserByKey(userMgrModel.cUserID);

            if ("A".Equals(execAction))
            {
                if (userO != null)
                {
                    if (!"".Equals(StringUtil.toString(userO.USER_ID)))
                    {
                        return(Json(new { success = false, err = "使用者已存在系統,不可新增!!" }, JsonRequestBehavior.AllowGet));
                    }
                }
                bUserChg = true;
            }
            else
            {
                if (userO == null)
                {
                    return(Json(new { success = false, err = "該使用者不存在系統!!" }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    if (StringUtil.toString(userMgrModel.isDisabled).Equals(StringUtil.toString(userO.IS_DISABLED)) &&
                        StringUtil.toString(userMgrModel.isMail).Equals(StringUtil.toString(userO.IS_MAIL)) &&
                        StringUtil.toString(userMgrModel.vMemo).Equals(StringUtil.toString(userO.MEMO))
                        )
                    {
                        bUserChg = false;
                    }
                    else
                    {
                        bUserChg = true;
                    }
                }
            }


            //比對是否有異動"角色授權"
            CodeUserRoleDao          codeUserRoleDao = new CodeUserRoleDao();
            List <CodeUserRoleModel> roleDataO       = codeUserRoleDao.qryByUserID(userMgrModel.cUserID);
            List <CodeUserRoleModel> roleList        = new List <CodeUserRoleModel>();

            if (roleData != null)
            {
                foreach (CodeUserRoleModel role in roleData)
                {
                    CodeUserRoleModel codeUserRoleModel = new CodeUserRoleModel();
                    codeUserRoleModel.userId = StringUtil.toString(userMgrModel.cUserID);
                    codeUserRoleModel.roleId = StringUtil.toString(role.roleId);


                    if (roleDataO.Exists(x => x.roleId == role.roleId))
                    {
                        codeUserRoleModel.execAction = "";
                    }
                    else
                    {
                        bRoleChg = true;
                        codeUserRoleModel.execAction = "A";
                    }
                    roleList.Add(codeUserRoleModel);
                }
            }


            foreach (CodeUserRoleModel oRole in roleDataO)
            {
                if (roleList != null)
                {
                    if (!roleList.Exists(x => x.roleId == oRole.roleId))
                    {
                        bRoleChg = true;
                        CodeUserRoleModel codeUserRoleModel = new CodeUserRoleModel();
                        codeUserRoleModel.userId     = StringUtil.toString(userMgrModel.cUserID);
                        codeUserRoleModel.roleId     = StringUtil.toString(oRole.roleId);
                        codeUserRoleModel.execAction = "D";
                        roleList.Add(codeUserRoleModel);
                    }
                }
                else
                {
                    bRoleChg = true;
                    CodeUserRoleModel codeUserRoleModel = new CodeUserRoleModel();
                    codeUserRoleModel.userId     = StringUtil.toString(oRole.userId);
                    codeUserRoleModel.roleId     = StringUtil.toString(oRole.roleId);
                    codeUserRoleModel.execAction = "D";
                    roleList.Add(codeUserRoleModel);
                }
            }

            if (bUserChg == false && bRoleChg == false)
            {
                return(Json(new { success = false, errors = "未異動畫面資料,將不進行修改覆核作業!!" }, JsonRequestBehavior.AllowGet));
            }


            /*------------------ DB處理   begin------------------*/
            string strConn = DbUtil.GetDBTreasuryConnStr();

            using (SqlConnection conn = new SqlConnection(strConn))
            {
                conn.Open();

                SqlTransaction transaction = conn.BeginTransaction("Transaction");
                try
                {
                    AuthApprDao authApprDao = new AuthApprDao();
                    AUTH_APPR   authAppr    = new AUTH_APPR();
                    authAppr.AUTH_APLY_TYPE   = "U";
                    authAppr.APPR_STATUS      = "1";
                    authAppr.APPR_MAPPING_KEY = userMgrModel.cUserID;
                    authAppr.CREATE_UID       = Session["UserID"].ToString();

                    //新增"覆核資料檔"
                    string aplyNo = authApprDao.insert(authAppr, conn, transaction);


                    // 異動"使用者資料檔"資料狀態
                    if (!"A".Equals(execAction))
                    {
                        Log log = new Log();
                        log.CFUNCTION = "使用者管理-修改";
                        log.CACTION   = "U";
                        log.CCONTENT  = codeUserDao.userLogContent(userO);
                        LogDao.Insert(log, Session["UserID"].ToString());


                        userO.DATA_STATUS     = "2";
                        userO.LAST_UPDATE_UID = Session["UserID"].ToString();
                        userO.LAST_UPDATE_DT  = DateTime.Now;
                        userO.FREEZE_UID      = Session["UserID"].ToString();
                        userO.FREEZE_DT       = DateTime.Now;

                        int cnt = codeUserDao.Update(userO, conn, transaction);
                    }


                    //處理使用者資料檔的異動
                    if (bUserChg)
                    {
                        CodeUserHisDao codeUserHisDao = new CodeUserHisDao();
                        CODE_USER_HIS  userHis        = new CODE_USER_HIS();
                        userHis.APLY_NO     = aplyNo;
                        userHis.USER_ID     = userMgrModel.cUserID;
                        userHis.IS_DISABLED = userMgrModel.isDisabled;
                        userHis.IS_MAIL     = userMgrModel.isMail;
                        userHis.MEMO        = userMgrModel.vMemo;
                        if (!"A".Equals(execAction))
                        {
                            userHis.IS_DISABLED_B = userO.IS_DISABLED;
                            userHis.IS_MAIL_B     = userO.IS_MAIL;
                            userHis.MEMO_B        = userO.MEMO;
                            userHis.EXEC_ACTION   = "U";
                        }
                        else
                        {
                            userHis.EXEC_ACTION = "A";
                        }

                        codeUserHisDao.insert(userHis, conn, transaction);
                    }


                    //處理角色金庫設備資料檔的異動
                    if (bRoleChg)
                    {
                        CodeUserRoleHisDao codeUserRoleHisDao = new CodeUserRoleHisDao();
                        foreach (CodeUserRoleModel role in roleList)
                        {
                            codeUserRoleHisDao.insert(aplyNo, role, conn, transaction);
                            //if (!"".Equals(role.execAction))
                            //{
                            //    codeUserRoleHisDao.insert(aplyNo, role, conn, transaction);
                            //}
                        }
                    }

                    transaction.Commit();

                    /*------------------ DB處理   end------------------*/
                    return(Json(new { success = true, aplyNo = aplyNo }));
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                    logger.Error("[updateUser]其它錯誤:" + e.ToString());

                    return(Json(new { success = false, err = "其它錯誤,請洽系統管理員!!" }, JsonRequestBehavior.AllowGet));
                }
            }
        }