296 lines
		
	
	
		
			13 KiB
		
	
	
	
		
			C#
		
	
	
	
			
		
		
	
	
			296 lines
		
	
	
		
			13 KiB
		
	
	
	
		
			C#
		
	
	
	
| using System;
 | |
| using System.Collections.Generic;
 | |
| using System.Linq;
 | |
| using System.Text;
 | |
| using System.Threading.Tasks;
 | |
| using System.Web.UI.WebControls;
 | |
| 
 | |
| namespace BLL
 | |
| {
 | |
|     public class CostControlDetailService
 | |
|     {
 | |
|         /// <summary>
 | |
|         /// 根据Id获取一个费控项明细信息
 | |
|         /// </summary>
 | |
|         /// <param name="costControlDetailId">费控项明细Id</param>
 | |
|         public static Model.WBS_CostControlDetail GetCostControlDetailByCostControlDetailId(string costControlDetailId)
 | |
|         {
 | |
|             return Funs.DB.WBS_CostControlDetail.FirstOrDefault(e => e.CostControlDetailId == costControlDetailId);
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 根据项目Id获取有对应月份的周计划的费控项明细id
 | |
|         /// </summary>
 | |
|         /// <param name="costControlDetailId">费控项明细Id</param>
 | |
|         public static string GetHasWeekPlanCostControlIdByProjectIdAndMonth(string projectId, DateTime months)
 | |
|         {
 | |
|             Model.SGGLDB db = Funs.DB;
 | |
|             return (from x in db.WBS_CostControl
 | |
|                     join y in db.Wbs_WbsSet
 | |
|                     on x.WbsSetId equals y.WbsSetId
 | |
|                     where y.ProjectId == projectId && y.IsApprove == true &&
 | |
|                     (from a in db.WBS_CostControlDetail where a.CostControlId == x.CostControlId && a.Months == months && a.StartDate != null select a).Count() > 0
 | |
|                     select x.CostControlId).FirstOrDefault();
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 根据CostControlId判断是否存在费控项明细信息
 | |
|         /// </summary>
 | |
|         /// <param name="costControlId">costControlId</param>
 | |
|         public static bool IsExitCostControlDetailByCostControlId(string costControlId)
 | |
|         {
 | |
|             return (from x in Funs.DB.WBS_CostControlDetail where x.CostControlId == costControlId select x).Count() > 0;
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 根据costControlId和年及月获取对应费控项明细信息
 | |
|         /// </summary>
 | |
|         /// <param name="costControlId">对应wbsId</param>
 | |
|         /// <param name="toFlag">对应标志</param>
 | |
|         /// <param name="years">年</param>
 | |
|         /// <param name="months">月</param>
 | |
|         public static Model.WBS_CostControlDetail GetCostControlDetailByCostControlIdAndMonths(string costControlId, DateTime months)
 | |
|         {
 | |
|             return (from x in Funs.DB.WBS_CostControlDetail where x.CostControlId == costControlId && x.Months == months && x.StartDate == null select x).FirstOrDefault();
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 根据costControlId和年及月获取对应费控项明细信息
 | |
|         /// </summary>
 | |
|         /// <param name="costControlId">对应wbsId</param>
 | |
|         /// <param name="toFlag">对应标志</param>
 | |
|         /// <param name="years">年</param>
 | |
|         /// <param name="months">月</param>
 | |
|         public static Model.WBS_CostControlDetail GetCostControlDetailByCostControlIdAndMonthsWeek(string costControlId, DateTime months, DateTime startDate)
 | |
|         {
 | |
|             return (from x in Funs.DB.WBS_CostControlDetail where x.CostControlId == costControlId && x.Months == months && x.StartDate == startDate select x).FirstOrDefault();
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 根据costControlId和年及月获取对应费控项明细视图信息
 | |
|         /// </summary>
 | |
|         /// <param name="costControlId">对应wbsId</param>
 | |
|         /// <param name="toFlag">对应标志</param>
 | |
|         /// <param name="years">年</param>
 | |
|         /// <param name="months">月</param>
 | |
|         public static Model.View_WBS_CostControlDetail GetCostControlDetailViewByCostControlIdAndMonths(string costControlId, DateTime months)
 | |
|         {
 | |
|             return (from x in Funs.DB.View_WBS_CostControlDetail where x.CostControlId == costControlId && x.Months == months select x).FirstOrDefault();
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 根据costControlId和年及月获取对应费控项明细信息
 | |
|         /// </summary>
 | |
|         /// <param name="costControlId">对应wbsId</param>
 | |
|         /// <param name="toFlag">对应标志</param>
 | |
|         /// <param name="years">年</param>
 | |
|         /// <param name="months">月</param>
 | |
|         public static Model.View_WBS_CostControlDetail GetViewCostControlDetailByCostControlIdAndMonth(string costControlId, DateTime months)
 | |
|         {
 | |
|             return (from x in Funs.DB.View_WBS_CostControlDetail where x.CostControlId == costControlId && x.Months == months && x.StartDate == null select x).FirstOrDefault();
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 根据costControlId和年及月获取对应费控项明细信息
 | |
|         /// </summary>
 | |
|         /// <param name="costControlId">对应wbsId</param>
 | |
|         /// <param name="toFlag">对应标志</param>
 | |
|         /// <param name="years">年</param>
 | |
|         /// <param name="months">月</param>
 | |
|         public static Model.View_WBS_CostControlDetail GetViewCostControlDetailByCostControlIdAndMonthWeek(string costControlId, DateTime months, DateTime startDate)
 | |
|         {
 | |
|             return (from x in Funs.DB.View_WBS_CostControlDetail where x.CostControlId == costControlId && x.Months == months && x.StartDate == startDate select x).FirstOrDefault();
 | |
|         }
 | |
| 
 | |
|         public static Model.WBS_CostControlDetail GetWBS_CostControlDetailByCostControlId(string costControlId)
 | |
|         {
 | |
|             return (from x in Funs.DB.WBS_CostControlDetail where x.CostControlId == costControlId select x).FirstOrDefault();
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 
 | |
|         /// </summary>
 | |
|         /// <param name="costControlId"></param>
 | |
|         /// <param name="toFlag"></param>
 | |
|         /// <param name="months"></param>
 | |
|         /// <returns></returns>
 | |
|         public static bool IsExitWeekCostControlDetailByCostControlIdAndMonth(string costControlId, DateTime months)
 | |
|         {
 | |
|             bool result = false;
 | |
|             var q = Funs.DB.WBS_CostControlDetail.FirstOrDefault(e => e.CostControlId == costControlId && e.Months == months);
 | |
|             if (q != null)
 | |
|             {
 | |
|                 result = true;
 | |
|             }
 | |
|             return result;
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 根据年及月获取之前月份的对应费控项明细信息集合(含当月)
 | |
|         /// </summary>
 | |
|         /// <param name="years">年</param>
 | |
|         /// <param name="months">月</param>
 | |
|         public static List<Model.WBS_CostControlDetail> GetTotalWBS_CostControlDetailsByYearMonth2(string costControlId, DateTime months)
 | |
|         {
 | |
|             return (from x in Funs.DB.WBS_CostControlDetail where x.CostControlId == costControlId && x.Months <= months select x).ToList();
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 根据CostControlId月获取所有月份的对应费控项明细信息集合
 | |
|         /// </summary>
 | |
|         /// <param name="costControlId">costControlId</param>
 | |
|         public static List<Model.WBS_CostControlDetail> GetMonthCostControlDetailsByCostControlId(string costControlId)
 | |
|         {
 | |
|             return (from x in Funs.DB.WBS_CostControlDetail where x.CostControlId == costControlId && x.StartDate == null orderby x.Months select x).ToList();
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 根据CostControlId月获取对应月份的对应费控项周明细信息集合
 | |
|         /// </summary>
 | |
|         /// <param name="costControlId">costControlId</param>
 | |
|         public static List<Model.WBS_CostControlDetail> GetWeekCostControlDetailsByCostControlId(string costControlId, DateTime months)
 | |
|         {
 | |
|             return (from x in Funs.DB.WBS_CostControlDetail where x.CostControlId == costControlId && x.Months == months && x.StartDate != null orderby x.StartDate select x).ToList();
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 增加费控项明细
 | |
|         /// </summary>
 | |
|         /// <param name="user">费控项明细</param>
 | |
|         public static void AddCostControlDetail(Model.WBS_CostControlDetail costControlDetail)
 | |
|         {
 | |
|             Model.SGGLDB db = Funs.DB;
 | |
|             Model.WBS_CostControlDetail newWBS_CostControlDetail = new Model.WBS_CostControlDetail();
 | |
|             newWBS_CostControlDetail.CostControlDetailId = costControlDetail.CostControlDetailId;
 | |
|             newWBS_CostControlDetail.CostControlId = costControlDetail.CostControlId;
 | |
|             newWBS_CostControlDetail.Months = costControlDetail.Months;
 | |
|             newWBS_CostControlDetail.StartDate = costControlDetail.StartDate;
 | |
|             newWBS_CostControlDetail.EndDate = costControlDetail.EndDate;
 | |
|             if (costControlDetail.PlanNum == 0)
 | |
|             {
 | |
|                 newWBS_CostControlDetail.PlanNum = null;
 | |
|             }
 | |
|             else
 | |
|             {
 | |
|                 newWBS_CostControlDetail.PlanNum = costControlDetail.PlanNum;
 | |
|             }
 | |
|             if (costControlDetail.ThisNum == 0)
 | |
|             {
 | |
|                 newWBS_CostControlDetail.ThisNum = null;
 | |
|             }
 | |
|             else
 | |
|             {
 | |
|                 newWBS_CostControlDetail.ThisNum = costControlDetail.ThisNum;
 | |
|             }
 | |
|             db.WBS_CostControlDetail.InsertOnSubmit(newWBS_CostControlDetail);
 | |
|             db.SubmitChanges();
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 修改费控项明细
 | |
|         /// </summary>
 | |
|         /// <param name="user">费控项明细</param>
 | |
|         public static void UpdateCostControlDetail(Model.WBS_CostControlDetail costControlDetail)
 | |
|         {
 | |
|             Model.SGGLDB db = Funs.DB;
 | |
|             Model.WBS_CostControlDetail newWBS_CostControlDetail = db.WBS_CostControlDetail.First(e => e.CostControlDetailId == costControlDetail.CostControlDetailId);
 | |
|             newWBS_CostControlDetail.StartDate = costControlDetail.StartDate;
 | |
|             newWBS_CostControlDetail.EndDate = costControlDetail.EndDate;
 | |
|             if (costControlDetail.PlanNum == 0)
 | |
|             {
 | |
|                 newWBS_CostControlDetail.PlanNum = null;
 | |
|             }
 | |
|             else
 | |
|             {
 | |
|                 newWBS_CostControlDetail.PlanNum = costControlDetail.PlanNum;
 | |
|             }
 | |
|             if (costControlDetail.ThisNum == 0)
 | |
|             {
 | |
|                 newWBS_CostControlDetail.ThisNum = null;
 | |
|             }
 | |
|             else
 | |
|             {
 | |
|                 newWBS_CostControlDetail.ThisNum = costControlDetail.ThisNum;
 | |
|             }
 | |
| 
 | |
|             db.SubmitChanges();
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 根据Id删除费控项明细信息
 | |
|         /// </summary>
 | |
|         /// <param name="userId"></param>
 | |
|         public static void DeleteCostControlDetail(string costControlDetailId)
 | |
|         {
 | |
|             Model.SGGLDB db = Funs.DB;
 | |
|             Model.WBS_CostControlDetail ins = db.WBS_CostControlDetail.First(e => e.CostControlDetailId == costControlDetailId);
 | |
|             db.WBS_CostControlDetail.DeleteOnSubmit(ins);
 | |
|             db.SubmitChanges();
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 根据costControlId删除费控项明细信息
 | |
|         /// </summary>
 | |
|         /// <param name="userId"></param>
 | |
|         public static void DeleteCostControlDetailByCostControlId(string costControlId)
 | |
|         {
 | |
|             Model.SGGLDB db = Funs.DB;
 | |
|             var details = from x in db.WBS_CostControlDetail where x.CostControlId == costControlId select x;
 | |
|             if (details.Count() > 0)
 | |
|             {
 | |
|                 db.WBS_CostControlDetail.DeleteAllOnSubmit(details);
 | |
|                 db.SubmitChanges();
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         ///  周计划下拉框
 | |
|         /// </summary>
 | |
|         /// <param name="dropName">下拉框名字</param>
 | |
|         /// <param name="isShowPlease">是否显示请选择</param>
 | |
|         public static void InitWeekPlanList(FineUIPro.DropDownList dropName, string costControlId, DateTime months, bool isShowPlease)
 | |
|         {
 | |
|             dropName.DataValueField = "Value";
 | |
|             dropName.DataTextField = "Text";
 | |
|             dropName.DataSource = GetWeekPlanList(costControlId, months);
 | |
|             dropName.DataBind();
 | |
|             if (isShowPlease)
 | |
|             {
 | |
|                 Funs.FineUIPleaseSelect(dropName);
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         ///  根据费控项Id和月份获取对应月份的周计划记录
 | |
|         /// </summary>
 | |
|         /// <param name="projectId">项目Id</param>
 | |
|         /// <returns></returns>
 | |
|         public static ListItem[] GetWeekPlanList(string costControlId, DateTime months)
 | |
|         {
 | |
|             var q = (from x in Funs.DB.WBS_CostControlDetail
 | |
|                      where x.CostControlId == costControlId && x.Months == months && x.StartDate != null
 | |
|                      orderby x.StartDate
 | |
|                      select x).ToList();
 | |
|             ListItem[] list = new ListItem[q.Count()];
 | |
|             string dateStr = string.Empty, date = string.Empty;
 | |
|             for (int i = 0; i < list.Count(); i++)
 | |
|             {
 | |
|                 date = string.Empty;
 | |
|                 dateStr = string.Empty;
 | |
|                 if (q[i].StartDate != null)
 | |
|                 {
 | |
|                     dateStr = string.Format("{0:yyyy-MM-dd}", q[i].StartDate);
 | |
|                     date = string.Format("{0:yyyy-MM-dd}", q[i].StartDate);
 | |
|                 }
 | |
|                 if (q[i].EndDate != null)
 | |
|                 {
 | |
|                     dateStr += "至" + string.Format("{0:yyyy-MM-dd}", q[i].EndDate);
 | |
|                     date += "," + string.Format("{0:yyyy-MM-dd}", q[i].EndDate);
 | |
|                 }
 | |
|                 list[i] = new ListItem(dateStr, date);
 | |
|             }
 | |
|             return list;
 | |
|         }
 | |
|     }
 | |
| }
 |