Esempio n. 1
0
        public void ExecExecConfirmData(int urpchSn)
        {
            IEnumerable <uRolePowerConfirmHistoryConfirmData> urpchcdie = db.uRolePowerConfirmHistoryConfirmData.Where(n => n.uRolePowerConfirmHistorySn == urpchSn).ToList();

            foreach (var urpchcd in urpchcdie)
            {
                //Table UserNews
                if (urpchcd.cTableName == "UserNews")
                {
                    ConfirmCRUD <UserNews> crudUserNews = new ConfirmCRUD <UserNews>();
                    if (urpchcd.execAction == SaveExecConfirmDataModelActionEnum.Create.ToString())
                    {
                        UserNews newUserNews = new UserNews();
                        crudUserNews.ExecConfirmAction(db, urpchcd, newUserNews);
                    }
                    else if (urpchcd.execAction == SaveExecConfirmDataModelActionEnum.Update.ToString() ||
                             urpchcd.execAction == SaveExecConfirmDataModelActionEnum.Remove.ToString())
                    {
                        int      usn         = Convert.ToInt32(urpchcd.primaryColumnValue);
                        UserNews newUserNews = db.UserNews.Where(n => n.sn == usn).FirstOrDefault();
                        crudUserNews.ExecConfirmAction(db, urpchcd, newUserNews);
                    }
                    db.SaveChanges();
                }

                //Table UserNewsUrls
                if (urpchcd.cTableName == "UserNewsUrls")
                {
                    ConfirmCRUD <UserNewsUrls> crudUserNewsUrls = new ConfirmCRUD <UserNewsUrls>();
                    if (urpchcd.execAction == SaveExecConfirmDataModelActionEnum.Create.ToString())
                    {
                        UserNewsUrls newUserNewsUrls = new UserNewsUrls();
                        crudUserNewsUrls.ExecConfirmAction(db, urpchcd, newUserNewsUrls);
                    }
                    else if (urpchcd.execAction == SaveExecConfirmDataModelActionEnum.Update.ToString() ||
                             urpchcd.execAction == SaveExecConfirmDataModelActionEnum.Remove.ToString())
                    {
                        int          usn             = Convert.ToInt32(urpchcd.primaryColumnValue);
                        UserNewsUrls newUserNewsUrls = db.UserNewsUrls.Where(n => n.UserNewsUrlsID == usn).FirstOrDefault();
                        crudUserNewsUrls.ExecConfirmAction(db, urpchcd, newUserNewsUrls);
                    }
                    db.SaveChanges();
                }

                //Table UserNewsUrls
                if (urpchcd.cTableName == "AspNetUsers")
                {
                    ConfirmCRUD <AspNetUsers> crudAspNetUserss = new ConfirmCRUD <AspNetUsers>();
                    if (urpchcd.execAction == SaveExecConfirmDataModelActionEnum.Create.ToString())
                    {
                        AspNetUsers newAspNetUsers = new AspNetUsers();
                        crudAspNetUserss.ExecConfirmAction(db, urpchcd, newAspNetUsers);
                    }
                    else if (urpchcd.execAction == SaveExecConfirmDataModelActionEnum.Update.ToString() ||
                             urpchcd.execAction == SaveExecConfirmDataModelActionEnum.Remove.ToString())
                    {
                        string      usn            = urpchcd.primaryColumnValue;
                        AspNetUsers newAspNetUsers = db.AspNetUsers.Where(n => n.Id == usn).FirstOrDefault();
                        crudAspNetUserss.ExecConfirmAction(db, urpchcd, newAspNetUsers);
                    }
                    db.SaveChanges();
                }
            }
        }
