<%@ WebService Language="C#" Class="FlashWS" %>
using System;
using System.Web;
using System.Web.Services;
using System.Data;
using System.Data.SqlClient;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using NineSky.Common;
// Flash数据类
public class FlashData
{
public int ID;
public string Name;
public int Type;
public int ArtistID;
public string ArtistName;
public int TrackID;
public string TrackName;
public string Path;
public string FileName;
public int FileSize;
public string Author;
public string Intro;
public int PubTag;
public string ImgUrl;
}
// 歌手数据类
public class ArtistData
{
public string ID; //歌手ID
public string DocID; //档案ID
public string NName; //昵称
public string CName; //中文名
public string EName; //英文名(韩文\日文等)
public string Area; //地区(1=大陆,2=香港,3=台湾,4=东南亚,5=日本,6=韩国,7=欧美,8=合辑)
public string Sex; //性别(1=男,2=女,3=乐队,4=其他,5=合辑,6=原声,7=动漫游戏)
public string Nation; //国籍
public string Intro; //介绍
public string Picture; //歌手图片
public string AlbumNum; //专辑数
public string TrackNum; //歌曲数
public string Star; //星级
public string PY; //拼音
public string Hot; //热门
public string ImgUrl;
public string MusicTag;
public string KTTag;
public string PhotoTag;
public string FlashTag;
public string MTVTag;
public string CDCoverTag;
}
// 歌手数据集合类
public class ArtistList
{
public int TotalCount;
public Letter[] Letters;
public string Test;
}
public class Letter
{
public string Name;
public int ArtistCount;
public ArtistData[] Artists;
}
[WebService(Namespace="http://ws.9sky.org/flash/")]
public class FlashWS : WebService {
private string ConnectString = System.Configuration.ConfigurationSettings.AppSettings["Data06"];
private string ConnectStringMusic06 = System.Configuration.ConfigurationSettings.AppSettings["Music06"];
// 读取指定数据信息(album\artist\track\lyric\mv\cd\news\flash\photo)
private SqlDataReader Db_MusicInfo(int Id, string strIdType)
{
SqlParameter[] arrParam = new SqlParameter[2];
arrParam[0] = new SqlParameter("@Id", SqlDbType.Int);
arrParam[0].Value = Id;
arrParam[1] = new SqlParameter("@Type", SqlDbType.VarChar);
arrParam[1].Value = strIdType;
SqlDataReader dr = SqlHelper.ExecuteReader(ConnectString, CommandType.StoredProcedure, "xp2_music_Detail", arrParam);
return dr;
}
// 生成Flash数据
private FlashData Build_FlashData(SqlDataReader dr)
{
System.DBNull DBNull = System.DBNull.Value;
FlashData flash = new FlashData();
if(dr.HasRows)
{
flash.ID = Convert.ToInt32(dr["flash_id"]);
flash.Name = Convert.ToString(dr["flash_name"]);
flash.Type = Convert.ToInt32(dr["flash_type"]);
if(dr["flash_artid"] != DBNull)
flash.ArtistID = Convert.ToInt32(dr["flash_artid"]);
if(dr["flash_artname"] != DBNull)
flash.ArtistName = Convert.ToString(dr["flash_artname"]);
if(dr["flash_trkid"] != DBNull)
flash.TrackID = Convert.ToInt32(dr["flash_trkid"]);
if(dr["flash_trkname"] != DBNull)
flash.TrackName = Convert.ToString(dr["flash_trkname"]);
if(dr["flash_path"] != DBNull)
flash.Path = Convert.ToString(dr["flash_path"]);
if(dr["flash_filename"] != DBNull)
flash.FileName = Convert.ToString(dr["flash_filename"]);
if(dr["flash_filesize"] != DBNull)
flash.FileSize = Convert.ToInt32(dr["flash_filesize"]);
if(dr["flash_author"] != DBNull)
flash.Author = Convert.ToString(dr["flash_author"]);
if(dr["flash_intro"] != DBNull)
flash.Intro = Convert.ToString(dr["flash_intro"]);
if(dr["flash_pubtag"] != DBNull)
flash.PubTag = Convert.ToInt32(dr["flash_pubtag"]);
flash.ImgUrl = "http://img1.9sky.com/flash/120/" + dr["flash_filename"].ToString().Replace(".swf","-120") + ".jpg";
}
return flash;
}
[WebMethod(EnableSession=true,Description="获取指定Flash信息",CacheDuration=30)]
//****************************************************
// 获取指定Flash信息
//****************************************************
public FlashData ReadFlashInfo(int flaId)
{
SqlDataReader dr = Db_MusicInfo(flaId,"flash");
FlashData flash = new FlashData();
if(dr.HasRows)
{
dr.Read();
flash = Build_FlashData(dr);
}
dr.Close();
return flash;
}
// 读取歌手列表 strType="PY", "Sort", "Hot"
// intSite=11=本站-music,12=本站-KT,13=本站-EMI,14=本站-MTV,15=本站-Flash, 21=VNET-music,22=VNET-KT,23=VNET-emi,24=VNET-mtv,25=VNET-flash
private DataSet Db_Artist_List(string strType, string strPY, string strArea, string strSex, int intSite, int intTopN)
{
SqlParameter[] arrParam = new SqlParameter[6];
arrParam[0] = new SqlParameter("@Type", SqlDbType.NVarChar);
arrParam[0].Value = strType;
arrParam[1] = new SqlParameter("@PY", SqlDbType.NVarChar);
arrParam[1].Value = strPY;
arrParam[2] = new SqlParameter("@Area", SqlDbType.NVarChar);
arrParam[2].Value = strArea;
arrParam[3] = new SqlParameter("@Sex", SqlDbType.NVarChar);
arrParam[3].Value = strSex;
arrParam[4] = new SqlParameter("@Site", SqlDbType.Int);
arrParam[4].Value = intSite;
arrParam[5] = new SqlParameter("@TopN", SqlDbType.Int);
arrParam[5].Value = intTopN;
DataSet ds = SqlHelper.ExecuteDataset(ConnectStringMusic06, CommandType.StoredProcedure, "ws_artist_list", arrParam);
return ds;
}
// 读取首字母分页组集合
private DataSet Db_Artist_Paging(string strIdType, int intNPage, string strArea, string strSex)
{
string strSql = "";
string strWhere = "";
// strWhere = "and art_Sex IN ('" + strSex.Replace(",","','") +"') AND art_Area IN ('" + strArea.Replace(",","','") + "')";
if(strIdType == "track")
strSql = "select count(art_PY),art_PY from Artist where art_MusicTag=1 " + strWhere + " Group by art_PY order by art_PY asc";
else if(strIdType == "mv")
strSql = "select count(art_PY),art_PY from Artist where art_MTVTag=1 " + strWhere + " Group by art_PY order by art_PY asc";
else if(strIdType == "radio")
strSql = "select count(art_PY),art_PY from Artist where art_MusicTag=1 " + strWhere + " Group by art_PY order by art_PY asc";
else if(strIdType == "flash")
strSql = "select count(art_PY),art_PY from Artist where art_FlashTag=1 " + strWhere + " Group by art_PY order by art_PY asc";
SqlParameter[] arrParam = new SqlParameter[2];
arrParam[0] = new SqlParameter("@strSql", SqlDbType.NVarChar);
arrParam[0].Value = strSql;
arrParam[1] = new SqlParameter("@npage", SqlDbType.Int);
arrParam[1].Value = intNPage;
DataSet ds = SqlHelper.ExecuteDataset(ConnectString, CommandType.StoredProcedure, "xp2_artist_artPage", arrParam);
return ds;
}
//生成歌手Artist数据(数据结果返回级标识串 strOpendata 由5位和值组成, 值 = 1 有返回; 0 没有返回)
private ArtistData Build_ArtistData(DataRow dr, string strOpendata)
{
System.DBNull DBNull = System.DBNull.Value;
ArtistData artist = new ArtistData();
if(strOpendata.Substring(0,1) == "1")
{
artist.ID = Convert.ToString(dr["art_id"]);
artist.CName = Convert.ToString(dr["art_cname"]);
if(dr["art_py"] != DBNull)
artist.PY = Convert.ToString(dr["art_py"]);
}
if(strOpendata.Substring(1,1) == "1")
{
if(dr["art_area"] != DBNull)
artist.Area = Convert.ToString(dr["art_area"]);
if(dr["art_sex"] != DBNull)
artist.Sex = Convert.ToString(dr["art_sex"]);
}
if(strOpendata.Substring(2,1) == "1")
{
if(dr["art_ename"] != DBNull)
artist.EName = Convert.ToString(dr["art_ename"]);
}
if(strOpendata.Substring(3,1) == "1")
{
if(dr["art_nname"] != DBNull)
artist.NName = Convert.ToString(dr["art_nname"]);
if(Convert.ToString(dr["art_picture"]) == "1")
artist.ImgUrl = "http://img.9sky.com/artist/" + artist.ID.ToString() + ".jpg";
else
artist.ImgUrl = "http://img.9sky.com/artist/0.jpg";
if(dr["art_nation"] != DBNull)
artist.Nation = Convert.ToString(dr["art_nation"]);
if(dr["art_intro"] != DBNull)
artist.Intro = Convert.ToString(dr["art_intro"]);
if(dr["art_albnum"] != DBNull)
artist.AlbumNum = Convert.ToString(dr["art_albnum"]);
if(dr["art_trknum"] != DBNull)
artist.TrackNum = Convert.ToString(dr["art_trknum"]);
if(dr["art_star"] != DBNull)
artist.Star = Convert.ToString(dr["art_star"]);
if(dr["art_DocID"] != DBNull)
artist.DocID = Convert.ToString(dr["art_DocID"]);
}
if(strOpendata.Substring(4,1) == "1")
{
artist.MusicTag = Convert.ToString(dr["art_MusicTag"]);
artist.KTTag = Convert.ToString(dr["art_KTTag"]);
artist.PhotoTag = Convert.ToString(dr["art_PhotoTag"]);
artist.FlashTag = Convert.ToString(dr["art_FlashTag"]);
artist.MTVTag = Convert.ToString(dr["art_MTVTag"]);
artist.CDCoverTag = Convert.ToString(dr["art_CDCoverTag"]);
}
return artist;
}
//SqlDataReader转DataTable
private DataTable ConvertToTable(SqlDataReader dr)
{
DataTable oSchemaTable = dr.GetSchemaTable();
DataTable dt = new DataTable();
for(int i=0; i<oSchemaTable.Rows.Count; i++)
dt.Columns.Add(oSchemaTable.Rows[i]["ColumnName"].ToString(),(System.Type)oSchemaTable.Rows[i]["DataType"]);
DataRow oDataRow = dt.NewRow();
for(int i = 0; i <= oSchemaTable.Rows.Count - 1; i++)
oDataRow[i] = dr[oSchemaTable.Rows[i]["ColumnName"].ToString()];
dt.Rows.Add(oDataRow);
return dt;
}
[WebMethod(EnableSession=true,Description="获取指定歌手信息",CacheDuration=30)]
//****************************************************
// 获取指定歌手信息
//****************************************************
public ArtistData ReadArtistInfo(int artId)
{
SqlDataReader dr = Db_MusicInfo(artId, "artist");
ArtistData artist = new ArtistData();
System.DBNull DBNull = System.DBNull.Value;
if(dr.HasRows)
{
dr.Read();
DataTable dt = ConvertToTable(dr);
artist = Build_ArtistData(dt.Rows[0],"11100");
}
dr.Close();
return artist;
}
//转化为整型
private int ConvertToInt32(string bstr)
{
return ((IsNumeric(bstr)==true && bstr.Trim().Length>0) ? Convert.ToInt32(bstr) : 0);
}
//是否是数字
private bool IsNumeric(string bstr)
{
char[] charArray = bstr.ToCharArray();
foreach(char c in charArray)
{
if(!Char.IsNumber(c))
{
return false;
}
}
return true;
}
[WebMethod(EnableSession=true,CacheDuration=600)]
// 读取首字母分页指定类型歌手列表集合 strType="PY", "Sort", "Hot"
// 站点 intSite=11=本站-music,12=本站-KT,13=本站-EMI, 21=VNET-music,22=VNET-KT,23=VNET-emi
private ArtistList ReadArtistList(string strType, string strPY, int intSort, int intTopN, string strMethodName)
{
// strOpenData = GetAuthenticate(strMethodName);
string strArea = "";
string strSex = "";
GetArtType(intSort, out strArea, out strSex); //分类歌手
DataTable dt = Db_Artist_List(strType, strPY, strArea, strSex, 15, intTopN).Tables[0];
string strAllPY = "";
string preChar = "#";
string nowChar = "#";
string strArtistCount = "";
int count = 0;
//获取歌手拼音乐字母串
for(int i=0; i<dt.Rows.Count; i++)
{
ArtistData artist = Build_ArtistData(dt.Rows[i],"11100");
nowChar = artist.PY.ToUpper();
if(preChar != nowChar && !(IsNumeric(preChar)&&IsNumeric(nowChar)))
{
strAllPY = strAllPY + "," + (IsNumeric(nowChar)==true?"0":artist.PY.ToUpper()); //所有歌手拼音字线串
strArtistCount = strArtistCount + count.ToString() + ","; //每个字母有歌手数量串
count = 0;
}
preChar = nowChar;
count++;
}
ArtistList artistlist = new ArtistList();
artistlist.TotalCount = 0;
artistlist.Test = "strAllPY";
artistlist.Letters = new Letter[0] ;
if(dt.Rows.Count>0)
{
strAllPY = strAllPY.Substring(1,strAllPY.Length-1);
strArtistCount = strArtistCount + count.ToString();
strArtistCount = strArtistCount.Substring(2,strArtistCount.Length-2);
string[] PY = strAllPY.Split(',');
string[] ArtistCount = strArtistCount.Split(',');
artistlist.TotalCount = dt.Rows.Count;
artistlist.Letters = new Letter[PY.Length];
int TotalCount = 0;
for(int i=0; i<PY.Length; i++)
{
artistlist.Letters[i] = new Letter();
artistlist.Letters[i].Name = PY[i];
artistlist.Letters[i].ArtistCount = ConvertToInt32(ArtistCount[i]);
artistlist.Letters[i].Artists = new ArtistData[ConvertToInt32(ArtistCount[i])];
for(int j=0; j<ConvertToInt32(ArtistCount[i]); j++)
{
ArtistData artist = Build_ArtistData(dt.Rows[TotalCount],"11100");
artistlist.Letters[i].Artists[j] = artist;
TotalCount++;
}
}
}
dt.Dispose();
return artistlist;
}
[WebMethod(EnableSession=true,Description="读取有mtv的歌手分类类别的歌手记录集合",CacheDuration=600)]
public ArtistList ReadArtistListBySort(int intSort)
{
// strSiteID = SourceID;
return ReadArtistList("Sort", "", intSort, 100, "ArtistList");
}
private void GetArtType(int intSort, out string strArea, out string strSex)
{
strArea = "";
strSex = "";
switch(intSort)
{
case 1: //所有
strArea = "1,2,3,4,5,6,7,8";
strSex = "1,2,3,4,5,6,7";
break;
case 10: //华人音乐 - 所有
strArea = "1,2,3,4";
strSex = "1,2,3,5";
break;
case 11: //华人音乐 - 男
strArea = "1,2,3,4";
strSex = "1";
break;
case 12: //华人音乐 - 女
strArea = "1,2,3,4";
strSex = "2";
break;
case 13: //华人音乐 - 乐队组合
strArea = "1,2,3,4";
strSex = "3";
break;
case 14: //华人音乐 - 精选合辑
strArea = "1,2,3,4";
strSex = "5";
break;
case 20: //欧美音乐 - 所有
strSex = "1,2,3,5";
strArea = "7";
break;
case 21: //欧美音乐 - 男
strArea = "7";
strSex = "1";
break;
case 22: //欧美音乐 - 女
strArea = "7";
strSex = "2";
break;
case 23: //欧美音乐 - 乐队组合
strArea = "7";
strSex = "3";
break;
case 24: //欧美音乐 - 精选合辑
strArea = "7";
strSex = "5";
break;
case 30: //韩日音乐 - 所有
strArea = "5,6";
strSex = "1,2,3,5";
break;
case 31: //韩日音乐 - 男
strArea = "5,6";
strSex = "1";
break;
case 32: //韩日音乐 - 女
strArea = "5,6";
strSex = "2";
break;
case 33: //韩日音乐 - 乐队组合
strArea = "5,6";
strSex = "3";
break;
case 34: //韩日音乐 - 精选合辑
strArea = "5,6";
strSex = "5";
break;
case 50: //别类珍藏 //另类合辑
strArea = "1,2,3,4,5,6,7,8";
strSex = "4,5";
break;
case 60: //影视原声
strArea = "1,2,3,4,5,6,7,8";
strSex = "6";
break;
case 70: //游戏动漫
strArea = "1,2,3,4,5,6,7,8";
strSex = "7";
break;
default: //华人音乐 - 所有
strArea = "1,2,3,4";
strSex = "1,2,3,5";
break;
}
}
}
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/huchenhui1981/archive/2006/11/24/1412284.aspx