You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
317 lines
10 KiB
317 lines
10 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using QMAPP.FJC.Entity.Basic;
|
|
using QMFrameWork.Data;
|
|
using QMFrameWork.Log;
|
|
using System.Data;
|
|
|
|
namespace QMAPP.FJC.DAL.Basic
|
|
{
|
|
public class CorpDAL
|
|
{
|
|
#region 获取信息
|
|
/// <summary>
|
|
/// 获取信息
|
|
/// </summary>
|
|
/// <param name="">条件</param>
|
|
/// <returns>信息</returns>
|
|
public Corp Get(Corp model)
|
|
{
|
|
try
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//获取信息
|
|
model = session.Get<Corp>(model);
|
|
}
|
|
return model;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogManager.LogHelper.Error(new LogInfo()
|
|
{
|
|
ErrorInfo = ex,
|
|
Tag = ex.StackTrace,
|
|
Info = "公司信息数据层-获取信息"
|
|
});
|
|
throw;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 获取列表
|
|
/// <summary>
|
|
/// 获取列表
|
|
/// </summary>
|
|
/// <param name="condition">条件</param>
|
|
/// <param name="page">数据页</param>
|
|
/// <returns>数据页</returns>
|
|
public DataPage GetList(Corp condition, DataPage page)
|
|
{
|
|
string sql = null;
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
sql = this.GetQuerySql(condition, ref parameters);
|
|
//分页关键字段及排序
|
|
page.KeyName = "PID";
|
|
page.SortExpression = "CORP_CODE DESC";
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
page = session.GetDataPage<Corp>(sql, parameters.ToArray(), page);
|
|
}
|
|
return page;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogManager.LogHelper.Error(new LogInfo()
|
|
{
|
|
ErrorInfo = ex,
|
|
Tag = ex.StackTrace,
|
|
Info = "公司信息数据层-获取列表"
|
|
});
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取列表
|
|
/// </summary>
|
|
/// <param name="condition">条件</param>
|
|
/// <returns>全部集合</returns>
|
|
public List<Corp> GetAllList(Corp condition)
|
|
{
|
|
List<Corp> list = new List<Corp>();
|
|
string sql = null;
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
sql = this.GetQuerySql(condition, ref parameters);
|
|
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
list = session.GetList<Corp>(sql, parameters.ToArray()).ToList();
|
|
}
|
|
return list;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogManager.LogHelper.Error(new LogInfo()
|
|
{
|
|
ErrorInfo = ex,
|
|
Tag = ex.StackTrace,
|
|
Info = "操作者数据层-获取区域列表"
|
|
});
|
|
throw;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 获取查询语句
|
|
/// <summary>
|
|
/// 获取查询语句
|
|
/// </summary>
|
|
/// <param name="user">查询条件</param>
|
|
/// <param name="parameters">参数</param>
|
|
/// <returns>查询语句</returns>
|
|
private string GetQuerySql(Corp condition, ref List<DataParameter> parameters)
|
|
{
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
StringBuilder whereBuilder = new StringBuilder();
|
|
try
|
|
{
|
|
//构成查询语句
|
|
sqlBuilder.AppendLine(" SELECT R.* ");
|
|
//sqlBuilder.AppendLine(" ,R.CORP_CODE ");
|
|
//sqlBuilder.AppendLine(" ,R.CORP_NAME ");
|
|
//sqlBuilder.AppendLine(" ,R.CORP_SHORT ");
|
|
//sqlBuilder.AppendLine(" ,R.REMARK ");
|
|
//sqlBuilder.AppendLine(" ,R.CREATEUSER ");
|
|
//sqlBuilder.AppendLine(" ,R.CREATEDATE ");
|
|
//sqlBuilder.AppendLine(" ,R.UPDATEUSER ");
|
|
//sqlBuilder.AppendLine(" ,R.UPDATEDATE ");
|
|
sqlBuilder.AppendLine(" ,C.USERNAME AS CREATEUSERNAME ");
|
|
sqlBuilder.AppendLine(" ,U.USERNAME AS UPDATEUSERNAME ");
|
|
sqlBuilder.AppendLine(" FROM T_MD_CORP R ");
|
|
sqlBuilder.AppendLine(" LEFT JOIN T_QM_USER C ON C.USERID=R.CREATEUSER ");
|
|
sqlBuilder.AppendLine(" LEFT JOIN T_QM_USER U ON U.USERID=R.UPDATEUSER ");
|
|
|
|
//查询条件
|
|
if (string.IsNullOrEmpty(condition.CORP_CODE) == false)
|
|
{
|
|
whereBuilder.Append(" AND CORP_CODE = @CORP_CODE ");
|
|
parameters.Add(new DataParameter { ParameterName = "CORP_CODE", DataType = DbType.String, Value = condition.CORP_CODE });
|
|
}
|
|
if (string.IsNullOrEmpty(condition.CORP_NAME) == false)
|
|
{
|
|
whereBuilder.Append(" AND CORP_NAME = @CORP_NAME ");
|
|
parameters.Add(new DataParameter { ParameterName = "CORP_NAME", DataType = DbType.String, Value = condition.CORP_NAME });
|
|
}
|
|
if (whereBuilder.Length > 0)
|
|
{
|
|
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
|
|
}
|
|
return sqlBuilder.ToString();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 信息是否重复
|
|
/// <summary>
|
|
/// 判断名称是否存在
|
|
/// </summary>
|
|
/// <param name="info"></param>
|
|
/// <returns>true:已存在;fasel:不存在。</returns>
|
|
public bool ExistsCorp(Corp model)
|
|
{
|
|
string PID = "";
|
|
int count = 0;
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
|
|
try
|
|
{
|
|
if (string.IsNullOrEmpty(model.PID) == false)
|
|
{
|
|
PID = model.PID;
|
|
}
|
|
sqlBuilder.AppendLine("SELECT COUNT(*) FROM T_MD_CORP ");
|
|
sqlBuilder.AppendLine(" WHERE PID <> @PID AND CORP_CODE=@CORP_CODE");
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
count = Convert.ToInt32(session.ExecuteSqlScalar(sqlBuilder.ToString(),
|
|
new DataParameter("PID", PID),
|
|
new DataParameter { ParameterName = "CORP_CODE", Value = model.CORP_CODE }));
|
|
}
|
|
if (count > 0)
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 插入信息
|
|
/// <summary>
|
|
/// 插入信息(单表)
|
|
/// </summary>
|
|
/// <param name="">信息</param>
|
|
/// <returns>插入行数</returns>
|
|
public int Insert(Corp model)
|
|
{
|
|
int count = 0;
|
|
try
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//插入基本信息
|
|
count = session.Insert<Corp>(model);
|
|
}
|
|
return count;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 更新信息
|
|
/// <summary>
|
|
/// 更新信息
|
|
/// </summary>
|
|
/// <param name=""></param>
|
|
/// <returns>更新行数</returns>
|
|
public int Update(Corp model)
|
|
{
|
|
int count = 0;
|
|
try
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//更新基本信息
|
|
count = session.Update<Corp>(model);
|
|
}
|
|
return count;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 删除
|
|
/// <summary>
|
|
/// 删除信息
|
|
/// </summary>
|
|
/// <param name=""></param>
|
|
/// <returns>删除个数</returns>
|
|
//提交事务
|
|
public int Delete(Corp model)
|
|
{
|
|
int count = 0;
|
|
try
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//删除基本信息
|
|
count = session.Delete<Corp>(model);
|
|
}
|
|
return count;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 获取公司下拉列表
|
|
/// <summary>
|
|
/// 获取公司列表(下拉列表数据源)
|
|
/// </summary>
|
|
/// <param name="condition">条件</param>
|
|
/// <returns>全部集合</returns>
|
|
public List<Corp> GetCorpList(Corp condition)
|
|
{
|
|
List<Corp> list = new List<Corp>();
|
|
string sql = null;
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
sql = this.GetQuerySql(condition, ref parameters);
|
|
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
list = session.GetList<Corp>(sql, parameters.ToArray()).ToList();
|
|
}
|
|
return list;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogManager.LogHelper.Error(new LogInfo()
|
|
{
|
|
ErrorInfo = ex,
|
|
Tag = ex.StackTrace,
|
|
Info = "公司信息-获取公司列表"
|
|
});
|
|
throw;
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
}
|
|
|