示例#1
0
        private async void TriggerControlsWithPrivilegies(Credentials user)
        {
            using (var repo = new Repository())
            {
                tilePassport.Tag = user.IsEdu ? user.EduId : (user.IsMunicipality ? user.MunitId : 0);

                var syncCtx = SynchronizationContext.Current;
                var view = windowsUIViewMain;
                if (user.IsRegion || user.IsMinistry)
                {
                    tileForms.Click += (sender, args) =>
                        Actions.LoadMunicipalityLayerAction.Invoke(sender, args, view, false, FormType.Edu, syncCtx);
                    tileArchiveForms.Click += (sender, args) =>
                        Actions.LoadMunicipalityLayerAction.Invoke(sender, args, view, true, FormType.Edu, syncCtx);
                    tileAdditionalForms.Click += (sender, args) => 
                        Actions.LoadMunicipalityLayerAction.Invoke(sender, args, view, false, FormType.OtherEdu, syncCtx);
                    tileArchiveAdditionalForms.Click += (sender, args) => 
                        Actions.LoadMunicipalityLayerAction.Invoke(sender, args, view, true, FormType.OtherEdu, syncCtx);
                    tileMunicipalityForms.Click += (sender, args) => 
                        Actions.LoadMunicipalityMunicipalityLayerAction.Invoke(sender, args, view, false, FormType.Municipality, syncCtx);
                    tileMunicipalityArchiveForms.Click += (sender, args) => 
                        Actions.LoadMunicipalityMunicipalityLayerAction.Invoke(sender, args, view, true, FormType.Municipality, syncCtx);
                    tileMunicipalityAdditionalForms.Click += (sender, args) => 
                        Actions.LoadMunicipalityMunicipalityLayerAction.Invoke(sender, args, view, false, FormType.OtherMunicipality, syncCtx);
                    tileMunicipalityArchiveAdditionalForms.Click += (sender, args) => 
                        Actions.LoadMunicipalityMunicipalityLayerAction.Invoke(sender, args, view, true, FormType.OtherMunicipality, syncCtx);

                    var regionAction = Actions.LoadRegionsLayerAction;
                    if (user.IsRegion)
                    {
                        regionAction = Actions.LoadRegionFormsLayerAction;
                    }
                    tileRegionForms.Click += (sender, args) => 
                        regionAction.Invoke(sender, args, view, false, FormType.Region, syncCtx);
                    tileRegionAdditionalForms.Click += (sender, args) => 
                        regionAction.Invoke(sender, args, view, false, FormType.OtherRegion, syncCtx);
                    tileRegionArchiveForms.Click += (sender, args) => 
                        regionAction.Invoke(sender, args, view, true, FormType.Region, syncCtx);
                    tileRegionArchiveAdditionalForms.Click += (sender, args) => 
                        regionAction.Invoke(sender, args, view, true, FormType.OtherRegion, syncCtx);
                }
                else if (user.IsMunicipality)
                {
                    var munit = await repo.GetMunicipality(user.MunitId);
                    tileMunicipalityForms.Tag = TagHelper.GetTag(TagHelper.TagType.Tile, munit);
                    tileMunicipalityForms.Click +=
                        (sender, args) =>
                            Actions.LoadMunicipalityFormsLayerAction.Invoke(sender, args, view, false,
                                FormType.Municipality, syncCtx);
                    tileMunicipalityArchiveForms.Tag = TagHelper.GetTag(TagHelper.TagType.Tile, munit, "archive");
                    tileMunicipalityArchiveForms.Click +=
                        (sender, args) =>
                            Actions.LoadMunicipalityFormsLayerAction.Invoke(sender, args, view, true,
                                FormType.Municipality, syncCtx);

                    tileMunicipalityAdditionalForms.Tag = TagHelper.GetTag(TagHelper.TagType.Tile, munit);
                    tileMunicipalityAdditionalForms.Click +=
                        (sender, args) =>
                            Actions.LoadMunicipalityFormsLayerAction.Invoke(sender, args, view, false,
                                FormType.OtherMunicipality, syncCtx);
                    tileMunicipalityArchiveAdditionalForms.Tag = TagHelper.GetTag(TagHelper.TagType.Tile, munit, "archive");
                    tileMunicipalityArchiveAdditionalForms.Click +=
                        (sender, args) =>
                            Actions.LoadMunicipalityFormsLayerAction.Invoke(sender, args, view, true,
                                FormType.OtherMunicipality, syncCtx);

                    tileForms.Tag = TagHelper.GetTag(TagHelper.TagType.Tile, munit);
                    tileForms.Click +=
                        (sender, args) =>
                            Actions.LoadEduKindLayerAction.Invoke(sender, args, view, false, FormType.Edu,
                                syncCtx);
                    tileArchiveForms.Tag = TagHelper.GetTag(TagHelper.TagType.Tile, munit, "archive");
                    tileArchiveForms.Click +=
                        (sender, args) =>
                            Actions.LoadEduKindLayerAction.Invoke(sender, args, view, true, FormType.Edu,
                                syncCtx);

                    tileAdditionalForms.Tag = TagHelper.GetTag(TagHelper.TagType.Tile, munit);
                    tileAdditionalForms.Click +=
                        (sender, args) =>
                            Actions.LoadEduKindLayerAction.Invoke(sender, args, view, false, FormType.OtherEdu,
                                syncCtx);
                    tileArchiveAdditionalForms.Tag = TagHelper.GetTag(TagHelper.TagType.Tile, munit,
                        "archive");
                    tileArchiveAdditionalForms.Click +=
                        (sender, args) =>
                            Actions.LoadEduKindLayerAction.Invoke(sender, args, view, true, FormType.OtherEdu,
                                syncCtx);

                    pageGroupQueries.Items.Clear();
                    pageGroupQueries.Items.Add(documentQueriesEdu);

                    tabbedGroupStatistics.Items.Remove(documentMunicipalityFormStatistics);
                    tabbedGroupStatistics.Items.Remove(documentMunicipalityFormDetailedStatistics);
                }
                else if (user.IsEdu)
                {
                    var edu = await repo.GetEdu(user.EduId);
                    tileForms.Tag = TagHelper.GetTag(TagHelper.TagType.Tile, edu);
                    tileForms.Click +=
                        (sender, args) =>
                            Actions.LoadEduFormsLayerAction.Invoke(sender, args, view, false, FormType.Edu,
                                syncCtx);
                    tileArchiveForms.Tag = TagHelper.GetTag(TagHelper.TagType.Tile, edu, "archive");
                    tileArchiveForms.Click +=
                        (sender, args) =>
                            Actions.LoadEduFormsLayerAction.Invoke(sender, args, view, true, FormType.Edu,
                                syncCtx);

                    tileAdditionalForms.Tag = TagHelper.GetTag(TagHelper.TagType.Tile, edu);
                    tileAdditionalForms.Click +=
                        (sender, args) =>
                            Actions.LoadEduFormsLayerAction.Invoke(sender, args, view, false, FormType.OtherEdu,
                                syncCtx);
                    tileArchiveAdditionalForms.Tag = TagHelper.GetTag(TagHelper.TagType.Tile, edu, "archive");
                    tileArchiveAdditionalForms.Click +=
                        (sender, args) =>
                            Actions.LoadEduFormsLayerAction.Invoke(sender, args, view, true, FormType.OtherEdu,
                                syncCtx);
                    pageGroupQueries.Items.Clear();
                }

                if (user.AccessRights.HasFlag(AccessRights.EduForms))
                {
                    tileContainerMain.Items.Add(tileForms);
                    tileContainerMain.Items.Add(tileArchiveForms);
                    tileContainerMain.Items.Add(tileAdditionalForms);
                    tileContainerMain.Items.Add(tileArchiveAdditionalForms);
                }
                if (user.AccessRights.HasFlag(AccessRights.MunitForms))
                {
                    tileContainerMain.Items.Add(tileMunicipalityForms);
                    tileContainerMain.Items.Add(tileMunicipalityArchiveForms);
                    tileContainerMain.Items.Add(tileMunicipalityAdditionalForms);
                    tileContainerMain.Items.Add(tileMunicipalityArchiveAdditionalForms);
                }
                if (user.AccessRights.HasFlag(AccessRights.RegionForms))
                {
                    tileContainerMain.Items.Add(tileRegionForms);
                    tileContainerMain.Items.Add(tileRegionArchiveForms);
                    tileContainerMain.Items.Add(tileRegionAdditionalForms);
                    tileContainerMain.Items.Add(tileRegionArchiveAdditionalForms);
                }
                if (user.AccessRights.HasFlag(AccessRights.Statistics))
                {
                    tileContainerMain.Items.Add(tileFormStatistics);
                }
                if (user.AccessRights.HasFlag(AccessRights.UploadForm))
                {
                    tileContainerMain.Items.Add(tileSpreadsheet);
                }
                if (user.AccessRights.HasFlag(AccessRights.Dictionaries))
                {
                    tileContainerMain.Items.Add(tileDictionaries);
                    tileContainerMain.Items.Add(tileMessageList);
                }
                if (user.AccessRights.HasFlag(AccessRights.Queries))
                {
                    tileContainerMain.Items.Add(tileQueries);
                }
                if (user.AccessRights.HasFlag(AccessRights.CreateQueries))
                {
                    tileContainerMain.Items.Add(tileCreateQuery);
                }
                if (user.AccessRights.HasFlag(AccessRights.Passport))
                {
                    tileContainerMain.Items.Add(tilePassport);
                }
                if (user.AccessRights.HasFlag(AccessRights.SendMessage))
                {
                    tileContainerMain.Items.Add(tileMessage);
                }
                
                if (user.IsEdu)
                {
                    tileForms.Tag = string.Format("Forms{0}", (int) FormType.Edu);
                    tileAdditionalForms.Tag = string.Format("Forms{0}", (int) FormType.OtherEdu);
                }
                var items = new BaseTile[tileContainerMain.Items.Count];
                tileContainerMain.Items.CopyTo(items, 0);
                tileContainerMain.Items.Clear();
                tileContainerMain.Items.AddRange(items.OrderBy(t => t.Group));
                
                labelLoggedUser.Text = user.Name;
                labelLoggedUser.Cursor = Cursors.Hand;
                if (user.IsEdu)
                {
                    labelLoggedUser.Click += (s, e) =>
                    {
                        windowsUIViewMain.ActivateContainer(pagePassport);
                    };
                }
                GuiUtility.NotifyAboutForms(user);
                if (Notifications.List.Count > 0)
                    flyoutPanelNotifications.ShowPopup();
                labelLoggedUser.Text = Authentication.Credentials.Name;

                ((HostForm)MdiParent).BarVisible = Authentication.Credentials.IsRegion;
            }
        }