复制代码 代码如下: private string toadd = "├".<BR><BR>private void GetArticleCategory(string pid) { SqlConnection conn = new SqlConnection("server=.;database=test;uid=sa;pwd=;"); string sql = "select Articlesgroup_id,Groupname from Articlesgroup where [email protected] order by Groupname"; SqlCommand cmd = new SqlCommand(sql, conn); SqlParameter Pid = new SqlParameter("@pid", SqlDbType.Int); Pid.Value = pid; cmd.Parameters.Add(Pid); conn.Open(); SqlDataReader sdr = cmd.ExecuteReader(); while (sdr.Read()) { this.DropDownList1.Items.Add(new ListItem(toadd + " " + sdr[1].ToString(), sdr[0].ToString())); toadd += "─┴"; this.GetArticleCategory(sdr[0].ToString()); toadd = toadd.Substring(0, toadd.Length - 2); } sdr.Close(); conn.Close(); } 在Page_Load里调用 程序代码 复制代码 代码如下: protected void Page_Load(object sender, EventArgs e) { this.keyword.Attributes.Add("onfocus","if( this.value=='key key key') {this.value='' };"); if (!Page.IsPostBack) { this.GetArticleCategory("0"); } this.DropDownList1.Items.Insert(0, new ListItem("Search All",

复制代码 代码如下: private static volatile T _instance = null; private static object objLock = new Object(); private T() { } public static T Instance { get { if (_instance == null) { lock (objLock) { if (_instance == null) { _instance = new T(); } } } return _instance; } } 在必要的时候需如果要刷新当前instance,可以这样写: 复制代码 代码如下:

“一个.aspx的页面中,用到了两个用户控件,其中想做的到A控件有一个按钮,点击的时候获取到B控件中的一个textbox的值。 因为在生成的时候名字会改变,用findcontrol的时候名字该如何写呢? 另外像这种问题有几种解决的办法呢?”论坛上看到这个问题,Insus.NET提供自己的解决方法,先看看解决运行的效果:  首先创建一个站点,然后创建两个用户控件,一个是UcA,一个是UcB。 在UcB的控件上拉一个TextBox。 复制代码 代码如下: <%@ Control Language="C#" AutoEventWireup="true" CodeFile="UcB.ascx.cs" Inherits="UcB" %> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> 创建一个接口IGetValue: 复制代码 代码如下: IGetValue.cs using System; using System.Collections.Generic; using System.Linq; using System.Web; /// <summary> /// Summary description for IGetValue /// </summary> namespace Insus.NET { public interface IGetValue { string GetValue(); } } 接下来,用户控件UcB实现这个接口,接口返回TextBox的Text值。 复制代码 代码如下: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using Insus.NET; public partial class UcB : System.Web.UI.UserControl,IGetValue { protected void Page_Load(object sender, EventArgs e) { } public string GetValue() { return this.TextBox1.Text.Trim(); } } 创建一个aspx页面,如Default.aspx,切换至设计模式,把两个用户控件UcA,UcB拉至Default.aspx: 复制代码 代码如下: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <%@ Register Src="UcA.ascx" TagName="UcA" TagPrefix="uc1" %> <%@ Register Src="UcB.ascx" TagName="UcB" TagPrefix="uc2" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <fieldset> <legend>UcA </legend> <uc1:UcA ID="UcA1" runat="server" /> </fieldset> <fieldset> <legend>UcB </legend> <uc2:UcB ID="UcB1" runat="server" /> </fieldset> </form> </body> </html> 到这里,再创建一个接口Interface,目的是为了获取UcB这个用户控件。 复制代码 代码如下: IGetUserControl.cs using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; /// <summary> /// Summary description for IGetUserControl /// </summary> namespace Insus.NET { public interface IGetUserControl { UserControl GetUc(); } } 接口创建好之后,在Default.aspx.cs实现这个IGetUserControl接口。 复制代码 代码如下: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using Insus.NET; public partial class _Default : System.Web.UI.Page,IGetUserControl { protected void Page_Load(object sender, EventArgs e) { } public UserControl GetUc() { return this.UcB1; } } 到最后,我们在UcA这个用户控件的按钮Click事件写: 复制代码 代码如下: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using Insus.NET; public partial class UcA : System.Web.UI.UserControl { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender,

要做基于WPF的音频文件循环顺序播放首先要了解WPF下有哪些类是用于控制音频的. WPF下主要有两个音频控制的类,这里做下比较:    1.SoundPlayer      2.MediaPlayer     派生MediaElement一.SoundPlayer类       1.基于.NET FRAMEWORK 2.0;    2.可播放WAV音频文件;     3.只能播放一个文件,同时播放多个文件会后一个文件的播放操作会终止前一个播放的文件;    4.不能对音量进行控制;二.MediaPlayer类    1.基于WPF;     2.支持多种音频文件;    3.可以同时播放多个声音;    4.可以调整音量对音频进行控制;    5.支持设置静音和左右扬声器;    6.可以控制音频播放速度和获取播放进度和控制进度;     MediaElement类同MediaPlayer的功能类似,作为WPF页面可用的标签是MediaPlayer的衍生; WPF下音频文件循环顺序播放的开发思路:首先新建一个类继承MediaElement;这个类包含播放逻辑功能:    1.读取指定文件夹内的所有音频文件;    2.将读取的文件路径放入列表;    3.顺序读取列表中的文件名;    4.播放音频文件;    5.播放完毕读取下一个文件名直至列表结尾;    6.播放音频文件至列表结尾则转制列表头继续播放;在XAML界面加载这个类;Window Load事件里执行这个类的播放列表;下面贴出了WPF下音频文件循环顺序播放的代码:复制代码 代码如下:WPF界面代码  <Window x:Class="MediaApplication.MainWindow"         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"         xmlns:md="clr-namespace:MediaApplication"         Title="MainWindow" Height="350" Width="525" Loaded="Window_Loaded">     <StackPanel>         <md:MediaManager x:Name="media"></md:MediaManager>     </StackPanel>  </Window>复制代码 代码如下:WPF界面CS代码  using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.IO; using System.Collections.ObjectModel; using System.Configuration; namespace MediaApplication {     /// <summary>     /// Interaction logic for MainWindow.xaml     /// </summary>     public partial class MainWindow : Window {         public MainWindow() {             InitializeComponent();         }         private void Window_Loaded(object sender, RoutedEventArgs e) {             this.media.PlayList();         }      } }复制代码 代码如下:MediaManager类 using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Windows.Controls;using System.IO;using System.Configuration;using System.Windows;using System.Collections.ObjectModel;namespace MediaApplication {    public class MediaManager : MediaElement {        public MediaManager() {            try {                GetAllDirList(new DirectoryInfo(ConfigurationManager.AppSettings["dir"].ToString()));            } catch {            }        }        public void PlayList() {            if(files.Count > 0)            {                this.UnloadedBehavior = MediaState.Manual;                this.LoadedBehavior = MediaState.Manual;                this.MediaEnded += new RoutedEventHandler(media_MediaEnded);                this.Source = new Uri( files[index], UriKind.RelativeOrAbsolute);                this.Play();            }          }        private void GetAllDirList(DirectoryInfo directory) {                        foreach(string filter in filters)             {                foreach (FileInfo file in directory.GetFiles(filter)) {                    files.Add(file.FullName);                }            }             foreach (DirectoryInfo subDirectory in directory.GetDirectories()) {                GetAllDirList(subDirectory);            }        }        private void media_MediaEnded(object sender, RoutedEventArgs e) {            this.Source = new Uri( files[++index % files.Count], UriKind.RelativeOrAbsolute);            this.Play();        }        private ObservableCollection<string> files = new ObservableCollection<string>();        private int index = 0;        private string[] filters = new string[] { "*.wav",

微软的visual studio没有自带连接Mysql的驱动,要去网上下载一个mysql-connector-net-6.4.3驱动,然后安装就可以使用。下面是我封装好的连接数据库的类,直接调用即可。复制代码 代码如下:using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Data;using System.Data.SqlClient;using System.Configuration;using MySql.Data.MySqlClient;namespace DAL{  public class GetConnection    {        private static MySqlConnection  _connection;      /// <summary>      /// 获取数据库连接桥      /// </summary>        private static MySqlConnection Connection        {            get            {               //string connectionString = ConfigurationManager.AppSettings["ConnectionString"];                string connectionString = "server=localhost;user id=root; password=root; database=system; pooling=false";                //server=222.222.222.222;port=3306;uid=user;pwd=;database=basename;远程连接的                //string connectionString = "Data Source=202.192.72.22;Initial Catalog=wwj;Persist Security Info=True;User ID=wwj;Password=wwj123";                if (_connection == null)                {                    _connection = new MySqlConnection(connectionString);                    _connection.Open();                }                if (_connection.State == ConnectionState.Closed)                {                    _connection.Open();                }                if (_connection.State == ConnectionState.Broken)                {                    _connection.Close();                    _connection.Open();                }                return GetConnection._connection;            }        }      /// <summary>      /// 获取表数据      /// </summary>      /// <param name="sql"></param>      /// <returns></returns>        public static MySqlDataReader GetDataRead(string sql)        {            MySqlCommand command = new MySqlCommand(sql, Connection);            MySqlDataReader read = command.ExecuteReader();            return read;        }        public static int NoSelect(string sql)        {            MySqlCommand command = new MySqlCommand(sql, Connection);            int row = command.ExecuteNonQuery();            return row;        }        public static DataTable GetDataTable(string sql)        {            MySqlCommand command = new MySqlCommand(sql, Connection);            DataTable dt = new DataTable();            MySqlDataAdapter sda = new MySqlDataAdapter(command);            sda.Fill(dt);            return dt;        }        /// <summary>        /// 执行sql语句,返回一行一列。。        /// </summary>        /// <param name="sql">SQL语句</param>        /// <returns></returns>        public static string GetScalar(string sql)        {            MySqlCommand command = new MySqlCommand(sql, Connection);            return command.ExecuteScalar().ToString();        }    }}比如说你想执行删除的,你可以调用GetConnection.NoSelect("delete from UserInfo where Id=1");读数据库的某一张表,可以调用GetConnection.GetDataTable("select * from UserInfo");调用都很方便。

分类:腾博会手机版下载

时间:2016-01-21 06:10:06