获得所有user以及相关person

fn_User_GetAllUserPerson

    with userSectorCte(userid, sectorid)
    as
    (
        select u.id, us.SectorId
        from  [User] u
        inner join User_Sector us on us.UserId = u.id
        where u.Validity = 1 and u.Level = @UserLevel

        UNION ALL   
        SELECT userid,s.Id
        FROM Sector s
        INNER JOIN userSectorCte us ON us.sectorid = s.ParentId
    )
    --select * from userSectorCte
    select distinct usCte.userid as 'UserId', sp.PersonId
    from userSectorCte usCte
    inner join Sector s on s.Id = usCte.sectorid
    inner join Service serv on serv.SectorId = s.Id and serv.Validity = 1
    inner join Service_Person sp on sp.ServiceId = serv.Id
    inner join Person p on p.id = sp.PersonId and p.Validity = 1   
    where s.Level = 2

self.comboActionPlan = new Ext.form.ComboBox({
                id: 'TraceActionPlan.cbActionPlan',
                columnWidth: 0.5,
                mode: 'local',
                triggerAction: 'all',
                store: self.Controller.ActionPlanStore,
                valueField: 'ID',
                displayField: 'PacName',
                listeners: {
                    select: self.cbActionPlan_select,
                    render: function(combo) {
                        combo.store.load({});
                    }
                }
            });

            //displayfield Population
            self.dfPopulation = new Ext.form.DisplayField({
                columnWidth:0.3,
                value:translate('Population')
            });

            //combo Population
            self.comboPopulation = new Ext.form.ComboBox({
                columnWidth: 0.5,
                typeAhead: true,
                triggerAction: 'all',
                lazyRender: true,
                id: 'TraceActionPlan.view.comboPopulation',
                listeners: {
                    select: self.comboPopulation_handler,
                    render: function(combo) {
                        combo.store.load({
                            params: {
                                userId: Application.Main.State.User.ID,
                                userLevel: Application.Main.State.User.Level,
                                loadOnlyMaxLevel: true,
                                loadNetworks: true,
                                lang: Application.Main.State.LanguageCode
                            }                       
                        });
                    }
                },
                minListWidth: 250,
                mode: 'local',
                store: self.Controller.userStore,
                valueField: 'Id',
                displayField: 'Name'
            });
           
            self.Controller.userStore.on({
                'load':function(store){
                    try{
                        if(store.data.length == 1){   
                            var data = store.data.items[0].data;
                            self.comboPopulation.setValue(data.Name);
                            self.Controller.criteriaActionPlanSearch.PopulationId = data.Id;
                            self.Controller.criteriaActionPlanSearch.PopulationType = data.Type;
                        }
                    }catch(ext){
                        ExceptionHandler.report('TraceActionPlan.userStore.onLoad');
                    }
                }
            });
           
            self.Controller.ActionPlanStore.on({
                'load': function(store){
                    try {
                        var combo = Ext.getCmp('TraceActionPlan.cbActionPlan');
                        var record = store.getAt(0);           
                        combo.fireEvent('select',combo,record);
                                                   
                    } catch(exc) {
                        ExceptionHandler.report('Targeting.cbActionPlanStore.onLoad');
                    }
                }
            });

posted on 2011-03-31 17:09  鱼不爱水  阅读(115)  评论(0)    收藏  举报