主界面代码
 using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient; namespace 私属音乐点播
{
public partial class frmMain : Form
{
public frmMain()
{
InitializeComponent();
}
DBHelper db = new DBHelper();
/// <summary>
/// lv的目标界面定义,0歌曲,1歌手,2国家,3性别,
/// 亮点
/// </summary>
int num = ; //lv的目标界面定义,0歌曲,1歌手,2国家,3性别,4字数
//单击歌星点歌按钮事件
private void tsbtnTool_singer_Click(object sender, EventArgs e)
{
//目标项在表中的个数
string strCounts=@"select COUNT(1) from singer_info";
//查询歌手Id和歌手名字,私有dr方法
string str = @"select singer_id,singer_name from singer_info";
//获取歌手方法
GetSinger(strCounts, str);
}
//双击lv_Login组件事件
string gender = "男";
private void lv_Login_DoubleClick(object sender, EventArgs e)
{ //亮点
switch (num)
{
//歌曲双击事件
case :
int result = Convert.ToInt32(lv_Login.SelectedItems[].Tag);
DoubleClickSong(result);
break;
//歌手双击事件
case :
int singerId = Convert.ToInt32(lv_Login.SelectedItems[].Tag);
string str = @"select song_id,song_name,singer_name,song_play_count from song_info,singer_info where song_info.singer_id=" + singerId + " and song_info.singer_id = singer_info.singer_id";
num = ;
SingerToSongs(str);
break;
//国家双击事件
case :
int type_id = Convert.ToInt32(lv_Login.SelectedItems[].Tag);
string strCount = @"select count(1) from singer_info where singer_sex='" + gender + "' and singertype_id=" + type_id + "";
string strInfo=@"select singer_id,singer_name from singer_info where singer_sex='" + gender + "' and singertype_id=" + type_id + "";
//下一个lv_Login为歌曲,num=1
num = ;
GetSinger(strCount,strInfo);
break;
//性别双击事件
case :
gender = lv_Login.SelectedItems[].Text;
//下一个为歌手地区,num值为2
num = ;
//搞出国家lv方法
GetSingerType();
break;
//字数点歌
case :
num = ;
string playCount;
if (Convert.ToInt32(lv_Login.SelectedItems[].Tag)!=)
{
playCount = @"select song_id,song_name,singer_name,song_play_count from song_info,singer_info where song_word_count = " + lv_Login.SelectedItems[].Tag + " and song_info.singer_id = singer_info.singer_id";
}
else
{
playCount = @"select song_id,song_name,singer_name,song_play_count from song_info,singer_info where song_word_count > 10 and song_info.singer_id = singer_info.singer_id";
}
SingerToSongs(playCount);
break;
//其他非合法组件双击事件,直接跳出
default:
//不用思索,直接跳出
return;
}
}
//类型点歌按钮事件
private void tsbtnTool_type_Click(object sender, EventArgs e)
{
//打开性别lv
//目标lv为性别,所以num为3
num = ;
imglist.Images.Clear();
lv_Login.Clear();
lv_Login.Controls.Clear();
lv_Login.View = View.LargeIcon;
try
{
imglist.ImageSize = new Size(, );
imglist.Images.Add(Image.FromFile(@"D:\课程\S1\KTV\MyKTV\image\male.png"));
imglist.Images.Add(Image.FromFile(@"D:\课程\S1\KTV\MyKTV\image\female.png"));
imglist.Images.Add(Image.FromFile(@"D:\课程\S1\KTV\MyKTV\image\couple.png"));
}
catch (Exception)
{
imglist.ImageSize = new Size(, );
ListViewItem male1 = new ListViewItem("男");
ListViewItem female1 = new ListViewItem("女");
ListViewItem couple1 = new ListViewItem("组合");
lv_Login.Items.Add(male1);
lv_Login.Items.Add(female1);
lv_Login.Items.Add(couple1);
return;
}
lv_Login.LargeImageList = imglist;
ListViewItem male = new ListViewItem("男", );
ListViewItem female = new ListViewItem("女", );
ListViewItem couple = new ListViewItem("组合", );
lv_Login.Items.Add(male);
lv_Login.Items.Add(female);
lv_Login.Items.Add(couple);
}
#region 拼音点歌事件
private void tsbtnTool_pinyin_Click(object sender, EventArgs e)
{
lv_Login.Clear();
lv_Login.Controls.Add(txt);
lv_Login.Controls.Add(lbl);
txt.Location = new Point(, );
txt.Size = new System.Drawing.Size(new Point(, ));
txt.Focus();
lbl.Text = "(请输入要查找的歌曲拼音或缩写)";
lbl.Font = new Font("幼圆", );
lbl.ForeColor = Color.Blue;
lbl.Location = new Point(, );
lbl.Size = new Size(new Point(, ));
txt.TextChanged += txt_TextChanged;
lvNew.Location = new Point(-, );
lvNew.Size = new Size(, );
lvNew.FullRowSelect = true;
lvNew.View = View.Details;
lvNew.Columns.Clear();
lvNew.Columns.Add("歌曲名称", );
lvNew.Columns.Add("歌手", );
lvNew.Columns.Add("点播次数", );
lvNew.DoubleClick += lvNew_DoubleClick;
lv_Login.Controls.Add(lvNew);
}
//添加三个个控件
TextBox txt = new TextBox();
Label lbl = new Label();
ListView lvNew = new ListView();
//lv_Login的新添项lvNew的Items双击事件
private void lvNew_DoubleClick(object sender, EventArgs e)
{
//在这里引用歌曲双击事件
int result = Convert.ToInt32(lvNew.SelectedItems[].Tag);
//MessageBox.Show(result.ToString());
DoubleClickSong(result);
}
//new出的txt的text值改变时事件
private void txt_TextChanged(object sender, EventArgs e)
{
lvNew.Items.Clear();
string result="";
if (!txt.Text.Trim().Equals(string.Empty))
{
foreach (char item in txt.Text)
{
if (item>='a'&&item<='z')
{
result += item;
result += '%';
}else if (item>='A'&&item<='Z')
{
result += item.ToString().ToLower();
result += '%';
}
}
}
string str;
if (!result.Equals(string.Empty))
{
str = @"select song_id,song_name,singer_name,song_play_count from song_info,singer_info where song_ab like '%" + result + "%' and song_info.singer_id = singer_info.singer_id";
}
else
{
return;
}
try
{
SqlDataReader dr = db.Dr(str);
if (dr.HasRows)
{
while (dr.Read())
{
ListViewItem item = new ListViewItem(dr["song_name"].ToString());
item.Tag = dr["song_id"].ToString();
item.SubItems.Add(dr["singer_name"].ToString());
item.SubItems.Add(dr["song_play_count"].ToString());
lvNew.Items.Add(item);
}
dr.Close();
}
}
catch (Exception)
{
MessageBox.Show("私有连接异常!");
}
finally
{
db.CloseConnection();
}
}
#endregion
//金榜排行按钮点击事件
private void tsbtnTool_order_Click(object sender, EventArgs e)
{
imglist.Images.Clear();
lv_Login.SmallImageList = imglist;
string str = @"select top 10 song_id,song_name,singer_name,song_play_count from song_info,singer_info where song_info.singer_id=singer_info.singer_id order by song_play_count desc";
num = ;
SingerToSongs(str);
lv_Login.View = View.List;
imglist.ImageSize = new Size(, );
try
{
for (int i = ; i < ; i++)
{
imglist.Images.Add(Image.FromFile(@"D:\课程\S1\KTV\MyKTV\image\" + i + ".png"));
lv_Login.Items[i].ImageIndex = i;
}
}
catch (Exception)
{ }
}
//单击字数点歌按钮事件
private void tsbtnTool_counts_Click(object sender, EventArgs e)
{
//目标lv_Login为字数lv, num为4
num = ;
lv_Login.Clear();
lv_Login.Controls.Clear();
imglist.Images.Clear();
lv_Login.LargeImageList = imglist;
imglist.ImageSize = new System.Drawing.Size(, );
lv_Login.View = View.LargeIcon;
for (int i = ; i < ; i++)
{
imglist.Images.Add(Image.FromFile(@"D:\课程\S1\KTV\MyKTV\image\" + i + ".png"));
ListViewItem item = new ListViewItem((i) + "个字",i-);
item.Tag = i+;
lv_Login.Items.Add(item);
}
imglist.Images.Add(Image.FromFile(@"D:\课程\S1\KTV\MyKTV\image\N.png"));
ListViewItem itemN = new ListViewItem("N个字", );
itemN.Tag = ;
lv_Login.Items.Add(itemN);
}
//定时器事件
private void timer_Tick(object sender, EventArgs e)
{
Playing();
}
/// <summary>
/// 歌手双击方法
/// </summary>
/// <param name="str">查询歌曲语句</param>
public void SingerToSongs(string str)
{
num = ;
lv_Login.View = View.Details;
lv_Login.Clear();
lv_Login.Controls.Clear();
lv_Login.Columns.Add("歌曲名称", );
lv_Login.Columns.Add("歌手", );
lv_Login.Columns.Add("点播次数", );
try
{
SqlDataReader dr = db.Dr(str);
if (dr.HasRows)
{
while (dr.Read())
{
ListViewItem item = new ListViewItem(dr["song_name"].ToString());
item.Tag = dr["song_id"].ToString();
item.SubItems.Add(dr["singer_name"].ToString());
item.SubItems.Add(dr["song_play_count"].ToString());
lv_Login.Items.Add(item);
}
dr.Close();
}
}
catch (Exception)
{
MessageBox.Show("私有连接异常!");
}
finally
{
db.CloseConnection();
}
}
/// <summary>
/// 播放列表专属数组
/// </summary>
Song[] playing_list = new Song[];
/// <summary>
/// 歌曲双击方法
/// </summary>
/// <param name="result">双击歌曲项的Tag值</param>
public void DoubleClickSong(int result)
{
//循环判定
foreach (Song song in playing_list)
{
if (song!=null && song.SongId == result.ToString())
{
MessageBox.Show("已点!");
return;
}
else if (song==null)
{
break;
}
}
int i = ;
foreach (Song one in playing_list)
{
if (one != null)
i++;
}
string str = @"select song_name from song_info where song_id = " + result + "";
try
{
SqlDataReader dr = db.Dr(str);
if (dr.HasRows)
{
if (dr.Read())
{
playing_list[i] = new Song();
playing_list[i].SongName = dr["song_name"].ToString();
playing_list[i].SongId = result.ToString();
}
}
dr.Close();
}
catch (Exception)
{
MessageBox.Show("私有连接异常!");
}
finally
{
db.CloseConnection();
if (playing_list[i]!=null)
{
playing_list[i].Songurl = GetSongurlById(result.ToString());
}
}
ListViewItem item = new ListViewItem(playing_list[i].SongName);
///注意
///注意
if (i == )
{
item.SubItems.Add("正在播放");
wmp.URL = playing_list[i].Songurl;
try
{
SetPlayCount(playing_list[i].SongId);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
else
{
item.SubItems.Add("未播放");
try
{
SetPlayCount(playing_list[i].SongId);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
item.SubItems.Add(playing_list[i].SongId);
item.Tag = playing_list[i].Songurl;
lvPlay_list.Items.Add(item);
timer.Enabled = true;
}
/// 当前播放的歌曲在对象数组中的下标
/// </summary>
int playingIndex = ;
/// <summary>
/// 播放方法
/// </summary>
public void Playing()
{
//重新写
if (wmp.playState==WMPLib.WMPPlayState.wmppsPlaying)
{
try
{
//面板信息更改
lblPlaying_name.Text = playing_list[playingIndex].SongName;
lblNext_name.Text = playing_list[playingIndex+].SongName;
}
catch (Exception)
{
lblNext_name.Text = "无";
}
}
else if (wmp.playState == WMPLib.WMPPlayState.wmppsStopped)
{
try
{
//状态更新
lvPlay_list.Items[playingIndex].SubItems[].Text = "已播放";
}
catch (Exception)
{
return;
}
playingIndex++;
//为播放列表的最后一个时,返回index,跳出方法
if (playing_list[playingIndex] == null)
{
playingIndex--;
wmp.URL = string.Empty;
return;
}
wmp.URL = playing_list[playingIndex].Songurl;
lvPlay_list.Items[playingIndex].SubItems[].Text = "正在播放";
//面板提示信息更新
lblPlaying_name.Text = playing_list[playingIndex].SongName;
try
{
lblNext_name.Text = playing_list[playingIndex + ].SongName;
}
catch (Exception)
{
lblNext_name.Text = "无";
}
}
//歌曲读取异常(为空,或,路径异常)
else if (wmp.playState==WMPLib.WMPPlayState.wmppsReady)
{
if (wmp.URL==string.Empty)
{
//只要路径为空,只需要判定播放列表是否为空,否则直接播放
if (playing_list[playingIndex] == null)
{
return;
}
wmp.URL = playing_list[playingIndex].Songurl;
try
{
lvPlay_list.Items[playingIndex].SubItems[].Text = "正在播放";
}
catch (Exception)
{
return;
}
//面板提示信息更新
lblPlaying_name.Text = playing_list[playingIndex].SongName;
try
{
lblNext_name.Text = playing_list[playingIndex +].SongName;
}
catch (Exception)
{
lblNext_name.Text = "无";
}
}
else
{
lvPlay_list.Items[playingIndex].SubItems[].Text = "路径异常";
playingIndex++;
//为播放列表的最后一个时,返回index,跳出方法
if (playing_list[playingIndex] == null)
{
wmp.URL = string.Empty;
return;
}
wmp.URL = playing_list[playingIndex].Songurl;
try
{
lvPlay_list.Items[playingIndex].SubItems[].Text = "正在播放";
}
catch (Exception)
{
return;
} //面板提示信息更新
lblPlaying_name.Text = playing_list[playingIndex].SongName;
try
{
lblNext_name.Text = playing_list[playingIndex + ].SongName;
}
catch (Exception)
{
lblNext_name.Text = "无";
}
}
}
else
{
return;
}
}
/// <summary>
/// 根据歌手id查找歌手图片路径
/// </summary>
/// <param name="id">singerId</param>
/// <returns>singerPhotoUrl</returns>
public string GetSingerurlById(string id)
{
string str2 = @"select resource_path from resource where resource_type='歌手图片地址'";
string singerphoto_url = db.ScalForString(str2);
string str = @"select singer_photo_url from singer_info where singer_id='" + id + "'";
string singer_url = db.ScalForString(str);
string sb = singerphoto_url + singer_url;
return sb;
}
/// <summary>
/// 根据歌曲id查找歌曲路径
/// </summary>
/// <param name="id">songId</param>
/// <returns>songUrl</returns>
public string GetSongurlById(string id)
{
string str = @"select resource_path from resource where resource_type = '歌曲地址'";
StringBuilder sb = new StringBuilder(db.ScalForString(str));
string str2 = @"select song_url from song_info where song_id = " + id + "";
sb.Append(db.ScalForString(str2));
return sb.ToString();
}
/// <summary>
/// 播放次数更新方法
/// </summary>
/// <param name="songId">歌曲Id的字符串格式</param>
/// <returns>是否成功</returns>
public bool SetPlayCount(string songId)
{
int result;
string str1 = @"select song_play_count from song_info where song_id=" + songId + "";
try
{
result = Convert.ToInt32(db.Scal(str1));
}
catch (Exception)
{
result = ;
}
result++;
string str = @"update song_info set song_play_count = " + result + " where song_id=" + songId + "";
if (db.Non(str)>)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// new国家lv_Login方法
/// </summary>
private void GetSingerType()
{
lv_Login.Clear();
lv_Login.Controls.Clear();
imglist.Images.Clear();
lv_Login.View = View.LargeIcon;
lv_Login.LargeImageList = imglist;
string str1 = @"select count(1) from singer_type";
int result;
try
{
result = Convert.ToInt32(db.Scal(str1));
}
catch (Exception)
{
return;
}
string str = @"select singertype_id, singertype_name from singer_type";
try
{
SqlDataReader dr = db.Dr(str);
if (dr.HasRows)
{
for (int i = ; i < result; i++)
{
dr.Read();
Image img;
try
{
img = Image.FromFile(@"D:\课程\S1\KTV\MyKTV\image" + Convert.ToString(dr["singertype_name"]) + ".png");
}
catch (Exception)
{
img = Image.FromFile("D:\\课程\\S1\\KTV\\MyKTV\\image\\singer_temp.jpg");
}
imglist.Images.Add(img);
ListViewItem item = new ListViewItem(dr["singertype_name"].ToString(),i);
item.Tag = Convert.ToString(dr["singertype_id"]);
lv_Login.Items.Add(item);
}
}
dr.Close();
}
catch (Exception)
{
MessageBox.Show("歌手地区读取异常!");
}
finally
{
db.CloseConnection();
}
}
/// <summary>
/// 获取歌手信息
/// </summary>
/// <param name="strCounts">条件下歌手个数查询语句</param>
/// <param name="str">条件下歌手信息查询语句</param>
private void GetSinger(string strCounts, string str)
{
//歌手lv的目标lv为歌曲
num = ;
imglist.Images.Clear();
lv_Login.Clear();
lv_Login.Controls.Clear();
lv_Login.View = View.LargeIcon;
//确定大图标的图像列表对象
lv_Login.LargeImageList = imglist;
imglist.ImageSize = new System.Drawing.Size(, );
int result = db.ScalForInt(strCounts);
SqlCommand comm = new SqlCommand(str, db.conn);
//new出对象数组,用于存储目标表格信息
Song[] song = new Song[result];
try
{
db.OpenConnection();
SqlDataReader dr = comm.ExecuteReader();
if (dr != null)
if (dr.HasRows)
{
for (int i = ; i < result; i++)
{
if (dr.Read())
{
//读取了歌手id,歌手名称
song[i] = new Song();
song[i].SingerId = dr["singer_id"].ToString();
song[i].SingerName = dr["singer_name"].ToString();
}
}
dr.Close();
}
}
catch (Exception)
{
MessageBox.Show("私有连接异常!");
}
finally
{
db.CloseConnection();
} //改变imagelist的图片大小:imglist.ImageSize = new Size(32, 32); //循环读出图片url,加载对应图片到imglist,给items组合项添加对象数组中每一项
for (int i = ; i < result; i++)
{
song[i].SingerPhoto = GetSingerurlById(song[i].SingerId);
Image img;
//亮点
try
{
img = Image.FromFile(song[i].SingerPhoto);
}
catch (Exception)
{
img = Image.FromFile("D:\\课程\\S1\\KTV\\MyKTV\\image\\singer_temp.jpg");
}
imglist.Images.Add(img);
ListViewItem item = new ListViewItem(song[i].SingerName, i);
item.Tag = song[i].SingerId;
lv_Login.Items.Add(item);
}
}
#region 删除播放列表歌曲,双击播放
////删除选中歌曲按钮事件
private void btnDel_Click(object sender, EventArgs e)
{
int result;
try
{
result = Convert.ToInt32(lvPlay_list.SelectedItems[].Index);
}
catch (Exception)
{
return;
}
//清空对象数组与列表
lvPlay_list.SelectedItems[].Remove();
///亮点
if (result == playingIndex)
{ try
{
if (playing_list[result + ] != null)
{
for (int i = result + ; i < playing_list.Length; i++)
{
playing_list[i - ].SongId = playing_list[i].SongId;
playing_list[i - ].SongName = playing_list[i].SongName;
playing_list[i - ].Songurl = playing_list[i].Songurl;
}
wmp.URL = playing_list[result].Songurl;
}
else
{
playing_list[result] = playing_list[result + ];
wmp.URL = string.Empty;
}
}
catch (Exception)
{
wmp.URL = string.Empty;
}
} }
////双击播放列表组件时
private void lvPlay_list_DoubleClick(object sender, EventArgs e)
{
try
{
wmp.URL = playing_list[Convert.ToInt32(lvPlay_list.SelectedItems[].Index)].Songurl;
lvPlay_list.Items[playingIndex].SubItems[].Text = "已播放";
playingIndex = Convert.ToInt32(lvPlay_list.SelectedItems[].Index);
lvPlay_list.Items[playingIndex].SubItems[].Text = "正在播放";
}
catch (Exception)
{
return;
}
}
////列表循环方式按钮点击事件
private void btnState_Click(object sender, EventArgs e)
{
// Timer timeResult = new Timer();
// if (btnState.Text=="列表循环模式")
// {
// btnState.Text = "单曲循环模式";
// timer.Enabled = false;
// timeResult.Enabled = true;
// timeResult.Interval = 1000;
// timeResult.Tick += timeResult_Tick;
// }
// else if (btnState.Text=="单曲循环模式")
// {
// btnState.Text = "无循环模式";
// timer.Enabled = true;
// timeResult.Enabled = false;
// }
// else if (btnState.Text=="无循环模式")
// {
// btnState.Text = "列表循环模式";
// timer.Enabled = false;
// timeResult.Enabled = true;
// timeResult.Interval = 1000;
// timeResult.Tick += timeResult_Tick;
// }
}
////附加定时器事件
void timeResult_Tick(object sender, EventArgs e)
{ // if (wmp.playState==WMPLib.WMPPlayState.wmppsStopped&&btnState.Text=="单曲循环模式")
// {
// wmp.URL = playing_list[playingIndex].Songurl;
// }
// else if (btnState.Text=="列表循环模式")
// {
// int result=-1;
// foreach (Song item in playing_list)
// {
// if (item!=null)
// {
// result++;
// }
// else
// {
// break;
// }
// }
// if (playingIndex==result)
// {
// playingIndex = 0;
// }
// }
}
#endregion }
}
数据库连接辅助代码
 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Data; namespace 私属音乐点播
{
class DBHelper
{
public static string sql = @"Data source=.;initial catalog=KTV;uid=sa;pwd=liuzs";
public SqlConnection conn = new SqlConnection(sql);
//打开数据库连接
public void OpenConnection()
{
if (conn.State == ConnectionState.Closed)
{
conn.Open(); }
else if (conn.State == ConnectionState.Broken)
{
conn.Close();
conn.Open();
}
}
//关闭数据库连接
public void CloseConnection()
{
if (conn.State == ConnectionState.Open || conn.State == ConnectionState.Broken)
{
conn.Close();
}
}
//返回受影响行号方法
public int Non(string str)
{
SqlCommand comm = new SqlCommand(str,conn);
int result = ;
try
{
OpenConnection();
result = Convert.ToInt32(comm.ExecuteNonQuery());
}
catch (Exception)
{
System.Windows.Forms.MessageBox.Show("获取表行号网络异常!");
}
finally
{
CloseConnection();
}
return result;
}
//返回查询首行首列为Int值方法
public int ScalForInt(string str)
{
SqlCommand comm = new SqlCommand(str,conn);
int result = ;
try
{
OpenConnection();
result = Convert.ToInt32(comm.ExecuteScalar());
}
catch (Exception)
{
System.Windows.Forms.MessageBox.Show("获取整型查询值网络异常!");
}
finally
{
CloseConnection();
}
return result;
}
//返回查询首行首列为String值方法
public string ScalForString(string str)
{
SqlCommand comm = new SqlCommand(str,conn);
string result = "";
try
{
OpenConnection();
result = Convert.ToString(comm.ExecuteScalar());
}
catch (Exception)
{
System.Windows.Forms.MessageBox.Show("获取字符串查询值网络异常!");
}
finally
{
CloseConnection();
}
return result;
}
//返回查询首行首列值方法
public object Scal(string str)
{
SqlCommand comm = new SqlCommand(str,conn);
object result = null;
try
{
OpenConnection();
result = comm.ExecuteScalar();
}
catch (Exception)
{
System.Windows.Forms.MessageBox.Show("获取查询值网络异常!");
}
finally
{
CloseConnection();
}
return result;
}
/// <summary>
/// 返回DataReader方法
/// 需要手动关闭读取器,关闭连接
/// 不可与其他数据库查询方法连用,da除外
/// </summary>
/// <param name="str">查询语句</param>
/// <returns>dr对象</returns>
public SqlDataReader Dr(string str)
{
SqlCommand comm = new SqlCommand(str,conn);
SqlDataReader dr = null;
try
{
OpenConnection();
dr = comm.ExecuteReader();
}
catch (Exception)
{
System.Windows.Forms.MessageBox.Show("获取查询值集合网络异常!");
}
return dr;
}
//返回DataAdapter方法
public SqlDataAdapter Da(string str)
{
SqlDataAdapter da = null;
try
{
da = new SqlDataAdapter(str, conn);
}
catch (Exception)
{
System.Windows.Forms.MessageBox.Show("获取表单网络异常!");
}
finally
{
CloseConnection();
}
return da;
} }
}

写这些代码也是我在S1的总结,虽然不是半年来学习的全部,但也是大部分了.

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;using System.Data.SqlClient;
namespace 私属音乐点播{    public partial class frmMain : Form    {        public frmMain()        {            InitializeComponent();        }        DBHelper db = new DBHelper();        /// <summary>        /// lv的目标界面定义,0歌曲,1歌手,2国家,3性别,        /// 亮点        /// </summary>        int num = 0;    //lv的目标界面定义,0歌曲,1歌手,2国家,3性别,4字数        //单击歌星点歌按钮事件        private void tsbtnTool_singer_Click(object sender, EventArgs e)        {            //目标项在表中的个数            string strCounts=@"select COUNT(1) from singer_info";            //查询歌手Id和歌手名字,私有dr方法            string str = @"select singer_id,singer_name from singer_info";            //获取歌手方法            GetSinger(strCounts, str);        }        //双击lv_Login组件事件        string gender = "男";        private void lv_Login_DoubleClick(object sender, EventArgs e)        {                        //亮点            switch (num)            {                //歌曲双击事件                case 0:                    int result = Convert.ToInt32(lv_Login.SelectedItems[0].Tag);                    DoubleClickSong(result);                    break;                //歌手双击事件                case 1:                    int singerId = Convert.ToInt32(lv_Login.SelectedItems[0].Tag);                    string str = @"select song_id,song_name,singer_name,song_play_count from song_info,singer_info where song_info.singer_id=" + singerId + " and song_info.singer_id = singer_info.singer_id";                    num = 0;                    SingerToSongs(str);                    break;                //国家双击事件                case 2:                    int type_id = Convert.ToInt32(lv_Login.SelectedItems[0].Tag);                    string strCount = @"select count(1) from singer_info where singer_sex='" + gender + "' and singertype_id=" + type_id + "";                    string strInfo=@"select singer_id,singer_name from singer_info where singer_sex='" + gender + "' and singertype_id=" + type_id + "";                    //下一个lv_Login为歌曲,num=1                    num = 1;                    GetSinger(strCount,strInfo);                    break;                //性别双击事件                case 3:                    gender = lv_Login.SelectedItems[0].Text;                    //下一个为歌手地区,num值为2                    num = 2;                    //搞出国家lv方法                    GetSingerType();                    break;                //字数点歌                case 4:                    num = 0;                    string playCount;                    if (Convert.ToInt32(lv_Login.SelectedItems[0].Tag)!=11)                    {                        playCount = @"select song_id,song_name,singer_name,song_play_count from song_info,singer_info where song_word_count = " + lv_Login.SelectedItems[0].Tag + " and song_info.singer_id = singer_info.singer_id";                    }                    else                    {                        playCount = @"select song_id,song_name,singer_name,song_play_count from song_info,singer_info where song_word_count > 10 and song_info.singer_id = singer_info.singer_id";                    }                    SingerToSongs(playCount);                    break;                //其他非合法组件双击事件,直接跳出                default:                    //不用思索,直接跳出                    return;            }        }        //类型点歌按钮事件        private void tsbtnTool_type_Click(object sender, EventArgs e)        {            //打开性别lv            //目标lv为性别,所以num为3            num = 3;            imglist.Images.Clear();            lv_Login.Clear();            lv_Login.Controls.Clear();            lv_Login.View = View.LargeIcon;            try            {                imglist.ImageSize = new Size(166, 168);                imglist.Images.Add(Image.FromFile(@"D:\课程\S1\KTV\MyKTV\image\male.png"));                imglist.Images.Add(Image.FromFile(@"D:\课程\S1\KTV\MyKTV\image\female.png"));                imglist.Images.Add(Image.FromFile(@"D:\课程\S1\KTV\MyKTV\image\couple.png"));            }            catch (Exception)            {                imglist.ImageSize = new Size(100, 100);                ListViewItem male1 = new ListViewItem("男");                ListViewItem female1 = new ListViewItem("女");                ListViewItem couple1 = new ListViewItem("组合");                lv_Login.Items.Add(male1);                lv_Login.Items.Add(female1);                lv_Login.Items.Add(couple1);                return;            }            lv_Login.LargeImageList = imglist;            ListViewItem male = new ListViewItem("男", 0);            ListViewItem female = new ListViewItem("女", 1);            ListViewItem couple = new ListViewItem("组合", 2);            lv_Login.Items.Add(male);            lv_Login.Items.Add(female);            lv_Login.Items.Add(couple);        }        #region 拼音点歌事件        private void tsbtnTool_pinyin_Click(object sender, EventArgs e)        {            lv_Login.Clear();            lv_Login.Controls.Add(txt);            lv_Login.Controls.Add(lbl);            txt.Location = new Point(200, 10);            txt.Size = new System.Drawing.Size(new Point(150, 18));            txt.Focus();            lbl.Text = "(请输入要查找的歌曲拼音或缩写)";            lbl.Font = new Font("幼圆", 10);            lbl.ForeColor = Color.Blue;            lbl.Location = new Point(350, 10);            lbl.Size = new Size(new Point(250, 18));            txt.TextChanged += txt_TextChanged;            lvNew.Location = new Point(-1, 40);            lvNew.Size = new Size(680, 580);            lvNew.FullRowSelect = true;            lvNew.View = View.Details;            lvNew.Columns.Clear();            lvNew.Columns.Add("歌曲名称", 300);            lvNew.Columns.Add("歌手", 150);            lvNew.Columns.Add("点播次数", 100);            lvNew.DoubleClick += lvNew_DoubleClick;            lv_Login.Controls.Add(lvNew);        }        //添加三个个控件        TextBox txt = new TextBox();        Label lbl = new Label();        ListView lvNew = new ListView();        //lv_Login的新添项lvNew的Items双击事件        private void lvNew_DoubleClick(object sender, EventArgs e)        {            //在这里引用歌曲双击事件            int result = Convert.ToInt32(lvNew.SelectedItems[0].Tag);            //MessageBox.Show(result.ToString());            DoubleClickSong(result);        }        //new出的txt的text值改变时事件        private void txt_TextChanged(object sender, EventArgs e)        {            lvNew.Items.Clear();            string result="";            if (!txt.Text.Trim().Equals(string.Empty))        {        foreach (char item in txt.Text)            {            if (item>='a'&&item<='z')                {                        result += item;                        result += '%';                }else if (item>='A'&&item<='Z')                {                        result += item.ToString().ToLower();                        result += '%';                }            }        }            string str;            if (!result.Equals(string.Empty))            {                str = @"select song_id,song_name,singer_name,song_play_count from song_info,singer_info where song_ab like '%" + result + "%' and song_info.singer_id = singer_info.singer_id";            }            else            {                return;            }            try            {                SqlDataReader dr = db.Dr(str);                if (dr.HasRows)                {                    while (dr.Read())                    {                        ListViewItem item = new ListViewItem(dr["song_name"].ToString());                        item.Tag = dr["song_id"].ToString();                        item.SubItems.Add(dr["singer_name"].ToString());                        item.SubItems.Add(dr["song_play_count"].ToString());                        lvNew.Items.Add(item);                    }                    dr.Close();                }            }            catch (Exception)            {                MessageBox.Show("私有连接异常!");            }            finally            {                db.CloseConnection();            }        }        #endregion        //金榜排行按钮点击事件        private void tsbtnTool_order_Click(object sender, EventArgs e)        {            imglist.Images.Clear();            lv_Login.SmallImageList = imglist;            string str = @"select top 10 song_id,song_name,singer_name,song_play_count from song_info,singer_info where song_info.singer_id=singer_info.singer_id order by song_play_count desc";            num = 0;            SingerToSongs(str);            lv_Login.View = View.List;            imglist.ImageSize = new Size(60, 60);            try            {                for (int i = 0; i < 10; i++)                {                    imglist.Images.Add(Image.FromFile(@"D:\课程\S1\KTV\MyKTV\image\" + i + ".png"));                    lv_Login.Items[i].ImageIndex = i;                }            }            catch (Exception)            {                            }        }        //单击字数点歌按钮事件        private void tsbtnTool_counts_Click(object sender, EventArgs e)        {            //目标lv_Login为字数lv, num为4            num = 4;            lv_Login.Clear();            lv_Login.Controls.Clear();            imglist.Images.Clear();            lv_Login.LargeImageList = imglist;            imglist.ImageSize = new System.Drawing.Size(60, 60);            lv_Login.View = View.LargeIcon;            for (int i = 1; i < 11; i++)            {                imglist.Images.Add(Image.FromFile(@"D:\课程\S1\KTV\MyKTV\image\" + i + ".png"));                ListViewItem item = new ListViewItem((i) + "个字",i-1);                item.Tag = i+1;                lv_Login.Items.Add(item);            }            imglist.Images.Add(Image.FromFile(@"D:\课程\S1\KTV\MyKTV\image\N.png"));            ListViewItem itemN = new ListViewItem("N个字", 10);            itemN.Tag = 11;            lv_Login.Items.Add(itemN);        }        //定时器事件        private void timer_Tick(object sender, EventArgs e)        {            Playing();        }        /// <summary>        /// 歌手双击方法        /// </summary>        /// <param name="str">查询歌曲语句</param>        public void SingerToSongs(string str)        {            num = 0;            lv_Login.View = View.Details;            lv_Login.Clear();            lv_Login.Controls.Clear();            lv_Login.Columns.Add("歌曲名称", 300);            lv_Login.Columns.Add("歌手", 150);            lv_Login.Columns.Add("点播次数", 100);            try            {                SqlDataReader dr = db.Dr(str);                if (dr.HasRows)                {                    while (dr.Read())                    {                        ListViewItem item = new ListViewItem(dr["song_name"].ToString());                        item.Tag = dr["song_id"].ToString();                        item.SubItems.Add(dr["singer_name"].ToString());                        item.SubItems.Add(dr["song_play_count"].ToString());                        lv_Login.Items.Add(item);                    }                    dr.Close();                }            }            catch (Exception)            {                MessageBox.Show("私有连接异常!");            }            finally            {                db.CloseConnection();            }        }        /// <summary>        /// 播放列表专属数组        /// </summary>        Song[] playing_list = new Song[100];        /// <summary>        /// 歌曲双击方法        /// </summary>        /// <param name="result">双击歌曲项的Tag值</param>        public void DoubleClickSong(int result)        {            //循环判定            foreach (Song song in playing_list)            {                if (song!=null && song.SongId == result.ToString())                {                    MessageBox.Show("已点!");                    return;                }                else if (song==null)                {                    break;                }            }            int i = 0;            foreach (Song one in playing_list)            {                if (one != null)                    i++;            }            string str = @"select song_name from song_info where song_id = " + result + "";            try            {                SqlDataReader dr = db.Dr(str);                if (dr.HasRows)                {                    if (dr.Read())                    {                        playing_list[i] = new Song();                        playing_list[i].SongName = dr["song_name"].ToString();                        playing_list[i].SongId = result.ToString();                    }                }                dr.Close();            }            catch (Exception)            {                MessageBox.Show("私有连接异常!");            }            finally            {                db.CloseConnection();                if (playing_list[i]!=null)                {                    playing_list[i].Songurl = GetSongurlById(result.ToString());                }            }            ListViewItem item = new ListViewItem(playing_list[i].SongName);            ///注意            ///注意            if (i == 0)            {                item.SubItems.Add("正在播放");                wmp.URL = playing_list[i].Songurl;                try                {                    SetPlayCount(playing_list[i].SongId);                }                catch (Exception ex)                {                    MessageBox.Show(ex.Message);                }            }            else            {                item.SubItems.Add("未播放");                try                {                    SetPlayCount(playing_list[i].SongId);                }                catch (Exception ex)                {                    MessageBox.Show(ex.Message);                }            }            item.SubItems.Add(playing_list[i].SongId);            item.Tag = playing_list[i].Songurl;            lvPlay_list.Items.Add(item);            timer.Enabled = true;        }        /// 当前播放的歌曲在对象数组中的下标        /// </summary>        int playingIndex = 0;        /// <summary>        /// 播放方法        /// </summary>        public void Playing()        {            //重新写            if (wmp.playState==WMPLib.WMPPlayState.wmppsPlaying)            {                try                {                    //面板信息更改                    lblPlaying_name.Text = playing_list[playingIndex].SongName;                    lblNext_name.Text = playing_list[playingIndex+1].SongName;                }                catch (Exception)                {                    lblNext_name.Text = "无";                }            }            else if (wmp.playState == WMPLib.WMPPlayState.wmppsStopped)            {                try                {                    //状态更新                    lvPlay_list.Items[playingIndex].SubItems[1].Text = "已播放";                }                catch (Exception)                {                    return;                }                playingIndex++;                //为播放列表的最后一个时,返回index,跳出方法                if (playing_list[playingIndex] == null)                {                    playingIndex--;                    wmp.URL = string.Empty;                    return;                }                wmp.URL = playing_list[playingIndex].Songurl;                lvPlay_list.Items[playingIndex].SubItems[1].Text = "正在播放";                //面板提示信息更新                lblPlaying_name.Text = playing_list[playingIndex].SongName;                try                {                    lblNext_name.Text = playing_list[playingIndex + 1].SongName;                }                catch (Exception)                {                    lblNext_name.Text = "无";                }            }            //歌曲读取异常(为空,或,路径异常)            else if (wmp.playState==WMPLib.WMPPlayState.wmppsReady)            {                if (wmp.URL==string.Empty)                {                    //只要路径为空,只需要判定播放列表是否为空,否则直接播放                    if (playing_list[playingIndex] == null)                    {                        return;                    }                    wmp.URL = playing_list[playingIndex].Songurl;                    try                    {                        lvPlay_list.Items[playingIndex].SubItems[1].Text = "正在播放";                    }                    catch (Exception)                    {                        return;                    }                    //面板提示信息更新                    lblPlaying_name.Text = playing_list[playingIndex].SongName;                    try                    {                        lblNext_name.Text = playing_list[playingIndex +1].SongName;                    }                    catch (Exception)                    {                        lblNext_name.Text = "无";                    }                }                else                {                    lvPlay_list.Items[playingIndex].SubItems[1].Text = "路径异常";                    playingIndex++;                    //为播放列表的最后一个时,返回index,跳出方法                    if (playing_list[playingIndex] == null)                    {                        wmp.URL = string.Empty;                        return;                    }                    wmp.URL = playing_list[playingIndex].Songurl;                    try                    {                        lvPlay_list.Items[playingIndex].SubItems[1].Text = "正在播放";                    }                    catch (Exception)                    {                        return;                    }                                        //面板提示信息更新                    lblPlaying_name.Text = playing_list[playingIndex].SongName;                    try                    {                        lblNext_name.Text = playing_list[playingIndex + 1].SongName;                    }                    catch (Exception)                    {                        lblNext_name.Text = "无";                    }                }            }            else            {                return;            }        }        /// <summary>        /// 根据歌手id查找歌手图片路径        /// </summary>        /// <param name="id">singerId</param>        /// <returns>singerPhotoUrl</returns>        public string GetSingerurlById(string id)        {            string str2 = @"select resource_path from resource where resource_type='歌手图片地址'";            string singerphoto_url = db.ScalForString(str2);            string str = @"select singer_photo_url from singer_info where singer_id='" + id + "'";            string singer_url = db.ScalForString(str);            string sb = singerphoto_url + singer_url;            return sb;        }        /// <summary>        /// 根据歌曲id查找歌曲路径        /// </summary>        /// <param name="id">songId</param>        /// <returns>songUrl</returns>        public string GetSongurlById(string id)        {            string str = @"select resource_path from resource where resource_type = '歌曲地址'";            StringBuilder sb = new StringBuilder(db.ScalForString(str));            string str2 = @"select song_url from song_info where song_id = " + id + "";            sb.Append(db.ScalForString(str2));            return sb.ToString();        }        /// <summary>        /// 播放次数更新方法        /// </summary>        /// <param name="songId">歌曲Id的字符串格式</param>        /// <returns>是否成功</returns>        public bool SetPlayCount(string songId)        {            int result;            string str1 = @"select song_play_count from song_info where song_id=" + songId + "";            try            {                result = Convert.ToInt32(db.Scal(str1));            }            catch (Exception)            {                result = 0;            }            result++;            string str = @"update song_info set song_play_count = " + result + " where song_id=" + songId + "";            if (db.Non(str)>0)            {                return true;            }            else            {                return false;            }        }        /// <summary>        /// new国家lv_Login方法        /// </summary>        private void GetSingerType()        {            lv_Login.Clear();            lv_Login.Controls.Clear();            imglist.Images.Clear();            lv_Login.View = View.LargeIcon;            lv_Login.LargeImageList = imglist;            string str1 = @"select count(1) from singer_type";            int result;            try            {                result = Convert.ToInt32(db.Scal(str1));            }            catch (Exception)            {                return;            }            string str = @"select singertype_id, singertype_name from singer_type";            try            {                SqlDataReader dr = db.Dr(str);                if (dr.HasRows)                {                    for (int i = 0; i < result; i++)                    {                        dr.Read();                        Image img;                        try                        {                            img = Image.FromFile(@"D:\课程\S1\KTV\MyKTV\image" + Convert.ToString(dr["singertype_name"]) + ".png");                        }                        catch (Exception)                        {                            img = Image.FromFile("D:\\课程\\S1\\KTV\\MyKTV\\image\\singer_temp.jpg");                        }                        imglist.Images.Add(img);                        ListViewItem item = new ListViewItem(dr["singertype_name"].ToString(),i);                        item.Tag = Convert.ToString(dr["singertype_id"]);                        lv_Login.Items.Add(item);                    }                }                dr.Close();            }            catch (Exception)            {                MessageBox.Show("歌手地区读取异常!");            }            finally            {                db.CloseConnection();            }        }        /// <summary>        /// 获取歌手信息        /// </summary>        /// <param name="strCounts">条件下歌手个数查询语句</param>        /// <param name="str">条件下歌手信息查询语句</param>        private void GetSinger(string strCounts, string str)        {            //歌手lv的目标lv为歌曲            num = 1;            imglist.Images.Clear();            lv_Login.Clear();            lv_Login.Controls.Clear();            lv_Login.View = View.LargeIcon;            //确定大图标的图像列表对象            lv_Login.LargeImageList = imglist;            imglist.ImageSize = new System.Drawing.Size(72, 128);            int result = db.ScalForInt(strCounts);            SqlCommand comm = new SqlCommand(str, db.conn);            //new出对象数组,用于存储目标表格信息            Song[] song = new Song[result];            try            {                db.OpenConnection();                SqlDataReader dr = comm.ExecuteReader();                if (dr != null)                    if (dr.HasRows)                    {                        for (int i = 0; i < result; i++)                        {                            if (dr.Read())                            {                                //读取了歌手id,歌手名称                                song[i] = new Song();                                song[i].SingerId = dr["singer_id"].ToString();                                song[i].SingerName = dr["singer_name"].ToString();                            }                        }                        dr.Close();                    }            }            catch (Exception)            {                MessageBox.Show("私有连接异常!");            }            finally            {                db.CloseConnection();            }
            //改变imagelist的图片大小:imglist.ImageSize = new Size(32, 32);
            //循环读出图片url,加载对应图片到imglist,给items组合项添加对象数组中每一项            for (int i = 0; i < result; i++)            {                song[i].SingerPhoto = GetSingerurlById(song[i].SingerId);                Image img;                //亮点                try                {                    img = Image.FromFile(song[i].SingerPhoto);                }                catch (Exception)                {                    img = Image.FromFile("D:\\课程\\S1\\KTV\\MyKTV\\image\\singer_temp.jpg");                }                imglist.Images.Add(img);                ListViewItem item = new ListViewItem(song[i].SingerName, i);                item.Tag = song[i].SingerId;                lv_Login.Items.Add(item);            }        }        #region 删除播放列表歌曲,双击播放        ////删除选中歌曲按钮事件        private void btnDel_Click(object sender, EventArgs e)        {            int result;            try            {                result = Convert.ToInt32(lvPlay_list.SelectedItems[0].Index);            }            catch (Exception)            {                return;            }            //清空对象数组与列表            lvPlay_list.SelectedItems[0].Remove();            ///亮点            if (result == playingIndex)            {
                try                {                    if (playing_list[result + 1] != null)                    {                        for (int i = result + 1; i < playing_list.Length; i++)                        {                            playing_list[i - 1].SongId = playing_list[i].SongId;                            playing_list[i - 1].SongName = playing_list[i].SongName;                            playing_list[i - 1].Songurl = playing_list[i].Songurl;                        }                        wmp.URL = playing_list[result].Songurl;                    }                    else                    {                        playing_list[result] = playing_list[result + 1];                        wmp.URL = string.Empty;                    }                }                catch (Exception)                {                    wmp.URL = string.Empty;                }            }                   }        ////双击播放列表组件时        private void lvPlay_list_DoubleClick(object sender, EventArgs e)        {            try            {                wmp.URL = playing_list[Convert.ToInt32(lvPlay_list.SelectedItems[0].Index)].Songurl;                lvPlay_list.Items[playingIndex].SubItems[1].Text = "已播放";                playingIndex = Convert.ToInt32(lvPlay_list.SelectedItems[0].Index);                lvPlay_list.Items[playingIndex].SubItems[1].Text = "正在播放";            }            catch (Exception)            {                return;            }        }        ////列表循环方式按钮点击事件        private void btnState_Click(object sender, EventArgs e)        {        //    Timer timeResult = new Timer();        //    if (btnState.Text=="列表循环模式")        //    {        //        btnState.Text = "单曲循环模式";        //        timer.Enabled = false;        //        timeResult.Enabled = true;        //        timeResult.Interval = 1000;        //        timeResult.Tick += timeResult_Tick;        //    }        //    else if (btnState.Text=="单曲循环模式")        //    {        //        btnState.Text = "无循环模式";        //        timer.Enabled = true;        //        timeResult.Enabled = false;        //    }        //    else if (btnState.Text=="无循环模式")        //    {        //        btnState.Text = "列表循环模式";        //        timer.Enabled = false;        //        timeResult.Enabled = true;        //        timeResult.Interval = 1000;        //        timeResult.Tick += timeResult_Tick;        //    }        }        ////附加定时器事件        void timeResult_Tick(object sender, EventArgs e)        {
        //    if (wmp.playState==WMPLib.WMPPlayState.wmppsStopped&&btnState.Text=="单曲循环模式")        //    {        //        wmp.URL = playing_list[playingIndex].Songurl;        //    }        //    else if (btnState.Text=="列表循环模式")        //    {        //        int result=-1;        //        foreach (Song item in playing_list)        //        {        //            if (item!=null)        //            {        //                result++;        //            }        //            else        //            {        //                break;        //            }        //        }        //        if (playingIndex==result)        //        {        //            playingIndex = 0;        //        }        //    }        }        #endregion

用C#,SQL Server编写的音乐播放软件的更多相关文章

  1. SQL Server中的CLR编程——用.NET为SQL Server编写存储过程和函数

    原文:SQL Server中的CLR编程--用.NET为SQL Server编写存储过程和函数 很早就知道可以用.NET为SQL Server2005及以上版本编写存储过程.触发器和存储过程的,不过之 ...

  2. sql server编写通用脚本自动统计各表数据量心得

    工作过程中,如果一个数据库的表比较多,手工编写统计脚本就会比较繁琐,于是摸索出自动生成各表统计数据量脚本的通用方法,直接上代码: /* 脚本来源:https://www.cnblogs.com/zha ...

  3. sql server编写简洁四则运算表达式脚本实现计算批次功能(C#等其它编程语言也能直接用此通用表达式)

    问题: 在数据库编程开发中,有时会遇到数据量比较大的情况,如果直接大批量进行添加数据.修改数据.删除数据,就会是比较大的事务,事务日志也比较大,耗时久的话会对正常操作造成一定的阻塞.虽不至于达到删库跑 ...

  4. 安装 SQL Server 2005 的硬件和软件要求(官方全面)

    SQL Server 2005 安装要求 本主题介绍了安装 SQL Server 205 的硬件和软件要求,以及查看安装文档的说明. 硬件和软件要求(32 位和 64 位) 访问 SQL Server ...

  5. sql server编写脚本求解第1天1分钱之后每天两倍持续一个月的等比数列问题

    一.问题 问题1 场景:如果你未来的丈母娘要求你,第1天给她1分钱,第2天给2分钱,第3天给4分钱,以此类推,每天给前一天的2倍,给1个月(按30天)算就行.问:第30天给多少钱,总共给多少钱? 问题 ...

  6. Sql server 编写99乘法表

    Sql 组织编写语句 declare @one int,@tow int,@str varchar(100),@num intselect @one=1while(@one<=9)beginse ...

  7. 安装 SQL Server 2012 的硬件和软件要求(官方全面)

    以下各节列出了安装和运行 SQL Server 2012 的最低硬件和软件要求. 有关 SharePoint 集成模式下 Analysis Services 的要求的详细信息,请参阅硬件和软件要求(S ...

  8. sql server编写archive通用模板脚本实现自动分批删除数据

    博主做过比较多项目的archive脚本编写,对于这种删除数据的脚本开发,肯定是一开始的话用最简单的一个delete语句,然后由于部分表数据量比较大啊,索引比较多啊,会发现删除数据很慢而且影响系统的正常 ...

  9. sql server编写一个语句脚本自动清空各表数据以初始化数据库

    问题:有时已有项目要移植,例如原来在广州地区使用的某系统,突然说惠州那边也要用这套一样的系统.或者,在demo环境下弄了一些测试数据.然后要清空全部表数据.如果表比较多的话,逐个表手工编写脚本就太麻烦 ...

随机推荐

  1. C#事件支持发布者/订阅者模式(观察者模式)

    C#事件支持发布者/订阅者模式,发布者将事件通知给订阅者,而订阅者在事件发生时调用已经注册好的事件处理函数.        public delegate void delUpdate();  //委 ...

  2. 【python】函数

    内置函数: abs('A') 报错:TypeError: bad operand type for abs(): 'str' 传入的参数类型不对 自定义函数: 1 def my_abs(x): 2 i ...

  3. JQ源码学习-1-无new构建

    此文章仅为个人学习 Aaron的jQuery源码分析 笔记之用. 一:采用 构造函数 返回 原型初始化方法,原型初始化方法又返回构造函数 的方式代替new 但当 返回的却是‘web’而不是Object ...

  4. 使用vs2010创建MFC C++ Ribbon程序

    Your First MFC C++ Ribbon Application with Visual Studio 2010 Earlier this month, I put together my ...

  5. Ubuntu下libpcap安装

    1.首先按下面的博客教程下载和安装四个软件包: 点击打开链接 2.这四个软件都安装好之后按下面教程新建Makefile文件和test.c文件: 点击打开链接 Makefie: all: test.c ...

  6. 基于HTML5的网络拓扑图

    电信网管系统中,设备状态信息的实时展示非常重要,通常会挂载一堆图标来展示状态或告警信息,图标的信息量有限,有时需要更详细的面板,甚至以图表的形式展现,本文将结合最近客户提到的需求,使用 Qunee1. ...

  7. [软件架构]模块化编程思想及(C++)实践

    Repost 内容简介: 模块化思想 模块的构成 模块的管理 模块化实践 定义模块结构 声明模块对象 定义模块列表 模块列表对象 模块化思想 1.     将系统分成很多的模块,模块内部关注自身需要实 ...

  8. ASIHTTPRequest中数据压缩问题与gzip

    出现了类似问题,先mark,以后修改 最近使用asi发现,部分网络回调数据不能正常的json解析,将responseHeaders头打印出来,才发现公司服务器部分数据添加了gzip压缩传输. 最近简单 ...

  9. AJAX请求WebService

    1.WebService代码 [WebMethod] [ScriptMethod(UseHttpGet = false)] public string GetObject() { User user ...

  10. Java—从文件中读取数据

    1.FileInputStream() // 构建字节输入流对象,参数为文件名 FileInputStream fin = new FileInputStream("message" ...