Пример #1
0
        public void UpdateRecord(List <int> UpdList, DAO dao, string DBNo, string sysLinkName, string CacheKey = null)
        {
            if (UpdList == null || UpdList.Count == 0)
            {
                return;
            }
            string        sql = "";
            StringBuilder sbd = new StringBuilder();

            foreach (var id in UpdList)
            {
                sbd.Append(id);
                sbd.Append(",");
            }

            sql = string.Format("select su.*,dp.name as DepName from Sys_User su left join dept dp on su.dep=dp.dep where su.ID in({0})", sbd.ToString(0, sbd.Length - 1));


            BooleanValue <DataTable> bv = dao.GetDataTable(sql);

            if (bv.Success && bv.Value.Rows.Count > 0)
            {
                if (CacheKey != null)
                {
                    object busisData = null;
                    YueMES.Base.Dal.DTO.TryGetCache(string.IsNullOrEmpty(CacheKey) ? Default_sql : CacheKey, DBNo, out busisData);
                    if (busisData == null)
                    {
                        return;
                    }
                    Sys_Users busis = (Sys_Users)busisData;
                    lock (_lock)
                    {
                        if (busis.Columns.Count != bv.Value.Columns.Count)
                        {
                            return;
                        }
                        foreach (var id in UpdList)
                        {
                            DataRow[] drs = busis.Select(string.Format("ID={0}", id));
                            if (drs.Length == 0)
                            {
                                continue;
                            }
                            busis.Rows.Remove(drs[0]);
                        }
                        foreach (DataRow row in bv.Value.Rows)
                        {
                            busis.LoadDataRow(row, true);
                        }

                        busis.AcceptChanges();
                    }
                }
            }

            sql = "SELECT r.ID FROM sys_User a INNER JOIN sys_Role_User b ON a.ID=b.UserID INNER JOIN sys_Role r ON b.MID=r.ID where a.ID IN({0})";
            sql = string.Format(sql, sbd.ToString(0, sbd.Length - 1));
            bv  = dao.GetDataTable(sql);

            if (bv.Success && bv.Value.Rows.Count > 0)
            {
                base.addThreadInfo(DBNo);
                foreach (DataRow row in bv.Value.Rows)
                {
                    Sys_Role busi = Sys_Roles.GetItem(Convert.ToInt32(row["ID"]));
                    if (busi == null)
                    {
                        continue;
                    }
                    busi.ResetRoleUsers();
                }
            }
        }
Пример #2
0
        public void RemoveRecord(List <int> DelList, DAO dao, string DBNo, string sysLinkName, string CacheKey = null)
        {
            if (DelList == null || DelList.Count == 0)
            {
                return;
            }
            if (CacheKey != null)
            {
                object busisData = null;
                YueMES.Base.Dal.DTO.TryGetCache(string.IsNullOrEmpty(CacheKey) ? Default_sql : CacheKey, DBNo, out busisData);
                if (busisData == null)
                {
                    return;
                }
                Sys_Users busis = (Sys_Users)busisData;
                base.addThreadInfo(DBNo);
                List <DataRow> lst = null;
                if (DAO.Default.dataBaseType == DataBaseType.Oracle)
                {
                    lst = (from a in busis.AsEnumerable()
                           join b in Sys_Role_Users.Default.AsEnumerable()
                           on a.Field <Int64>("ID") equals b.Field <Int64>("UserID")
                           join c in Sys_Roles.Default.AsEnumerable()
                           on b.Field <Int64>("MID") equals c.Field <Int64>("ID")
                           where DelList.Contains(Convert.ToInt32(a.Field <Int64>("ID")))
                           select c).ToList();
                }
                else
                {
                    lst = (from a in busis.AsEnumerable()
                           join b in Sys_Role_Users.Default.AsEnumerable()
                           on a.Field <int>("ID") equals b.Field <int>("UserID")
                           join c in Sys_Roles.Default.AsEnumerable()
                           on b.Field <int>("MID") equals c.Field <int>("ID")
                           where DelList.Contains(a.Field <int>("ID"))
                           select c).ToList();
                }
                if (lst != null && lst.Count > 0)
                {
                    foreach (DataRow row in lst)
                    {
                        Sys_Role role = Sys_Roles.GetItem(Convert.ToInt32(row["ID"]));
                        if (role != null)
                        {
                            role.ResetRoleUsers();
                        }
                    }
                }


                lock (_lock)
                {
                    foreach (var id in DelList)
                    {
                        DataRow[] drs = busis.Select(string.Format("ID={0}", id));
                        if (drs.Length == 0)
                        {
                            continue;
                        }
                        busis.Rows.Remove(drs[0]);
                    }

                    busis.AcceptChanges();
                }
            }
        }