/// <summary>
/// Array 的摘要说明。
/// </summary>
public class Array
{
public Array()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
/// <summary>
/// 取得排序数组的最后一数+1
/// </summary>
/// <param name="table">数据表名</param>
/// <param name="strWhere">排序数组的筛选条件</param>
/// <returns>排序数组的最后一数+1</returns>
public static int GetNewLastArrayNum(string table,string strWhere)
{
if(strWhere != ""){strWhere = " Where " + strWhere;}
Database db = DatabaseFactory.CreateDatabase();
string sql="select max(Array) From " + table + strWhere;
IDataReader reader = db.ExecuteReader(CommandType.Text,sql);
if(reader.Read())
if(reader[0] != DBNull.Value)
return Convert.ToInt32(reader[0])+1;
else
return 1;
else
return 1;
}
/// <summary>
/// 更新数据表中的排列序号
/// </summary>
/// <param name="sqlTableName">数据表名</param>
/// <param name="strWhere">排序数组的筛选条件</param>
/// <param name="idFieldName">标识的列名,如ID</param>
/// <param name="id">当前触发时的ID</param>
/// <param name="array">当前触发时的排序值</param>
public static void UpArrayNum(string sqlTableName,string strWhere,string idFieldName,int id,int array)
{
string strWhereNow = "";
if(strWhere != ""){strWhereNow = " and " + strWhere;}
int newArray;
int newID;
string upSql="";
Database db = DatabaseFactory.CreateDatabase();
string sql="select " + idFieldName + ",Array From " + sqlTableName + " Where " + idFieldName + "<>" + id +
strWhereNow + " And Array="+array;
IDataReader reader = db.ExecuteReader(CommandType.Text,sql);
if(reader.Read())
{
upSql="UpDate " + sqlTableName + " Set Array=Array+1 Where " + idFieldName + "=" +
Convert.ToInt32(reader[idFieldName]) + strWhereNow;
newArray = Convert.ToInt32(reader["Array"])+1;
newID = Convert.ToInt32(reader[idFieldName]);
reader.Close();
db.ExecuteNonQuery(CommandType.Text,upSql);
UpArrayNum(sqlTableName,strWhere,idFieldName,newID,newArray);
}
else
{
reader.Close();
return;
}
}
}