Esempio n. 2
0
        public String checkNeedConfirm(out int?outurpchSn, string userName, int powerID, string confirmUrl, string confirmDescription = "")
        {
            string checkResult = "";

            outurpchSn = null;

            IEnumerable <uRoles>                uRolesie                = db.uRoles.ToList();
            IEnumerable <uRoleUsers>            uRoleUsersie            = db.uRoleUsers.ToList();
            IEnumerable <uRolePowers>           uRolePowersie           = db.uRolePowers.ToList();
            IEnumerable <uRolePowerConfirm>     uRolePowerConfirmie     = db.uRolePowerConfirm.ToList();
            IEnumerable <uRolePowerConfirmRole> uRolePowerConfirmRoleie = db.uRolePowerConfirmRole.ToList();

            #region 取出歷史覆核清單
            uRolePowerConfirmHistory olduRolePowerConfirmHistory = (from r in uRolesie
                                                                    join ru in uRoleUsersie on r.uRoleID equals ru.uRoleID
                                                                    join rp in uRolePowersie on r.uRoleID equals rp.uRoleID
                                                                    join rpc in uRolePowerConfirmie on rp.urpSn equals rpc.uRolePowerSn
                                                                    join rpch in db.uRolePowerConfirmHistory on rpc.ucrSn equals rpch.uRolePowerConfirmSn
                                                                    where ru.uUserID == userName && rp.powerID == powerID && (rpch.state == 0 || rpch.state == 1)
                                                                    select rpch).FirstOrDefault();
            #endregion
            if (olduRolePowerConfirmHistory == null)
            {
                #region 取出所有擁有角色覆核設定
                List <uRolePowerConfirmDecide> urpcli = (from r in uRolesie
                                                         join ru in uRoleUsersie on r.uRoleID equals ru.uRoleID
                                                         join rp in uRolePowersie on r.uRoleID equals rp.uRoleID
                                                         join rpc in uRolePowerConfirmie on rp.urpSn equals rpc.uRolePowerSn
                                                         where ru.uUserID == userName && rp.powerID == powerID && (rpc.uEachRoleMinNum.HasValue || rpc.uTotlaRoleMinNum.HasValue)
                                                         select new uRolePowerConfirmDecide
                {
                    uRolePowerConfirm = rpc,
                    roleRegisteredDate = r.registedDate.Value,
                    firstSurRoleID = r.supervisorID,
                    uRoleID = r.uRoleID
                }).ToList();
                for (int i = 0; i < urpcli.Count; i++)
                {
                    int roleNums = (from rpc in uRolePowerConfirmie
                                    join rpcr in uRolePowerConfirmRoleie on rpc.ucrSn equals rpcr.uRolePowerConfirmSn
                                    where rpc.ucrSn == urpcli[i].uRolePowerConfirm.ucrSn
                                    select rpc).Count();
                    int  roleLevel         = 0;
                    bool checkRoleLevelEnd = true;
                    int? tmpSurRoleID      = urpcli[i].firstSurRoleID;
                    if (tmpSurRoleID.HasValue)
                    {
                        while (checkRoleLevelEnd)
                        {
                            tmpSurRoleID = uRolesie.Where(n => n.uRoleID == tmpSurRoleID).Select(n => n.supervisorID).FirstOrDefault();
                            if (!tmpSurRoleID.HasValue)
                            {
                                checkRoleLevelEnd = false;
                            }
                            roleLevel++;
                        }
                    }
                    urpcli[i].roleNums  = roleNums;
                    urpcli[i].roleLevel = roleLevel;
                }
                #endregion
                bool needConfirm = false;
                if (urpcli.Count() > 0)
                {
                    needConfirm = true;
                }
                if (needConfirm)
                {
                    List <uRolePowerConfirmDecide> decidedConfirmSet = new List <uRolePowerConfirmDecide>();
                    decidedConfirmSet.AddRange(urpcli);
                    #region 選擇覆核設定
                    while (decidedConfirmSet.Count() > 1)
                    {
                        if (decidedConfirmSet[1].uRolePowerConfirm.rolePriority > decidedConfirmSet[0].uRolePowerConfirm.rolePriority)
                        {
                            decidedConfirmSet.RemoveAt(0);
                            continue;
                        }
                        if (decidedConfirmSet[1].uRolePowerConfirm.rolePriority < decidedConfirmSet[0].uRolePowerConfirm.rolePriority)
                        {
                            decidedConfirmSet.RemoveAt(1);
                            continue;
                        }
                        if (decidedConfirmSet[1].roleLevel < decidedConfirmSet[0].roleLevel)
                        {
                            decidedConfirmSet.RemoveAt(0);
                            continue;
                        }
                        if (decidedConfirmSet[1].roleLevel > decidedConfirmSet[0].roleLevel)
                        {
                            decidedConfirmSet.RemoveAt(1);
                            continue;
                        }
                        if (decidedConfirmSet[1].roleNums > decidedConfirmSet[0].roleNums)
                        {
                            decidedConfirmSet.RemoveAt(0);
                            continue;
                        }
                        if (decidedConfirmSet[1].roleNums < decidedConfirmSet[0].roleNums)
                        {
                            decidedConfirmSet.RemoveAt(1);
                            continue;
                        }
                        if (decidedConfirmSet[1].uRolePowerConfirm.uTotlaRoleMinNum > decidedConfirmSet[0].uRolePowerConfirm.uTotlaRoleMinNum)
                        {
                            decidedConfirmSet.RemoveAt(0);
                            continue;
                        }
                        if (decidedConfirmSet[1].uRolePowerConfirm.uTotlaRoleMinNum < decidedConfirmSet[0].uRolePowerConfirm.uTotlaRoleMinNum)
                        {
                            decidedConfirmSet.RemoveAt(1);
                            continue;
                        }
                        if (decidedConfirmSet[1].uRolePowerConfirm.uEachRoleMinNum > decidedConfirmSet[0].uRolePowerConfirm.uEachRoleMinNum)
                        {
                            decidedConfirmSet.RemoveAt(0);
                            continue;
                        }
                        if (decidedConfirmSet[1].uRolePowerConfirm.uEachRoleMinNum < decidedConfirmSet[0].uRolePowerConfirm.uEachRoleMinNum)
                        {
                            decidedConfirmSet.RemoveAt(1);
                            continue;
                        }
                        if (decidedConfirmSet[1].roleRegisteredDate > decidedConfirmSet[0].roleRegisteredDate)
                        {
                            decidedConfirmSet.RemoveAt(0);
                            continue;
                        }
                        if (decidedConfirmSet[1].roleRegisteredDate < decidedConfirmSet[0].roleRegisteredDate)
                        {
                            decidedConfirmSet.RemoveAt(1);
                            continue;
                        }
                        if (decidedConfirmSet[1].uRoleID < decidedConfirmSet[0].uRoleID)
                        {
                            decidedConfirmSet.RemoveAt(0);
                            continue;
                        }
                        if (decidedConfirmSet[1].uRoleID > decidedConfirmSet[0].uRoleID)
                        {
                            decidedConfirmSet.RemoveAt(1);
                            continue;
                        }
                    }
                    #endregion
                    checkResult = "開始處理覆核,開始時間為" + DateTime.Now.ToString() + "。";
                    #region 寫入發派覆核清單
                    List <uRoleUsers> needConfirmUserWithRole = (from urpcr in uRolePowerConfirmRoleie
                                                                 join urpc in uRolePowerConfirmie on urpcr.uRolePowerConfirmSn equals urpc.ucrSn
                                                                 join uru in uRoleUsersie on urpcr.uConfirmRoleID equals uru.uRoleID
                                                                 where urpc.ucrSn == decidedConfirmSet[0].uRolePowerConfirm.ucrSn
                                                                 select uru).ToList();
                    uRolePowerConfirmHistory newurpch = new uRolePowerConfirmHistory
                    {
                        uRolePowerConfirmSn = decidedConfirmSet[0].uRolePowerConfirm.ucrSn,
                        startDate           = DateTime.Now,
                        state   = 0,
                        UserID  = userName,
                        powerID = powerID
                    };
                    if (decidedConfirmSet[0].uRolePowerConfirm.maxDay.HasValue)
                    {
                        newurpch.limitDate = DateTime.Now.AddDays(decidedConfirmSet[0].uRolePowerConfirm.maxDay.Value);
                    }
                    db.uRolePowerConfirmHistory.Add(newurpch);
                    db.SaveChanges();


                    List <uRolePowerConfirmHistoryDetail> newpchdList = new List <uRolePowerConfirmHistoryDetail>();
                    foreach (uRoleUsers uru in needConfirmUserWithRole)
                    {
                        uRolePowerConfirmHistoryDetail urpchd = new uRolePowerConfirmHistoryDetail
                        {
                            uRolePowerConfirmHistorySn = newurpch.urpchSn,
                            ConfirmRoleID = uru.uRoleID,
                            ConfirmUserID = uru.uUserID,
                            state         = 0
                        };
                        db.uRolePowerConfirmHistoryDetail.Add(urpchd);
                        newpchdList.Add(urpchd);
                    }
                    db.SaveChanges();

                    outurpchSn = newurpch.urpchSn;
                    #endregion
                    int toUserNewsurpchSn = newurpch.urpchSn;
                    //寫入發派覆核資料庫
                    HubServerMethods NewsHub   = new HubServerMethods();
                    string           powerName = db.uPowers.Where(n => n.powerID == powerID).Select(n => n.powerName).FirstOrDefault();
                    int        drid            = decidedConfirmSet[0].uRoleID;
                    uRolesDpmt urd             = (from ur in db.uRoles
                                                  join d in db.Department on ur.departmentID equals d.departmentID
                                                  where ur.uRoleID == drid
                                                  select new uRolesDpmt
                    {
                        uRoles = ur,
                        Department = d.departmentName
                    }).FirstOrDefault();
                    AspNetUsers asu = db.AspNetUsers.Where(n => n.UserName == userName).FirstOrDefault();
                    List <int>  returnUserNewsSnList = new List <int>();
                    foreach (var newpchd in newpchdList)
                    {
                        List <UserNewsUrls> confirmUrls = new List <UserNewsUrls>();
                        UserNewsUrls        confirmUrl1 = new UserNewsUrls
                        {
                            UserNewsTitle = "核准覆核",
                            UserNewsUrl   = confirmUrl + "?needConfirmUserID=" + userName + "&needConfirmPowerID=" + powerID + "&ConfirmResult=1",
                            UserNewsCSS   = "btn btn-warning"
                        };
                        UserNewsUrls confirmUrl2 = new UserNewsUrls
                        {
                            UserNewsTitle = "否決覆核",
                            UserNewsUrl   = confirmUrl + "?needConfirmUserID=" + userName + "&needConfirmPowerID=" + powerID + "&ConfirmResult=0",
                            UserNewsCSS   = "btn btn-danger"
                        };
                        confirmUrls.Add(confirmUrl1);
                        confirmUrls.Add(confirmUrl2);
                        string fromUser   = userName;
                        string toUser     = newpchd.ConfirmUserID;
                        string msgTitle   = "執行權限需要被覆核";
                        string msgContent = "使用者:'" + asu.Name + "'&lt帳號:" + userName + "&gt<br/>"
                                            + "使用角色:'" + urd.uRoles.uRoleName + "'&lt部門:" + urd.Department + "&gt<br/>"
                                            + "使用權限:'" + powerName + "'&gt<br/>"
                                            + "核准內容:" + confirmDescription;
                        int returnUserNewsSn = NewsHub.SendMessageToUser(fromUser, toUser, msgTitle, msgContent, "", confirmUrls, "True");
                        returnUserNewsSnList.Add(returnUserNewsSn);
                    }
                    //"~/ConfirmUserPower/UserConfirmUserPower?needConfirmUserID=xxx&needConfirmPowerID=xxx&ConfirmResult=xxx"

                    //紀錄發送覆核消息與覆核紀錄關聯
                    AddUserNewsConfirmList(returnUserNewsSnList, toUserNewsurpchSn);
                }
            }
            else
            {
                Repository <uRolePowerConfirmHistory> dburpch = new Repository <uRolePowerConfirmHistory>();
                if (olduRolePowerConfirmHistory.state == 0)
                {
                    if (olduRolePowerConfirmHistory.limitDate.HasValue && olduRolePowerConfirmHistory.limitDate.Value > DateTime.Now)
                    {
                        checkResult = "覆核已過期,請重新點擊。";
                        olduRolePowerConfirmHistory.state   = -1;
                        olduRolePowerConfirmHistory.endDate = DateTime.Now;
                        dburpch.UpdateWithoutNull(olduRolePowerConfirmHistory);
                    }
                    else
                    {
                        checkResult = "覆核已在處理中,開始時間為" + olduRolePowerConfirmHistory.startDate.Value.ToString();
                        if (olduRolePowerConfirmHistory.limitDate.HasValue)
                        {
                            checkResult += ",期限時間為" + olduRolePowerConfirmHistory.limitDate.Value;
                        }
                        checkResult += "。";
                    }
                }
                else
                {
                    //此處為一次解鎖操作
                    //olduRolePowerConfirmHistory.state = 2;
                    //olduRolePowerConfirmHistory.endDate = DateTime.Now;
                    //dburpch.UpdateWithoutNull(olduRolePowerConfirmHistory);


                    //ExecExecConfirmData()
                }
            }

            return(checkResult);
        }