Beispiel #1
0
        /// <summary>
        /// 依存するモデルオブジェクトを外します。
        /// </summary>
        public static void RemoveDependModel(this IParentModel self,
                                             object model)
        {
            if (model == null)
            {
                return;
            }

            lock (self)
            {
                // 参照比較で比較します。
                var index = self.DependModelList.FindIndex(
                    obj => object.ReferenceEquals(obj, model));
                if (index < 0)
                {
                    return;
                }

                self.DependModelList.RemoveAt(index);

                // 必要ならPropertyChangedを外します。
                var notify = model as INotifyPropertyChanged;
                if (notify != null)
                {
                    notify.PropertyChanged -= self.DependModel_PropertyChanged;
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Prepara os valores e retorna os em um formato de exibição para o usuário
        /// <para>Como padrão retorna os três primeiros campos do select que foi criado</para>
        /// </summary>
        /// <param name="w">Filtro, se necessário. Não é obrigatório e pode ser nulo</param>
        /// <param name="model">Modelo base</param>
        /// <typeparam name="T">Tipo de modelo que deverá ser retornado</typeparam>
        /// <param name="pageSize">Tamanho da página de registros</param>
        /// <param name="executeCommand">Se true, irá executar o comando e retornar os dados</param>
        /// <returns>Retorna os valores em um um formato de exibição para o usuário</returns>
        public static IDisplayValues GetDisplayValues(IParentModel model, Where w = null, bool executeCommand = true, int pageSize = 100)
        {
            if (w == null)
            {
                w = new Where
                {
                    Limit = pageSize
                }
            }
            ;

            IDisplayValues result     = new DisplayValues(model);
            DataReader     dataReader = null;

            try
            {
                model.Connection = DbContext.CreateConnection();
                TableDefinitionAttribute tableDefinition = FindTableDefinition(model);
                //recuperar o campo GUID da tabela mais básica
                Command command = new Command();
                new CommandFactory(model).PrepareCommandSelect(tableDefinition, w, null, null, ref command);
                command.Connection = model.Connection;
                dataReader         = executeCommand ? command.ExecuteReader() : command.ExecuteReader(System.Data.CommandBehavior.SchemaOnly);
            }
            finally
            {
                model.Connection.Close();
            }

            result.Where      = w;
            result.DataReader = dataReader;
            return(result);
        }
Beispiel #3
0
 public ParentHeaderViewModel(IParentModel parent, Func <IParentModel, Uri> getUrl,
                              Func <IParentModel, Uri> getIconUrl)
 {
     Parent     = parent;
     GetUrl     = getUrl;
     GetIconUrl = getIconUrl;
 }
Beispiel #4
0
        /// <summary>
        /// 依存する他のモデルオブジェクトを追加します。
        /// </summary>
        public static void AddDependModel(this IParentModel self, object model,
                                          bool notifyAllPropertyChanged)
        {
            if (model == null)
            {
                return;
            }

            lock (self)
            {
                // もしそのモデルオブジェクトがINotifyPropertyChangedを
                // 継承していれば、そのオブジェクトのプロパティ値変更情報を
                // 使います。
                var notify = model as INotifyPropertyChanged;
                if (notify != null)
                {
                    notify.PropertyChanged += self.DependModel_PropertyChanged;
                }

                self.DependModelList.Add(model);

                // モデルが持つ全プロパティの変更通知を出します。
                // (重複したプロパティに対して通知が出されることがあります)
                if (notifyAllPropertyChanged)
                {
                    self.RaiseAllPropertyChanged(model);
                }
            }
        }
Beispiel #5
0
 /// <summary>
 /// 指定のモデルオブジェクトが依存リストに追加されたか調べます。
 /// </summary>
 public static bool HasDependModel(this IParentModel self, object model)
 {
     lock (self)
     {
         return(self.DependModelList.FindIndex(
                    obj => object.ReferenceEquals(obj, model)) >= 0);
     }
 }
 public ParentNewsListViewModel(BaseViewModelConfig config, IParentModel parent,
                                IEnumerable <Common.Models.News> news, int totalNews,
                                int currentPage) : base(config)
 {
     Parent      = parent;
     News        = news;
     TotalNews   = totalNews;
     CurrentPage = currentPage;
 }
Beispiel #7
0
 /// <summary>
 /// 依存するモデルオブジェクトすべて削除します。
 /// </summary>
 public static void ClearDependModels(this IParentModel self)
 {
     lock (self)
     {
         while (self.DependModelList.Count > 0)
         {
             self.RemoveDependModel(self.DependModelList[0]);
         }
     }
 }
 /// <summary>
 /// Inicia esta instância
 /// </summary>
 public DisplayValues(IParentModel model)
 {
     PageSize = 100;
     Columns  = new List <Parameter>();
     Values   = new List <object[]>();
     Model    = model;
     Where    = new Where
     {
         Limit = new Limit(PageSize, 0)
     };
 }
Beispiel #9
0
        /// <summary>
        /// Preenche o modelo com os dados de base
        /// </summary>
        /// <param name="model">modelo que deverá ser preenchido</param>
        /// <param name="dataReader">DataReader com os dados que deverão ser passados ao ojeto</param>
        internal static void Populate(IParentModel model, DataReader dataReader)
        {
            model.CurrentDataReader = dataReader;
            model.New = false;
            if (PreparePopulateAction == null)
            {
                throw new NotImplementedException("PreparePopulateAction was not implemented for this DbContext. Please implement the action DbContext.PreparePopulateAction");
            }

            PreparePopulateAction(model);
        }
Beispiel #10
0
        /// <summary>
        /// Exibe o formulário de psquisa com os registros
        /// </summary>
        ///<param name="model">Modelo que deverá s</param>
        public static SearchWindowResult Show(IParentModel model)
        {
            SearchWindowForm form = new SearchWindowForm();
            form.MainGrid.Populate(model.GetDisplayValues());
            form.ShowDialog();
            SearchWindowResult result = form.Result;
            form.Close();
            form.Dispose();

            return result;
        }
Beispiel #11
0
        private async Task <FileCat> GetCat(IParentModel parent, string catUrl, bool loadChildren = false,
                                            int?loadLastItems = null)
        {
            var url = catUrl.Split('/').Last();

            return(await Mediator.Send(new GetFilesCategoryQuery
            {
                Parent = parent,
                Url = url,
                LoadChildren = loadChildren,
                LoadLastItems = loadLastItems
            }));
        }
Beispiel #12
0
        private async Task <File> GetFile(IParentModel parent, string catUrl, string articleUrl)
        {
            if (!string.IsNullOrEmpty(catUrl) && !string.IsNullOrEmpty(articleUrl))
            {
                if (catUrl.IndexOf('/') > -1)
                {
                    catUrl = catUrl.Split('/').Last();
                }

                return(await Mediator.Send(new GetFileByUrlQuery(parent, catUrl, articleUrl)));
            }
            return(null);
        }
Beispiel #13
0
        public Uri ParentUrl(IParentModel parent, bool absoluteUrl = false)
        {
            switch (parent.Type)
            {
            case ParentType.Game:
                return(PublicUrl((Game)parent, absoluteUrl));

            case ParentType.Developer:
                return(PublicUrl((Developer)parent, absoluteUrl));

            case ParentType.Topic:
                return(PublicUrl((Topic)parent, absoluteUrl));

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Beispiel #14
0
        public virtual bool DoSave()
        {
            bool flag = true;

            this.SaveDataInfo = "保存失败!";
            foreach (KeyValuePair <string, IChildForm> pair in this.IChildrens)
            {
                if (pair.Value.EveryThingIsOk)
                {
                    pair.Value.SaveDataInfo = "";
                    pair.Value.UpdataToModel();
                    if (pair.Value.CheckErrorInput() == ChildFormStatus.HasErrorInput)
                    {
                        flag = false;
                        this.IParentFrm.ChildStatus(pair.Key, ChildFormStatus.HasErrorInput);
                        Controler controler = this;
                        string    str       = controler.SaveDataInfo + pair.Value.SaveDataInfo;
                        controler.SaveDataInfo = str;
                    }
                }
            }
            if (!flag)
            {
                return(false);
            }
            foreach (KeyValuePair <string, IChildForm> pair2 in this.IChildrens)
            {
                if (pair2.Value.EveryThingIsOk)
                {
                    flag = pair2.Value.SaveModelToDB();
                }
            }
            if (!flag)
            {
                return(false);
            }
            IParentModel <RecordsBaseInfoModel> iParentFrm = this.IParentFrm as IParentModel <RecordsBaseInfoModel>;

            if (iParentFrm != null)
            {
                iParentFrm.SaveModel();
            }
            return(flag);
        }
Beispiel #15
0
        private async Task <IActionResult> ParentNewsList(IParentModel parent, int page = 1)
        {
            if (page < 1)
            {
                return(BadRequest());
            }

            var canUserSeeUnpublishedNews = await HasRight(UserRights.News);

            var newsResult = await Mediator.Send(new GetNewsQuery
            {
                WithUnPublishedNews = canUserSeeUnpublishedNews,
                Page   = page,
                Parent = parent
            });

            return(View("ParentNews",
                        new ParentNewsListViewModel(ViewModelConfig, parent, newsResult.models, newsResult.totalCount, page)));
        }
        public async Task <IParentModel> GetModelParentAsync(IChildModel model)
        {
            IParentModel parent = null;

            if (model.GameId > 0)
            {
                parent = (await GetGamesAsync()).FirstOrDefault(x => x.Id == model.GameId);
            }
            if (model.DeveloperId > 0)
            {
                parent = (await GetDevelopersAsync()).FirstOrDefault(x => x.Id == model.DeveloperId);
            }
            if (model.TopicId > 0)
            {
                parent = (await GetTopicsAsync()).FirstOrDefault(x => x.Id == model.TopicId);
            }
            if (parent == null)
            {
                throw new Exception("No parent!");
            }
            return(parent);
        }
Beispiel #17
0
        protected IQueryable <T> ApplyParentCondition <T>(IQueryable <T> query, IParentModel parent) where T : IChildModel
        {
            switch (parent.Type)
            {
            case ParentType.Game:
                query = query.Where(x => x.GameId == (int)parent.GetId());
                break;

            case ParentType.Developer:
                query = query.Where(x => x.DeveloperId == (int)parent.GetId());
                break;

            case ParentType.Topic:
                query = query.Where(x => x.TopicId == (int)parent.GetId());
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            return(query);
        }
Beispiel #18
0
 public ParentArticlesViewModel(BaseViewModelConfig config, IParentModel parent,
                                IEnumerable <ArticleCat> cats) : base(config)
 {
     Parent = parent;
     Cats   = cats;
 }
Beispiel #19
0
 public Uri ParentFilesUrl(IParentModel parent, bool absolute = false)
 {
     return(GetUrl(FilesRoutesEnum.FilesByParent, new { parentUrl = parent.ParentUrl }, absolute));
 }
Beispiel #20
0
 /// <summary>
 /// Exibe o formulário de pesquisa com os registros
 /// </summary>
 ///<param name="model">Modelo que deverá ser</param>
 public static SearchWindowResult Show(IParentModel model, Where w = null)
 {
     //Se em algum ponto foi informado um filtro, o "GetDisplayValues()" vai adicionar esse filtro em seu comando.
     return Show(model.GetDisplayValues(w));
 }
Beispiel #21
0
 public Uri ParentNewsUrl(IParentModel parent, int?page = null, bool absolute = false)
 {
     return(GetUrl(page > 0 ? NewsRoutesEnum.NewsByParentWithPage : NewsRoutesEnum.NewsByParent,
                   new { parentUrl = parent.ParentUrl, page }, absolute));
 }
Beispiel #22
0
        public override bool DoSave()
        {
            BindingFlags bindingAttr = BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly;
            PhysicalForm iParentFrm  = base.IParentFrm as PhysicalForm;
            bool         flag        = true;

            base.SaveDataInfo = "保存失败!\r\n";
            IEnumerable <IGrouping <string, RecordsRequiredModel> > enumerable = from a in iParentFrm.Archive_requireds group a by a.BTable;

            foreach (KeyValuePair <string, IChildForm> pair in base.IChildrens)
            {
                if (pair.Value.EveryThingIsOk)
                {
                    pair.Value.SaveDataInfo = "";
                    pair.Value.UpdataToModel();
                    foreach (PropertyInfo info in pair.Value.GetType().GetProperties(bindingAttr))
                    {
                        if (info.PropertyType.Name.Contains("Records"))
                        {
                            using (IEnumerator <IGrouping <string, RecordsRequiredModel> > enumerator = enumerable.GetEnumerator())
                            {
                                while (enumerator.MoveNext())
                                {
                                    Predicate <RecordsRequiredModel>         match     = null;
                                    IGrouping <string, RecordsRequiredModel> tmp_model = enumerator.Current;
                                    if ((info.PropertyType.Name == tmp_model.Key) && ((pair.Key != "一般情况") || (tmp_model.Key != "RecordsPhysicalExamModel")))
                                    {
                                        object obj2 = info.GetValue(pair.Value, null);
                                        if (match == null)
                                        {
                                            match = req => req.BTable == tmp_model.Key;
                                        }
                                        foreach (RecordsRequiredModel archive_required in iParentFrm.Archive_requireds.FindAll(match))
                                        {
                                            decimal?nullable = archive_required.IsRequired;
                                            if (((nullable.GetValueOrDefault() != 0M) ? 0 : (nullable.HasValue ? 1 : 0)) == 0)
                                            {
                                                PropertyInfo property = obj2.GetType().GetProperty(archive_required.Name, bindingAttr);
                                                if (property != null)
                                                {
                                                    object obj3 = property.GetValue(obj2, null);
                                                    if (obj3 == null)
                                                    {
                                                        PEControler controler = this;
                                                        string      str       = controler.SaveDataInfo + archive_required.Comment + " :必填\r\n";
                                                        controler.SaveDataInfo = str;
                                                        flag = false;
                                                    }
                                                    else if (string.IsNullOrEmpty(obj3.ToString()))
                                                    {
                                                        PEControler controler2 = this;
                                                        string      str2       = controler2.SaveDataInfo + archive_required.Comment + " :必填\r\n";
                                                        controler2.SaveDataInfo = str2;
                                                        flag = false;
                                                    }
                                                }
                                                else
                                                {
                                                    PEControler controler3 = this;
                                                    string      str3       = controler3.SaveDataInfo + archive_required.Comment + " :必填\r\n";
                                                    controler3.SaveDataInfo = str3;
                                                    flag = false;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    if (!flag)
                    {
                        return(false);
                    }
                    if (pair.Value.CheckErrorInput() == ChildFormStatus.HasErrorInput)
                    {
                        flag = false;
                        base.IParentFrm.ChildStatus(pair.Key, ChildFormStatus.HasErrorInput);
                        PEControler controler4 = this;
                        string      str4       = controler4.SaveDataInfo + pair.Value.SaveDataInfo;
                        controler4.SaveDataInfo = str4;
                    }
                }
            }
            if (!flag)
            {
                return(false);
            }
            foreach (KeyValuePair <string, IChildForm> pair2 in base.IChildrens)
            {
                if (pair2.Value.EveryThingIsOk)
                {
                    flag = pair2.Value.SaveModelToDB();
                }
            }
            if (!flag)
            {
                return(false);
            }
            IParentModel <RecordsBaseInfoModel> model = base.IParentFrm as IParentModel <RecordsBaseInfoModel>;

            if (model != null)
            {
                model.SaveModel();
            }
            return(flag);
        }
Beispiel #23
0
 /// <summary>
 /// 依存する他のモデルオブジェクトを追加します。
 /// </summary>
 public static void AddDependModel(this IParentModel self, object model)
 {
     self.AddDependModel(model, true);
 }
Beispiel #24
0
 public Uri ParentIconUrl(IParentModel parent)
 {
     return(ParentIconUrl((dynamic)parent));
 }
Beispiel #25
0
 public GetArticleByUrlQuery(IParentModel parent, string catUrl, string url)
 {
     Parent = parent;
     CatUrl = catUrl;
     Url    = url;
 }
Beispiel #26
0
 public ParentGalleryViewModel(BaseViewModelConfig config, IParentModel parent,
                               IEnumerable <GalleryCat> cats) : base(config)
 {
     Parent = parent;
     Cats   = cats;
 }
 public Uri ParentArticlesUrl(IParentModel parentModel, bool absolute = false)
 {
     return(GetUrl(ArticlesRoutesEnum.ArticlesByParent, new { parentUrl = parentModel.ParentUrl }, absolute));
 }
 public Uri ParentGalleryUrl(IParentModel parentModel, bool absolute = false)
 {
     return(GetUrl(GalleryRoutesEnum.ParentPage, new { parentUrl = parentModel.ParentUrl }, absolute));
 }