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 { /// /// 根据单位id获取单位信息 /// /// /// public static Model.Base_Unit GetUnit(string unitId) { return Funs.DB.Base_Unit.FirstOrDefault(x => x.UnitId == unitId); } /// /// 获取单位名称 /// /// /// 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; } /// /// 判断单位编号是否存在 /// /// 单位ID /// 单位编号 /// 项目ID /// 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; } /// /// 判断单位名称是否存在 /// /// 单位ID /// 单位编号 /// 项目ID /// 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; } /// /// 添加单位信息 /// /// public static void AddUnit(Model.Base_Unit newUnit) { Model.HJGLDB db = Funs.DB; db.Base_Unit.InsertOnSubmit(newUnit); db.SubmitChanges(); } /// /// 修改单位信息 /// /// 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(); } } /// /// 根据单位ID删除单位信息 /// /// 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(); } } /// /// 根据单位id获取单位信息 /// /// 项目ID /// 单位类型,如传null则为项目上所有单位 /// public static List 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 得到单位类型字符串 /// /// 得到单位类型字符串 /// /// /// 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 单位信息下拉项 /// /// 单位信息下拉项 /// /// 下拉框名称 /// 是否显示请选择 /// 项目 /// 类型是空为所有 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); } } /// /// 单位信息下拉项 /// /// 下拉框名称 /// 是否显示请选择 /// 项目 /// 类型是空为所有 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 单位类型下拉项 /// /// 单位类型下拉项 /// /// 下拉框名称 /// 是否显示请选择 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 } }