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.
646 lines
23 KiB
646 lines
23 KiB
4 years ago
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Linq;
|
||
|
using System.Text;
|
||
|
using System.Data;
|
||
|
using QMFrameWork.Data;
|
||
|
using QMAPP.Entity.Sys;
|
||
|
using QMAPP.Entity.Sys.Entity;
|
||
|
|
||
|
namespace QMAPP.DAL.Sys
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// 组织机构管理
|
||
|
/// 创建者:郭佳伟
|
||
|
/// 创建日期:2013.1.16
|
||
|
/// </summary>
|
||
|
public class OrgaizationManageDAL : BaseDAL
|
||
|
{
|
||
|
|
||
|
#region 获取组织机构列表
|
||
|
|
||
|
/// <summary>
|
||
|
/// 获取组织机构列表
|
||
|
/// </summary>
|
||
|
/// <param name="condition">条件</param>
|
||
|
/// <param name="page">数据页</param>
|
||
|
/// <returns>数据页</returns>
|
||
|
public DataPage GetList(Orgaization condition, DataPage page)
|
||
|
{
|
||
|
StringBuilder sqlBuilder = new StringBuilder();
|
||
|
StringBuilder whereBuilder = new StringBuilder();
|
||
|
List<DataParameter> parameters = new List<DataParameter>();
|
||
|
string sql = null;
|
||
|
try
|
||
|
{
|
||
|
sqlBuilder.Append("SELECT A.ORGAID,A.ORGADESC,A.ORGAPARENT,A.ACTIVATEFLG,U1.USERNAME AS CREATEUSER,A.CREATEDATE,U2.USERNAME AS UPDATEUSER,A.UPDATEDATE,");
|
||
|
sqlBuilder.Append("A.FLGDEL,(SELECT ORGADESC FROM T_QM_ORGANIZATION WHERE ORGAID = A.ORGAPARENT) AS ORGAPARENTDESC ");
|
||
|
sqlBuilder.Append(" FROM T_QM_ORGANIZATION A,T_QM_USER U1,T_QM_USER U2 WHERE A.CREATEUSER = U1.USERID AND A.UPDATEUSER = U2.USERID ");
|
||
|
sqlBuilder.Append(" AND A.FLGDEL = '0' ");
|
||
|
//查询条件
|
||
|
if (string.IsNullOrEmpty(condition.OrgaDESC) == false)
|
||
|
{
|
||
|
whereBuilder.Append(" AND A.ORGADESC = @ORGADESC");
|
||
|
parameters.Add(new DataParameter { ParameterName = "ORGADESC", DataType = DbType.String, Value = condition.OrgaDESC });
|
||
|
}
|
||
|
|
||
|
if (whereBuilder.Length > 0)
|
||
|
{
|
||
|
sqlBuilder.Append(whereBuilder.ToString());
|
||
|
}
|
||
|
|
||
|
//分页关键字段及排序
|
||
|
page.KeyName = "ORGAID";
|
||
|
if (string.IsNullOrEmpty(page.SortExpression))
|
||
|
{
|
||
|
page.SortExpression = "UPDATEDATE DESC";
|
||
|
}
|
||
|
if (page.SortExpression.IndexOf("CreateTime") > -1)
|
||
|
{
|
||
|
page.SortExpression = page.SortExpression.Replace("CreateTime", "CREATEDATE");
|
||
|
}
|
||
|
if (page.SortExpression.IndexOf("UpdateTime") > -1)
|
||
|
{
|
||
|
page.SortExpression = page.SortExpression.Replace("UpdateTime", "UPDATEDATE");
|
||
|
}
|
||
|
|
||
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
||
|
{
|
||
|
sql = this.ChangeSqlByDB(sqlBuilder.ToString(), session);
|
||
|
page = session.GetDataPage<Orgaization>(sql, parameters.ToArray(), page);
|
||
|
}
|
||
|
|
||
|
return page;
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
throw;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
#region 获取组织机构信息
|
||
|
|
||
|
/// <summary>
|
||
|
/// 获取组织机构信息
|
||
|
/// </summary>
|
||
|
/// <param name="orga">条件</param>
|
||
|
/// <returns>组织机构信息</returns>
|
||
|
public Orgaization Get(Orgaization orga)
|
||
|
{
|
||
|
string sql = null;
|
||
|
List<DataParameter> parameters = new List<DataParameter>();
|
||
|
Orgaization tmporga = new Orgaization();
|
||
|
try
|
||
|
{
|
||
|
//获取用户信息
|
||
|
sql = @"SELECT ORGAID,ORGADESC,ORGAPARENT,ACTIVATEFLG,CREATEUSER,CREATEDATE,UPDATEUSER,UPDATEDATE,FLGDEL,
|
||
|
(SELECT ORGADESC FROM T_QM_ORGANIZATION WHERE ORGAID = A.ORGAPARENT) AS ORGAPARENTDESC FROM T_QM_ORGANIZATION A WHERE ORGAID=@ORGAID";
|
||
|
parameters.Add(new DataParameter { ParameterName = "ORGAID", DataType = DbType.String, Value = orga.OrgaID });
|
||
|
|
||
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
||
|
{
|
||
|
sql = this.ChangeSqlByDB(sql, session);
|
||
|
tmporga = session.Get<Orgaization>(sql, parameters.ToArray());
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
return tmporga;
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
throw;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 获取机构角色
|
||
|
/// </summary>
|
||
|
/// <param name="organ">获取条件</param>
|
||
|
/// <returns>机构角色</returns>
|
||
|
public Orgaization GetOrganRoleList(Orgaization organ)
|
||
|
{
|
||
|
string sql = null;
|
||
|
List<DataParameter> parameters = new List<DataParameter>();
|
||
|
try
|
||
|
{
|
||
|
sql = "SELECT * FROM T_QM_ORGANROLE WHERE ORGANID = @ORGANID";
|
||
|
parameters.Add(new DataParameter("ORGANID",organ.OrgaID));
|
||
|
|
||
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
||
|
{
|
||
|
sql = this.ChangeSqlByDB(sql, session);
|
||
|
organ.RoleList = session.GetList<T_QM_ORGANROLE>(sql, parameters.ToArray()).ToList();
|
||
|
}
|
||
|
|
||
|
return organ;
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
throw;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
#region 组织机构编号是否重复
|
||
|
|
||
|
/// <summary>
|
||
|
/// 判断组织机构编号是否重复
|
||
|
/// </summary>
|
||
|
/// <param name="orga">组织机构信息</param>
|
||
|
/// <returns>true:已存在;fasel:不存在。</returns>
|
||
|
public bool ExistsOrga(Orgaization orga)
|
||
|
{
|
||
|
string OrgaID = "";
|
||
|
int count = 0;
|
||
|
string sql = null;
|
||
|
List<DataParameter> parameters = new List<DataParameter>();
|
||
|
try
|
||
|
{
|
||
|
if (string.IsNullOrEmpty(orga.OrgaID) == false)
|
||
|
{
|
||
|
OrgaID = orga.OrgaID;
|
||
|
}
|
||
|
|
||
|
if (orga.IsUpdate == true)
|
||
|
{
|
||
|
sql = "SELECT COUNT(*) FROM T_QM_ORGANIZATION WHERE ORGAID <> @ORGAID AND ORGADESC=@ORGADESC";
|
||
|
parameters.Add(new DataParameter("ORGAID", orga.OrgaID));
|
||
|
parameters.Add(new DataParameter("ORGADESC", orga.OrgaDESC));
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
sql = "SELECT COUNT(*) FROM T_QM_ORGANIZATION WHERE ORGAID = @ORGAID OR ORGADESC=@ORGADESC";
|
||
|
parameters.Add(new DataParameter("ORGAID", orga.OrgaID));
|
||
|
parameters.Add(new DataParameter("ORGADESC", orga.OrgaDESC));
|
||
|
}
|
||
|
|
||
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
||
|
{
|
||
|
sql = this.ChangeSqlByDB(sql, session);
|
||
|
count = int.Parse(session.ExecuteSqlScalar(sql, parameters.ToArray()).ToString());
|
||
|
}
|
||
|
|
||
|
if (count > 0)
|
||
|
{
|
||
|
return true;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
throw;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
#region 获取组织机构所有的权限
|
||
|
|
||
|
/// <summary>
|
||
|
/// 获取组织机构所有的权限
|
||
|
/// </summary>
|
||
|
/// <param name="condition">条件</param>
|
||
|
/// <returns>同级别菜单列表</returns>
|
||
|
public Orgaization GetOrgaAuthorityList(Orgaization orga)
|
||
|
{
|
||
|
Orgaization list = new Orgaization();
|
||
|
List<DataParameter> parameters = new List<DataParameter>();
|
||
|
string sql = null;
|
||
|
try
|
||
|
{
|
||
|
sql = "SELECT * FROM T_QM_ORGAIZATIONAUTHORITY WHERE ORGAID=@ORGAID";
|
||
|
parameters.Add(new DataParameter { ParameterName = "ORGAID", DataType = DbType.String, Value = orga.OrgaID });
|
||
|
|
||
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
||
|
{
|
||
|
sql = this.ChangeSqlByDB(sql, session);
|
||
|
list.OrgaAuthorityList = session.GetList<OrgaizationAuthority>(sql, parameters.ToArray()).ToList();
|
||
|
}
|
||
|
|
||
|
return list;
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
throw;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
#region 获取组织机构树菜单列表
|
||
|
|
||
|
/// <summary>
|
||
|
/// 获取同一级别的所有组织机构树菜单列表
|
||
|
/// </summary>
|
||
|
/// <param name="condition">条件</param>
|
||
|
/// <returns>同级别菜单列表</returns>
|
||
|
public List<Orgaization> GetSubTreeList(Orgaization orga)
|
||
|
{
|
||
|
List<DataParameter> parameters = new List<DataParameter>();
|
||
|
List<Orgaization> list = null;
|
||
|
string sql = null;
|
||
|
try
|
||
|
{
|
||
|
sql = "SELECT * FROM T_QM_ORGANIZATION WHERE DELFLAG='0' AND ORGAPARENT=@ORGAPARENT";
|
||
|
parameters.Add(new DataParameter { ParameterName = "ORGAPARENT", DataType = DbType.String, Value = orga.OrgaParent });
|
||
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
||
|
{
|
||
|
sql = this.ChangeSqlByDB(sql, session);
|
||
|
list = session.GetList<Orgaization>(sql, parameters.ToArray()).ToList();
|
||
|
}
|
||
|
|
||
|
return list;
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
throw;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
#region 获取组织机构树菜单列表
|
||
|
|
||
|
/// <summary>
|
||
|
/// 获取所有组织机构树菜单列表
|
||
|
/// </summary>
|
||
|
/// <param name="condition">条件</param>
|
||
|
/// <returns>同级别菜单列表</returns>
|
||
|
public List<Orgaization> GetAllList()
|
||
|
{
|
||
|
List<DataParameter> parameters = new List<DataParameter>();
|
||
|
List<Orgaization> list = null;
|
||
|
string sql = null;
|
||
|
try
|
||
|
{
|
||
|
sql = "SELECT * FROM T_QM_ORGANIZATION WHERE FLGDEL='0'";
|
||
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
||
|
{
|
||
|
list = session.GetList<Orgaization>(sql, parameters.ToArray()).ToList();
|
||
|
}
|
||
|
|
||
|
return list;
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
throw;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
#region 插入组织机构与人员信息
|
||
|
|
||
|
/// <summary>
|
||
|
/// 插入组织机构与人员信息
|
||
|
/// </summary>
|
||
|
/// <param name="orga">组织机构与人员信息</param>
|
||
|
/// <returns>插入数</returns>
|
||
|
public int InsertOrgaUser(UserOrgaization orga)
|
||
|
{
|
||
|
int count = 0;
|
||
|
UserOrgaization insertUserOrga = new UserOrgaization();
|
||
|
try
|
||
|
{
|
||
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
||
|
{
|
||
|
session.OpenTs();
|
||
|
|
||
|
string[] userlist = orga.UserID.Split(new Char[]{ ',' });
|
||
|
insertUserOrga = orga;
|
||
|
for(int i = 0 ;i<userlist.Length;i++){
|
||
|
//插入基本信息
|
||
|
insertUserOrga.UserID = userlist[i].Split(new Char[] { '|' })[0];
|
||
|
insertUserOrga.IsMainOgra = userlist[i].Split(new Char[] { '|' })[1];
|
||
|
session.Insert<UserOrgaization>(orga);
|
||
|
}
|
||
|
|
||
|
|
||
|
session.CommitTs();
|
||
|
}
|
||
|
return count;
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
throw;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
#region 删除组织机构与人员信息
|
||
|
|
||
|
/// <summary>
|
||
|
/// 删除组织机构信息
|
||
|
/// </summary>
|
||
|
/// <param name="orga">组织机构信息</param>
|
||
|
/// <returns>删除个数</returns>
|
||
|
public int DeleteOrgaUser(UserOrgaization orga)
|
||
|
{
|
||
|
int count = 0;
|
||
|
string sql = null;
|
||
|
List<DataParameter> parameters = new List<DataParameter>();
|
||
|
try
|
||
|
{
|
||
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
||
|
{
|
||
|
session.OpenTs();
|
||
|
|
||
|
//先删除改人员所在组织机构的所有权限信息
|
||
|
sql = "DELETE T_QM_USERAUTHORITY WHERE ORGAID=@ORGAID AND USERID = @USERID";
|
||
|
parameters.Add(new DataParameter { ParameterName = "ORGAID", DataType = DbType.String, Value = orga.OrgaID });
|
||
|
parameters.Add(new DataParameter { ParameterName = "USERID", DataType = DbType.String, Value = orga.UserID });
|
||
|
|
||
|
sql = this.ChangeSqlByDB(sql, session);
|
||
|
count = session.ExecuteSql(sql, parameters.ToArray());
|
||
|
|
||
|
//在删除组织机构下人员的信息
|
||
|
parameters.Clear();
|
||
|
sql = "DELETE T_QM_USERORGAIZATION WHERE ORGAID=@ORGAID AND USERID = @USERID";
|
||
|
parameters.Add(new DataParameter { ParameterName = "ORGAID", DataType = DbType.String, Value = orga.OrgaID });
|
||
|
parameters.Add(new DataParameter { ParameterName = "USERID", DataType = DbType.String, Value = orga.UserID });
|
||
|
parameters.Add(new DataParameter { ParameterName = "ISMAINORGA", DataType = DbType.String, Value = orga.IsMainOgra });
|
||
|
|
||
|
sql = this.ChangeSqlByDB(sql, session);
|
||
|
count = session.ExecuteSql(sql, parameters.ToArray());
|
||
|
|
||
|
|
||
|
session.CommitTs();
|
||
|
}
|
||
|
return count;
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
throw;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
#region 插入组织机构信息
|
||
|
|
||
|
/// <summary>
|
||
|
/// 插入组织机构信息
|
||
|
/// </summary>
|
||
|
/// <param name="orga">组织机构信息</param>
|
||
|
/// <returns>插入数</returns>
|
||
|
public int Insert(Orgaization orga)
|
||
|
{
|
||
|
int count = 0;
|
||
|
|
||
|
try
|
||
|
{
|
||
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
||
|
{
|
||
|
session.OpenTs();
|
||
|
orga.DelFlag = "0";
|
||
|
if (String.IsNullOrEmpty(orga.OrgaParent))
|
||
|
{
|
||
|
orga.OrgaParent = "0";
|
||
|
}
|
||
|
//插入基本信息
|
||
|
session.Insert<Orgaization>(orga);
|
||
|
|
||
|
//插入组织机构与权限信息
|
||
|
if (orga.OrgaAuthorityList!=null)
|
||
|
{
|
||
|
session.Insert<OrgaizationAuthority>(orga.OrgaAuthorityList);
|
||
|
}
|
||
|
|
||
|
//插入组织机构与角色信息
|
||
|
if (orga.RoleList != null)
|
||
|
{
|
||
|
session.Insert<T_QM_ORGANROLE>(orga.RoleList);
|
||
|
}
|
||
|
|
||
|
session.CommitTs();
|
||
|
}
|
||
|
return count;
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
throw;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
#region 删除组织机构信息
|
||
|
|
||
|
/// <summary>
|
||
|
/// 删除组织机构信息
|
||
|
/// </summary>
|
||
|
/// <param name="orga">组织机构信息</param>
|
||
|
/// <returns>删除个数</returns>
|
||
|
public int Delete(Orgaization orga)
|
||
|
{
|
||
|
int count = 0;
|
||
|
string sql = null;
|
||
|
try
|
||
|
{
|
||
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
||
|
{
|
||
|
//校验是否为激活状态
|
||
|
string activateFlg = "";
|
||
|
sql = "SELECT ACTIVATEFLG FROM T_QM_ORGANIZATION WHERE ORGAID = @ORGAID";
|
||
|
sql = this.ChangeSqlByDB(sql, session);
|
||
|
activateFlg = (string)session.ExecuteSqlScalar(sql, new DataParameter { ParameterName = "ORGAID", DataType = DbType.String, Value = orga.OrgaID });
|
||
|
if (activateFlg == "1")
|
||
|
return 0;
|
||
|
|
||
|
session.OpenTs();
|
||
|
|
||
|
//删除组织机构与权限信息
|
||
|
sql = "DELETE T_QM_ORGAIZATIONAUTHORITY WHERE ORGAID = @ORGAID";
|
||
|
sql = this.ChangeSqlByDB(sql, session);
|
||
|
count = session.ExecuteSql(sql, new DataParameter { ParameterName = "ORGAID", DataType = DbType.String, Value = orga.OrgaID });
|
||
|
|
||
|
//删除组织机构与角色信息
|
||
|
sql = "DELETE T_QM_ORGANROLE WHERE ORGANID = @ORGAID";
|
||
|
sql = this.ChangeSqlByDB(sql, session);
|
||
|
count = session.ExecuteSql(sql, new DataParameter { ParameterName = "ORGAID", DataType = DbType.String, Value = orga.OrgaID });
|
||
|
|
||
|
|
||
|
//删除组织机构信息
|
||
|
sql = "UPDATE T_QM_ORGANIZATION SET FLGDEL = '1' WHERE ORGAID = @ORGAID";
|
||
|
sql = this.ChangeSqlByDB(sql, session);
|
||
|
count = session.ExecuteSql(sql, new DataParameter { ParameterName = "ORGAID", DataType = DbType.String, Value = orga.OrgaID });
|
||
|
|
||
|
|
||
|
session.CommitTs();
|
||
|
}
|
||
|
return count;
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
throw;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
#region 更新组织机构
|
||
|
|
||
|
/// <summary>
|
||
|
/// 更新组织机构
|
||
|
/// </summary>
|
||
|
/// <param name="orga">组织机构</param>
|
||
|
/// <returns>更新个数</returns>
|
||
|
public int Update(Orgaization orga)
|
||
|
{
|
||
|
int count = 0;
|
||
|
string sql = null;
|
||
|
try
|
||
|
{
|
||
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
||
|
{
|
||
|
session.OpenTs();
|
||
|
|
||
|
//删除组织机构与权限信息
|
||
|
sql = "DELETE T_QM_ORGAIZATIONAUTHORITY WHERE ORGAID=@ORGAID";
|
||
|
sql = this.ChangeSqlByDB(sql, session);
|
||
|
count = session.ExecuteSql(sql, new DataParameter { ParameterName = "ORGAID", DataType = DbType.String, Value = orga.OrgaID });
|
||
|
|
||
|
//插入组织机构与权限信息
|
||
|
if (orga.OrgaAuthorityList != null)
|
||
|
{
|
||
|
session.Insert<OrgaizationAuthority>(orga.OrgaAuthorityList);
|
||
|
}
|
||
|
|
||
|
//删除组织机构与角色信息
|
||
|
sql = "DELETE T_QM_ORGANROLE WHERE ORGANID=@ORGANID";
|
||
|
sql = this.ChangeSqlByDB(sql, session);
|
||
|
count = session.ExecuteSql(sql, new DataParameter { ParameterName = "ORGANID", DataType = DbType.String, Value = orga.OrgaID });
|
||
|
|
||
|
//插入组织机构与角色信息
|
||
|
if (orga.RoleList != null)
|
||
|
{
|
||
|
session.Insert<T_QM_ORGANROLE>(orga.RoleList);
|
||
|
}
|
||
|
|
||
|
//设置用户激活状态
|
||
|
if (orga.ACTIVATEFLG == "0")
|
||
|
{
|
||
|
sql = "UPDATE T_QM_USER SET ACTIVATEFLG = '0' WHERE ORGANID = @ORGAID";
|
||
|
sql = this.ChangeSqlByDB(sql, session);
|
||
|
session.ExecuteSql(sql, new DataParameter { ParameterName = "ORGAID", DataType = DbType.String, Value = orga.OrgaID });
|
||
|
}
|
||
|
|
||
|
//更新基本信息
|
||
|
count = session.Update<Orgaization>(orga);
|
||
|
|
||
|
session.CommitTs();
|
||
|
}
|
||
|
return count;
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
throw;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
#region 获取导出的数据
|
||
|
/// <summary>
|
||
|
/// 获取导出的数据
|
||
|
/// </summary>
|
||
|
/// <param name="condition">查询条件</param>
|
||
|
/// <returns>数据</returns>
|
||
|
public DataTable GetExportData(Orgaization condition)
|
||
|
{
|
||
|
StringBuilder sqlBuilder = new StringBuilder();
|
||
|
StringBuilder whereBuilder = new StringBuilder();
|
||
|
DataTable dt = null;
|
||
|
string sql = null;
|
||
|
List<DataParameter> parameters = new List<DataParameter>();
|
||
|
try
|
||
|
{
|
||
|
//构成查询语句
|
||
|
sqlBuilder.Append("SELECT A.ORGAID,A.ORGADESC,A.ORGAPARENT,A.ACTIVATEFLG,U1.USERNAME AS CREATEUSER,A.CREATEDATE,U2.USERNAME AS UPDATEUSER,A.UPDATEDATE,");
|
||
|
sqlBuilder.Append("A.FLGDEL,(SELECT ORGADESC FROM T_QM_ORGANIZATION WHERE ORGAID = A.ORGAPARENT) AS ORGAPARENTDESC ");
|
||
|
sqlBuilder.Append(" FROM T_QM_ORGANIZATION A,T_QM_USER U1,T_QM_USER U2 WHERE A.CREATEUSER = U1.USERID AND A.UPDATEUSER = U2.USERID ");
|
||
|
sqlBuilder.Append(" AND A.FLGDEL = '0' ");
|
||
|
|
||
|
//查询条件
|
||
|
if (string.IsNullOrEmpty(condition.OrgaDESC) == false)
|
||
|
{
|
||
|
whereBuilder.Append(" AND A.ORGADESC = @ORGADESC");
|
||
|
parameters.Add(new DataParameter { ParameterName = "ORGADESC", DataType = DbType.String, Value = condition.OrgaDESC });
|
||
|
}
|
||
|
|
||
|
if (whereBuilder.Length > 0)
|
||
|
{
|
||
|
sqlBuilder.Append(whereBuilder.ToString());
|
||
|
}
|
||
|
|
||
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
||
|
{
|
||
|
sql = this.ChangeSqlByDB(sqlBuilder.ToString(), session);
|
||
|
dt = session.GetTable(sql, parameters.ToArray());
|
||
|
dt.TableName = "T_QM_ORGANIZATION";
|
||
|
}
|
||
|
|
||
|
foreach (DataRow row in dt.Rows)
|
||
|
{
|
||
|
if (row["ACTIVATEFLG"].ToString() == "1")
|
||
|
{
|
||
|
row["ACTIVATEFLG"] = "是";
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
row["ACTIVATEFLG"] = "否";
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return dt;
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
throw;
|
||
|
}
|
||
|
}
|
||
|
#endregion
|
||
|
|
||
|
#region 获取组织机构
|
||
|
|
||
|
/// <summary>
|
||
|
/// 获取组织机构信息
|
||
|
/// </summary>
|
||
|
/// <param name="orga">条件</param>
|
||
|
/// <returns>组织机构信息</returns>
|
||
|
public Orgaization Get(string orgaDesc)
|
||
|
{
|
||
|
string sql = null;
|
||
|
List<DataParameter> parameters = new List<DataParameter>();
|
||
|
Orgaization tmporga = new Orgaization();
|
||
|
try
|
||
|
{
|
||
|
//获取用户信息
|
||
|
sql = @"SELECT ORGAID FROM T_QM_ORGANIZATION A WHERE ORGADESC=@ORGADESC";
|
||
|
parameters.Add(new DataParameter { ParameterName = "ORGADESC", DataType = DbType.String, Value = orgaDesc });
|
||
|
|
||
|
sql = this.ChangeSqlByDB(sql, this.BaseSession);
|
||
|
tmporga = this.BaseSession.Get<Orgaization>(sql, parameters.ToArray());
|
||
|
|
||
|
return tmporga;
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
throw;
|
||
|
}
|
||
|
}
|
||
|
#endregion
|
||
|
|
||
|
|
||
|
}
|
||
|
}
|