using System; using System.Collections.Generic; using System.Data; using System.Linq; namespace BLL { public class WorkPackageService { /// /// 添加分部分项工程 /// /// public static void AddWorkPackage(Model.WBS_WorkPackage WorkPackage) { Model.SGGLDB db = Funs.DB; Model.WBS_WorkPackage newWorkPackage = new Model.WBS_WorkPackage(); newWorkPackage.WorkPackageId = WorkPackage.WorkPackageId; newWorkPackage.WorkPackageCode = WorkPackage.WorkPackageCode; newWorkPackage.UnitWorkId = WorkPackage.UnitWorkId; newWorkPackage.SuperWorkPack = WorkPackage.SuperWorkPack; newWorkPackage.PackageCode = WorkPackage.PackageCode; newWorkPackage.SuperWorkPackageId = WorkPackage.SuperWorkPackageId; newWorkPackage.PackageContent = WorkPackage.PackageContent; newWorkPackage.ProjectId = WorkPackage.ProjectId; newWorkPackage.IsChild = WorkPackage.IsChild; newWorkPackage.SortIndex = WorkPackage.SortIndex; newWorkPackage.InitWorkPackageCode = WorkPackage.InitWorkPackageCode; newWorkPackage.Weights = WorkPackage.Weights; newWorkPackage.ProjectType = WorkPackage.ProjectType; newWorkPackage.IsApprove = WorkPackage.IsApprove; newWorkPackage.Costs = WorkPackage.Costs; newWorkPackage.SubItemType = WorkPackage.SubItemType; newWorkPackage.PreJobId = WorkPackage.PreJobId; newWorkPackage.PlanProjectQuantity = WorkPackage.PlanProjectQuantity; newWorkPackage.RealProjectQuantity = WorkPackage.RealProjectQuantity; newWorkPackage.PlanStartDate = WorkPackage.PlanStartDate; newWorkPackage.PlanEndDate = WorkPackage.PlanEndDate; newWorkPackage.RealStartDate = WorkPackage.RealStartDate; newWorkPackage.RealEndDate = WorkPackage.RealEndDate; newWorkPackage.Unit = WorkPackage.Unit; db.WBS_WorkPackage.InsertOnSubmit(newWorkPackage); db.SubmitChanges(); } /// /// 修改分部分项工程 /// /// public static void UpdateWorkPackage(Model.WBS_WorkPackage WorkPackage) { Model.SGGLDB db = Funs.DB; Model.WBS_WorkPackage newWorkPackage = db.WBS_WorkPackage.First(e => e.WorkPackageId == WorkPackage.WorkPackageId); newWorkPackage.WorkPackageCode = WorkPackage.WorkPackageCode; newWorkPackage.UnitWorkId = WorkPackage.UnitWorkId; newWorkPackage.PackageCode = WorkPackage.PackageCode; newWorkPackage.PackageContent = WorkPackage.PackageContent; newWorkPackage.ProjectId = WorkPackage.ProjectId; newWorkPackage.IsChild = WorkPackage.IsChild; newWorkPackage.SortIndex = WorkPackage.SortIndex; newWorkPackage.Weights = WorkPackage.Weights; newWorkPackage.IsApprove = WorkPackage.IsApprove; newWorkPackage.Costs = WorkPackage.Costs; newWorkPackage.SubItemType = WorkPackage.SubItemType; newWorkPackage.PreJobId = WorkPackage.PreJobId; newWorkPackage.PlanProjectQuantity = WorkPackage.PlanProjectQuantity; newWorkPackage.RealProjectQuantity = WorkPackage.RealProjectQuantity; newWorkPackage.PlanStartDate = WorkPackage.PlanStartDate; newWorkPackage.PlanEndDate = WorkPackage.PlanEndDate; newWorkPackage.RealStartDate = WorkPackage.RealStartDate; newWorkPackage.RealEndDate = WorkPackage.RealEndDate; newWorkPackage.Unit = WorkPackage.Unit; newWorkPackage.IsMileStone = WorkPackage.IsMileStone; db.SubmitChanges(); } /// /// 根据单位工程id获取一个第一级分部信息 /// /// /// public static Model.WBS_WorkPackage GetWorkPackages1ByUnitWorkId(string unitWorkId) { return Funs.DB.WBS_WorkPackage.FirstOrDefault(x => x.SuperWorkPackageId == null && x.IsApprove == true && x.UnitWorkId == unitWorkId); } /// /// 根据单位工程Id获取第一级所有分部信息 /// /// /// public static List GetWorkPackages1sByUnitWorkId(string unitWorkId) { return (from x in Funs.DB.WBS_WorkPackage where x.SuperWorkPackageId == null && x.UnitWorkId.ToString() == unitWorkId orderby x.WorkPackageCode select x).ToList(); } /// /// 根据单位工程Id获取第一级审批所有分部信息 /// /// /// public static List GetApproveWorkPackages1sByUnitWorkId(string unitWorkId) { return (from x in Funs.DB.WBS_WorkPackage where x.SuperWorkPackageId == null && x.UnitWorkId.ToString() == unitWorkId && x.IsApprove == true orderby x.WorkPackageCode select x).ToList(); } /// /// 根据分部分项名称和单位工程id获取项目分部分项内容 /// /// /// /// public static Model.WBS_WorkPackage GetWorkPackageByPackageContent(string packageContent, string unitWorkId) { return Funs.DB.WBS_WorkPackage.FirstOrDefault(x => x.PackageContent == packageContent && x.UnitWorkId == unitWorkId); } /// /// 根据单位工程Id获取所有分部信息 /// /// /// public static List GetAllWorkPackagesByUnitWorkId(string unitWorkId) { return (from x in Funs.DB.WBS_WorkPackage where x.UnitWorkId.ToString() == unitWorkId orderby x.WorkPackageCode select x).ToList(); } /// /// 根据项目Id获取所有分部信息 /// /// /// public static List GetAllWorkPackagesByProjectId(string projectId) { return (from x in Funs.DB.WBS_WorkPackage where x.ProjectId == projectId orderby x.WorkPackageCode select x).ToList(); } /// /// 根据分部分项Id获取分部分项信息 /// /// /// public static Model.WBS_WorkPackage GetWorkPackageByWorkPackageId(string workPackageId) { return Funs.DB.WBS_WorkPackage.FirstOrDefault(x => x.WorkPackageId == workPackageId); } /// /// 根据单位工程Id和初始化编号获取分部分项信息 /// /// /// /// public static Model.WBS_WorkPackage GetWorkPackageByUnitWorkIdAndInitWorkPackageCode(string unitWorkId, string initWorkPackageCode) { return Funs.DB.WBS_WorkPackage.FirstOrDefault(x => x.UnitWorkId == unitWorkId && x.InitWorkPackageCode == initWorkPackageCode); } /// /// 根据父级Id获取所有分部分项信息 /// /// /// public static List GetAllWorkPackagesBySuperWorkPackageId(string workPackageId) { return (from x in Funs.DB.WBS_WorkPackage where x.SuperWorkPackageId == workPackageId orderby x.WorkPackageCode select x).ToList(); } /// /// 根据父级Id获取所有审批分部分项信息 /// /// /// public static List GetAllApproveWorkPackagesBySuperWorkPackageId(string workPackageId) { return (from x in Funs.DB.WBS_WorkPackage where x.SuperWorkPackageId == workPackageId && x.IsApprove == true orderby x.WorkPackageCode select x).ToList(); } /// /// 根据子分部工程Id删除一个子分部工程信息 /// /// public static void DeleteWorkPackage(string WorkPackageId) { Model.SGGLDB db = Funs.DB; Model.WBS_WorkPackage WorkPackage = db.WBS_WorkPackage.First(e => e.WorkPackageId == WorkPackageId); db.WBS_WorkPackage.DeleteOnSubmit(WorkPackage); db.SubmitChanges(); } /// /// 根据分部分项Id删除所有明细信息 /// /// public static void DeleteAllWorkPackageByUnitWorkId(string unitWorkId) { Model.SGGLDB db = Funs.DB; List q = (from x in db.WBS_WorkPackage where x.UnitWorkId == unitWorkId orderby x.WorkPackageCode select x).ToList(); db.WBS_WorkPackage.DeleteAllOnSubmit(q); db.SubmitChanges(); } /// /// 根据初始工作包编码和单位工程获取工作包集合 /// /// /// /// public static List GetWorkPackagesByInitWorkPackageCodeAndUnitWorkId(string initWorkPackageCode, string unitWorkId) { return (from x in Funs.DB.WBS_WorkPackage where x.InitWorkPackageCode == initWorkPackageCode && x.UnitWorkId.ToString() == unitWorkId orderby x.WorkPackageCode descending select x).ToList(); } /// /// 根据单位工程Id获取所有分部信息 /// /// /// public static List GetAllWorkPackagesByUnitWorkIds(string[] unitWorkIds) { return (from x in Funs.DB.WBS_WorkPackage where unitWorkIds.Contains(x.UnitWorkId) orderby x.WorkPackageCode select x).ToList(); } /// /// 获取单位工程分部分项下拉列表 /// /// /// /// public static void InitWorkPackagesDropDownListByUnitWorkId(FineUIPro.DropDownList dropName, string unitWorkId, bool isShowPlease) { dropName.DataValueField = "WorkPackageId"; dropName.DataTextField = "PackageContent"; dropName.DataSource = GetAllWorkPackagesByUnitWorkId(unitWorkId); dropName.DataBind(); if (isShowPlease) { Funs.FineUIPleaseSelect(dropName); } } /// /// 获取模拟树表格 /// /// public static DataTable GetAllTreeDataTable(string projectId) { using (var db = new Model.SGGLDB(Funs.ConnString)) { IQueryable workPackages = from x in db.WBS_WorkPackage where x.ProjectId == projectId select x; IQueryable unitWorks = from x in db.WBS_UnitWork where x.ProjectId == projectId select x; List getWBSs = (from x in db.View_WBS where x.ProjectId == projectId select x).ToList(); List WBSList = new List(); DataTable table = new DataTable(); table.Columns.Add(new DataColumn("Id", typeof(String))); table.Columns.Add(new DataColumn("SupId", typeof(String))); table.Columns.Add(new DataColumn("Name", typeof(String))); table.Columns.Add(new DataColumn("WBSType", typeof(String))); table.Columns.Add(new DataColumn("ProjectId", typeof(String))); table.Columns.Add(new DataColumn("ShowId", typeof(String))); table.Columns.Add(new DataColumn("Weights", typeof(String))); table.Columns.Add(new DataColumn("Unit", typeof(String))); table.Columns.Add(new DataColumn("PlanProjectQuantity", typeof(String))); table.Columns.Add(new DataColumn("RealProjectQuantity", typeof(String))); table.Columns.Add(new DataColumn("PlanStartDate", typeof(DateTime))); table.Columns.Add(new DataColumn("PlanEndDate", typeof(DateTime))); table.Columns.Add(new DataColumn("RealStartDate", typeof(DateTime))); table.Columns.Add(new DataColumn("RealEndDate", typeof(DateTime))); table.Columns.Add(new DataColumn("IsMileStone", typeof(bool))); if (getWBSs.Count() > 0) { List newList = new List(); var projectTypes = getWBSs.Where(x => x.WBSType == "ProjectType" && x.SupId == "0"); foreach (var item in projectTypes) { newList.Add(item); AddDetail(newList, getWBSs.ToList(), item.Id); } DataRow row; foreach (Model.View_WBS item in newList) { row = table.NewRow(); row[0] = item.Id; row[1] = item.SupId; row[2] = item.Name; row[3] = item.WBSType; row[4] = item.ProjectId; if (item.WBSType == "WorkPackage") { var childWorkPackages = from x in workPackages where x.SuperWorkPackageId == item.Id && x.IsApprove == true select x; if (childWorkPackages.Count() == 0) { row[5] = item.Id; var workPackage = workPackages.FirstOrDefault(x => x.WorkPackageId == item.Id); if (workPackage != null) { if (workPackage.Weights != null) { row[6] = decimal.Round(Convert.ToDecimal(workPackage.Weights), 2); } row[7] = workPackage.Unit; if (workPackage.PlanProjectQuantity != null) { row[8] = decimal.Round(Convert.ToDecimal(workPackage.PlanProjectQuantity), 2); } if (workPackage.RealProjectQuantity != null) { row[9] = decimal.Round(Convert.ToDecimal(workPackage.RealProjectQuantity), 2); } if (workPackage.PlanStartDate != null) { row[10] = workPackage.PlanStartDate; } if (workPackage.PlanEndDate != null) { row[11] = workPackage.PlanEndDate; } if (workPackage.RealStartDate != null) { row[12] = workPackage.RealStartDate; } if (workPackage.RealEndDate != null) { row[13] = workPackage.RealEndDate; } if (workPackage.IsMileStone != null) { row[14] = workPackage.IsMileStone; } } } } else if (item.WBSType == "UnitWork") { var unitWork = unitWorks.FirstOrDefault(x => x.UnitWorkId == item.Id); if (unitWork != null) { if (unitWork.PlanStartDate != null) { row[10] = unitWork.PlanStartDate; } if (unitWork.PlanEndDate != null) { row[11] = unitWork.PlanEndDate; } if (unitWork.RealStartDate != null) { row[12] = unitWork.RealStartDate; } if (unitWork.RealEndDate != null) { row[13] = unitWork.RealEndDate; } } } table.Rows.Add(row); } } return table; } } private static void AddDetail(List newList, List oldList, string id) { var items = oldList.Where(x => x.SupId == id).OrderBy(x => x.Code); foreach (var item in items) { newList.Add(item); AddDetail(newList, oldList, item.Id); } } } }