月耳思进

人生在世如身处荆棘之中,心不动,人不妄动,不动则不伤;如心动则人妄动,伤其身痛其骨,于是体会到世间诸般痛苦。
  首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

C:\Inetpub\wwwroot\JYSoftWeb\AffairOfLaw\BLL\UserInterface\UserInfoBLL.cs

Posted on 2006-07-06 17:24  Xfan  阅读(430)  评论(0编辑  收藏  举报
using System;
using JySoft.AffairOfLaw.Model.Common;
using JYSoft.Platform.Security.Data;
using JYSoft.Platform.Security.Facade;
using JySoft.AffairOfLaw;
using System.Collections;

namespace JySoft.AffairOfLaw.BLL.UserInterface
{
    
/// <summary>
    
/// UserInfoBLL 的摘要说明。
    
/// </summary>

    public class UserInfoBLL
    
{
        
        
public UserInfoBLL()
        
{
        }

        
/// <summary>
        
/// 获取用户信息  用户ID 用户姓名 部门ID 部门名称 公司ID 公司名称
        
/// </summary>
        
/// <param name="iUserID"></param>
        
/// <param name="strUserName"></param>
        
/// <returns>UserID UserName DeptID DeptName CompanyID CompanyName</returns>

        public UserInfo GetUserInfo(int iUserID,string strUserName)
        
{
            
///OrganizeFacade组织机构管理正面类,提供组织的创建,获取等功能
            OrganizeFacadeAgent agent = new JYSoft.Platform.Security.Facade.OrganizeFacadeAgent();
            
//UserInfo自定义用户类
            UserInfo info = new JySoft.AffairOfLaw.Model.Common.UserInfo();
            
            info.UserID 
= iUserID;
            info.UserName 
= strUserName;
        
            
if(this.IsProvinceCompany(iUserID))
            
{
                
//ProvinceDepartmentLevel 省公司部室的组织机构级别
                Organize deptOrg = agent.GetEmpTopOrganizeByLevel(iUserID,Configuration.Orgnize.ProvinceDepartmentLevel);
                
                
if(deptOrg != null)
                
{
                    info.DeptID  
= deptOrg.OrgnizeId;
                    info.DeptName 
= deptOrg.OrganizeName;
                }


                
//ProvinceCompanyLevel 省公司组织机构的级别
                Organize compOrg = agent.GetEmpTopOrganizeByLevel(iUserID,Configuration.Orgnize.ProvinceCompanyLevel);
                
                
if(compOrg != null)
                
{
                    info.CompanyID  
= compOrg.OrgnizeId;
                    info.CompanyName 
= compOrg.OrganizeName;
                }

            }

                
//如果是市公司的员工
            else
            
{
                Organize deptOrg 
= agent.GetEmpTopOrganizeByLevel(iUserID,Configuration.Orgnize.CityDepartmentLevel);
                
if(deptOrg != null)
                
{
                    info.DeptID  
= deptOrg.OrgnizeId;
                    info.DeptName 
= deptOrg.OrganizeName;
                }

                Organize compOrg 
= agent.GetEmpTopOrganizeByLevel(iUserID,Configuration.Orgnize.CityCompanyLevel);
                
if(compOrg != null)
                
{
                    info.CompanyID  
= compOrg.OrgnizeId;
                    info.CompanyName 
= compOrg.OrganizeName;
                }

            }

           
            
return info;
        }


        
/// <summary>
        
/// 获取用户的公司ID
        
/// </summary>
        
/// <returns></returns>

        public Organize GetCompanyInfo(int iUserID)
        

            OrganizeFacadeAgent agent 
= new OrganizeFacadeAgent();
            Organize deptOrg 
= null;
            
if(IsProvinceCompany(iUserID) == true)
            
{
                deptOrg 
= agent.GetEmpTopOrganizeByLevel(iUserID,JySoft.AffairOfLaw.Configuration.Orgnize.ProvinceCompanyLevel);
            }

            
else
            
{
                deptOrg 
= agent.GetEmpTopOrganizeByLevel(iUserID,JySoft.AffairOfLaw.Configuration.Orgnize.CityDepartmentLevel);
            }

            
return deptOrg;
        }

         
        
/// <summary>
        
/// 获取用户的部室信息
        
/// </summary>
        
/// <param name="iUserID"></param>
        
/// <returns></returns>

        public Organize GetDepartmentInfo(int iUserID)
        
{
            OrganizeFacadeAgent agent 
= new OrganizeFacadeAgent();
            Organize companyOrg 
= null;
            
if(IsProvinceCompany(iUserID) == true)
            
{
                companyOrg 
= agent.GetEmpTopOrganizeByLevel(iUserID,JySoft.AffairOfLaw.Configuration.Orgnize.ProvinceDepartmentLevel);
                
            }

            
else
            
{
                companyOrg 
= agent.GetEmpTopOrganizeByLevel(iUserID,JySoft.AffairOfLaw.Configuration.Orgnize.CityDepartmentLevel);
            }

            
return companyOrg;
        }



    
        
/// <summary>
        
/// 判断该用户是不是省公司用户
        
/// </summary>
        
/// <param name="iUserID"></param>
        
/// <returns></returns>

        public bool IsProvinceCompany(int iUserID)
        
{
            OrganizeFacadeAgent agent 
= new OrganizeFacadeAgent();
            
//Organize 类 组织机构实体类
            
//JySoft.AffairOfLaw.Configuration.Orgnize.JugeCompanyLevel 部门等级
            Organize proCompOrg = agent.GetEmpTopOrganizeByLevel(iUserID,JySoft.AffairOfLaw.Configuration.Orgnize.JugeCompanyLevel);
            
//如果是省公司的员工
            
//OrgnizeId 组织机构编号 
            if(proCompOrg != null && proCompOrg.OrgnizeId == JySoft.AffairOfLaw.Configuration.Orgnize.ProvinceOrgID)
            
{
                
return true;
            }

            
else
            
{
                
return false;
            }

        }


        
/// <summary>
        
/// 取得指定节点的接受人员 JYSoft.Workflow.Definitions.User[] GetActors( string taskID)
        
/// </summary>
        
/// <returns>
        
///  接受人员集合actors
        
/// </returns>

        public JYSoft.Workflow.Definitions.User[] GetActors( string processID,string stepCode,JySoft.AffairOfLaw.Model.Common.UserInfo userInfo)
        
{
              
//FlowFrameService 工作流框架需要调用的服务正面 
              JYSoft.Workflow.Facades.FlowFrameServiceAgent service = new JYSoft.Workflow.Facades.FlowFrameServiceAgent();
//            JYSoft.Workflow.Runtime.Task task = service.GetTaskByTaskID(taskID);         
//            string workFlowID = task.ProcessInstanceId;  //取得工作流程ID
//            string stepID =service.GetStepIDByProcDefIDAndStepCode(processInstanceId,"bsqrsh");  //根据工作流程ID和环节点名称取得环节点ID
//            JYSoft.Workflow.Definitions.User[] actors = new JYSoft.Workflow.Facades.FlowFrameService().GetStepReceiptors(stepID);
            
            
//processID  工作流程ID
            
//stepCode  环节点名称
            
//stepID 环节点ID
            string stepID = service.GetStepIDByProcDefIDAndStepCode( processID,stepCode);
            
//获得流程步骤的接收者
            JYSoft.Workflow.Definitions.User[] users = service.GetCurrentStepReceiptors(stepID);

            JYSoft.Workflow.Facades.FlowFrameServiceAgent agent 
= new JYSoft.Workflow.Facades.FlowFrameServiceAgent();
            
//JYSoft.Workflow.Definitions.User[] users = new JYSoft.Workflow.Facades.FlowFrameServiceAgent().GetCurrentStepReceiptors("JYBSFZRDG");
//            Organizes organizes; //= new JYSoft.Platform.Security .Facade.OrganizeFacadeAgent().GetOrganizeWithSubOrgs(
            
            
if(userInfo.CompanyID == JySoft.AffairOfLaw.Configuration.Orgnize.ProvinceOrgID)
            
{
                organizes 
= new JYSoft.Platform.Security.Facade.OrganizeFacadeAgent().GetEmpTopOrganizesByLevel(userInfo.UserID,JySoft.AffairOfLaw.Configuration.Orgnize.ProvinceCompanyLevel + 1);

            }

            
else
            
{
                organizes 
= new JYSoft.Platform.Security .Facade.OrganizeFacadeAgent().GetEmpTopOrganizesByLevel(userInfo.UserID,JySoft.AffairOfLaw.Configuration.Orgnize.CityCompanyLevel);
            }


            Organize organize 
= new JYSoft.Platform.Security .Facade.OrganizeFacadeAgent().GetOrganizeWithSubOrgs(organizes[0].OrgnizeId);
            JYSoft.Workflow.Definitions.User[] receiptorUsers  
=  this.GetUsers(organize,users);
            
return receiptorUsers;
        }


         
/// <summary>
         
/// 用户是否存在于某个组织机构中
         
/// </summary>
         
/// <param name="organize"></param>
         
/// <param name="user"></param>
         
/// <returns></returns>
         
/// JYSoft.Workflow.Definitions.User user 属性groupid groupname id name type
         
///JYSoft.Platform.Security.Data.Organize organize 属性

        private bool IsExist(Organize organize,JYSoft.Workflow.Definitions.User user)
        
{
            
bool exist = false;
            
if(user.GroupId == organize.OrgnizeId.ToString())
            
{
                exist 
= true;
                
return exist;
            }

            
//SubOrganizes 下级组织机构集合 
            foreach(Organize entity in organize.OrgnizeId.SubOrganizes)
            
{
                 IsExist(entity,user,
ref exist);
                
if(exist == true)
                
{
                    
return exist;
                }


            }

            
return false;
        }


         
//ref 关键字使参数按引用传递。其效果是,当控制权传递回调用方法时,在方法中对参数所做的任何更改都将反映在该变量中。
        
//若要使用 ref 参数,则方法定义和调用方法都必须显式使用 ref 关键字
        private void IsExist(Organize organize,JYSoft.Workflow.Definitions.User user,ref bool exist)
        
{
            
if(user.GroupId == organize.OrgnizeId.ToString())
            
{
                exist 
= true;
                
return;
            }

            
foreach(Organize entity in organize.SubOrganizes)
            
{
                 IsExist(entity,user,
ref exist);
                
if(exist == true)
                
{
                    
return;
                }

            }

        }
 
        
/// <summary>
        
/// 获取某个组织机构下的User
        
/// </summary>
        
/// <param name="organize"></param>
        
/// <param name="users"></param>
        
/// <returns></returns>

        private JYSoft.Workflow.Definitions.User[] GetUsers(Organize organize, JYSoft.Workflow.Definitions.User[] users)
        
{
            ArrayList arr 
= new ArrayList();
            
for(int i = 0; i < users.Length; i ++)
            
{
                
if(IsExist(organize,users[i]))     
                
{
                    arr.Add(users[i]);
                }

            }

            JYSoft.Workflow.Definitions.User[] receiptorUsers 
= new  JYSoft.Workflow.Definitions.User[arr.Count];
            arr.CopyTo(receiptorUsers);
            
return receiptorUsers;
        }


        
/// <summary>
        
/// 递归根据某一组织机构ID获取组织机构
        
/// </summary>
        
/// <param name="entities"></param>
        
/// <param name="orgnizeID"></param>
        
/// <returns></returns>

        private Organize GetOrganize(Organizes entities,int orgnizeID)
        
{
            
foreach(Organize entity in entities)
            
{
                
if(entity.OrgnizeId == orgnizeID)
                
{
                    
return entity;
                }

                
else
                
{
 
                    Organize tmpEntity 
= GetOrganize(entity.SubOrganizes,orgnizeID);
                    
if(tmpEntity != null
                    
{
                        
return tmpEntity;
                    }

                }

            }

            
return null;
        }


    }

}