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; /// /// 根据单位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; } /// /// 根据单位编码获取单位信息 /// /// 单位编号 /// 单位信息 public static List GetSubUnitList() { return (from x in db.Base_Unit where x.IsSubUnit == true select x).ToList(); } /// /// 根据项目id获取该项目所有内部单位信息 /// /// /// public static List 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; } /// /// 判断单位编号是否存在 /// /// 单位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 /// 单位编号 /// 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; } /// /// 判断是否存在本单位 /// /// 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; } } /// /// 添加单位信息 /// /// public static void AddUnit(Model.Base_Unit newUnit) { Model.SGGLDB db = Funs.DB; db.Base_Unit.InsertOnSubmit(newUnit); db.SubmitChanges(); } /// /// 修改单位信息 /// /// 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(); } } /// /// 根据单位ID删除单位信息 /// /// 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(); } } /// /// 根据项目ID查询单位信息 /// /// /// public static List GetAllUnitList() { return (from x in Funs.DB.Base_Unit select x).ToList(); } /// /// 获取项目单位名称项 /// /// public static List 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; } /// /// 根据单位id获取单位信息 /// /// /// 一个单位有可能多种类型 /// public static List 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; } /// /// 根据分包本单位类型ID获取单位项 /// /// public static List 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; } /// /// 根据分包单位类型ID获取单位项 /// /// 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 得到单位类型字符串 /// /// 得到单位类型字符串 /// /// /// 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 } }