/// <summary> /// 下移记录的方法 /// </summary> /// <param name="dbHelper">当前数据库连接</param> /// <param name="tableName">表名</param> /// <param name="categoryId">类别主键</param> /// <param name="id">当前主键</param> /// <returns>目标主键</returns> public static int SetDown(IDbHelper dbHelper, string tableName, string categoryId, string id) { string downId = string.Empty; string sortCode = string.Empty; string downSortCode = string.Empty; int returnValue = 0; downId = GetDownId(dbHelper, tableName, categoryId, id); if (downId.Length == 0) { return(returnValue); } List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >(); parameters.Add(new KeyValuePair <string, object>(BaseBusinessLogic.FieldId, id)); sortCode = DbLogic.GetProperty(dbHelper, tableName, parameters, BaseBusinessLogic.FieldSortCode); parameters = new List <KeyValuePair <string, object> >(); parameters.Add(new KeyValuePair <string, object>(BaseBusinessLogic.FieldId, downId)); downSortCode = DbLogic.GetProperty(dbHelper, tableName, parameters, BaseBusinessLogic.FieldSortCode); List <KeyValuePair <string, object> > whereParameters = new List <KeyValuePair <string, object> >(); whereParameters.Add(new KeyValuePair <string, object>(BaseBusinessLogic.FieldId, downId)); parameters = new List <KeyValuePair <string, object> >(); parameters.Add(new KeyValuePair <string, object>(BaseBusinessLogic.FieldSortCode, sortCode)); DbLogic.SetProperty(dbHelper, tableName, whereParameters, parameters); whereParameters = new List <KeyValuePair <string, object> >(); whereParameters.Add(new KeyValuePair <string, object>(BaseBusinessLogic.FieldId, id)); parameters = new List <KeyValuePair <string, object> >(); parameters.Add(new KeyValuePair <string, object>(BaseBusinessLogic.FieldSortCode, downSortCode)); returnValue = DbLogic.SetProperty(dbHelper, tableName, whereParameters, parameters); return(returnValue); }
// // 设置属性 // public virtual int SetProperty(KeyValuePair <string, object> parameter) { List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >(); parameters.Add(parameter); return(DbLogic.SetProperty(DbHelper, this.CurrentTableName, null, parameters)); }
public const string CommandSwap = "Swap"; // 交换排序方法命名定义 // // 排序操作针对数据库的运算方式定义(好用高效的排序顺序设定方法) // #region public static int SetTop(IDbHelper dbHelper, string tableName, string id) 置顶排序命令 /// <summary> /// 置顶排序方法 /// </summary> /// <param name="dbHelper">当前数据库连接</param> /// <param name="tableName">表名</param> /// <param name="id">主键</param> /// <returns>影响行数</returns> public static int SetTop(IDbHelper dbHelper, string tableName, string id) { BaseSequenceManager sequenceManager = new BaseSequenceManager(dbHelper); string sequence = sequenceManager.GetReduction(tableName); List <KeyValuePair <string, object> > whereParameters = new List <KeyValuePair <string, object> >(); whereParameters.Add(new KeyValuePair <string, object>(BaseBusinessLogic.FieldId, id)); List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >(); parameters.Add(new KeyValuePair <string, object>(BaseBusinessLogic.FieldSortCode, sequence)); return(DbLogic.SetProperty(dbHelper, tableName, whereParameters, parameters)); }
public static int SetBottom(IDbHelper dbHelper, string tableName, string id, string sequenceName) { if (String.IsNullOrEmpty(sequenceName)) { sequenceName = tableName; } BaseSequenceManager sequenceManager = new BaseSequenceManager(dbHelper); string sequence = sequenceManager.GetSequence(sequenceName); List <KeyValuePair <string, object> > whereParameters = new List <KeyValuePair <string, object> >(); whereParameters.Add(new KeyValuePair <string, object>(BaseBusinessLogic.FieldId, id)); List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >(); parameters.Add(new KeyValuePair <string, object>(BaseBusinessLogic.FieldSortCode, sequence)); return(DbLogic.SetProperty(dbHelper, tableName, whereParameters, parameters)); }
/// <summary> /// 交换排序方法 /// </summary> /// <param name="dbHelper">当前数据库连接</param> /// <param name="tableName">表名</param> /// <param name="id">记录主键</param> /// <param name="targetId">目标记录主键</param> /// <returns>影响行数</returns> public static int Swap(IDbHelper dbHelper, string tableName, string id, string targetId) { int returnValue = 0; // 要移动的主键的排序码 List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >(); parameters.Add(new KeyValuePair <string, object>(BaseBusinessLogic.FieldId, id)); string sortCode = DbLogic.GetProperty(dbHelper, tableName, parameters, BaseBusinessLogic.FieldSortCode); // 目标主键的排序码 parameters = new List <KeyValuePair <string, object> >(); parameters.Add(new KeyValuePair <string, object>(BaseBusinessLogic.FieldId, targetId)); string targetSortCode = DbLogic.GetProperty(dbHelper, tableName, parameters, BaseBusinessLogic.FieldSortCode); // 以下方法,在MySQL里不能正常运行,虽然效率是很高 // 设置要移动的主键的排序码(注:少读取数据库一次,提高主键运行效率) // string sqlQuery = " UPDATE " + tableName // + " SET " + BaseBusinessLogic.FieldSortCode + " = (SELECT " + BaseBusinessLogic.FieldSortCode // + " FROM " + tableName // + " WHERE " + BaseBusinessLogic.FieldId + " = '" + targetId + "') " // + " WHERE " + BaseBusinessLogic.FieldId + " = '" + Id + "' "; // returnValue = DbHelper.ExecuteNonQuery(sqlQuery); List <KeyValuePair <string, object> > whereParameters = new List <KeyValuePair <string, object> >(); whereParameters.Add(new KeyValuePair <string, object>(BaseBusinessLogic.FieldId, id)); parameters = new List <KeyValuePair <string, object> >(); parameters.Add(new KeyValuePair <string, object>(BaseBusinessLogic.FieldSortCode, targetSortCode)); // 设置目标主键的排序码 returnValue += DbLogic.SetProperty(dbHelper, tableName, whereParameters, parameters); whereParameters = new List <KeyValuePair <string, object> >(); whereParameters.Add(new KeyValuePair <string, object>(BaseBusinessLogic.FieldId, targetId)); parameters = new List <KeyValuePair <string, object> >(); parameters.Add(new KeyValuePair <string, object>(BaseBusinessLogic.FieldSortCode, sortCode)); // 设置目标主键的排序码 returnValue += DbLogic.SetProperty(dbHelper, tableName, whereParameters, parameters); return(returnValue); }
public virtual int SetProperty(List <KeyValuePair <string, object> > whereParameters, List <KeyValuePair <string, object> > parameters) { return(DbLogic.SetProperty(DbHelper, this.CurrentTableName, whereParameters, parameters)); }