示例#1
0
文件: LookUpLogic.cs 项目: HAMANZ/LMJ
        public GeneralContents <T> GetContent <T>(AdminTables table, string langCode, int offset, int limit, List <string> fields, bool isAll, long?LookUpId)
        {
            GeneralContents <T> contents = new GeneralContents <T>();

            LookUpAttributes        main       = new LookUpAttributes();
            Language                lang       = new Language();
            List <LookUpAttributes> attributes = new List <LookUpAttributes>();

            try
            {
                string XMLPath = ConfigurationManager.AppSettings["XMLPath"]; // @"~\LookUp.xml";

                lang = _LanguageAccessor.Get(langCode);

                //Get class's attributes

                attributes = Tools.GetAttributes(table.ToString(), XMLPath);
                //Get main attribute
                main = attributes
                       .Where(e => e.isMain == true)
                       .FirstOrDefault();

                int total = 0;
                if (main == null)
                {
                    main      = new LookUpAttributes();
                    main.Code = "This is any text";
                }

                /* contents = GetMono<T>(table, lang.Id, main.Code);*/
                if (attributes.Count != 0)
                {
                    contents.Contents = ReturnListOf <T>(table, lang.Id, offset, limit, attributes, main, fields, isAll, out total, LookUpId);
                }
                contents.TotalContent = total;
            }
            catch (Exception ex)
            {
                throw;
            }
            return(contents);
        }
