Ejemplo n.º 1
0
        private void ChechByResRole(HttpContext context)
        {
            bool isRepeat   = false; //是否有重复
            var  priResRole = context.Request.QueryString["ResRole"];
            var  otherIds   = context.Request.QueryString["OtherIds"];

            if (!string.IsNullOrEmpty(priResRole) && !string.IsNullOrEmpty(otherIds))
            {
                otherIds = ClearRepeatRes(otherIds);
                var priArr     = priResRole.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                var resDepList = new sys_resource_department_dal().GetListByIds(otherIds);
                if (priArr.Count() == 2 && resDepList != null && resDepList.Count > 0)
                {
                    var thisResDep = resDepList.FirstOrDefault(_ => _.resource_id.ToString() == priArr[0]);
                    if (thisResDep != null)
                    {
                        isRepeat = true;
                        resDepList.Remove(thisResDep);
                        otherIds = string.Empty;
                        resDepList.ForEach(_ => {
                            otherIds += _.id.ToString() + ',';
                        });
                        if (!string.IsNullOrEmpty(otherIds))
                        {
                            otherIds = otherIds.Substring(0, otherIds.Length - 1);
                        }
                    }
                }
            }
            context.Response.Write(new Tools.Serialize().SerializeJson(new { isRepeat = isRepeat, newDepResIds = otherIds }));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 剔除掉选择的重复的员工
        /// </summary>
        private string ClearRepeatRes(string resDepIds)
        {
            string newResDepIds = resDepIds;
            var    resDepList   = new sys_resource_department_dal().GetListByIds(resDepIds);

            if (resDepList != null && resDepList.Count > 0)
            {
                var resDepArr = resDepList.ToArray();
                foreach (var resDep in resDepArr)
                {
                    // 获取到重复的员工信息
                    if (resDepList.Any(_ => _.id == resDep.id))
                    {
                        var repList = resDepArr.Where(thisResDep => thisResDep.id != resDep.id && thisResDep.resource_id == resDep.resource_id).ToList();
                        if (repList != null && repList.Count > 0)
                        {
                            repList.ForEach(_ => { resDepList.Remove(_); });
                        }
                        resDepArr = resDepList.ToArray();
                    }
                }
                if (resDepList != null && resDepList.Count > 0)
                {
                    newResDepIds = "";
                    resDepList.ForEach(_ => { newResDepIds += _.id.ToString() + ","; });
                    if (newResDepIds != "")
                    {
                        newResDepIds = newResDepIds.Substring(0, newResDepIds.Length - 1);
                    }
                }
            }
            return(newResDepIds);
        }