天津投入产出系统后端
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.

200 lines
6.2 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QMAPP.MD.Entity;
using QMFrameWork.Data;
using QMFrameWork.Log;
using System.Data;
using QMAPP.DAL;
namespace QMAPP.MD.DAL
{
/// <summary>
/// 模块名称:公司
/// 作 者:郭兆福
/// 编写日期:2017年05月05日
/// </summary>
public class CorpDAL : BaseDAL
{
#region 获取信息
/// <summary>
/// 获取信息
/// </summary>
/// <returns>信息</returns>
public Corp Get()
{
Corp model;
try
{
StringBuilder sqlBuilder = new StringBuilder();
sqlBuilder.AppendLine(" SELECT TOP 1 R.PID ");
sqlBuilder.AppendLine(" ,R.CORP_CODE ");
sqlBuilder.AppendLine(" ,R.CORP_CODE AS CORP_CODE_OLD");
sqlBuilder.AppendLine(" ,R.CORP_NAME ");
sqlBuilder.AppendLine(" ,R.CORP_SHORT ");
sqlBuilder.AppendLine(" ,R.Siteid ");
sqlBuilder.AppendLine(" ,R.Orgid ");
sqlBuilder.AppendLine(" ,R.REMARK ");
sqlBuilder.AppendLine(" ,R.CREATEUSER ");
sqlBuilder.AppendLine(" ,R.CREATEDATE ");
sqlBuilder.AppendLine(" ,R.UPDATEUSER ");
sqlBuilder.AppendLine(" ,R.UPDATEDATE ");
sqlBuilder.AppendLine(" FROM T_MD_CORP R ");
List<DataParameter> para = new List<DataParameter>();
using (IDataSession session = AppDataFactory.CreateMainSession())
{
// 对应多种数据库
string sqlChange = this.ChangeSqlByDB(sqlBuilder.ToString(), session);
//获取信息
model = session.Get<Corp>(sqlChange, para.ToArray());
}
return null == model ? new Corp() : model;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "公司信息数据层-获取信息" );
throw ex;
}
}
#endregion
#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)
{
RecordExceptionLog(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>
/// <returns>true:已存在;false:不存在。</returns>
public bool ExistsCorp()
{
int count = 0;
StringBuilder sqlBuilder = new StringBuilder();
try
{
List<DataParameter> para = new List<DataParameter>();
sqlBuilder.AppendLine("SELECT COUNT(*) FROM T_MD_CORP ");
using (IDataSession session = AppDataFactory.CreateMainSession())
{
count = Convert.ToInt32(session.ExecuteSqlScalar(sqlBuilder.ToString(), para.ToArray()));
}
return count == 0 ? false : true;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 判断公司下边是否有工厂
/// <summary>
/// 判断公司下边是否有工厂
/// </summary>
/// <param name="sorpCode">公司编码</param>
/// <returns>true:使用 false:未使用</returns>
public bool IsCorpUsed(string corpCode)
{
int count = 0;
StringBuilder sqlBuilder = new StringBuilder();
try
{
sqlBuilder.AppendLine("SELECT COUNT(*) FROM T_MD_FACTORY ");
sqlBuilder.AppendLine(" WHERE CORP_CODE=@CORP_CODE AND FLGDEL = '0'");
using (IDataSession session = AppDataFactory.CreateMainSession())
{
// 对应多种数据库
string sqlChange = this.ChangeSqlByDB(sqlBuilder.ToString(), session);
count = Convert.ToInt32(session.ExecuteSqlScalar(sqlChange,
new DataParameter { ParameterName = "CORP_CODE", Value = corpCode }));
}
return count == 0 ? false : true;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
}
}