using System; using System.Data; using System.Collections.Generic; using System.Linq; using System.Text; using QMFrameWork.Data; using QMAPP.Entity.Sys; namespace QMAPP.DAL.Sys { /// /// 桌面快捷方式数据层对象 /// 创建者:李炳海 /// 创建日期:2015.2.25 /// public class DeskTopItemDAL:BaseDAL { #region 根据桌面布局信息 /// /// 根据桌面布局信息 /// /// 用户ID /// 桌面布局信息集合 public List GetList(string userID) { List parameters = new List(); string sql = @"SELECT PID,USERID,MENUID,SORT FROM T_QM_DESKTOPITEM WHERE USERID = @USERID ORDER BY SORT ASC"; parameters.Add(new DataParameter { ParameterName = "USERID", DataType = DbType.String, Value = userID }); try { using (IDataSession session = AppDataFactory.CreateMainSession()) { sql = base.ChangeSqlByDB(sql, session); return session.GetList(sql, parameters.ToArray()).ToList(); } } catch (Exception ex) { throw ex; } } #endregion #region 获取最大值序号 /// /// 获取最大值序号 /// /// 用户主键 /// 最大值序号 public int GetMaxSort(string userID) { string sql = "SELECT MAX(SORT) FROM T_QM_DESKTOPITEM WHERE USERID = @USERID"; int count = 0; object value; try { using (IDataSession session = AppDataFactory.CreateMainSession()) { sql = base.ChangeSqlByDB(sql, session); value=session.ExecuteSqlScalar(sql,new DataParameter("USERID",userID)); if (value!=System.DBNull.Value) { count=int.Parse(value.ToString()); } } return count; } catch (Exception ex) { throw ex; } } #endregion #region 添加 /// /// 添加 /// /// 信息 /// 插入行数 public int Insert(DeskTopItem info) { int count = 0; try { using (IDataSession session = AppDataFactory.CreateMainSession()) { count = session.Insert(info); } return count; } catch (Exception ex) { throw ex; } } #endregion #region 交换序号 /// /// 交换序号 /// /// 用户主键 /// 主键1 /// 主键2 public void ExchangeSort(string userID, string id1, string id2) { DeskTopItem item1 = new DeskTopItem(); DeskTopItem item2 = new DeskTopItem(); int sort = 0; string sql = ""; item1.PID = id1; item2.PID = id2; try { using (IDataSession session = AppDataFactory.CreateMainSession()) { //获取基本信息 sql = "SELECT * FROM T_QM_DESKTOPITEM WHERE USERID = @USERID AND MENUID = @MENUID"; sql = this.ChangeSqlByDB(sql, session); item1 = session.Get(sql, new DataParameter("USERID", userID), new DataParameter("MENUID",id1)); item2 = session.Get(sql, new DataParameter("USERID", userID), new DataParameter("MENUID", id2)); //交换序号 sort = item1.SORT; item1.SORT = item2.SORT; item2.SORT = sort; //更新 session.Update(item1); session.Update(item2); } } catch (Exception ex) { throw ex; } } #endregion #region 删除 /// /// 删除 /// /// 主键 /// 删除个数 public int Delete(string userID,string id) { int count = 0; string sql = ""; try { sql = "DELETE FROM T_QM_DESKTOPITEM WHERE USERID = @USERID AND MENUID = @MENUID"; using (IDataSession session = AppDataFactory.CreateMainSession()) { sql = this.ChangeSqlByDB(sql, session); count = session.ExecuteSql(sql, new DataParameter("USERID", userID), new DataParameter("MENUID", id)); } return count; } catch (Exception ex) { throw ex; } } #endregion } }