273 lines
9.0 KiB
C#
273 lines
9.0 KiB
C#
|
namespace BLL
|
|||
|
{
|
|||
|
using System;
|
|||
|
using System.Collections;
|
|||
|
using System.Diagnostics.CodeAnalysis;
|
|||
|
using System.Globalization;
|
|||
|
using System.Linq;
|
|||
|
using System.Data.Linq;
|
|||
|
using System.Web.Security;
|
|||
|
using System.Web.UI.WebControls;
|
|||
|
using Model;
|
|||
|
using BLL;
|
|||
|
using System.Collections.Generic;
|
|||
|
|
|||
|
public static class Base_UnitService
|
|||
|
{
|
|||
|
public static Model.SGGLDB db = Funs.DB;
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 根据单位id获取单位信息
|
|||
|
/// </summary>
|
|||
|
/// <param name="UnitId"></param>
|
|||
|
/// <returns></returns>
|
|||
|
public static Model.Base_Unit GetUnit(string unitId)
|
|||
|
{
|
|||
|
return Funs.DB.Base_Unit.FirstOrDefault(x => x.UnitId == unitId);
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// 获取单位名称
|
|||
|
/// </summary>
|
|||
|
/// <param name="UnitId"></param>
|
|||
|
/// <returns></returns>
|
|||
|
public static string GetUnitNameByUnitId(string unitId)
|
|||
|
{
|
|||
|
string name = string.Empty;
|
|||
|
var unit = Funs.DB.Base_Unit.FirstOrDefault(x => x.UnitId == unitId);
|
|||
|
if (unit != null)
|
|||
|
{
|
|||
|
name = unit.UnitName;
|
|||
|
}
|
|||
|
return name;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 根据单位编码获取单位信息
|
|||
|
/// </summary>
|
|||
|
/// <param name="unitCode">单位编号</param>
|
|||
|
/// <returns>单位信息</returns>
|
|||
|
public static List<Model.Base_Unit> GetSubUnitList()
|
|||
|
{
|
|||
|
return (from x in db.Base_Unit where x.IsSubUnit == true select x).ToList();
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 根据项目id获取该项目所有内部单位信息
|
|||
|
/// </summary>
|
|||
|
/// <param name="UnitId"></param>
|
|||
|
/// <returns></returns>
|
|||
|
public static List<Model.Base_Unit> GetSubUnits(string projectId)
|
|||
|
{
|
|||
|
var q = (from x in Funs.DB.Base_Unit
|
|||
|
join y in Funs.DB.Project_Unit on x.UnitId equals y.UnitId
|
|||
|
where y.ProjectId == projectId && x.IsSubUnit == true
|
|||
|
orderby x.UnitCode
|
|||
|
select x).ToList();
|
|||
|
return q;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 判断单位编号是否存在
|
|||
|
/// </summary>
|
|||
|
/// <param name="unitId">单位ID</param>
|
|||
|
/// <param name="unitCode">单位编号</param>
|
|||
|
/// <returns></returns>
|
|||
|
public static bool IsExistUnitCode(string unitId, string unitCode)
|
|||
|
{
|
|||
|
bool isExitCode = false;
|
|||
|
var q = from x in Funs.DB.Base_Unit where x.UnitCode == unitCode && x.UnitId != unitId select x;
|
|||
|
if (q.Count() > 0)
|
|||
|
{
|
|||
|
isExitCode = true;
|
|||
|
}
|
|||
|
return isExitCode;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 判断单位名称是否存在
|
|||
|
/// </summary>
|
|||
|
/// <param name="unitId">单位ID</param>
|
|||
|
/// <param name="unitCode">单位编号</param>
|
|||
|
/// <returns></returns>
|
|||
|
public static bool IsExistUnitName(string unitId, string unitName)
|
|||
|
{
|
|||
|
bool isExitCode = false;
|
|||
|
var q = from x in Funs.DB.Base_Unit where x.UnitName == unitName && x.UnitId != unitId select x;
|
|||
|
if (q.Count() > 0)
|
|||
|
{
|
|||
|
isExitCode = true;
|
|||
|
}
|
|||
|
return isExitCode;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 判断是否存在本单位
|
|||
|
/// </summary>
|
|||
|
/// <returns></returns>
|
|||
|
public static bool IsExitMain()
|
|||
|
{
|
|||
|
var q = from x in Funs.DB.Base_Unit where x.IsMain == true select x;
|
|||
|
if (q.Count() > 0)
|
|||
|
{
|
|||
|
return true;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
return false;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 添加单位信息
|
|||
|
/// </summary>
|
|||
|
/// <param name="unit"></param>
|
|||
|
public static void AddUnit(Model.Base_Unit newUnit)
|
|||
|
{
|
|||
|
Model.SGGLDB db = Funs.DB;
|
|||
|
db.Base_Unit.InsertOnSubmit(newUnit);
|
|||
|
db.SubmitChanges();
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 修改单位信息
|
|||
|
/// </summary>
|
|||
|
/// <param name="unit"></param>
|
|||
|
public static void updateUnit(Model.Base_Unit unit)
|
|||
|
{
|
|||
|
Model.SGGLDB db = Funs.DB;
|
|||
|
Model.Base_Unit newUnit = db.Base_Unit.FirstOrDefault(e => e.UnitId == unit.UnitId);
|
|||
|
if (newUnit != null)
|
|||
|
{
|
|||
|
newUnit.UnitCode = unit.UnitCode;
|
|||
|
newUnit.UnitName = unit.UnitName;
|
|||
|
newUnit.Corporate = unit.Corporate;
|
|||
|
newUnit.Address = unit.Address;
|
|||
|
newUnit.Telephone = unit.Telephone;
|
|||
|
newUnit.Fax = unit.Fax;
|
|||
|
newUnit.ProjectRange = unit.ProjectRange;
|
|||
|
newUnit.IsMain = unit.IsMain;
|
|||
|
db.SubmitChanges();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 根据单位ID删除单位信息
|
|||
|
/// </summary>
|
|||
|
/// <param name="unitId"></param>
|
|||
|
public static void DeleteUnitByUnitId(string unitId)
|
|||
|
{
|
|||
|
Model.SGGLDB db = Funs.DB;
|
|||
|
Model.Base_Unit newUnit = db.Base_Unit.FirstOrDefault(e => e.UnitId == unitId);
|
|||
|
if (newUnit != null)
|
|||
|
{
|
|||
|
db.Base_Unit.DeleteOnSubmit(newUnit);
|
|||
|
db.SubmitChanges();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 根据项目ID查询单位信息
|
|||
|
/// </summary>
|
|||
|
/// <param name="unitType"></param>
|
|||
|
/// <returns></returns>
|
|||
|
public static List<Model.Base_Unit> GetAllUnitList()
|
|||
|
{
|
|||
|
return (from x in Funs.DB.Base_Unit select x).ToList();
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 获取项目单位名称项
|
|||
|
/// </summary>
|
|||
|
/// <returns></returns>
|
|||
|
public static List<Model.Base_Unit> GetUnitCodeByProjectIdList(string projectId)
|
|||
|
{
|
|||
|
var q = (from x in db.Base_Unit
|
|||
|
join y in db.Project_Unit
|
|||
|
on x.UnitId equals y.UnitId
|
|||
|
where y.ProjectId == projectId
|
|||
|
orderby x.UnitCode
|
|||
|
select x).ToList();
|
|||
|
return q;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 根据单位id获取单位信息
|
|||
|
/// </summary>
|
|||
|
/// <param name="projectId"></param>
|
|||
|
/// <param name="unitType">一个单位有可能多种类型</param>
|
|||
|
/// <returns></returns>
|
|||
|
public static List<Model.Base_Unit> GetUnitsByProjectUnitType(string projectId, string unitType)
|
|||
|
{
|
|||
|
var q = (from x in Funs.DB.Base_Unit
|
|||
|
join y in Funs.DB.Project_Unit on x.UnitId equals y.UnitId
|
|||
|
where y.ProjectId == projectId && y.UnitType.Contains(unitType)
|
|||
|
orderby x.UnitCode
|
|||
|
select x).ToList();
|
|||
|
return q;
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// 根据分包本单位类型ID获取单位项
|
|||
|
/// </summary>
|
|||
|
/// <returns></returns>
|
|||
|
public static List<Model.Base_Unit> GetUnitListByUnitId(string projectId, string unitId)
|
|||
|
{
|
|||
|
var q = (from x in Funs.DB.Base_Unit
|
|||
|
join y in Funs.DB.Project_Unit on x.UnitId equals y.UnitId
|
|||
|
where y.ProjectId == projectId && y.UnitId == unitId
|
|||
|
orderby x.UnitCode
|
|||
|
select x).ToList();
|
|||
|
return q;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 根据分包单位类型ID获取单位项
|
|||
|
/// </summary>
|
|||
|
/// <returns></returns>
|
|||
|
public static ListItem[] GetUnitList()
|
|||
|
{
|
|||
|
var q = (from x in Funs.DB.Base_Unit
|
|||
|
join y in Funs.DB.Project_Unit on x.UnitId equals y.UnitId
|
|||
|
orderby x.UnitCode
|
|||
|
select x).Distinct().ToList();
|
|||
|
ListItem[] list = new ListItem[q.Count()];
|
|||
|
for (int i = 0; i < q.Count(); i++)
|
|||
|
{
|
|||
|
list[i] = new ListItem(q[i].UnitCode + "-" + q[i].UnitName, q[i].UnitId.ToString());
|
|||
|
}
|
|||
|
return list;
|
|||
|
}
|
|||
|
|
|||
|
#region 得到单位类型字符串
|
|||
|
/// <summary>
|
|||
|
/// 得到单位类型字符串
|
|||
|
/// </summary>
|
|||
|
/// <param name="bigType"></param>
|
|||
|
/// <returns></returns>
|
|||
|
public static string ConvertUnitTypeStr(object unitType)
|
|||
|
{
|
|||
|
string name = string.Empty;
|
|||
|
if (unitType != null && unitType.ToString() != "")
|
|||
|
{
|
|||
|
string[] typeList = unitType.ToString().Split(',');
|
|||
|
foreach (string type in typeList)
|
|||
|
{
|
|||
|
var q = BLL.DropListService.UnitTypeSearchList().FirstOrDefault(x => x.Value == type);
|
|||
|
if (q != null)
|
|||
|
{
|
|||
|
name = name + q.Text + ",";
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
if (name != null)
|
|||
|
{
|
|||
|
name = name.Substring(0, name.LastIndexOf(","));
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return name;
|
|||
|
}
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|