最近在國外網站晃悠
一直聽說印度的軟件業比較發達
下面是類結構圖
程序的功能方面實現起來並不是很輕松
M
DataManager
namespace IndiaStudyChannel
{
/**//// <summary>
/// Summary description for DataManager
/// </summary>
/// 由 liudao 翻譯整理
/// 該源碼下載自(51aspx.com)
public class DataManager
{
public DataManager()
{
}
public static DataTable ExecuteQuery(string query)
{
string connectionString = System
SqlConnection connection = new SqlConnection(connectionString);
connection
try
{
SqlDataAdapter adapter = new SqlDataAdapter(query
DataSet ds = new DataSet();
adapter
return ds
}
finally
{
if ( connection
connection
}
}
public static void ExecuteNonQuery(string query)
{
string connectionString = System
SqlConnection connection = new SqlConnection(connectionString);
connection
try
{
SqlCommand cmd = new SqlCommand();
cmd = connection
cmd
cmd
cmd
}
finally
{
if ( connection
connection
}
}
public static object ExecuteScalar(string query)
{
string connectionString = System
SqlConnection connection = new SqlConnection(connectionString);
connection
//
try
{
SqlCommand cmd = new SqlCommand();
cmd = connection
cmd
cmd
return cmd
}
finally
{
if ( connection
connection
}
}
}
}
把常用的sql方法寫成一個類
通用函數類(字符串處理等)
namespace IndiaStudyChannel
{
/**//// <summary>
/// Summary description for Utils
/// </summary>
/// 由 liudao 翻譯整理
/// 該源碼下載自(51aspx.com)
public class Utils
{
public Utils()
{
}
/**//// <summary>
/// This method removes some dangerous characters from the word to avoid
/// </summary>
/// <param name=
/// <returns></returns>
public static string MakeSafeWord(string s)
{
if ( s == null )
return
return s
}
/**//// <summary>
/// This method checks if the passed user id is an adinistrator or if this is same as current user
/// </summary>
/// <param name=
/// <returns></returns>
public static bool IsOwner(object userId)
{
if ( System
{
// There is no userid saved in session
return false;
}
// Get current user from session
string currentUser = System
// Get the admin user id from config file
string adminUser = System
if ( currentUser == adminUser )
{
// Current user is an administrator
return true;
}
if ( userId != null && userId
{
// Current user is same as the userId passed
return true;
}
return false;
}
/**//// <summary>
/// This method checks if the passed user id is an adinistrator or if this is same as current user
/// </summary>
/// <param name=
/// <returns></returns>
public static bool IsAdministrator()
{
if ( System
{
// There is no userid saved in session
return false;
}
// Get current user from session
string currentUser = System
// Get the admin user id from config file
string adminUser = System
if ( currentUser == adminUser )
{
// Current user is an administrator
return true;
}
return false;
}
public static string FormatFileName(string s)
{
char[] chars = {
foreach (char c in chars)
{
s = s
}
s = s
s = s
if ( s
{
s = s
}
return s;
}
}
}
函數的調用也很簡單
protected void Page_Load(object sender
{
string query =
dg
dg
}
其他優秀的地方都體現在細節方面
通過這個程序發現我們在軟件方面要向印度方面學習的確實太多太多
·去除了部分
·使數據庫等等支持中文字符(修改排序規則
·翻譯了大部分菜單及控件名稱
文中有翻譯可笑或者不妥之處還望大家批評指正!(liudao)
該項目的完整源碼下載地址>>
譯者補注
沒想到文章發完以後引各位朋友這麼熱心的關注
·該代碼對於高手來說確實是沒有什麼
·大家要抱著初學者的心態來看待這個源碼
·高手應該在這裡引領新手
·這裡提到的印度也許是一個理想的不存在的國度——一個需要我們去實現的良好軟件大環境
也許是本人太菜
印度!一個不可輕視的近鄰!
From:http://tw.wingwit.com/Article/program/net/201311/13367.html