示例#2
0
文件: LookUpLogic.cs 项目: HAMANZ/LMJ
        public List <LookUpAttributes> GetAttributes(AdminTables table, string langCode)
        {
            LookUpAttributes        main       = new LookUpAttributes();
            Language                lang       = new Language();
            List <LookUpAttributes> attributes = new List <LookUpAttributes>();

            try
            {
                string XMLPath = ConfigurationManager.AppSettings["XMLPath"]; // @"~\LookUp.xml";

                lang = _LanguageAccessor.Get(langCode);

                //Get class's attributes

                attributes = Tools.GetAttributes(table.ToString(), XMLPath);

                return(attributes);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
示例#3
0
文件: Tools.cs 项目: HAMANZ/LMJ
        static public List <LookUpAttributes> GetAttributes(string ClassName, string XMLPath)
        {
            List <LookUpAttributes> attributes = new List <LookUpAttributes>();
            LookUpAttributes        attr       = new LookUpAttributes();
            XmlDocument             doc        = new XmlDocument();


            try
            {
                doc.Load(XMLPath);
                XmlNode Lookups = doc.ChildNodes[1];

                foreach (XmlNode child in Lookups.ChildNodes)
                {
                    if (child.Attributes["Name"].Value == ClassName)
                    {
                        foreach (XmlNode node in child)
                        {
                            attr      = new LookUpAttributes();
                            attr.Name = node.Attributes["Name"].Value;
                            attr.Code = node.Attributes["Code"].Value;
                            if (node.Attributes["isLangNull"].Value == "False")
                            {
                                attr.isLangNull = false;
                            }
                            else
                            {
                                attr.isLangNull = true;
                            }

                            if (node.Attributes["isMedia"].Value == "False")
                            {
                                attr.isMedia = false;
                            }
                            else
                            {
                                attr.isMedia = true;
                            }

                            if (node.Attributes["isMain"].Value == "False")
                            {
                                attr.isMain = false;
                            }
                            else
                            {
                                attr.isMain = true;
                            }

                            if (node.Attributes["isList"].Value == "False")
                            {
                                attr.isList = false;
                            }
                            else
                            {
                                attr.isList = true;
                            }

                            if (node.Attributes["isVideo"].Value == "False")
                            {
                                attr.isVideo = false;
                            }
                            else
                            {
                                attr.isVideo = true;
                            }


                            attributes.Add(attr);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }
            return(attributes);
        }
示例#4
0
文件: LookUpLogic.cs 项目: HAMANZ/LMJ
        public List <T> ReturnListOf <T>(AdminTables table, long langId, int offset, int limit, List <LookUpAttributes> attributes, LookUpAttributes main, List <string> fields, bool isAll, out int total, long?lookUpId)
        {
            try
            {
                LookUpMultiLanguage lookupMulti = new LookUpMultiLanguage();
                LookUp        lookUp            = new LookUp();
                long          tableId;
                List <LookUp> allRowsThatHaveCodeOfMainChild      = new List <LookUp>();
                List <LookUp> selectedRowsThatHaveCodeOfMainChild = new List <LookUp>();
                List <LookUp> contents = new List <LookUp>();

                System.Type UsedClass  = __SharedClassesForeachTable[table];
                var         UsedObject = Activator.CreateInstance(UsedClass);

                List <string> images = new List <string>();

                dynamic dynamic = (dynamic)UsedObject;
                tableId = __SharedTableIds[table];
                List <dynamic> allDynamic = new List <dynamic>();


                var accessor = FastMember.TypeAccessor.Create(typeof(T));

                if (lookUpId == null)
                {
                    allRowsThatHaveCodeOfMainChild = GetRowsOfTableByCode(tableId, main.Code);

                    total = allRowsThatHaveCodeOfMainChild.Count();
                    selectedRowsThatHaveCodeOfMainChild = allRowsThatHaveCodeOfMainChild.OrderByDescending(s => s.Id).Skip(offset).Take(limit).ToList();
                }
                else
                {
                    selectedRowsThatHaveCodeOfMainChild.Add(_LookUpAccessor.Get((long)lookUpId));
                    total = 1;
                }

                foreach (LookUp row in selectedRowsThatHaveCodeOfMainChild)
                {
                    contents = new List <LookUp>();
                    contents = _LookUpAccessor.GetChildren(row.Id);
                    dynamic  = (dynamic)Activator.CreateInstance(UsedClass);
                    accessor[dynamic, "Id"] = row.Id;

                    // main
                    if (main.isLangNull)
                    {
                        lookupMulti = _LookUpMultiAccessor.Get(row.Id, null);
                    }
                    else
                    {
                        lookupMulti = _LookUpMultiAccessor.Get(row.Id, langId);
                    }
                    if (lookupMulti != null)
                    {
                        accessor[dynamic, main.Name] = lookupMulti.Description;
                    }

                    //TO DO set id

                    foreach (LookUpAttributes obj in attributes)
                    {
                        if (obj.Code == main.Code)
                        {
                            continue;
                        }
                        if (!isAll)
                        {
                            if (fields.Contains(obj.Name) == false)
                            {
                                continue;
                            }
                        }
                        lookUp = new LookUp();
                        lookUp = contents.Where(e => e.Code == obj.Code).FirstOrDefault();
                        if (lookUp == null)
                        {
                            continue;
                        }
                        if (obj.Name == "Date")
                        {
                            accessor[dynamic, obj.Name] = (row.SysDate).Value.Date; //new
                            continue;
                        }
                        if (obj.isMedia)
                        {
                            try
                            {
                                if (obj.isList)
                                {
                                    //get list
                                    images = new List <string>();
                                    images = _MediaAccessor.Get(lookUp.Id, obj.isVideo)
                                             .Select(e => e.Name).ToList();
                                    if (images.Count != 0)
                                    {
                                        accessor[dynamic, obj.Name] = images;
                                    }
                                }
                                else
                                {
                                    LookUpMedia media = new LookUpMedia();
                                    media = _MediaAccessor.Get(lookUp.Id, obj.isVideo).FirstOrDefault();
                                    if (media == null)
                                    {
                                        continue;
                                    }
                                    // get one image
                                    accessor[dynamic, obj.Name] = media.Name;
                                }
                            }
                            catch (Exception ex)
                            {
                                throw new Exception("exception in media id=" + lookUp.Id);
                            }
                        }
                        else
                        {
                            try
                            {
                                if (obj.isLangNull)
                                {
                                    lookupMulti = _LookUpMultiAccessor.Get(lookUp.Id, null);
                                }
                                else
                                {
                                    lookupMulti = _LookUpMultiAccessor.Get(lookUp.Id, langId);
                                }

                                accessor[dynamic, obj.Name] = lookupMulti.Description;
                            }
                            catch (Exception ex)
                            {
                                throw new Exception("exception in lookup multi id=" + lookUp.Id);
                            }
                        }
                    }
                    allDynamic.Add(dynamic);
                }

                List <T> list = new List <T>();
                foreach (dynamic d in allDynamic)
                {
                    list.Add((T)d);
                }


                return(list);
            }
            catch (Exception ex)
            {
                throw;
            }
        }