Exemplo n.º 1
0
        List <ShowCategoryModel> Query(string where, string count)
        {
            int  intCount = 5, myCount = 0;
            bool isRight = false;

            if (int.TryParse(count, out intCount) && intCount > 0)
            {
                isRight = true;
            }

            List <ShowCategoryModel> dic = new List <ShowCategoryModel>();

            string sqlField1 = " SELECT DISTINCT [" + ChannelName + "],[" + ChannelID + "],[" + FullUrl + "],[" + TitleImage + "] FROM [" + dataSourceName + "]  ";

            if (!string.IsNullOrEmpty(where))
            {
                sqlField1 += " where " + where;
            }
            IDatabase    db           = Assistant.GetDatabases()["We7.CMS.Common"];
            SqlStatement sqlstatement = new SqlStatement();

            sqlstatement.SqlClause = sqlField1;
            db.DbDriver.FormatSQL(sqlstatement);
            DataTable dt = new DataTable();

            using (IConnection conn = db.CreateConnection())
            {
                dt = conn.Query(sqlstatement);
            }
            foreach (DataRow row in dt.Rows)
            {
                if (isRight)
                {
                    myCount++;
                    if (myCount >= intCount)
                    {
                        break;
                    }
                }
                string            name    = row[ChannelName].ToString();
                string            value   = row[ChannelID].ToString();
                string            picUrl  = row[TitleImage].ToString();
                string            linkUrl = row[FullUrl].ToString();
                ShowCategoryModel model   = new ShowCategoryModel();
                if (!String.IsNullOrEmpty(name) && !String.IsNullOrEmpty(value))
                {
                    model.Name    = name;
                    model.Value   = value;
                    model.PicUrl  = picUrl;
                    model.LinkUrl = linkUrl;
                    dic.Add(model);
                }
            }
            return(dic);
        }
Exemplo n.º 2
0
        List <ShowCategoryModel> Query(string xpath, string count)
        {
            int  intCount = 5, myCount = 0;
            bool isRight = false;

            if (int.TryParse(count, out intCount) && intCount > 0)
            {
                isRight = true;
            }
            List <ShowCategoryModel> dic = new  List <ShowCategoryModel>();
            XmlNodeList nodes            = XmlHelper.GetXmlNodeList(dataSourceName, xpath);

            foreach (XmlElement xe in nodes)
            {
                if (isRight)
                {
                    myCount++;
                    if (myCount >= intCount)
                    {
                        break;
                    }
                }
                string name    = xe.GetAttribute(ChannelName);
                string value   = xe.GetAttribute(ChannelID);
                string picUrl  = xe.GetAttribute(TitleImage);
                string linkUrl = xe.GetAttribute(FullUrl);
                List <ShowCategoryModel> lsChild = new List <ShowCategoryModel>();
                ShowCategoryModel        model   = new ShowCategoryModel();
                if (!String.IsNullOrEmpty(name) && !String.IsNullOrEmpty(value))
                {
                    model.Name    = name;
                    model.Value   = value;
                    model.PicUrl  = picUrl;
                    model.LinkUrl = linkUrl;
                    dic.Add(model);
                }
            }
            return(dic);
        }