258 lines
8.9 KiB
C#
258 lines
8.9 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
|
|
{
|
|
/// <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="unitId">单位ID</param>
|
|
/// <param name="unitCode">单位编号</param>
|
|
/// <param name="projectId">项目ID</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>
|
|
/// <param name="projectId">项目ID</param>
|
|
/// <returns></returns>
|
|
public static bool IsExistUnitName(string unitId, string unitName)
|
|
{
|
|
bool isExitName = false;
|
|
var q = from x in Funs.DB.Base_Unit where x.UnitName == unitName && x.UnitId != unitId select x;
|
|
if (q.Count() > 0)
|
|
{
|
|
isExitName = true;
|
|
}
|
|
return isExitName;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 添加单位信息
|
|
/// </summary>
|
|
/// <param name="unit"></param>
|
|
public static void AddUnit(Model.Base_Unit newUnit)
|
|
{
|
|
Model.HJGLDB 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.HJGLDB 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.UnitTypeId = unit.UnitTypeId;
|
|
db.SubmitChanges();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据单位ID删除单位信息
|
|
/// </summary>
|
|
/// <param name="unitId"></param>
|
|
public static void DeleteUnitByUnitId(string unitId)
|
|
{
|
|
Model.HJGLDB 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="projectId">项目ID</param>
|
|
/// <param name="unitTypeId">单位类型,如传null则为项目上所有单位</param>
|
|
/// <returns></returns>
|
|
public static List<Model.Base_Unit> GetUnitsByProjectUnitType(string unitTypeId)
|
|
{
|
|
var q = (from x in Funs.DB.Base_Unit
|
|
orderby x.UnitCode
|
|
select x).ToList();
|
|
if (!string.IsNullOrEmpty(unitTypeId))
|
|
{
|
|
q = q.Where(e => e.UnitTypeId == unitTypeId).ToList();
|
|
}
|
|
return q;
|
|
}
|
|
|
|
public static IEnumerable GetUnitsByProjectUnitType(string projectType, string unitTypeId)
|
|
{
|
|
var q = (from x in Funs.DB.Project_Unit
|
|
join y in Funs.DB.Base_Unit on x.UnitId equals y.UnitId
|
|
join z in Funs.DB.Base_Project on x.ProjectId equals z.ProjectId
|
|
where y.UnitTypeId == unitTypeId && z.ProjectTypeId == projectType
|
|
select new { x.UnitId, y.UnitName }
|
|
).ToList();
|
|
if (q.Count() > 0)
|
|
{
|
|
q = q.Distinct().ToList();
|
|
}
|
|
return q;
|
|
}
|
|
|
|
#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
|
|
|
|
|
|
#region 单位信息下拉项
|
|
/// <summary>
|
|
/// 单位信息下拉项
|
|
/// </summary>
|
|
/// <param name="dropName">下拉框名称</param>
|
|
/// <param name="isShowPlease">是否显示请选择</param>
|
|
/// <param name="projectId">项目</param>
|
|
/// <param name="unitTypeId">类型是空为所有</param>
|
|
public static void InitUnitDropDownList(FineUIPro.DropDownList dropName, bool isShowPlease, string unitTypeId,string itemText)
|
|
{
|
|
dropName.DataValueField = "UnitId";
|
|
dropName.DataTextField = "UnitName";
|
|
dropName.DataSource = GetUnitsByProjectUnitType(unitTypeId);
|
|
dropName.DataBind();
|
|
if (isShowPlease)
|
|
{
|
|
Funs.FineUIPleaseSelect(dropName,itemText);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 单位信息下拉项
|
|
/// </summary>
|
|
/// <param name="dropName">下拉框名称</param>
|
|
/// <param name="isShowPlease">是否显示请选择</param>
|
|
/// <param name="projectId">项目</param>
|
|
/// <param name="unitTypeId">类型是空为所有</param>
|
|
public static void InitProjectUnitDropDownList(FineUIPro.DropDownList dropName, bool isShowPlease,string projectId, string unitTypeId,string itemText)
|
|
{
|
|
dropName.DataValueField = "UnitId";
|
|
dropName.DataTextField = "UnitName";
|
|
dropName.DataSource = 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(unitTypeId)
|
|
select x;
|
|
dropName.DataBind();
|
|
if (isShowPlease)
|
|
{
|
|
Funs.FineUIPleaseSelect(dropName,itemText);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 单位类型下拉项
|
|
/// <summary>
|
|
/// 单位类型下拉项
|
|
/// </summary>
|
|
/// <param name="dropName">下拉框名称</param>
|
|
/// <param name="isShowPlease">是否显示请选择</param>
|
|
public static void UnitTypeDropDownList(FineUIPro.DropDownList dropName, bool isShowPlease,string itemText)
|
|
{
|
|
dropName.DataValueField = "UnitTypeId";
|
|
dropName.DataTextField = "UnitTypeName";
|
|
dropName.DataSource = (from x in Funs.DB.Base_UnitType select x).ToList();
|
|
dropName.DataBind();
|
|
if (isShowPlease)
|
|
{
|
|
Funs.FineUIPleaseSelect(dropName,itemText);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
}
|
|
}
|