using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using QMFrameWork.Data;
using QMAPP.Entity.Sys;
namespace QMAPP.DAL.Sys
{
///
/// 模块编号:
/// 作 用:在线帮助持久层
/// 作 者:韩磊
/// 编写日期:2014年12月22日
///
public class OnlineHelpDAL :BaseDAL
{
#region 获取页面级帮助
///
/// 获取页面级帮助
///
/// 条件
/// 页面级帮助对象
public OnlineHelp Get(OnlineHelp helpInfo)
{
try
{
List ret= GetList(helpInfo);
if (ret.Count > 0)
{
helpInfo = ret[0];
}
return helpInfo;
}
catch (Exception ex)
{
throw;
}
}
#endregion
#region 插入在线帮助信息
///
/// 插入在线帮助信息
///
/// 在线帮助信息
/// 插入数
public int Insert(OnlineHelp helpInfo)
{
int count = 0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//插入基本信息
StringBuilder sql = new StringBuilder();
sql.Append("INSERT INTO T_QM_ONLINEHELP (PID,MENUID,PAGENAME,MODELNAME,COLUMNANME,KIND,HELPCONTENT)");
sql.Append("VALUES (@PID,@MENUID,@PAGENAME,@MODELNAME,@COLUMNANME,@KIND,@HELPCONTENT)");
List parameters = new List();
parameters.Add(new DataParameter { ParameterName = "PID", DataType = DbType.String, Value = helpInfo.PID });
parameters.Add(new DataParameter { ParameterName = "MENUID", DataType = DbType.String, Value = helpInfo.MENUID });
parameters.Add(new DataParameter { ParameterName = "PAGENAME", DataType = DbType.String, Value = helpInfo.PAGENAME });
parameters.Add(new DataParameter { ParameterName = "MODELNAME", DataType = DbType.String, Value = helpInfo.MODELNAME });
parameters.Add(new DataParameter { ParameterName = "COLUMNANME", DataType = DbType.String, Value = helpInfo.COLUMNANME });
parameters.Add(new DataParameter { ParameterName = "KIND", DataType = DbType.String, Value = helpInfo.KIND });
//parameters.Add(new DataParameter { ParameterName = "HELPCONTENT", Value = Encoding.Default.GetBytes(helpInfo.HELPCONTENT) });
parameters.Add(new DataParameter { ParameterName = "HELPCONTENT", Value = helpInfo.HELPCONTENT });
count=session.ExecuteSql(sql.ToString(), parameters.ToArray());
}
return count;
}
catch (Exception ex)
{
throw;
}
}
#endregion
#region 更新在线帮助信息
///
/// 更新在线帮助信息
///
/// 锁定信息
/// 更新个数
public int Update(OnlineHelp helpInfo)
{
int count = 0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//更新基本信息
StringBuilder sql = new StringBuilder();
sql.Append("UPDATE T_QM_ONLINEHELP SET HELPCONTENT=@HELPCONTENT ,MODELNAME=@MODELNAME ,PAGENAME=@PAGENAME WHERE PID=@PID");
List parameters = new List();
parameters.Add(new DataParameter { ParameterName = "PID", DataType = DbType.String, Value = helpInfo.PID });
//parameters.Add(new DataParameter { ParameterName = "HELPCONTENT", Value =Encoding.Default.GetBytes(helpInfo.HELPCONTENT) });
parameters.Add(new DataParameter { ParameterName = "HELPCONTENT", Value = helpInfo.HELPCONTENT });
parameters.Add(new DataParameter { ParameterName = "MODELNAME", DataType = DbType.String, Value = helpInfo.MODELNAME });
parameters.Add(new DataParameter { ParameterName = "PAGENAME", DataType = DbType.String, Value = helpInfo.PAGENAME });
count=session.ExecuteSql(sql.ToString(), parameters.ToArray());
}
return count;
}
catch (Exception ex)
{
throw;
}
}
#endregion
#region 获取字段级帮助集合
///
/// 获取字段级帮助集合
///
/// 条件
/// 数据页
/// 数据页
public List GetList(OnlineHelp condition)
{
string sql = null;
List parameters = new List();
List ret = new List();
DataTable dt = new DataTable();
try
{
sql = this.GetQuerySql(condition, ref parameters);
using (IDataSession session = AppDataFactory.CreateMainSession())
{
dt = session.GetTable(sql, parameters.ToArray());
}
if (dt != null && dt.Rows.Count > 0)
{
foreach (DataRow item in dt.Rows)
{
OnlineHelp helpInfo = new OnlineHelp();
helpInfo.PID = item["PID"].ToString();
helpInfo.KIND = item["KIND"].ToString();
helpInfo.MODELNAME = item["MODELNAME"].ToString();
helpInfo.PAGENAME = item["PAGENAME"].ToString();
helpInfo.COLUMNANME = item["COLUMNANME"].ToString();
if (!(item["HELPCONTENT"] is DBNull))
{
string content = item["HELPCONTENT"].ToString();
helpInfo.HELPCONTENT = content;
}
helpInfo.MENUID = item["MENUID"].ToString();
ret.Add(helpInfo);
}
}
return ret;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取查询语句
///
/// 获取查询语句
///
/// 查询条件
/// 参数
/// 查询语句
private string GetQuerySql(OnlineHelp condition, ref List parameters)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
try
{
//构成查询语句
sqlBuilder.Append("SELECT PID,MENUID,PAGENAME,MODELNAME,COLUMNANME,KIND,HELPCONTENT ");
sqlBuilder.Append("FROM T_QM_ONLINEHELP ");
// 查询条件
if (string.IsNullOrEmpty(condition.MENUID) == false)
{
whereBuilder.Append(" AND MENUID = @MENUID");
parameters.Add(new DataParameter { ParameterName = "MENUID", DataType = DbType.String, Value = condition.MENUID });
}
if (string.IsNullOrEmpty(condition.KIND) == false)
{
whereBuilder.Append(" AND KIND = @KIND");
parameters.Add(new DataParameter { ParameterName = "KIND", DataType = DbType.String, Value = condition.KIND });
}
if (whereBuilder.Length > 0)
{
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
}
return sqlBuilder.ToString();
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 更新在线帮助信息
///
/// 更新在线帮助信息
///
/// 在线帮助信息集合
/// 更新个数
public int Save(List helpInfos)
{
int count = 0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
session.OpenTs();
foreach (OnlineHelp item in helpInfos)
{
if (string.IsNullOrEmpty(item.PID) == true)
{
item.PID = Guid.NewGuid().ToString();
count=Insert(item);
}
else
{
count= Update(item);
}
}
session.CommitTs();
}
return count;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
}
}