?? systemtools.cs
字號(hào):
?using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
/// <summary>
/// SystemTools 的摘要說明
/// </summary>
public class SystemTools
{
public SystemTools()
{
///
}
public SqlDataReader GetProfiles()
{
///創(chuàng)建鏈接
SqlConnection myConnection = new SqlConnection(
ConfigurationManager.ConnectionStrings["SQLCONNECTIONSTRING"].ConnectionString);
string cmdText = "SELECT * FROM Profile";
///創(chuàng)建Command
SqlCommand myCommand = new SqlCommand(cmdText,myConnection);
///定義DataReader
SqlDataReader dr = null;
try
{
///打開鏈接
myConnection.Open();
///讀取數(shù)據(jù)
dr = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
}
catch(SqlException ex)
{
///拋出異常
throw new Exception(ex.Message,ex);
}
///返回DataReader
return dr;
}
public int SetRepeatVote(string sIsRepeatVote)
{
///創(chuàng)建鏈接
SqlConnection myConnection = new SqlConnection(
ConfigurationManager.ConnectionStrings["SQLCONNECTIONSTRING"].ConnectionString);
string cmdText = "UPDATE Profile SET IsRepeatVote = '" + sIsRepeatVote + "'";
///創(chuàng)建Command
SqlCommand myCommand = new SqlCommand(cmdText,myConnection);
///定義返回值
int nResult = -1;
try
{
///打開鏈接
myConnection.Open();
///執(zhí)行SQL語句
nResult = myCommand.ExecuteNonQuery();
}
catch(SqlException ex)
{
///拋出異常
throw new Exception(ex.Message,ex);
}
finally
{ ///關(guān)閉鏈接
myConnection.Close();
}
///返回nResult
return nResult;
}
public static void SetListBoxItem(ListBox listBox,string sItemValue)
{
int index = 0;
foreach(ListItem item in listBox.Items)
{
///判斷值是否相等,并且設(shè)置控件的SelectedIndex
if(item.Value.ToLower() == sItemValue.ToLower())
{
listBox.SelectedIndex = index;
break;
}
index++;
}
}
public static void SetListBoxItem(DropDownList listBox,string sItemValue)
{
int index = 0;
foreach(ListItem item in listBox.Items)
{
///判斷值是否相等,并且設(shè)置控件的SelectedIndex
if(item.Value.ToLower() == sItemValue.ToLower())
{
listBox.SelectedIndex = index;
break;
}
index++;
}
}
public static void SetListBoxItem(ListBox listBox,string sItemValue,bool IsBool)
{
int index = 0;
if(IsBool == true)
{
sItemValue = sItemValue.ToLower() == "true" ? "1" : "0";
}
foreach(ListItem item in listBox.Items)
{
///判斷值是否相等,并且設(shè)置控件的SelectedIndex
if(item.Value.ToLower() == sItemValue.ToLower())
{
listBox.SelectedIndex = index;
break;
}
index++;
}
}
public static void SetListBoxItem(DropDownList listBox,string sItemValue,bool IsBool)
{
int index = 0;
if(IsBool == true)
{
sItemValue = sItemValue.ToLower() == "true" ? "1" : "0";
}
foreach(ListItem item in listBox.Items)
{
///判斷值是否相等,并且設(shè)置控件的SelectedIndex
if(item.Value.ToLower() == sItemValue.ToLower())
{
listBox.SelectedIndex = index;
break;
}
index++;
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -